[RFC v2: vf-token 0/7] Introduce vf-token when using userspace PF

vf token is set by a vfio-pci based PF driver and it must be known to the vfio-pci based VF driver. This vf-token is set by the PF driver before VF drivers can access the device. vfio-pci driver and qemu support vf-token. This RFC patch series adds support to provide the vf-token (uuid format) in the domain XML and to generate the qemu commandline including the vf-token. To support vf-token the new element will be used as follows: <hostdev mode='subsystem' type='pci' managed='yes'> <driver name='vfio'/> <source> <address domain='0x0000' bus='0x0' slot='0x00' function='0x1'> <vf-token uuid='00112233-4455-6677-8899-aabbccddeeff'/> </address> </source> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> </hostdev> The generated commandline will include the following: -device {"driver":"vfio-pci","host":"0000:00:0.1", "vf-token":"00112233-4455-6677-8899-aabbccddeeff", "id":"hostdev0","bus":"pci.0","addr":"0x1"} Changes since initial RFC: 1. Added documentation 2. Added test cases and ran test suite - virtsocketest fails when run with 'ninja test' 3. fixed spaces and uuid string format 4. Used S:vftoken in virJSONValueObjectAdd instead of introducing a conditional Vivek Kashyap (7): virpci: Define vf-token qemu: vf-token capability conf: vf-token flag conf: vf-token parsing and formatting conf: test cases qemu: validate & generate command line doc: doc and news NEWS.rst | 8 +++++ docs/formatdomain.rst | 4 +++ src/conf/device_conf.c | 32 +++++++++++++++-- src/conf/device_conf.h | 3 ++ src/conf/domain_addr.h | 1 + src/conf/domain_conf.c | 8 +++++ src/conf/schemas/basictypes.rng | 7 ++++ src/libvirt_private.syms | 1 + src/qemu/qemu_capabilities.c | 3 ++ src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 13 +++++++ src/qemu/qemu_domain_address.c | 3 ++ src/qemu/qemu_validate.c | 20 +++++++++++ src/util/virpci.c | 7 ++++ src/util/virpci.h | 12 +++++++ .../qemucapabilitiesdata/caps_8.1.0_s390x.xml | 1 + .../caps_8.1.0_x86_64.xml | 1 + .../caps_8.2.0_x86_64.xml | 1 + .../hostdev-vfio-vf-token.x86_64-latest.args | 34 +++++++++++++++++++ .../hostdev-vfio-vf-token.xml | 22 ++++++++++++ tests/qemuxml2argvtest.c | 1 + 21 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-vf-token.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-vf-token.xml -- 2.25.1

Define the vf-token extension for PCI device Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> --- src/util/virpci.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/util/virpci.h b/src/util/virpci.h index faca6cf6f9..f080fceb97 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -50,7 +50,15 @@ struct _virZPCIDeviceAddress { /* Don't forget to update virPCIDeviceAddressCopy if needed. */ }; +typedef struct _virPCIDeviceToken virPCIDeviceToken; + +struct _virPCIDeviceToken { + unsigned char uuid[VIR_UUID_BUFLEN]; + bool isSet; +}; + #define VIR_PCI_DEVICE_ADDRESS_FMT "%04x:%02x:%02x.%d" +#define VIR_PCI_DEVICE_TOKEN_FMT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" /* Represents format of PF's phys_port_name in switchdev mode: * 'p%u' or 'p%us%u'. New line checked since value is read from sysfs file. @@ -65,6 +73,7 @@ struct _virPCIDeviceAddress { virTristateSwitch multi; int extFlags; /* enum virPCIDeviceAddressExtensionFlags */ virZPCIDeviceAddress zpci; + virPCIDeviceToken token; /* Don't forget to update virPCIDeviceAddressCopy if needed. */ }; -- 2.25.1

Introduce qemu capability for vf-token Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> --- src/qemu/qemu_capabilities.c | 3 +++ src/qemu/qemu_capabilities.h | 1 + 2 files changed, 4 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 83119e871a..f4cacd48d0 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -698,6 +698,7 @@ VIR_ENUM_IMPL(virQEMUCaps, /* 450 */ "run-with.async-teardown", /* QEMU_CAPS_RUN_WITH_ASYNC_TEARDOWN */ "virtio-blk-vhost-vdpa", /* QEMU_CAPS_DEVICE_VIRTIO_BLK_VHOST_VDPA */ + "vf-token", /* QEMU_CAPS_VFIO_VFTOKEN */ ); @@ -1385,6 +1386,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "virtio-crypto-device", QEMU_CAPS_DEVICE_VIRTIO_CRYPTO }, { "cryptodev-backend-lkcf", QEMU_CAPS_OBJECT_CRYPTO_LKCF }, { "pvpanic-pci", QEMU_CAPS_DEVICE_PANIC_PCI }, + { "vf-token", QEMU_CAPS_VFIO_VFTOKEN }, }; @@ -1447,6 +1449,7 @@ static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsVirtioSCSI[] = { }; static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsVfioPCI[] = { + { "vf-token", QEMU_CAPS_VFIO_VFTOKEN, NULL }, }; static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsSCSIDisk[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 3c4f7f625b..f97b1c9fd5 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -677,6 +677,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for syntax-check */ /* 450 */ QEMU_CAPS_RUN_WITH_ASYNC_TEARDOWN, /* asynchronous teardown -run-with async-teardown=on|off */ QEMU_CAPS_DEVICE_VIRTIO_BLK_VHOST_VDPA, /* virtio-blk-vhost-vdpa block driver */ + QEMU_CAPS_VFIO_VFTOKEN, /* vf-token support */ QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; -- 2.25.1

Please change the subject/summary to: qemu: capabilities: Introduce QEMU_CAPS_VFIO_VFTOKEN capability On Wed, Nov 29, 2023 at 21:07:22 -0700, Vivek Kashyap wrote:
Introduce qemu capability for vf-token
Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> --- src/qemu/qemu_capabilities.c | 3 +++ src/qemu/qemu_capabilities.h | 1 + 2 files changed, 4 insertions(+)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 83119e871a..f4cacd48d0 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -698,6 +698,7 @@ VIR_ENUM_IMPL(virQEMUCaps, /* 450 */ "run-with.async-teardown", /* QEMU_CAPS_RUN_WITH_ASYNC_TEARDOWN */ "virtio-blk-vhost-vdpa", /* QEMU_CAPS_DEVICE_VIRTIO_BLK_VHOST_VDPA */ + "vf-token", /* QEMU_CAPS_VFIO_VFTOKEN */ );
@@ -1385,6 +1386,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "virtio-crypto-device", QEMU_CAPS_DEVICE_VIRTIO_CRYPTO }, { "cryptodev-backend-lkcf", QEMU_CAPS_OBJECT_CRYPTO_LKCF }, { "pvpanic-pci", QEMU_CAPS_DEVICE_PANIC_PCI }, + { "vf-token", QEMU_CAPS_VFIO_VFTOKEN }, };
@@ -1447,6 +1449,7 @@ static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsVirtioSCSI[] = { };
static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsVfioPCI[] = { + { "vf-token", QEMU_CAPS_VFIO_VFTOKEN, NULL }, };
static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsSCSIDisk[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 3c4f7f625b..f97b1c9fd5 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -677,6 +677,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for syntax-check */ /* 450 */ QEMU_CAPS_RUN_WITH_ASYNC_TEARDOWN, /* asynchronous teardown -run-with async-teardown=on|off */ QEMU_CAPS_DEVICE_VIRTIO_BLK_VHOST_VDPA, /* virtio-blk-vhost-vdpa block driver */ + QEMU_CAPS_VFIO_VFTOKEN, /* vf-token support */
As pointed out the last time: https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/message/KSKO... after this patch the test suite fails: 224/322 libvirt:bin / qemucapabilitiestest FAIL 1.30s exit status 1
MALLOC_PERTURB_=96 abs_top_srcdir=/home/pipo/libvirt abs_srcdir=/home/pipo/libvirt/tests abs_builddir=/home/pipo/build/libvirt/gcc/tests VIR_TEST_EXPENSIVE=0 LC_ALL=C LD_LIBRARY_PATH=/home/pipo/build/libvirt/gcc/src:/home/pipo/build/libvirt/gcc/tests G_DEBUG=fatal-warnings LIBVIRT_AUTOSTART=0 abs_top_builddir=/home/pipo/build/libvirt/gcc /home/pipo/build/libvirt/gcc/tests/qemucapabilitiestest ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ✀ ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― stderr: TEST: qemucapabilitiestest ..........................!.......!..... 40 ............................!... 72 FAIL 3 tests failed. Run them using: VIR_TEST_DEBUG=1 VIR_TEST_RANGE=27,35,69 /home/pipo/build/libvirt/gcc/tests/qemucapabilitiestest
as you didn't include the required output file updates here. I also explicitly noted that it's required to be done so that the test suite passes after every commit and I've also noted how to do it. In your next post please make sure to address all feedback.

Define PCI address extension flag for vf-token Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> --- src/conf/domain_addr.h | 1 + src/qemu/qemu_domain_address.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index e72fb48847..29e7257177 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -29,6 +29,7 @@ typedef enum { VIR_PCI_ADDRESS_EXTENSION_NONE = 0, /* no extension */ VIR_PCI_ADDRESS_EXTENSION_ZPCI = 1 << 0, /* zPCI support */ + VIR_PCI_ADDRESS_EXTENSION_VFTOKEN = 1 << 1, /* VF token support */ } virPCIDeviceAddressExtensionFlags; typedef enum { diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 099778b2a8..3be5acbc9e 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -575,6 +575,9 @@ qemuDomainDeviceCalculatePCIAddressExtensionFlags(virQEMUCaps *qemuCaps, extFlags |= VIR_PCI_ADDRESS_EXTENSION_ZPCI; } + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VFIO_VFTOKEN)) + extFlags |= VIR_PCI_ADDRESS_EXTENSION_VFTOKEN; + return extFlags; } -- 2.25.1

XML parsing and formatting of vf-token attribute Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> --- src/conf/device_conf.c | 32 ++++++++++++++++++++++++++++++-- src/conf/device_conf.h | 3 +++ src/conf/domain_conf.c | 8 ++++++++ src/conf/schemas/basictypes.rng | 7 +++++++ src/libvirt_private.syms | 1 + src/util/virpci.c | 7 +++++++ src/util/virpci.h | 3 +++ 7 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index f3d977f2b7..f365e98bfd 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -188,11 +188,20 @@ virDeviceInfoPCIAddressExtensionIsWanted(const virDomainDeviceInfo *info) virZPCIDeviceAddressIsIncomplete(&info->addr.pci.zpci); } +bool +virDeviceExtensionIsPresent(const virPCIDeviceAddress *pci) +{ + return (((pci->extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) && + virZPCIDeviceAddressIsPresent(&pci->zpci)) || + ((pci->extFlags & VIR_PCI_ADDRESS_EXTENSION_VFTOKEN) && + pci->token.isSet)); +} + bool virDeviceInfoPCIAddressExtensionIsPresent(const virDomainDeviceInfo *info) { - return (info->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) && - virZPCIDeviceAddressIsPresent(&info->addr.pci.zpci); + return (info->addr.pci.extFlags != VIR_PCI_ADDRESS_EXTENSION_NONE) && + virDeviceExtensionIsPresent(&info->addr.pci); } int @@ -200,6 +209,7 @@ virPCIDeviceAddressParseXML(xmlNodePtr node, virPCIDeviceAddress *addr) { xmlNodePtr zpci; + xmlNodePtr token; memset(addr, 0, sizeof(*addr)); @@ -231,6 +241,11 @@ virPCIDeviceAddressParseXML(xmlNodePtr node, return -1; } + if ((token = virXMLNodeGetSubelement(node, "vf-token"))) { + if (virPCIDeviceTokenParseXML(token, addr) < 0) + return -1; + } + return 0; } @@ -248,6 +263,19 @@ virPCIDeviceAddressFormat(virBuffer *buf, addr.function); } +int +virPCIDeviceTokenParseXML(xmlNodePtr node, + virPCIDeviceAddress *addr) +{ + if (virXMLPropUUID(node, "uuid", VIR_XML_PROP_NONE, + addr->token.uuid) < 0) + return -1; + + addr->token.isSet = 1; + + return 0; +} + int virCCWDeviceAddressParseXML(xmlNodePtr node, virCCWDeviceAddress *addr) diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index a83377417a..a37ee29b88 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -188,6 +188,9 @@ bool virDeviceInfoPCIAddressExtensionIsPresent(const virDomainDeviceInfo *info); int virPCIDeviceAddressParseXML(xmlNodePtr node, virPCIDeviceAddress *addr); +int virPCIDeviceTokenParseXML(xmlNodePtr node, + virPCIDeviceAddress *addr); + void virPCIDeviceAddressFormat(virBuffer *buf, virPCIDeviceAddress addr, bool includeTypeInAddr); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 22ad43e1d7..8bda81815a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5403,6 +5403,14 @@ virDomainDeviceInfoFormat(virBuffer *buf, info->addr.pci.zpci.uid.value, info->addr.pci.zpci.fid.value); } + + if (virPCIVFIOTokenIDIsPresent(&info->addr.pci.token)) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + virBufferAsprintf(&childBuf, "<vf-token uuid='%s'/>\n", + virUUIDFormat(info->addr.pci.token.uuid, + uuidstr)); + } break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE: diff --git a/src/conf/schemas/basictypes.rng b/src/conf/schemas/basictypes.rng index 26eb538077..bbb7484430 100644 --- a/src/conf/schemas/basictypes.rng +++ b/src/conf/schemas/basictypes.rng @@ -121,6 +121,13 @@ <ref name="virOnOff"/> </attribute> </optional> + <optional> + <element name="vf-token"> + <attribute name="uuid"> + <ref name="UUID"/> + </attribute> + </element> + </optional> </define> <define name="zpciaddress"> <optional> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 553b01b8c0..0726ae6622 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3137,6 +3137,7 @@ virPCIHeaderTypeToString; virPCIIsVirtualFunction; virPCIStubDriverTypeFromString; virPCIStubDriverTypeToString; +virPCIVFIOTokenIDIsPresent; virPCIVirtualFunctionListFree; virZPCIDeviceAddressIsIncomplete; virZPCIDeviceAddressIsPresent; diff --git a/src/util/virpci.c b/src/util/virpci.c index baacde4c14..2aca144e85 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2313,6 +2313,13 @@ virZPCIDeviceAddressIsPresent(const virZPCIDeviceAddress *addr) } +bool +virPCIVFIOTokenIDIsPresent(const virPCIDeviceToken *token) +{ + return token->isSet; +} + + void virPCIVirtualFunctionListFree(virPCIVirtualFunctionList *list) { diff --git a/src/util/virpci.h b/src/util/virpci.h index f080fceb97..2d49bbd53f 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -279,6 +279,9 @@ int virPCIDeviceAddressParse(char *address, virPCIDeviceAddress *bdf); bool virZPCIDeviceAddressIsIncomplete(const virZPCIDeviceAddress *addr); bool virZPCIDeviceAddressIsPresent(const virZPCIDeviceAddress *addr); +bool virPCIVFIOTokenIDIsPresent(const virPCIDeviceToken *token); +bool virDeviceExtensionIsPresent(const virPCIDeviceAddress *pci); + int virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path, int pfNetDevIdx, char **pfname, -- 2.25.1

On Wed, Nov 29, 2023 at 21:07:24 -0700, Vivek Kashyap wrote:
XML parsing and formatting of vf-token attribute
Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> --- src/conf/device_conf.c | 32 ++++++++++++++++++++++++++++++-- src/conf/device_conf.h | 3 +++ src/conf/domain_conf.c | 8 ++++++++ src/conf/schemas/basictypes.rng | 7 +++++++ src/libvirt_private.syms | 1 + src/util/virpci.c | 7 +++++++ src/util/virpci.h | 3 +++ 7 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index f3d977f2b7..f365e98bfd 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -188,11 +188,20 @@ virDeviceInfoPCIAddressExtensionIsWanted(const virDomainDeviceInfo *info) virZPCIDeviceAddressIsIncomplete(&info->addr.pci.zpci); }
+bool +virDeviceExtensionIsPresent(const virPCIDeviceAddress *pci) +{ + return (((pci->extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) && + virZPCIDeviceAddressIsPresent(&pci->zpci)) || + ((pci->extFlags & VIR_PCI_ADDRESS_EXTENSION_VFTOKEN) && + pci->token.isSet)); +} + bool virDeviceInfoPCIAddressExtensionIsPresent(const virDomainDeviceInfo *info) { - return (info->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) && - virZPCIDeviceAddressIsPresent(&info->addr.pci.zpci); + return (info->addr.pci.extFlags != VIR_PCI_ADDRESS_EXTENSION_NONE) && + virDeviceExtensionIsPresent(&info->addr.pci); }
Fixes to coding style requested before: https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/message/46WY... were not addressed. Note that reviews aren't an easy task an thus not addressing all feedback may deter reviewers from a timely look at your next postings.
int @@ -200,6 +209,7 @@ virPCIDeviceAddressParseXML(xmlNodePtr node, virPCIDeviceAddress *addr) { xmlNodePtr zpci; + xmlNodePtr token;
memset(addr, 0, sizeof(*addr));
@@ -231,6 +241,11 @@ virPCIDeviceAddressParseXML(xmlNodePtr node, return -1; }
+ if ((token = virXMLNodeGetSubelement(node, "vf-token"))) { + if (virPCIDeviceTokenParseXML(token, addr) < 0) + return -1; + } + return 0; }
@@ -248,6 +263,19 @@ virPCIDeviceAddressFormat(virBuffer *buf, addr.function); }
+int
No need to export this function, as it's used just in this file. Place it properly and make it static.
+virPCIDeviceTokenParseXML(xmlNodePtr node, + virPCIDeviceAddress *addr) +{ + if (virXMLPropUUID(node, "uuid", VIR_XML_PROP_NONE, + addr->token.uuid) < 0) + return -1; + + addr->token.isSet = 1; + + return 0; +} + int virCCWDeviceAddressParseXML(xmlNodePtr node, virCCWDeviceAddress *addr) diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index a83377417a..a37ee29b88 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -188,6 +188,9 @@ bool virDeviceInfoPCIAddressExtensionIsPresent(const virDomainDeviceInfo *info); int virPCIDeviceAddressParseXML(xmlNodePtr node, virPCIDeviceAddress *addr);
+int virPCIDeviceTokenParseXML(xmlNodePtr node, + virPCIDeviceAddress *addr); +
Drop this hunk.
void virPCIDeviceAddressFormat(virBuffer *buf, virPCIDeviceAddress addr, bool includeTypeInAddr); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 22ad43e1d7..8bda81815a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5403,6 +5403,14 @@ virDomainDeviceInfoFormat(virBuffer *buf, info->addr.pci.zpci.uid.value, info->addr.pci.zpci.fid.value); } + + if (virPCIVFIOTokenIDIsPresent(&info->addr.pci.token)) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + virBufferAsprintf(&childBuf, "<vf-token uuid='%s'/>\n", + virUUIDFormat(info->addr.pci.token.uuid, + uuidstr)); + } break;
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE: diff --git a/src/conf/schemas/basictypes.rng b/src/conf/schemas/basictypes.rng index 26eb538077..bbb7484430 100644 --- a/src/conf/schemas/basictypes.rng +++ b/src/conf/schemas/basictypes.rng @@ -121,6 +121,13 @@ <ref name="virOnOff"/> </attribute> </optional> + <optional> + <element name="vf-token"> + <attribute name="uuid"> + <ref name="UUID"/> + </attribute> + </element> + </optional> </define> <define name="zpciaddress"> <optional>
And move the documentation from the last patch to this one.

On Thu, Nov 30, 2023 at 09:36:00 +0100, Peter Krempa wrote:
On Wed, Nov 29, 2023 at 21:07:24 -0700, Vivek Kashyap wrote:
XML parsing and formatting of vf-token attribute
Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> --- src/conf/device_conf.c | 32 ++++++++++++++++++++++++++++++-- src/conf/device_conf.h | 3 +++ src/conf/domain_conf.c | 8 ++++++++ src/conf/schemas/basictypes.rng | 7 +++++++ src/libvirt_private.syms | 1 + src/util/virpci.c | 7 +++++++ src/util/virpci.h | 3 +++ 7 files changed, 59 insertions(+), 2 deletions(-)
[...]
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 22ad43e1d7..8bda81815a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5403,6 +5403,14 @@ virDomainDeviceInfoFormat(virBuffer *buf, info->addr.pci.zpci.uid.value, info->addr.pci.zpci.fid.value); } + + if (virPCIVFIOTokenIDIsPresent(&info->addr.pci.token)) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + virBufferAsprintf(&childBuf, "<vf-token uuid='%s'/>\n", + virUUIDFormat(info->addr.pci.token.uuid, + uuidstr));
Also this is the wrong place to format this data. This function formats the frontend address. You are parsing the token inside the <source><address> sub-element. Also add a qemuxml2xmltest case with the same input to make sure you actually test it.
+ } break;
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE:

Add related test cases Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> Signed-off-by: Ciara Loftus <ciara.loftus@intel.com> --- .../qemucapabilitiesdata/caps_8.1.0_s390x.xml | 1 + .../caps_8.1.0_x86_64.xml | 1 + .../caps_8.2.0_x86_64.xml | 1 + .../hostdev-vfio-vf-token.x86_64-latest.args | 34 +++++++++++++++++++ .../hostdev-vfio-vf-token.xml | 22 ++++++++++++ tests/qemuxml2argvtest.c | 1 + 6 files changed, 60 insertions(+) create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-vf-token.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-vf-token.xml diff --git a/tests/qemucapabilitiesdata/caps_8.1.0_s390x.xml b/tests/qemucapabilitiesdata/caps_8.1.0_s390x.xml index 427ee9d5c7..f4a65a133f 100644 --- a/tests/qemucapabilitiesdata/caps_8.1.0_s390x.xml +++ b/tests/qemucapabilitiesdata/caps_8.1.0_s390x.xml @@ -112,6 +112,7 @@ <flag name='rbd-encryption-layering'/> <flag name='rbd-encryption-luks-any'/> <flag name='run-with.async-teardown'/> + <flag name='vf-token'/> <version>8000050</version> <microcodeVersion>39100245</microcodeVersion> <package>v8.0.0-1270-g1c12355b</package> diff --git a/tests/qemucapabilitiesdata/caps_8.1.0_x86_64.xml b/tests/qemucapabilitiesdata/caps_8.1.0_x86_64.xml index d266dd0f31..202a2c7f8d 100644 --- a/tests/qemucapabilitiesdata/caps_8.1.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_8.1.0_x86_64.xml @@ -198,6 +198,7 @@ <flag name='qcow2-discard-no-unref'/> <flag name='run-with.async-teardown'/> <flag name='virtio-blk-vhost-vdpa'/> + <flag name='vf-token'/> <version>8001000</version> <microcodeVersion>43100245</microcodeVersion> <package>v8.1.0</package> diff --git a/tests/qemucapabilitiesdata/caps_8.2.0_x86_64.xml b/tests/qemucapabilitiesdata/caps_8.2.0_x86_64.xml index ef3bd14597..24809ab70f 100644 --- a/tests/qemucapabilitiesdata/caps_8.2.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_8.2.0_x86_64.xml @@ -199,6 +199,7 @@ <flag name='qcow2-discard-no-unref'/> <flag name='run-with.async-teardown'/> <flag name='virtio-blk-vhost-vdpa'/> + <flag name='vf-token'/> <version>8001050</version> <microcodeVersion>43100246</microcodeVersion> <package>v8.1.0-3111-gad6ef0a42e</package> diff --git a/tests/qemuxml2argvdata/hostdev-vfio-vf-token.x86_64-latest.args b/tests/qemuxml2argvdata/hostdev-vfio-vf-token.x86_64-latest.args new file mode 100644 index 0000000000..e449c84ea9 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-vfio-vf-token.x86_64-latest.args @@ -0,0 +1,34 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=off,dump-guest-core=off,memory-backend=pc.ram,acpi=off \ +-accel tcg \ +-cpu qemu64 \ +-m size=219136k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-boot strict=on \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-device '{"driver":"vfio-pci","host":"0000:00:00.0","vf-token":"00112233-4455-6677-8899-aabbccddeeff","id":"hostdev0","bus":"pci.0","addr":"0x8"}' \ +-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}' \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/hostdev-vfio-vf-token.xml b/tests/qemuxml2argvdata/hostdev-vfio-vf-token.xml new file mode 100644 index 0000000000..87dddd762a --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-vfio-vf-token.xml @@ -0,0 +1,22 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory>219100</memory> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <controller type='pci' index='0' model='pci-root'/> + <hostdev mode='subsystem' type='pci' managed='no'> + <driver name='vfio'/> + <source> + <address domain='0x0000' bus='0x00' slot='0x00' function='0x0'> + <vf-token uuid='00112233-4455-6677-8899-aabbccddeeff'/> + </address> + </source> + <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/> + </hostdev> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index b2ea2191dc..20bc914748 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1547,6 +1547,7 @@ mymain(void) DO_TEST_CAPS_LATEST_PARSE_ERROR("hostdev-pci-duplicate"); DO_TEST_CAPS_LATEST("hostdev-vfio"); DO_TEST_CAPS_LATEST("hostdev-vfio-multidomain"); + DO_TEST_CAPS_LATEST("hostdev-vfio-vf-token"); DO_TEST_CAPS_LATEST("hostdev-mdev-precreated"); DO_TEST_CAPS_LATEST_PARSE_ERROR("hostdev-mdev-src-address-invalid"); DO_TEST_CAPS_LATEST_PARSE_ERROR("hostdev-mdev-invalid-target-address"); -- 2.25.1

On Wed, Nov 29, 2023 at 21:07:25 -0700, Vivek Kashyap wrote:
Add related test cases
Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> Signed-off-by: Ciara Loftus <ciara.loftus@intel.com> --- .../qemucapabilitiesdata/caps_8.1.0_s390x.xml | 1 + .../caps_8.1.0_x86_64.xml | 1 + .../caps_8.2.0_x86_64.xml | 1 + .../hostdev-vfio-vf-token.x86_64-latest.args | 34 +++++++++++++++++++ .../hostdev-vfio-vf-token.xml | 22 ++++++++++++ tests/qemuxml2argvtest.c | 1 + 6 files changed, 60 insertions(+) create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-vf-token.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-vf-token.xml
diff --git a/tests/qemucapabilitiesdata/caps_8.1.0_s390x.xml b/tests/qemucapabilitiesdata/caps_8.1.0_s390x.xml index 427ee9d5c7..f4a65a133f 100644 --- a/tests/qemucapabilitiesdata/caps_8.1.0_s390x.xml +++ b/tests/qemucapabilitiesdata/caps_8.1.0_s390x.xml @@ -112,6 +112,7 @@ <flag name='rbd-encryption-layering'/> <flag name='rbd-encryption-luks-any'/> <flag name='run-with.async-teardown'/> + <flag name='vf-token'/> <version>8000050</version> <microcodeVersion>39100245</microcodeVersion> <package>v8.0.0-1270-g1c12355b</package> diff --git a/tests/qemucapabilitiesdata/caps_8.1.0_x86_64.xml b/tests/qemucapabilitiesdata/caps_8.1.0_x86_64.xml index d266dd0f31..202a2c7f8d 100644 --- a/tests/qemucapabilitiesdata/caps_8.1.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_8.1.0_x86_64.xml @@ -198,6 +198,7 @@ <flag name='qcow2-discard-no-unref'/> <flag name='run-with.async-teardown'/> <flag name='virtio-blk-vhost-vdpa'/> + <flag name='vf-token'/> <version>8001000</version> <microcodeVersion>43100245</microcodeVersion> <package>v8.1.0</package> diff --git a/tests/qemucapabilitiesdata/caps_8.2.0_x86_64.xml b/tests/qemucapabilitiesdata/caps_8.2.0_x86_64.xml index ef3bd14597..24809ab70f 100644 --- a/tests/qemucapabilitiesdata/caps_8.2.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_8.2.0_x86_64.xml @@ -199,6 +199,7 @@ <flag name='qcow2-discard-no-unref'/> <flag name='run-with.async-teardown'/> <flag name='virtio-blk-vhost-vdpa'/> + <flag name='vf-token'/> <version>8001050</version> <microcodeVersion>43100246</microcodeVersion> <package>v8.1.0-3111-gad6ef0a42e</package>
As noted, these belong to 2/7, otherwise tests fail after that commit ...
diff --git a/tests/qemuxml2argvdata/hostdev-vfio-vf-token.x86_64-latest.args b/tests/qemuxml2argvdata/hostdev-vfio-vf-token.x86_64-latest.args new file mode 100644 index 0000000000..e449c84ea9 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-vfio-vf-token.x86_64-latest.args @@ -0,0 +1,34 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=off,dump-guest-core=off,memory-backend=pc.ram,acpi=off \ +-accel tcg \ +-cpu qemu64 \ +-m size=219136k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-boot strict=on \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-device '{"driver":"vfio-pci","host":"0000:00:00.0","vf-token":"00112233-4455-6677-8899-aabbccddeeff","id":"hostdev0","bus":"pci.0","addr":"0x8"}' \ +-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}' \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ +-msg timestamp=on
... and this MUST come after 6/7 otherwise testsuite fails on this patch.
diff --git a/tests/qemuxml2argvdata/hostdev-vfio-vf-token.xml b/tests/qemuxml2argvdata/hostdev-vfio-vf-token.xml new file mode 100644 index 0000000000..87dddd762a --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-vfio-vf-token.xml @@ -0,0 +1,22 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory>219100</memory> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <controller type='pci' index='0' model='pci-root'/> + <hostdev mode='subsystem' type='pci' managed='no'> + <driver name='vfio'/> + <source> + <address domain='0x0000' bus='0x00' slot='0x00' function='0x0'> + <vf-token uuid='00112233-4455-6677-8899-aabbccddeeff'/> + </address> + </source> + <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/> + </hostdev> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index b2ea2191dc..20bc914748 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1547,6 +1547,7 @@ mymain(void) DO_TEST_CAPS_LATEST_PARSE_ERROR("hostdev-pci-duplicate"); DO_TEST_CAPS_LATEST("hostdev-vfio"); DO_TEST_CAPS_LATEST("hostdev-vfio-multidomain"); + DO_TEST_CAPS_LATEST("hostdev-vfio-vf-token"); DO_TEST_CAPS_LATEST("hostdev-mdev-precreated"); DO_TEST_CAPS_LATEST_PARSE_ERROR("hostdev-mdev-src-address-invalid"); DO_TEST_CAPS_LATEST_PARSE_ERROR("hostdev-mdev-invalid-target-address"); -- 2.25.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org

Introduce a validation function for vf-token support in qemu and generate vf-token device attribute in qemu command line Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> --- src/qemu/qemu_command.c | 13 +++++++++++++ src/qemu/qemu_validate.c | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d54149ed2d..c8b8c37ff9 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4710,6 +4710,7 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def, pcisrc->addr.slot, pcisrc->addr.function); const char *failover_pair_id = NULL; + g_autofree char *token = NULL; /* caller has to assign proper passthrough backend type */ switch (pcisrc->backend) { @@ -4736,9 +4737,21 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def, teaming->persistent) failover_pair_id = teaming->persistent; + if ((dev->info->pciAddrExtFlags & VIR_PCI_ADDRESS_EXTENSION_VFTOKEN) && + pcisrc->addr.token.isSet) { + const unsigned char *uuid = pcisrc->addr.token.uuid; + + token = g_strdup_printf(VIR_PCI_DEVICE_TOKEN_FMT, + uuid[0], uuid[1], uuid[2], uuid[3], + uuid[4], uuid[5], uuid[6], uuid[7], + uuid[8], uuid[9], uuid[10], uuid[11], + uuid[12], uuid[13], uuid[14], uuid[15]); + } + if (virJSONValueObjectAdd(&props, "s:driver", "vfio-pci", "s:host", host, + "S:vf-token", token, "s:id", dev->info->alias, "p:bootindex", dev->info->effectiveBootIndex, "S:failover_pair_id", failover_pair_id, diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index e475ad035e..13114ca3d1 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1364,6 +1364,24 @@ qemuValidateDomainDeviceDefZPCIAddress(virDomainDeviceInfo *info, } +static int +qemuValidateDomainDeviceDefVFTokenId(virDomainDeviceInfo *info, + virQEMUCaps *qemuCaps) +{ + virPCIDeviceToken *vftoken = &info->addr.pci.token; + + if (virPCIVFIOTokenIDIsPresent(vftoken) && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VFIO_VFTOKEN)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", + _("This QEMU binary doesn't support vf token ids")); + return -1; + } + + return 0; +} + + static int qemuValidateDomainDeviceDefAddressDrive(virDomainDeviceInfo *info, const virDomainDef *def, @@ -1483,6 +1501,8 @@ qemuValidateDomainDeviceDefAddress(const virDomainDeviceDef *dev, case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: if (qemuValidateDomainDeviceDefZPCIAddress(info, qemuCaps) < 0) return -1; + if (qemuValidateDomainDeviceDefVFTokenId(info, qemuCaps) < 0) + return -1; break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: -- 2.25.1

On Wed, Nov 29, 2023 at 21:07:26 -0700, Vivek Kashyap wrote:
Introduce a validation function for vf-token support in qemu and generate vf-token device attribute in qemu command line
Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> --- src/qemu/qemu_command.c | 13 +++++++++++++ src/qemu/qemu_validate.c | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d54149ed2d..c8b8c37ff9 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4710,6 +4710,7 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def, pcisrc->addr.slot, pcisrc->addr.function); const char *failover_pair_id = NULL; + g_autofree char *token = NULL;
/* caller has to assign proper passthrough backend type */ switch (pcisrc->backend) { @@ -4736,9 +4737,21 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def, teaming->persistent) failover_pair_id = teaming->persistent;
+ if ((dev->info->pciAddrExtFlags & VIR_PCI_ADDRESS_EXTENSION_VFTOKEN) && + pcisrc->addr.token.isSet) {
Broken coding style. I've pointed it out last time: https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/message/RBIW...
+ const unsigned char *uuid = pcisrc->addr.token.uuid; + + token = g_strdup_printf(VIR_PCI_DEVICE_TOKEN_FMT,
So VIR_PCI_DEVICE_TOKEN_FMT is: "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" virUUIDFormat uses: "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" Thus the exactly same format string. So use virUUIDFromat here rather than reimplementing it. Hint: token = g_strdup(virUUIDFormat(pcisrc->addr.token.uuid, uuidstrbuf));
+ uuid[0], uuid[1], uuid[2], uuid[3], + uuid[4], uuid[5], uuid[6], uuid[7], + uuid[8], uuid[9], uuid[10], uuid[11], + uuid[12], uuid[13], uuid[14], uuid[15]); + } + if (virJSONValueObjectAdd(&props, "s:driver", "vfio-pci", "s:host", host, + "S:vf-token", token, "s:id", dev->info->alias, "p:bootindex", dev->info->effectiveBootIndex, "S:failover_pair_id", failover_pair_id, diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index e475ad035e..13114ca3d1 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1364,6 +1364,24 @@ qemuValidateDomainDeviceDefZPCIAddress(virDomainDeviceInfo *info, }
+static int +qemuValidateDomainDeviceDefVFTokenId(virDomainDeviceInfo *info, + virQEMUCaps *qemuCaps) +{ + virPCIDeviceToken *vftoken = &info->addr.pci.token; + + if (virPCIVFIOTokenIDIsPresent(vftoken) && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VFIO_VFTOKEN)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", + _("This QEMU binary doesn't support vf token ids")); + return -1; + } + + return 0; +} + + static int qemuValidateDomainDeviceDefAddressDrive(virDomainDeviceInfo *info, const virDomainDef *def, @@ -1483,6 +1501,8 @@ qemuValidateDomainDeviceDefAddress(const virDomainDeviceDef *dev, case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: if (qemuValidateDomainDeviceDefZPCIAddress(info, qemuCaps) < 0) return -1; + if (qemuValidateDomainDeviceDefVFTokenId(info, qemuCaps) < 0) + return -1; break;
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: -- 2.25.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org

Update documentation and information about vf-token Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> --- NEWS.rst | 8 ++++++++ docs/formatdomain.rst | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index f12734c2a1..3fb0230e71 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -22,6 +22,14 @@ v9.10.0 (unreleased) The QEMU hypervisor driver now allows setting ``pipewire`` backend for ``<audio/>`` device. + * qemu: support VF tokens for vfio-pci + + "vf-token",implemented as a UUID, is a shared secret between userspace + vfio-based PF and VF drivers. The token is set by the PF driver and is part + of the device matching by the VF driver. The vfio vf-token uuid is + included in the VM XML specification for the pci device, and the token is + passed in qemu commandline on VM launch. + * **Improvements** * **Bug fixes** diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 310d2bc427..08d7540de5 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3744,6 +3744,10 @@ control where on the bus the device will be placed: between 0x0001 and 0xffff, inclusive), and ``fid`` (a hex value between 0x00000000 and 0xffffffff, inclusive) used by PCI devices on S390 for User-defined Identifiers and Function Identifiers. + :since:'Since 8.1.0`, the vf-token element is supported in uuid format. The + vf-token is a shared secret between userspace vfio-pci PF driver and VF + driver. The token is set by the PF driver, and must be provided for VF + access. :since:`Since 1.3.5` , some hypervisor drivers may accept an ``<address type='pci'/>`` element with no other attributes as an explicit request to assign a PCI address for the device rather than some other type of -- 2.25.1

On Wed, Nov 29, 2023 at 21:07:27 -0700, Vivek Kashyap wrote:
Update documentation and information about vf-token
Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> --- NEWS.rst | 8 ++++++++ docs/formatdomain.rst | 4 ++++ 2 files changed, 12 insertions(+)
diff --git a/NEWS.rst b/NEWS.rst index f12734c2a1..3fb0230e71 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -22,6 +22,14 @@ v9.10.0 (unreleased) The QEMU hypervisor driver now allows setting ``pipewire`` backend for ``<audio/>`` device.
+ * qemu: support VF tokens for vfio-pci + + "vf-token",implemented as a UUID, is a shared secret between userspace + vfio-based PF and VF drivers. The token is set by the PF driver and is part + of the device matching by the VF driver. The vfio vf-token uuid is + included in the VM XML specification for the pci device, and the token is + passed in qemu commandline on VM launch.
Note that updates to NEWS.rst must always be a separate patch without any other changes.
+ * **Improvements**
* **Bug fixes** diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 310d2bc427..08d7540de5 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3744,6 +3744,10 @@ control where on the bus the device will be placed: between 0x0001 and 0xffff, inclusive), and ``fid`` (a hex value between 0x00000000 and 0xffffffff, inclusive) used by PCI devices on S390 for User-defined Identifiers and Function Identifiers. + :since:'Since 8.1.0`, the vf-token element is supported in uuid format. The + vf-token is a shared secret between userspace vfio-pci PF driver and VF
So wait, this is considered a 'secret'? If so note that it's put on qemu's commandline and thus exposed for ALL users on the sytem.
+ driver. The token is set by the PF driver, and must be provided for VF + access.
If this is to be a secret it MUST be passed to qemu via a 'secret' object which will most likely require also qemu changes first.
:since:`Since 1.3.5` , some hypervisor drivers may accept an ``<address type='pci'/>`` element with no other attributes as an explicit request to assign a PCI address for the device rather than some other type of -- 2.25.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org

On Thu, Nov 30, 2023 at 09:45:30 +0100, Peter Krempa wrote:
On Wed, Nov 29, 2023 at 21:07:27 -0700, Vivek Kashyap wrote:
Update documentation and information about vf-token
Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com> --- NEWS.rst | 8 ++++++++ docs/formatdomain.rst | 4 ++++ 2 files changed, 12 insertions(+)
diff --git a/NEWS.rst b/NEWS.rst index f12734c2a1..3fb0230e71 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -22,6 +22,14 @@ v9.10.0 (unreleased) The QEMU hypervisor driver now allows setting ``pipewire`` backend for ``<audio/>`` device.
+ * qemu: support VF tokens for vfio-pci + + "vf-token",implemented as a UUID, is a shared secret between userspace + vfio-based PF and VF drivers. The token is set by the PF driver and is part + of the device matching by the VF driver. The vfio vf-token uuid is + included in the VM XML specification for the pci device, and the token is + passed in qemu commandline on VM launch.
Note that updates to NEWS.rst must always be a separate patch without any other changes.
+ * **Improvements**
* **Bug fixes** diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 310d2bc427..08d7540de5 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3744,6 +3744,10 @@ control where on the bus the device will be placed: between 0x0001 and 0xffff, inclusive), and ``fid`` (a hex value between 0x00000000 and 0xffffffff, inclusive) used by PCI devices on S390 for User-defined Identifiers and Function Identifiers.
One more thing:
+ :since:'Since 8.1.0`, the vf-token element is supported in uuid format. The
This is supposed to say the libvirt version when this was introduced thus 10.0.0 will be the next one you'll be able to make with these patches. You can additionally mention the qemu version required but it MUST be separate and the libvirt version is always required. There are plenty examples in this file.
participants (2)
-
Peter Krempa
-
Vivek Kashyap