public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Roland McGrath <roland@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linux Kernel <linux-kernel@vger.kernel.org>,
	Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: Re: [BUG] ptraced process waiting on syscall may return kernel internal errnos
Date: Fri, 15 Jun 2007 23:48:11 +0200	[thread overview]
Message-ID: <200706152348.12019.rjw@sisk.pl> (raw)
In-Reply-To: <20070615113127.GB84@tv-sign.ru>

On Friday, 15 June 2007 13:31, Oleg Nesterov wrote:
> On 06/15, Rafael J. Wysocki wrote:
> >
> > +static void freeze_task(struct task_struct *p)
> > +{
> >  	if (!freezing(p)) {
> >  		rmb();
> >  		if (!frozen(p)) {
> >  			set_freeze_flag(p);
> > -			if (p->state == TASK_STOPPED)
> > -				force_sig_specific(SIGSTOP, p);
> > -			spin_lock_irqsave(&p->sighand->siglock, flags);
> > -			signal_wake_up(p, p->state == TASK_STOPPED);
> > -			spin_unlock_irqrestore(&p->sighand->siglock, flags);
> > +			task_lock(p);
> > +			/* We don't want to send signals to kernel threads */
> > +			if (p->mm && !(p->flags & PF_BORROWED_MM)) {
> > +				task_unlock(p);
> > +				send_fake_signal(p);
> > +			} else {
> > +				task_unlock(p);
> > +				wake_up_state(p, TASK_INTERRUPTIBLE);
> > +			}
> 
> I don't think this is enough. Note that recalc_sigpending() checks freezing().
> So a kernel thread still can get TIF_SIGPENDING if it does recalc_sigpending().

Yes, you're right, I have overlooked that.

Still, this can be prevented by changing recalc_sigpending_tsk() in the following way:

--- linux-2.6.22-rc4.orig/kernel/signal.c	2007-06-07 00:01:48.000000000 +0200
+++ linux-2.6.22-rc4/kernel/signal.c	2007-06-15 21:22:00.000000000 +0200
@@ -99,13 +99,13 @@ static inline int has_pending_signals(si
 static int recalc_sigpending_tsk(struct task_struct *t)
 {
 	if (t->signal->group_stop_count > 0 ||
-	    (freezing(t)) ||
 	    PENDING(&t->pending, &t->blocked) ||
 	    PENDING(&t->signal->shared_pending, &t->blocked)) {
 		set_tsk_thread_flag(t, TIF_SIGPENDING);
 		return 1;
 	}
-	clear_tsk_thread_flag(t, TIF_SIGPENDING);
+	if (!freezing(t))
+		clear_tsk_thread_flag(t, TIF_SIGPENDING);
 	return 0;
 }
 
> > --- linux-2.6.22-rc4-mm2.orig/include/linux/wait.h	2007-06-15 01:05:33.000000000 +0200
> > +++ linux-2.6.22-rc4-mm2/include/linux/wait.h	2007-06-15 01:05:41.000000000 +0200
> > @@ -240,7 +240,7 @@ do {									\
> >  		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
> >  		if (condition)						\
> >  			break;						\
> > -		if (!signal_pending(current)) {				\
> > +		if (!signal_pending(current) && !freezing(current)) {	\
> >  			schedule();					\
> >  			continue;					\
> >  		}							\
> 
> Personally, I think we should not modify wait_event_interruptible() and friends.
> If a kernel thread wants to be frozen, it should take care about freezing()
> itself.

Yes, I agree, but wanted to get a working patch quickly. ;-)

I think we might define freezer-friendly versions of wait_event_interruptible()
and friends in <linux/freezer.h>, like this:

+#define wait_event_interruptible_ff(wq, condition)			\
+({									\
+	int __ret = 0;							\
+	if (!(condition) && !freezing(current))				\
+		__wait_event_interruptible(wq, 				\
+				(condition) || freezing(current),	\
+				__ret);					\
+	if (!(condition) && freezing(current))				\
+		__ret = -ERESTARTSYS;					\
+	__ret;								\
+})

and make the freezable kernel threads use them instead of the ones defined
in <linux/wait.h>.  There are only a few threads that need that, BTW.
 
> OK, I guess I was too paranoid and you were right, it is better to ignore this
> minor problem for now.

Okay, but I still think we shouldn't send fake signals to kernel threads. :-)

I'd like to revisit it after 2.6.22 is out, if you don't mind.

Greetings,
Rafael


-- 
"Premature optimization is the root of all evil." - Donald Knuth

  reply	other threads:[~2007-06-15 21:41 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-06  5:47 [BUG] ptraced process waiting on syscall may return kernel internal errnos Satoru Takeuchi
2007-06-06 10:59 ` Roland McGrath
2007-06-06 15:35   ` Linus Torvalds
2007-06-06 23:07     ` Paul Mackerras
2007-06-07  3:25     ` Benjamin Herrenschmidt
2007-06-07  3:27     ` Benjamin Herrenschmidt
2007-06-07 11:33     ` Satoru Takeuchi
2007-06-07 15:54       ` Linus Torvalds
2007-06-07 22:24         ` Benjamin Herrenschmidt
2007-06-08  3:18           ` Linus Torvalds
2007-06-08  5:30             ` Benjamin Herrenschmidt
2007-06-11 22:16             ` Benjamin Herrenschmidt
2007-06-08  3:07         ` Satoru Takeuchi
2007-06-13 22:06     ` Roland McGrath
2007-06-07  3:20   ` Benjamin Herrenschmidt
2007-06-13 15:15   ` Oleg Nesterov
2007-06-13 22:36     ` Benjamin Herrenschmidt
2007-06-13 23:01       ` Roland McGrath
2007-06-13 23:18         ` Benjamin Herrenschmidt
2007-06-14  0:02           ` Roland McGrath
2007-06-13 22:53     ` Roland McGrath
2007-06-14 12:26     ` Rafael J. Wysocki
2007-06-14 12:58       ` Oleg Nesterov
2007-06-14 23:35         ` Rafael J. Wysocki
2007-06-15 11:31           ` Oleg Nesterov
2007-06-15 21:48             ` Rafael J. Wysocki [this message]
2007-06-15  0:06         ` Benjamin Herrenschmidt

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=200706152348.12019.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=akpm@linux-foundation.org \
    --cc=benh@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@tv-sign.ru \
    --cc=roland@redhat.com \
    --cc=takeuchi_satoru@jp.fujitsu.com \
    --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