* [PATCH] fanotify: allow freeze when waiting response for permission events
@ 2024-03-05 6:18 Winston Wen
2024-03-06 17:59 ` Jan Kara
0 siblings, 1 reply; 2+ messages in thread
From: Winston Wen @ 2024-03-05 6:18 UTC (permalink / raw)
To: Jan Kara, Amir Goldstein
Cc: Vivek Trivedi, Orion Poplawski, Peter Zijlstra, linux-fsdevel,
Winston Wen
This is a long-standing issue that uninterruptible sleep in fanotify
could make system hibernation fail if the usperspace server gets frozen
before the process waiting for the response (as reported e.g. [1][2]).
A few years ago, there was an attempt to switch to interruptible sleep
while waiting [3], but that would lead to EINTR returns from open(2)
and break userspace [4], so it's been changed to only killable [5].
And the core freezer logic had been rewritten [6][7] in v6.1, allowing
freezing in uninterrupted sleep, so we can solve this problem now.
[1] https://lore.kernel.org/lkml/1518774280-38090-1-git-send-email-t.vivek@samsung.com/
[2] https://lore.kernel.org/lkml/c1bb16b7-9eee-9cea-2c96-a512d8b3b9c7@nwra.com/
[3] https://lore.kernel.org/linux-fsdevel/20190213145443.26836-1-jack@suse.cz/
[4] https://lore.kernel.org/linux-fsdevel/d0031e3a-f050-0832-fa59-928a80ffd44b@nwra.com/
[5] https://lore.kernel.org/linux-fsdevel/20190221105558.GA20921@quack2.suse.cz/
[6] https://lore.kernel.org/lkml/20220822114649.055452969@infradead.org/
[7] https://lore.kernel.org/lkml/20230908-avoid-spurious-freezer-wakeups-v4-0-6155aa3dafae@quicinc.com/
Signed-off-by: Winston Wen <wentao@uniontech.com>
---
fs/notify/fanotify/fanotify.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index 1e4def21811e..285beaf5bc09 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -228,8 +228,10 @@ static int fanotify_get_response(struct fsnotify_group *group,
pr_debug("%s: group=%p event=%p\n", __func__, group, event);
- ret = wait_event_killable(group->fanotify_data.access_waitq,
- event->state == FAN_EVENT_ANSWERED);
+ ret = wait_event_state(group->fanotify_data.access_waitq,
+ event->state == FAN_EVENT_ANSWERED,
+ TASK_KILLABLE|TASK_FREEZABLE);
+
/* Signal pending? */
if (ret < 0) {
spin_lock(&group->notification_lock);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fanotify: allow freeze when waiting response for permission events
2024-03-05 6:18 [PATCH] fanotify: allow freeze when waiting response for permission events Winston Wen
@ 2024-03-06 17:59 ` Jan Kara
0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2024-03-06 17:59 UTC (permalink / raw)
To: Winston Wen
Cc: Jan Kara, Amir Goldstein, Vivek Trivedi, Orion Poplawski,
Peter Zijlstra, linux-fsdevel
On Tue 05-03-24 14:18:04, Winston Wen wrote:
> This is a long-standing issue that uninterruptible sleep in fanotify
> could make system hibernation fail if the usperspace server gets frozen
> before the process waiting for the response (as reported e.g. [1][2]).
>
> A few years ago, there was an attempt to switch to interruptible sleep
> while waiting [3], but that would lead to EINTR returns from open(2)
> and break userspace [4], so it's been changed to only killable [5].
>
> And the core freezer logic had been rewritten [6][7] in v6.1, allowing
> freezing in uninterrupted sleep, so we can solve this problem now.
>
> [1] https://lore.kernel.org/lkml/1518774280-38090-1-git-send-email-t.vivek@samsung.com/
> [2] https://lore.kernel.org/lkml/c1bb16b7-9eee-9cea-2c96-a512d8b3b9c7@nwra.com/
> [3] https://lore.kernel.org/linux-fsdevel/20190213145443.26836-1-jack@suse.cz/
> [4] https://lore.kernel.org/linux-fsdevel/d0031e3a-f050-0832-fa59-928a80ffd44b@nwra.com/
> [5] https://lore.kernel.org/linux-fsdevel/20190221105558.GA20921@quack2.suse.cz/
> [6] https://lore.kernel.org/lkml/20220822114649.055452969@infradead.org/
> [7] https://lore.kernel.org/lkml/20230908-avoid-spurious-freezer-wakeups-v4-0-6155aa3dafae@quicinc.com/
>
> Signed-off-by: Winston Wen <wentao@uniontech.com>
Thanks and I'm glad this has finally a workable solution (keeping fingers
crossed ;)). I've added the patch to my tree.
Honza
> ---
> fs/notify/fanotify/fanotify.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
> index 1e4def21811e..285beaf5bc09 100644
> --- a/fs/notify/fanotify/fanotify.c
> +++ b/fs/notify/fanotify/fanotify.c
> @@ -228,8 +228,10 @@ static int fanotify_get_response(struct fsnotify_group *group,
>
> pr_debug("%s: group=%p event=%p\n", __func__, group, event);
>
> - ret = wait_event_killable(group->fanotify_data.access_waitq,
> - event->state == FAN_EVENT_ANSWERED);
> + ret = wait_event_state(group->fanotify_data.access_waitq,
> + event->state == FAN_EVENT_ANSWERED,
> + TASK_KILLABLE|TASK_FREEZABLE);
> +
> /* Signal pending? */
> if (ret < 0) {
> spin_lock(&group->notification_lock);
> --
> 2.43.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-06 17:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-05 6:18 [PATCH] fanotify: allow freeze when waiting response for permission events Winston Wen
2024-03-06 17:59 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox