From: Oleg Nesterov <oleg@redhat.com>
To: stephane eranian <eranian@googlemail.com>
Cc: Jamie Lokier <jamie@shareable.org>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
mingo@elte.hu, linux-kernel@vger.kernel.org, tglx@linutronix.de,
robert.richter@amd.com, paulus@samba.org, andi@firstfloor.org,
mpjohn@us.ibm.com, cel@us.ibm.com, cjashfor@us.ibm.com,
mucci@eecs.utk.edu, terpstra@eecs.utk.edu,
perfmon2-devel@lists.sourceforge.net,
mtk.manpages@googlemail.com, roland@redhat.com
Subject: Re: F_SETOWN_TID: F_SETOWN was thread-specific for a while
Date: Tue, 18 Aug 2009 13:45:33 +0200 [thread overview]
Message-ID: <20090818114533.GA32289@redhat.com> (raw)
In-Reply-To: <7c86c4470908171526j60add584qfc635ba91cd4df46@mail.gmail.com>
On 08/18, stephane eranian wrote:
>
> On Mon, Aug 17, 2009 at 7:16 PM, Oleg Nesterov<oleg@redhat.com> wrote:
> > Sorry for late reply...
> >
> > On 08/10, stephane eranian wrote:
> >>
> >> On Mon, Aug 10, 2009 at 7:03 PM, Oleg Nesterov<oleg@redhat.com> wrote:
> >> >
> >> > Not sure if it is safe to change the historical behaviour.
> >> >
> >> Don't need to change it.
> >
> > Good,
> >
> >> But for SIGIO, if you see SA_SIGINFO, then pass the si_fd.
> >
> > But this means we do change the behaviour ;) Confused.
> >
> I meant do not remove F_SETSIG and its side-effect on si_fd.
Ah, now I see what you meant.
> > In any case. We should not look at SA_SIGINFO at all. If sys_sigaction() was
> > called without SA_SIGINFO, then it doesn'matter if we send SEND_SIG_PRIV or
> > siginfo_t with the correct si_fd/etc.
> >
> What's the official role of SA_SIGINFO? Pass a siginfo struct?
>
> Does POSIX describe the rules governing the content of si_fd?
> Or is si_fd a Linux-ony extension in which case it goes with F_SETSIG.
Not sure I understand your concern...
OK. You suggest to pass siginfo_t with .si_fd/etc when we detect SA_SIGINFO.
But, in that case we can _always_ pass siginfo_t, regardless of SA_SIGINFO.
If the task has a signal handler and sigaction() was called without
SA_SIGINFO, then the handler must not look into *info (the second arg of
sigaction->sa_sigaction). And in fact, __setup_rt_frame() doesn't even
copy the info to the user-space:
if (ka->sa.sa_flags & SA_SIGINFO) {
if (copy_siginfo_to_user(&frame->info, info))
return -EFAULT;
}
OK? Or I missed something?
> > And again, this is even documented. The change is trivial but user-space
> > visible, it may confuse the (stupid) app which uses SIGIO + SA_SIGINFO
> > without F_SETSIG.
> >
> That would be an app that uses SIGINFO and fiddles with si_fd which has no
> defined content. What kind of app would that be?
The stupid app. But it is always unsafe to make the user-visible changes
without good reasons. Even when we fix the bug (and the current code is not
buggy) sometimes we have "this patch breaks my app or test-case!" reports.
If nothing else, we can break the test-case which simply does
void sigio_handler(int sig, siginfo_t *info, void *u)
{
assert(info->si_code == 0 && info->si_code = 0x80);
}
Once again: this is _documented_ !
And we can't set .si_fd = fd whithout changing .si_code, this will break
copy_siginfo_to_user().
Or. Suppose that some app does:
void io_handler(int sig, siginfo_t *info, void *u)
{
if ((info->si_code & __SI_MASK) != SI_POLL) {
// RT signal failed! sig MUST be == SIGIO
recover();
} else {
do_something(info->si_fd);
}
}
int main(void)
{
sigaction(SIGRTMIN, { SA_SIGINFO, io_handler });
sigaction(SIGIO, { SA_SIGINFO, io_handler });
...
}
This is correct. But if we change the current behaviour, this app won't
be able to detect the overflow.
> It would seem natural that in the siginfo passed to the handler of SIGIO, the
> file descriptor be passed by default. That is all I am trying to say here.
Completely agreed! I was always puzzled by send_sigio_to_task(). I was never
able to understand why it looks so strange.
So, I think it should be
static void send_sigio_to_task(struct task_struct *p,
struct fown_struct *fown,
int fd,
int reason)
{
siginfo_t si;
/*
* F_SETSIG can change ->signum lockless in parallel, make
* sure we read it once and use the same value throughout.
*/
int signum = ACCESS_ONCE(fown->signum) ?: SIGIO;
if (!sigio_perm(p, fown, signum))
return;
si.si_signo = signum;
si.si_errno = 0;
si.si_code = reason;
si.si_fd = fd;
/* Make sure we are called with one of the POLL_*
reasons, otherwise we could leak kernel stack into
userspace. */
BUG_ON((reason & __SI_MASK) != __SI_POLL);
if (reason - POLL_IN >= NSIGPOLL)
si.si_band = ~0L;
else
si.si_band = band_table[reason - POLL_IN];
/* Failure to queue an rt signal must be reported as SIGIO */
if (!group_send_sig_info(signum, &si, p))
group_send_sig_info(SIGIO, SEND_SIG_PRIV, p);
}
(except it should be on top of fcntl-add-f_etown_ex.patch).
This way, at least we don't break the "detect RT signal failed" above.
What do you think?
But let me repeat: I just can't convince myself we have a good reason
to change the strange, but carefully documented behaviour.
In case you agree with the code above, I can send the patch. But only
if I have a "good" changelog from you + your Signed-of-by in advance ;)
Otherwise, please feel free to send this/similar change yourself.
Oleg.
next prev parent reply other threads:[~2009-08-18 11:50 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-27 16:51 perf_counters issue with self-sampling threads stephane eranian
2009-07-27 16:56 ` Peter Zijlstra
2009-07-27 21:25 ` Andi Kleen
[not found] ` <7c86c4470907272213w2ee57080re50dd22a4d73a7e0@mail.gmail.com>
2009-07-28 8:51 ` stephane eranian
2009-07-28 8:56 ` Andi Kleen
2009-07-28 9:13 ` stephane eranian
2009-08-04 16:09 ` stephane eranian
2009-07-29 12:19 ` Peter Zijlstra
2009-07-29 12:37 ` stephane eranian
2009-07-29 12:46 ` Peter Zijlstra
2009-07-29 22:17 ` Oleg Nesterov
2009-07-30 11:31 ` Peter Zijlstra
2009-07-30 19:20 ` Oleg Nesterov
2009-07-30 20:00 ` Peter Zijlstra
2009-07-30 20:28 ` Oleg Nesterov
2009-07-30 21:09 ` stephane eranian
2009-07-31 8:35 ` [RFC][PATCH] fcntl: F_[SG]ETOWN_TID Peter Zijlstra
2009-07-31 14:01 ` stephane eranian
2009-07-31 20:52 ` Oleg Nesterov
2009-07-31 21:11 ` Andrew Morton
2009-08-01 1:27 ` [PATCH 0/2] send_sigio/do_send_sig_info (Was: [RFC][PATCH] fcntl: F_[SG]ETOWN_TID) Oleg Nesterov
2009-08-03 15:48 ` [PATCH 3/2] fcntl: F_[SG]ETOWN_TID Peter Zijlstra
2009-08-03 17:16 ` Oleg Nesterov
2009-08-03 17:47 ` Peter Zijlstra
2009-08-03 18:06 ` Oleg Nesterov
2009-08-03 18:36 ` Peter Zijlstra
2009-08-03 19:02 ` Oleg Nesterov
2009-08-04 11:39 ` [PATCH 3/2 -v3] fcntl: F_[SG]ETOWN_EX Peter Zijlstra
2009-08-04 16:20 ` Oleg Nesterov
2009-08-04 16:52 ` Peter Zijlstra
2009-08-04 17:19 ` Oleg Nesterov
2009-08-06 13:14 ` [PATCH 3/2 -v4] " Peter Zijlstra
2009-08-06 19:05 ` Oleg Nesterov
2009-08-07 12:10 ` stephane eranian
2009-08-01 1:28 ` [PATCH 1/2] signals: introduce do_send_sig_info() helper Oleg Nesterov
2009-08-01 1:28 ` [PATCH 2/2] signals: send_sigio: use do_send_sig_info() to avoid check_kill_permission() Oleg Nesterov
2009-08-03 12:53 ` [RFC][PATCH] fcntl: F_[SG]ETOWN_TID stephane eranian
2009-08-09 5:46 ` F_SETOWN_TID: F_SETOWN was thread-specific for a while Jamie Lokier
2009-08-10 12:22 ` stephane eranian
2009-08-10 17:03 ` Oleg Nesterov
2009-08-10 21:01 ` stephane eranian
2009-08-17 17:16 ` Oleg Nesterov
2009-08-17 17:40 ` Oleg Nesterov
2009-08-17 22:26 ` stephane eranian
2009-08-18 11:45 ` Oleg Nesterov [this message]
2009-08-20 10:00 ` stephane eranian
2009-08-11 13:10 ` Jamie Lokier
2009-08-17 17:05 ` Oleg Nesterov
2009-08-03 15:21 ` [RFC][PATCH] fcntl: F_[SG]ETOWN_TID 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=20090818114533.GA32289@redhat.com \
--to=oleg@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=cel@us.ibm.com \
--cc=cjashfor@us.ibm.com \
--cc=eranian@googlemail.com \
--cc=jamie@shareable.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mpjohn@us.ibm.com \
--cc=mtk.manpages@googlemail.com \
--cc=mucci@eecs.utk.edu \
--cc=paulus@samba.org \
--cc=perfmon2-devel@lists.sourceforge.net \
--cc=robert.richter@amd.com \
--cc=roland@redhat.com \
--cc=terpstra@eecs.utk.edu \
--cc=tglx@linutronix.de \
/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