qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] virtio: Add vhost-user-gpio device's support
@ 2022-01-12 11:34 Viresh Kumar
  2022-01-12 11:34 ` [PATCH 1/2] hw/virtio: add boilerplate for vhost-user-gpio device Viresh Kumar
                   ` (4 more replies)
  0 siblings, 5 replies; 24+ messages in thread
From: Viresh Kumar @ 2022-01-12 11:34 UTC (permalink / raw)
  To: qemu-devel, Alex Bennée, Michael S. Tsirkin
  Cc: Viresh Kumar, Vincent Guittot, stratos-dev

Hello,

This patchset adds vhost-user-gpio device's support in Qemu. The support for the
same has already been added to virtio specification and Linux Kernel.

A Rust based backend is also in progress and is tested against this patchset:

https://github.com/rust-vmm/vhost-device/pull/76

--
Viresh

Viresh Kumar (2):
  hw/virtio: add boilerplate for vhost-user-gpio device
  hw/virtio: add vhost-user-gpio-pci boilerplate

 hw/virtio/Kconfig                   |   5 +
 hw/virtio/meson.build               |   2 +
 hw/virtio/vhost-user-gpio-pci.c     |  69 ++++++
 hw/virtio/vhost-user-gpio.c         | 343 ++++++++++++++++++++++++++++
 include/hw/virtio/vhost-user-gpio.h |  35 +++
 5 files changed, 454 insertions(+)
 create mode 100644 hw/virtio/vhost-user-gpio-pci.c
 create mode 100644 hw/virtio/vhost-user-gpio.c
 create mode 100644 include/hw/virtio/vhost-user-gpio.h

-- 
2.31.1.272.g89b43f80a514



^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 1/2] hw/virtio: add boilerplate for vhost-user-gpio device
  2022-01-12 11:34 [PATCH 0/2] virtio: Add vhost-user-gpio device's support Viresh Kumar
@ 2022-01-12 11:34 ` Viresh Kumar
  2022-01-14 14:05   ` Alex Bennée
  2022-01-14 14:06   ` Alex Bennée
  2022-01-12 11:34 ` [PATCH 2/2] hw/virtio: add vhost-user-gpio-pci boilerplate Viresh Kumar
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 24+ messages in thread
From: Viresh Kumar @ 2022-01-12 11:34 UTC (permalink / raw)
  To: qemu-devel, Alex Bennée, Michael S. Tsirkin
  Cc: Viresh Kumar, Vincent Guittot, stratos-dev

This creates the QEMU side of the vhost-user-gpio device which connects
to the remote daemon. It is based of vhost-user-i2c code.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 hw/virtio/Kconfig                   |   5 +
 hw/virtio/meson.build               |   1 +
 hw/virtio/vhost-user-gpio.c         | 343 ++++++++++++++++++++++++++++
 include/hw/virtio/vhost-user-gpio.h |  35 +++
 4 files changed, 384 insertions(+)
 create mode 100644 hw/virtio/vhost-user-gpio.c
 create mode 100644 include/hw/virtio/vhost-user-gpio.h

diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig
index c144d42f9bd0..b16a63609530 100644
--- a/hw/virtio/Kconfig
+++ b/hw/virtio/Kconfig
@@ -59,6 +59,11 @@ config VIRTIO_MEM
     depends on VIRTIO_MEM_SUPPORTED
     select MEM_DEVICE
 
+config VHOST_USER_GPIO
+    bool
+    default y
+    depends on VIRTIO && VHOST_USER
+
 config VHOST_USER_I2C
     bool
     default y
diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build
index 521f7d64a86a..c7e67adff337 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_USER_GPIO', if_true: files('vhost-user-gpio.c'))
 
 virtio_pci_ss = ss.source_set()
 virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c'))
diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c
new file mode 100644
index 000000000000..c5f67c0104a9
--- /dev/null
+++ b/hw/virtio/vhost-user-gpio.c
@@ -0,0 +1,343 @@
+/*
+ * Vhost-user GPIO virtio device
+ *
+ * Copyright (c) 2022 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/qdev-properties.h"
+#include "hw/virtio/virtio-bus.h"
+#include "hw/virtio/vhost-user-gpio.h"
+#include "qemu/error-report.h"
+#include "standard-headers/linux/virtio_ids.h"
+
+static const int feature_bits[] = {
+    VIRTIO_GPIO_F_IRQ
+};
+
+static void vu_gpio_get_config(VirtIODevice *vdev, uint8_t *config)
+{
+    VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev);
+
+    memcpy(config, &gpio->config, sizeof(gpio->config));
+}
+
+static int vu_gpio_config_notifier(struct vhost_dev *dev)
+{
+    VHostUserGPIO *gpio = VHOST_USER_GPIO(dev->vdev);
+
+    memcpy(dev->vdev->config, &gpio->config, sizeof(gpio->config));
+    virtio_notify_config(dev->vdev);
+
+    return 0;
+}
+
+const VhostDevConfigOps gpio_ops = {
+    .vhost_dev_config_notifier = vu_gpio_config_notifier,
+};
+
+static int vu_gpio_start(VirtIODevice *vdev)
+{
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
+    VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev);
+    int ret, i;
+
+    if (!k->set_guest_notifiers) {
+        error_report("binding does not support guest notifiers");
+        return -ENOSYS;
+    }
+
+    ret = vhost_dev_enable_notifiers(&gpio->vhost_dev, vdev);
+    if (ret < 0) {
+        error_report("Error enabling host notifiers: %d", ret);
+        return ret;
+    }
+
+    ret = k->set_guest_notifiers(qbus->parent, gpio->vhost_dev.nvqs, true);
+    if (ret < 0) {
+        error_report("Error binding guest notifier: %d", ret);
+        goto err_host_notifiers;
+    }
+
+    gpio->vhost_dev.acked_features = vdev->guest_features;
+
+    ret = vhost_dev_start(&gpio->vhost_dev, vdev);
+    if (ret < 0) {
+        error_report("Error starting vhost-user-gpio: %d", ret);
+        goto err_guest_notifiers;
+    }
+
+    /*
+     * guest_notifier_mask/pending not used yet, so just unmask
+     * everything here. virtio-pci will do the right thing by
+     * enabling/disabling irqfd.
+     */
+    for (i = 0; i < gpio->vhost_dev.nvqs; i++) {
+        vhost_virtqueue_mask(&gpio->vhost_dev, vdev, i, false);
+    }
+
+    return 0;
+
+err_guest_notifiers:
+    k->set_guest_notifiers(qbus->parent, gpio->vhost_dev.nvqs, false);
+err_host_notifiers:
+    vhost_dev_disable_notifiers(&gpio->vhost_dev, vdev);
+
+    return ret;
+}
+
+static void vu_gpio_stop(VirtIODevice *vdev)
+{
+    VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev);
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
+    int ret;
+
+    if (!k->set_guest_notifiers) {
+        return;
+    }
+
+    vhost_dev_stop(&gpio->vhost_dev, vdev);
+
+    ret = k->set_guest_notifiers(qbus->parent, gpio->vhost_dev.nvqs, false);
+    if (ret < 0) {
+        error_report("vhost guest notifier cleanup failed: %d", ret);
+        return;
+    }
+
+    vhost_dev_disable_notifiers(&gpio->vhost_dev, vdev);
+}
+
+static void vu_gpio_set_status(VirtIODevice *vdev, uint8_t status)
+{
+    VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev);
+    bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
+
+    if (!vdev->vm_running) {
+        should_start = false;
+    }
+
+    if (!gpio->connected) {
+        return;
+    }
+
+    if (gpio->vhost_dev.started == should_start) {
+        return;
+    }
+
+    if (should_start) {
+        if (vu_gpio_start(vdev)) {
+            qemu_chr_fe_disconnect(&gpio->chardev);
+        }
+    } else {
+        vu_gpio_stop(vdev);
+    }
+}
+
+static uint64_t vu_gpio_get_features(VirtIODevice *vdev,
+                                    uint64_t requested_features, Error **errp)
+{
+    VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev);
+
+    virtio_add_feature(&requested_features, VIRTIO_GPIO_F_IRQ);
+    return vhost_get_features(&gpio->vhost_dev, feature_bits, requested_features);
+}
+
+static void vu_gpio_handle_output(VirtIODevice *vdev, VirtQueue *vq)
+{
+    /*
+     * Not normally called; it's the daemon that handles the queue;
+     * however virtio's cleanup path can call this.
+     */
+}
+
+static void vu_gpio_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask)
+{
+    VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev);
+
+    vhost_virtqueue_mask(&gpio->vhost_dev, vdev, idx, mask);
+}
+
+static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserGPIO *gpio)
+{
+    virtio_delete_queue(gpio->command_vq);
+    virtio_delete_queue(gpio->interrupt_vq);
+    g_free(gpio->vhost_dev.vqs);
+    gpio->vhost_dev.vqs = NULL;
+    virtio_cleanup(vdev);
+    vhost_user_cleanup(&gpio->vhost_user);
+}
+
+static int vu_gpio_connect(DeviceState *dev)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev);
+    Error *local_err = NULL;
+    int ret;
+
+    if (gpio->connected) {
+        return 0;
+    }
+    gpio->connected = true;
+
+    vhost_dev_set_config_notifier(&gpio->vhost_dev, &gpio_ops);
+
+    ret = vhost_dev_init(&gpio->vhost_dev, &gpio->vhost_user,
+                         VHOST_BACKEND_TYPE_USER, 0, &local_err);
+    if (ret < 0) {
+        error_report("vhost-user-gpio: vhost initialization failed: %s",
+                     strerror(-ret));
+        return ret;
+    }
+
+    /* restore vhost state */
+    if (virtio_device_started(vdev, vdev->status)) {
+        vu_gpio_start(vdev);
+    }
+
+    return 0;
+}
+
+static void vu_gpio_disconnect(DeviceState *dev)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev);
+
+    if (!gpio->connected) {
+        return;
+    }
+    gpio->connected = false;
+
+    vu_gpio_stop(vdev);
+    vhost_dev_cleanup(&gpio->vhost_dev);
+}
+
+static void vu_gpio_event(void *opaque, QEMUChrEvent event)
+{
+    DeviceState *dev = opaque;
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev);
+
+    switch (event) {
+    case CHR_EVENT_OPENED:
+        if (vu_gpio_connect(dev) < 0) {
+            qemu_chr_fe_disconnect(&gpio->chardev);
+            return;
+        }
+        break;
+    case CHR_EVENT_CLOSED:
+        vu_gpio_disconnect(dev);
+        break;
+    case CHR_EVENT_BREAK:
+    case CHR_EVENT_MUX_IN:
+    case CHR_EVENT_MUX_OUT:
+        /* Ignore */
+        break;
+    }
+}
+
+static void vu_gpio_device_realize(DeviceState *dev, Error **errp)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VHostUserGPIO *gpio = VHOST_USER_GPIO(dev);
+    Error *err = NULL;
+    int ret;
+
+    if (!gpio->chardev.chr) {
+        error_setg(errp, "vhost-user-gpio: chardev is mandatory");
+        return;
+    }
+
+    if (!vhost_user_init(&gpio->vhost_user, &gpio->chardev, errp)) {
+        return;
+    }
+
+    virtio_init(vdev, "vhost-user-gpio", VIRTIO_ID_GPIO, sizeof(gpio->config));
+
+    gpio->vhost_dev.nvqs = 2;
+    gpio->command_vq = virtio_add_queue(vdev, 256, vu_gpio_handle_output);
+    gpio->interrupt_vq = virtio_add_queue(vdev, 256, vu_gpio_handle_output);
+    gpio->vhost_dev.vqs = g_new0(struct vhost_virtqueue, gpio->vhost_dev.nvqs);
+
+    gpio->connected = false;
+
+    qemu_chr_fe_set_handlers(&gpio->chardev, NULL, NULL, vu_gpio_event, NULL,
+                             dev, NULL, true);
+
+reconnect:
+    if (qemu_chr_fe_wait_connected(&gpio->chardev, &err) < 0) {
+        error_report_err(err);
+        do_vhost_user_cleanup(vdev, gpio);
+        return;
+    }
+
+    /* check whether vhost_user_gpio_connect() failed or not */
+    if (!gpio->connected) {
+        goto reconnect;
+    }
+
+    ret = vhost_dev_get_config(&gpio->vhost_dev, (uint8_t *)&gpio->config,
+                               sizeof(gpio->config), errp);
+    if (ret < 0) {
+        error_report("vhost-user-gpio: get config failed");
+        goto reconnect;
+    }
+
+    return;
+}
+
+static void vu_gpio_device_unrealize(DeviceState *dev)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VHostUserGPIO *gpio = VHOST_USER_GPIO(dev);
+
+    vu_gpio_set_status(vdev, 0);
+    qemu_chr_fe_set_handlers(&gpio->chardev, NULL, NULL, NULL, NULL, NULL, NULL,
+                             false);
+    vhost_dev_cleanup(&gpio->vhost_dev);
+    do_vhost_user_cleanup(vdev, gpio);
+}
+
+static const VMStateDescription vu_gpio_vmstate = {
+    .name = "vhost-user-gpio",
+    .unmigratable = 1,
+};
+
+static Property vu_gpio_properties[] = {
+    DEFINE_PROP_CHR("chardev", VHostUserGPIO, chardev),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void vu_gpio_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+
+    device_class_set_props(dc, vu_gpio_properties);
+    dc->vmsd = &vu_gpio_vmstate;
+    set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
+    vdc->realize = vu_gpio_device_realize;
+    vdc->unrealize = vu_gpio_device_unrealize;
+    vdc->get_features = vu_gpio_get_features;
+    vdc->get_config = vu_gpio_get_config;
+    vdc->set_status = vu_gpio_set_status;
+    vdc->guest_notifier_mask = vu_gpio_guest_notifier_mask;
+}
+
+static const TypeInfo vu_gpio_info = {
+    .name = TYPE_VHOST_USER_GPIO,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VHostUserGPIO),
+    .class_init = vu_gpio_class_init,
+};
+
+static void vu_gpio_register_types(void)
+{
+    type_register_static(&vu_gpio_info);
+}
+
+type_init(vu_gpio_register_types)
diff --git a/include/hw/virtio/vhost-user-gpio.h b/include/hw/virtio/vhost-user-gpio.h
new file mode 100644
index 000000000000..afeb56f53e99
--- /dev/null
+++ b/include/hw/virtio/vhost-user-gpio.h
@@ -0,0 +1,35 @@
+/*
+ * Vhost-user GPIO virtio device
+ *
+ * Copyright (c) 2021 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef _QEMU_VHOST_USER_GPIO_H
+#define _QEMU_VHOST_USER_GPIO_H
+
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/vhost.h"
+#include "hw/virtio/vhost-user.h"
+#include "standard-headers/linux/virtio_gpio.h"
+#include "chardev/char-fe.h"
+
+#define TYPE_VHOST_USER_GPIO "vhost-user-gpio-device"
+OBJECT_DECLARE_SIMPLE_TYPE(VHostUserGPIO, VHOST_USER_GPIO);
+
+struct VHostUserGPIO {
+    /*< private >*/
+    VirtIODevice parent;
+    CharBackend chardev;
+    struct virtio_gpio_config config;
+    struct vhost_virtqueue *vhost_vq;
+    struct vhost_dev vhost_dev;
+    VhostUserState vhost_user;
+    VirtQueue *command_vq;
+    VirtQueue *interrupt_vq;
+    bool connected;
+    /*< public >*/
+};
+
+#endif /* _QEMU_VHOST_USER_GPIO_H */
-- 
2.31.1.272.g89b43f80a514



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 2/2] hw/virtio: add vhost-user-gpio-pci boilerplate
  2022-01-12 11:34 [PATCH 0/2] virtio: Add vhost-user-gpio device's support Viresh Kumar
  2022-01-12 11:34 ` [PATCH 1/2] hw/virtio: add boilerplate for vhost-user-gpio device Viresh Kumar
@ 2022-01-12 11:34 ` Viresh Kumar
  2022-01-14 14:10   ` Alex Bennée
  2022-01-17  8:47 ` [PATCH 0/2] virtio: Add vhost-user-gpio device's support Michael S. Tsirkin
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 24+ messages in thread
From: Viresh Kumar @ 2022-01-12 11:34 UTC (permalink / raw)
  To: qemu-devel, Alex Bennée, Michael S. Tsirkin
  Cc: Viresh Kumar, Vincent Guittot, stratos-dev

This allows is to instantiate a vhost-user-gpio device as part of a PCI
bus. It is mostly boilerplate which looks pretty similar to the
vhost-user-fs-pci device.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 hw/virtio/meson.build           |  1 +
 hw/virtio/vhost-user-gpio-pci.c | 69 +++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)
 create mode 100644 hw/virtio/vhost-user-gpio-pci.c

diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build
index c7e67adff337..fe6a4e9acb2a 100644
--- a/hw/virtio/meson.build
+++ b/hw/virtio/meson.build
@@ -30,6 +30,7 @@ virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_I2C'], if_true: fil
 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_USER_GPIO', if_true: files('vhost-user-gpio.c'))
+virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO'], if_true: files('vhost-user-gpio-pci.c'))
 
 virtio_pci_ss = ss.source_set()
 virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c'))
diff --git a/hw/virtio/vhost-user-gpio-pci.c b/hw/virtio/vhost-user-gpio-pci.c
new file mode 100644
index 000000000000..8dd042d5e1c1
--- /dev/null
+++ b/hw/virtio/vhost-user-gpio-pci.c
@@ -0,0 +1,69 @@
+/*
+ * Vhost-user gpio virtio device PCI glue
+ *
+ * Copyright (c) 2022 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "hw/qdev-properties.h"
+#include "hw/virtio/vhost-user-gpio.h"
+#include "virtio-pci.h"
+
+struct VHostUserGPIOPCI {
+    VirtIOPCIProxy parent_obj;
+    VHostUserGPIO vdev;
+};
+
+typedef struct VHostUserGPIOPCI VHostUserGPIOPCI;
+
+#define TYPE_VHOST_USER_GPIO_PCI "vhost-user-gpio-pci-base"
+
+DECLARE_INSTANCE_CHECKER(VHostUserGPIOPCI, VHOST_USER_GPIO_PCI,
+                         TYPE_VHOST_USER_GPIO_PCI)
+
+static void vhost_user_gpio_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+    VHostUserGPIOPCI *dev = VHOST_USER_GPIO_PCI(vpci_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+
+    vpci_dev->nvectors = 1;
+    qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
+}
+
+static void vhost_user_gpio_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+    PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+    k->realize = vhost_user_gpio_pci_realize;
+    set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
+    pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+    pcidev_k->device_id = 0; /* Set by virtio-pci based on virtio id */
+    pcidev_k->revision = 0x00;
+    pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
+}
+
+static void vhost_user_gpio_pci_instance_init(Object *obj)
+{
+    VHostUserGPIOPCI *dev = VHOST_USER_GPIO_PCI(obj);
+
+    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
+                                TYPE_VHOST_USER_GPIO);
+}
+
+static const VirtioPCIDeviceTypeInfo vhost_user_gpio_pci_info = {
+    .base_name = TYPE_VHOST_USER_GPIO_PCI,
+    .non_transitional_name = "vhost-user-gpio-pci",
+    .instance_size = sizeof(VHostUserGPIOPCI),
+    .instance_init = vhost_user_gpio_pci_instance_init,
+    .class_init = vhost_user_gpio_pci_class_init,
+};
+
+static void vhost_user_gpio_pci_register(void)
+{
+    virtio_pci_types_register(&vhost_user_gpio_pci_info);
+}
+
+type_init(vhost_user_gpio_pci_register);
-- 
2.31.1.272.g89b43f80a514



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/2] hw/virtio: add boilerplate for vhost-user-gpio device
  2022-01-12 11:34 ` [PATCH 1/2] hw/virtio: add boilerplate for vhost-user-gpio device Viresh Kumar
@ 2022-01-14 14:05   ` Alex Bennée
  2022-01-14 14:06   ` Alex Bennée
  1 sibling, 0 replies; 24+ messages in thread
From: Alex Bennée @ 2022-01-14 14:05 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: stratos-dev, Vincent Guittot, qemu-devel, Michael S. Tsirkin


Viresh Kumar <viresh.kumar@linaro.org> writes:

> This creates the QEMU side of the vhost-user-gpio device which connects
> to the remote daemon. It is based of vhost-user-i2c code.
>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/2] hw/virtio: add boilerplate for vhost-user-gpio device
  2022-01-12 11:34 ` [PATCH 1/2] hw/virtio: add boilerplate for vhost-user-gpio device Viresh Kumar
  2022-01-14 14:05   ` Alex Bennée
@ 2022-01-14 14:06   ` Alex Bennée
  2022-01-17  6:38     ` Viresh Kumar
  1 sibling, 1 reply; 24+ messages in thread
From: Alex Bennée @ 2022-01-14 14:06 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: stratos-dev, Vincent Guittot, qemu-devel, Michael S. Tsirkin


Viresh Kumar <viresh.kumar@linaro.org> writes:

> This creates the QEMU side of the vhost-user-gpio device which connects
> to the remote daemon. It is based of vhost-user-i2c code.
>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
<snip>
> +++ b/include/hw/virtio/vhost-user-gpio.h
> @@ -0,0 +1,35 @@
> +/*
> + * Vhost-user GPIO virtio device
> + *
> + * Copyright (c) 2021 Viresh Kumar <viresh.kumar@linaro.org>
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#ifndef _QEMU_VHOST_USER_GPIO_H
> +#define _QEMU_VHOST_USER_GPIO_H
> +
> +#include "hw/virtio/virtio.h"
> +#include "hw/virtio/vhost.h"
> +#include "hw/virtio/vhost-user.h"
> +#include "standard-headers/linux/virtio_gpio.h"

Hmm this fails:

  In file included from ../../hw/virtio/vhost-user-gpio.c:13:
  /home/alex/lsrc/qemu.git/include/hw/virtio/vhost-user-gpio.h:15:10: fatal error: standard-headers/linux/virtio_gpio.h: No such file or directory
     15 | #include "standard-headers/linux/virtio_gpio.h"
        |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  compilation terminated.

The usual solution is to create a patch that imports the headers using:

  ./scripts/update-linux-headers.sh

either from the current mainline (or your own tree if the feature is in
flight) and mark the patch clearly as not for merging.

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/2] hw/virtio: add vhost-user-gpio-pci boilerplate
  2022-01-12 11:34 ` [PATCH 2/2] hw/virtio: add vhost-user-gpio-pci boilerplate Viresh Kumar
@ 2022-01-14 14:10   ` Alex Bennée
  0 siblings, 0 replies; 24+ messages in thread
From: Alex Bennée @ 2022-01-14 14:10 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: stratos-dev, Vincent Guittot, qemu-devel, Michael S. Tsirkin


Viresh Kumar <viresh.kumar@linaro.org> writes:

> This allows is to instantiate a vhost-user-gpio device as part of a PCI
> bus. It is mostly boilerplate which looks pretty similar to the
> vhost-user-fs-pci device.
>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/2] hw/virtio: add boilerplate for vhost-user-gpio device
  2022-01-14 14:06   ` Alex Bennée
@ 2022-01-17  6:38     ` Viresh Kumar
  2022-01-17 10:17       ` Alex Bennée
  0 siblings, 1 reply; 24+ messages in thread
From: Viresh Kumar @ 2022-01-17  6:38 UTC (permalink / raw)
  To: Alex Bennée
  Cc: stratos-dev, Vincent Guittot, qemu-devel, Michael S. Tsirkin

On 14-01-22, 14:06, Alex Bennée wrote:
> 
> Viresh Kumar <viresh.kumar@linaro.org> writes:
> 
> > This creates the QEMU side of the vhost-user-gpio device which connects
> > to the remote daemon. It is based of vhost-user-i2c code.
> >
> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> <snip>
> > +++ b/include/hw/virtio/vhost-user-gpio.h
> > @@ -0,0 +1,35 @@
> > +/*
> > + * Vhost-user GPIO virtio device
> > + *
> > + * Copyright (c) 2021 Viresh Kumar <viresh.kumar@linaro.org>
> > + *
> > + * SPDX-License-Identifier: GPL-2.0-or-later
> > + */
> > +
> > +#ifndef _QEMU_VHOST_USER_GPIO_H
> > +#define _QEMU_VHOST_USER_GPIO_H
> > +
> > +#include "hw/virtio/virtio.h"
> > +#include "hw/virtio/vhost.h"
> > +#include "hw/virtio/vhost-user.h"
> > +#include "standard-headers/linux/virtio_gpio.h"
> 
> Hmm this fails:
> 
>   In file included from ../../hw/virtio/vhost-user-gpio.c:13:
>   /home/alex/lsrc/qemu.git/include/hw/virtio/vhost-user-gpio.h:15:10: fatal error: standard-headers/linux/virtio_gpio.h: No such file or directory
>      15 | #include "standard-headers/linux/virtio_gpio.h"
>         |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   compilation terminated.
> 
> The usual solution is to create a patch that imports the headers using:
> 
>   ./scripts/update-linux-headers.sh
> 
> either from the current mainline (or your own tree if the feature is in
> flight) and mark the patch clearly as not for merging.

I have that patch with me and I planned to mention it in the cover-letter, but
completely failed while sending it.

Should I resend this with the NOT-TO-BE-APPLIED patch now ? Everything is in
mainline, so the committer just needs to run scripts/update-linux-headers.sh.

-- 
viresh


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/2] virtio: Add vhost-user-gpio device's support
  2022-01-12 11:34 [PATCH 0/2] virtio: Add vhost-user-gpio device's support Viresh Kumar
  2022-01-12 11:34 ` [PATCH 1/2] hw/virtio: add boilerplate for vhost-user-gpio device Viresh Kumar
  2022-01-12 11:34 ` [PATCH 2/2] hw/virtio: add vhost-user-gpio-pci boilerplate Viresh Kumar
@ 2022-01-17  8:47 ` Michael S. Tsirkin
  2022-01-17 10:11   ` Alex Bennée
  2022-02-04 12:23 ` Michael S. Tsirkin
  2022-04-05 10:55 ` Alex Bennée
  4 siblings, 1 reply; 24+ messages in thread
From: Michael S. Tsirkin @ 2022-01-17  8:47 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: Vincent Guittot, Alex Bennée, qemu-devel, stratos-dev

On Wed, Jan 12, 2022 at 05:04:57PM +0530, Viresh Kumar wrote:
> Hello,
> 
> This patchset adds vhost-user-gpio device's support in Qemu. The support for the
> same has already been added to virtio specification and Linux Kernel.
> 
> A Rust based backend is also in progress and is tested against this patchset:
> 
> https://github.com/rust-vmm/vhost-device/pull/76


