From d3f66f8702664bd0d1489bf0ecfd9c212dcca74b Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 11 May 2022 16:36:08 +0100 Subject: [PATCH] hypervisor: Make vm module private And thus only export what is necessary through a `pub use`. This is consistent with some of the other modules and makes it easier to understand what the external interface of the hypervisor crate is. Signed-off-by: Rob Bradford --- hypervisor/src/lib.rs | 9 ++++++--- vm-device/src/interrupt/mod.rs | 2 +- vmm/src/cpu.rs | 2 +- vmm/src/device_manager.rs | 4 ++-- vmm/src/vm.rs | 14 +++++++------- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/hypervisor/src/lib.rs b/hypervisor/src/lib.rs index 4e7b32f44..7ac0b7990 100644 --- a/hypervisor/src/lib.rs +++ b/hypervisor/src/lib.rs @@ -40,7 +40,7 @@ pub mod mshv; pub mod hypervisor; /// Vm related module -pub mod vm; +mod vm; /// CPU related module mod cpu; @@ -48,16 +48,19 @@ mod cpu; /// Device related module mod device; -pub use crate::hypervisor::{Hypervisor, HypervisorError}; pub use cpu::{HypervisorCpuError, Vcpu, VmExit}; pub use device::{Device, HypervisorDeviceError}; +pub use hypervisor::{Hypervisor, HypervisorError}; #[cfg(feature = "tdx")] pub use kvm::TdxCapabilities; #[cfg(feature = "kvm")] pub use kvm::*; #[cfg(all(feature = "mshv", target_arch = "x86_64"))] pub use mshv::*; -pub use vm::{DataMatch, HypervisorVmError, Vm}; +pub use vm::{ + DataMatch, HypervisorVmError, InterruptSourceConfig, LegacyIrqSourceConfig, MsiIrqSourceConfig, + Vm, VmOps, +}; use std::sync::Arc; diff --git a/vm-device/src/interrupt/mod.rs b/vm-device/src/interrupt/mod.rs index b0ff25ac9..f4f7ebee8 100644 --- a/vm-device/src/interrupt/mod.rs +++ b/vm-device/src/interrupt/mod.rs @@ -57,7 +57,7 @@ //! * The virtual device backend requests the interrupt manager to create an interrupt group //! according to guest configuration information -pub use hypervisor::vm::{InterruptSourceConfig, LegacyIrqSourceConfig, MsiIrqSourceConfig}; +pub use hypervisor::{InterruptSourceConfig, LegacyIrqSourceConfig, MsiIrqSourceConfig}; use std::sync::Arc; use vmm_sys_util::eventfd::EventFd; diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index e544db8e1..97c6c5b38 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -34,7 +34,7 @@ use hypervisor::kvm::kvm_bindings; use hypervisor::x86_64::{SpecialRegisters, StandardRegisters}; #[cfg(target_arch = "x86_64")] use hypervisor::CpuId; -use hypervisor::{vm::VmOps, CpuState, HypervisorCpuError, VmExit}; +use hypervisor::{CpuState, HypervisorCpuError, VmExit, VmOps}; #[cfg(feature = "tdx")] use hypervisor::{TdxExitDetails, TdxExitStatus}; use libc::{c_void, siginfo_t}; diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index b1b397f50..da1a4eb64 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -53,7 +53,7 @@ use devices::legacy::Serial; use devices::{ interrupt_controller, interrupt_controller::InterruptController, AcpiNotificationFlags, }; -use hypervisor::{DeviceFd, IoEventAddress}; +use hypervisor::{DeviceFd, HypervisorVmError, IoEventAddress}; use libc::{ cfmakeraw, isatty, tcgetattr, tcsetattr, termios, MAP_NORESERVE, MAP_PRIVATE, MAP_SHARED, O_TMPFILE, PROT_READ, PROT_WRITE, TCSANOW, @@ -468,7 +468,7 @@ pub enum DeviceManagerError { InvalidIommuHotplug, /// Failed to create UEFI flash - CreateUefiFlash(hypervisor::vm::HypervisorVmError), + CreateUefiFlash(HypervisorVmError), /// Invalid identifier as it is not unique. IdentifierNotUnique(String), diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 775b35d3f..7535585d1 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -49,7 +49,7 @@ use devices::interrupt_controller::{self, InterruptController}; use devices::AcpiNotificationFlags; #[cfg(all(target_arch = "x86_64", feature = "gdb"))] use gdbstub_arch::x86::reg::X86_64CoreRegs; -use hypervisor::vm::{HypervisorVmError, VmOps}; +use hypervisor::{HypervisorVmError, VmOps}; use linux_loader::cmdline::Cmdline; #[cfg(target_arch = "x86_64")] use linux_loader::loader::elf::PvhBootCapability::PvhEntryPresent; @@ -353,28 +353,28 @@ struct VmOpsHandler { } impl VmOps for VmOpsHandler { - fn guest_mem_write(&self, gpa: u64, buf: &[u8]) -> hypervisor::vm::Result { + fn guest_mem_write(&self, gpa: u64, buf: &[u8]) -> result::Result { self.memory .memory() .write(buf, GuestAddress(gpa)) .map_err(|e| HypervisorVmError::GuestMemWrite(e.into())) } - fn guest_mem_read(&self, gpa: u64, buf: &mut [u8]) -> hypervisor::vm::Result { + fn guest_mem_read(&self, gpa: u64, buf: &mut [u8]) -> result::Result { self.memory .memory() .read(buf, GuestAddress(gpa)) .map_err(|e| HypervisorVmError::GuestMemRead(e.into())) } - fn mmio_read(&self, gpa: u64, data: &mut [u8]) -> hypervisor::vm::Result<()> { + fn mmio_read(&self, gpa: u64, data: &mut [u8]) -> result::Result<(), HypervisorVmError> { if let Err(vm_device::BusError::MissingAddressRange) = self.mmio_bus.read(gpa, data) { warn!("Guest MMIO read to unregistered address 0x{:x}", gpa); } Ok(()) } - fn mmio_write(&self, gpa: u64, data: &[u8]) -> hypervisor::vm::Result<()> { + fn mmio_write(&self, gpa: u64, data: &[u8]) -> result::Result<(), HypervisorVmError> { match self.mmio_bus.write(gpa, data) { Err(vm_device::BusError::MissingAddressRange) => { warn!("Guest MMIO write to unregistered address 0x{:x}", gpa); @@ -390,7 +390,7 @@ impl VmOps for VmOpsHandler { } #[cfg(target_arch = "x86_64")] - fn pio_read(&self, port: u64, data: &mut [u8]) -> hypervisor::vm::Result<()> { + fn pio_read(&self, port: u64, data: &mut [u8]) -> result::Result<(), HypervisorVmError> { use pci::{PCI_CONFIG_IO_PORT, PCI_CONFIG_IO_PORT_SIZE}; if (PCI_CONFIG_IO_PORT..(PCI_CONFIG_IO_PORT + PCI_CONFIG_IO_PORT_SIZE)).contains(&port) { @@ -409,7 +409,7 @@ impl VmOps for VmOpsHandler { } #[cfg(target_arch = "x86_64")] - fn pio_write(&self, port: u64, data: &[u8]) -> hypervisor::vm::Result<()> { + fn pio_write(&self, port: u64, data: &[u8]) -> result::Result<(), HypervisorVmError> { use pci::{PCI_CONFIG_IO_PORT, PCI_CONFIG_IO_PORT_SIZE}; if (PCI_CONFIG_IO_PORT..(PCI_CONFIG_IO_PORT + PCI_CONFIG_IO_PORT_SIZE)).contains(&port) {