All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Longpeng(Mike)" via <qemu-devel@nongnu.org>
To: <stefanha@redhat.com>, <mst@redhat.com>, <jasowang@redhat.com>,
	<sgarzare@redhat.com>
Cc: <cohuck@redhat.com>, <pbonzini@redhat.com>,
	<arei.gonglei@huawei.com>, <yechuan@huawei.com>,
	<huangzhichao@huawei.com>, <qemu-devel@nongnu.org>,
	Longpeng <longpeng2@huawei.com>
Subject: [RFC 03/10] vdpa: add the infrastructure of vdpa-dev
Date: Wed, 5 Jan 2022 08:58:53 +0800	[thread overview]
Message-ID: <20220105005900.860-4-longpeng2@huawei.com> (raw)
In-Reply-To: <20220105005900.860-1-longpeng2@huawei.com>

From: Longpeng <longpeng2@huawei.com>

Add the infrastructure of vdpa-dev (the generic vDPA device), we
can add a generic vDPA device as follow:
  -device vhost-vdpa-device-pci,vdpa-dev=/dev/vhost-vdpa-X

Signed-off-by: Longpeng <longpeng2@huawei.com>
---
 hw/virtio/Kconfig            |  5 ++++
 hw/virtio/meson.build        |  2 ++
 hw/virtio/vdpa-dev-pci.c     | 51 ++++++++++++++++++++++++++++++++++++
 hw/virtio/vdpa-dev.c         | 41 +++++++++++++++++++++++++++++
 include/hw/virtio/vdpa-dev.h | 16 +++++++++++
 5 files changed, 115 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

diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig
index c144d42f9b..2723283382 100644
--- a/hw/virtio/Kconfig
+++ b/hw/virtio/Kconfig
@@ -68,3 +68,8 @@ config VHOST_USER_RNG
     bool
     default y
     depends on VIRTIO && VHOST_USER
+
+config VHOST_VDPA_DEV
+    bool
+    default y if VIRTIO_PCI
+    depends on VIRTIO && VHOST_VDPA && LINUX
diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build
index 521f7d64a8..8e8943e20b 100644
--- a/hw/virtio/meson.build
+++ b/hw/virtio/meson.build
@@ -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'))
@@ -49,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)
 
diff --git a/hw/virtio/vdpa-dev-pci.c b/hw/virtio/vdpa-dev-pci.c
new file mode 100644
index 0000000000..a5a7b528a9
--- /dev/null
+++ b/hw/virtio/vdpa-dev-pci.c
@@ -0,0 +1,51 @@
+#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)
+{
+    return;
+}
+
+static void vhost_vdpa_device_pci_class_init(ObjectClass *klass, void *data)
+{
+    return;
+}
+
+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);
diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c
new file mode 100644
index 0000000000..f4f92b90b0
--- /dev/null
+++ b/hw/virtio/vdpa-dev.c
@@ -0,0 +1,41 @@
+#include "qemu/osdep.h"
+#include <sys/ioctl.h>
+#include <linux/vhost.h>
+#include "qapi/error.h"
+#include "qemu/error-report.h"
+#include "qemu/cutils.h"
+#include "hw/qdev-core.h"
+#include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
+#include "hw/virtio/vhost.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-bus.h"
+#include "hw/virtio/virtio-access.h"
+#include "hw/virtio/vdpa-dev.h"
+#include "sysemu/sysemu.h"
+#include "sysemu/runstate.h"
+
+static void vhost_vdpa_device_class_init(ObjectClass *klass, void *data)
+{
+    return;
+}
+
+static void vhost_vdpa_device_instance_init(Object *obj)
+{
+    return;
+}
+
+static const TypeInfo vhost_vdpa_device_info = {
+    .name = TYPE_VHOST_VDPA_DEVICE,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VhostVdpaDevice),
+    .class_init = vhost_vdpa_device_class_init,
+    .instance_init = vhost_vdpa_device_instance_init,
+};
+
+static void register_vhost_vdpa_device_type(void)
+{
+    type_register_static(&vhost_vdpa_device_info);
+}
+
+type_init(register_vhost_vdpa_device_type);
diff --git a/include/hw/virtio/vdpa-dev.h b/include/hw/virtio/vdpa-dev.h
new file mode 100644
index 0000000000..dd94bd74a2
--- /dev/null
+++ b/include/hw/virtio/vdpa-dev.h
@@ -0,0 +1,16 @@
+#ifndef _VHOST_VDPA_DEVICE_H
+#define _VHOST_VDPA_DEVICE_H
+
+#include "hw/virtio/vhost.h"
+#include "hw/virtio/vhost-vdpa.h"
+#include "qom/object.h"
+
+
+#define TYPE_VHOST_VDPA_DEVICE "vhost-vdpa-device"
+OBJECT_DECLARE_SIMPLE_TYPE(VhostVdpaDevice, VHOST_VDPA_DEVICE)
+
+struct VhostVdpaDevice {
+    VirtIODevice parent_obj;
+};
+
+#endif
-- 
2.23.0



  parent reply	other threads:[~2022-01-05  1:09 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-05  0:58 [RFC 00/10] add generic vDPA device support Longpeng(Mike) via
2022-01-05  0:58 ` [RFC 01/10] virtio: get class_id and pci device id by the virtio id Longpeng(Mike) via
2022-01-05  4:37   ` Jason Wang
2022-01-05  5:47     ` longpeng2--- via
2022-01-05  6:15       ` Jason Wang
2022-01-10  3:03         ` longpeng2--- via
2022-01-05 10:46   ` Cornelia Huck
2022-01-06  1:50     ` longpeng2--- via
2022-01-10  5:43   ` Michael S. Tsirkin
2022-01-10  6:27     ` longpeng2--- via
2022-01-10  7:14       ` Michael S. Tsirkin
2022-01-05  0:58 ` [RFC 02/10] vhost: add 3 commands for vhost-vdpa Longpeng(Mike) via
2022-01-05  4:35   ` Jason Wang
2022-01-05  6:40     ` longpeng2--- via
2022-01-05  6:43       ` Jason Wang
2022-01-05  7:02     ` Michael S. Tsirkin
2022-01-05  7:54       ` Jason Wang
2022-01-05  8:37         ` longpeng2--- via
2022-01-05  9:09           ` Jason Wang
2022-01-05 12:26             ` Michael S. Tsirkin
2022-01-06  2:34               ` Jason Wang
2022-01-06  8:00                 ` longpeng2--- via
2022-01-07  2:41                   ` Jason Wang
2022-01-06 14:09                 ` Michael S. Tsirkin
2022-01-07  2:53                   ` Jason Wang
2022-01-05  9:12         ` Michael S. Tsirkin
2022-01-05  9:21           ` Jason Wang
2022-01-05  0:58 ` Longpeng(Mike) via [this message]
2022-01-05  9:48   ` [RFC 03/10] vdpa: add the infrastructure of vdpa-dev Stefan Hajnoczi
2022-01-06  1:22     ` longpeng2--- via
2022-01-06 11:25       ` Stefan Hajnoczi
2022-01-07  2:22         ` Jason Wang
2022-01-05  0:58 ` [RFC 04/10] vdpa-dev: implement the instance_init/class_init interface Longpeng(Mike) via
2022-01-05 10:00   ` Stefan Hajnoczi
2022-01-06  2:39     ` longpeng2--- via
2022-01-05 11:28   ` Stefano Garzarella
2022-01-06  2:40     ` longpeng2--- via
2022-01-05  0:58 ` [RFC 05/10] vdpa-dev: implement the realize interface Longpeng(Mike) via
2022-01-05 10:17   ` Stefan Hajnoczi
2022-01-06  3:02     ` longpeng2--- via
2022-01-06 11:34       ` Stefan Hajnoczi
2022-01-17 12:34         ` longpeng2--- via
2022-01-19 17:15           ` Stefan Hajnoczi
2022-01-05  0:58 ` [RFC 06/10] vdpa-dev: implement the unrealize interface Longpeng(Mike) via
2022-01-05 11:16   ` Stefano Garzarella
2022-01-06  3:23     ` longpeng2--- via
2022-01-10  9:38       ` Stefano Garzarella
2022-01-05  0:58 ` [RFC 07/10] vdpa-dev: implement the get_config/set_config interface Longpeng(Mike) via
2022-01-05  0:58 ` [RFC 08/10] vdpa-dev: implement the get_features interface Longpeng(Mike) via
2022-01-05  0:58 ` [RFC 09/10] vdpa-dev: implement the set_status interface Longpeng(Mike) via
2022-01-05  0:59 ` [RFC 10/10] vdpa-dev: mark the device as unmigratable Longpeng(Mike) via
2022-01-05 10:21 ` [RFC 00/10] add generic vDPA device support Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220105005900.860-4-longpeng2@huawei.com \
    --to=qemu-devel@nongnu.org \
    --cc=arei.gonglei@huawei.com \
    --cc=cohuck@redhat.com \
    --cc=huangzhichao@huawei.com \
    --cc=jasowang@redhat.com \
    --cc=longpeng2@huawei.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=yechuan@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.