feat(virtq): add packed virtio ring primitives#1382
feat(virtq): add packed virtio ring primitives#1382andreiltd wants to merge 9 commits intohyperlight-dev:mainfrom
Conversation
3db3820 to
bd2fd96
Compare
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.
857f4bf to
2c6adcb
Compare
79ee809 to
141fc6b
Compare
141fc6b to
e27dacb
Compare
ludfjig
left a comment
There was a problem hiding this comment.
This PR is very clean, big fan!
I know we don't really have policy on asserts vs errors etc in hyperlight (I personally like asserts...), but ring.rs has 3 debug_assert! that could be useful in release mode as well, and they're already in methods that return Results. Do you think it makes sense to convert them to errros instead?
| desc.write_release(&self.mem, addr) | ||
| .map_err(|_| RingError::MemError)?; |
There was a problem hiding this comment.
nit: lot's of map_err lose their context when going to RingError::MemError, maybe can parametrize RingError<E> on generic E which is some M::Error? Not sure, feel free to ignore
There was a problem hiding this comment.
I tried this initially yes, and make it generic creates much more API churn especially for the layers on top of virtq. But let me think a bit more how we could preserve context without making ring error generic.
There was a problem hiding this comment.
I've added more context to the MemError variant:
#[error("Backend memory error while {op} at address 0x{addr:x}, len {len}")]
MemError {
/// Memory operation that failed.
op: MemOp,
/// Address passed to the memory backend.
addr: u64,
/// Number of bytes requested for the operation.
len: usize,
},I guess the alternative would be to use type erasure like Box<dyn Error> but that will require extra bounds on M::Error: Error + Send + Sync + 'static and will allocate on error path?
simongdavies
left a comment
There was a problem hiding this comment.
Great stuff a few minor comments but looks good to me
| avail == wrap && used == wrap | ||
| } | ||
|
|
||
| /// Is this descriptor writable by the device? |
There was a problem hiding this comment.
The comments here use the terms "guest" "host" and "device" and "driver" I read the HIP again at https://github.com/andreiltd/hyperlight/blob/tandr/rng-rfc/proposals/0001-rng-buf/README.md#design-details
but still wasn't sure how to interpret these terms here? The HIP suggests that the driver is always the guest and the device is always the host but then goes on to say that for bi-directional communication these roles are reversed , I think it might help us in the future to define explicitly what we are referring to in the code comments.
There was a problem hiding this comment.
Yes, HIP needs to be updated. Initial version of HIP assumed the roles are swapped depending on direction -- but that idea has been later discarded following allocation discussion in the heap. The most recent agreement is: driver - always a guest, device - always host. I also unified naming here so that it refers to virtio semantics so driver/device.
c384e6f to
6541fea
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>
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
6541fea to
519472d
Compare
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
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: