LATX, fix: Preserve queued RCU callbacks across fork - #474
Open
LaurenIsACoder wants to merge 2 commits into
Open
LATX, fix: Preserve queued RCU callbacks across fork#474LaurenIsACoder wants to merge 2 commits into
LaurenIsACoder wants to merge 2 commits into
Conversation
The RCU consumer subtracts a batch from the pending count before waiting for its grace period. A fork during that wait inherits queued callbacks without their count, so the child can leave work pending or hang on drain. Concurrent enqueue can also expose incomplete links to the fork snapshot. Serialize enqueue, dequeue and count updates with the atfork queue lock. Decrement the count only when a callback is dequeued, and never hold the queue lock across callbacks, grace-period waits or worker creation. Retain the existing lazy and deferred child-worker startup policy. Callbacks already dispatched to a vanished thread are outside this queue contract. Add a native RCU fork regression covering held readers, child startup, reentrant callbacks and concurrent producers. The held-reader drain times out with the old accounting and passes with the fix. The original KZT branch passed 25 lat-pr-fast tests; unavailable guest integration tests were skipped. Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
LaurenIsACoder
force-pushed
the
latx-rcu-fork-queue
branch
from
September 8, 2026 03:51
97b51fa to
1856f4f
Compare
This was referenced Sep 8, 2026
The RCU queue fix affects all configurations, but its regression is only registered for LATX/KZT. Comparing completed totals across concurrent publication can also hide a lost callback when later callbacks compensate for it. Register the common fork regression on POSIX hosts and keep the held-reader scenario as a separate LATX/KZT invocation. Pause the common-case consumer inside an already-dispatched callback, outside the grace-period lock, so ordinary atfork locking can proceed while producer callbacks stay queued. Mark each callback published after call_rcu1() returns and require every published callback in the child snapshot to run exactly once after drain. Keep the executable out of the default build and document explicit runs. On LoongArch, the common KZT, non-KZT and non-LATX cases and the KZT held-reader case each passed 20 repetitions. Full lat-pr-fast suites passed 26/26 with KZT and 25/25 without it. Reversing the production fix reproduced the held-reader drain timeout. Tests-disabled registration and final product builds were also checked. Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
LaurenIsACoder
added a commit
to LaurenIsACoder/lat
that referenced
this pull request
Sep 8, 2026
Repeated public-loader dlopen/dlclose cycles leave stale ELF metadata in the context even after its guest mappings disappear. Freeing it immediately would invalidate metadata still borrowed by native frames or RCU readers. At a guest-execution safe point, scan under the mapping lock using a fresh loader snapshot and retire unowned metadata through RCU. Retain the main executable, attached libraries, malloc-backed borrowers, live link-map entries and ELFs with surviving load segments. Reuse vacant context slots without shifting other library indexes. Busy or stale snapshots and an exclusive-barrier timeout conservatively defer reclamation. Add lifecycle regressions for retained owners, snapshots, slot reuse and deferred destruction. The branch passed 26 lat-pr-fast tests and sanitizer checks. A 500-cycle libbz2 loader workload kept elfsize at 7; retaining a handle kept it at 8. This does not bound translation caches or establish full application memory stability; unavailable integration tests were skipped. Requires the queued-RCU fork fix in PR lat-opensource#474 before merging, so a child preserves inherited metadata retirements. Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
LaurenIsACoder
force-pushed
the
latx-rcu-fork-queue
branch
from
September 8, 2026 07:07
9eba600 to
8ef728a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope and invariant
Based on upstream
bfe17ae7c1. Pending RCU callbacks must stay represented by both complete queue links and the pending count when fork snapshots the process.Previously the consumer subtracted a batch before waiting for its grace period. A fork during that wait inherited queued nodes without the matching count; the child could leave them unprocessed or block a later drain. Concurrent producers could also be captured between queue-link updates.
Serialize enqueue/dequeue/count transitions with fork, decrement only when a node is actually dequeued, and preserve the child's queued work. The queue mutex is never held over a callback, grace-period wait or worker creation. Keep the existing lazy/deferred worker policy so namespace setup does not gain an unexpected helper thread.
Boundary: callbacks already dequeued into a vanished thread's stack are not replayed. Inherited queued callbacks start at the existing first-call/drain/explicit-deferred-start safe points; this is not a promise of immediate cleanup in an otherwise idle child.
Author self-review and combined validation
The actual published diffs were reviewed individually and checked against the local candidates. Follow-up corrections were folded into their existing commits; author/sign-off metadata updates preserved the per-PR source trees. The series remains six commits across #472, #473, #474, #475 and #476.
All five branches merge without conflicts on
bfe17ae7c1. The combined source tree80aaaaf13688387640f528d1c0bccb6a800f8d6ebuilds and passes 33/33 lat-pr-fast tests. On that combined binary, the 500-cycle KZT unload and retained-handle checks, 520-cycle SMC/fork checks, and 512 successful TSYNC operations alongside thread creation also complete successfully. A tests-disabled configuration registers no tests.The integration suite still reports 27 skips, including after selecting the available guest sysroot with
LATX_X86_64_SYSROOT: 25 require clang and two require the x86 cross compiler. These are not passes. This author self-review does not substitute for the upstream CI matrix, maintainer review or real-application acceptance.Validation
LoongArch64, GCC 15.3, x86_64-linux-user, LAT O1, KZT compiled in, release:
This is an independent infrastructure fix. The separate KZT unloaded-header reclamation PR must be merged after this one to preserve its queued retirements across fork. No runtime installation or application acceptance is included.