Re: [RESEND] [RFC][PATCH X86_32 1/2]: Call do_notify_resume() withinterrupts enabled

From: Russell King
Date: Wed Oct 26 2011 - 11:20:09 EST


On Wed, Oct 26, 2011 at 02:38:39PM +0200, Linus Torvalds wrote:
> Ingo, Thomas, I think this is your call, but it seems valid,

Hi Linus,

I guess I should've talked to you about this during a moment during the
kernel summit, but as I'm now back home it'll have to be email.

I've been toying with a similar patch for ARM, but I keep feeling uneasy
about having interrupts enabled in this path (even though they get enabled
in the depths of the signal handling code.)

I worry about are race condition like the following:

syscall enter
...
syscall returns -ERESTARTNOHAND
check for signal
signal pending, but no handler, setup for restart
interrupt happens, sets need_resched
need_resched set
switch to another thread
...
something happens which queues SIGIO
switch back to this thread
check for signal
signal pending, has handler, but we've setup for a restart
return to userspace
run SIGIO handler
restart syscall

This feels like it violates the expectations of the syscall being
restarted - which explicitly asks to be restarted only if there wasn't
a handler run.

I've been working on the assumption that this is a problem and we should
do something about it - but it's non-trivial to solve all the corner cases.
We can do a lot better with the restarting if we delay setting up for a
restart until either we setup the user stack for the sig handler or
immediately before returning to userspace (with a TIF flag.)

If you're interested in seeing where I got to, the patch is available at:
https://lkml.org/lkml/2011/8/25/231

However, that doesn't solve the (probably unsolvable) case where an
ERESTARTSYS syscall is interrupted by a SA_RESTART-marked handler, and
while that handler is running it is then interrupted by a non-SA_RESTART-
marked handler. I think that is far too an obscure case to care about
though.

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of:
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/