pci-assign: More small cleanups
cover pci-assign: More small cleanups
Besides an update for hiding unsupported ioport BARs and tiny code massages, this removes the obsolete iommu property from the pci-assign device.
Jan Kiszka (5):
pci-assign: Hide ioport regions on lacking sysfs support
pci-assign: Drop iommu property
pci-assign: Privatize type definitions
pci-assign: Drop write-only AssignedDevRegion::num
pci-assign: Drop kvm_assigned_irq::host_irq initialization
hw/device-assignment.c | 120 +++++++++++++++++++++++++++++++++++++++-------- hw/device-assignment.h | 98 --------------------------------------- 2 files changed, 99 insertions(+), 119 deletions(-)
Signature · 1 line
1.7.3.4
PATCH 1/5 pci-assign: Hide ioport regions on lacking sysfs support
As suggested by Alex: Instead of failing if the kernel does not allow us to speak to an ioport region, warn the user but, hide the region and continue.
--- hw/device-assignment.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
hw/device-assignment.c +4 -3
@@ -430,10 +430,11 @@ static int assigned_dev_register_regions(PCIRegion *io_regions, ret);abort (); }else if (errno !=EINVAL ) { -fprintf (stderr, -"Kernel doesn't support ioport resource access.\n" ); +fprintf (stderr,"Kernel doesn't support ioport resource " +"access, hiding this region.\n" );close (pci_dev->v_addrs[i].region->resource_fd); -return -1 ; + cur_region->valid =0 ; +continue ; } pci_dev->v_addrs[i].u.r_baseport = cur_region->base_addr;
Signature · 1 line
1.7.3.4
PATCH 2/5 pci-assign: Drop iommu property
In reply to Jan KiszkaDisabling the IOMMU for an assigned device was never more than a highly experimental features and is no longer supported by host kernels >= 3.2. So drop this useless control from property list.
--- hw/device-assignment.c | 22 ++++++---------------- hw/device-assignment.h | 6 ++---- 2 files changed, 8 insertions(+), 20 deletions(-)
hw/device-assignment.c +6 -16
@@ -749,21 +749,13 @@ static int assign_device(AssignedDevice *dev) assigned_dev_data.busnr = dev->h_busnr; assigned_dev_data.devfn = dev->h_devfn; -/* We always enable the IOMMU unless disabled on the command line */ -if (dev->features &ASSIGNED_DEVICE_USE_IOMMU_MASK ) { -if (!kvm_check_extension (kvm_state,KVM_CAP_IOMMU )) { -fprintf (stderr,"No IOMMU found. Unable to assign device \"%s\"\n" , - dev->dev.qdev.id); -return -ENODEV ; - } - assigned_dev_data.flags |=KVM_DEV_ASSIGN_ENABLE_IOMMU ; - } -if (!(dev->features &ASSIGNED_DEVICE_USE_IOMMU_MASK )) { -fprintf (stderr, -"WARNING: Assigning a device without IOMMU protection can " -"cause host memory corruption if the device issues DMA write " -"requests!\n" ); + assigned_dev_data.flags =KVM_DEV_ASSIGN_ENABLE_IOMMU ; +if (!kvm_check_extension (kvm_state,KVM_CAP_IOMMU )) { +fprintf (stderr,"No IOMMU found. Unable to assign device \"%s\"\n" , + dev->dev.qdev.id); +return -ENODEV ; } +if (dev->features &ASSIGNED_DEVICE_SHARE_INTX_MASK &&kvm_has_intx_set_mask ()) { assigned_dev_data.flags |=KVM_DEV_ASSIGN_PCI_2_3 ;
@@ -1782,8 +1774,6 @@ PropertyInfo qdev_prop_hostaddr = {static Property da_properties[] = {DEFINE_PROP ("host" , AssignedDevice, host, qdev_prop_hostaddr, PCIHostDevice), -DEFINE_PROP_BIT ("iommu" , AssignedDevice, features, -ASSIGNED_DEVICE_USE_IOMMU_BIT , true),DEFINE_PROP_BIT ("prefer_msi" , AssignedDevice, features,ASSIGNED_DEVICE_PREFER_MSI_BIT , false), DEFINE_PROP_BIT("share_intx", AssignedDevice, features,
hw/device-assignment.h +2 -4
@@ -74,11 +74,9 @@ typedef struct {PCIRegion *region; } AssignedDevRegion; -#define ASSIGNED_DEVICE_USE_IOMMU_BIT 0 -#define ASSIGNED_DEVICE_PREFER_MSI_BIT 1 -#define ASSIGNED_DEVICE_SHARE_INTX_BIT 2 +#define ASSIGNED_DEVICE_PREFER_MSI_BIT 0 +#define ASSIGNED_DEVICE_SHARE_INTX_BIT 1 -#define ASSIGNED_DEVICE_USE_IOMMU_MASK (1 << ASSIGNED_DEVICE_USE_IOMMU_BIT)#define ASSIGNED_DEVICE_PREFER_MSI_MASK (1 << ASSIGNED_DEVICE_PREFER_MSI_BIT)#define ASSIGNED_DEVICE_SHARE_INTX_MASK (1 << ASSIGNED_DEVICE_SHARE_INTX_BIT)
Signature · 1 line
1.7.3.4
PATCH 3/5 pci-assign: Privatize type definitions
In reply to Jan KiszkaNo need to carry the type definitions in device-assignment.h. Move them over to allow dropping the header once we use an INTx routing notifier instead of exporting assigned_dev_update_irqs.
--- hw/device-assignment.c | 90 +++++++++++++++++++++++++++++++++++++++++++++ hw/device-assignment.h | 96 ------------------------------------------------ 2 files changed, 90 insertions(+), 96 deletions(-)
hw/device-assignment.c +90 -0
@@ -28,6 +28,7 @@#include <stdio.h> #include <unistd.h> #include <sys/io.h> +#include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include "qemu-kvm.h"
@@ -40,6 +41,7 @@#include "monitor.h" #include "range.h" #include "sysemu.h" +#include "pci.h" #define MSIX_PAGE_SIZE 0x1000
@@ -61,6 +63,94 @@#define DEBUG (fmt, ...) do { } while(0)#endif +typedef struct PCIHostDevice { +int seg; +int bus; +int dev; +int func; +}PCIHostDevice ; + +typedef struct { +int type;/* Memory or port I/O */ +int valid; +uint32_t base_addr; +uint32_t size;/* size of the region */ +int resource_fd; +}PCIRegion ; + +typedef struct { +uint8_t bus, dev, func;/* Bus inside domain, device and function */ +int irq;/* IRQ number */ +uint16_t region_number;/* number of active regions */ + +/* Port I/O or MMIO Regions */ +PCIRegion regions[PCI_NUM_REGIONS -1 ]; +int config_fd; +}PCIDevRegions ; + +typedef struct { +MemoryRegion container; +MemoryRegion real_iomem; +union { +void *r_virtbase;/* mmapped access address for memory regions */ +uint32_t r_baseport;/* the base guest port for I/O regions */ + } u; +int num;/* our index within v_addrs[] */ +pcibus_t e_size;/* emulated size of region in bytes */ +pcibus_t r_size;/* real size of region in bytes */ +PCIRegion *region; +}AssignedDevRegion ; + +#define ASSIGNED_DEVICE_PREFER_MSI_BIT 0 +#define ASSIGNED_DEVICE_SHARE_INTX_BIT 1 + +#define ASSIGNED_DEVICE_PREFER_MSI_MASK (1 << ASSIGNED_DEVICE_PREFER_MSI_BIT) +#define ASSIGNED_DEVICE_SHARE_INTX_MASK (1 << ASSIGNED_DEVICE_SHARE_INTX_BIT) + +typedef struct { +uint32_t addr_lo; +uint32_t addr_hi; +uint32_t data; +uint32_t ctrl; +}MSIXTableEntry ; + +typedef struct AssignedDevice { +PCIDevice dev; +PCIHostDevice host; +uint32_t features; +int intpin; +uint8_t debug_flags; +AssignedDevRegion v_addrs[PCI_NUM_REGIONS -1 ]; +PCIDevRegions real_device; +int run; +int girq; +uint16_t h_segnr; +uint8_t h_busnr; +uint8_t h_devfn; +int irq_requested_type; +int bound; +struct { +#define ASSIGNED_DEVICE_CAP_MSI (1 << 0) +#define ASSIGNED_DEVICE_CAP_MSIX (1 << 1) +uint32_t available; +#define ASSIGNED_DEVICE_MSI_ENABLED (1 << 0) +#define ASSIGNED_DEVICE_MSIX_ENABLED (1 << 1) +#define ASSIGNED_DEVICE_MSIX_MASKED (1 << 2) +uint32_t state; + } cap; +uint8_t emulate_config_read[PCI_CONFIG_SPACE_SIZE ]; +uint8_t emulate_config_write[PCI_CONFIG_SPACE_SIZE ]; +int irq_entries_nr; +struct kvm_irq_routing_entry *entry; +MSIXTableEntry *msix_table; +target_phys_addr_t msix_table_addr; +uint16_t msix_max; +MemoryRegion mmio; +char *configfd_name; +int32_t bootindex; +QLIST_ENTRY (AssignedDevice) next; +}AssignedDevice ; +static void assigned_dev_load_option_rom (AssignedDevice *dev);static void assigned_dev_unregister_msix_mmio (AssignedDevice *dev);
hw/device-assignment.h +0 -96
102 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 4/5 pci-assign: Drop write-only AssignedDevRegion::num
In reply to Jan KiszkaNo one was reading back this field.
--- hw/device-assignment.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
hw/device-assignment.c +0 -2
@@ -95,7 +95,6 @@ typedef struct {void *r_virtbase;/* mmapped access address for memory regions */ uint32_t r_baseport;/* the base guest port for I/O regions */ } u; -int num;/* our index within v_addrs[] */ pcibus_t e_size;/* emulated size of region in bytes */ pcibus_t r_size;/* real size of region in bytes */ PCIRegion *region;
@@ -449,7 +448,6 @@ static int assigned_dev_register_regions(PCIRegion *io_regions,for (i =0 ; i < regions_num; i++, cur_region++) {if (!cur_region->valid)continue ; - pci_dev->v_addrs[i].num = i;/* handle memory io regions */ if (cur_region->type &IORESOURCE_MEM ) {
Signature · 1 line
1.7.3.4
PATCH 5/5 pci-assign: Drop kvm_assigned_irq::host_irq initialization
In reply to Jan Kiszkareal_device.irq is never set explicitly, thus remains 0. So we can simply drop this line as assigned_irq_data is zero-initialized anyway.
--- hw/device-assignment.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
hw/device-assignment.c +0 -1
@@ -883,7 +883,6 @@ static int assign_irq(AssignedDevice *dev)memset (&assigned_irq_data,0 ,sizeof (assigned_irq_data)); assigned_irq_data.assigned_dev_id =calc_assigned_dev_id (dev); assigned_irq_data.guest_irq = irq; - assigned_irq_data.host_irq = dev->real_device.irq;if (dev->irq_requested_type) { assigned_irq_data.flags = dev->irq_requested_type; r =kvm_deassign_irq (kvm_state, &assigned_irq_data);
Signature · 1 line
1.7.3.4
Quoted 11 lines · Jan Kiszka
Besides an update for hiding unsupported ioport BARs and tiny code massages, this removes the obsolete iommu property from the pci-assign device.
Jan Kiszka (5):
pci-assign: Hide ioport regions on lacking sysfs support
pci-assign: Drop iommu property
pci-assign: Privatize type definitions
pci-assign: Drop write-onlyAssignedDevRegion::num
pci-assign: Dropkvm_assigned_irq::host_irqinitialization
Quoted 4 lines
hw/device-assignment.c | 120 +++++++++++++++++++++++++++++++++++++++-------- hw/device-assignment.h | 98 --------------------------------------- 2 files changed, 99 insertions(+), 119 deletions(-)
Looks good. For series:
Marcelo Tosatti
AppliedQuoted 11 lines · Jan Kiszka
Besides an update for hiding unsupported ioport BARs and tiny code massages, this removes the obsolete iommu property from the pci-assign device.
Jan Kiszka (5):
pci-assign: Hide ioport regions on lacking sysfs support
pci-assign: Drop iommu property
pci-assign: Privatize type definitions
pci-assign: Drop write-onlyAssignedDevRegion::num
pci-assign: Dropkvm_assigned_irq::host_irqinitialization
Quoted 3 lines
hw/device-assignment.c | 120 +++++++++++++++++++++++++++++++++++++++-------- hw/device-assignment.h | 98 --------------------------------------- 2 files changed, 99 insertions(+), 119 deletions(-)
Applied, thanks.