linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] wait: add wait_event_freezable_killable_exclusive
@ 2025-06-09  3:07 Sergey Senozhatsky
  2025-06-09  3:07 ` [PATCH 2/2] fuse: use freezable wait in fuse_get_req() Sergey Senozhatsky
  2025-06-09  6:34 ` [PATCH 1/2] wait: add wait_event_freezable_killable_exclusive Sergey Senozhatsky
  0 siblings, 2 replies; 3+ messages in thread
From: Sergey Senozhatsky @ 2025-06-09  3:07 UTC (permalink / raw)
  To: Miklos Szeredi, Peter Zijlstra
  Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Tomasz Figa, linux-fsdevel,
	linux-kernel, Sergey Senozhatsky

Add a freezable variant of exclusive wait.  This can be useful
in, for example, FUSE when system suspend occurs while FUSE is
blocked on requests (which prevents system suspend.)

Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
 include/linux/wait.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/wait.h b/include/linux/wait.h
index 327894f022cf..b98cfd094543 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -657,6 +657,20 @@ do {										\
 	__ret;									\
 })
 
+#define __wait_event_freezable_killable_exclusive(wq, condition)		\
+	___wait_event(wq, condition, (TASK_KILLABLE|TASK_FREEZABLE), 1, 0,	\
+		      schedule())
+
+#define wait_event_freezable_killable_exclusive(wq, condition)			\
+({										\
+	int __ret = 0;								\
+	might_sleep();								\
+	if (!(condition))							\
+		__ret = __wait_event_freezable_killable_exclusive(wq,		\
+								  condition);	\
+	__ret;									\
+})
+
 /**
  * wait_event_idle - wait for a condition without contributing to system load
  * @wq_head: the waitqueue to wait on
-- 
2.50.0.rc1.591.g9c95f17f64-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] fuse: use freezable wait in fuse_get_req()
  2025-06-09  3:07 [PATCH 1/2] wait: add wait_event_freezable_killable_exclusive Sergey Senozhatsky
@ 2025-06-09  3:07 ` Sergey Senozhatsky
  2025-06-09  6:34 ` [PATCH 1/2] wait: add wait_event_freezable_killable_exclusive Sergey Senozhatsky
  1 sibling, 0 replies; 3+ messages in thread
From: Sergey Senozhatsky @ 2025-06-09  3:07 UTC (permalink / raw)
  To: Miklos Szeredi, Peter Zijlstra
  Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Tomasz Figa, linux-fsdevel,
	linux-kernel, Sergey Senozhatsky

Use freezable wait in fuse_get_req() so that it won't block
the system from entering suspend in some situations:

 Freezing user space processes failed after 20.009 seconds
 Call trace:
  __switch_to+0xcc/0x168
  schedule+0x57c/0x1138
  fuse_get_req+0xd0/0x2b0
  fuse_simple_request+0x120/0x620
  fuse_getxattr+0xe4/0x158
  fuse_xattr_get+0x2c/0x48
  __vfs_getxattr+0x160/0x1d8
  get_vfs_caps_from_disk+0x74/0x1a8
  __audit_inode+0x244/0x4d8
  user_path_at_empty+0x2e0/0x390
  __arm64_sys_faccessat+0xdc/0x260

Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
 fs/fuse/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index e80cd8f2c049..3792ca26c42f 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -207,7 +207,7 @@ static struct fuse_req *fuse_get_req(struct mnt_idmap *idmap,
 
 	if (fuse_block_alloc(fc, for_background)) {
 		err = -EINTR;
-		if (wait_event_killable_exclusive(fc->blocked_waitq,
+		if (wait_event_freezable_killable_exclusive(fc->blocked_waitq,
 				!fuse_block_alloc(fc, for_background)))
 			goto out;
 	}
-- 
2.50.0.rc1.591.g9c95f17f64-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] wait: add wait_event_freezable_killable_exclusive
  2025-06-09  3:07 [PATCH 1/2] wait: add wait_event_freezable_killable_exclusive Sergey Senozhatsky
  2025-06-09  3:07 ` [PATCH 2/2] fuse: use freezable wait in fuse_get_req() Sergey Senozhatsky
@ 2025-06-09  6:34 ` Sergey Senozhatsky
  1 sibling, 0 replies; 3+ messages in thread
From: Sergey Senozhatsky @ 2025-06-09  6:34 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Miklos Szeredi, Peter Zijlstra, Ingo Molnar, Juri Lelli,
	Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Tomasz Figa, linux-fsdevel, linux-kernel

On (25/06/09 12:07), Sergey Senozhatsky wrote:
> Add a freezable variant of exclusive wait.  This can be useful
> in, for example, FUSE when system suspend occurs while FUSE is
> blocked on requests (which prevents system suspend.)
> 
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> ---
>  include/linux/wait.h | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/include/linux/wait.h b/include/linux/wait.h
> index 327894f022cf..b98cfd094543 100644
> --- a/include/linux/wait.h
> +++ b/include/linux/wait.h
> @@ -657,6 +657,20 @@ do {										\
>  	__ret;									\
>  })
>  
> +#define __wait_event_freezable_killable_exclusive(wq, condition)		\
> +	___wait_event(wq, condition, (TASK_KILLABLE|TASK_FREEZABLE), 1, 0,	\
> +		      schedule())
> +
> +#define wait_event_freezable_killable_exclusive(wq, condition)			\
> +({										\
> +	int __ret = 0;								\
> +	might_sleep();								\
> +	if (!(condition))							\
> +		__ret = __wait_event_freezable_killable_exclusive(wq,		\
> +								  condition);	\
> +	__ret;									\
> +})

Or I can do something like:

+#define __wait_event_state_exclusive(wq, condition, state)			\
+	___wait_event(wq, condition, state, 1, 0, schedule())
+
+#define wait_event_state_exclusive(wq, condition, state)			\
+({										\
+	int __ret = 0;								\
+	might_sleep();								\
+	if (!(condition))							\
+		__ret = __wait_event_state_exclusive(wq, condition, state);	\
+	__ret;									\
+})


And then in fuse something like this:

@@ -207,8 +207,9 @@ static struct fuse_req *fuse_get_req(struct mnt_idmap *idmap,
 
 	if (fuse_block_alloc(fc, for_background)) {
 		err = -EINTR;
-		if (wait_event_killable_exclusive(fc->blocked_waitq,
-				!fuse_block_alloc(fc, for_background)))
+		if (wait_event_state_exclusive(fc->blocked_waitq,
+				!fuse_block_alloc(fc, for_background),
+				(TASK_KILLABLE|TASK_FREEZABLE)))
 			goto out;
 	}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-09  6:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-09  3:07 [PATCH 1/2] wait: add wait_event_freezable_killable_exclusive Sergey Senozhatsky
2025-06-09  3:07 ` [PATCH 2/2] fuse: use freezable wait in fuse_get_req() Sergey Senozhatsky
2025-06-09  6:34 ` [PATCH 1/2] wait: add wait_event_freezable_killable_exclusive Sergey Senozhatsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).