Skip to content

Commit c092a05

Browse files
bulk update of docs related to virtio queue
This commit takes care of all outdated comments related to Queue/QueueState. Also, added a few lines about saving and restoring state. Signed-off-by: Andreea Florescu <[email protected]>
1 parent abdddd8 commit c092a05

File tree

5 files changed

+14
-40
lines changed

5 files changed

+14
-40
lines changed

crates/virtio-device/src/lib.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ pub mod status {
5656
pub const DEVICE_NEEDS_RESET: u8 = 64;
5757
}
5858

59-
// Adding a `M: GuestAddressSpace` generic type parameter here as well until we sort out the
60-
// current discussion about how a memory object/reference gets passed to a queue.
61-
// We might end up with the queue type as an associated type here in the future, if it makes
62-
// sense to define an interface for queues which abstracts away whether they are split or packed.
63-
// On the other hand, if we split the queue into a config/state part and a live part, then we'd
64-
// only need to work with the configuration here, and there's no need for generic type parameters
65-
// or associated types related to that.
66-
6759
// We're currently relying on macros from the `log` crate to output messages (as do other modules
6860
// from `vm-virtio`). This is temporary solution until we agree on a better alternative going
6961
// forward since different customers most likely have different expectation around levels,

crates/virtio-device/src/virtio_config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ where
190190

191191
impl<T> WithDriverSelect for T
192192
where
193-
// Added a `static bound here while `M` is around to simplify dealing with lifetimes.
194193
T: BorrowMut<VirtioConfig<Queue>> + VirtioDevice,
195194
{
196195
fn queue_select(&self) -> u16 {

crates/virtio-queue-ser/src/state.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,6 @@ pub struct QueueStateSer {
3131

3232
// The following `From` implementations can be used to convert from a `QueueStateSer` to the
3333
// `QueueState` from the base crate and vice versa.
34-
// WARNING: They don't check for any invalid data, that would otherwise be checked when initializing
35-
// a queue object from scratch (for example setting a queue size greater than its max possible
36-
// size). The problem with the current `QueueState` implementation is that it can be used as the
37-
// queue object itself. `QueueState`'s fields are public, which allows the user to set up and use an
38-
// invalid queue. Once we fix https://github.com/rust-vmm/vm-virtio/issues/143, `QueueState` will be
39-
// renamed to `Queue`, its fields will no longer be public, and `QueueState` will consist of the
40-
// actual state. This way we can also check against any invalid data when trying to get a `Queue`
41-
// from the state object.
42-
// Nevertheless, we don't make any assumptions in the virtio-queue code about the queue's state that
43-
// would otherwise result in a panic, when initialized with random data, so from this point of view
44-
// these conversions are safe to use.
4534
impl From<&QueueStateSer> for QueueState {
4635
fn from(state: &QueueStateSer) -> Self {
4736
QueueState {
@@ -121,11 +110,6 @@ mod tests {
121110
fn test_ser_with_len_zero() {
122111
// This is a regression test that tests that a queue where the size is set to 0 does not
123112
// cause any problems when poping the descriptor chain.
124-
//
125-
// In the future this should be updated such that the Queue does not have the fields as
126-
// public, and the way to obtain a Queue from a serialized Queue is by using a `try_from`
127-
// function which then makes sure that the deserialized values are valid before creating
128-
// a queue that might be invalid.
129113
let queue_ser = QueueStateSer {
130114
max_size: 16,
131115
next_avail: 0,

crates/virtio-queue/README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ format.
99
The purpose of the virtio-queue API is to be consumed by virtio device
1010
implementations (such as the block device or vsock device).
1111
The main abstraction is the `Queue`. The crate is also defining a state object
12-
for the queue, i.e. `QueueState`. The `Queue` objects are always created from a
13-
state (even if it’s an empty one) in order to avoid branching in the calling
14-
functions.
12+
for the queue, i.e. `QueueState`.
1513

1614
## Usage
1715

@@ -40,9 +38,7 @@ Each virtqueue consists of three parts:
4038

4139
Before booting the virtual machine (VM), the VMM does the following set up:
4240

43-
1. initialize an array of Queues based on a `max_size` and a reference to the
44-
memory object, by using `Queue::new(mem: M, max_size: u16)`, the queue
45-
objects are created from a default state.
41+
1. initialize an array of Queues using the Queue constructor.
4642
2. register the device to the MMIO bus, so that the driver can later send
4743
read/write requests from/to the MMIO space, some of those requests also set
4844
up the queues’ state.
@@ -135,17 +131,13 @@ of the next descriptor if VIRTQ_DESC_F_NEXT is set.
135131

136132
## Design
137133

138-
`QueueStateT` is a trait that allows different implementations for a `Queue`
134+
`QueueT` is a trait that allows different implementations for a `Queue`
139135
object for single-threaded context and multi-threaded context. The
140136
implementations provided in `virtio-queue` are:
141137

142-
1. `QueueState` → it is used for the single-threaded context, and keeps the
143-
state of a virtio queue.
144-
2. `QueueStateSync` → it is used for the multi-threaded context, and is simply
145-
a wrapper over an `Arc<Mutex<QueueState>>`.
146-
147-
`Queue` is a wrapper over a `QueueState` that also holds the guest memory
148-
object associated with the queue.
138+
1. `Queue` → it is used for the single-threaded context.
139+
2. `QueueSync` → it is used for the multi-threaded context, and is simply
140+
a wrapper over an `Arc<Mutex<Queue>>`.
149141

150142
Besides the above abstractions, the `virtio-queue` crate provides also the
151143
following ones:
@@ -159,6 +151,13 @@ following ones:
159151
* `AvailIter` - is a consuming iterator over all available descriptor chain
160152
heads in the queue.
161153

154+
## Save/Restore Queue
155+
156+
The `Queue` allows saving the state through the `state` function which returns
157+
a `QueueState`. `Queue` objects can be created from a previously saved state by
158+
using `QueueState::try_from`. The VMM should check for errors when restoring
159+
a `Queue` from a previously saved state.
160+
162161
### Notification suppression
163162

164163
A big part of the `virtio-queue` crate consists of the notification suppression

crates/virtio-queue/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub trait QueueGuard<'a> {
107107
/// provided for single-threaded context and multi-threaded context.
108108
///
109109
/// Using Higher-Rank Trait Bounds (HRTBs) to effectively define an associated type that has a
110-
/// lifetime parameter, without tagging the `QueueStateT` trait with a lifetime as well.
110+
/// lifetime parameter, without tagging the `QueueT` trait with a lifetime as well.
111111
pub trait QueueT: for<'a> QueueGuard<'a> {
112112
/// Construct an empty virtio queue state object with the given `max_size`.
113113
///

0 commit comments

Comments
 (0)