Repository navigation
Conversation
For a ring set up on application provided memory with io_uring_queue_init_mem(), io_uring_alloc_huge() sets sq->ring_sz and cq->ring_sz to 0, as io_uring_unmap_rings() uses them to tell whether the library owns the mapping. io_uring_ring_dontfork() reads the same fields as the length passed to madvise(), so for such a ring the call for the SQ/CQ ring region has a length of 0. It succeeds without effect, and io_uring_ring_dontfork() returns 0 although only the SQE region got MADV_DONTFORK. Derive the length of the ring region from the ring state when the field is 0, the same way io_uring_sqes_size() already does for the SQE region. Signed-off-by: Nexory <St4yl3r30@hotmail.de>
Check that io_uring_ring_dontfork() keeps both the SQE region and the SQ/CQ ring region from a child after fork(), for a ring from io_uring_queue_init() and for one on application provided memory from io_uring_queue_init_mem(). Signed-off-by: Nexory <St4yl3r30@hotmail.de>
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.
As discussed by mail, here is the fix as a pull request.
For a ring set up with io_uring_queue_init_mem(), io_uring_alloc_huge() sets sq->ring_sz and cq->ring_sz to 0, because io_uring_unmap_rings() uses them to tell whether the library owns the mapping. io_uring_ring_dontfork() reads the same fields as the madvise() length, so for such a ring it applies MADV_DONTFORK to the SQE region only and still returns 0.
The first commit derives the length of the ring region from the ring state when the field is 0, the same way io_uring_sqes_size() does for the SQEs. The second adds test/ring-dontfork-mem.c, which checks a ring from io_uring_queue_init() and one from io_uring_queue_init_mem(). Without the fix the test fails with "queue_init_mem: sq/cq ring still readable in child"; with it, the test passes.
make runtests passes with and without the change here, on a 6.12.111 kernel, with five tests excluded that also fail on an unchanged tree in my container. Building with the CI flags (-Wall -Wextra -Werror) adds no new errors with gcc 14 or clang 19.