Skip to contentSkip to conversation

add generic vDPA device support

PATCH RESEND Superseded Longpeng(Mike) via 5 participants 13 messages May 14, 2022 – Jun 9, 2022 Arm/Amlogic Meson SoC support

v6 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v6 cover add generic vDPA device support

From: Longpeng <[email protected]>

Hi guys,

With the generic vDPA device, QEMU won't need to touch the device types any more, such like vfio.

We can use the generic vDPA device as follow:
-device vhost-vdpa-device-pci,vhostdev=/dev/vhost-vdpa-X Or
-M microvm -m 512m -smp 2 -kernel ... -initrd ... -device \
vhost-vdpa-device,vhostdev=/dev/vhost-vdpa-x

I've done some simple tests on Huawei's offloading card (net, 0.95).

Changes v5 -> v6:
Patch 2:
- Turn to the original approach in the RFC to initialize the virtio_pci_id_info array. [Michael]
https://lore.kernel.org/all/[email protected]/
Patch 3:
- Fix logical error of exception handler around the post_init. [Stefano]
- Fix some coding style warnings. [Stefano]
Patch 4:
- Fix some coding style warnings. [Stefano]

Changes v4 -> v5:
Patch 3:
- remove vhostfd [Jason]
- support virtio-mmio [Jason]

Changes v3 -> v4:
v3: https://www.mail-archive.com/[email protected]/msg877015.html
- reorganize the series [Stefano]
- fix some typos [Stefano]
- fix logical error in vhost_vdpa_device_realize [Stefano]

Changes v2 -> v3
Patch 4 & 5:
- only call vdpa ioctls in vdpa-dev.c [Stefano, Longpeng]
- s/VQS_NUM/VQS_COUNT [Stefano]
- check both vdpa_dev_fd and vdpa_dev [Stefano]
Patch 6:
- move all steps into vhost_vdpa_device_unrealize. [Stefano]

Changes RFC -> v2
Patch 1:
- rename 'pdev_id' to 'trans_devid' [Michael]
- only use transitional device id for the devices listed in the spec [Michael]
- use macros to make the id_info table clearer [Longpeng]
- add some modern devices in the id_info table [Longpeng]
Patch 2:
- remove the GET_VECTORS_NUM command [Jason]
Patch 4:
- expose vdpa_dev_fd as a QOM preperty [Stefan]
- introduce vhost_vdpa_device_get_u32 as a common function to make the code clearer [Stefan]
- fix the misleading description of 'dc->desc' [Stefano]
Patch 5:
- check returned number of virtqueues [Stefan]
Patch 6:
- init s->num_queues [Stefano]
- free s->dev.vqs [Stefano]

Longpeng (Mike) (4):
linux-headers: Update headers to Linux 5.18-rc6
virtio: get class_id and pci device id by the virtio id
vdpa: add vdpa-dev support
vdpa: add vdpa-dev-pci support

 hw/virtio/Kconfig            |   5 +
 hw/virtio/meson.build        |   2 +
 hw/virtio/vdpa-dev-pci.c     | 102 ++++++++++
 hw/virtio/vdpa-dev.c         | 377 +++++++++++++++++++++++++++++++++++
 hw/virtio/virtio-pci.c       |  88 ++++++++
 hw/virtio/virtio-pci.h       |   5 +
 include/hw/virtio/vdpa-dev.h |  43 ++++
 linux-headers/linux/vhost.h  |   7 +
 8 files changed, 629 insertions(+)
 create mode 100644 hw/virtio/vdpa-dev-pci.c
 create mode 100644 hw/virtio/vdpa-dev.c
 create mode 100644 include/hw/virtio/vdpa-dev.h
Signature · 1 line
2.23.0
#1 lore raw

PATCH RESEND v6 1/4 linux-headers: Update headers to Linux 5.18-rc6

From: Longpeng <[email protected]>

Update headers to 5.18-rc6. I need latest vhost changes.

---
 linux-headers/linux/vhost.h | 7 +++++++
 1 file changed, 7 insertions(+)
linux-headers/linux/vhost.h +7 -0
index c998860d7b..5d99e7c242 100644
@@ -150,4 +150,11 @@
 /* Get the valid iova range */
 #define VHOST_VDPA_GET_IOVA_RANGE	_IOR(VHOST_VIRTIO, 0x78, \
 					     struct vhost_vdpa_iova_range)
+
+/* Get the config size */
+#define VHOST_VDPA_GET_CONFIG_SIZE	_IOR(VHOST_VIRTIO, 0x79, __u32)
+
+/* Get the count of all virtqueues */
+#define VHOST_VDPA_GET_VQS_COUNT	_IOR(VHOST_VIRTIO, 0x80, __u32)
+
 #endif
Signature · 1 line
2.23.0
#2 lore raw

PATCH RESEND v6 2/4 virtio: get class_id and pci device id by the virtio id

In reply to Longpeng(Mike) via

From: Longpeng <[email protected]>

Add helpers to get the "Transitional PCI Device ID" and "class_id" of the device specified by the "Virtio Device ID".

These helpers will be used to build the generic vDPA device later.

---
 hw/virtio/virtio-pci.c | 88 ++++++++++++++++++++++++++++++++++++++++++
 hw/virtio/virtio-pci.h |  5 +++
 2 files changed, 93 insertions(+)
hw/virtio/virtio-pci.c +88 -0
index 7cf1231c1c..247d7a9002 100644
@@ -19,6 +19,7 @@
 
 #include "exec/memop.h"
 #include "standard-headers/linux/virtio_pci.h"
+#include "standard-headers/linux/virtio_ids.h"
 #include "hw/boards.h"
 #include "hw/virtio/virtio.h"
 #include "migration/qemu-file-types.h"
@@ -212,6 +213,90 @@ static int virtio_pci_load_queue(DeviceState *d, int n, QEMUFile *f)
     return 0;
 }
 
+typedef struct VirtIOPCIIDInfo {
+    /* virtio id */
+    uint16_t vdev_id;
+    /* pci device id for the transitional device */
+    uint16_t trans_devid;
+    uint16_t class_id;
+} VirtIOPCIIDInfo;
+
+static const VirtIOPCIIDInfo virtio_pci_id_info[] = {
+    {
+        .vdev_id = VIRTIO_ID_CRYPTO,
+        .class_id = PCI_CLASS_OTHERS,
+    }, {
+        .vdev_id = VIRTIO_ID_FS,
+        .class_id = PCI_CLASS_STORAGE_OTHER,
+    }, {
+        .vdev_id = VIRTIO_ID_NET,
+        .trans_devid = PCI_DEVICE_ID_VIRTIO_NET,
+        .class_id = PCI_CLASS_NETWORK_ETHERNET,
+    }, {
+        .vdev_id = VIRTIO_ID_BLOCK,
+        .trans_devid = PCI_DEVICE_ID_VIRTIO_BLOCK,
+        .class_id = PCI_CLASS_STORAGE_SCSI,
+    }, {
+        .vdev_id = VIRTIO_ID_CONSOLE,
+        .trans_devid = PCI_DEVICE_ID_VIRTIO_CONSOLE,
+        .class_id = PCI_CLASS_COMMUNICATION_OTHER,
+    }, {
+        .vdev_id = VIRTIO_ID_SCSI,
+        .trans_devid = PCI_DEVICE_ID_VIRTIO_SCSI,
+        .class_id = PCI_CLASS_STORAGE_SCSI
+    }, {
+        .vdev_id = VIRTIO_ID_9P,
+        .trans_devid = PCI_DEVICE_ID_VIRTIO_9P,
+        .class_id = PCI_BASE_CLASS_NETWORK,
+    }, {
+        .vdev_id = VIRTIO_ID_BALLOON,
+        .trans_devid = PCI_DEVICE_ID_VIRTIO_BALLOON,
+        .class_id = PCI_CLASS_OTHERS,
+    }, {
+        .vdev_id = VIRTIO_ID_RNG,
+        .trans_devid = PCI_DEVICE_ID_VIRTIO_RNG,
+        .class_id = PCI_CLASS_OTHERS,
+    },
+};
+
+static const VirtIOPCIIDInfo *virtio_pci_get_id_info(uint16_t vdev_id)
+{
+    const VirtIOPCIIDInfo *info = NULL;
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(virtio_pci_id_info); i++) {
+        if (virtio_pci_id_info[i].vdev_id == vdev_id) {
+            info = &virtio_pci_id_info[i];
+            break;
+        }
+    }
+
+    if (!info) {
+        /* The device id is invalid or not added to the id_info yet. */
+        error_report("Invalid virtio device(id %u)", vdev_id);
+        abort();
+    }
+
+    return info;
+}
+
+/*
+ * Get the Transitional Device ID for the specific device, return
+ * zero if the device is non-transitional.
+ */
+uint16_t virtio_pci_get_trans_devid(uint16_t device_id)
+{
+    return virtio_pci_get_id_info(device_id)->trans_devid;
+}
+
+/*
+ * Get the Class ID for the specific device.
+ */
+uint16_t virtio_pci_get_class_id(uint16_t device_id)
+{
+    return virtio_pci_get_id_info(device_id)->class_id;
+}
+
 static bool virtio_pci_ioeventfd_enabled(DeviceState *d)
 {
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
@@ -1675,6 +1760,9 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
          * is set to PCI_SUBVENDOR_ID_REDHAT_QUMRANET by default.
          */
         pci_set_word(config + PCI_SUBSYSTEM_ID, virtio_bus_get_vdev_id(bus));
+        if (proxy->trans_devid) {
+            pci_config_set_device_id(config, proxy->trans_devid);
+        }
     } else {
         /* pure virtio-1.0 */
         pci_set_word(config + PCI_VENDOR_ID,
hw/virtio/virtio-pci.h +5 -0
index 2446dcd9ae..f08665cd1b 100644
@@ -146,6 +146,8 @@ struct VirtIOPCIProxy {
     bool disable_modern;
     bool ignore_backend_features;
     OnOffAuto disable_legacy;
+    /* Transitional device id */
+    uint16_t trans_devid;
     uint32_t class_code;
     uint32_t nvectors;
     uint32_t dfselect;
@@ -158,6 +160,9 @@ struct VirtIOPCIProxy {
     VirtioBusState bus;
 };
 
+uint16_t virtio_pci_get_trans_devid(uint16_t device_id);
+uint16_t virtio_pci_get_class_id(uint16_t device_id);
+
 static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
 {
     return !proxy->disable_modern;
Signature · 1 line
2.23.0
#3 lore raw

PATCH RESEND v6 3/4 vdpa: add vdpa-dev support

In reply to Longpeng(Mike) via

From: Longpeng <[email protected]>

Supports vdpa-dev, we can use the deivce directly:

-M microvm -m 512m -smp 2 -kernel ... -initrd ... -device \
vhost-vdpa-device,vhostdev=/dev/vhost-vdpa-x

---
 hw/virtio/Kconfig            |   5 +
 hw/virtio/meson.build        |   1 +
 hw/virtio/vdpa-dev.c         | 377 +++++++++++++++++++++++++++++++++++
 include/hw/virtio/vdpa-dev.h |  43 ++++
 4 files changed, 426 insertions(+)
 create mode 100644 hw/virtio/vdpa-dev.c
 create mode 100644 include/hw/virtio/vdpa-dev.h
hw/virtio/Kconfig +5 -0
index c144d42f9b..724eb58a32 100644
@@ -68,3 +68,8 @@ config VHOST_USER_RNG
     bool
     default y
     depends on VIRTIO && VHOST_USER
+
+config VHOST_VDPA_DEV
+    bool
+    default y
+    depends on VIRTIO && VHOST_VDPA && LINUX
hw/virtio/meson.build +1 -0
index 67dc77e00f..8f6f86db71 100644
@@ -29,6 +29,7 @@ virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c'))
 virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_I2C'], if_true: files('vhost-user-i2c-pci.c'))
 virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c'))
 virtio_ss.add(when: ['CONFIG_VHOST_USER_RNG', 'CONFIG_VIRTIO_PCI'], if_true: files('vhost-user-rng-pci.c'))
+virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c'))
 
 virtio_pci_ss = ss.source_set()
 virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c'))
hw/virtio/vdpa-dev.c new file +377 -0

377 lines not on this page · raw message

include/hw/virtio/vdpa-dev.h new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
2.23.0
Reviewed-by on v6 3/4
#4 lore raw

Re: [PATCH v6 resend 3/4] vdpa: add vdpa-dev support

Quoted 8 lines · Longpeng(Mike)

From: Longpeng <[email protected]>

Supports vdpa-dev, we can use the deivce directly:

-M microvm -m 512m -smp 2 -kernel ... -initrd ... -device \
vhost-vdpa-device,vhostdev=/dev/vhost-vdpa-x

Quoted 8 lines

---

hw/virtio/Kconfig            |   5 +
hw/virtio/meson.build        |   1 +
hw/virtio/vdpa-dev.c         | 377 +++++++++++++++++++++++++++++++++++
include/hw/virtio/vdpa-dev.h |  43 ++++
4 files changed, 426 insertions(+)

create mode 100644 hw/virtio/vdpa-dev.c create mode 100644 include/hw/virtio/vdpa-dev.h

#5 lore raw

PATCH RESEND v6 4/4 vdpa: add vdpa-dev-pci support

In reply to Longpeng(Mike) via

From: Longpeng <[email protected]>

Supports vdpa-dev-pci, we can use the device as follow:

-device vhost-vdpa-device-pci,vhostdev=/dev/vhost-vdpa-X

---
 hw/virtio/meson.build    |   1 +
 hw/virtio/vdpa-dev-pci.c | 102 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+)
 create mode 100644 hw/virtio/vdpa-dev-pci.c
hw/virtio/meson.build +1 -0
index 8f6f86db71..c2da69616f 100644
@@ -50,6 +50,7 @@ virtio_pci_ss.add(when: 'CONFIG_VIRTIO_SERIAL', if_true: files('virtio-serial-pc
 virtio_pci_ss.add(when: 'CONFIG_VIRTIO_PMEM', if_true: files('virtio-pmem-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem-pci.c'))
+virtio_pci_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev-pci.c'))
 
 virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss)
 
hw/virtio/vdpa-dev-pci.c new file +102 -0

102 lines not on this page · raw message

Signature · 1 line
2.23.0
#6 lore raw

Re: [PATCH v6 resend 4/4] vdpa: add vdpa-dev-pci support

Quoted 8 lines · Longpeng(Mike)

From: Longpeng <[email protected]>

Supports vdpa-dev-pci, we can use the device as follow:

-device vhost-vdpa-device-pci,vhostdev=/dev/vhost-vdpa-X

Build fails:

FAILED: libqemu-aarch64-softmmu.fa.p/hw_virtio_vdpa-dev-pci.c.o
cc -m64 -mcx16 -Ilibqemu-aarch64-softmmu.fa.p -I. -I.. -Itarget/arm -I../target/arm -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/pixman-1 -I/usr/include/capstone -I/usr/include/spice-server -I/usr/include/spice-1 -I/usr/include/cacard -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/nss3 -I/usr/include/nspr4 -I/usr/include/PCSC -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -isystem /scm/qemu/linux-headers -isystem linux-headers -iquote . -iquote /scm/qemu -iquote /scm/qemu/include -iquote /scm/qemu/disas/libvixl -iquote /scm/qemu/tcg/i386 -pthread -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -fstack-protector-strong -fPIE -isystem../linux-headers -isystemlinux-headers -DNEED_CPU_H '-DCONFIG_TARGET="aarch64-softmmu-config-target.h"' '-DCONFIG_DEVICES="aarch64-softmmu-config-devices.h"' -MD -MQ libqemu-aarch64-softmmu.fa.p/hw_virtio_vdpa-dev-pci.c.o -MF libqemu-aarch64-softmmu.fa.p/hw_virtio_vdpa-dev-pci.c.o.d -o libqemu-aarch64-softmmu.fa.p/hw_virtio_vdpa-dev-pci.c.o -c ../hw/virtio/vdpa-dev-pci.c ../hw/virtio/vdpa-dev-pci.c:26:10: fatal error: virtio-pci.h: No such file or directory
26 | #include "virtio-pci.h"

      |          ^~~~~~~~~~~~~~

compilation terminated.

Quoted 128 lines
---
 hw/virtio/meson.build    |   1 +
 hw/virtio/vdpa-dev-pci.c | 102 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+)
 create mode 100644 hw/virtio/vdpa-dev-pci.c
hw/virtio/meson.build +1 -0
index 8f6f86db71..c2da69616f 100644
@@ -50,6 +50,7 @@ virtio_pci_ss.add(when: 'CONFIG_VIRTIO_SERIAL', if_true: files('virtio-serial-pc
 virtio_pci_ss.add(when: 'CONFIG_VIRTIO_PMEM', if_true: files('virtio-pmem-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem-pci.c'))
+virtio_pci_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev-pci.c'))
 
 virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss)
 
hw/virtio/vdpa-dev-pci.c new file +102 -0
new file mode 100644
index 0000000000..fde35dfc92
@@ -0,0 +1,102 @@
+/*
+ * Vhost Vdpa Device PCI Bindings
+ *
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved.
+ *
+ * Authors:
+ *   Longpeng <[email protected]>
+ *
+ * Largely based on the "vhost-user-blk-pci.c" and "vhost-user-blk.c"
+ * implemented by:
+ *   Changpeng Liu <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+#include "qemu/osdep.h"
+#include <sys/ioctl.h>
+#include <linux/vhost.h>
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/vdpa-dev.h"
+#include "hw/pci/pci.h"
+#include "hw/qdev-properties.h"
+#include "qapi/error.h"
+#include "qemu/error-report.h"
+#include "qemu/module.h"
+#include "virtio-pci.h"
+#include "qom/object.h"
+
+
+typedef struct VhostVdpaDevicePCI VhostVdpaDevicePCI;
+
+#define TYPE_VHOST_VDPA_DEVICE_PCI "vhost-vdpa-device-pci-base"
+DECLARE_INSTANCE_CHECKER(VhostVdpaDevicePCI, VHOST_VDPA_DEVICE_PCI,
+                         TYPE_VHOST_VDPA_DEVICE_PCI)
+
+struct VhostVdpaDevicePCI {
+    VirtIOPCIProxy parent_obj;
+    VhostVdpaDevice vdev;
+};
+
+static void vhost_vdpa_device_pci_instance_init(Object *obj)
+{
+    VhostVdpaDevicePCI *dev = VHOST_VDPA_DEVICE_PCI(obj);
+
+    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
+                                TYPE_VHOST_VDPA_DEVICE);
+    object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
+                              "bootindex");
+}
+
+static Property vhost_vdpa_device_pci_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static int vhost_vdpa_device_pci_post_init(VhostVdpaDevice *v, Error **errp)
+{
+    VhostVdpaDevicePCI *dev = container_of(v, VhostVdpaDevicePCI, vdev);
+    VirtIOPCIProxy *vpci_dev = &dev->parent_obj;
+
+    vpci_dev->class_code = virtio_pci_get_class_id(v->vdev_id);
+    vpci_dev->trans_devid = virtio_pci_get_trans_devid(v->vdev_id);
+    /* one for config vector */
+    vpci_dev->nvectors = v->num_queues + 1;
+
+    return 0;
+}
+
+static void
+vhost_vdpa_device_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+    VhostVdpaDevicePCI *dev = VHOST_VDPA_DEVICE_PCI(vpci_dev);
+
+    dev->vdev.post_init = vhost_vdpa_device_pci_post_init;
+    qdev_realize(DEVICE(&dev->vdev), BUS(&vpci_dev->bus), errp);
+}
+
+static void vhost_vdpa_device_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+
+    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+    device_class_set_props(dc, vhost_vdpa_device_pci_properties);
+    k->realize = vhost_vdpa_device_pci_realize;
+}
+
+static const VirtioPCIDeviceTypeInfo vhost_vdpa_device_pci_info = {
+    .base_name               = TYPE_VHOST_VDPA_DEVICE_PCI,
+    .generic_name            = "vhost-vdpa-device-pci",
+    .transitional_name       = "vhost-vdpa-device-pci-transitional",
+    .non_transitional_name   = "vhost-vdpa-device-pci-non-transitional",
+    .instance_size  = sizeof(VhostVdpaDevicePCI),
+    .instance_init  = vhost_vdpa_device_pci_instance_init,
+    .class_init     = vhost_vdpa_device_pci_class_init,
+};
+
+static void vhost_vdpa_device_pci_register(void)
+{
+    virtio_pci_types_register(&vhost_vdpa_device_pci_info);
+}
+
+type_init(vhost_vdpa_device_pci_register);
Signature · 1 line
2.23.0
#7 lore raw

Re: [PATCH v6 resend 4/4] vdpa: add vdpa-dev-pci support

Quoted 11 lines · Michael S. Tsirkin
Quoted 8 lines · Longpeng(Mike)

From: Longpeng <[email protected]>

Supports vdpa-dev-pci, we can use the device as follow:

-device vhost-vdpa-device-pci,vhostdev=/dev/vhost-vdpa-X

Quoted 9 lines

Build fails:

FAILED: libqemu-aarch64-softmmu.fa.p/hw_virtio_vdpa-dev-pci.c.o
cc -m64 -mcx16 -Ilibqemu-aarch64-softmmu.fa.p -I. -I.. -Itarget/arm -I../target/arm -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/pixman-1 -I/usr/include/capstone -I/usr/include/spice-server -I/usr/include/spice-1 -I/usr/include/cacard -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/nss3 -I/usr/include/nspr4 -I/usr/include/PCSC -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -isystem /scm/qemu/linux-headers -isystem linux-headers -iquote . -iquote /scm/qemu -iquote /scm/qemu/include -iquote /scm/qemu/disas/libvixl -iquote /scm/qemu/tcg/i386 -pthread -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -fstack-protector-strong -fPIE -isystem../linux-headers -isystemlinux-headers -DNEED_CPU_H '-DCONFIG_TARGET="aarch64-softmmu-config-target.h"' '-DCONFIG_DEVICES="aarch64-softmmu-config-devices.h"' -MD -MQ libqemu-aarch64-softmmu.fa.p/hw_virtio_vdpa-dev-pci.c.o -MF libqemu-aarch64-softmmu.fa.p/hw_virtio_vdpa-dev-pci.c.o.d -o libqemu-aarch64-softmmu.fa.p/hw_virtio_vdpa-dev-pci.c.o -c ../hw/virtio/vdpa-dev-pci.c ../hw/virtio/vdpa-dev-pci.c:26:10: fatal error: virtio-pci.h: No such file or directory

    26 | #include "virtio-pci.h"
       |          ^~~~~~~~~~~~~~

compilation terminated.

The following patch moved the virtio-pci.h to the include/ directory:

e1b1f53 2022-05-16 04:38:40 -0400 hw/virtio: move virtio-pci.h into shared include space

I'll rebase this series recently.

Thanks.

Quoted 132 lines
Quoted 129 lines
---
  hw/virtio/meson.build    |   1 +
  hw/virtio/vdpa-dev-pci.c | 102 +++++++++++++++++++++++++++++++++++++++
  2 files changed, 103 insertions(+)

create mode 100644 hw/virtio/vdpa-dev-pci.c

hw/virtio/meson.build +1 -0
index 8f6f86db71..c2da69616f 100644
@@ -50,6 +50,7 @@ virtio_pci_ss.add(when: 'CONFIG_VIRTIO_SERIAL', if_true: files('virtio-serial-pc
  virtio_pci_ss.add(when: 'CONFIG_VIRTIO_PMEM', if_true: files('virtio-pmem-pci.c'))
  virtio_pci_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu-pci.c'))
  virtio_pci_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem-pci.c'))
+virtio_pci_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev-pci.c'))
 
  virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss)
 
hw/virtio/vdpa-dev-pci.c new file +102 -0
new file mode 100644
index 0000000000..fde35dfc92
@@ -0,0 +1,102 @@
+/*
+ * Vhost Vdpa Device PCI Bindings
+ *
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved.
+ *
+ * Authors:
+ *   Longpeng <[email protected]>
+ *
+ * Largely based on the "vhost-user-blk-pci.c" and "vhost-user-blk.c"
+ * implemented by:
+ *   Changpeng Liu <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+#include "qemu/osdep.h"
+#include <sys/ioctl.h>
+#include <linux/vhost.h>
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/vdpa-dev.h"
+#include "hw/pci/pci.h"
+#include "hw/qdev-properties.h"
+#include "qapi/error.h"
+#include "qemu/error-report.h"
+#include "qemu/module.h"
+#include "virtio-pci.h"
+#include "qom/object.h"
+
+
+typedef struct VhostVdpaDevicePCI VhostVdpaDevicePCI;
+
+#define TYPE_VHOST_VDPA_DEVICE_PCI "vhost-vdpa-device-pci-base"
+DECLARE_INSTANCE_CHECKER(VhostVdpaDevicePCI, VHOST_VDPA_DEVICE_PCI,
+                         TYPE_VHOST_VDPA_DEVICE_PCI)
+
+struct VhostVdpaDevicePCI {
+    VirtIOPCIProxy parent_obj;
+    VhostVdpaDevice vdev;
+};
+
+static void vhost_vdpa_device_pci_instance_init(Object *obj)
+{
+    VhostVdpaDevicePCI *dev = VHOST_VDPA_DEVICE_PCI(obj);
+
+    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
+                                TYPE_VHOST_VDPA_DEVICE);
+    object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
+                              "bootindex");
+}
+
+static Property vhost_vdpa_device_pci_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static int vhost_vdpa_device_pci_post_init(VhostVdpaDevice *v, Error **errp)
+{
+    VhostVdpaDevicePCI *dev = container_of(v, VhostVdpaDevicePCI, vdev);
+    VirtIOPCIProxy *vpci_dev = &dev->parent_obj;
+
+    vpci_dev->class_code = virtio_pci_get_class_id(v->vdev_id);
+    vpci_dev->trans_devid = virtio_pci_get_trans_devid(v->vdev_id);
+    /* one for config vector */
+    vpci_dev->nvectors = v->num_queues + 1;
+
+    return 0;
+}
+
+static void
+vhost_vdpa_device_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+    VhostVdpaDevicePCI *dev = VHOST_VDPA_DEVICE_PCI(vpci_dev);
+
+    dev->vdev.post_init = vhost_vdpa_device_pci_post_init;
+    qdev_realize(DEVICE(&dev->vdev), BUS(&vpci_dev->bus), errp);
+}
+
+static void vhost_vdpa_device_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+
+    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+    device_class_set_props(dc, vhost_vdpa_device_pci_properties);
+    k->realize = vhost_vdpa_device_pci_realize;
+}
+
+static const VirtioPCIDeviceTypeInfo vhost_vdpa_device_pci_info = {
+    .base_name               = TYPE_VHOST_VDPA_DEVICE_PCI,
+    .generic_name            = "vhost-vdpa-device-pci",
+    .transitional_name       = "vhost-vdpa-device-pci-transitional",
+    .non_transitional_name   = "vhost-vdpa-device-pci-non-transitional",
+    .instance_size  = sizeof(VhostVdpaDevicePCI),
+    .instance_init  = vhost_vdpa_device_pci_instance_init,
+    .class_init     = vhost_vdpa_device_pci_class_init,
+};
+
+static void vhost_vdpa_device_pci_register(void)
+{
+    virtio_pci_types_register(&vhost_vdpa_device_pci_info);
+}
+
+type_init(vhost_vdpa_device_pci_register);
Signature · 1 line
2.23.0

.

#8 lore raw
In reply to Longpeng(Mike) via

Hi guys,

Ping...Any other comments?

Quoted 86 lines · Longpeng(Mike)

From: Longpeng <[email protected]>

Hi guys,

With the generic vDPA device, QEMU won't need to touch the device types any more, such like vfio.

We can use the generic vDPA device as follow:

   -device vhost-vdpa-device-pci,vhostdev=/dev/vhost-vdpa-X
   Or
   -M microvm -m 512m -smp 2 -kernel ... -initrd ... -device \
   vhost-vdpa-device,vhostdev=/dev/vhost-vdpa-x

I've done some simple tests on Huawei's offloading card (net, 0.95).

Changes v5 -> v6:
Patch 2:
- Turn to the original approach in the RFC to initialize the virtio_pci_id_info array. [Michael]
https://lore.kernel.org/all/[email protected]/
Patch 3:
- Fix logical error of exception handler around the post_init. [Stefano]
- Fix some coding style warnings. [Stefano]
Patch 4:
- Fix some coding style warnings. [Stefano]

Changes v4 -> v5:
Patch 3:
- remove vhostfd [Jason]
- support virtio-mmio [Jason]

Changes v3 -> v4:
v3: https://www.mail-archive.com/[email protected]/msg877015.html
- reorganize the series [Stefano]
- fix some typos [Stefano]
- fix logical error in vhost_vdpa_device_realize [Stefano]

Changes v2 -> v3
Patch 4 & 5:
- only call vdpa ioctls in vdpa-dev.c [Stefano, Longpeng]
- s/VQS_NUM/VQS_COUNT [Stefano]
- check both vdpa_dev_fd and vdpa_dev [Stefano]
Patch 6:
- move all steps into vhost_vdpa_device_unrealize. [Stefano]

Changes RFC -> v2
Patch 1:
- rename 'pdev_id' to 'trans_devid' [Michael]
- only use transitional device id for the devices listed in the spec [Michael]
- use macros to make the id_info table clearer [Longpeng]
- add some modern devices in the id_info table [Longpeng]
Patch 2:
- remove the GET_VECTORS_NUM command [Jason]
Patch 4:
- expose vdpa_dev_fd as a QOM preperty [Stefan]
- introduce vhost_vdpa_device_get_u32 as a common function to make the code clearer [Stefan]
- fix the misleading description of 'dc->desc' [Stefano]
Patch 5:
- check returned number of virtqueues [Stefan]
Patch 6:
- init s->num_queues [Stefano]
- free s->dev.vqs [Stefano]

Longpeng (Mike) (4):
linux-headers: Update headers to Linux 5.18-rc6
virtio: get class_id and pci device id by the virtio id
vdpa: add vdpa-dev support
vdpa: add vdpa-dev-pci support

  hw/virtio/Kconfig            |   5 +
  hw/virtio/meson.build        |   2 +
  hw/virtio/vdpa-dev-pci.c     | 102 ++++++++++
  hw/virtio/vdpa-dev.c         | 377 +++++++++++++++++++++++++++++++++++
  hw/virtio/virtio-pci.c       |  88 ++++++++
  hw/virtio/virtio-pci.h       |   5 +
  include/hw/virtio/vdpa-dev.h |  43 ++++
  linux-headers/linux/vhost.h  |   7 +
  8 files changed, 629 insertions(+)

create mode 100644 hw/virtio/vdpa-dev-pci.c
create mode 100644 hw/virtio/vdpa-dev.c
create mode 100644 include/hw/virtio/vdpa-dev.h

#9 lore raw
Quoted 4 lines · Cloud Infrastructure Service Product Dept.)

Hi guys,

Ping...Any other comments?

Will go through this and try to provide some acks soon.

Thanks

Quoted 89 lines · Longpeng(Mike)
Quoted 86 lines

From: Longpeng <[email protected]>

Hi guys,

With the generic vDPA device, QEMU won't need to touch the device types any more, such like vfio.

We can use the generic vDPA device as follow:

   -device vhost-vdpa-device-pci,vhostdev=/dev/vhost-vdpa-X
   Or
   -M microvm -m 512m -smp 2 -kernel ... -initrd ... -device \
   vhost-vdpa-device,vhostdev=/dev/vhost-vdpa-x

I've done some simple tests on Huawei's offloading card (net, 0.95).

Changes v5 -> v6:
Patch 2:
- Turn to the original approach in the RFC to initialize the virtio_pci_id_info array. [Michael]
https://lore.kernel.org/all/[email protected]/
Patch 3:
- Fix logical error of exception handler around the post_init. [Stefano]
- Fix some coding style warnings. [Stefano]
Patch 4:
- Fix some coding style warnings. [Stefano]

Changes v4 -> v5:
Patch 3:
- remove vhostfd [Jason]
- support virtio-mmio [Jason]

Changes v3 -> v4:
v3: https://www.mail-archive.com/[email protected]/msg877015.html
- reorganize the series [Stefano]
- fix some typos [Stefano]
- fix logical error in vhost_vdpa_device_realize [Stefano]

Changes v2 -> v3
Patch 4 & 5:
- only call vdpa ioctls in vdpa-dev.c [Stefano, Longpeng]
- s/VQS_NUM/VQS_COUNT [Stefano]
- check both vdpa_dev_fd and vdpa_dev [Stefano]
Patch 6:
- move all steps into vhost_vdpa_device_unrealize. [Stefano]

Changes RFC -> v2
Patch 1:
- rename 'pdev_id' to 'trans_devid' [Michael]
- only use transitional device id for the devices listed in the spec [Michael]
- use macros to make the id_info table clearer [Longpeng]
- add some modern devices in the id_info table [Longpeng]
Patch 2:
- remove the GET_VECTORS_NUM command [Jason]
Patch 4:
- expose vdpa_dev_fd as a QOM preperty [Stefan]
- introduce vhost_vdpa_device_get_u32 as a common function to make the code clearer [Stefan]
- fix the misleading description of 'dc->desc' [Stefano]
Patch 5:
- check returned number of virtqueues [Stefan]
Patch 6:
- init s->num_queues [Stefano]
- free s->dev.vqs [Stefano]

Longpeng (Mike) (4):
linux-headers: Update headers to Linux 5.18-rc6
virtio: get class_id and pci device id by the virtio id
vdpa: add vdpa-dev support
vdpa: add vdpa-dev-pci support

  hw/virtio/Kconfig            |   5 +
  hw/virtio/meson.build        |   2 +
  hw/virtio/vdpa-dev-pci.c     | 102 ++++++++++
  hw/virtio/vdpa-dev.c         | 377 +++++++++++++++++++++++++++++++++++
  hw/virtio/virtio-pci.c       |  88 ++++++++
  hw/virtio/virtio-pci.h       |   5 +
  include/hw/virtio/vdpa-dev.h |  43 ++++
  linux-headers/linux/vhost.h  |   7 +
  8 files changed, 629 insertions(+)

create mode 100644 hw/virtio/vdpa-dev-pci.c
create mode 100644 hw/virtio/vdpa-dev.c
create mode 100644 include/hw/virtio/vdpa-dev.h

Acked-by
#10 lore raw
In reply to longpeng2--- via
Quoted 4 lines · Cloud Infrastructure Service Product Dept.)

Hi guys,

Ping...Any other comments?

Looks good to me.

(This probably requires a rebase since it doesn't apply cleanly on master).

Thanks

Quoted 89 lines · Longpeng(Mike)
Quoted 86 lines

From: Longpeng <[email protected]>

Hi guys,

With the generic vDPA device, QEMU won't need to touch the device types any more, such like vfio.

We can use the generic vDPA device as follow:

   -device vhost-vdpa-device-pci,vhostdev=/dev/vhost-vdpa-X
   Or
   -M microvm -m 512m -smp 2 -kernel ... -initrd ... -device \
   vhost-vdpa-device,vhostdev=/dev/vhost-vdpa-x

I've done some simple tests on Huawei's offloading card (net, 0.95).

Changes v5 -> v6:
Patch 2:
- Turn to the original approach in the RFC to initialize the virtio_pci_id_info array. [Michael]
https://lore.kernel.org/all/[email protected]/
Patch 3:
- Fix logical error of exception handler around the post_init. [Stefano]
- Fix some coding style warnings. [Stefano]
Patch 4:
- Fix some coding style warnings. [Stefano]

Changes v4 -> v5:
Patch 3:
- remove vhostfd [Jason]
- support virtio-mmio [Jason]

Changes v3 -> v4:
v3: https://www.mail-archive.com/[email protected]/msg877015.html
- reorganize the series [Stefano]
- fix some typos [Stefano]
- fix logical error in vhost_vdpa_device_realize [Stefano]

Changes v2 -> v3
Patch 4 & 5:
- only call vdpa ioctls in vdpa-dev.c [Stefano, Longpeng]
- s/VQS_NUM/VQS_COUNT [Stefano]
- check both vdpa_dev_fd and vdpa_dev [Stefano]
Patch 6:
- move all steps into vhost_vdpa_device_unrealize. [Stefano]

Changes RFC -> v2
Patch 1:
- rename 'pdev_id' to 'trans_devid' [Michael]
- only use transitional device id for the devices listed in the spec [Michael]
- use macros to make the id_info table clearer [Longpeng]
- add some modern devices in the id_info table [Longpeng]
Patch 2:
- remove the GET_VECTORS_NUM command [Jason]
Patch 4:
- expose vdpa_dev_fd as a QOM preperty [Stefan]
- introduce vhost_vdpa_device_get_u32 as a common function to make the code clearer [Stefan]
- fix the misleading description of 'dc->desc' [Stefano]
Patch 5:
- check returned number of virtqueues [Stefan]
Patch 6:
- init s->num_queues [Stefano]
- free s->dev.vqs [Stefano]

Longpeng (Mike) (4):
linux-headers: Update headers to Linux 5.18-rc6
virtio: get class_id and pci device id by the virtio id
vdpa: add vdpa-dev support
vdpa: add vdpa-dev-pci support

  hw/virtio/Kconfig            |   5 +
  hw/virtio/meson.build        |   2 +
  hw/virtio/vdpa-dev-pci.c     | 102 ++++++++++
  hw/virtio/vdpa-dev.c         | 377 +++++++++++++++++++++++++++++++++++
  hw/virtio/virtio-pci.c       |  88 ++++++++
  hw/virtio/virtio-pci.h       |   5 +
  include/hw/virtio/vdpa-dev.h |  43 ++++
  linux-headers/linux/vhost.h  |   7 +
  8 files changed, 629 insertions(+)

create mode 100644 hw/virtio/vdpa-dev-pci.c
create mode 100644 hw/virtio/vdpa-dev.c
create mode 100644 include/hw/virtio/vdpa-dev.h

#11 lore raw
Quoted 5 lines · Jason Wang
Quoted 3 lines · Cloud Infrastructure Service Product Dept.)

Hi guys,

Quoted 8 lines
Quoted 1 line

Ping...Any other comments?

Looks good to me.

(This probably requires a rebase since it doesn't apply cleanly on master).

Okay, I'll rebase in next version.
Thanks.

Quoted 93 lines

Thanks

Quoted 75 lines · Longpeng(Mike)
Quoted 73 lines

From: Longpeng <[email protected]>

Hi guys,

With the generic vDPA device, QEMU won't need to touch the device types any more, such like vfio.

We can use the generic vDPA device as follow:

    -device vhost-vdpa-device-pci,vhostdev=/dev/vhost-vdpa-X
    Or
    -M microvm -m 512m -smp 2 -kernel ... -initrd ... -device \
    vhost-vdpa-device,vhostdev=/dev/vhost-vdpa-x

I've done some simple tests on Huawei's offloading card (net, 0.95).

Changes v5 -> v6:
Patch 2:
- Turn to the original approach in the RFC to initialize the virtio_pci_id_info array. [Michael]
https://lore.kernel.org/all/[email protected]/
Patch 3:
- Fix logical error of exception handler around the post_init. [Stefano]
- Fix some coding style warnings. [Stefano]
Patch 4:
- Fix some coding style warnings. [Stefano]

Changes v4 -> v5:
Patch 3:
- remove vhostfd [Jason]
- support virtio-mmio [Jason]

Changes v3 -> v4:
v3: https://www.mail-archive.com/[email protected]/msg877015.html
- reorganize the series [Stefano]
- fix some typos [Stefano]
- fix logical error in vhost_vdpa_device_realize [Stefano]

Changes v2 -> v3
Patch 4 & 5:
- only call vdpa ioctls in vdpa-dev.c [Stefano, Longpeng]
- s/VQS_NUM/VQS_COUNT [Stefano]
- check both vdpa_dev_fd and vdpa_dev [Stefano]
Patch 6:
- move all steps into vhost_vdpa_device_unrealize. [Stefano]

Changes RFC -> v2
Patch 1:
- rename 'pdev_id' to 'trans_devid' [Michael]
- only use transitional device id for the devices listed in the spec [Michael]
- use macros to make the id_info table clearer [Longpeng]
- add some modern devices in the id_info table [Longpeng]
Patch 2:
- remove the GET_VECTORS_NUM command [Jason]
Patch 4:
- expose vdpa_dev_fd as a QOM preperty [Stefan]
- introduce vhost_vdpa_device_get_u32 as a common function to make the code clearer [Stefan]
- fix the misleading description of 'dc->desc' [Stefano]
Patch 5:
- check returned number of virtqueues [Stefan]
Patch 6:
- init s->num_queues [Stefano]
- free s->dev.vqs [Stefano]

Longpeng (Mike) (4):
linux-headers: Update headers to Linux 5.18-rc6
virtio: get class_id and pci device id by the virtio id
vdpa: add vdpa-dev support
vdpa: add vdpa-dev-pci support

Quoted 14 lines
Quoted 9 lines
   hw/virtio/Kconfig            |   5 +
   hw/virtio/meson.build        |   2 +
   hw/virtio/vdpa-dev-pci.c     | 102 ++++++++++
   hw/virtio/vdpa-dev.c         | 377 +++++++++++++++++++++++++++++++++++
   hw/virtio/virtio-pci.c       |  88 ++++++++
   hw/virtio/virtio-pci.h       |   5 +
   include/hw/virtio/vdpa-dev.h |  43 ++++
   linux-headers/linux/vhost.h  |   7 +
   8 files changed, 629 insertions(+)
Quoted 4 lines

create mode 100644 hw/virtio/vdpa-dev-pci.c create mode 100644 hw/virtio/vdpa-dev.c create mode 100644 include/hw/virtio/vdpa-dev.h

.

#12 lore raw
In reply to Longpeng(Mike) via
Quoted 7 lines · Longpeng(Mike)

From: Longpeng <[email protected]>

Hi guys,

With the generic vDPA device, QEMU won't need to touch the device types any more, such like vfio.

Quoted 7 lines

We can use the generic vDPA device as follow:
-device vhost-vdpa-device-pci,vhostdev=/dev/vhost-vdpa-X Or
-M microvm -m 512m -smp 2 -kernel ... -initrd ... -device \
vhost-vdpa-device,vhostdev=/dev/vhost-vdpa-x

I've done some simple tests on Huawei's offloading card (net, 0.95).

Please send a follow-up patch that adds documentation for this new device type. Maybe in a new docs/system/devices/vhost-vdpa.rst file?

Stefan