I'm reluctant to add this with no tests in tree.
Want to write a minimal libhost-user based backend?
We also need some maintainers to step up.


> --
> Viresh
> 
> Viresh Kumar (2):
>   hw/virtio: add boilerplate for vhost-user-gpio device
>   hw/virtio: add vhost-user-gpio-pci boilerplate
> 
>  hw/virtio/Kconfig                   |   5 +
>  hw/virtio/meson.build               |   2 +
>  hw/virtio/vhost-user-gpio-pci.c     |  69 ++++++
>  hw/virtio/vhost-user-gpio.c         | 343 ++++++++++++++++++++++++++++
>  include/hw/virtio/vhost-user-gpio.h |  35 +++
>  5 files changed, 454 insertions(+)
>  create mode 100644 hw/virtio/vhost-user-gpio-pci.c
>  create mode 100644 hw/virtio/vhost-user-gpio.c
>  create mode 100644 include/hw/virtio/vhost-user-gpio.h
> 
> -- 
> 2.31.1.272.g89b43f80a514



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/2] virtio: Add vhost-user-gpio device's support
  2022-01-17  8:47 ` [PATCH 0/2] virtio: Add vhost-user-gpio device's support Michael S. Tsirkin
@ 2022-01-17 10:11   ` Alex Bennée
  2022-01-20  4:02     ` Viresh Kumar
  2022-01-20 11:25     ` [PATCH 0/2] virtio: Add vhost-user-gpio device's support Michael S. Tsirkin
  0 siblings, 2 replies; 24+ messages in thread
From: Alex Bennée @ 2022-01-17 10:11 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Viresh Kumar, Vincent Guittot, qemu-devel, stratos-dev


"Michael S. Tsirkin" <mst@redhat.com> writes:

> On Wed, Jan 12, 2022 at 05:04:57PM +0530, Viresh Kumar wrote:
>> Hello,
>> 
>> This patchset adds vhost-user-gpio device's support in Qemu. The support for the
>> same has already been added to virtio specification and Linux Kernel.
>> 
>> A Rust based backend is also in progress and is tested against this patchset:
>> 
>> https://github.com/rust-vmm/vhost-device/pull/76
>
>
> I'm reluctant to add this with no tests in tree.
> Want to write a minimal libhost-user based backend?

This is going to be a problem going forward as we have more out-of-tree
backends written as a first preference. While the first couple of vhost
devices have C implementations in contrib before we worked on the rust
version I think we are getting to the point of skipping a first C
version for future devices.

However I notice we have qtest/vhost-user-test.c so would that be enough
to ensure we can instantiate the device and a basic vhost-user
initialisation sequence doesn't cause it to crap out. This obviously
won't be exercising the virtq processing itself but does that really
exercise any of QEMU's boilerplate anyway?

> We also need some maintainers to step up.

You mean more reviewers for the vhost and virtio sections of QEMU's
maintainers?

>
>
>> --
>> Viresh
>> 
>> Viresh Kumar (2):
>>   hw/virtio: add boilerplate for vhost-user-gpio device
>>   hw/virtio: add vhost-user-gpio-pci boilerplate
>> 
>>  hw/virtio/Kconfig                   |   5 +
>>  hw/virtio/meson.build               |   2 +
>>  hw/virtio/vhost-user-gpio-pci.c     |  69 ++++++
>>  hw/virtio/vhost-user-gpio.c         | 343 ++++++++++++++++++++++++++++
>>  include/hw/virtio/vhost-user-gpio.h |  35 +++
>>  5 files changed, 454 insertions(+)
>>  create mode 100644 hw/virtio/vhost-user-gpio-pci.c
>>  create mode 100644 hw/virtio/vhost-user-gpio.c
>>  create mode 100644 include/hw/virtio/vhost-user-gpio.h
>> 
>> -- 
>> 2.31.1.272.g89b43f80a514


-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/2] hw/virtio: add boilerplate for vhost-user-gpio device
  2022-01-17  6:38     ` Viresh Kumar
@ 2022-01-17 10:17       ` Alex Bennée
  0 siblings, 0 replies; 24+ messages in thread
From: Alex Bennée @ 2022-01-17 10:17 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: stratos-dev, Vincent Guittot, qemu-devel, Michael S. Tsirkin


Viresh Kumar <viresh.kumar@linaro.org> writes:

> On 14-01-22, 14:06, Alex Bennée wrote:
>> 
>> Viresh Kumar <viresh.kumar@linaro.org> writes:
>> 
>> > This creates the QEMU side of the vhost-user-gpio device which connects
>> > to the remote daemon. It is based of vhost-user-i2c code.
>> >
>> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
>> <snip>
>> > +++ b/include/hw/virtio/vhost-user-gpio.h
>> > @@ -0,0 +1,35 @@
>> > +/*
>> > + * Vhost-user GPIO virtio device
>> > + *
>> > + * Copyright (c) 2021 Viresh Kumar <viresh.kumar@linaro.org>
>> > + *
>> > + * SPDX-License-Identifier: GPL-2.0-or-later
>> > + */
>> > +
>> > +#ifndef _QEMU_VHOST_USER_GPIO_H
>> > +#define _QEMU_VHOST_USER_GPIO_H
>> > +
>> > +#include "hw/virtio/virtio.h"
>> > +#include "hw/virtio/vhost.h"
>> > +#include "hw/virtio/vhost-user.h"
>> > +#include "standard-headers/linux/virtio_gpio.h"
>> 
>> Hmm this fails:
>> 
>>   In file included from ../../hw/virtio/vhost-user-gpio.c:13:
>>   /home/alex/lsrc/qemu.git/include/hw/virtio/vhost-user-gpio.h:15:10: fatal error: standard-headers/linux/virtio_gpio.h: No such file or directory
>>      15 | #include "standard-headers/linux/virtio_gpio.h"
>>         |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>   compilation terminated.
>> 
>> The usual solution is to create a patch that imports the headers using:
>> 
>>   ./scripts/update-linux-headers.sh
>> 
>> either from the current mainline (or your own tree if the feature is in
>> flight) and mark the patch clearly as not for merging.
>
> I have that patch with me and I planned to mention it in the cover-letter, but
> completely failed while sending it.
>
> Should I resend this with the NOT-TO-BE-APPLIED patch now ? Everything is in
> mainline, so the committer just needs to run
> scripts/update-linux-headers.sh.

If it's a released version of mainline even better because you can just
include the patch generated from a clean release and it can get merged.

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/2] virtio: Add vhost-user-gpio device's support
  2022-01-17 10:11   ` Alex Bennée
@ 2022-01-20  4:02     ` Viresh Kumar
  2022-01-20 10:57       ` Michael S. Tsirkin
  2022-01-21 15:15       ` [RFC PATCH] tests/qtest: attempt to enable tests for virtio-gpio (!working) Alex Bennée
  2022-01-20 11:25     ` [PATCH 0/2] virtio: Add vhost-user-gpio device's support Michael S. Tsirkin
  1 sibling, 2 replies; 24+ messages in thread
From: Viresh Kumar @ 2022-01-20  4:02 UTC (permalink / raw)
  To: Alex Bennée
  Cc: stratos-dev, Vincent Guittot, qemu-devel, Michael S. Tsirkin

On 17-01-22, 10:11, Alex Bennée wrote:
> 
> "Michael S. Tsirkin" <mst@redhat.com> writes:
> 
> > On Wed, Jan 12, 2022 at 05:04:57PM +0530, Viresh Kumar wrote:
> >> Hello,
> >> 
> >> This patchset adds vhost-user-gpio device's support in Qemu. The support for the
> >> same has already been added to virtio specification and Linux Kernel.
> >> 
> >> A Rust based backend is also in progress and is tested against this patchset:
> >> 
> >> https://github.com/rust-vmm/vhost-device/pull/76
> >
> >
> > I'm reluctant to add this with no tests in tree.
> > Want to write a minimal libhost-user based backend?

I actually have one already, that I wrote before attempting the Rust
counterpart, but never upstreamed as I am not sure if anyone is ever
going to use it, as I am not. And I thought what's the point of
merging code which I will never end up using.

I am not sure what test I can add here to make sure this doesn't
breaks in future though.

> This is going to be a problem going forward as we have more out-of-tree
> backends written as a first preference. While the first couple of vhost
> devices have C implementations in contrib before we worked on the rust
> version I think we are getting to the point of skipping a first C
> version for future devices.
> 
> However I notice we have qtest/vhost-user-test.c so would that be enough
> to ensure we can instantiate the device and a basic vhost-user
> initialisation sequence doesn't cause it to crap out. This obviously
> won't be exercising the virtq processing itself but does that really
> exercise any of QEMU's boilerplate anyway?
> 
> > We also need some maintainers to step up.
> 
> You mean more reviewers for the vhost and virtio sections of QEMU's
> maintainers?

And I too was waiting for replies on these. I can surely write
something up if you guys feel there is a need. I just want to
understand it better.

-- 
viresh


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/2] virtio: Add vhost-user-gpio device's support
  2022-01-20  4:02     ` Viresh Kumar
@ 2022-01-20 10:57       ` Michael S. Tsirkin
  2022-01-20 15:41         ` Alex Bennée
  2022-01-21 15:15       ` [RFC PATCH] tests/qtest: attempt to enable tests for virtio-gpio (!working) Alex Bennée
  1 sibling, 1 reply; 24+ messages in thread
From: Michael S. Tsirkin @ 2022-01-20 10:57 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: Vincent Guittot, Alex Bennée, qemu-devel, stratos-dev

On Thu, Jan 20, 2022 at 09:32:34AM +0530, Viresh Kumar wrote:
> On 17-01-22, 10:11, Alex Bennée wrote:
> > 
> > "Michael S. Tsirkin" <mst@redhat.com> writes:
> > 
> > > On Wed, Jan 12, 2022 at 05:04:57PM +0530, Viresh Kumar wrote:
> > >> Hello,
> > >> 
> > >> This patchset adds vhost-user-gpio device's support in Qemu. The support for the
> > >> same has already been added to virtio specification and Linux Kernel.
> > >> 
> > >> A Rust based backend is also in progress and is tested against this patchset:
> > >> 
> > >> https://github.com/rust-vmm/vhost-device/pull/76
> > >
> > >
> > > I'm reluctant to add this with no tests in tree.
> > > Want to write a minimal libhost-user based backend?
> 
> I actually have one already, that I wrote before attempting the Rust
> counterpart, but never upstreamed as I am not sure if anyone is ever
> going to use it, as I am not. And I thought what's the point of
> merging code which I will never end up using.
> 
> I am not sure what test I can add here to make sure this doesn't
> breaks in future though.

something that executes with make check.


> > This is going to be a problem going forward as we have more out-of-tree
> > backends written as a first preference. While the first couple of vhost
> > devices have C implementations in contrib before we worked on the rust
> > version I think we are getting to the point of skipping a first C
> > version for future devices.
> > 
> > However I notice we have qtest/vhost-user-test.c so would that be enough
> > to ensure we can instantiate the device and a basic vhost-user
> > initialisation sequence doesn't cause it to crap out. This obviously
> > won't be exercising the virtq processing itself but does that really
> > exercise any of QEMU's boilerplate anyway?
> > 
> > > We also need some maintainers to step up.
> > 
> > You mean more reviewers for the vhost and virtio sections of QEMU's
> > maintainers?
> 
> And I too was waiting for replies on these. I can surely write
> something up if you guys feel there is a need. I just want to
> understand it better.
> 
> -- 
> viresh



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/2] virtio: Add vhost-user-gpio device's support
  2022-01-17 10:11   ` Alex Bennée
  2022-01-20  4:02     ` Viresh Kumar
@ 2022-01-20 11:25     ` Michael S. Tsirkin
  1 sibling, 0 replies; 24+ messages in thread
From: Michael S. Tsirkin @ 2022-01-20 11:25 UTC (permalink / raw)
  To: Alex Bennée; +Cc: Viresh Kumar, Vincent Guittot, qemu-devel, stratos-dev

On Mon, Jan 17, 2022 at 10:11:21AM +0000, Alex Bennée wrote:
> 
> "Michael S. Tsirkin" <mst@redhat.com> writes:
> 
> > On Wed, Jan 12, 2022 at 05:04:57PM +0530, Viresh Kumar wrote:
> >> Hello,
> >> 
> >> This patchset adds vhost-user-gpio device's support in Qemu. The support for the
> >> same has already been added to virtio specification and Linux Kernel.
> >> 
> >> A Rust based backend is also in progress and is tested against this patchset:
> >> 
> >> https://github.com/rust-vmm/vhost-device/pull/76
> >
> >
> > I'm reluctant to add this with no tests in tree.
> > Want to write a minimal libhost-user based backend?
> 
> This is going to be a problem going forward as we have more out-of-tree
> backends written as a first preference. While the first couple of vhost
> devices have C implementations in contrib before we worked on the rust
> version I think we are getting to the point of skipping a first C
> version for future devices.

Not sure what to do then. Integrate using submodules somehow?


> However I notice we have qtest/vhost-user-test.c so would that be enough
> to ensure we can instantiate the device and a basic vhost-user
> initialisation sequence doesn't cause it to crap out. This obviously
> won't be exercising the virtq processing itself but does that really
> exercise any of QEMU's boilerplate anyway?

we do have tests e.g. for network based on vhost-user, yes.


> > We also need some maintainers to step up.
> 
> You mean more reviewers for the vhost and virtio sections of QEMU's
> maintainers?
> 
> >
> >
> >> --
> >> Viresh
> >> 
> >> Viresh Kumar (2):
> >>   hw/virtio: add boilerplate for vhost-user-gpio device
> >>   hw/virtio: add vhost-user-gpio-pci boilerplate
> >> 
> >>  hw/virtio/Kconfig                   |   5 +
> >>  hw/virtio/meson.build               |   2 +
> >>  hw/virtio/vhost-user-gpio-pci.c     |  69 ++++++
> >>  hw/virtio/vhost-user-gpio.c         | 343 ++++++++++++++++++++++++++++
> >>  include/hw/virtio/vhost-user-gpio.h |  35 +++
> >>  5 files changed, 454 insertions(+)
> >>  create mode 100644 hw/virtio/vhost-user-gpio-pci.c
> >>  create mode 100644 hw/virtio/vhost-user-gpio.c
> >>  create mode 100644 include/hw/virtio/vhost-user-gpio.h
> >> 
> >> -- 
> >> 2.31.1.272.g89b43f80a514
> 
> 
> -- 
> Alex Bennée



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/2] virtio: Add vhost-user-gpio device's support
  2022-01-20 10:57       ` Michael S. Tsirkin
@ 2022-01-20 15:41         ` Alex Bennée
  0 siblings, 0 replies; 24+ messages in thread
From: Alex Bennée @ 2022-01-20 15:41 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Viresh Kumar, Vincent Guittot, qemu-devel, stratos-dev


"Michael S. Tsirkin" <mst@redhat.com> writes:

> On Thu, Jan 20, 2022 at 09:32:34AM +0530, Viresh Kumar wrote:
>> On 17-01-22, 10:11, Alex Bennée wrote:
>> > 
>> > "Michael S. Tsirkin" <mst@redhat.com> writes:
>> > 
>> > > On Wed, Jan 12, 2022 at 05:04:57PM +0530, Viresh Kumar wrote:
>> > >> Hello,
>> > >> 
>> > >> This patchset adds vhost-user-gpio device's support in Qemu. The support for the
>> > >> same has already been added to virtio specification and Linux Kernel.
>> > >> 
>> > >> A Rust based backend is also in progress and is tested against this patchset:
>> > >> 
>> > >> https://github.com/rust-vmm/vhost-device/pull/76
>> > >
>> > >
>> > > I'm reluctant to add this with no tests in tree.
>> > > Want to write a minimal libhost-user based backend?
>> 
>> I actually have one already, that I wrote before attempting the Rust
>> counterpart, but never upstreamed as I am not sure if anyone is ever
>> going to use it, as I am not. And I thought what's the point of
>> merging code which I will never end up using.
>> 
>> I am not sure what test I can add here to make sure this doesn't
>> breaks in future though.
>
> something that executes with make check.

With Eric's latest series
(20220118203833.316741-1-eric.auger@redhat.com) we are already
exercising most of the PCI code:

  ➜  gcov ./libqemu-aarch64-softmmu.fa.p/hw_virtio_vhost-user-gpio.c.gcda
  File '../../hw/virtio/vhost-user-gpio.c'
  Lines executed:10.43% of 163
  Creating 'vhost-user-gpio.c.gcov'

  File '/home/alex/lsrc/qemu.git/include/qemu/bitops.h'
  Lines executed:100.00% of 4
  Creating 'bitops.h.gcov'

  File '/home/alex/lsrc/qemu.git/include/hw/virtio/virtio.h'
  Lines executed:12.50% of 8
  Creating 'virtio.h.gcov'

  File '/home/alex/lsrc/qemu.git/include/hw/virtio/vhost-user-gpio.h'
  Lines executed:0.00% of 1
  Creating 'vhost-user-gpio.h.gcov'

  File '/home/alex/lsrc/qemu.git/include/hw/virtio/virtio-bus.h'
  Lines executed:0.00% of 1
  Creating 'virtio-bus.h.gcov'

  File '/home/alex/lsrc/qemu.git/include/hw/qdev-core.h'
  Lines executed:50.00% of 2
  Creating 'qdev-core.h.gcov'

  🕙15:40:35 alex@zen:qemu.git/builds/gprof  on  review/virtio-gpio-boilerplate [$?] 
  ➜  gcov ./libqemu-aarch64-softmmu.fa.p/hw_virtio_vhost-user-gpio-pci.c.gcda
  File '../../hw/virtio/vhost-user-gpio-pci.c'
  Lines executed:76.92% of 26
  Creating 'vhost-user-gpio-pci.c.gcov'

  File '/home/alex/lsrc/qemu.git/include/qemu/bitops.h'
  Lines executed:100.00% of 4
  Creating 'bitops.h.gcov'

  File '../../hw/virtio/virtio-pci.h'
  Lines executed:100.00% of 1
  Creating 'virtio-pci.h.gcov'

  File '/home/alex/lsrc/qemu.git/include/hw/pci/pci.h'
  Lines executed:100.00% of 1
  Creating 'pci.h.gcov'

  File '/home/alex/lsrc/qemu.git/include/hw/qdev-core.h'
  Lines executed:50.00% of 2
  Creating 'qdev-core.h.gcov'

So I think if we add the runes to ensure we instantiate both types
explicitly I think we will have enough coverage.

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [RFC PATCH] tests/qtest: attempt to enable tests for virtio-gpio (!working)
  2022-01-20  4:02     ` Viresh Kumar
  2022-01-20 10:57       ` Michael S. Tsirkin
@ 2022-01-21 15:15       ` Alex Bennée
  2022-03-31  9:52         ` Alex Bennée
  1 sibling, 1 reply; 24+ messages in thread
From: Alex Bennée @ 2022-01-21 15:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Viresh Kumar, Thomas Huth, Alex Bennée,
	Paolo Bonzini

We don't have a virtio-gpio implementation in QEMU and only
support a vhost-user backend. The QEMU side of the code is minimal so
it should be enough to instantiate the device and pass some vhost-user
messages over the control socket. To do this we hook into the existing
vhost-user-test code and just add the bits required for gpio.

Based-on: 20220118203833.316741-1-eric.auger@redhat.com
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>

---

This goes as far as to add things to the QOS tree but so far it's
failing to properly start QEMU with the chardev socket needed to
communicate between the mock vhost-user daemon and QEMU itself.
---
 tests/qtest/libqos/virtio-gpio.h | 34 +++++++++++
 tests/qtest/libqos/virtio-gpio.c | 98 ++++++++++++++++++++++++++++++++
 tests/qtest/vhost-user-test.c    | 34 +++++++++++
 tests/qtest/libqos/meson.build   |  1 +
 4 files changed, 167 insertions(+)
 create mode 100644 tests/qtest/libqos/virtio-gpio.h
 create mode 100644 tests/qtest/libqos/virtio-gpio.c

diff --git a/tests/qtest/libqos/virtio-gpio.h b/tests/qtest/libqos/virtio-gpio.h
new file mode 100644
index 0000000000..abe6967ae9
--- /dev/null
+++ b/tests/qtest/libqos/virtio-gpio.h
@@ -0,0 +1,34 @@
+/*
+ * virtio-gpio structures
+ *
+ * Copyright (c) 2022 Linaro Ltd
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef TESTS_LIBQOS_VIRTIO_GPIO_H
+#define TESTS_LIBQOS_VIRTIO_GPIO_H
+
+#include "qgraph.h"
+#include "virtio.h"
+#include "virtio-pci.h"
+
+typedef struct QVhostUserGPIO QVhostUserGPIO;
+typedef struct QVhostUserGPIOPCI QVhostUserGPIOPCI;
+typedef struct QVhostUserGPIODevice QVhostUserGPIODevice;
+
+struct QVhostUserGPIO {
+    QVirtioDevice *vdev;
+};
+
+struct QVhostUserGPIOPCI {
+    QVirtioPCIDevice pci_vdev;
+    QVhostUserGPIO gpio;
+};
+
+struct QVhostUserGPIODevice {
+    QOSGraphObject obj;
+    QVhostUserGPIO gpio;
+};
+
+#endif
diff --git a/tests/qtest/libqos/virtio-gpio.c b/tests/qtest/libqos/virtio-gpio.c
new file mode 100644
index 0000000000..62c8074777
--- /dev/null
+++ b/tests/qtest/libqos/virtio-gpio.c
@@ -0,0 +1,98 @@
+/*
+ * virtio-gpio nodes for testing
+ *
+ * Copyright (c) 2022 Linaro Ltd
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "libqtest.h"
+#include "qemu/module.h"
+#include "qgraph.h"
+#include "virtio-gpio.h"
+
+static void *qvirtio_gpio_get_driver(QVhostUserGPIO *v_gpio,
+                                       const char *interface)
+{
+    if (!g_strcmp0(interface, "vhost-user-gpio")) {
+        return v_gpio;
+    }
+    if (!g_strcmp0(interface, "virtio")) {
+        return v_gpio->vdev;
+    }
+
+    fprintf(stderr, "%s not present in virtio-gpio-device\n", interface);
+    g_assert_not_reached();
+}
+
+static void *qvirtio_gpio_device_get_driver(void *object,
+                                              const char *interface)
+{
+    QVhostUserGPIODevice *v_gpio = object;
+    return qvirtio_gpio_get_driver(&v_gpio->gpio, interface);
+}
+
+static void *virtio_gpio_device_create(void *virtio_dev,
+                                         QGuestAllocator *t_alloc,
+                                         void *addr)
+{
+    QVhostUserGPIODevice *virtio_device = g_new0(QVhostUserGPIODevice, 1);
+    QVhostUserGPIO *interface = &virtio_device->gpio;
+
+    interface->vdev = virtio_dev;
+
+    virtio_device->obj.get_driver = qvirtio_gpio_device_get_driver;
+
+    return &virtio_device->obj;
+}
+
+/* virtio-gpio-pci */
+static void *qvirtio_gpio_pci_get_driver(void *object, const char *interface)
+{
+    QVhostUserGPIOPCI *v_gpio = object;
+    if (!g_strcmp0(interface, "pci-device")) {
+        return v_gpio->pci_vdev.pdev;
+    }
+    return qvirtio_gpio_get_driver(&v_gpio->gpio, interface);
+}
+
+static void *virtio_gpio_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
+                                      void *addr)
+{
+    QVhostUserGPIOPCI *virtio_spci = g_new0(QVhostUserGPIOPCI, 1);
+    QVhostUserGPIO *interface = &virtio_spci->gpio;
+    QOSGraphObject *obj = &virtio_spci->pci_vdev.obj;
+
+    virtio_pci_init(&virtio_spci->pci_vdev, pci_bus, addr);
+    interface->vdev = &virtio_spci->pci_vdev.vdev;
+
+    obj->get_driver = qvirtio_gpio_pci_get_driver;
+
+    return obj;
+}
+
+static void virtio_gpio_register_nodes(void)
+{
+    QPCIAddress addr = {
+        .devfn = QPCI_DEVFN(4, 0),
+    };
+
+    QOSGraphEdgeOptions edge_opts = { };
+
+    /* vhost-user-gpio-device */
+    edge_opts.extra_device_opts = "id=gpio0,chardev=vhgpio0";
+    qos_node_create_driver("vhost-user-gpio-device",
+                            virtio_gpio_device_create);
+    qos_node_consumes("vhost-user-gpio-device", "virtio-bus", &edge_opts);
+    qos_node_produces("vhost-user-gpio-device", "vhost-user-gpio");
+
+    /* virtio-gpio-pci */
+    edge_opts.extra_device_opts = "id=gpio0,addr=04.0,chardev=vhgpio0";
+    add_qpci_address(&edge_opts, &addr);
+    qos_node_create_driver("vhost-user-gpio-pci", virtio_gpio_pci_create);
+    qos_node_consumes("vhost-user-gpio-pci", "pci-bus", &edge_opts);
+    qos_node_produces("vhost-user-gpio-pci", "vhost-user-gpio");
+}
+
+libqos_init(virtio_gpio_register_nodes);
diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
index ee30f54796..4f8789424b 100644
--- a/tests/qtest/vhost-user-test.c
+++ b/tests/qtest/vhost-user-test.c
@@ -43,6 +43,7 @@
                         " -numa node,memdev=mem"
 #define QEMU_CMD_CHR    " -chardev socket,id=%s,path=%s%s"
 #define QEMU_CMD_NETDEV " -netdev vhost-user,id=hs0,chardev=%s,vhostforce=on"
+#define QEMU_CMD_GPIO   " -device vhost-user-gpio-pci,id=gpio0,chardev=%s,vhostforce=on"
 
 #define HUGETLBFS_MAGIC       0x958458f6
 
@@ -137,6 +138,7 @@ enum {
 
 enum {
     VHOST_USER_NET,
+    VHOST_USER_GPIO,
 };
 
 typedef struct TestServer {
@@ -194,6 +196,14 @@ static void append_vhost_net_opts(TestServer *s, GString *cmd_line,
                            chr_opts, s->chr_name);
 }
 
+static void append_vhost_gpio_opts(TestServer *s, GString *cmd_line,
+                             const char *chr_opts)
+{
+    g_string_append_printf(cmd_line, QEMU_CMD_CHR QEMU_CMD_GPIO,
+                           s->chr_name, s->socket_path,
+                           chr_opts, s->chr_name);
+}
+
 static void append_mem_opts(TestServer *server, GString *cmd_line,
                             int size, enum test_memfd memfd)
 {
@@ -1014,3 +1024,27 @@ static void register_vhost_user_test(void)
                  test_multiqueue, &opts);
 }
 libqos_init(register_vhost_user_test);
+
+static struct vhost_user_ops g_vu_gpio_ops = {
+    .type = VHOST_USER_GPIO,
+
+    .append_opts = append_vhost_gpio_opts,
+
+    .set_features = vu_net_set_features,
+    .get_protocol_features = vu_net_get_protocol_features,
+};
+
+static void register_vhost_gpio_test(void)
+{
+    QOSGraphTestOptions opts = {
+        .before = vhost_user_test_setup,
+        .subprocess = true,
+        .arg = &g_vu_gpio_ops,
+    };
+
+    qemu_add_opts(&qemu_chardev_opts);
+
+    qos_add_test("read-guest-mem/memfile",
+                 "vhost-user-gpio", test_read_guest_mem, &opts);
+}
+libqos_init(register_vhost_gpio_test);
diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build
index 8c8ee15553..f581330d8b 100644
--- a/tests/qtest/libqos/meson.build
+++ b/tests/qtest/libqos/meson.build
@@ -42,6 +42,7 @@ libqos_srcs = files('../libqtest.c',
         'virtio-scsi.c',
         'virtio-serial.c',
         'virtio-iommu.c',
+        'virtio-gpio.c',
         'generic-pcihost.c',
 
         # qgraph machines:
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/2] virtio: Add vhost-user-gpio device's support
  2022-01-12 11:34 [PATCH 0/2] virtio: Add vhost-user-gpio device's support Viresh Kumar
                   ` (2 preceding siblings ...)
  2022-01-17  8:47 ` [PATCH 0/2] virtio: Add vhost-user-gpio device's support Michael S. Tsirkin
@ 2022-02-04 12:23 ` Michael S. Tsirkin
  2022-02-04 13:52   ` Alex Bennée
  2022-04-05 10:55 ` Alex Bennée
  4 siblings, 1 reply; 24+ messages in thread
From: Michael S. Tsirkin @ 2022-02-04 12:23 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: Vincent Guittot, Alex Bennée, qemu-devel, stratos-dev

On Wed, Jan 12, 2022 at 05:04:57PM +0530, Viresh Kumar wrote:
> Hello,
> 
> This patchset adds vhost-user-gpio device's support in Qemu. The support for the
> same has already been added to virtio specification and Linux Kernel.
> 
> A Rust based backend is also in progress and is tested against this patchset:
> 
> https://github.com/rust-vmm/vhost-device/pull/76

So I'm waiting for v2 of this, right?

> --
> Viresh
> 
> Viresh Kumar (2):
>   hw/virtio: add boilerplate for vhost-user-gpio device
>   hw/virtio: add vhost-user-gpio-pci boilerplate
> 
>  hw/virtio/Kconfig                   |   5 +
>  hw/virtio/meson.build               |   2 +
>  hw/virtio/vhost-user-gpio-pci.c     |  69 ++++++
>  hw/virtio/vhost-user-gpio.c         | 343 ++++++++++++++++++++++++++++
>  include/hw/virtio/vhost-user-gpio.h |  35 +++
>  5 files changed, 454 insertions(+)
>  create mode 100644 hw/virtio/vhost-user-gpio-pci.c
>  create mode 100644 hw/virtio/vhost-user-gpio.c
>  create mode 100644 include/hw/virtio/vhost-user-gpio.h
> 
> -- 
> 2.31.1.272.g89b43f80a514



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/2] virtio: Add vhost-user-gpio device's support
  2022-02-04 12:23 ` Michael S. Tsirkin
@ 2022-02-04 13:52   ` Alex Bennée
  2022-02-04 14:06     ` Michael S. Tsirkin
  0 siblings, 1 reply; 24+ messages in thread
From: Alex Bennée @ 2022-02-04 13:52 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Viresh Kumar, Vincent Guittot, qemu-devel, stratos-dev


"Michael S. Tsirkin" <mst@redhat.com> writes:

> On Wed, Jan 12, 2022 at 05:04:57PM +0530, Viresh Kumar wrote:
>> Hello,
>> 
>> This patchset adds vhost-user-gpio device's support in Qemu. The support for the
>> same has already been added to virtio specification and Linux Kernel.
>> 
>> A Rust based backend is also in progress and is tested against this patchset:
>> 
>> https://github.com/rust-vmm/vhost-device/pull/76
>
> So I'm waiting for v2 of this, right?

If you can give any pointers for how to properly instantiate the stub in
qtest then we can spin v2 pretty quickly. I tried but it didn't work:

  Subject: [RFC PATCH] tests/qtest: attempt to enable tests for virtio-gpio (!working)
  Date: Fri, 21 Jan 2022 15:15:34 +0000
  Message-Id: <20220121151534.3654562-1-alex.bennee@linaro.org>
  X-Mailer: git-send-email 2.30.2
  In-Reply-To: <20220120040234.ehcjcdr6wrvlz3yc@vireshk-i7>
  References: <20220120040234.ehcjcdr6wrvlz3yc@vireshk-i7>

it's all a bit opaque as to why it didn't.

>
>> --
>> Viresh
>> 
>> Viresh Kumar (2):
>>   hw/virtio: add boilerplate for vhost-user-gpio device
>>   hw/virtio: add vhost-user-gpio-pci boilerplate
>> 
>>  hw/virtio/Kconfig                   |   5 +
>>  hw/virtio/meson.build               |   2 +
>>  hw/virtio/vhost-user-gpio-pci.c     |  69 ++++++
>>  hw/virtio/vhost-user-gpio.c         | 343 ++++++++++++++++++++++++++++
>>  include/hw/virtio/vhost-user-gpio.h |  35 +++
>>  5 files changed, 454 insertions(+)
>>  create mode 100644 hw/virtio/vhost-user-gpio-pci.c
>>  create mode 100644 hw/virtio/vhost-user-gpio.c
>>  create mode 100644 include/hw/virtio/vhost-user-gpio.h
>> 
>> -- 
>> 2.31.1.272.g89b43f80a514


-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/2] virtio: Add vhost-user-gpio device's support
  2022-02-04 13:52   ` Alex Bennée
@ 2022-02-04 14:06     ` Michael S. Tsirkin
  2022-03-31  9:58       ` Alex Bennée
  0 siblings, 1 reply; 24+ messages in thread
From: Michael S. Tsirkin @ 2022-02-04 14:06 UTC (permalink / raw)
  To: Alex Bennée; +Cc: Viresh Kumar, Vincent Guittot, qemu-devel, stratos-dev

On Fri, Feb 04, 2022 at 01:52:47PM +0000, Alex Bennée wrote:
> 
> "Michael S. Tsirkin" <mst@redhat.com> writes:
> 
> > On Wed, Jan 12, 2022 at 05:04:57PM +0530, Viresh Kumar wrote:
> >> Hello,
> >> 
> >> This patchset adds vhost-user-gpio device's support in Qemu. The support for the
> >> same has already been added to virtio specification and Linux Kernel.
> >> 
> >> A Rust based backend is also in progress and is tested against this patchset:
> >> 
> >> https://github.com/rust-vmm/vhost-device/pull/76
> >
> > So I'm waiting for v2 of this, right?
> 
> If you can give any pointers for how to properly instantiate the stub in
> qtest then we can spin v2 pretty quickly. I tried but it didn't work:
> 
>   Subject: [RFC PATCH] tests/qtest: attempt to enable tests for virtio-gpio (!working)
>   Date: Fri, 21 Jan 2022 15:15:34 +0000
>   Message-Id: <20220121151534.3654562-1-alex.bennee@linaro.org>
>   X-Mailer: git-send-email 2.30.2
>   In-Reply-To: <20220120040234.ehcjcdr6wrvlz3yc@vireshk-i7>
>   References: <20220120040234.ehcjcdr6wrvlz3yc@vireshk-i7>
> 
> it's all a bit opaque as to why it didn't.

A bit rushed short term, it this isn't resolved soon I'll try to help.
Maybe try CC other vhost-user maintainers (for blk,gpu etc) meanwhile.

> >
> >> --
> >> Viresh
> >> 
> >> Viresh Kumar (2):
> >>   hw/virtio: add boilerplate for vhost-user-gpio device
> >>   hw/virtio: add vhost-user-gpio-pci boilerplate
> >> 
> >>  hw/virtio/Kconfig                   |   5 +
> >>  hw/virtio/meson.build               |   2 +
> >>  hw/virtio/vhost-user-gpio-pci.c     |  69 ++++++
> >>  hw/virtio/vhost-user-gpio.c         | 343 ++++++++++++++++++++++++++++
> >>  include/hw/virtio/vhost-user-gpio.h |  35 +++
> >>  5 files changed, 454 insertions(+)
> >>  create mode 100644 hw/virtio/vhost-user-gpio-pci.c
> >>  create mode 100644 hw/virtio/vhost-user-gpio.c
> >>  create mode 100644 include/hw/virtio/vhost-user-gpio.h
> >> 
> >> -- 
> >> 2.31.1.272.g89b43f80a514
> 
> 
> -- 
> Alex Bennée



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC PATCH] tests/qtest: attempt to enable tests for virtio-gpio (!working)
  2022-01-21 15:15       ` [RFC PATCH] tests/qtest: attempt to enable tests for virtio-gpio (!working) Alex Bennée
@ 2022-03-31  9:52         ` Alex Bennée
  2022-03-31 16:17           ` Stefan Hajnoczi
  2022-04-04 17:59           ` Dr. David Alan Gilbert
  0 siblings, 2 replies; 24+ messages in thread
From: Alex Bennée @ 2022-03-31  9:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Halil Pasic, Thomas Huth, Michael S. Tsirkin,
	Viresh Kumar, Cornelia Huck, Eric Farman, Coiby Xu,
	Dr. David Alan Gilbert, Eric Auger, Gerd Hoffmann,
	Stefan Hajnoczi, Marc-André Lureau, Paolo Bonzini,
	Raphael Norwitz, Alex Bennée


(expanding the CC list for help, anyone have a better idea about how
vhost-user qtests should work/see obvious issues with this patch?)

Alex Bennée <alex.bennee@linaro.org> writes:

> We don't have a virtio-gpio implementation in QEMU and only
> support a vhost-user backend. The QEMU side of the code is minimal so
> it should be enough to instantiate the device and pass some vhost-user
> messages over the control socket. To do this we hook into the existing
> vhost-user-test code and just add the bits required for gpio.
>
> Based-on: 20220118203833.316741-1-eric.auger@redhat.com
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
>
> ---
>
> This goes as far as to add things to the QOS tree but so far it's
> failing to properly start QEMU with the chardev socket needed to
> communicate between the mock vhost-user daemon and QEMU itself.
> ---
>  tests/qtest/libqos/virtio-gpio.h | 34 +++++++++++
>  tests/qtest/libqos/virtio-gpio.c | 98 ++++++++++++++++++++++++++++++++
>  tests/qtest/vhost-user-test.c    | 34 +++++++++++
>  tests/qtest/libqos/meson.build   |  1 +
>  4 files changed, 167 insertions(+)
>  create mode 100644 tests/qtest/libqos/virtio-gpio.h
>  create mode 100644 tests/qtest/libqos/virtio-gpio.c
>
> diff --git a/tests/qtest/libqos/virtio-gpio.h b/tests/qtest/libqos/virtio-gpio.h
> new file mode 100644
> index 0000000000..abe6967ae9
> --- /dev/null
> +++ b/tests/qtest/libqos/virtio-gpio.h
> @@ -0,0 +1,34 @@
> +/*
> + * virtio-gpio structures
> + *
> + * Copyright (c) 2022 Linaro Ltd
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#ifndef TESTS_LIBQOS_VIRTIO_GPIO_H
> +#define TESTS_LIBQOS_VIRTIO_GPIO_H
> +
> +#include "qgraph.h"
> +#include "virtio.h"
> +#include "virtio-pci.h"
> +
> +typedef struct QVhostUserGPIO QVhostUserGPIO;
> +typedef struct QVhostUserGPIOPCI QVhostUserGPIOPCI;
> +typedef struct QVhostUserGPIODevice QVhostUserGPIODevice;
> +
> +struct QVhostUserGPIO {
> +    QVirtioDevice *vdev;
> +};
> +
> +struct QVhostUserGPIOPCI {
> +    QVirtioPCIDevice pci_vdev;
> +    QVhostUserGPIO gpio;
> +};
> +
> +struct QVhostUserGPIODevice {
> +    QOSGraphObject obj;
> +    QVhostUserGPIO gpio;
> +};
> +
> +#endif
> diff --git a/tests/qtest/libqos/virtio-gpio.c b/tests/qtest/libqos/virtio-gpio.c
> new file mode 100644
> index 0000000000..62c8074777
> --- /dev/null
> +++ b/tests/qtest/libqos/virtio-gpio.c
> @@ -0,0 +1,98 @@
> +/*
> + * virtio-gpio nodes for testing
> + *
> + * Copyright (c) 2022 Linaro Ltd
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "qemu/osdep.h"
> +#include "libqtest.h"
> +#include "qemu/module.h"
> +#include "qgraph.h"
> +#include "virtio-gpio.h"
> +
> +static void *qvirtio_gpio_get_driver(QVhostUserGPIO *v_gpio,
> +                                       const char *interface)
> +{
> +    if (!g_strcmp0(interface, "vhost-user-gpio")) {
> +        return v_gpio;
> +    }
> +    if (!g_strcmp0(interface, "virtio")) {
> +        return v_gpio->vdev;
> +    }
> +
> +    fprintf(stderr, "%s not present in virtio-gpio-device\n", interface);
> +    g_assert_not_reached();
> +}
> +
> +static void *qvirtio_gpio_device_get_driver(void *object,
> +                                              const char *interface)
> +{
> +    QVhostUserGPIODevice *v_gpio = object;
> +    return qvirtio_gpio_get_driver(&v_gpio->gpio, interface);
> +}
> +
> +static void *virtio_gpio_device_create(void *virtio_dev,
> +                                         QGuestAllocator *t_alloc,
> +                                         void *addr)
> +{
> +    QVhostUserGPIODevice *virtio_device = g_new0(QVhostUserGPIODevice, 1);
> +    QVhostUserGPIO *interface = &virtio_device->gpio;
> +
> +    interface->vdev = virtio_dev;
> +
> +    virtio_device->obj.get_driver = qvirtio_gpio_device_get_driver;
> +
> +    return &virtio_device->obj;
> +}
> +
> +/* virtio-gpio-pci */
> +static void *qvirtio_gpio_pci_get_driver(void *object, const char *interface)
> +{
> +    QVhostUserGPIOPCI *v_gpio = object;
> +    if (!g_strcmp0(interface, "pci-device")) {
> +        return v_gpio->pci_vdev.pdev;
> +    }
> +    return qvirtio_gpio_get_driver(&v_gpio->gpio, interface);
> +}
> +
> +static void *virtio_gpio_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
> +                                      void *addr)
> +{
> +    QVhostUserGPIOPCI *virtio_spci = g_new0(QVhostUserGPIOPCI, 1);
> +    QVhostUserGPIO *interface = &virtio_spci->gpio;
> +    QOSGraphObject *obj = &virtio_spci->pci_vdev.obj;
> +
> +    virtio_pci_init(&virtio_spci->pci_vdev, pci_bus, addr);
> +    interface->vdev = &virtio_spci->pci_vdev.vdev;
> +
> +    obj->get_driver = qvirtio_gpio_pci_get_driver;
> +
> +    return obj;
> +}
> +
> +static void virtio_gpio_register_nodes(void)
> +{
> +    QPCIAddress addr = {
> +        .devfn = QPCI_DEVFN(4, 0),
> +    };
> +
> +    QOSGraphEdgeOptions edge_opts = { };
> +
> +    /* vhost-user-gpio-device */
> +    edge_opts.extra_device_opts = "id=gpio0,chardev=vhgpio0";
> +    qos_node_create_driver("vhost-user-gpio-device",
> +                            virtio_gpio_device_create);
> +    qos_node_consumes("vhost-user-gpio-device", "virtio-bus", &edge_opts);
> +    qos_node_produces("vhost-user-gpio-device", "vhost-user-gpio");
> +
> +    /* virtio-gpio-pci */
> +    edge_opts.extra_device_opts = "id=gpio0,addr=04.0,chardev=vhgpio0";
> +    add_qpci_address(&edge_opts, &addr);
> +    qos_node_create_driver("vhost-user-gpio-pci", virtio_gpio_pci_create);
> +    qos_node_consumes("vhost-user-gpio-pci", "pci-bus", &edge_opts);
> +    qos_node_produces("vhost-user-gpio-pci", "vhost-user-gpio");
> +}
> +
> +libqos_init(virtio_gpio_register_nodes);
> diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
> index ee30f54796..4f8789424b 100644
> --- a/tests/qtest/vhost-user-test.c
> +++ b/tests/qtest/vhost-user-test.c
> @@ -43,6 +43,7 @@
>                          " -numa node,memdev=mem"
>  #define QEMU_CMD_CHR    " -chardev socket,id=%s,path=%s%s"
>  #define QEMU_CMD_NETDEV " -netdev vhost-user,id=hs0,chardev=%s,vhostforce=on"
> +#define QEMU_CMD_GPIO   " -device vhost-user-gpio-pci,id=gpio0,chardev=%s,vhostforce=on"
>  
>  #define HUGETLBFS_MAGIC       0x958458f6
>  
> @@ -137,6 +138,7 @@ enum {
>  
>  enum {
>      VHOST_USER_NET,
> +    VHOST_USER_GPIO,
>  };
>  
>  typedef struct TestServer {
> @@ -194,6 +196,14 @@ static void append_vhost_net_opts(TestServer *s, GString *cmd_line,
>                             chr_opts, s->chr_name);
>  }
>  
> +static void append_vhost_gpio_opts(TestServer *s, GString *cmd_line,
> +                             const char *chr_opts)
> +{
> +    g_string_append_printf(cmd_line, QEMU_CMD_CHR QEMU_CMD_GPIO,
> +                           s->chr_name, s->socket_path,
> +                           chr_opts, s->chr_name);
> +}
> +
>  static void append_mem_opts(TestServer *server, GString *cmd_line,
>                              int size, enum test_memfd memfd)
>  {
> @@ -1014,3 +1024,27 @@ static void register_vhost_user_test(void)
>                   test_multiqueue, &opts);
>  }
>  libqos_init(register_vhost_user_test);
> +
> +static struct vhost_user_ops g_vu_gpio_ops = {
> +    .type = VHOST_USER_GPIO,
> +
> +    .append_opts = append_vhost_gpio_opts,
> +
> +    .set_features = vu_net_set_features,
> +    .get_protocol_features = vu_net_get_protocol_features,
> +};
> +
> +static void register_vhost_gpio_test(void)
> +{
> +    QOSGraphTestOptions opts = {
> +        .before = vhost_user_test_setup,
> +        .subprocess = true,
> +        .arg = &g_vu_gpio_ops,
> +    };
> +
> +    qemu_add_opts(&qemu_chardev_opts);
> +
> +    qos_add_test("read-guest-mem/memfile",
> +                 "vhost-user-gpio", test_read_guest_mem, &opts);
> +}
> +libqos_init(register_vhost_gpio_test);
> diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build
> index 8c8ee15553..f581330d8b 100644
> --- a/tests/qtest/libqos/meson.build
> +++ b/tests/qtest/libqos/meson.build
> @@ -42,6 +42,7 @@ libqos_srcs = files('../libqtest.c',
>          'virtio-scsi.c',
>          'virtio-serial.c',
>          'virtio-iommu.c',
> +        'virtio-gpio.c',
>          'generic-pcihost.c',
>  
>          # qgraph machines:


-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/2] virtio: Add vhost-user-gpio device's support
  2022-02-04 14:06     ` Michael S. Tsirkin
@ 2022-03-31  9:58       ` Alex Bennée
  0 siblings, 0 replies; 24+ messages in thread
From: Alex Bennée @ 2022-03-31  9:58 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Halil Pasic, Eric Farman, Vincent Guittot, Michael S. Tsirkin,
	Viresh Kumar, Cornelia Huck, qemu-devel, Coiby Xu,
	Dr. David Alan Gilbert, Eric Auger, Gerd Hoffmann,
	Stefan Hajnoczi, Marc-André Lureau, Raphael Norwitz,
	stratos-dev


"Michael S. Tsirkin" <mst@redhat.com> writes:

> On Fri, Feb 04, 2022 at 01:52:47PM +0000, Alex Bennée wrote:
>> 
>> "Michael S. Tsirkin" <mst@redhat.com> writes:
>> 
>> > On Wed, Jan 12, 2022 at 05:04:57PM +0530, Viresh Kumar wrote:
>> >> Hello,
>> >> 
>> >> This patchset adds vhost-user-gpio device's support in Qemu. The support for the
>> >> same has already been added to virtio specification and Linux Kernel.
>> >> 
>> >> A Rust based backend is also in progress and is tested against this patchset:
>> >> 
>> >> https://github.com/rust-vmm/vhost-device/pull/76
>> >
>> > So I'm waiting for v2 of this, right?
>> 
>> If you can give any pointers for how to properly instantiate the stub in
>> qtest then we can spin v2 pretty quickly. I tried but it didn't work:
>> 
>>   Subject: [RFC PATCH] tests/qtest: attempt to enable tests for virtio-gpio (!working)
>>   Date: Fri, 21 Jan 2022 15:15:34 +0000
>>   Message-Id: <20220121151534.3654562-1-alex.bennee@linaro.org>
>>   X-Mailer: git-send-email 2.30.2
>>   In-Reply-To: <20220120040234.ehcjcdr6wrvlz3yc@vireshk-i7>
>>   References: <20220120040234.ehcjcdr6wrvlz3yc@vireshk-i7>
>> 
>> it's all a bit opaque as to why it didn't.
>
> A bit rushed short term, it this isn't resolved soon I'll try to help.
> Maybe try CC other vhost-user maintainers (for blk,gpu etc) meanwhile.

I have expanded the CC list for this thread and the RFC patch to see if
anyone has pointers. I'll pull this series into my vhost cleanups series
for post 7.0.

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC PATCH] tests/qtest: attempt to enable tests for virtio-gpio (!working)
  2022-03-31  9:52         ` Alex Bennée
@ 2022-03-31 16:17           ` Stefan Hajnoczi
  2022-04-04 17:59           ` Dr. David Alan Gilbert
  1 sibling, 0 replies; 24+ messages in thread
From: Stefan Hajnoczi @ 2022-03-31 16:17 UTC (permalink / raw)
  To: Alex Bennée
  Cc: Laurent Vivier, Thomas Huth, Michael S. Tsirkin, Eric Farman,
	Viresh Kumar, Cornelia Huck, qemu-devel, Coiby Xu,
	Dr. David Alan Gilbert, Halil Pasic, Eric Auger, Gerd Hoffmann,
	Marc-André Lureau, Paolo Bonzini, Raphael Norwitz

[-- Attachment #1: Type: text/plain, Size: 253 bytes --]

On Thu, Mar 31, 2022 at 10:52:56AM +0100, Alex Bennée wrote:
> 
> (expanding the CC list for help, anyone have a better idea about how
> vhost-user qtests should work/see obvious issues with this patch?)

This is better than no test :).

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC PATCH] tests/qtest: attempt to enable tests for virtio-gpio (!working)
  2022-03-31  9:52         ` Alex Bennée
  2022-03-31 16:17           ` Stefan Hajnoczi
@ 2022-04-04 17:59           ` Dr. David Alan Gilbert
  2022-04-05 13:46             ` Alex Bennée
  1 sibling, 1 reply; 24+ messages in thread
From: Dr. David Alan Gilbert @ 2022-04-04 17:59 UTC (permalink / raw)
  To: Alex Bennée
  Cc: Laurent Vivier, Halil Pasic, Thomas Huth, Michael S. Tsirkin,
	Eric Farman, Viresh Kumar, Cornelia Huck, qemu-devel, Coiby Xu,
	Raphael Norwitz, Eric Auger, Gerd Hoffmann, Stefan Hajnoczi,
	Marc-André Lureau, Paolo Bonzini

* Alex Bennée (alex.bennee@linaro.org) wrote:
> 
> (expanding the CC list for help, anyone have a better idea about how
> vhost-user qtests should work/see obvious issues with this patch?)

How exactly does it fail?

DAve

> Alex Bennée <alex.bennee@linaro.org> writes:
> 
> > We don't have a virtio-gpio implementation in QEMU and only
> > support a vhost-user backend. The QEMU side of the code is minimal so
> > it should be enough to instantiate the device and pass some vhost-user
> > messages over the control socket. To do this we hook into the existing
> > vhost-user-test code and just add the bits required for gpio.
> >
> > Based-on: 20220118203833.316741-1-eric.auger@redhat.com
> > Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> > Cc: Viresh Kumar <viresh.kumar@linaro.org>
> > Cc: Paolo Bonzini <pbonzini@redhat.com>
> >
> > ---
> >
> > This goes as far as to add things to the QOS tree but so far it's
> > failing to properly start QEMU with the chardev socket needed to
> > communicate between the mock vhost-user daemon and QEMU itself.
> > ---
> >  tests/qtest/libqos/virtio-gpio.h | 34 +++++++++++
> >  tests/qtest/libqos/virtio-gpio.c | 98 ++++++++++++++++++++++++++++++++
> >  tests/qtest/vhost-user-test.c    | 34 +++++++++++
> >  tests/qtest/libqos/meson.build   |  1 +
> >  4 files changed, 167 insertions(+)
> >  create mode 100644 tests/qtest/libqos/virtio-gpio.h
> >  create mode 100644 tests/qtest/libqos/virtio-gpio.c
> >
> > diff --git a/tests/qtest/libqos/virtio-gpio.h b/tests/qtest/libqos/virtio-gpio.h
> > new file mode 100644
> > index 0000000000..abe6967ae9
> > --- /dev/null
> > +++ b/tests/qtest/libqos/virtio-gpio.h
> > @@ -0,0 +1,34 @@
> > +/*
> > + * virtio-gpio structures
> > + *
> > + * Copyright (c) 2022 Linaro Ltd
> > + *
> > + * SPDX-License-Identifier: GPL-2.0-or-later
> > + */
> > +
> > +#ifndef TESTS_LIBQOS_VIRTIO_GPIO_H
> > +#define TESTS_LIBQOS_VIRTIO_GPIO_H
> > +
> > +#include "qgraph.h"
> > +#include "virtio.h"
> > +#include "virtio-pci.h"
> > +
> > +typedef struct QVhostUserGPIO QVhostUserGPIO;
> > +typedef struct QVhostUserGPIOPCI QVhostUserGPIOPCI;
> > +typedef struct QVhostUserGPIODevice QVhostUserGPIODevice;
> > +
> > +struct QVhostUserGPIO {
> > +    QVirtioDevice *vdev;
> > +};
> > +
> > +struct QVhostUserGPIOPCI {
> > +    QVirtioPCIDevice pci_vdev;
> > +    QVhostUserGPIO gpio;
> > +};
> > +
> > +struct QVhostUserGPIODevice {
> > +    QOSGraphObject obj;
> > +    QVhostUserGPIO gpio;
> > +};
> > +
> > +#endif
> > diff --git a/tests/qtest/libqos/virtio-gpio.c b/tests/qtest/libqos/virtio-gpio.c
> > new file mode 100644
> > index 0000000000..62c8074777
> > --- /dev/null
> > +++ b/tests/qtest/libqos/virtio-gpio.c
> > @@ -0,0 +1,98 @@
> > +/*
> > + * virtio-gpio nodes for testing
> > + *
> > + * Copyright (c) 2022 Linaro Ltd
> > + *
> > + * SPDX-License-Identifier: GPL-2.0-or-later
> > + */
> > +
> > +#include "qemu/osdep.h"
> > +#include "libqtest.h"
> > +#include "qemu/module.h"
> > +#include "qgraph.h"
> > +#include "virtio-gpio.h"
> > +
> > +static void *qvirtio_gpio_get_driver(QVhostUserGPIO *v_gpio,
> > +                                       const char *interface)
> > +{
> > +    if (!g_strcmp0(interface, "vhost-user-gpio")) {
> > +        return v_gpio;
> > +    }
> > +    if (!g_strcmp0(interface, "virtio")) {
> > +        return v_gpio->vdev;
> > +    }
> > +
> > +    fprintf(stderr, "%s not present in virtio-gpio-device\n", interface);
> > +    g_assert_not_reached();
> > +}
> > +
> > +static void *qvirtio_gpio_device_get_driver(void *object,
> > +                                              const char *interface)
> > +{
> > +    QVhostUserGPIODevice *v_gpio = object;
> > +    return qvirtio_gpio_get_driver(&v_gpio->gpio, interface);
> > +}
> > +
> > +static void *virtio_gpio_device_create(void *virtio_dev,
> > +                                         QGuestAllocator *t_alloc,
> > +                                         void *addr)
> > +{
> > +    QVhostUserGPIODevice *virtio_device = g_new0(QVhostUserGPIODevice, 1);
> > +    QVhostUserGPIO *interface = &virtio_device->gpio;
> > +
> > +    interface->vdev = virtio_dev;
> > +
> > +    virtio_device->obj.get_driver = qvirtio_gpio_device_get_driver;
> > +
> > +    return &virtio_device->obj;
> > +}
> > +
> > +/* virtio-gpio-pci */
> > +static void *qvirtio_gpio_pci_get_driver(void *object, const char *interface)
> > +{
> > +    QVhostUserGPIOPCI *v_gpio = object;
> > +    if (!g_strcmp0(interface, "pci-device")) {
> > +        return v_gpio->pci_vdev.pdev;
> > +    }
> > +    return qvirtio_gpio_get_driver(&v_gpio->gpio, interface);
> > +}
> > +
> > +static void *virtio_gpio_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
> > +                                      void *addr)
> > +{
> > +    QVhostUserGPIOPCI *virtio_spci = g_new0(QVhostUserGPIOPCI, 1);
> > +    QVhostUserGPIO *interface = &virtio_spci->gpio;
> > +    QOSGraphObject *obj = &virtio_spci->pci_vdev.obj;
> > +
> > +    virtio_pci_init(&virtio_spci->pci_vdev, pci_bus, addr);
> > +    interface->vdev = &virtio_spci->pci_vdev.vdev;
> > +
> > +    obj->get_driver = qvirtio_gpio_pci_get_driver;
> > +
> > +    return obj;
> > +}
> > +
> > +static void virtio_gpio_register_nodes(void)
> > +{
> > +    QPCIAddress addr = {
> > +        .devfn = QPCI_DEVFN(4, 0),
> > +    };
> > +
> > +    QOSGraphEdgeOptions edge_opts = { };
> > +
> > +    /* vhost-user-gpio-device */
> > +    edge_opts.extra_device_opts = "id=gpio0,chardev=vhgpio0";
> > +    qos_node_create_driver("vhost-user-gpio-device",
> > +                            virtio_gpio_device_create);
> > +    qos_node_consumes("vhost-user-gpio-device", "virtio-bus", &edge_opts);
> > +    qos_node_produces("vhost-user-gpio-device", "vhost-user-gpio");
> > +
> > +    /* virtio-gpio-pci */
> > +    edge_opts.extra_device_opts = "id=gpio0,addr=04.0,chardev=vhgpio0";
> > +    add_qpci_address(&edge_opts, &addr);
> > +    qos_node_create_driver("vhost-user-gpio-pci", virtio_gpio_pci_create);
> > +    qos_node_consumes("vhost-user-gpio-pci", "pci-bus", &edge_opts);
> > +    qos_node_produces("vhost-user-gpio-pci", "vhost-user-gpio");
> > +}
> > +
> > +libqos_init(virtio_gpio_register_nodes);
> > diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
> > index ee30f54796..4f8789424b 100644
> > --- a/tests/qtest/vhost-user-test.c
> > +++ b/tests/qtest/vhost-user-test.c
> > @@ -43,6 +43,7 @@
> >                          " -numa node,memdev=mem"
> >  #define QEMU_CMD_CHR    " -chardev socket,id=%s,path=%s%s"
> >  #define QEMU_CMD_NETDEV " -netdev vhost-user,id=hs0,chardev=%s,vhostforce=on"
> > +#define QEMU_CMD_GPIO   " -device vhost-user-gpio-pci,id=gpio0,chardev=%s,vhostforce=on"
> >  
> >  #define HUGETLBFS_MAGIC       0x958458f6
> >  
> > @@ -137,6 +138,7 @@ enum {
> >  
> >  enum {
> >      VHOST_USER_NET,
> > +    VHOST_USER_GPIO,
> >  };
> >  
> >  typedef struct TestServer {
> > @@ -194,6 +196,14 @@ static void append_vhost_net_opts(TestServer *s, GString *cmd_line,
> >                             chr_opts, s->chr_name);
> >  }
> >  
> > +static void append_vhost_gpio_opts(TestServer *s, GString *cmd_line,
> > +                             const char *chr_opts)
> > +{
> > +    g_string_append_printf(cmd_line, QEMU_CMD_CHR QEMU_CMD_GPIO,
> > +                           s->chr_name, s->socket_path,
> > +                           chr_opts, s->chr_name);
> > +}
> > +
> >  static void append_mem_opts(TestServer *server, GString *cmd_line,
> >                              int size, enum test_memfd memfd)
> >  {
> > @@ -1014,3 +1024,27 @@ static void register_vhost_user_test(void)
> >                   test_multiqueue, &opts);
> >  }
> >  libqos_init(register_vhost_user_test);
> > +
> > +static struct vhost_user_ops g_vu_gpio_ops = {
> > +    .type = VHOST_USER_GPIO,
> > +
> > +    .append_opts = append_vhost_gpio_opts,
> > +
> > +    .set_features = vu_net_set_features,
> > +    .get_protocol_features = vu_net_get_protocol_features,
> > +};
> > +
> > +static void register_vhost_gpio_test(void)
> > +{
> > +    QOSGraphTestOptions opts = {
> > +        .before = vhost_user_test_setup,
> > +        .subprocess = true,
> > +        .arg = &g_vu_gpio_ops,
> > +    };
> > +
> > +    qemu_add_opts(&qemu_chardev_opts);
> > +
> > +    qos_add_test("read-guest-mem/memfile",
> > +                 "vhost-user-gpio", test_read_guest_mem, &opts);
> > +}
> > +libqos_init(register_vhost_gpio_test);
> > diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build
> > index 8c8ee15553..f581330d8b 100644
> > --- a/tests/qtest/libqos/meson.build
> > +++ b/tests/qtest/libqos/meson.build
> > @@ -42,6 +42,7 @@ libqos_srcs = files('../libqtest.c',
> >          'virtio-scsi.c',
> >          'virtio-serial.c',
> >          'virtio-iommu.c',
> > +        'virtio-gpio.c',
> >          'generic-pcihost.c',
> >  
> >          # qgraph machines:
> 
> 
> -- 
> Alex Bennée
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/2] virtio: Add vhost-user-gpio device's support
  2022-01-12 11:34 [PATCH 0/2] virtio: Add vhost-user-gpio device's support Viresh Kumar
                   ` (3 preceding siblings ...)
  2022-02-04 12:23 ` Michael S. Tsirkin
@ 2022-04-05 10:55 ` Alex Bennée
  4 siblings, 0 replies; 24+ messages in thread
From: Alex Bennée @ 2022-04-05 10:55 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: stratos-dev, Vincent Guittot, qemu-devel, Michael S. Tsirkin


Viresh Kumar <viresh.kumar@linaro.org> writes:

> Hello,
>
> This patchset adds vhost-user-gpio device's support in Qemu. The support for the
> same has already been added to virtio specification and Linux Kernel.
>
> A Rust based backend is also in progress and is tested against this patchset:
>
> https://github.com/rust-vmm/vhost-device/pull/76

Queued to virtio/virtio-cleanups-and-gpio-v2, thanks.

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC PATCH] tests/qtest: attempt to enable tests for virtio-gpio (!working)
  2022-04-04 17:59           ` Dr. David Alan Gilbert
@ 2022-04-05 13:46             ` Alex Bennée
  0 siblings, 0 replies; 24+ messages in thread
From: Alex Bennée @ 2022-04-05 13:46 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: Laurent Vivier, Halil Pasic, Thomas Huth, Michael S. Tsirkin,
	Eric Farman, Viresh Kumar, Cornelia Huck, qemu-devel, Coiby Xu,
	Raphael Norwitz, Eric Auger, Gerd Hoffmann, Stefan Hajnoczi,
	Marc-André Lureau, Paolo Bonzini


"Dr. David Alan Gilbert" <dgilbert@redhat.com> writes:

> * Alex Bennée (alex.bennee@linaro.org) wrote:
>> 
>> (expanding the CC list for help, anyone have a better idea about how
>> vhost-user qtests should work/see obvious issues with this patch?)
>
> How exactly does it fail?

➜  env QTEST_QEMU_BINARY=./qemu-system-aarch64 QTEST_QEMU_STORAGE_DAEMON_BINARY=./storage-daemon/qemu-storage-daemon G_TEST_DBUS_DAEMON=/home/alex/lsrc/qemu.git/tests/dbus-v
mstate-daemon.sh QTEST_QEMU_IMG=./qemu-img MALLOC_PERTURB_=137 ./tests/qtest/qos-test -p /aarch64/virt/generic-pcihost/pci-bus-generic/pci-bus/vhost-user-gpio-pci/vhost-user-gpio/vhost-user-gpio-tests/read-guest-mem/memfile
# random seed: R02S5d7667675b4f6dd3b8559f8db621296c
# starting QEMU: exec ./qemu-system-aarch64 -qtest unix:/tmp/qtest-1245871.sock -qtest-log /dev/null -chardev socket,path=/tmp/qtest-1245871.qmp,id=char0 -mon chardev=char0,mode=control -display none -machine none -accel qtest
# Start of aarch64 tests
# Start of virt tests
# Start of generic-pcihost tests
# Start of pci-bus-generic tests
# Start of pci-bus tests
# Start of vhost-user-gpio-pci tests
# Start of vhost-user-gpio tests
# Start of vhost-user-gpio-tests tests
# Start of read-guest-mem tests
# child process (/aarch64/virt/generic-pcihost/pci-bus-generic/pci-bus/vhost-user-gpio-pci/vhost-user-gpio/vhost-user-gpio-tests/read-guest-mem/memfile/subprocess [1245877])
 exit status: 1 (error)
# child process (/aarch64/virt/generic-pcihost/pci-bus-generic/pci-bus/vhost-user-gpio-pci/vhost-user-gpio/vhost-user-gpio-tests/read-guest-mem/memfile/subprocess [1245877]) stdout: ""
# child process (/aarch64/virt/generic-pcihost/pci-bus-generic/pci-bus/vhost-user-gpio-pci/vhost-user-gpio/vhost-user-gpio-tests/read-guest-mem/memfile/subprocess [1245877]) stderr: "qemu-system-aarch64: -device vhost-user-gpio-pci,id=gpio0,chardev=chr-vhost-user-test,vhostforce=on: Duplicate ID 'gpio0' for device\nsocket_accept failed: Resource temporarily unavailable\n**\nERROR:../../tests/qtest/libqtest.c:321:qtest_init_without_qmp_handshake: assertion failed: (s->fd >= 0 && s->qmp_fd >= 0)\n"
**
ERROR:../../tests/qtest/qos-test.c:189:subprocess_run_one_test: child process (/aarch64/virt/generic-pcihost/pci-bus-generic/pci-bus/vhost-user-gpio-pci/vhost-user-gpio/vhost-user-gpio-tests/read-guest-mem/memfile/subprocess [1245877]) failed unexpectedly
Bail out! ERROR:../../tests/qtest/qos-test.c:189:subprocess_run_one_test: child process (/aarch64/virt/generic-pcihost/pci-bus-generic/pci-bus/vhost-user-gpio-pci/vhost-user-gpio/vhost-user-gpio-tests/read-guest-mem/memfile/subprocess [1245877]) failed unexpectedly
fish: “env QTEST_QEMU_BINARY=./qemu-sy…” terminated by signal SIGABRT
(Abort)

Although it would be nice if I could individually run qos-tests with all
the make machinery setting things up.


>
> DAve
>
>> Alex Bennée <alex.bennee@linaro.org> writes:
>> 
>> > We don't have a virtio-gpio implementation in QEMU and only
>> > support a vhost-user backend. The QEMU side of the code is minimal so
>> > it should be enough to instantiate the device and pass some vhost-user
>> > messages over the control socket. To do this we hook into the existing
>> > vhost-user-test code and just add the bits required for gpio.
>> >
>> > Based-on: 20220118203833.316741-1-eric.auger@redhat.com
>> > Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> > Cc: Viresh Kumar <viresh.kumar@linaro.org>
>> > Cc: Paolo Bonzini <pbonzini@redhat.com>
>> >
>> > ---
>> >
>> > This goes as far as to add things to the QOS tree but so far it's
>> > failing to properly start QEMU with the chardev socket needed to
>> > communicate between the mock vhost-user daemon and QEMU itself.
>> > ---
>> >  tests/qtest/libqos/virtio-gpio.h | 34 +++++++++++
>> >  tests/qtest/libqos/virtio-gpio.c | 98 ++++++++++++++++++++++++++++++++
>> >  tests/qtest/vhost-user-test.c    | 34 +++++++++++
>> >  tests/qtest/libqos/meson.build   |  1 +
>> >  4 files changed, 167 insertions(+)
>> >  create mode 100644 tests/qtest/libqos/virtio-gpio.h
>> >  create mode 100644 tests/qtest/libqos/virtio-gpio.c
>> >
>> > diff --git a/tests/qtest/libqos/virtio-gpio.h b/tests/qtest/libqos/virtio-gpio.h
>> > new file mode 100644
>> > index 0000000000..abe6967ae9
>> > --- /dev/null
>> > +++ b/tests/qtest/libqos/virtio-gpio.h
>> > @@ -0,0 +1,34 @@
>> > +/*
>> > + * virtio-gpio structures
>> > + *
>> > + * Copyright (c) 2022 Linaro Ltd
>> > + *
>> > + * SPDX-License-Identifier: GPL-2.0-or-later
>> > + */
>> > +
>> > +#ifndef TESTS_LIBQOS_VIRTIO_GPIO_H
>> > +#define TESTS_LIBQOS_VIRTIO_GPIO_H
>> > +
>> > +#include "qgraph.h"
>> > +#include "virtio.h"
>> > +#include "virtio-pci.h"
>> > +
>> > +typedef struct QVhostUserGPIO QVhostUserGPIO;
>> > +typedef struct QVhostUserGPIOPCI QVhostUserGPIOPCI;
>> > +typedef struct QVhostUserGPIODevice QVhostUserGPIODevice;
>> > +
>> > +struct QVhostUserGPIO {
>> > +    QVirtioDevice *vdev;
>> > +};
>> > +
>> > +struct QVhostUserGPIOPCI {
>> > +    QVirtioPCIDevice pci_vdev;
>> > +    QVhostUserGPIO gpio;
>> > +};
>> > +
>> > +struct QVhostUserGPIODevice {
>> > +    QOSGraphObject obj;
>> > +    QVhostUserGPIO gpio;
>> > +};
>> > +
>> > +#endif
>> > diff --git a/tests/qtest/libqos/virtio-gpio.c b/tests/qtest/libqos/virtio-gpio.c
>> > new file mode 100644
>> > index 0000000000..62c8074777
>> > --- /dev/null
>> > +++ b/tests/qtest/libqos/virtio-gpio.c
>> > @@ -0,0 +1,98 @@
>> > +/*
>> > + * virtio-gpio nodes for testing
>> > + *
>> > + * Copyright (c) 2022 Linaro Ltd
>> > + *
>> > + * SPDX-License-Identifier: GPL-2.0-or-later
>> > + */
>> > +
>> > +#include "qemu/osdep.h"
>> > +#include "libqtest.h"
>> > +#include "qemu/module.h"
>> > +#include "qgraph.h"
>> > +#include "virtio-gpio.h"
>> > +
>> > +static void *qvirtio_gpio_get_driver(QVhostUserGPIO *v_gpio,
>> > +                                       const char *interface)
>> > +{
>> > +    if (!g_strcmp0(interface, "vhost-user-gpio")) {
>> > +        return v_gpio;
>> > +    }
>> > +    if (!g_strcmp0(interface, "virtio")) {
>> > +        return v_gpio->vdev;
>> > +    }
>> > +
>> > +    fprintf(stderr, "%s not present in virtio-gpio-device\n", interface);
>> > +    g_assert_not_reached();
>> > +}
>> > +
>> > +static void *qvirtio_gpio_device_get_driver(void *object,
>> > +                                              const char *interface)
>> > +{
>> > +    QVhostUserGPIODevice *v_gpio = object;
>> > +    return qvirtio_gpio_get_driver(&v_gpio->gpio, interface);
>> > +}
>> > +
>> > +static void *virtio_gpio_device_create(void *virtio_dev,
>> > +                                         QGuestAllocator *t_alloc,
>> > +                                         void *addr)
>> > +{
>> > +    QVhostUserGPIODevice *virtio_device = g_new0(QVhostUserGPIODevice, 1);
>> > +    QVhostUserGPIO *interface = &virtio_device->gpio;
>> > +
>> > +    interface->vdev = virtio_dev;
>> > +
>> > +    virtio_device->obj.get_driver = qvirtio_gpio_device_get_driver;
>> > +
>> > +    return &virtio_device->obj;
>> > +}
>> > +
>> > +/* virtio-gpio-pci */
>> > +static void *qvirtio_gpio_pci_get_driver(void *object, const char *interface)
>> > +{
>> > +    QVhostUserGPIOPCI *v_gpio = object;
>> > +    if (!g_strcmp0(interface, "pci-device")) {
>> > +        return v_gpio->pci_vdev.pdev;
>> > +    }
>> > +    return qvirtio_gpio_get_driver(&v_gpio->gpio, interface);
>> > +}
>> > +
>> > +static void *virtio_gpio_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
>> > +                                      void *addr)
>> > +{
>> > +    QVhostUserGPIOPCI *virtio_spci = g_new0(QVhostUserGPIOPCI, 1);
>> > +    QVhostUserGPIO *interface = &virtio_spci->gpio;
>> > +    QOSGraphObject *obj = &virtio_spci->pci_vdev.obj;
>> > +
>> > +    virtio_pci_init(&virtio_spci->pci_vdev, pci_bus, addr);
>> > +    interface->vdev = &virtio_spci->pci_vdev.vdev;
>> > +
>> > +    obj->get_driver = qvirtio_gpio_pci_get_driver;
>> > +
>> > +    return obj;
>> > +}
>> > +
>> > +static void virtio_gpio_register_nodes(void)
>> > +{
>> > +    QPCIAddress addr = {
>> > +        .devfn = QPCI_DEVFN(4, 0),
>> > +    };
>> > +
>> > +    QOSGraphEdgeOptions edge_opts = { };
>> > +
>> > +    /* vhost-user-gpio-device */
>> > +    edge_opts.extra_device_opts = "id=gpio0,chardev=vhgpio0";
>> > +    qos_node_create_driver("vhost-user-gpio-device",
>> > +                            virtio_gpio_device_create);
>> > +    qos_node_consumes("vhost-user-gpio-device", "virtio-bus", &edge_opts);
>> > +    qos_node_produces("vhost-user-gpio-device", "vhost-user-gpio");
>> > +
>> > +    /* virtio-gpio-pci */
>> > +    edge_opts.extra_device_opts = "id=gpio0,addr=04.0,chardev=vhgpio0";
>> > +    add_qpci_address(&edge_opts, &addr);
>> > +    qos_node_create_driver("vhost-user-gpio-pci", virtio_gpio_pci_create);
>> > +    qos_node_consumes("vhost-user-gpio-pci", "pci-bus", &edge_opts);
>> > +    qos_node_produces("vhost-user-gpio-pci", "vhost-user-gpio");
>> > +}
>> > +
>> > +libqos_init(virtio_gpio_register_nodes);
>> > diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
>> > index ee30f54796..4f8789424b 100644
>> > --- a/tests/qtest/vhost-user-test.c
>> > +++ b/tests/qtest/vhost-user-test.c
>> > @@ -43,6 +43,7 @@
>> >                          " -numa node,memdev=mem"
>> >  #define QEMU_CMD_CHR    " -chardev socket,id=%s,path=%s%s"
>> >  #define QEMU_CMD_NETDEV " -netdev vhost-user,id=hs0,chardev=%s,vhostforce=on"
>> > +#define QEMU_CMD_GPIO   " -device vhost-user-gpio-pci,id=gpio0,chardev=%s,vhostforce=on"
>> >  
>> >  #define HUGETLBFS_MAGIC       0x958458f6
>> >  
>> > @@ -137,6 +138,7 @@ enum {
>> >  
>> >  enum {
>> >      VHOST_USER_NET,
>> > +    VHOST_USER_GPIO,
>> >  };
>> >  
>> >  typedef struct TestServer {
>> > @@ -194,6 +196,14 @@ static void append_vhost_net_opts(TestServer *s, GString *cmd_line,
>> >                             chr_opts, s->chr_name);
>> >  }
>> >  
>> > +static void append_vhost_gpio_opts(TestServer *s, GString *cmd_line,
>> > +                             const char *chr_opts)
>> > +{
>> > +    g_string_append_printf(cmd_line, QEMU_CMD_CHR QEMU_CMD_GPIO,
>> > +                           s->chr_name, s->socket_path,
>> > +                           chr_opts, s->chr_name);
>> > +}
>> > +
>> >  static void append_mem_opts(TestServer *server, GString *cmd_line,
>> >                              int size, enum test_memfd memfd)
>> >  {
>> > @@ -1014,3 +1024,27 @@ static void register_vhost_user_test(void)
>> >                   test_multiqueue, &opts);
>> >  }
>> >  libqos_init(register_vhost_user_test);
>> > +
>> > +static struct vhost_user_ops g_vu_gpio_ops = {
>> > +    .type = VHOST_USER_GPIO,
>> > +
>> > +    .append_opts = append_vhost_gpio_opts,
>> > +
>> > +    .set_features = vu_net_set_features,
>> > +    .get_protocol_features = vu_net_get_protocol_features,
>> > +};
>> > +
>> > +static void register_vhost_gpio_test(void)
>> > +{
>> > +    QOSGraphTestOptions opts = {
>> > +        .before = vhost_user_test_setup,
>> > +        .subprocess = true,
>> > +        .arg = &g_vu_gpio_ops,
>> > +    };
>> > +
>> > +    qemu_add_opts(&qemu_chardev_opts);
>> > +
>> > +    qos_add_test("read-guest-mem/memfile",
>> > +                 "vhost-user-gpio", test_read_guest_mem, &opts);
>> > +}
>> > +libqos_init(register_vhost_gpio_test);
>> > diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build
>> > index 8c8ee15553..f581330d8b 100644
>> > --- a/tests/qtest/libqos/meson.build
>> > +++ b/tests/qtest/libqos/meson.build
>> > @@ -42,6 +42,7 @@ libqos_srcs = files('../libqtest.c',
>> >          'virtio-scsi.c',
>> >          'virtio-serial.c',
>> >          'virtio-iommu.c',
>> > +        'virtio-gpio.c',
>> >          'generic-pcihost.c',
>> >  
>> >          # qgraph machines:
>> 
>> 
>> -- 
>> Alex Bennée
>> 


-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2022-04-05 13:54 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12 11:34 [PATCH 0/2] virtio: Add vhost-user-gpio device's support Viresh Kumar
2022-01-12 11:34 ` [PATCH 1/2] hw/virtio: add boilerplate for vhost-user-gpio device Viresh Kumar
2022-01-14 14:05   ` Alex Bennée
2022-01-14 14:06   ` Alex Bennée
2022-01-17  6:38     ` Viresh Kumar
2022-01-17 10:17       ` Alex Bennée
2022-01-12 11:34 ` [PATCH 2/2] hw/virtio: add vhost-user-gpio-pci boilerplate Viresh Kumar
2022-01-14 14:10   ` Alex Bennée
2022-01-17  8:47 ` [PATCH 0/2] virtio: Add vhost-user-gpio device's support Michael S. Tsirkin
2022-01-17 10:11   ` Alex Bennée
2022-01-20  4:02     ` Viresh Kumar
2022-01-20 10:57       ` Michael S. Tsirkin
2022-01-20 15:41         ` Alex Bennée
2022-01-21 15:15       ` [RFC PATCH] tests/qtest: attempt to enable tests for virtio-gpio (!working) Alex Bennée
2022-03-31  9:52         ` Alex Bennée
2022-03-31 16:17           ` Stefan Hajnoczi
2022-04-04 17:59           ` Dr. David Alan Gilbert
2022-04-05 13:46             ` Alex Bennée
2022-01-20 11:25     ` [PATCH 0/2] virtio: Add vhost-user-gpio device's support Michael S. Tsirkin
2022-02-04 12:23 ` Michael S. Tsirkin
2022-02-04 13:52   ` Alex Bennée
2022-02-04 14:06     ` Michael S. Tsirkin
2022-03-31  9:58       ` Alex Bennée
2022-04-05 10:55 ` Alex Bennée

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).