From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: <mingo@kernel.org>, <oleg@redhat.com>,
<torvalds@linux-foundation.org>, <tglx@linutronix.de>,
<ilya.dryomov@inktank.com>, <umgwanakikbuti@gmail.com>,
<linux-kernel@vger.kernel.org>,
Eric Paris <eparis@parisplace.org>,
John McCutchan <john@johnmccutchan.com>,
Robert Love <rlove@rlove.org>
Subject: Re: [RFC][PATCH 4/7] inotify: Deal with nested sleeps
Date: Tue, 5 Aug 2014 10:22:11 +0800 [thread overview]
Message-ID: <53E03FD3.5050705@cn.fujitsu.com> (raw)
In-Reply-To: <20140804103537.564978189@infradead.org>
I don't think this one needs nested sleeps.
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index cc423a3..1ca5888 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -233,15 +233,16 @@ static ssize_t inotify_read(struct file *file, char __user *buf,
group = file->private_data;
while (1) {
+ mutex_lock(&group->notification_mutex);
prepare_to_wait(&group->notification_waitq, &wait, TASK_INTERRUPTIBLE);
- mutex_lock(&group->notification_mutex);
kevent = get_one_event(group, count);
mutex_unlock(&group->notification_mutex);
pr_debug("%s: group=%p kevent=%p\n", __func__, group, kevent);
if (kevent) {
+ __set_current_state(TASK_RUNNING);
ret = PTR_ERR(kevent);
if (IS_ERR(kevent))
break;
On 08/04/2014 06:30 PM, Peter Zijlstra wrote:
> inotify_read is a wait loop with sleeps in. Wait loops rely on
> task_struct::state and sleeps do too, since that's the only means of
> actually sleeping. Therefore the nested sleeps destroy the wait loop
> state and the wait loop breaks the sleep functions that assume
> TASK_RUNNING (mutex_lock).
>
> Fix this by using the new woken_wake_function and wait_woken() stuff,
> which registers wakeups in wait and thereby allows shrinking the
> task_state::state changes to the actual sleep part.
>
> Cc: Eric Paris <eparis@parisplace.org>
> Cc: John McCutchan <john@johnmccutchan.com>
> Cc: Robert Love <rlove@rlove.org>
> Signed-off-by: Peter Zijlstra <peterz@infradead.org>
> ---
> fs/notify/inotify/inotify_user.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> --- a/fs/notify/inotify/inotify_user.c
> +++ b/fs/notify/inotify/inotify_user.c
> @@ -227,14 +227,13 @@ static ssize_t inotify_read(struct file
> struct fsnotify_event *kevent;
> char __user *start;
> int ret;
> - DEFINE_WAIT(wait);
> + DEFINE_WAIT_FUNC(wait, woken_wake_function);
>
> start = buf;
> group = file->private_data;
>
> + add_wait_queue(&group->notification_waitq, &wait);
> while (1) {
> - prepare_to_wait(&group->notification_waitq, &wait, TASK_INTERRUPTIBLE);
> -
> mutex_lock(&group->notification_mutex);
> kevent = get_one_event(group, count);
> mutex_unlock(&group->notification_mutex);
> @@ -264,10 +263,10 @@ static ssize_t inotify_read(struct file
> if (start != buf)
> break;
>
> - schedule();
> + wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
> }
> + remove_wait_queue(&group->notification_waitq, &wait);
>
> - finish_wait(&group->notification_waitq, &wait);
> if (start != buf && ret != -EFAULT)
> ret = buf - start;
> return ret;
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
> .
>
next prev parent reply other threads:[~2014-08-05 2:20 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-04 10:30 [RFC][PATCH 0/7] nested sleeps, fixes and debug infra Peter Zijlstra
2014-08-04 10:30 ` [RFC][PATCH 1/7] wait: Provide infrastructure to deal with nested blocking Peter Zijlstra
2014-08-04 13:44 ` Peter Zijlstra
2014-08-04 18:35 ` Oleg Nesterov
2014-08-04 10:30 ` [RFC][PATCH 2/7] wait: Provide Peter Zijlstra
2014-08-04 10:30 ` [RFC][PATCH 3/7] exit: Desl with nested sleeps Peter Zijlstra
2014-08-04 18:53 ` Oleg Nesterov
2014-08-04 10:30 ` [RFC][PATCH 4/7] inotify: Deal " Peter Zijlstra
2014-08-04 19:23 ` Oleg Nesterov
2014-08-04 21:02 ` Peter Zijlstra
2014-08-05 2:22 ` Lai Jiangshan [this message]
2014-08-05 7:28 ` Peter Zijlstra
2014-08-04 10:30 ` [RFC][PATCH 5/7] tty: " Peter Zijlstra
2014-08-05 23:29 ` Greg Kroah-Hartman
2014-08-04 10:30 ` [RFC][PATCH 6/7] smp: Correctly deal " Peter Zijlstra
2014-08-04 10:30 ` [RFC][PATCH 7/7] sched: Debug " Peter Zijlstra
2014-08-05 8:33 ` [RFC][PATCH 0/7] nested sleeps, fixes and debug infra Ilya Dryomov
2014-08-05 13:06 ` Peter Zijlstra
2014-08-06 7:51 ` Ilya Dryomov
2014-08-06 8:31 ` Peter Zijlstra
2014-08-06 21:16 ` David Miller
2014-08-07 8:10 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53E03FD3.5050705@cn.fujitsu.com \
--to=laijs@cn.fujitsu.com \
--cc=eparis@parisplace.org \
--cc=ilya.dryomov@inktank.com \
--cc=john@johnmccutchan.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rlove@rlove.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=umgwanakikbuti@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome