Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some io_uring additions #546

Merged
merged 1 commit into from
Feb 28, 2023

Conversation

jordanisaacs
Copy link
Contributor

A couple io_uring additions and an adjustment to io_uring_register.

io_uring_register can return positive values:

On success, io_uring_register(2) returns either 0 or a positive
value, depending on the opcode used. On error, a negative error
value is returned. The caller should not rely on the errno
variable.

sqe.ioprio takes in flags for certain operations so added a union for those (accept and send/recv)

Adds io_uring_recvmsg_out which outs recvmsg flags (see here)

__u32 flags; /* Flags result as would have been populated by recvmsg(2) */

src/io_uring.rs Outdated
impl Default for ioprio_or_flags_union {
#[inline]
fn default() -> Self {
let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
Copy link
Contributor

Choose a reason for hiding this comment

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

::zeroed() would be much clearer instead of the ptr write.

Copy link
Member

Choose a reason for hiding this comment

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

I believe the original idea for write_bytes in other places that do this is that zeroed() doesn't guarantee to write to any padding bytes, while write_bytes does. However, looking at it now, this doesn't seem like it should matter. This default() function still relies on Rust to move the value into the return value, which possibly doesn't guarantee to preserve padding bytes, in which case we could just as well use zeroed() instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like the UCG WG hasn't fully flushed out union semantics yet, but Ralf is leaning towards making it bag-o-bytes. Either way, zeroed can't leave padding bytes that are potentially used by one of the variants in an initialized state since it's a union and you don't know which variant will be used. If there are uninit padding bytes, they'd have to be unused by all variants (which seems like what currently happens: rust-lang/unsafe-code-guidelines#354 (comment))


I wonder if it's just better to return Self { flags: 0 }. You could argue that if the union is ever expanded, then it's remaining bytes will be uninitialized (I think) which is bad, but then again it's a union and you have no idea what variant it contains anyway. Also Linux can't change it's API so it seems pretty safe to just say flags: 0 and call it good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am more a fan of using ::mem::zeroed() as functionally it does the same thing as Self { ioprio: 0 } (note: changed the field name). But it won't break if the union is ever extended. As what sunfishcode said makes sense, changed this to be how all unions do the defaults.

I'm not sure if the padding bytes not being zeroed is an issue anyway. Only the unions that are fields of io_uring_sqe implement default. As those are going to be aligned correctly, I don't see why the kernel would be touching those uninit padding bytes. As zeroed() will zero the largest variant of the union.

@jordanisaacs jordanisaacs force-pushed the iouring-flags branch 2 times, most recently from 96b7de3 to afb7deb Compare February 28, 2023 17:23
@sunfishcode sunfishcode merged commit 59f7b71 into bytecodealliance:main Feb 28, 2023
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.

3 participants