Skip to content

fix(driver,iour): don't read zerocopy notification results as errno - #1141

Open
lexoliu wants to merge 1 commit into
compio-rs:masterfrom
lexoliu:zc-notif-usage
Open

lexoliu wants to merge 1 commit into
compio-rs:masterfrom
lexoliu:zc-notif-usage

Conversation

@lexoliu

@lexoliu lexoliu commented Nov 11, 2026 •

Copy link
Copy Markdown

The res of a zerocopy notification isn't an errno. When the send sets IORING_SEND_ZC_REPORT_USAGE, the kernel puts IORING_NOTIF_USAGE_ZC_COPIED (1 << 31) there if it copied the data (uapi, v6.2, notif.c). create_result reads it as a negative errno and negates it (iour/mod.rs). -i32::MIN overflows, so a debug build panics and a release build returns an io::Error with a garbage code.

compio's own SendZc ops don't set the flag, but any OpCode that sets zc_flags to get the usage report runs into this. create_result now checks IORING_CQE_F_NOTIF first and returns the notification's res as u32. Extra::is_notification documents what that value holds.

The new test sends over loopback with REPORT_USAGE, where the kernel always copies, and checks that the notification reports the copy. On master it panics with "attempt to negate with overflow"; with this change it passes on Linux 6.18. It skips on kernels that reject the flag.

@github-actions github-actions Bot added bug Something isn't working driver: io-uring About the io-uring driver package: driver Related to compio-driver labels Nov 11, 2026
// The result of a zerocopy notification is a set of flags, not an
// errno: with `IORING_SEND_ZC_REPORT_USAGE` the kernel sets
// `IORING_NOTIF_USAGE_ZC_COPIED` (`1 << 31`) when the data was copied.
Ok(result as u32 as usize)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should clear the flag instead of a conversion.

//! A zerocopy notification reports its usage in the sign bit of `res`, which
//! must not be read as an errno.

#![cfg(all(io_uring, not(fusion)))]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also test fusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working driver: io-uring About the io-uring driver package: driver Related to compio-driver

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants