Skip to content

feat(virtq): add packed virtio ring primitives#1382

Open
andreiltd wants to merge 1 commit intohyperlight-dev:mainfrom
andreiltd:tandr/virtq-1-ring
Open

feat(virtq): add packed virtio ring primitives#1382
andreiltd wants to merge 1 commit intohyperlight-dev:mainfrom
andreiltd:tandr/virtq-1-ring

Conversation

@andreiltd
Copy link
Copy Markdown
Member

@andreiltd andreiltd commented Apr 16, 2026

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:

@andreiltd andreiltd force-pushed the tandr/virtq-1-ring branch from 3db3820 to bd2fd96 Compare April 16, 2026 10:20
@andreiltd andreiltd added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Apr 16, 2026
@andreiltd andreiltd force-pushed the tandr/virtq-1-ring branch from bd2fd96 to b4c8142 Compare April 16, 2026 10:23
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>
@andreiltd andreiltd force-pushed the tandr/virtq-1-ring branch from b4c8142 to 16de50c Compare April 16, 2026 10:30
Copy link
Copy Markdown
Contributor

@dblnz dblnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
/// 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
/// 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think base has been renamed

///
/// # Safety
///
/// - `base` must be valid for reads and writes of `size` descriptors
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// - `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`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// - `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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the fields necessary to be pub? Is the logic using it outside of hyperlight_common?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe have advance be advance_by(1)

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

Labels

kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants