Skip to content

Tracking issue: Refactor driver with control API #741

Closed

Description

@George-Miao

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.

Tracking:

Activity

  1. added theissue type on Mar 6, 2026
  2. Berrysoft commented on Mar 7, 2026

    @Berrysoft
    Member

    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.

  3. George-Miao commented on Mar 7, 2026

    @George-Miao
    MemberAuthor

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

  4. Berrysoft commented on Mar 7, 2026

    @Berrysoft
    Member

    Fair enough. Though it might be a big project.

  5. Berrysoft commented on Mar 7, 2026

    @Berrysoft
    Member

    @George-Miao I'm considering a smaller change. Still two types. One for running and one for return.

  6. Berrysoft commented on Mar 7, 2026

    @Berrysoft
    Member

    According to the document,

    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.

  7. added this to the v0.19 milestone on Mar 11, 2026
  8. pinned this issue on Mar 25, 2026
  9. unpinned this issue on Mar 25, 2026
  10. changed the title [-]compio-driver is internally unsound[/-] [+]Tracking issue: Refactor driver with control + carry API[/+] on Mar 27, 2026
  11. changed the title [-]Tracking issue: Refactor driver with control + carry API[/-] [+]Tracking issue: Refactor driver with control API[/+] on Mar 27, 2026
  12. George-Miao commented on Apr 1, 2026

    @George-Miao
    MemberAuthor

    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>

  13. George-Miao commented on Apr 1, 2026

    @George-Miao
    MemberAuthor

    Also, there're still lots of ops with self-referential data that are not refactored to use Control API, need updating.

  14. Berrysoft commented on Apr 3, 2026

    @Berrysoft
    Member

    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.
  15. George-Miao commented on Apr 10, 2026

    @George-Miao
    MemberAuthor

    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().

  16. Berrysoft commented on Apr 10, 2026

    @Berrysoft
    Member

    I agree. That would be easier for init to implement.

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

Metadata

Metadata

Labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions