spapr_pci: allow control of BAR alignment through SLOF
PATCH 1/1 spapr_pci: allow control of BAR alignment through SLOF
In certain cases, such as PCI-passthrough with VFIO, we cannot offload MMIO accesses to KVM unless the BAR alignment matches the host. This patch, in conjunction with a separately submitted patch for SLOF which allows for control of this via the device-tree, allows us to set this alignment via QEMU.
--- hw/ppc/spapr.c | 7 ++++++- hw/ppc/spapr_pci.c | 8 ++++++++ include/hw/pci-host/spapr.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +6 -1
@@ -3121,7 +3121,12 @@ DEFINE_SPAPR_MACHINE(2_9, "2.9", true);* pseries-2.8 */ #define SPAPR_COMPAT_2_8 \ - HW_COMPAT_2_8 + HW_COMPAT_2_8 \ + { \ + .driver = TYPE_SPAPR_PCI_HOST_BRIDGE, \ + .property = "mem_bar_min_align", \ + .value = "0", \ + }, \static void spapr_machine_2_8_instance_options (MachineState *machine) {
hw/ppc/spapr_pci.c +8 -0
@@ -1660,6 +1660,10 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)return ; } +if (sphb->mem_bar_min_align == (uint64_t )-1 ) { + sphb->mem_bar_min_align = qemu_real_host_page_size; + } + sphb->dtbusname =g_strdup_printf ("pci@%" PRIx64, sphb->buid); namebuf =alloca (strlen (sphb->dtbusname) +32 );
@@ -1854,6 +1858,8 @@ static Property spapr_phb_properties[] = {DEFINE_PROP_UINT32 ("numa_node" , sPAPRPHBState, numa_node,-1 ),DEFINE_PROP_BOOL ("pre-2.8-migration" , sPAPRPHBState, pre_2_8_migration, false), +DEFINE_PROP_UINT64 ("mem_bar_min_align" , sPAPRPHBState, mem_bar_min_align, +-1 ), DEFINE_PROP_END_OF_LIST(), };
@@ -2224,6 +2230,8 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb,if (ret) {return ret; } +_FDT (fdt_setprop_cell (fdt, bus_off,"qemu,mem-bar-min-align" , + phb->mem_bar_min_align));return 0 ; }
include/hw/pci-host/spapr.h +1 -0
@@ -79,6 +79,7 @@ struct sPAPRPHBState {uint64_t dma64_win_addr;uint32_t numa_node; +uint64_t mem_bar_min_align;/* Fields for migration compatibility hacks */ bool pre_2_8_migration;
Signature · 1 line
2.7.4
Quoted 60 lines · Michael Roth
In certain cases, such as PCI-passthrough with VFIO, we cannot offload MMIO accesses to KVM unless the BAR alignment matches the host. This patch, in conjunction with a separately submitted patch for SLOF which allows for control of this via the device-tree, allows us to set this alignment via QEMU.
Cc Nikunj A Dadhania <[email protected]>Cc David Gibson <[email protected]>Cc Alexey Kardashevskiy <[email protected]>Signed-off-by Michael Roth <[email protected]>--- hw/ppc/spapr.c | 7 ++++++- hw/ppc/spapr_pci.c | 8 ++++++++ include/hw/pci-host/spapr.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-)hw/ppc/spapr.c +6
-1@@ -3121,7 +3121,12 @@ DEFINE_SPAPR_MACHINE(2_9, "2.9", true);* pseries-2.8 */ #define SPAPR_COMPAT_2_8 \ - HW_COMPAT_2_8 + HW_COMPAT_2_8 \ + { \ + .driver = TYPE_SPAPR_PCI_HOST_BRIDGE, \ + .property = "mem_bar_min_align", \ + .value = "0", \ + }, \static void spapr_machine_2_8_instance_options (MachineState *machine) {hw/ppc/spapr_pci.c +6
-0@@ -1660,6 +1660,10 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)return ; } +if (sphb->mem_bar_min_align == (uint64_t )-1 ) { + sphb->mem_bar_min_align = qemu_real_host_page_size; + } + sphb->dtbusname =g_strdup_printf ("pci@%" PRIx64, sphb->buid); namebuf =alloca (strlen (sphb->dtbusname) +32 );@@ -1854,6 +1858,8 @@ static Property spapr_phb_properties[] = {DEFINE_PROP_UINT32 ("numa_node" , sPAPRPHBState, numa_node,-1 ),DEFINE_PROP_BOOL ("pre-2.8-migration" , sPAPRPHBState, pre_2_8_migration, false), +DEFINE_PROP_UINT64 ("mem_bar_min_align" , sPAPRPHBState, mem_bar_min_align, +-1 ), DEFINE_PROP_END_OF_LIST(), };
hw/ppc/spapr_pci.c int spapr_populate_pci_dt(sPAPRPHBState *phb, · line 2234
Quoted 5 lines
hw/ppc/spapr_pci.c +2
-0@@ -2224,6 +2230,8 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb,if (ret) {return ret; } +_FDT (fdt_setprop_cell (fdt, bus_off,"qemu,mem-bar-min-align" , + phb->mem_bar_min_align));
AFAICT the sensible thing to do here is to leave the property out on older machine types. In which case you need an if (phb->mem_bar_min_align) here.
Quoted 15 lines
hw/ppc/spapr_pci.c +0
-0return 0 ; }include/hw/pci-host/spapr.h +1
-0@@ -79,6 +79,7 @@ struct sPAPRPHBState {uint64_t dma64_win_addr;uint32_t numa_node; +uint64_t mem_bar_min_align;/* Fields for migration compatibility hacks */ bool pre_2_8_migration;
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoting David Gibson (2017-02-28 20:56:44)
Quoted 60 lines · Michael Roth
Quoted 59 lines
In certain cases, such as PCI-passthrough with VFIO, we cannot offload MMIO accesses to KVM unless the BAR alignment matches the host. This patch, in conjunction with a separately submitted patch for SLOF which allows for control of this via the device-tree, allows us to set this alignment via QEMU.
Cc Nikunj A Dadhania <[email protected]>Cc David Gibson <[email protected]>Cc Alexey Kardashevskiy <[email protected]>Signed-off-by Michael Roth <[email protected]>--- hw/ppc/spapr.c | 7 ++++++- hw/ppc/spapr_pci.c | 8 ++++++++ include/hw/pci-host/spapr.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-)hw/ppc/spapr.c +6
-1@@ -3121,7 +3121,12 @@ DEFINE_SPAPR_MACHINE(2_9, "2.9", true);* pseries-2.8 */ #define SPAPR_COMPAT_2_8 \ - HW_COMPAT_2_8 + HW_COMPAT_2_8 \ + { \ + .driver = TYPE_SPAPR_PCI_HOST_BRIDGE, \ + .property = "mem_bar_min_align", \ + .value = "0", \ + }, \static void spapr_machine_2_8_instance_options (MachineState *machine) {hw/ppc/spapr_pci.c +6
-0@@ -1660,6 +1660,10 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)return ; } +if (sphb->mem_bar_min_align == (uint64_t )-1 ) { + sphb->mem_bar_min_align = qemu_real_host_page_size; + } + sphb->dtbusname =g_strdup_printf ("pci@%" PRIx64, sphb->buid); namebuf =alloca (strlen (sphb->dtbusname) +32 );@@ -1854,6 +1858,8 @@ static Property spapr_phb_properties[] = {DEFINE_PROP_UINT32 ("numa_node" , sPAPRPHBState, numa_node,-1 ),DEFINE_PROP_BOOL ("pre-2.8-migration" , sPAPRPHBState, pre_2_8_migration, false), +DEFINE_PROP_UINT64 ("mem_bar_min_align" , sPAPRPHBState, mem_bar_min_align, +-1 ), DEFINE_PROP_END_OF_LIST(), };
Quoted 10 lines
hw/ppc/spapr_pci.c int spapr_populate_pci_dt(sPAPRPHBState *phb, · line 2234
Quoted 6 lines
hw/ppc/spapr_pci.c +2
-0@@ -2224,6 +2230,8 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb,if (ret) {return ret; } +_FDT (fdt_setprop_cell (fdt, bus_off,"qemu,mem-bar-min-align" , + phb->mem_bar_min_align));AFAICT the sensible thing to do here is to leave the property out on older machine types. In which case you need an if (
phb->mem_bar_min_align) here.
Yah. On the SLOF side it seemed like 64K was the safer default, which made this more of an override. But that doesn't make much sense unless you're mix-and-matching SLOFs/QEMUs. Will change it for v2.
Quoted 21 lines
Quoted 15 lines
hw/ppc/spapr_pci.c +0
-0return 0 ; }include/hw/pci-host/spapr.h +1
-0@@ -79,6 +79,7 @@ struct sPAPRPHBState {uint64_t dma64_win_addr;uint32_t numa_node; +uint64_t mem_bar_min_align;/* Fields for migration compatibility hacks */ bool pre_2_8_migration;Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson