Skip to content

setup: make io_uring_ring_dontfork() cover rings on app memory - #1654

Open
Nexory wants to merge 2 commits into
axboe:masterfrom
Nexory:hunt/liburing-dontfork
Open

Nexory wants to merge 2 commits into
axboe:masterfrom
Nexory:hunt/liburing-dontfork

Conversation

@Nexory

@Nexory Nexory commented Oct 10, 2026

Copy link
Copy Markdown

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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant