From: Oleg Nesterov <oleg@tv-sign.ru>
To: Roland McGrath <roland@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"linux-os (Dick Johnson)" <linux-os@analogic.com>,
linux-kernel@vger.kernel.org
Subject: Re: Kernel threads
Date: Sat, 10 Mar 2007 02:46:02 +0300 [thread overview]
Message-ID: <20070309234602.GA188@tv-sign.ru> (raw)
In-Reply-To: <20070309213852.059FC1801C4@magilla.sf.frob.com>
On 03/09, Roland McGrath wrote:
>
> > Yes sure, this change shoud be tested in -mm tree (I'll send the patch
> > on Sunday after some testing). The only (afaics) problem is that with
> > this change a kernel thread must not do do_fork(CLONE_THREAD).
>
> To clarify, the danger here is that an exit_signal=-1 leader would
> self-reap and leave behind live threads with dangling ->group_leader
> pointers. This danger doesn't exist for normal user group leaders with
> parents ignoring SIGCHLD, because exit_signal is never set to -1 until
> do_notify_parent, which is never called until the last thread in the group
> dies (except when ptrace'd, but then do_notify_parent never resets
> exit_signal at all). Is that right?
I think yes.
> > I think it should not, but currently this is technically
> > possible. Perhaps it makes sense to add BUG_ON(CLONE_THREAD &&
> > group_leader->exit_signal==-1) in copy_process().
>
> It probably wouldn't hurt to make it:
>
> if (user_mode(regs))
> BUG_ON(current->group_leader->exit_signal == -1);
Well, this is of course right, but a bit strange. Because we can add
this check to any function which can't be called after exit_notify().
> else
> BUG_ON((clone_flags & (CLONE_THREAD|CLONE_UNTRACED))
> != CLONE_UNTRACED);
I think this _should_ be right, but please note that fork_idle() does
copy_process(CLONE_VM). Also, we may have some external driver which
plays with do_fork/copy_process.
> > While we are talking about kernel threads, there is something I can't
> > undestand. kthread/daemonize use sigprocmask(SIG_BLOCK) to protect
> > against signals. This doesn't look right to me, because this doesn't
> > prevent the signal delivery, this only blocks signal_wake_up(). Every
> > "killall -33 khelper" means a "struct siginfo" leak.
>
> It does prevent the delivery (signal_pending() never set), but not the queuing.
Yep.
> > Imho, the kernel thread shouldn't play with ->blocked at all. Instead
> > it should set SIG_IGN for all handlers. If it really needs, say, SIGCHLD,
> > it should call allow_signal() anyway. Do you see any problems with this
> > approach?
>
> That sounds reasonable to me generally. However, if kernel threads ever
> spawn user children, they may not want the self-reaping behavior of
> ignoring SIGCHLD even if they never dequeue the signal (because they want
> to call do_wait).
Yes. That is why wait_for_helper() does allow_signal(SIGCHLD). I think a
kernel thread must not make any assumption about ->action[SIGCHLD] if it
wants to call wait4, but we may break some "buggy" external driver.
In fact, most threads inherit action[SIGCHLD] == SIG_IGN from worker_thread().
BTW, wait_for_helper() does do_sigaction() before allow_signal(). Looks
unneeded to me.
> There might be other strange caveats like that I'm not
> thinking of.
Yes, this makes me worry too :)
Oleg.
next prev parent reply other threads:[~2007-03-09 23:45 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-08 16:38 Kernel threads Oleg Nesterov
2007-03-09 0:31 ` Roland McGrath
2007-03-09 20:52 ` Oleg Nesterov
2007-03-09 21:38 ` Roland McGrath
2007-03-09 23:46 ` Oleg Nesterov [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-03-06 16:03 linux-os (Dick Johnson)
2007-03-08 9:00 ` Andrew Morton
2003-04-25 7:53 Kernel Threads Romero, Miguel Angel
2002-11-20 9:36 kernel threads Madhavi
2002-04-12 17:07 Vahid Fereydunkolahi
2002-04-12 17:45 ` Masoud Sharbiani
2001-12-13 7:05 blesson paul
[not found] <no.id>
2001-08-16 22:37 ` Alan Cox
2001-08-21 12:15 ` Christian Widmer
2001-08-16 22:23 Christian Widmer
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=20070309234602.GA188@tv-sign.ru \
--to=oleg@tv-sign.ru \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-os@analogic.com \
--cc=roland@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.