[libvirt] [PATCH 1/2] qemu: Add SPAPR_VFIO_BRIDGE capability for PPC platform

From: Li Zhang <zhlcindy@linux.vnet.ibm.com> To support VFIO for PPC, it is needed spapr-vfio-pci-host-bridge in QEMU. This patch is to add one capability for it. Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + 2 files changed, 3 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d94188a..7cc02db 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -241,6 +241,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "usb-storage", /* 155 */ "usb-storage.removable", "virtio-mmio", + "spapr-pci-vfio-host-bridge", ); struct _virQEMUCaps { @@ -1391,6 +1392,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "i82801b11-bridge", QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE }, { "usb-storage", QEMU_CAPS_DEVICE_USB_STORAGE }, { "virtio-mmio", QEMU_CAPS_DEVICE_VIRTIO_MMIO }, + { "spapr-pci-vfio-host-bridge", QEMU_CAPS_SPAPR_VFIO_BRIDGE }, }; static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index f3c8fa8..33d303e 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -196,6 +196,7 @@ enum virQEMUCapsFlags { QEMU_CAPS_DEVICE_USB_STORAGE = 155, /* -device usb-storage */ QEMU_CAPS_USB_STORAGE_REMOVABLE = 156, /* usb-storage.removable */ QEMU_CAPS_DEVICE_VIRTIO_MMIO = 157, /* -device virtio-mmio */ + QEMU_CAPS_SPAPR_VFIO_BRIDGE = 158, /* -device spapr-pci-vfio-host-bridge */ QEMU_CAPS_LAST, /* this must always be the last item */ }; -- 1.8.1.4

From: Li Zhang <zhlcindy@linux.vnet.ibm.com> PPC supports VFIO by assigning iommu groups to guests manually. It needs the QEMU command line to support it. The command line is as the following: -device spapr-pci-vfio-host-bridge,iommu=1,id=SOMEBUS,index=123 This patch will get the iommu group by XML configuration, and all these devices in the iommu group need to be detached manually before the guest is created. Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_command.c | 55 ++++++++++++++++++++++++++++++++++++++++++------- src/qemu/qemu_command.h | 3 +++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 1521431..64f6ba0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5368,6 +5368,35 @@ qemuOpenPCIConfig(virDomainHostdevDefPtr dev) } char * +qemuBuildSPAPRVFIODevStr(virDomainHostdevDefPtr dev, + virQEMUCapsPtr qemuCaps) +{ + int iommuGroup; + virPCIDeviceAddressPtr addr; + virBuffer buf = VIR_BUFFER_INITIALIZER; + + addr = (virPCIDeviceAddressPtr)&dev->source.subsys.u.pci.addr; + if ((iommuGroup = virPCIDeviceAddressGetIOMMUGroupNum(addr)) < 0) + goto cleanup; + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPAPR_VFIO_BRIDGE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("SPAPR_VFIO_BRIDGE is not supported by QEMU")); + goto cleanup; + } + + virBufferAddLit(&buf, "spapr-pci-vfio-host-bridge"); + virBufferAsprintf(&buf, ",iommu=%d", iommuGroup); + virBufferAsprintf(&buf, ",id=VFIOBUS%d", iommuGroup); + virBufferAsprintf(&buf, ",index=%d", iommuGroup + 1); + + return virBufferContentAndReset(&buf); + +cleanup: + virBufferFreeAndReset(&buf); + return NULL; +} + +char * qemuBuildPCIHostdevDevStr(virDomainDefPtr def, virDomainHostdevDefPtr dev, const char *configfd, @@ -9221,13 +9250,25 @@ qemuBuildCommandLine(virConnectPtr conn, VIR_COMMAND_PASS_FD_CLOSE_PARENT); } } - virCommandAddArg(cmd, "-device"); - devstr = qemuBuildPCIHostdevDevStr(def, hostdev, configfd_name, qemuCaps); - VIR_FREE(configfd_name); - if (!devstr) - goto error; - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPAPR_VFIO_BRIDGE) && + hostdev->source.subsys.u.pci.backend == + VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO && + def->os.arch == VIR_ARCH_PPC64) { + virCommandAddArg(cmd, "-device"); + devstr = qemuBuildSPAPRVFIODevStr(hostdev, qemuCaps); + if (!devstr) + goto error; + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } else { + virCommandAddArg(cmd, "-device"); + devstr = qemuBuildPCIHostdevDevStr(def, hostdev, configfd_name, qemuCaps); + VIR_FREE(configfd_name); + if (!devstr) + goto error; + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCIDEVICE)) { virCommandAddArg(cmd, "-pcidevice"); if (!(devstr = qemuBuildPCIHostdevPCIDevStr(hostdev))) diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 2f248eb..c764788 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -153,6 +153,9 @@ char * qemuBuildPCIHostdevDevStr(virDomainDefPtr def, virDomainHostdevDefPtr dev, const char *configfd, virQEMUCapsPtr qemuCaps); +char * +qemuBuildSPAPRVFIODevStr(virDomainHostdevDefPtr dev, + virQEMUCapsPtr qemuCaps); int qemuOpenPCIConfig(virDomainHostdevDefPtr dev); -- 1.8.1.4

ping? On 2013年09月16日 15:42, Li Zhang wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
PPC supports VFIO by assigning iommu groups to guests manually. It needs the QEMU command line to support it. The command line is as the following:
-device spapr-pci-vfio-host-bridge,iommu=1,id=SOMEBUS,index=123
This patch will get the iommu group by XML configuration, and all these devices in the iommu group need to be detached manually before the guest is created.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_command.c | 55 ++++++++++++++++++++++++++++++++++++++++++------- src/qemu/qemu_command.h | 3 +++ 2 files changed, 51 insertions(+), 7 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 1521431..64f6ba0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5368,6 +5368,35 @@ qemuOpenPCIConfig(virDomainHostdevDefPtr dev) }
char * +qemuBuildSPAPRVFIODevStr(virDomainHostdevDefPtr dev, + virQEMUCapsPtr qemuCaps) +{ + int iommuGroup; + virPCIDeviceAddressPtr addr; + virBuffer buf = VIR_BUFFER_INITIALIZER; + + addr = (virPCIDeviceAddressPtr)&dev->source.subsys.u.pci.addr; + if ((iommuGroup = virPCIDeviceAddressGetIOMMUGroupNum(addr)) < 0) + goto cleanup; + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPAPR_VFIO_BRIDGE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("SPAPR_VFIO_BRIDGE is not supported by QEMU")); + goto cleanup; + } + + virBufferAddLit(&buf, "spapr-pci-vfio-host-bridge"); + virBufferAsprintf(&buf, ",iommu=%d", iommuGroup); + virBufferAsprintf(&buf, ",id=VFIOBUS%d", iommuGroup); + virBufferAsprintf(&buf, ",index=%d", iommuGroup + 1); + + return virBufferContentAndReset(&buf); + +cleanup: + virBufferFreeAndReset(&buf); + return NULL; +} + +char * qemuBuildPCIHostdevDevStr(virDomainDefPtr def, virDomainHostdevDefPtr dev, const char *configfd, @@ -9221,13 +9250,25 @@ qemuBuildCommandLine(virConnectPtr conn, VIR_COMMAND_PASS_FD_CLOSE_PARENT); } } - virCommandAddArg(cmd, "-device"); - devstr = qemuBuildPCIHostdevDevStr(def, hostdev, configfd_name, qemuCaps); - VIR_FREE(configfd_name); - if (!devstr) - goto error; - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPAPR_VFIO_BRIDGE) && + hostdev->source.subsys.u.pci.backend == + VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO && + def->os.arch == VIR_ARCH_PPC64) { + virCommandAddArg(cmd, "-device"); + devstr = qemuBuildSPAPRVFIODevStr(hostdev, qemuCaps); + if (!devstr) + goto error; + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } else { + virCommandAddArg(cmd, "-device"); + devstr = qemuBuildPCIHostdevDevStr(def, hostdev, configfd_name, qemuCaps); + VIR_FREE(configfd_name); + if (!devstr) + goto error; + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCIDEVICE)) { virCommandAddArg(cmd, "-pcidevice"); if (!(devstr = qemuBuildPCIHostdevPCIDevStr(hostdev))) diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 2f248eb..c764788 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -153,6 +153,9 @@ char * qemuBuildPCIHostdevDevStr(virDomainDefPtr def, virDomainHostdevDefPtr dev, const char *configfd, virQEMUCapsPtr qemuCaps); +char * +qemuBuildSPAPRVFIODevStr(virDomainHostdevDefPtr dev, + virQEMUCapsPtr qemuCaps);
int qemuOpenPCIConfig(virDomainHostdevDefPtr dev);

ping ? On 2013年09月16日 15:42, Li Zhang wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
To support VFIO for PPC, it is needed spapr-vfio-pci-host-bridge in QEMU. This patch is to add one capability for it.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + 2 files changed, 3 insertions(+)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d94188a..7cc02db 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -241,6 +241,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "usb-storage", /* 155 */ "usb-storage.removable", "virtio-mmio", + "spapr-pci-vfio-host-bridge", );
struct _virQEMUCaps { @@ -1391,6 +1392,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "i82801b11-bridge", QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE }, { "usb-storage", QEMU_CAPS_DEVICE_USB_STORAGE }, { "virtio-mmio", QEMU_CAPS_DEVICE_VIRTIO_MMIO }, + { "spapr-pci-vfio-host-bridge", QEMU_CAPS_SPAPR_VFIO_BRIDGE }, };
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index f3c8fa8..33d303e 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -196,6 +196,7 @@ enum virQEMUCapsFlags { QEMU_CAPS_DEVICE_USB_STORAGE = 155, /* -device usb-storage */ QEMU_CAPS_USB_STORAGE_REMOVABLE = 156, /* usb-storage.removable */ QEMU_CAPS_DEVICE_VIRTIO_MMIO = 157, /* -device virtio-mmio */ + QEMU_CAPS_SPAPR_VFIO_BRIDGE = 158, /* -device spapr-pci-vfio-host-bridge */
QEMU_CAPS_LAST, /* this must always be the last item */ };

On 09/16/2013 03:42 AM, Li Zhang wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
To support VFIO for PPC, it is needed spapr-vfio-pci-host-bridge in QEMU. This patch is to add one capability for it.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + 2 files changed, 3 insertions(+)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d94188a..7cc02db 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -241,6 +241,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "usb-storage", /* 155 */ "usb-storage.removable", "virtio-mmio", + "spapr-pci-vfio-host-bridge",
Having no access to the appropriate hardware, I can't verify if this is the correct name for the device or not, but will assume it is. ACK for what you have, but this only detects the capability and exposes it to the commandline generator - it's better to not push something that changes the ABI (the list of capabilities are included when saving/migrating) without also having a patch that demonstrates its utility (and that patch should also add a test case to qemuxml2argvtest)
);
struct _virQEMUCaps { @@ -1391,6 +1392,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "i82801b11-bridge", QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE }, { "usb-storage", QEMU_CAPS_DEVICE_USB_STORAGE }, { "virtio-mmio", QEMU_CAPS_DEVICE_VIRTIO_MMIO }, + { "spapr-pci-vfio-host-bridge", QEMU_CAPS_SPAPR_VFIO_BRIDGE }, };
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index f3c8fa8..33d303e 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -196,6 +196,7 @@ enum virQEMUCapsFlags { QEMU_CAPS_DEVICE_USB_STORAGE = 155, /* -device usb-storage */ QEMU_CAPS_USB_STORAGE_REMOVABLE = 156, /* usb-storage.removable */ QEMU_CAPS_DEVICE_VIRTIO_MMIO = 157, /* -device virtio-mmio */ + QEMU_CAPS_SPAPR_VFIO_BRIDGE = 158, /* -device spapr-pci-vfio-host-bridge */
QEMU_CAPS_LAST, /* this must always be the last item */ };

On 2013年09月23日 17:47, Laine Stump wrote:
From: Li Zhang <zhlcindy@linux.vnet.ibm.com>
To support VFIO for PPC, it is needed spapr-vfio-pci-host-bridge in QEMU. This patch is to add one capability for it.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com> --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + 2 files changed, 3 insertions(+)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d94188a..7cc02db 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -241,6 +241,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "usb-storage", /* 155 */ "usb-storage.removable", "virtio-mmio", + "spapr-pci-vfio-host-bridge", Having no access to the appropriate hardware, I can't verify if this is
On 09/16/2013 03:42 AM, Li Zhang wrote: the correct name for the device or not, but will assume it is.
This name is defined by QEMU, and it's a little long. :)
ACK for what you have, but this only detects the capability and exposes it to the commandline generator - it's better to not push something that changes the ABI (the list of capabilities are included when saving/migrating) without also having a patch that demonstrates its utility (and that patch should also add a test case to qemuxml2argvtest)
OK, I will add one test case for it.
);
struct _virQEMUCaps { @@ -1391,6 +1392,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "i82801b11-bridge", QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE }, { "usb-storage", QEMU_CAPS_DEVICE_USB_STORAGE }, { "virtio-mmio", QEMU_CAPS_DEVICE_VIRTIO_MMIO }, + { "spapr-pci-vfio-host-bridge", QEMU_CAPS_SPAPR_VFIO_BRIDGE }, };
static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index f3c8fa8..33d303e 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -196,6 +196,7 @@ enum virQEMUCapsFlags { QEMU_CAPS_DEVICE_USB_STORAGE = 155, /* -device usb-storage */ QEMU_CAPS_USB_STORAGE_REMOVABLE = 156, /* usb-storage.removable */ QEMU_CAPS_DEVICE_VIRTIO_MMIO = 157, /* -device virtio-mmio */ + QEMU_CAPS_SPAPR_VFIO_BRIDGE = 158, /* -device spapr-pci-vfio-host-bridge */
QEMU_CAPS_LAST, /* this must always be the last item */ };
participants (2)
-
Laine Stump
-
Li Zhang