Repository navigation
Conversation
f600529 to
0c50f31
Compare
b64c226 to
b9adeab
Compare
b9adeab to
abd83d1
Compare
abd83d1 to
395ab18
Compare
24f6c25 to
cbaf6a8
Compare
cbaf6a8 to
a80eaec
Compare
a80eaec to
c26f5a7
Compare
c26f5a7 to
c2a9568
Compare
3772e83 to
66f95e6
Compare
51fd40c to
e7d21a1
Compare
Benchmark changes outside ±20%Compared Improvements
Workflow run · commit |
e7d21a1 to
bad319d
Compare
bad319d to
dfba2ee
Compare
There was a problem hiding this comment.
All reported issues were addressed across 9 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
dfba2ee to
850d08a
Compare
sys_wait4 and sys_waitid become wrappers around wait4_once and waitid_once, which hold the old bodies and their retries, and proc_send_guest_signal splits into proc_append_guest_signal, which writes the record, and the SIGUSR2 to the target. Nothing changes behavior; the next commit adds a drain after each wait and appends records without sending SIGUSR2 at once. check-eintr-contract.py follows the EINTR returns into wait4_once and waitid_once, and the comments that named sys_wait4 for code now in wait4_once name it.
850d08a to
053b1d2
Compare
053b1d2 to
da7ad9c
Compare
There was a problem hiding this comment.
All reported issues were addressed across 6 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
702159e to
c8f9879
Compare
There was a problem hiding this comment.
All reported issues were addressed across 8 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Linux discards a SIGCHLD at the child's exit when the parent ignores it there, under SIG_IGN or under SIG_DFL with SIGCHLD unblocked, so a handler that the parent installs later never runs for that child; a SIGCHLD that Linux keeps is pending before a wait returns the child. Here the parent decided when it drained the child's record, and that record could arrive after the wait. A handler installed after the exit, or after SIGCHLD was blocked, then ran for the child, and a handler could run after the wait had returned the child. Decide at the exit instead. Each process keeps a small mapped flag file whose word says whether a SIGCHLD that an exit generated now would be discarded, and rewrites it when its SIGCHLD action, a thread's SIGCHLD mask bit, a thread exit or a CLONE_VM child's reap changes that. The exiting child reads its parent's word, under the lifecycle registry lock or, when it cannot open the registry, without it, and marks its record discarded or kept. wait4 and waitid drain the records before they return a child, so a kept signal is pending by then. lmbench's lat_fs no longer sees a stale SIGCHLD between its phases. When SIG_IGN or SIG_DFL replaces the SIGCHLD action, rt_sigaction drains the parent's records first, for a record left undecided, then drops a pending SIGCHLD from every pending set, as do_sigaction does; a periodic POSIX timer whose SIGCHLD it drops fires again. The same call raises a drop count that the word carries. A kept record carries the count its child read, and the drain discards it when the count has changed since, so a child that read the word before the call and appends after it loses its SIGCHLD too. rt_sigaction reads the new action before it writes the old one, as Linux does. A failed open, ftruncate or mmap of the flag file is logged once and not retried. The drain returns at once when the transport is empty, and runs the reparent and auto-reap work a record asks for after it releases the transport lock, because an exiting child holds the lifecycle registry lock while it appends there. Every case of test-sigchld-after-wait, and case 7 of test-signal, passes on Linux 6.18 too. The decision still differs from Linux (read in kernel/signal.c and kernel/exit.c unless noted): it counts every thread's mask, a CLONE_VM child's until the reap and an exited thread's until its slot is released, where Linux reads the one thread the signal targets; it does not look at ptrace; a kept SIGCHLD is delivered under the disposition in force at the drain (a probe measured 5 of 5 rounds here, 0 of 5 on Linux 6.18); a kill from another process, and a record whose sender could not read the flag file, are decided at the drain; and a SIG_IGN or SIG_DFL drops a record still undrained even when SIGCHLD was unblocked at the exit, where Linux has already run the handler. Closes sysprog21#498 Closes sysprog21#536
sig_ignored (kernel/signal.c) decides a SIGCHLD sent with kill when it is generated: it is discarded under SIG_IGN or SIG_DFL, and kept while it is blocked, under SIG_IGN too. Here a kill from another process left its record for the drain to decide, so a handler that the target installed before the drain ran for a SIGCHLD that Linux had discarded. A kill, pidfd_send_signal or rt_sigqueueinfo that a process sent to itself was queued and decided at delivery, so it woke a signalfd for SIGCHLD, and a handler that another thread installed in between would run for it (by reading, not run). The flag file's word gains a bit for a kill. A kill from another process reads the target's word, as an exiting child reads its parent's, and marks its record discarded or kept with the drop count it read; a signal that a process sends itself is decided under sig_lock before it is queued. The killdfl and killchild late cases and the default kill cases of test-sigchld-after-wait pass on Linux 6.18 too. A process that has not republished yet, such as a fork child that has not changed its SIGCHLD action or mask, has no flag file, so a kill from another process to it is still decided at the drain, which rt_sigaction runs before it drops a pending SIGCHLD. A kill to a traced target with SIGCHLD unblocked, which sig_ignored keeps under SIG_IGN or SIG_DFL, is discarded here (by reading, not run).
c8f9879 to
d823f7e
Compare
| uint64_t rusage_gva) | ||
| { | ||
| int64_t rc = wait4_once(g, pid, status_gva, options, rusage_gva); | ||
| if (rc > 0 || rc == -LINUX_EFAULT || signal_sigchld_autoreap()) |
There was a problem hiding this comment.
Under auto-reap this drains on every return, WNOHANG included. A drain that reads a SIGCHLD record calls proc_autoreap_exited_children, whose host wait4(host_pid, &status, 0, &ru) blocks until the child's host process is gone. The exiting child appends its record before it runs proc_notify_reparent, which retries for up to 50 ms per live child it hands to the adopter. So waitpid(-1, NULL, WNOHANG) under SIG_IGN can stall for that long, where Linux returns ECHILD at once. The drain at the top of rt_sigaction does the same when the old action auto-reaps (SIG_IGN to SIG_DFL).
Before this change only the preempt thread paid for that host wait. When the drain runs on a syscall path, have its auto-reap use WNOHANG and leave a child whose host process has not exited yet to the preempt thread's drain.
Intent: Decide whether a SIGCHLD is discarded at the point where Linux decides it, at the child's exit or at a
kill, instead of when the parent later drains the child's record.Failure fixed: A child's SIGCHLD record can reach the parent after the wait that reaped the child, so a handler installed in between ran for that child. lmbench's lat_fs hung on this until the CI timeout (#498;
lat_fs -N 1 -s 1024in four loops beside ten busy processes timed out in 3 of 96 runs on upstream/main and 0 of 96 here). A handler installed after an unwaited exit or after blocking SIGCHLD also ran (#536), and so did one installed after akillunderSIG_DFL.This PR, in three commits:
wait4andwaitidbodies move intowait4_onceandwaitid_once, andproc_append_guest_signalis split out ofproc_send_guest_signal.SIG_IGN, orSIG_DFLwith no thread blocking it), whether one from akillwould be (SIG_IGNorSIG_DFL, with no thread blocking it), and how many timesrt_sigactionhas dropped pending SIGCHLD. The process rewrites the word when SIGCHLD's action or a thread's SIGCHLD mask bit changes, when a thread exits and when aCLONE_VMchild is reaped. Every fork writes it before the child can run.wait4andwaitiddrain the records before they return a child, so a kept SIGCHLD is pending when the wait returns.SIG_IGNorSIG_DFLfor SIGCHLD drains first, then drops pending SIGCHLD from every pending set asdo_sigactiondoes, and raises the drop count. The drain discards a kept record with an older count, which covers a child that read the word before the call and appended after it.rt_sigactionreads the new action before it writes the old one, as Linux does. A failedopen,ftruncateormmapof the flag file is logged once.killat the sender. A SIGCHLDkillfrom another process reads the target's word. Akill,pidfd_send_signalorrt_sigqueueinfothat a process sends itself is decided undersig_lockbefore it is queued.Three test-only knobs:
ELFUSE_SIGNAL_DRAIN_DELAY_USdelays each drain,ELFUSE_SIGCHLD_DECIDE_DELAY_USdelays an exiting child between its read and its append, andELFUSE_EXIT_SKIP_REGISTRY=1makes an exit skip the lifecycle registry.This replaces #505, which decided when the parent drained the record.
Verification: every case passes on elfuse and on Linux 6.18.63 (QEMU). The last column names each part whose removal, or a broken version, fails the matching cases in 10 of 10 rounds.
test-sigchld-after-wait, 17 casesWNOWAIT; blocked;SIG_IGNwhile blocked; #536; atgkillSIGCHLD, thenSIG_IGNorSIG_DFL; a periodic timer whose SIGCHLD is dropped;SIG_DFLand akillunderSIG_IGNkeep a blocked SIGCHLD; a SIGCHLD sent to itself four ways does not wake asignalfdSIG_DFL; the drop count; thekillrule; the decision before a self-sent signal is queuedtest-signalcase 7test-sigchld-late-drain, 13 cases, 250 ms drain delaySA_RESETHAND, after a thread exit, after aCLONE_VMreap, for an adopted child;ign,dfl,unblock;kill,killdfl,killchild;waitpid,waitidSA_RESETHAND, a thread exit or aCLONE_VMreap; the adopter's read; thekillread; the drain inrt_sigaction,wait4andwaitid; marking the record; the droptest-sigchld-exit-race, 3 cases, 300 ms decide delaytest-sigchld-exit-fallbackSIG_IGNwith SIGCHLD blockedCost, as the mean of 20000
sigactioncalls after one child has exited and of 300waitpidrounds, over three interleaved runs of each build:sigaction(SIGCHLD, SIG_DFL)overSIG_DFL, unblockedSIG_DFL, each call timed alonewaitpidof a child that has already exitedwaitpidMost of the added
sigactioncost is the drain'sstatof the empty transport: without that drain a call takes 0.84 to 1.23 us.make checkpasses (its BusyBoxnslookuplane skipped: no reachable nameserver).make test-matrix: 336 passed on elfuse-aarch64 and 310 on qemu-aarch64; the only failure is the Rosettaaudit-known-limitations, which fails on upstream/main too.Differences from Linux (by reading
kernel/signal.candkernel/exit.c, except where measured):CLONE_VMchild's mask counts until it is reaped, and an exited thread's until its slot is released, which can be afterpthread_joinreturns.SIG_DFLand from akillunderSIG_IGNorSIG_DFL.SIG_DFL, a handler installed before the drain runs (measured with a 300 ms decide delay: 5 of 5 rounds here, 0 of 5 on Linux 6.18). With SIGCHLD unblocked, aSIG_IGNorSIG_DFLinstalled before the drain drops a record whose handler Linux has already run.tgkill,tkill,rt_tgsigqueueinfo) is still decided at delivery, so underSIG_IGNorSIG_DFLit wakes asignalfd(measured: 6 of 6 combinations here, 0 of 6 on Linux 6.18). It is part of signal_queue keeps an ignored signal pending where Linux drops it #515.Not tested:
ftruncateormmapof the flag file (a failedopenwas run by hand: one log line, and a SIGCHLD block or unblock still took 0.82 us)wait4that returnsEFAULTand under auto-reapexecve, under the temporary masks ofppoll,pselect6andepoll_pwait, atrt_sigsuspendand at fault deliveryOlder than this PR: the stale-ppid race in reparent records (#539), and elfuse reaping a child that exited under an earlier handler when a handler replaces
SIG_IGN, where Linux keeps the zombie (#546; theigncase accepts either). A host signal that ends elfuse leaves its flag file behind, as it leaves the registry files (#548).Closes #498
Closes #536