virtio-devices: move userspace mapping to vm-device

Move UserspaceMapping to vm-device to avoid redefinition since
UserspaceMapping is used by both `virtio-devices` and `device`
crate.

Signed-off-by: Songqian Li <sionli@tencent.com>
This commit is contained in:
Songqian Li 2025-06-17 16:56:40 +08:00 committed by Bo Chen
parent 55212b0437
commit bd17c84d3c
9 changed files with 25 additions and 19 deletions

1
Cargo.lock generated
View file

@ -2403,6 +2403,7 @@ dependencies = [
"serde",
"thiserror 2.0.12",
"vfio-ioctls",
"vm-memory",
"vmm-sys-util",
]

View file

@ -12,8 +12,9 @@ use std::{ffi, io};
use libc::{MAP_NORESERVE, MAP_PRIVATE, PROT_READ, PROT_WRITE};
use libfuzzer_sys::{fuzz_target, Corpus};
use seccompiler::SeccompAction;
use virtio_devices::{Pmem, UserspaceMapping, VirtioDevice, VirtioInterrupt, VirtioInterruptType};
use virtio_devices::{Pmem, VirtioDevice, VirtioInterrupt, VirtioInterruptType};
use virtio_queue::{Queue, QueueT};
use vm_device::UserspaceMapping;
use vm_memory::bitmap::AtomicBitmap;
use vm_memory::guest_memory::FileOffset;
use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic, MmapRegion};

View file

@ -15,6 +15,7 @@ use std::thread;
use libc::EFD_NONBLOCK;
use virtio_queue::Queue;
use vm_device::UserspaceMapping;
use vm_memory::{GuestAddress, GuestMemoryAtomic, GuestUsize};
use vm_migration::{MigratableError, Pausable};
use vm_virtio::{AccessPlatform, VirtioDeviceType};
@ -37,15 +38,6 @@ pub trait VirtioInterrupt: Send + Sync {
}
}
#[derive(Clone)]
pub struct UserspaceMapping {
pub host_addr: u64,
pub mem_slot: u32,
pub addr: GuestAddress,
pub len: GuestUsize,
pub mergeable: bool,
}
#[derive(Clone)]
pub struct VirtioSharedMemory {
pub offset: u64,

View file

@ -47,8 +47,8 @@ pub use self::balloon::Balloon;
pub use self::block::{Block, BlockState};
pub use self::console::{Console, ConsoleResizer, Endpoint};
pub use self::device::{
DmaRemapping, UserspaceMapping, VirtioCommon, VirtioDevice, VirtioInterrupt,
VirtioInterruptType, VirtioSharedMemoryList,
DmaRemapping, VirtioCommon, VirtioDevice, VirtioInterrupt, VirtioInterruptType,
VirtioSharedMemoryList,
};
pub use self::epoll_helper::{
EpollHelper, EpollHelperError, EpollHelperHandler, EPOLL_HELPER_EVENT_LAST,

View file

@ -18,6 +18,7 @@ use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use virtio_queue::{DescriptorChain, Queue, QueueT};
use vm_device::UserspaceMapping;
use vm_memory::{
Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic,
GuestMemoryError, GuestMemoryLoadGuard,
@ -28,8 +29,8 @@ use vmm_sys_util::eventfd::EventFd;
use super::{
ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler,
Error as DeviceError, UserspaceMapping, VirtioCommon, VirtioDevice, VirtioDeviceType,
EPOLL_HELPER_EVENT_LAST, VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1,
Error as DeviceError, VirtioCommon, VirtioDevice, VirtioDeviceType, EPOLL_HELPER_EVENT_LAST,
VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1,
};
use crate::seccomp_filters::Thread;
use crate::thread_helper::spawn_virtio_thread;

View file

@ -11,6 +11,7 @@ use serde_with::{serde_as, Bytes};
use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures};
use vhost::vhost_user::{FrontendReqHandler, VhostUserFrontend, VhostUserFrontendReqHandler};
use virtio_queue::Queue;
use vm_device::UserspaceMapping;
use vm_memory::{ByteValued, GuestMemoryAtomic};
use vm_migration::protocol::MemoryRangeTable;
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
@ -22,9 +23,8 @@ use crate::seccomp_filters::Thread;
use crate::thread_helper::spawn_virtio_thread;
use crate::vhost_user::VhostUserCommon;
use crate::{
ActivateResult, GuestMemoryMmap, GuestRegionMmap, MmapRegion, UserspaceMapping, VirtioCommon,
VirtioDevice, VirtioDeviceType, VirtioInterrupt, VirtioSharedMemoryList,
VIRTIO_F_IOMMU_PLATFORM,
ActivateResult, GuestMemoryMmap, GuestRegionMmap, MmapRegion, VirtioCommon, VirtioDevice,
VirtioDeviceType, VirtioInterrupt, VirtioSharedMemoryList, VIRTIO_F_IOMMU_PLATFORM,
};
const NUM_QUEUE_OFFSET: usize = 1;

View file

@ -14,4 +14,5 @@ hypervisor = { path = "../hypervisor" }
serde = { workspace = true, features = ["derive", "rc"] }
thiserror = { workspace = true }
vfio-ioctls = { workspace = true, default-features = false }
vm-memory = { workspace = true, features = ["backend-mmap"] }
vmm-sys-util = { workspace = true }

View file

@ -4,6 +4,7 @@
//
use serde::{Deserialize, Serialize};
use vm_memory::{GuestAddress, GuestUsize};
mod bus;
pub mod dma_mapping;
@ -58,3 +59,12 @@ pub enum Resource {
/// KVM memslot index.
KvmMemSlot(u32),
}
#[derive(Clone)]
pub struct UserspaceMapping {
pub host_addr: u64,
pub mem_slot: u32,
pub addr: GuestAddress,
pub len: GuestUsize,
pub mergeable: bool,
}

View file

@ -95,7 +95,7 @@ use vm_device::dma_mapping::ExternalDmaMapping;
use vm_device::interrupt::{
InterruptIndex, InterruptManager, LegacyIrqGroupConfig, MsiIrqGroupConfig,
};
use vm_device::{Bus, BusDevice, BusDeviceSync, Resource};
use vm_device::{Bus, BusDevice, BusDeviceSync, Resource, UserspaceMapping};
use vm_memory::guest_memory::FileOffset;
use vm_memory::{Address, GuestAddress, GuestMemoryRegion, GuestUsize, MmapRegion};
#[cfg(target_arch = "x86_64")]
@ -3231,7 +3231,7 @@ impl DeviceManager {
.create_userspace_mapping(region_base, region_size, host_addr, false, false, false)
.map_err(DeviceManagerError::MemoryManager)?;
let mapping = virtio_devices::UserspaceMapping {
let mapping = UserspaceMapping {
host_addr,
mem_slot,
addr: GuestAddress(region_base),