From: Oleg Nesterov <oleg-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Petr Mladek <pmladek-AlSwsSmVLrQ@public.gmane.org>
Cc: Andrew Morton
<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Ingo Molnar <mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
Peter Zijlstra <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
Richard Weinberger <richard-/L3Ra7n9ekc@public.gmane.org>,
Steven Rostedt <rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org>,
David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
Trond Myklebust
<trond.myklebust-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>,
Anna Schumaker
<anna.schumaker-HgOvQuBEEgTQT0dZR+AlfA@public.gmane.org>,
linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Chris Mason <clm-b10kYP2dOMg@public.gmane.org>,
"Paul E. McKenney"
<paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>,
Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
Linus Torvalds
<torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
Jiri Kosina <jkosina-AlSwsSmVLrQ@public.gmane.org>,
Borislav Petkov <bp-l3A5Bk7waGM@public.gmane.org>,
Michal Hocko <mhocko-AlSwsSmVLrQ@public.gmane.org>,
live-patching-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [RFC PATCH 06/18] signal/kthread: Initial implementation of kthread signal handling
Date: Sat, 6 Jun 2015 23:58:16 +0200 [thread overview]
Message-ID: <20150606215816.GB15591@redhat.com> (raw)
In-Reply-To: <1433516477-5153-7-git-send-email-pmladek-AlSwsSmVLrQ@public.gmane.org>
On 06/05, Petr Mladek wrote:
>
> The main question is how much it should follow POSIX and the signal
> handling of user space processes. On one hand, we want to be as close
> as possible.
Why? Let the kthread decide what it should if it gets, say, SIGSTOP.
> Finally, kthread_do_signal() is called on a safe place in the main
> iterant kthread cycle. Then we will not need any special code for
> signals when using this kthread API.
OK, I will not comment other parts of iterant API in this thread.
But as for signal handling, to me a single kthread_iterant->do_signal()
callback looks better. Rather than multiple callbacks passed as
->kthread_sa_handler.
That single callback can deque a signal and decide what it should do.
> + spin_lock_irqsave(&sighand->siglock, flags);
> +
> + if (unlikely(signal->flags & SIGNAL_CLD_MASK)) {
> + WARN(1, "there are no parents for kernel threads\n");
> + signal->flags &= ~SIGNAL_CLD_MASK;
> + }
> +
> + for (;;) {
> + struct k_sigaction *ka;
> +
> + signr = dequeue_signal(current, ¤t->blocked, &ksig.info);
> +
> + if (!signr)
> + break;
> +
> + ka = &sighand->action[signr-1];
> +
> + /* Do nothing for ignored signals */
> + if (ka->sa.kthread_sa_handler == KTHREAD_SIG_IGN)
> + continue;
Again, I agree something like the simple kthread_dequeue_signal() makes
sense. Say, to drop the ignore signal like this code does. Although I
do not think this is really important, SIG_IGN is only possible if this
kthread does something strange. Say, blocks/unblocs the ignored signal.
> +
> + /* Run the custom handler if any */
> + if (ka->sa.kthread_sa_handler != KTHREAD_SIG_DFL) {
> + ksig.ka = *ka;
> +
> + if (ka->sa.sa_flags & SA_ONESHOT)
> + ka->sa.kthread_sa_handler = KTHREAD_SIG_DFL;
> +
> + spin_unlock_irqrestore(&sighand->siglock, flags);
> + /* could run directly for kthreads */
> + ksig.ka.sa.kthread_sa_handler(signr);
> + freezable_cond_resched();
> + goto relock;
Well. But for what? A simple "switch (signr)" after kthread_dequeue_signal()
can do the same. Or, speaking of kthread_iterant_fn() it can even dequeue the
signal and pass it to kti->whatever(signr).
> + if (sig_kernel_ignore(signr))
> + continue;
For what? Why a kthread should unignore (say) SIGWINCH if it is not going
to react?
> + if (sig_kernel_stop(signr)) {
> + __set_current_state(TASK_STOPPED);
> + spin_unlock_irqrestore(&sighand->siglock, flags);
> + /* Don't run again until woken by SIGCONT or SIGKILL */
> + freezable_schedule();
> + goto relock;
Yes this avoids the race with SIGCONT. But as I said we can add another
trivial helper which checks JOBCTL_STOP_DEQUEUED. So a kthread can do
this itself.
To me, SIG_DFL behaviour just makes makes no sense when it comes to
kthreads. I do not even think this can simplify the code. Unlike user-
space task, kthread can happily dequeue SIGSTOP, so why should we mimic
the userspace SIG_DFL logic.
> + /* Death signals, but try to terminate cleanly */
> + kthread_stop_current();
> + __flush_signals(current);
> + break;
The same.
Oleg.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2015-06-06 21:58 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-05 15:00 [RFC PATCH 00/18] kthreads/signal: Safer kthread API and signal handling Petr Mladek
2015-06-05 15:01 ` [RFC PATCH 01/18] kthread: Allow to call __kthread_create_on_node() with va_list args Petr Mladek
2015-06-05 15:01 ` [RFC PATCH 03/18] kthread: Add kthread_stop_current() Petr Mladek
2015-06-05 15:01 ` [RFC PATCH 04/18] signal: Rename kernel_sigaction() to kthread_sigaction() and clean it up Petr Mladek
2015-06-05 15:01 ` [RFC PATCH 07/18] kthread: Make iterant kthreads freezable by default Petr Mladek
[not found] ` <1433516477-5153-8-git-send-email-pmladek-AlSwsSmVLrQ@public.gmane.org>
2015-06-09 7:20 ` Tejun Heo
[not found] ` <20150609072003.GY21465-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2015-06-09 15:53 ` Petr Mladek
[not found] ` <20150609155313.GC9409-KsEp0d+Q8qECVLCxKZUutA@public.gmane.org>
2015-06-10 4:31 ` Tejun Heo
[not found] ` <20150610043154.GG11955-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2015-06-12 13:24 ` Petr Mladek
[not found] ` <20150612132440.GH9409-KsEp0d+Q8qECVLCxKZUutA@public.gmane.org>
2015-06-13 23:22 ` Tejun Heo
[not found] ` <20150613232222.GB346-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2015-06-15 9:28 ` Petr Mladek
2015-06-05 15:01 ` [RFC PATCH 09/18] kthread: Make it easier to correctly sleep in iterant kthreads Petr Mladek
[not found] ` <1433516477-5153-10-git-send-email-pmladek-AlSwsSmVLrQ@public.gmane.org>
2015-06-05 16:10 ` Peter Zijlstra
[not found] ` <20150605161021.GJ19282-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2015-06-08 10:01 ` Petr Mladek
2015-06-08 11:39 ` Peter Zijlstra
2015-06-09 15:25 ` Petr Mladek
[not found] ` <20150609152526.GB9409-KsEp0d+Q8qECVLCxKZUutA@public.gmane.org>
2015-06-10 9:05 ` Peter Zijlstra
[not found] ` <20150608100107.GA3135-KsEp0d+Q8qECVLCxKZUutA@public.gmane.org>
2015-06-09 7:32 ` Tejun Heo
2015-06-08 17:48 ` Steven Rostedt
[not found] ` <20150608134810.3abd862b-f9ZlEuEWxVcJvu8Pb33WZ0EMvNT87kid@public.gmane.org>
2015-06-10 9:07 ` Peter Zijlstra
2015-06-10 14:07 ` Steven Rostedt
[not found] ` <20150610100729.6a674c15-f9ZlEuEWxVcJvu8Pb33WZ0EMvNT87kid@public.gmane.org>
2015-06-11 4:28 ` Jiri Kosina
2015-06-05 15:01 ` [RFC PATCH 10/18] jffs2: Remove forward definition of jffs2_garbage_collect_thread() Petr Mladek
2015-06-05 15:01 ` [RFC PATCH 11/18] jffs2: Convert jffs2_gcd_mtd kthread into the iterant API Petr Mladek
[not found] ` <1433516477-5153-12-git-send-email-pmladek-AlSwsSmVLrQ@public.gmane.org>
2015-06-06 21:16 ` Oleg Nesterov
[not found] ` <20150606211648.GA15591-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-06-06 21:32 ` Jiri Kosina
[not found] ` <alpine.LNX.2.00.1506062322550.12753-ztGlSCb7Y1iN3ZZ/Hiejyg@public.gmane.org>
2015-06-06 22:30 ` Oleg Nesterov
[not found] ` <20150606223001.GA18838-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-06-06 22:44 ` Jiri Kosina
[not found] ` <alpine.LNX.2.00.1506070034100.12753-ztGlSCb7Y1iN3ZZ/Hiejyg@public.gmane.org>
2015-06-06 22:58 ` Oleg Nesterov
2015-06-05 15:01 ` [RFC PATCH 13/18] ring_buffer: Use iterant kthreads API in the ring buffer benchmark Petr Mladek
2015-06-05 15:01 ` [RFC PATCH 14/18] ring_buffer: Allow to cleanly freeze the ring buffer benchmark kthreads Petr Mladek
2015-06-05 15:01 ` [RFC PATCH 16/18] kthread: Support interruptible sleep with a timeout by iterant kthreads Petr Mladek
[not found] ` <1433516477-5153-1-git-send-email-pmladek-AlSwsSmVLrQ@public.gmane.org>
2015-06-05 15:01 ` [RFC PATCH 02/18] kthread: Add API for " Petr Mladek
[not found] ` <1433516477-5153-3-git-send-email-pmladek-AlSwsSmVLrQ@public.gmane.org>
2015-06-09 6:23 ` Tejun Heo
[not found] ` <20150609062349.GW21465-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2015-06-15 12:46 ` Petr Mladek
2015-06-05 15:01 ` [RFC PATCH 05/18] freezer/scheduler: Add freezable_cond_resched() Petr Mladek
2015-06-05 15:01 ` [RFC PATCH 06/18] signal/kthread: Initial implementation of kthread signal handling Petr Mladek
[not found] ` <1433516477-5153-7-git-send-email-pmladek-AlSwsSmVLrQ@public.gmane.org>
2015-06-06 21:58 ` Oleg Nesterov [this message]
[not found] ` <20150606215816.GB15591-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-06-08 13:51 ` Petr Mladek
[not found] ` <20150608135107.GB3135-KsEp0d+Q8qECVLCxKZUutA@public.gmane.org>
2015-06-08 21:13 ` Oleg Nesterov
[not found] ` <20150608211336.GB24869-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-06-15 13:13 ` Petr Mladek
[not found] ` <20150615131341.GN9409-KsEp0d+Q8qECVLCxKZUutA@public.gmane.org>
2015-06-15 19:14 ` Oleg Nesterov
[not found] ` <20150615191429.GA29727-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-06-16 7:54 ` Petr Mladek
2015-06-09 7:10 ` Tejun Heo
[not found] ` <20150609071022.GX21465-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2015-06-09 12:15 ` Jiri Kosina
[not found] ` <alpine.LNX.2.00.1506091405360.12753-ztGlSCb7Y1iN3ZZ/Hiejyg@public.gmane.org>
2015-06-10 3:13 ` Tejun Heo
2015-06-05 15:01 ` [RFC PATCH 08/18] kthread: Allow to get struct kthread_iterant from task_struct Petr Mladek
2015-06-05 15:01 ` [RFC PATCH 12/18] lockd: Convert the central lockd service to kthread_iterant API Petr Mladek
2015-06-05 15:01 ` [RFC PATCH 15/18] ring_buffer: Allow to exit the ring buffer benchmark immediately Petr Mladek
[not found] ` <1433516477-5153-16-git-send-email-pmladek-AlSwsSmVLrQ@public.gmane.org>
2015-06-08 17:44 ` Steven Rostedt
[not found] ` <20150608134417.3fb7a811-f9ZlEuEWxVcJvu8Pb33WZ0EMvNT87kid@public.gmane.org>
2015-06-15 15:23 ` Petr Mladek
[not found] ` <20150615152313.GC3135-KsEp0d+Q8qECVLCxKZUutA@public.gmane.org>
2015-06-15 15:33 ` Steven Rostedt
2015-06-15 15:54 ` Petr Mladek
2015-06-05 15:01 ` [RFC PATCH 17/18] ring_buffer: Use the new API for a sleep with a timeout in the benchmark Petr Mladek
2015-06-09 6:10 ` [RFC PATCH 00/18] kthreads/signal: Safer kthread API and signal handling Tejun Heo
[not found] ` <20150609061025.GU21465-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2015-06-09 7:58 ` Tejun Heo
2015-06-17 11:34 ` Christoph Hellwig
2015-06-05 15:01 ` [RFC PATCH 18/18] jffs2: Use the new API for a sleep with a timeout Petr Mladek
2015-06-05 16:22 ` [RFC PATCH 00/18] kthreads/signal: Safer kthread API and signal handling Peter Zijlstra
[not found] ` <20150605162216.GK19282-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2015-06-09 6:14 ` Tejun Heo
[not found] ` <20150609061446.GV21465-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2015-06-10 10:40 ` Peter Zijlstra
[not found] ` <20150610104057.GE3644-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2015-06-11 22:02 ` Tejun Heo
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=20150606215816.GB15591@redhat.com \
--to=oleg-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=anna.schumaker-HgOvQuBEEgTQT0dZR+AlfA@public.gmane.org \
--cc=bp-l3A5Bk7waGM@public.gmane.org \
--cc=clm-b10kYP2dOMg@public.gmane.org \
--cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=jkosina-AlSwsSmVLrQ@public.gmane.org \
--cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=live-patching-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mhocko-AlSwsSmVLrQ@public.gmane.org \
--cc=mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
--cc=peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=pmladek-AlSwsSmVLrQ@public.gmane.org \
--cc=richard-/L3Ra7n9ekc@public.gmane.org \
--cc=rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org \
--cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=trond.myklebust-7I+n7zu2hftEKMMhf/gKZA@public.gmane.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;
as well as URLs for NNTP newsgroup(s).