From 59d01712adf0cd2383b6cd2afc345c087981fc03 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 5 Dec 2019 16:36:28 +0000 Subject: [PATCH] vmm: Remove kernel based IOAPIC handling from the device manager Previously the device setup code assumed that if no IOAPIC was passed in then the device should be added to the kernel irqchip. As an earlier change meant that there was always a userspace IOAPIC this kernel based code can be removed. The accessor still returns an Option type to leave scope for implementing a situation without an IOAPIC (no serial or GED device). This change does not add support no-IOAPIC mode as the original code did not either. Signed-off-by: Rob Bradford --- vmm/src/device_manager.rs | 95 ++++++++++----------------------------- vmm/src/vm.rs | 4 -- 2 files changed, 24 insertions(+), 75 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 50dfb3736..3edfa15a9 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -16,7 +16,7 @@ use devices::{ioapic, HotPlugNotificationType}; use kvm_bindings::{kvm_irq_routing_entry, kvm_userspace_memory_region}; use kvm_ioctls::*; use libc::O_TMPFILE; -use libc::{EFD_NONBLOCK, TIOCGWINSZ}; +use libc::TIOCGWINSZ; use net_util::Tap; #[cfg(feature = "pci_support")] @@ -177,23 +177,7 @@ pub enum DeviceManagerError { pub type DeviceManagerResult = result::Result; struct InterruptInfo<'a> { - _ioapic: &'a Option>>, -} - -struct KernelIoapicIrq { - evt: EventFd, -} - -impl KernelIoapicIrq { - fn new(evt: EventFd) -> Self { - KernelIoapicIrq { evt } - } -} - -impl devices::Interrupt for KernelIoapicIrq { - fn deliver(&self) -> result::Result<(), io::Error> { - self.evt.write(1) - } + _ioapic: &'a Arc>, } struct UserIoapicIrq { @@ -415,7 +399,6 @@ impl DeviceManager { pub fn new( vm_info: &VmInfo, allocator: SystemAllocator, - userspace_ioapic: bool, mut mem_slots: u32, _exit_evt: &EventFd, reset_evt: &EventFd, @@ -440,7 +423,7 @@ impl DeviceManager { vm_fd: vm_info.vm_fd.clone(), }); - let ioapic = DeviceManager::add_ioapic(vm_info, &address_manager, userspace_ioapic)?; + let ioapic = DeviceManager::add_ioapic(vm_info, &address_manager)?; let interrupt_info = InterruptInfo { _ioapic: &ioapic }; let console = DeviceManager::add_console_device( @@ -494,7 +477,7 @@ impl DeviceManager { Ok(DeviceManager { address_manager, console, - ioapic, + ioapic: Some(ioapic), mmap_regions, cmdline_additions, virt_iommu, @@ -642,23 +625,17 @@ impl DeviceManager { fn add_ioapic( vm_info: &VmInfo, address_manager: &Arc, - userspace_ioapic: bool, - ) -> DeviceManagerResult>>> { - let ioapic = if userspace_ioapic { - // Create IOAPIC - let ioapic = Arc::new(Mutex::new(ioapic::Ioapic::new( - vm_info.vm_fd.clone(), - APIC_START, - ))); + ) -> DeviceManagerResult>> { + // Create IOAPIC + let ioapic = Arc::new(Mutex::new(ioapic::Ioapic::new( + vm_info.vm_fd.clone(), + APIC_START, + ))); - address_manager - .mmio_bus - .insert(ioapic.clone(), IOAPIC_START.0, IOAPIC_SIZE) - .map_err(DeviceManagerError::BusError)?; - Some(ioapic) - } else { - None - }; + address_manager + .mmio_bus + .insert(ioapic.clone(), IOAPIC_START.0, IOAPIC_SIZE) + .map_err(DeviceManagerError::BusError)?; Ok(ioapic) } @@ -670,7 +647,7 @@ impl DeviceManager { address_manager: &Arc, reset_evt: EventFd, exit_evt: EventFd, - ioapic: &Option>>, + ioapic: &Arc>, ) -> DeviceManagerResult>>> { let acpi_device = Arc::new(Mutex::new(devices::AcpiShutdownDevice::new( exit_evt, reset_evt, @@ -691,17 +668,9 @@ impl DeviceManager { // We need to hardcode this as the ACPI tables need to specify a particular IRQ and it's not possible // to ask the allocator for a specific one. let ged_irq = 5; - let interrupt: Box = if let Some(ioapic) = &ioapic { - Box::new(UserIoapicIrq::new(ioapic.clone(), ged_irq)) - } else { - let ged_evt = EventFd::new(EFD_NONBLOCK).map_err(DeviceManagerError::EventFd)?; - vm_info - .vm_fd - .register_irqfd(&ged_evt, ged_irq as u32) - .map_err(DeviceManagerError::Irq)?; + let interrupt: Box = + Box::new(UserIoapicIrq::new(ioapic.clone(), ged_irq)); - Box::new(KernelIoapicIrq::new(ged_evt)) - }; let ged_device = Arc::new(Mutex::new(devices::AcpiGEDDevice::new(interrupt))); address_manager @@ -755,7 +724,7 @@ impl DeviceManager { fn add_console_device( vm_info: &VmInfo, address_manager: &Arc, - ioapic: &Option>>, + ioapic: &Arc>, virtio_devices: &mut Vec<(Box, bool)>, ) -> DeviceManagerResult> { let serial_config = vm_info.vm_cfg.lock().unwrap().serial.clone(); @@ -770,17 +739,8 @@ impl DeviceManager { let serial = if serial_config.mode != ConsoleOutputMode::Off { // Serial is tied to IRQ #4 let serial_irq = 4; - let interrupt: Box = if let Some(ioapic) = &ioapic { - Box::new(UserIoapicIrq::new(ioapic.clone(), serial_irq)) - } else { - let serial_evt = EventFd::new(EFD_NONBLOCK).map_err(DeviceManagerError::EventFd)?; - vm_info - .vm_fd - .register_irqfd(&serial_evt, serial_irq as u32) - .map_err(DeviceManagerError::Irq)?; - - Box::new(KernelIoapicIrq::new(serial_evt)) - }; + let interrupt: Box = + Box::new(UserIoapicIrq::new(ioapic.clone(), serial_irq)); let serial = Arc::new(Mutex::new(devices::legacy::Serial::new( interrupt, @@ -1496,17 +1456,10 @@ impl DeviceManager { .allocate_irq() .ok_or(DeviceManagerError::AllocateIrq)?; - let interrupt: Box = if let Some(ioapic) = interrupt_info._ioapic { - Box::new(UserIoapicIrq::new(ioapic.clone(), irq_num as usize)) - } else { - let irqfd = EventFd::new(EFD_NONBLOCK).map_err(DeviceManagerError::EventFd)?; - - vm_fd - .register_irqfd(&irqfd, irq_num as u32) - .map_err(DeviceManagerError::Irq)?; - - Box::new(KernelIoapicIrq::new(irqfd)) - }; + let interrupt: Box = Box::new(UserIoapicIrq::new( + interrupt_info._ioapic.clone(), + irq_num as usize, + )); mmio_device.assign_interrupt(interrupt); diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 6d98369eb..8d634ea65 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -380,9 +380,6 @@ impl Vm { cap.args[0] = ioapic::NUM_IOAPIC_PINS as u64; fd.enable_cap(&cap).map_err(Error::VmSetup)?; - // Because of the split irqchip, we need a userspace IOAPIC. - let userspace_ioapic = true; - // Patch tsc deadline timer bit cpuid_patches.push(cpu::CpuidPatch { function: 1, @@ -451,7 +448,6 @@ impl Vm { let device_manager = DeviceManager::new( &vm_info, allocator, - userspace_ioapic, ram_regions.len() as u32, &exit_evt, &reset_evt,