You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tracking issue: Refactor driver with control API #741
Currently we make all OpCodes !Unpin and Pin it onto heap with Key so that buffers submitted into kernel stays at where they are. However when operations are finished, we take the OpCodes out and return them back to user, and this violates Pin contract. What's more, some ops contains self referential pointers, and those pointers will become dangling when the op is returned, even though we're not accessing those (for now). This doesn't cause any runtime error but conceptually it is unsound and undefined behavior MAY happen in future.
Yes. However, that's unavoidable. We use Pin because the OpCode stores the pointer to the buffer. We move the OpCode because we need to return the buffer to the user. If the buffer is !Unpin, we have to violate the Pin contract.
Other runtimes solve the problem by contraint the buffer to be !Unpin, but we implemented the buffer traits for arrays and ArrayVec for convenience.
@Berrysoft It's not just for buffers. We require ops to be able to self referential, and have stable addresses so that the kernel can reference them. One solution I can think of is to have two types, one for submitting (think of a builder) and one for running state, that can be converted freely from each other.
Pin is specifically targeted at allowing the implementation of safe interfaces around types which have some state during which they become “address-sensitive.” A value in such an “address-sensitive” state is not okay with being moved around at-will. Such a value must stay un-moved and valid during the address-sensitive portion of its lifespan because some interface is relying on those invariants to be true in order for its implementation to be sound.
I admit that there're some OpCodes are "address-sensitive" during being processed by the driver or kernel, but when they complete, they are not "address-sensitive". The self-referential pointers are not used anymore.
The only problem is that, according to the document,
...if an element of your type could have been pinned, you must treat Drop as implicitly taking self: Pin<&mut Self>.
I have tried the two-types solution, but failed. I would like to fallback to the solution that mark the requirements in the safety notes of OpCode: the type should not implement Drop, or if the author insists, the drop method should not access the address-sensitive portion.
An alternative suggestion: add a method clear_self_references to OpCode, and ensure that it'll be called before self being moved.
changed the title [-]Tracking issue: Refactor driver with control + carry API[/-][+]Tracking issue: Refactor driver with control API[/+]on Mar 27, 2026
Only a few ops need self-referential control, e.g., RecvFrom or SendTo on io-uring. It's acceptable to use Vec or Box currently, I think. I don't like to initialize with &mut MaybeUninit because it's too ugly to use. Alternatives:
Limit the control type to be valid when zeroed. We can then fill with a zeroed control.
Fill libc::msghdr on first calling to create_entry.
Another proposal: Maybe limit Control to be Default-only since most of the time Control will be (), and manually implement default for the rest using std::mem::zeroed().
Activity
Berrysoft commentedon Mar 7, 2026
Yes. However, that's unavoidable. We use
Pinbecause theOpCodestores the pointer to the buffer. We move theOpCodebecause we need to return the buffer to the user. If the buffer is!Unpin, we have to violate thePincontract.Other runtimes solve the problem by contraint the buffer to be
!Unpin, but we implemented the buffer traits for arrays andArrayVecfor convenience.George-Miao commentedon Mar 7, 2026
@Berrysoft It's not just for buffers. We require ops to be able to self referential, and have stable addresses so that the kernel can reference them. One solution I can think of is to have two types, one for submitting (think of a builder) and one for running state, that can be converted freely from each other.
Berrysoft commentedon Mar 7, 2026
Fair enough. Though it might be a big project.
Berrysoft commentedon Mar 7, 2026
@George-Miao I'm considering a smaller change. Still two types. One for running and one for return.
Berrysoft commentedon Mar 7, 2026
According to the document,
I admit that there're some
OpCodes are "address-sensitive" during being processed by the driver or kernel, but when they complete, they are not "address-sensitive". The self-referential pointers are not used anymore.The only problem is that, according to the document,
I have tried the two-types solution, but failed. I would like to fallback to the solution that mark the requirements in the safety notes of
OpCode: the type should not implementDrop, or if the author insists, thedropmethod should not access the address-sensitive portion.An alternative suggestion: add a method
clear_self_referencestoOpCode, and ensure that it'll be called beforeselfbeing moved.[-]compio-driver is internally unsound[/-][+]Tracking issue: Refactor driver with control + carry API[/+][-]Tracking issue: Refactor driver with control + carry API[/-][+]Tracking issue: Refactor driver with control API[/+]George-Miao commentedon Apr 1, 2026
There's some problem with the design: control may need to be self referential as well. We may need to let init take
&mut MaybeUninit<Control>George-Miao commentedon Apr 1, 2026
Also, there're still lots of ops with self-referential data that are not refactored to use Control API, need updating.
Berrysoft commentedon Apr 3, 2026
Only a few ops need self-referential control, e.g.,
RecvFromorSendToon io-uring. It's acceptable to useVecorBoxcurrently, I think. I don't like to initialize with&mut MaybeUninitbecause it's too ugly to use. Alternatives:libc::msghdron first calling tocreate_entry.George-Miao commentedon Apr 10, 2026
Another proposal: Maybe limit Control to be
Default-only since most of the timeControlwill be(), and manually implement default for the rest usingstd::mem::zeroed().Berrysoft commentedon Apr 10, 2026
I agree. That would be easier for
initto implement.