Skip to content

Conversation

@Brian-Perkins
Copy link
Contributor

In preparation for adding the packed queue type, update how work is fetched and completed from a queue. Additionally, isolate split queue specific logic.

…ents

Move split queue logic into specific split queue implementations.
@Brian-Perkins Brian-Perkins requested a review from a team as a code owner January 23, 2026 22:36
Copilot AI review requested due to automatic review settings January 23, 2026 22:36
@github-actions github-actions bot added the unsafe Related to unsafe code label Jan 23, 2026
@github-actions
Copy link

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the virtio queue implementation to separate work fetching (reading from available ring) from work completion (writing to used ring), preparing the codebase for future packed queue support. The refactoring isolates split queue-specific logic and introduces cleaner abstractions.

Changes:

  • Split QueueCore into QueueCoreGetWork and QueueCoreCompleteWork to separate read and write operations
  • Introduced QueueWork, QueueCompletionContext, and QueueDescriptor types to encapsulate queue work and completion state
  • Renamed Descriptor to SplitDescriptor to distinguish split queue format from future packed queue format
  • Added power-of-2 validation for queue sizes and added VIRTIO_F_VERSION_1 feature flag support
  • Updated tests to use valid queue sizes (changed from 5 to 8 to satisfy power-of-2 requirement)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
vm/devices/virtio/virtio/src/queue.rs Core refactoring: split queue operations into get/complete, added new types, isolated split queue logic
vm/devices/virtio/virtio/src/common.rs Updated to use new split queue APIs, modified work completion flow
vm/devices/virtio/virtio/src/spec.rs Renamed Descriptor to SplitDescriptor for clarity
vm/devices/virtio/virtio/src/tests.rs Added indirect descriptor feature flag, fixed queue sizes to be power-of-2

Comment on lines +48 to +53
pub struct QueueDescriptor {
address: u64,
length: u32,
flags: DescriptorFlags,
next: Option<u16>,
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

QueueDescriptor is marked as pub but has all private fields and no public methods, making it an opaque type from outside the module. Since it's only used internally and converted to VirtioQueuePayload for external use, it should be marked pub(crate) instead of pub to clarify that it's an internal type not intended for external use.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

clippy disagrees

Ok((get_work, complete_work))
}

pub struct SplitQueueCompletionContext {
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

SplitQueueCompletionContext is marked as pub but is only used internally within the queue module (accessed via pattern matching in QueueCoreCompleteWork::complete_descriptor). It should be marked pub(crate) to indicate that it's an internal implementation detail not intended for external use.

Suggested change
pub struct SplitQueueCompletionContext {
pub(crate) struct SplitQueueCompletionContext {

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

clippy disagrees

@github-actions
Copy link

@Brian-Perkins
Copy link
Contributor Author

The unsafe blocks are in the tests.rs module so not part of production.

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

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant