virtio: Port codebase to the latest virtio-queue version

The new virtio-queue version introduced some breaking changes which need
to be addressed so that Cloud Hypervisor can still work with this
version.

The most important change is about removing a handle to the guest memory
from the Queue, meaning the caller has to provide the guest memory
handle for multiple methods from the QueueT trait.

One interesting aspect is that QueueT has been widely extended to
provide every getter and setter we need to access and update the Queue
structure without having direct access to its internal fields.

This patch ports all the virtio and vhost-user devices to this new crate
definition. It also updates both vhost-user-block and vhost-user-net
backends based on the updated vhost-user-backend crate. It also updates
the fuzz directory.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2022-07-06 16:08:08 +02:00
committed by Rob Bradford
parent 7199119bb2
commit a423bf13ad
41 changed files with 414 additions and 354 deletions
+12 -8
View File
@@ -21,16 +21,17 @@ use std::fmt::{self, Display};
use std::fs::File;
use std::io;
use std::mem::size_of;
use std::ops::Deref;
use std::os::unix::io::AsRawFd;
use std::result;
use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Barrier};
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_queue::{DescriptorChain, Queue};
use virtio_queue::{DescriptorChain, Queue, QueueOwnedT, QueueT};
use vm_memory::{
Address, ByteValued, Bytes, GuestAddress, GuestMemoryAtomic, GuestMemoryError,
GuestMemoryLoadGuard,
Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic,
GuestMemoryError, GuestMemoryLoadGuard,
};
use vm_migration::VersionMapped;
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
@@ -165,7 +166,8 @@ impl Request {
}
struct PmemEpollHandler {
queue: Queue<GuestMemoryAtomic<GuestMemoryMmap>>,
mem: GuestMemoryAtomic<GuestMemoryMmap>,
queue: Queue,
disk: File,
interrupt_cb: Arc<dyn VirtioInterrupt>,
queue_evt: EventFd,
@@ -178,7 +180,7 @@ impl PmemEpollHandler {
fn process_queue(&mut self) -> bool {
let mut used_desc_heads = [(0, 0); QUEUE_SIZE as usize];
let mut used_count = 0;
for mut desc_chain in self.queue.iter().unwrap() {
for mut desc_chain in self.queue.iter(self.mem.memory()).unwrap() {
let len = match Request::parse(&mut desc_chain, self.access_platform.as_ref()) {
Ok(ref req) if (req.type_ == RequestType::Flush) => {
let status_code = match self.disk.sync_all() {
@@ -213,8 +215,9 @@ impl PmemEpollHandler {
used_count += 1;
}
let mem = self.mem.memory();
for &(desc_index, len) in &used_desc_heads[..used_count] {
self.queue.add_used(desc_index, len).unwrap();
self.queue.add_used(mem.deref(), desc_index, len).unwrap();
}
used_count > 0
}
@@ -377,9 +380,9 @@ impl VirtioDevice for Pmem {
fn activate(
&mut self,
_mem: GuestMemoryAtomic<GuestMemoryMmap>,
mem: GuestMemoryAtomic<GuestMemoryMmap>,
interrupt_cb: Arc<dyn VirtioInterrupt>,
mut queues: Vec<(usize, Queue<GuestMemoryAtomic<GuestMemoryMmap>>, EventFd)>,
mut queues: Vec<(usize, Queue, EventFd)>,
) -> ActivateResult {
self.common.activate(&queues, &interrupt_cb)?;
let (kill_evt, pause_evt) = self.common.dup_eventfds();
@@ -392,6 +395,7 @@ impl VirtioDevice for Pmem {
let (_, queue, queue_evt) = queues.remove(0);
let mut handler = PmemEpollHandler {
mem,
queue,
disk,
interrupt_cb,