diff options
author | Jeremie Koenig <jk@jk.fr.eu.org> | 2019-12-29 17:59:55 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2019-12-29 18:32:49 +0100 |
commit | 653d74f12abea144219af00400ed1f1ac5dfa79f (patch) | |
tree | db3c4dcbecaad4b5e19b97193284682372c1d885 /sysdeps/mach/hurd/htl | |
parent | eb87a46c5630580d9556907dc8a61b298b462919 (diff) | |
download | glibc-653d74f12abea144219af00400ed1f1ac5dfa79f.tar.gz |
hurd: Global signal disposition
This adds _hurd_sigstate_set_global_rcv used by libpthread to enable
POSIX-confirming behavior of signals on a per-thread basis.
This also provides a sigstate destructor _hurd_sigstate_delete, and a
global process signal state, which needs to be locked and check when
global disposition is enabled, thus the addition of _hurd_sigstate_lock
_hurd_sigstate_actions _hurd_sigstate_pending _hurd_sigstate_unlock helpers.
This also updates all the glibc code accordingly.
This also drops support for get_int(INIT_SIGMASK), which did not make sense
any more since we do not have a single signal thread any more.
During fork/spawn, this also reinitializes the child global sigstate's
lock. That cures an issue that would very rarely cause a deadlock in the
child in fork, tries to unlock ss' critical section lock at the end of
fork. This will typically (always?) be observed in /bin/sh, which is not
surprising as that is the foremost caller of fork.
To reproduce an intermediate state, add an endless loop if
_hurd_global_sigstate is locked after __proc_dostop (cast through
volatile); that is, while still being in the fork's parent process.
When that triggers (use the libtool testsuite), the signal thread has
already locked ss (which is _hurd_global_sigstate), and is stuck at
hurdsig.c:685 in post_signal, trying to lock _hurd_siglock (which the
main thread already has locked and keeps locked until after
__task_create). This is the case that ss->thread == MACH_PORT_NULL, that
is, a global signal. In the main thread, between __proc_dostop and
__task_create is the __thread_abort call on the signal thread which would
abort any current kernel operation (but leave ss locked). Later in fork,
in the parent, when _hurd_siglock is unlocked in fork, the parent's
signal thread can proceed and will unlock eventually the global sigstate.
In the client, _hurd_siglock will likewise be unlocked, but the global
sigstate never will be, as the client's signal thread has been configured
to restart execution from _hurd_msgport_receive. Thus, when the child
tries to unlock ss' critical section lock at the end of fork, it will
first lock the global sigstate, will spin trying to lock it, which can
never be successful, and we get our deadlock.
Options seem to be:
* Move the locking of _hurd_siglock earlier in post_signal -- but that
may generally impact performance, if this locking isn't generally
needed anyway?
On the other hand, would it actually make sense to wait here until we
are not any longer in a critical section (which is meant to disable
signal delivery anyway (but not for preempted signals?))?
* Clear the global sigstate in the fork's child with the rationale that
we're anyway restarting the signal thread from a clean state. This
has now been implemented.
Why has this problem not been observed before Jérémie's patches? (Or has
it? Perhaps even more rarely?) In _S_msg_sig_post, the signal is now
posted to a *global receiver thread*, whereas previously it was posted to
the *designated signal-receiving thread*. The latter one was in a
critical section in fork, so didn't try to handle the signal until after
leaving the critical section? (Not completely analyzed and verified.)
Another question is what the signal is that is being received
during/around the time __proc_dostop executes.
Diffstat (limited to 'sysdeps/mach/hurd/htl')
-rw-r--r-- | sysdeps/mach/hurd/htl/pt-sigstate-destroy.c | 2 | ||||
-rw-r--r-- | sysdeps/mach/hurd/htl/pt-sigstate-init.c | 2 | ||||
-rw-r--r-- | sysdeps/mach/hurd/htl/pt-sigstate.c | 12 |
3 files changed, 13 insertions, 3 deletions
diff --git a/sysdeps/mach/hurd/htl/pt-sigstate-destroy.c b/sysdeps/mach/hurd/htl/pt-sigstate-destroy.c index 02868a03c5..c829f86234 100644 --- a/sysdeps/mach/hurd/htl/pt-sigstate-destroy.c +++ b/sysdeps/mach/hurd/htl/pt-sigstate-destroy.c @@ -17,10 +17,12 @@ <https://www.gnu.org/licenses/>. */ #include <pthread.h> +#include <hurd/signal.h> #include <pt-internal.h> void __pthread_sigstate_destroy (struct __pthread *thread) { + _hurd_sigstate_delete (thread->kernel_thread); } diff --git a/sysdeps/mach/hurd/htl/pt-sigstate-init.c b/sysdeps/mach/hurd/htl/pt-sigstate-init.c index 97bf0c3a78..951f909855 100644 --- a/sysdeps/mach/hurd/htl/pt-sigstate-init.c +++ b/sysdeps/mach/hurd/htl/pt-sigstate-init.c @@ -35,7 +35,7 @@ __pthread_sigstate_init (struct __pthread *thread) if (do_init_global) { struct hurd_sigstate *ss = _hurd_thread_sigstate (thread->kernel_thread); - (void) ss; + _hurd_sigstate_set_global_rcv (ss); } else if (__pthread_num_threads >= 2) do_init_global = 1; diff --git a/sysdeps/mach/hurd/htl/pt-sigstate.c b/sysdeps/mach/hurd/htl/pt-sigstate.c index 845152ee48..bc16629672 100644 --- a/sysdeps/mach/hurd/htl/pt-sigstate.c +++ b/sysdeps/mach/hurd/htl/pt-sigstate.c @@ -20,6 +20,7 @@ #include <assert.h> #include <signal.h> #include <hurd/signal.h> +#include <hurd/msg.h> #include <pt-internal.h> @@ -29,11 +30,12 @@ __pthread_sigstate (struct __pthread *thread, int how, { error_t err = 0; struct hurd_sigstate *ss; + sigset_t pending; ss = _hurd_thread_sigstate (thread->kernel_thread); assert (ss); - __spin_lock (&ss->lock); + _hurd_sigstate_lock (ss); if (oset != NULL) *oset = ss->blocked; @@ -64,7 +66,13 @@ __pthread_sigstate (struct __pthread *thread, int how, if (!err && clear_pending) __sigemptyset (&ss->pending); - __spin_unlock (&ss->lock); + pending = _hurd_sigstate_pending (ss) & ~ss->blocked; + _hurd_sigstate_unlock (ss); + + if (!err && pending) + /* Send a message to the signal thread so it + will wake up and check for pending signals. */ + __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ()); return err; } |