signal: Add calculate_sigpending()
Quoted 58 lines · <[email protected]> writes:
Quoted 18 lines · EricW.Biederman
Add a function
calculate_sigpendingto test to see if any signals are pending for a new task immediately following fork. Signals have to happen either before or after fork. Today our practice is to push all of the signals to before the fork, but that has the downside that frequent or periodic signals can make fork take much much longer than normal or prevent fork from completing entirely.+
calculate_sigpending();
}
/*kernel/signal.c +1
-0@@ -172,6 +172,17 @@ void recalc_sigpending(void) } +void calculate_sigpending (void )kernel/signal.c void recalc_sigpending(void) · line 183
Quoted 10 lines
kernel/signal.c +10
-0+{ +/* Have any signals or users of TIF_SIGPENDING been delayed +* until after fork? +*/ +spin_lock_irq (¤t->sighand->siglock); +set_tsk_thread_flag (current,TIF_SIGPENDING ); +recalc_sigpending (); +spin_unlock_irq (¤t->sighand->siglock); +} +The new function
calculate_sigpendingis similar torecalc_sigpending, butrecalc_sigpendinghas nospin_lock_irq(¤t->sighand->siglock)in it. This givesrecalc_sigpendingmore flexibility,
we may usespin_lock_irqorspin_lock_irqsavebeforerecalc_sigpending. eg:static int autofs4_write(struct
autofs_sb_info*sbi,
struct file *file, const void *addr, int bytes)
{
...spin_lock_irqsave(¤t->sighand->siglock, flags); sigdelset(¤t->pending.signal, SIGPIPE); recalc_sigpending(); spin_unlock_irqrestore(¤t->sighand->siglock, flags);...
}or:
voidkernel_sigaction(int sig, __sighandler_t action){ spin_lock_irq(¤t->sighand->siglock); ... recalc_sigpending(); ... spin_unlock_irq(¤t->sighand->siglock); }
Quoted 1 line
But
calculate_sigpendingis currently hardwired to callspin_lock_irq.
calculate_sigpending really only exists to keep the code comprehensible.
It is only ever expected to be called in exactly one place so the lack of flexibility should not be a problem. Further the use of irqsave is discouraged unless it is necessary.
The irqsave in autofs_write actually looks like a misfeature. We take a mutex a few lines earlier, so we know that irqs are enabled. Saving and restoring them is uncessary work. Further unless I am missing something that code path should be calling kernel_dequeue_signal, to ensure that any siginfo associated with that SIGPIPE gets dequeued.
Eric