mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 20:48:55 +00:00
vmm_vhost: use base::Event in place of EventFd
Use the cross-platform base::Event type to replace the Linux-specific base::EventFd. BUG=b:221882601 BUG=b:219522861 TEST=tools/presubmit Change-Id: I0503c130306b508af9dd5044653408bd316c7ef1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3533618 Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
parent
c286772db8
commit
445fd4d3f8
6 changed files with 60 additions and 69 deletions
|
@ -122,8 +122,8 @@ impl VvuDevice {
|
|||
}
|
||||
|
||||
impl VfioDeviceTrait for VvuDevice {
|
||||
fn event(&self) -> &base::EventFd {
|
||||
&self.rxq_evt.0
|
||||
fn event(&self) -> &Event {
|
||||
&self.rxq_evt
|
||||
}
|
||||
|
||||
fn start(&mut self) -> Result<()> {
|
||||
|
|
81
third_party/vmm_vhost/src/backend.rs
vendored
81
third_party/vmm_vhost/src/backend.rs
vendored
|
@ -13,8 +13,7 @@ use base::{RawDescriptor, INVALID_DESCRIPTOR};
|
|||
use std::cell::RefCell;
|
||||
use std::sync::RwLock;
|
||||
|
||||
// TODO(b/219522861): Remove this alias and use Event in the code.
|
||||
use base::Event as EventFd;
|
||||
use base::Event;
|
||||
|
||||
use super::Result;
|
||||
|
||||
|
@ -123,7 +122,7 @@ pub trait VhostBackend: std::marker::Sized {
|
|||
/// Set base address for page modification logging.
|
||||
fn set_log_base(&self, base: u64, fd: Option<RawDescriptor>) -> Result<()>;
|
||||
|
||||
/// Specify an eventfd file descriptor to signal on log write.
|
||||
/// Specify an event file descriptor to signal on log write.
|
||||
fn set_log_fd(&self, fd: RawDescriptor) -> Result<()>;
|
||||
|
||||
/// Set the number of descriptors in the vring.
|
||||
|
@ -150,27 +149,27 @@ pub trait VhostBackend: std::marker::Sized {
|
|||
/// Get the available vring base offset.
|
||||
fn get_vring_base(&self, queue_index: usize) -> Result<u32>;
|
||||
|
||||
/// Set the eventfd to trigger when buffers have been used by the host.
|
||||
/// Set the event to trigger when buffers have been used by the host.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `queue_index` - Index of the queue to modify.
|
||||
/// * `fd` - EventFd to trigger.
|
||||
fn set_vring_call(&self, queue_index: usize, fd: &EventFd) -> Result<()>;
|
||||
/// * `event` - Event to trigger.
|
||||
fn set_vring_call(&self, queue_index: usize, event: &Event) -> Result<()>;
|
||||
|
||||
/// Set the eventfd that will be signaled by the guest when buffers are
|
||||
/// Set the event that will be signaled by the guest when buffers are
|
||||
/// available for the host to process.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `queue_index` - Index of the queue to modify.
|
||||
/// * `fd` - EventFd that will be signaled from guest.
|
||||
fn set_vring_kick(&self, queue_index: usize, fd: &EventFd) -> Result<()>;
|
||||
/// * `event` - Event that will be signaled from guest.
|
||||
fn set_vring_kick(&self, queue_index: usize, event: &Event) -> Result<()>;
|
||||
|
||||
/// Set the eventfd that will be signaled by the guest when error happens.
|
||||
/// Set the event that will be signaled by the guest when error happens.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `queue_index` - Index of the queue to modify.
|
||||
/// * `fd` - EventFd that will be signaled from guest.
|
||||
fn set_vring_err(&self, queue_index: usize, fd: &EventFd) -> Result<()>;
|
||||
/// * `event` - Event that will be signaled from guest.
|
||||
fn set_vring_err(&self, queue_index: usize, event: &Event) -> Result<()>;
|
||||
}
|
||||
|
||||
/// An interface for setting up vhost-based backend drivers.
|
||||
|
@ -209,7 +208,7 @@ pub trait VhostBackendMut: std::marker::Sized {
|
|||
/// Set base address for page modification logging.
|
||||
fn set_log_base(&mut self, base: u64, fd: Option<RawDescriptor>) -> Result<()>;
|
||||
|
||||
/// Specify an eventfd file descriptor to signal on log write.
|
||||
/// Specify an event file descriptor to signal on log write.
|
||||
fn set_log_fd(&mut self, fd: RawDescriptor) -> Result<()>;
|
||||
|
||||
/// Set the number of descriptors in the vring.
|
||||
|
@ -236,27 +235,27 @@ pub trait VhostBackendMut: std::marker::Sized {
|
|||
/// Get the available vring base offset.
|
||||
fn get_vring_base(&mut self, queue_index: usize) -> Result<u32>;
|
||||
|
||||
/// Set the eventfd to trigger when buffers have been used by the host.
|
||||
/// Set the event to trigger when buffers have been used by the host.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `queue_index` - Index of the queue to modify.
|
||||
/// * `fd` - EventFd to trigger.
|
||||
fn set_vring_call(&mut self, queue_index: usize, fd: &EventFd) -> Result<()>;
|
||||
/// * `event` - Event to trigger.
|
||||
fn set_vring_call(&mut self, queue_index: usize, event: &Event) -> Result<()>;
|
||||
|
||||
/// Set the eventfd that will be signaled by the guest when buffers are
|
||||
/// Set the event that will be signaled by the guest when buffers are
|
||||
/// available for the host to process.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `queue_index` - Index of the queue to modify.
|
||||
/// * `fd` - EventFd that will be signaled from guest.
|
||||
fn set_vring_kick(&mut self, queue_index: usize, fd: &EventFd) -> Result<()>;
|
||||
/// * `event` - Event that will be signaled from guest.
|
||||
fn set_vring_kick(&mut self, queue_index: usize, event: &Event) -> Result<()>;
|
||||
|
||||
/// Set the eventfd that will be signaled by the guest when error happens.
|
||||
/// Set the event that will be signaled by the guest when error happens.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `queue_index` - Index of the queue to modify.
|
||||
/// * `fd` - EventFd that will be signaled from guest.
|
||||
fn set_vring_err(&mut self, queue_index: usize, fd: &EventFd) -> Result<()>;
|
||||
/// * `event` - Event that will be signaled from guest.
|
||||
fn set_vring_err(&mut self, queue_index: usize, event: &Event) -> Result<()>;
|
||||
}
|
||||
|
||||
impl<T: VhostBackendMut> VhostBackend for RwLock<T> {
|
||||
|
@ -306,16 +305,16 @@ impl<T: VhostBackendMut> VhostBackend for RwLock<T> {
|
|||
self.write().unwrap().get_vring_base(queue_index)
|
||||
}
|
||||
|
||||
fn set_vring_call(&self, queue_index: usize, fd: &EventFd) -> Result<()> {
|
||||
self.write().unwrap().set_vring_call(queue_index, fd)
|
||||
fn set_vring_call(&self, queue_index: usize, event: &Event) -> Result<()> {
|
||||
self.write().unwrap().set_vring_call(queue_index, event)
|
||||
}
|
||||
|
||||
fn set_vring_kick(&self, queue_index: usize, fd: &EventFd) -> Result<()> {
|
||||
self.write().unwrap().set_vring_kick(queue_index, fd)
|
||||
fn set_vring_kick(&self, queue_index: usize, event: &Event) -> Result<()> {
|
||||
self.write().unwrap().set_vring_kick(queue_index, event)
|
||||
}
|
||||
|
||||
fn set_vring_err(&self, queue_index: usize, fd: &EventFd) -> Result<()> {
|
||||
self.write().unwrap().set_vring_err(queue_index, fd)
|
||||
fn set_vring_err(&self, queue_index: usize, event: &Event) -> Result<()> {
|
||||
self.write().unwrap().set_vring_err(queue_index, event)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,16 +363,16 @@ impl<T: VhostBackendMut> VhostBackend for RefCell<T> {
|
|||
self.borrow_mut().get_vring_base(queue_index)
|
||||
}
|
||||
|
||||
fn set_vring_call(&self, queue_index: usize, fd: &EventFd) -> Result<()> {
|
||||
self.borrow_mut().set_vring_call(queue_index, fd)
|
||||
fn set_vring_call(&self, queue_index: usize, event: &Event) -> Result<()> {
|
||||
self.borrow_mut().set_vring_call(queue_index, event)
|
||||
}
|
||||
|
||||
fn set_vring_kick(&self, queue_index: usize, fd: &EventFd) -> Result<()> {
|
||||
self.borrow_mut().set_vring_kick(queue_index, fd)
|
||||
fn set_vring_kick(&self, queue_index: usize, event: &Event) -> Result<()> {
|
||||
self.borrow_mut().set_vring_kick(queue_index, event)
|
||||
}
|
||||
|
||||
fn set_vring_err(&self, queue_index: usize, fd: &EventFd) -> Result<()> {
|
||||
self.borrow_mut().set_vring_err(queue_index, fd)
|
||||
fn set_vring_err(&self, queue_index: usize, event: &Event) -> Result<()> {
|
||||
self.borrow_mut().set_vring_err(queue_index, event)
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
|
@ -445,17 +444,17 @@ mod tests {
|
|||
Ok(2)
|
||||
}
|
||||
|
||||
fn set_vring_call(&mut self, queue_index: usize, _fd: &EventFd) -> Result<()> {
|
||||
fn set_vring_call(&mut self, queue_index: usize, _event: &Event) -> Result<()> {
|
||||
assert_eq!(queue_index, 1);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_vring_kick(&mut self, queue_index: usize, _fd: &EventFd) -> Result<()> {
|
||||
fn set_vring_kick(&mut self, queue_index: usize, _event: &Event) -> Result<()> {
|
||||
assert_eq!(queue_index, 1);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_vring_err(&mut self, queue_index: usize, _fd: &EventFd) -> Result<()> {
|
||||
fn set_vring_err(&mut self, queue_index: usize, _event: &Event) -> Result<()> {
|
||||
assert_eq!(queue_index, 1);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -491,10 +490,10 @@ mod tests {
|
|||
b.set_vring_base(1, 2).unwrap();
|
||||
assert_eq!(b.get_vring_base(1).unwrap(), 2);
|
||||
|
||||
let eventfd = EventFd::new().unwrap();
|
||||
b.set_vring_call(1, &eventfd).unwrap();
|
||||
b.set_vring_kick(1, &eventfd).unwrap();
|
||||
b.set_vring_err(1, &eventfd).unwrap();
|
||||
let event = Event::new().unwrap();
|
||||
b.set_vring_call(1, &event).unwrap();
|
||||
b.set_vring_kick(1, &event).unwrap();
|
||||
b.set_vring_err(1, &event).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
9
third_party/vmm_vhost/src/connection/vfio.rs
vendored
9
third_party/vmm_vhost/src/connection/vfio.rs
vendored
|
@ -10,15 +10,12 @@ use std::marker::PhantomData;
|
|||
use std::os::unix::io::RawFd;
|
||||
use std::path::Path;
|
||||
|
||||
use base::{AsRawDescriptor, RawDescriptor};
|
||||
use base::{AsRawDescriptor, Event, RawDescriptor};
|
||||
use remain::sorted;
|
||||
use thiserror::Error as ThisError;
|
||||
|
||||
use super::{Error, Result};
|
||||
use crate::{
|
||||
connection::{Endpoint as EndpointTrait, Listener as ListenerTrait, Req},
|
||||
EventFd,
|
||||
};
|
||||
use crate::connection::{Endpoint as EndpointTrait, Listener as ListenerTrait, Req};
|
||||
|
||||
/// Errors for `Device::recv_into_bufs()`.
|
||||
#[sorted]
|
||||
|
@ -44,7 +41,7 @@ impl From<RecvIntoBufsError> for Error {
|
|||
/// VFIO device which can be used as virtio-vhost-user device backend.
|
||||
pub trait Device {
|
||||
/// This event must be read before handle_request() is called.
|
||||
fn event(&self) -> &EventFd;
|
||||
fn event(&self) -> &Event;
|
||||
|
||||
/// Starts VFIO device.
|
||||
fn start(&mut self) -> std::result::Result<(), anyhow::Error>;
|
||||
|
|
16
third_party/vmm_vhost/src/lib.rs
vendored
16
third_party/vmm_vhost/src/lib.rs
vendored
|
@ -392,13 +392,13 @@ mod tests {
|
|||
let num = master.get_queue_num().unwrap();
|
||||
assert_eq!(num, 2);
|
||||
|
||||
let eventfd = base::Event::new().unwrap();
|
||||
let event = base::Event::new().unwrap();
|
||||
let mem = [VhostUserMemoryRegionInfo {
|
||||
guest_phys_addr: 0,
|
||||
memory_size: 0x10_0000,
|
||||
userspace_addr: 0,
|
||||
mmap_offset: 0,
|
||||
mmap_handle: eventfd.as_raw_descriptor(),
|
||||
mmap_handle: event.as_raw_descriptor(),
|
||||
}];
|
||||
master.set_mem_table(&mem).unwrap();
|
||||
|
||||
|
@ -417,16 +417,16 @@ mod tests {
|
|||
#[cfg(unix)]
|
||||
{
|
||||
master
|
||||
.set_slave_request_fd(&eventfd as &dyn AsRawDescriptor)
|
||||
.set_slave_request_fd(&event as &dyn AsRawDescriptor)
|
||||
.unwrap();
|
||||
}
|
||||
master.set_vring_enable(0, true).unwrap();
|
||||
|
||||
// unimplemented yet
|
||||
master
|
||||
.set_log_base(0, Some(eventfd.as_raw_descriptor()))
|
||||
.set_log_base(0, Some(event.as_raw_descriptor()))
|
||||
.unwrap();
|
||||
master.set_log_fd(eventfd.as_raw_descriptor()).unwrap();
|
||||
master.set_log_fd(event.as_raw_descriptor()).unwrap();
|
||||
|
||||
master.set_vring_num(0, 256).unwrap();
|
||||
master.set_vring_base(0, 0).unwrap();
|
||||
|
@ -440,9 +440,9 @@ mod tests {
|
|||
log_addr: Some(0x4000),
|
||||
};
|
||||
master.set_vring_addr(0, &config).unwrap();
|
||||
master.set_vring_call(0, &eventfd).unwrap();
|
||||
master.set_vring_kick(0, &eventfd).unwrap();
|
||||
master.set_vring_err(0, &eventfd).unwrap();
|
||||
master.set_vring_call(0, &event).unwrap();
|
||||
master.set_vring_kick(0, &event).unwrap();
|
||||
master.set_vring_err(0, &event).unwrap();
|
||||
|
||||
let max_mem_slots = master.get_max_mem_slots().unwrap();
|
||||
assert_eq!(max_mem_slots, 32);
|
||||
|
|
15
third_party/vmm_vhost/src/master.rs
vendored
15
third_party/vmm_vhost/src/master.rs
vendored
|
@ -8,8 +8,7 @@ use std::mem;
|
|||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex, MutexGuard};
|
||||
|
||||
// TODO(b/219522861): Remove this alias and use Event in the code.
|
||||
use base::{AsRawDescriptor, Event as EventFd, RawDescriptor, INVALID_DESCRIPTOR};
|
||||
use base::{AsRawDescriptor, Event, RawDescriptor, INVALID_DESCRIPTOR};
|
||||
use data_model::DataInit;
|
||||
|
||||
use super::connection::{Endpoint, EndpointExt};
|
||||
|
@ -289,7 +288,7 @@ impl<E: Endpoint<MasterReq>> VhostBackend for Master<E> {
|
|||
/// Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag
|
||||
/// is set when there is no file descriptor in the ancillary data. This signals that polling
|
||||
/// will be used instead of waiting for the call.
|
||||
fn set_vring_call(&self, queue_index: usize, fd: &EventFd) -> Result<()> {
|
||||
fn set_vring_call(&self, queue_index: usize, event: &Event) -> Result<()> {
|
||||
let mut node = self.node();
|
||||
if queue_index as u64 >= node.max_queue_num {
|
||||
return Err(VhostUserError::InvalidParam);
|
||||
|
@ -297,7 +296,7 @@ impl<E: Endpoint<MasterReq>> VhostBackend for Master<E> {
|
|||
let hdr = node.send_fd_for_vring(
|
||||
MasterReq::SET_VRING_CALL,
|
||||
queue_index,
|
||||
fd.as_raw_descriptor(),
|
||||
event.as_raw_descriptor(),
|
||||
)?;
|
||||
node.wait_for_ack(&hdr)
|
||||
}
|
||||
|
@ -306,7 +305,7 @@ impl<E: Endpoint<MasterReq>> VhostBackend for Master<E> {
|
|||
/// Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag
|
||||
/// is set when there is no file descriptor in the ancillary data. This signals that polling
|
||||
/// should be used instead of waiting for a kick.
|
||||
fn set_vring_kick(&self, queue_index: usize, fd: &EventFd) -> Result<()> {
|
||||
fn set_vring_kick(&self, queue_index: usize, event: &Event) -> Result<()> {
|
||||
let mut node = self.node();
|
||||
if queue_index as u64 >= node.max_queue_num {
|
||||
return Err(VhostUserError::InvalidParam);
|
||||
|
@ -314,7 +313,7 @@ impl<E: Endpoint<MasterReq>> VhostBackend for Master<E> {
|
|||
let hdr = node.send_fd_for_vring(
|
||||
MasterReq::SET_VRING_KICK,
|
||||
queue_index,
|
||||
fd.as_raw_descriptor(),
|
||||
event.as_raw_descriptor(),
|
||||
)?;
|
||||
node.wait_for_ack(&hdr)
|
||||
}
|
||||
|
@ -322,7 +321,7 @@ impl<E: Endpoint<MasterReq>> VhostBackend for Master<E> {
|
|||
/// Set the event file descriptor to signal when error occurs.
|
||||
/// Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag
|
||||
/// is set when there is no file descriptor in the ancillary data.
|
||||
fn set_vring_err(&self, queue_index: usize, fd: &EventFd) -> Result<()> {
|
||||
fn set_vring_err(&self, queue_index: usize, event: &Event) -> Result<()> {
|
||||
let mut node = self.node();
|
||||
if queue_index as u64 >= node.max_queue_num {
|
||||
return Err(VhostUserError::InvalidParam);
|
||||
|
@ -330,7 +329,7 @@ impl<E: Endpoint<MasterReq>> VhostBackend for Master<E> {
|
|||
let hdr = node.send_fd_for_vring(
|
||||
MasterReq::SET_VRING_ERR,
|
||||
queue_index,
|
||||
fd.as_raw_descriptor(),
|
||||
event.as_raw_descriptor(),
|
||||
)?;
|
||||
node.wait_for_ack(&hdr)
|
||||
}
|
||||
|
|
4
third_party/vmm_vhost/src/sys/unix.rs
vendored
4
third_party/vmm_vhost/src/sys/unix.rs
vendored
|
@ -33,7 +33,3 @@ impl SystemListenerExt for SystemListener {
|
|||
self.accept().map(|(socket, _address)| socket)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(b/221882601): Once base has Event/EventFd, we can drop this type.
|
||||
#[cfg(feature = "vfio-device")]
|
||||
pub(crate) type EventFd = base::EventFd;
|
||||
|
|
Loading…
Reference in a new issue