feat(virtq): add packed virtio ring primitives#1382
feat(virtq): add packed virtio ring primitives#1382andreiltd wants to merge 1 commit intohyperlight-dev:mainfrom
Conversation
3db3820 to
bd2fd96
Compare
bd2fd96 to
b4c8142
Compare
Add low-level packed virtqueue ring implementation in hyperlight_common::virtq, based on the virtio packed ring format. Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
b4c8142 to
16de50c
Compare
dblnz
left a comment
There was a problem hiding this comment.
Great stuff, @andreiltd !
I left a few comments, most are small remarks, others are things I might have missed.
This is part 1 of my review, I still have some things left to look at that I plan on doing tomorrow.
| /// | ||
| /// # Safety | ||
| /// | ||
| /// The caller must ensure `paddr` is valid and points to at least `dst.len()` bytes. |
There was a problem hiding this comment.
Nit:
| /// The caller must ensure `paddr` is valid and points to at least `dst.len()` bytes. | |
| /// The caller must ensure `addr` is valid and points to at least `dst.len()` bytes. |
| /// | ||
| /// # Safety | ||
| /// | ||
| /// The caller must ensure `paddr` is valid and points to at least `src.len()` bytes. |
There was a problem hiding this comment.
Nit:
| /// The caller must ensure `paddr` is valid and points to at least `src.len()` bytes. | |
| /// The caller must ensure `addr` is valid and points to at least `src.len()` bytes. |
| /// | ||
| /// # Invariant | ||
| /// | ||
| /// The caller must ensure that `base` is valid for writes of Descriptor |
There was a problem hiding this comment.
I think base has been renamed
| /// | ||
| /// # Safety | ||
| /// | ||
| /// - `base` must be valid for reads and writes of `size` descriptors |
There was a problem hiding this comment.
| /// - `base` must be valid for reads and writes of `size` descriptors | |
| /// - `base_addr` must be valid for reads and writes of `size` descriptors |
| /// # Safety | ||
| /// | ||
| /// - `base` must be valid for reads and writes of `size` descriptors | ||
| /// - `base` must be properly aligned for `Descriptor` |
There was a problem hiding this comment.
| /// - `base` must be properly aligned for `Descriptor` | |
| /// - `base_addr` must be properly aligned for `Descriptor` |
| #[derive(Clone, Copy, Debug, Pod, Zeroable, PartialEq, Eq, Hash)] | ||
| pub struct EventSuppression { | ||
| // bits 0-14: offset, bit 15: wrap | ||
| pub off_wrap: u16, |
There was a problem hiding this comment.
Are the fields necessary to be pub? Is the logic using it outside of hyperlight_common?
There was a problem hiding this comment.
Do all these defined types need to be pub?
| /// and readable buffers must be added before writable buffers. | ||
| #[derive(Debug, Default)] | ||
| pub struct BufferChainBuilder<T> { | ||
| elems: SmallVec<[BufferElement; 16]>, |
There was a problem hiding this comment.
Maybe documenting this 16 inline capacity as an optimization for the user to be aware
|
|
||
| /// Advance to next position, wrapping around and toggling wrap counter if needed | ||
| #[inline] | ||
| pub(crate) fn advance(&mut self) { |
There was a problem hiding this comment.
Could this be called concurrently on the host?
|
|
||
| /// Advance by n positions using modular arithmetic. | ||
| #[inline] | ||
| pub(crate) fn advance_by(&mut self, n: u16) { |
There was a problem hiding this comment.
Nit: Maybe have advance be advance_by(1)
Add low-level packed virtqueue ring implementation in
hyperlight_common::virtq, based on the virtio packed ring format.This is split from: #1368 and does not include any actual plumbing for guest/host communication.
Useful materials: