From 34bb31791b0576f59760b27ce893ff3375afe149 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 7 Oct 2019 09:57:19 -0700 Subject: [PATCH] vm-device: Add new crate for virtio and VFIO agnostic traits The new crate vm-device is created here to host the definitions of traits not meant to be tied to virtio of VFIO specifically. We need to add a new trait to update external DMA mappings for devices, which is why the vm-device crate is the right fit for this. We can expect this crate to be extended later once the design gets approved from a rust-vmm perspective. In this specific use case, we can have some devices like VFIO or vhost-user ones requiring to be notified about mapping updates. This new trait ExternalDmaMapping will allow such devices to implement their own way to handle such event. Signed-off-by: Sebastien Boeuf --- Cargo.lock | 5 +++++ Cargo.toml | 1 + vm-device/Cargo.toml | 7 +++++++ vm-device/src/lib.rs | 11 +++++++++++ 4 files changed, 24 insertions(+) create mode 100644 vm-device/Cargo.toml create mode 100644 vm-device/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 6e3295e6a..f073e3cf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,6 +183,7 @@ dependencies = [ "vhost_rs 0.1.0", "vhost_user_backend 0.1.0", "virtio-bindings 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "vm-device 0.1.0", "vm-memory 0.1.0 (git+https://github.com/rust-vmm/vm-memory)", "vm-virtio 0.1.0", "vmm 0.1.0", @@ -1022,6 +1023,10 @@ dependencies = [ "vm-memory 0.1.0 (git+https://github.com/rust-vmm/vm-memory)", ] +[[package]] +name = "vm-device" +version = "0.1.0" + [[package]] name = "vm-memory" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 0000f6c89..b620e40a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ net_util = { path = "net_util" } vhost_user_backend = { path = "vhost_user_backend"} virtio-bindings = "0.1.0" vmm = { path = "vmm" } +vm-device = { path = "vm-device" } vm-memory = { git = "https://github.com/rust-vmm/vm-memory" } vmm-sys-util = "0.1.1" vm-virtio = { path = "vm-virtio" } diff --git a/vm-device/Cargo.toml b/vm-device/Cargo.toml new file mode 100644 index 000000000..88b5c228d --- /dev/null +++ b/vm-device/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "vm-device" +version = "0.1.0" +authors = ["The Cloud Hypervisor Authors"] +edition = "2018" + +[dependencies] diff --git a/vm-device/src/lib.rs b/vm-device/src/lib.rs new file mode 100644 index 000000000..c4d9b5bac --- /dev/null +++ b/vm-device/src/lib.rs @@ -0,0 +1,11 @@ +/// Trait meant for triggering the DMA mapping update related to an external +/// device not managed fully through virtio. It is dedicated to virtio-iommu +/// in order to trigger the map update anytime the mapping is updated from the +/// guest. +pub trait ExternalDmaMapping: Send + Sync { + /// Map a memory range + fn map(&self, iova: u64, gpa: u64, size: u64) -> std::result::Result<(), std::io::Error>; + + /// Unmap a memory range + fn unmap(&self, iova: u64, size: u64) -> std::result::Result<(), std::io::Error>; +}