Skip to content

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

Open
lexoliu wants to merge 2 commits into
compio-rs:masterfrom
lexoliu:zc-notif-usage
Open

lexoliu wants to merge 2 commits into
compio-rs:masterfrom
lexoliu:zc-notif-usage

Conversation

@lexoliu

@lexoliu lexoliu commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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_entry now clears IORING_NOTIF_USAGE_ZC_COPIED from the res of a notification (IORING_CQE_F_NOTIF), so it completes with Ok(0), and passes the bit on as Extra::zc_copied().

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. It also runs on the fusion driver.

@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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, clearing the bit is much cleaner. The notification now just completes with Ok(0), and whether the data was copied shows up as Extra::zc_copied().

//! 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a fusion run to the test now.

The driver now clears IORING_NOTIF_USAGE_ZC_COPIED from the res of a
zerocopy notification, so the result is Ok(0) like any other success,
and reports the flag through Extra::zc_copied. The test also runs on
the fusion driver.
@Berrysoft

Copy link
Copy Markdown
Member

The idea is good, but the code tastes... @George-Miao would you have a look?

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