From: ebiederm@xmission.com (Eric W. Biederman)
To: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Davide Libenzi <davidel@xmailserver.org>,
Ingo Molnar <mingo@elte.hu>,
Linus Torvalds <torvalds@linux-foundation.org>,
"Rafael J. Wysocki" <rjw@sisk.pl>,
Roland McGrath <roland@redhat.com>,
Rusty Russell <rusty@rustcorp.com.au>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] make kthread_stop() scalable
Date: Fri, 13 Apr 2007 17:44:41 -0600 [thread overview]
Message-ID: <m14pnjon4m.fsf@ebiederm.dsl.xmission.com> (raw)
In-Reply-To: <20070413130236.GA173@tv-sign.ru> (Oleg Nesterov's message of "Fri, 13 Apr 2007 17:02:36 +0400")
Oleg Nesterov <oleg@tv-sign.ru> writes:
> It's a shame kthread_stop() (may take a while!) runs with a global semaphore
> held. With this patch kthread() allocates all neccesary data (struct kthread)
> on its own stack, globals kthread_stop_xxx are deleted.
Oleg so fare you patches have been inspiring. However..
> HACKS:
>
> - re-use task_struct->set_child_tid to point to "struct kthread"
task_struct->vfork_done is a better cannidate.
> - use do_exit() directly to preserve "struct kthread" on stack
Calling do_exit directly like that is not a hack, as it appears the preferred
way to exit is to call do_exit, or complete_and_exit.
While this does improve the scalability and remove a global variable. It
also introduces a complex special case in the form of struct kthread.
It also doesn't solve the biggest problem with the current kthread interface
in that calling kthread_stop does not cause the code to break out of
interruptible sleeps.
> static int kthread(void *_create)
> {
> - struct kthread_create_info *create = _create;
> - int (*threadfn)(void *data);
> - void *data;
> - int ret = -EINTR;
> + struct kthread self = {
> + .task = current,
> + .err = -EINTR,
> + };
>
> /* Copy data: it's on kthread's stack */
> - threadfn = create->threadfn;
> - data = create->data;
> + struct kthread_create_info *create = _create;
> + int (*threadfn)(void *data) = create->threadfn;
> + void *data = create->data;
> +
> + /*
> + * This should be enough to assure that self is still on
> + * stack when we enter do_exit()
> + */
> + set_kthread(&self);
> + create->result = &self;
>
> @@ -91,7 +105,7 @@ static void create_kthread(struct kthrea
>
> /* We want our own signal handler (we take no signals by default). */
> pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD);
> - create->result = pid;
> + create->result = ERR_PTR(pid);
Ouch. You have a nasty race here.
If kthread runs before kernel_thread returns then setting
"create->result = ERR_PTR(pid);" could easily stomp
"create->result = &self".
Eric
next prev parent reply other threads:[~2007-04-13 23:46 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-13 13:02 [PATCH 3/3] make kthread_stop() scalable Oleg Nesterov
2007-04-13 23:44 ` Eric W. Biederman [this message]
2007-04-14 18:02 ` Oleg Nesterov
2007-04-14 18:34 ` Eric W. Biederman
2007-04-14 18:50 ` Oleg Nesterov
2007-04-14 3:13 ` [PATCH] kthread: Enhance kthread_stop to abort interruptible sleeps Eric W. Biederman
2007-04-14 3:17 ` [PATCH] kthread: Simplify kthread_create Eric W. Biederman
2007-04-14 18:35 ` [PATCH] kthread: Enhance kthread_stop to abort interruptible sleeps Oleg Nesterov
2007-04-14 19:04 ` Eric W. Biederman
2007-04-14 19:34 ` Oleg Nesterov
2007-04-24 10:09 ` Andrew Morton
2007-04-24 10:30 ` Eric W. Biederman
2007-04-24 10:42 ` Andrew Morton
2007-04-24 11:11 ` Eric W. Biederman
2007-04-24 15:05 ` Oleg Nesterov
2007-04-24 15:53 ` Oleg Nesterov
2007-04-24 17:18 ` Eric W. Biederman
2007-04-24 20:27 ` Oleg Nesterov
2007-04-24 21:19 ` Eric W. Biederman
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=m14pnjon4m.fsf@ebiederm.dsl.xmission.com \
--to=ebiederm@xmission.com \
--cc=akpm@linux-foundation.org \
--cc=davidel@xmailserver.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oleg@tv-sign.ru \
--cc=rjw@sisk.pl \
--cc=roland@redhat.com \
--cc=rusty@rustcorp.com.au \
--cc=torvalds@linux-foundation.org \
/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