Skip to contentSkip to conversation

virtio: Refactor vhost input stub

PATCH Applied Leo Yan 4 participants 12 messages Nov 20, 2023 – Jan 4, 2024 Arm/Amlogic Meson SoC support

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

v3 cover virtio: Refactor vhost input stub

This series is to refactor vhost stub vhost-user-input.

Since vhost input stub requires set_config() callback for communication event configurations between the backend and the guest, patch 01 is a preparison for support set_config() callback in vhost-user-base.

The patch 02 is to add documentation for vhost-user-input.

The patch 03 is to move virtio input stub from the input folder to the virtio folder.

The patch 04 derives vhost-user-input from vhost-user-base. We reuse the common code from vhhost-user-base as possible and the input stub is simplized significantly.

This patch set has been tested with the backend daemon:

  # ./build/contrib/vhost-user-input/vhost-user-input \
		     -p /dev/input/event20 -s /tmp/input.sock

The series is based on "[PATCH v8 0/7] virtio: cleanup vhost-user-generic and reduce c&p" which introduces vhost-user-base.
Based-on: <[email protected]>

Changes from v2:
- Created reference for shared memory object and updated vhost-user-input.rst respectively. (Marc-André)

Changes from v1:
- Fixed typo in vhost-user-input.rst.
- Updated MAINTAINERS for new added input document and changing folder for vhost-user-input.c. (Manos)

Leo Yan (4):
hw/virtio: Support set_config() callback in vhost-user-base docs/system: Add vhost-user-input documentation hw/virtio: Move vhost-user-input into virtio folder hw/virtio: derive vhost-user-input from vhost-user-base

 MAINTAINERS                              |   3 +-
 docs/system/device-emulation.rst         |   1 +
 docs/system/devices/vhost-user-input.rst |  45 ++++++++
 docs/system/devices/vhost-user.rst       |   4 +-
 hw/input/meson.build                     |   1 -
 hw/input/vhost-user-input.c              | 136 -----------------------
 hw/virtio/meson.build                    |   4 +-
 hw/virtio/vhost-user-base.c              |  17 +++
 hw/virtio/vhost-user-input-pci.c         |   3 -
 hw/virtio/vhost-user-input.c             |  58 ++++++++++
 include/hw/virtio/virtio-input.h         |   6 +-
 11 files changed, 132 insertions(+), 146 deletions(-)
 create mode 100644 docs/system/devices/vhost-user-input.rst
 delete mode 100644 hw/input/vhost-user-input.c
 create mode 100644 hw/virtio/vhost-user-input.c
Signature · 1 line
2.39.2
author
#1 lore raw

PATCH v3 1/4 hw/virtio: Support set_config() callback in vhost-user-base

The Virtio input device invokes set_config() callback for retrieving the event configuration info, but the callback is not supported in vhost-user-base.

This patch adds support set_config() callback in vhost-user-base.

---
 hw/virtio/vhost-user-base.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
hw/virtio/vhost-user-base.c +17 -0
index 78cfa9a5bb..a83167191e 100644
@@ -140,6 +140,22 @@ static void vub_get_config(VirtIODevice *vdev, uint8_t *config)
     }
 }
 
+static void vub_set_config(VirtIODevice *vdev, const uint8_t *config_data)
+{
+    VHostUserBase *vub = VHOST_USER_BASE(vdev);
+    int ret;
+
+    g_assert(vub->config_size && vub->vhost_user.supports_config == true);
+
+    ret = vhost_dev_set_config(&vub->vhost_dev, config_data,
+                               0, vub->config_size,
+                               VHOST_SET_CONFIG_TYPE_FRONTEND);
+    if (ret) {
+        error_report("vhost guest set device config space failed: %d", ret);
+        return;
+    }
+}
+
 /*
  * When the daemon signals an update to the config we just need to
  * signal the guest as we re-read the config on demand above.
@@ -337,6 +353,7 @@ static void vub_class_init(ObjectClass *klass, void *data)
     vdc->unrealize = vub_device_unrealize;
     vdc->get_features = vub_get_features;
     vdc->get_config = vub_get_config;
+    vdc->set_config = vub_set_config;
     vdc->set_status = vub_set_status;
 }
 
Signature · 1 line
2.39.2
author
#2 lore raw

PATCH v3 2/4 docs/system: Add vhost-user-input documentation

In reply to Leo Yan

This adds basic documentation for vhost-user-input.

---
 MAINTAINERS                              |  1 +
 docs/system/device-emulation.rst         |  1 +
 docs/system/devices/vhost-user-input.rst | 45 ++++++++++++++++++++++++
 docs/system/devices/vhost-user.rst       |  4 ++-
 4 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 docs/system/devices/vhost-user-input.rst
MAINTAINERS +1 -0
index 0624d67932..8a26fe9493 100644
@@ -2262,6 +2262,7 @@ L: [email protected]
 virtio-input
 M: Gerd Hoffmann <[email protected]>
 S: Odd Fixes
+F: docs/system/devices/vhost-user-input.rst
 F: hw/input/vhost-user-input.c
 F: hw/input/virtio-input*.c
 F: include/hw/virtio/virtio-input.h
docs/system/device-emulation.rst +1 -0
index d1f3277cb0..f19777411c 100644
@@ -94,6 +94,7 @@ Emulated Devices
    devices/virtio-gpu.rst
    devices/virtio-pmem.rst
    devices/virtio-snd.rst
+   devices/vhost-user-input.rst
    devices/vhost-user-rng.rst
    devices/canokey.rst
    devices/usb-u2f.rst
docs/system/devices/vhost-user-input.rst new file +45 -0

45 lines not on this page · raw message

docs/system/devices/vhost-user.rst +3 -1
index c6afc4836f..9b2da106ce 100644
@@ -42,7 +42,7 @@ platform details for what sort of virtio bus to use.
     - See https://github.com/rust-vmm/vhost-device
   * - vhost-user-input
     - Generic input driver
-    - See contrib/vhost-user-input
+    - :ref:`vhost_user_input`
   * - vhost-user-rng
     - Entropy driver
     - :ref:`vhost_user_rng`
@@ -91,6 +91,8 @@ following the :ref:`vhost_user_proto`. There are a number of daemons
 that can be built when enabled by the project although any daemon that
 meets the specification for a given device can be used.
 
+.. _shared_memory_object:
+
 Shared memory object
 ====================
 
Signature · 1 line
2.39.2
author
#3 lore raw

PATCH v3 3/4 hw/virtio: Move vhost-user-input into virtio folder

In reply to Leo Yan

vhost-user-input is in the input folder. On the other hand, the folder 'hw/virtio' maintains other virtio stubs (e.g. I2C, RNG, GPIO, etc).

This patch moves vhost-user-input into the virtio folder for better code organization. No functionality change.

---
 MAINTAINERS                             | 2 +-
 hw/input/meson.build                    | 1 -
 hw/virtio/meson.build                   | 4 +++-
 hw/{input => virtio}/vhost-user-input.c | 0
 4 files changed, 4 insertions(+), 3 deletions(-)
 rename hw/{input => virtio}/vhost-user-input.c (100%)
MAINTAINERS +1 -1
index 8a26fe9493..fdc3edc6cb 100644
@@ -2263,8 +2263,8 @@ virtio-input
 M: Gerd Hoffmann <[email protected]>
 S: Odd Fixes
 F: docs/system/devices/vhost-user-input.rst
-F: hw/input/vhost-user-input.c
 F: hw/input/virtio-input*.c
+F: hw/virtio/vhost-user-input.c
 F: include/hw/virtio/virtio-input.h
 F: contrib/vhost-user-input/*
 
hw/input/meson.build +0 -1
index 640556bbbc..3cc8ab85f0 100644
@@ -11,7 +11,6 @@ system_ss.add(when: 'CONFIG_TSC2005', if_true: files('tsc2005.c'))
 system_ss.add(when: 'CONFIG_VIRTIO_INPUT', if_true: files('virtio-input.c'))
 system_ss.add(when: 'CONFIG_VIRTIO_INPUT', if_true: files('virtio-input-hid.c'))
 system_ss.add(when: 'CONFIG_VIRTIO_INPUT_HOST', if_true: files('virtio-input-host.c'))
-system_ss.add(when: 'CONFIG_VHOST_USER_INPUT', if_true: files('vhost-user-input.c'))
 
 system_ss.add(when: 'CONFIG_PXA2XX', if_true: files('pxa2xx_keypad.c'))
 system_ss.add(when: 'CONFIG_TSC210X', if_true: files('tsc210x.c'))
hw/virtio/meson.build +3 -1
index 118d4d4da7..c924afcafc 100644
@@ -25,6 +25,7 @@ if have_vhost
     system_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c'))
     system_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c'))
     system_virtio_ss.add(when: 'CONFIG_VHOST_USER_SND', if_true: files('vhost-user-snd.c'))
+    system_virtio_ss.add(when: 'CONFIG_VHOST_USER_INPUT', if_true: files('vhost-user-input.c'))
 
     # PCI Stubs
     system_virtio_ss.add(when: 'CONFIG_VIRTIO_PCI', if_true: files('vhost-user-device-pci.c'))
@@ -36,6 +37,8 @@ if have_vhost
                          if_true: files('vhost-user-rng-pci.c'))
     system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_SND'],
                          if_true: files('vhost-user-snd-pci.c'))
+    system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_INPUT'],
+                         if_true: files('vhost-user-input-pci.c'))
   endif
   if have_vhost_vdpa
     system_virtio_ss.add(files('vhost-vdpa.c'))
@@ -59,7 +62,6 @@ virtio_pci_ss = ss.source_set()
 virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vsock-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk-pci.c'))
-virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_INPUT', if_true: files('vhost-user-input-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_SCSI', if_true: files('vhost-user-scsi-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-pci.c'))
hw/virtio/vhost-user-input.c renamed from hw/input/vhost-user-input.c +0 -0
similarity index 100%
rename from hw/input/vhost-user-input.c
rename to hw/virtio/vhost-user-input.c
Signature · 1 line
2.39.2
Reviewed-by on v3 3/4
#4 lore raw

Re: [PATCH v3 3/4] hw/virtio: Move vhost-user-input into virtio folder

Quoted 7 lines · Leo Yan

vhost-user-input is in the input folder. On the other hand, the folder 'hw/virtio' maintains other virtio stubs (e.g. I2C, RNG, GPIO, etc).

This patch moves vhost-user-input into the virtio folder for better code organization. No functionality change.

author
#5 lore raw

PATCH v3 4/4 hw/virtio: derive vhost-user-input from vhost-user-base

In reply to Leo Yan

This patch derives vhost-user-input from vhost-user-base class, so make the input stub as a simpler boilerplate wrapper.

With the refactoring, vhost-user-input adds the property 'chardev', this leads to conflict with the vhost-user-input-pci adds the same property. To resolve the error, remove the duplicate property from vhost-user-input-pci.

---
 hw/virtio/vhost-user-input-pci.c |   3 -
 hw/virtio/vhost-user-input.c     | 114 +++++--------------------------
 include/hw/virtio/virtio-input.h |   6 +-
 3 files changed, 21 insertions(+), 102 deletions(-)
hw/virtio/vhost-user-input-pci.c +0 -3
index b858898a36..3f4761ce88 100644
@@ -30,9 +30,6 @@ static void vhost_user_input_pci_instance_init(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vhi, sizeof(dev->vhi),
                                 TYPE_VHOST_USER_INPUT);
-
-    object_property_add_alias(obj, "chardev",
-                              OBJECT(&dev->vhi), "chardev");
 }
 
 static const VirtioPCIDeviceTypeInfo vhost_user_input_pci_info = {
hw/virtio/vhost-user-input.c +18 -96

141 lines not on this page · raw message

include/hw/virtio/virtio-input.h +3 -3
index a6c9703644..e69c0aeca3 100644
@@ -1,6 +1,8 @@
 #ifndef QEMU_VIRTIO_INPUT_H
 #define QEMU_VIRTIO_INPUT_H
 
+#include "hw/virtio/vhost-user.h"
+#include "hw/virtio/vhost-user-base.h"
 #include "ui/input.h"
 #include "sysemu/vhost-user-backend.h"
 
@@ -97,9 +99,7 @@ struct VirtIOInputHost {
 };
 
 struct VHostUserInput {
-    VirtIOInput                       parent_obj;
-
-    VhostUserBackend                  *vhost;
+    VHostUserBase parent_obj;
 };
 
 void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event);
Signature · 1 line
2.39.2
Reviewed-by on v3 4/4
#6 lore raw

Re: [PATCH v3 4/4] hw/virtio: derive vhost-user-input from vhost-user-base

Quoted 10 lines · Leo Yan

This patch derives vhost-user-input from vhost-user-base class, so make the input stub as a simpler boilerplate wrapper.

With the refactoring, vhost-user-input adds the property 'chardev', this leads to conflict with the vhost-user-input-pci adds the same property. To resolve the error, remove the duplicate property from vhost-user-input-pci.

---

#7 lore raw
In reply to Leo Yan
Quoted 1 line · Leo Yan

This series is to refactor vhost stub vhost-user-input.

I tagged this. Given we are in freeze, this will me merged after the release. To help make sure I don't lose this please ping me after the release. Thanks!

#8 lore raw
In reply to Leo Yan
Quoted 10 lines · Leo Yan

This series is to refactor vhost stub vhost-user-input.

Since vhost input stub requires set_config() callback for communication event configurations between the backend and the guest, patch 01 is a preparison for support set_config() callback in vhost-user-base.

The patch 02 is to add documentation for vhost-user-input.

The patch 03 is to move virtio input stub from the input folder to the virtio folder.

Thanks!
Now the release is out I'd like to apply this - can you please rebase on latest master and repost?

Quoted 47 lines

The patch 04 derives vhost-user-input from vhost-user-base. We reuse the common code from vhhost-user-base as possible and the input stub is simplized significantly.

This patch set has been tested with the backend daemon:

  # ./build/contrib/vhost-user-input/vhost-user-input \
		     -p /dev/input/event20 -s /tmp/input.sock

The series is based on "[PATCH v8 0/7] virtio: cleanup vhost-user-generic and reduce c&p" which introduces vhost-user-base.
Based-on: <[email protected]>

Changes from v2:
- Created reference for shared memory object and updated vhost-user-input.rst respectively. (Marc-André)

Changes from v1:
- Fixed typo in vhost-user-input.rst.
- Updated MAINTAINERS for new added input document and changing folder for vhost-user-input.c. (Manos)

Leo Yan (4):
hw/virtio: Support set_config() callback in vhost-user-base docs/system: Add vhost-user-input documentation hw/virtio: Move vhost-user-input into virtio folder hw/virtio: derive vhost-user-input from vhost-user-base

 MAINTAINERS                              |   3 +-
 docs/system/device-emulation.rst         |   1 +
 docs/system/devices/vhost-user-input.rst |  45 ++++++++
 docs/system/devices/vhost-user.rst       |   4 +-
 hw/input/meson.build                     |   1 -
 hw/input/vhost-user-input.c              | 136 -----------------------
 hw/virtio/meson.build                    |   4 +-
 hw/virtio/vhost-user-base.c              |  17 +++
 hw/virtio/vhost-user-input-pci.c         |   3 -
 hw/virtio/vhost-user-input.c             |  58 ++++++++++
 include/hw/virtio/virtio-input.h         |   6 +-
 11 files changed, 132 insertions(+), 146 deletions(-)
 create mode 100644 docs/system/devices/vhost-user-input.rst
 delete mode 100644 hw/input/vhost-user-input.c
 create mode 100644 hw/virtio/vhost-user-input.c
Signature · 1 line
2.39.2
author
#9 lore raw

Hi Michael,

Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Leo Yan

This series is to refactor vhost stub vhost-user-input.

Since vhost input stub requires set_config() callback for communication event configurations between the backend and the guest, patch 01 is a preparison for support set_config() callback in vhost-user-base.

Quoted 8 lines
Quoted 4 lines

The patch 02 is to add documentation for vhost-user-input.

The patch 03 is to move virtio input stub from the input folder to the virtio folder.

Thanks!
Now the release is out I'd like to apply this - can you please rebase on latest master and repost?

Sure. But I found it's not this patch series causing merging conflict.

Since my patch series is based on Alex's patch series "virtio: cleanup vhost-user-generic and reduce c&p" [1], when applying Alex's patch series on the master branch, I found the confliction with below commeits:

91208dd297 ("virtio: i2c: Check notifier helpers for VIRTIO_CONFIG_IRQ_IDX") 298d4f892e ("vhost-user: fix the reconnect error")

@Alex, could you rebase the patch set "virtio: cleanup vhost-user-generic and reduce c&p" and then I will resend my patch set?

Thanks,
Leo

[1] https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 12 lines
Quoted 12 lines

The patch 04 derives vhost-user-input from vhost-user-base. We reuse the common code from vhhost-user-base as possible and the input stub is simplized significantly.

This patch set has been tested with the backend daemon:

  # ./build/contrib/vhost-user-input/vhost-user-input \
		     -p /dev/input/event20 -s /tmp/input.sock

The series is based on "[PATCH v8 0/7] virtio: cleanup vhost-user-generic and reduce c&p" which introduces vhost-user-base.
Based-on: <[email protected]>

#10 lore raw
Quoted 28 lines · Leo Yan

Hi Michael,

Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Leo Yan

This series is to refactor vhost stub vhost-user-input.

Since vhost input stub requires set_config() callback for communication event configurations between the backend and the guest, patch 01 is a preparison for support set_config() callback in vhost-user-base.

Quoted 8 lines
Quoted 4 lines

The patch 02 is to add documentation for vhost-user-input.

The patch 03 is to move virtio input stub from the input folder to the virtio folder.

Thanks!
Now the release is out I'd like to apply this - can you please rebase on latest master and repost?

Sure. But I found it's not this patch series causing merging conflict.

Since my patch series is based on Alex's patch series "virtio: cleanup vhost-user-generic and reduce c&p" [1], when applying Alex's patch series on the master branch, I found the confliction with below commeits:

91208dd297 ("virtio: i2c: Check notifier helpers for VIRTIO_CONFIG_IRQ_IDX") 298d4f892e ("vhost-user: fix the reconnect error")

Quoted 20 lines

@Alex, could you rebase the patch set "virtio: cleanup vhost-user-generic and reduce c&p" and then I will resend my patch set?

Thanks,
Leo

[1] https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 12 lines
Quoted 12 lines

The patch 04 derives vhost-user-input from vhost-user-base. We reuse the common code from vhhost-user-base as possible and the input stub is simplized significantly.

This patch set has been tested with the backend daemon:

  # ./build/contrib/vhost-user-input/vhost-user-input \
		     -p /dev/input/event20 -s /tmp/input.sock

The series is based on "[PATCH v8 0/7] virtio: cleanup vhost-user-generic and reduce c&p" which introduces vhost-user-base.
Based-on: <[email protected]>

I'll fix up and include this series in my next posting. Hopefully by the end of this week.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
Applied
#11 lore raw
In reply to Leo Yan
Quoted 5 lines · Leo Yan

This series is to refactor vhost stub vhost-user-input.

Since vhost input stub requires set_config() callback for communication event configurations between the backend and the guest, patch 01 is a preparison for support set_config() callback in vhost-user-base.

Queued to virtio/vhost-user-device, thanks.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro