hermit-os / kernel

A Rust-based, lightweight unikernel.
http://hermit-os.org
Apache License 2.0
1.16k stars 85 forks source link

virtq: don't expose TransferTokens to the drivers #1298

Closed cagatay-y closed 2 months ago

cagatay-y commented 3 months ago

TransferTokens carry the control descriptor that represents the indirect descriptor table in them, which is not of the same type for split queues and packed queues. This type difference is currently hidden behind the type erasing MemDescr type, but when we change the structure to use the actual type for it, we will need to make TransferToken generic. An actually typed TransferToken would not work for driver code that decides the type of queue to use at runtime, as we cannot make a boxed slice (which control descriptors represent) work with dynamically-sized elements.

Furthermore, TransferTokens are tied to a particular type of queue, as it would be an error to dispatch a TransferToken that has a control descriptor that is suitable for a PackedVq through a SplitVq. To ensure dispatch through the correct type of queue, BufferTokens are created through queues and have a reference to the queue that created them, which forces the use of Rc, when a regular Box would likely suffice.

cagatay-y commented 3 months ago

There is a lot of code that has been moved in the PR. I highly recommend the VS Code extension Semantic Diff to show moved blocks (I didn't have much luck with the experimental "Show Moves" option in VS Code), particularly with the option "Compare Moved Code".

cagatay-y commented 3 months ago

The commit failed yesterday when I was testing something else. I am making the PR a draft until I figure out what the problem is.