linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 1/2] sched/wait: Add wait_event_state_exclusive()
@ 2025-06-10  4:52 Sergey Senozhatsky
  2025-06-10  4:52 ` [PATCHv2 2/2] fuse: use freezable wait in fuse_get_req() Sergey Senozhatsky
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Sergey Senozhatsky @ 2025-06-10  4:52 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

Allows exclusive waits with a custom @state.

Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---

v2: switched to wait_event_state_exclusive()

 include/linux/wait.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/linux/wait.h b/include/linux/wait.h
index 327894f022cf..9ebb0d2e422a 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -968,6 +968,18 @@ extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *);
 		      state, 0, timeout,					\
 		      __ret = schedule_timeout(__ret))
 
+#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;									\
+})
+
 #define __wait_event_killable_timeout(wq_head, condition, timeout)		\
 	___wait_event(wq_head, ___wait_cond_timeout(condition),			\
 		      TASK_KILLABLE, 0, timeout,				\
-- 
2.50.0.rc1.591.g9c95f17f64-goog


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

* [PATCHv2 2/2] fuse: use freezable wait in fuse_get_req()
  2025-06-10  4:52 [PATCHv2 1/2] sched/wait: Add wait_event_state_exclusive() Sergey Senozhatsky
@ 2025-06-10  4:52 ` Sergey Senozhatsky
  2025-06-19  2:51   ` Sergey Senozhatsky
  2025-07-02  5:37   ` Miklos Szeredi
  2025-06-13  9:17 ` [PATCHv2 1/2] sched/wait: Add wait_event_state_exclusive() Peter Zijlstra
  2025-07-20 20:58 ` Askar Safin
  2 siblings, 2 replies; 7+ messages in thread
From: Sergey Senozhatsky @ 2025-06-10  4:52 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:

 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>
---

v2: use wait_event_state_exclusive()

 fs/fuse/dev.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index e80cd8f2c049..a0fd319ab216 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -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;
 	}
 	/* Matches smp_wmb() in fuse_set_initialized() */
-- 
2.50.0.rc1.591.g9c95f17f64-goog


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

* Re: [PATCHv2 1/2] sched/wait: Add wait_event_state_exclusive()
  2025-06-10  4:52 [PATCHv2 1/2] sched/wait: Add wait_event_state_exclusive() Sergey Senozhatsky
  2025-06-10  4:52 ` [PATCHv2 2/2] fuse: use freezable wait in fuse_get_req() Sergey Senozhatsky
@ 2025-06-13  9:17 ` Peter Zijlstra
  2025-07-20 20:58 ` Askar Safin
  2 siblings, 0 replies; 7+ messages in thread
From: Peter Zijlstra @ 2025-06-13  9:17 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Miklos Szeredi, Ingo Molnar, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Tomasz Figa,
	linux-fsdevel, linux-kernel

On Tue, Jun 10, 2025 at 01:52:28PM +0900, Sergey Senozhatsky wrote:
> Allows exclusive waits with a custom @state.
> 
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

> ---
> 
> v2: switched to wait_event_state_exclusive()
> 
>  include/linux/wait.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/include/linux/wait.h b/include/linux/wait.h
> index 327894f022cf..9ebb0d2e422a 100644
> --- a/include/linux/wait.h
> +++ b/include/linux/wait.h
> @@ -968,6 +968,18 @@ extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *);
>  		      state, 0, timeout,					\
>  		      __ret = schedule_timeout(__ret))
>  
> +#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;									\
> +})
> +
>  #define __wait_event_killable_timeout(wq_head, condition, timeout)		\
>  	___wait_event(wq_head, ___wait_cond_timeout(condition),			\
>  		      TASK_KILLABLE, 0, timeout,				\
> -- 
> 2.50.0.rc1.591.g9c95f17f64-goog
> 

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

* Re: [PATCHv2 2/2] fuse: use freezable wait in fuse_get_req()
  2025-06-10  4:52 ` [PATCHv2 2/2] fuse: use freezable wait in fuse_get_req() Sergey Senozhatsky
@ 2025-06-19  2:51   ` Sergey Senozhatsky
  2025-07-02  5:37   ` Miklos Szeredi
  1 sibling, 0 replies; 7+ messages in thread
From: Sergey Senozhatsky @ 2025-06-19  2:51 UTC (permalink / raw)
  To: Miklos Szeredi
  Cc: Peter Zijlstra, Ingo Molnar, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Tomasz Figa,
	linux-fsdevel, linux-kernel, Sergey Senozhatsky

On (25/06/10 13:52), Sergey Senozhatsky wrote:
> Use freezable wait in fuse_get_req() so that it won't block
> the system from entering suspend:
> 
>  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>

Miklos, are you fine with this?

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

* Re: [PATCHv2 2/2] fuse: use freezable wait in fuse_get_req()
  2025-06-10  4:52 ` [PATCHv2 2/2] fuse: use freezable wait in fuse_get_req() Sergey Senozhatsky
  2025-06-19  2:51   ` Sergey Senozhatsky
@ 2025-07-02  5:37   ` Miklos Szeredi
  1 sibling, 0 replies; 7+ messages in thread
From: Miklos Szeredi @ 2025-07-02  5:37 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Peter Zijlstra, Ingo Molnar, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Tomasz Figa,
	linux-fsdevel, linux-kernel

On Tue, 10 Jun 2025 at 06:53, Sergey Senozhatsky
<senozhatsky@chromium.org> wrote:
>
> Use freezable wait in fuse_get_req() so that it won't block
> the system from entering suspend:
>
>  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>

Applied, thanks.

Miklos

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

* Re: [PATCHv2 1/2] sched/wait: Add wait_event_state_exclusive()
  2025-06-10  4:52 [PATCHv2 1/2] sched/wait: Add wait_event_state_exclusive() Sergey Senozhatsky
  2025-06-10  4:52 ` [PATCHv2 2/2] fuse: use freezable wait in fuse_get_req() Sergey Senozhatsky
  2025-06-13  9:17 ` [PATCHv2 1/2] sched/wait: Add wait_event_state_exclusive() Peter Zijlstra
@ 2025-07-20 20:58 ` Askar Safin
  2025-07-21  3:16   ` Sergey Senozhatsky
  2 siblings, 1 reply; 7+ messages in thread
From: Askar Safin @ 2025-07-20 20:58 UTC (permalink / raw)
  To: senozhatsky
  Cc: bsegall, dietmar.eggemann, juri.lelli, linux-fsdevel,
	linux-kernel, miklos, mingo, peterz, rostedt, tfiga,
	vincent.guittot

I just tested this patch on my laptop. It doesn't work!

Here is my setup.

I compiled kernel f0e84022479b4700609e874cf220b5d7d0363403 from branch "for-next" from git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse.git , which seems to contain this patchset.

I booted into it.

I mounted sshfs filesystem (it is FUSE).

I disabled network.

I did "ls". "ls" hanged, because network is down.

Then I did suspend, and suspend didn't work.

I'm available for further testing.

--
Askar Safin

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

* Re: [PATCHv2 1/2] sched/wait: Add wait_event_state_exclusive()
  2025-07-20 20:58 ` Askar Safin
@ 2025-07-21  3:16   ` Sergey Senozhatsky
  0 siblings, 0 replies; 7+ messages in thread
From: Sergey Senozhatsky @ 2025-07-21  3:16 UTC (permalink / raw)
  To: Askar Safin
  Cc: senozhatsky, bsegall, dietmar.eggemann, juri.lelli, linux-fsdevel,
	linux-kernel, miklos, mingo, peterz, rostedt, tfiga,
	vincent.guittot

On (25/07/20 23:58), Askar Safin wrote:
> I booted into it.
> 
> I mounted sshfs filesystem (it is FUSE).
> 
> I disabled network.
> 
> I did "ls". "ls" hanged, because network is down.
> 
> Then I did suspend, and suspend didn't work.

The patch is for background requests, e.g. for those that
are issued on a not fully initialized fuse connection.

You probably tested one the wait_event-s in request_wait_answer()
instead (as a guess.)

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

end of thread, other threads:[~2025-07-21  3:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-10  4:52 [PATCHv2 1/2] sched/wait: Add wait_event_state_exclusive() Sergey Senozhatsky
2025-06-10  4:52 ` [PATCHv2 2/2] fuse: use freezable wait in fuse_get_req() Sergey Senozhatsky
2025-06-19  2:51   ` Sergey Senozhatsky
2025-07-02  5:37   ` Miklos Szeredi
2025-06-13  9:17 ` [PATCHv2 1/2] sched/wait: Add wait_event_state_exclusive() Peter Zijlstra
2025-07-20 20:58 ` Askar Safin
2025-07-21  3:16   ` 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).