Skip to contentSkip to conversation

Add SCMI vhost-user VIRTIO device

PATCH Superseded Milan Zamazal 4 participants 11 messages May 30, 2023 – May 31, 2023 Arm/Amlogic Meson SoC support

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add SCMI vhost-user VIRTIO device

This patch series adds a vhost-user VIRTIO device for SCMI. It's similar to other similar vhost-user VIRTIO devices.

I'm aware of the work in progress by Alex Bennée to simplify similar devices and avoid excessive code duplication. I think the SCMI device support doesn't bring anything special and it can be rebased on the given work if/once it is merged.

Milan Zamazal (4):
hw/virtio: Add boilerplate for vhost-user-scmi device hw/virtio: Add vhost-user-scmi-pci boilerplate tests/qtest: Fix a comment typo in vhost-user-test.c tests/qtest: enable tests for virtio-scmi

 MAINTAINERS                         |   7 +
 hw/virtio/Kconfig                   |   5 +
 hw/virtio/meson.build               |   2 +
 hw/virtio/vhost-user-scmi-pci.c     |  68 +++++++
 hw/virtio/vhost-user-scmi.c         | 306 ++++++++++++++++++++++++++++
 include/hw/virtio/vhost-user-scmi.h |  30 +++
 tests/qtest/libqos/meson.build      |   1 +
 tests/qtest/libqos/virtio-scmi.c    | 174 ++++++++++++++++
 tests/qtest/libqos/virtio-scmi.h    |  34 ++++
 tests/qtest/vhost-user-test.c       |  46 ++++-
 10 files changed, 672 insertions(+), 1 deletion(-)
 create mode 100644 hw/virtio/vhost-user-scmi-pci.c
 create mode 100644 hw/virtio/vhost-user-scmi.c
 create mode 100644 include/hw/virtio/vhost-user-scmi.h
 create mode 100644 tests/qtest/libqos/virtio-scmi.c
 create mode 100644 tests/qtest/libqos/virtio-scmi.h
Signature · 1 line
2.38.5
#1 lore raw

PATCH 1/4 hw/virtio: Add boilerplate for vhost-user-scmi device

This creates the QEMU side of the vhost-user-scmi device which connects to the remote daemon. It is based on code of similar vhost-user devices.

---
 MAINTAINERS                         |   6 +
 hw/virtio/Kconfig                   |   5 +
 hw/virtio/meson.build               |   1 +
 hw/virtio/vhost-user-scmi.c         | 306 ++++++++++++++++++++++++++++
 include/hw/virtio/vhost-user-scmi.h |  30 +++
 5 files changed, 348 insertions(+)
 create mode 100644 hw/virtio/vhost-user-scmi.c
 create mode 100644 include/hw/virtio/vhost-user-scmi.h
MAINTAINERS +6 -0
index 4b025a7b63..1ce2f3dabe 100644
@@ -2202,6 +2202,12 @@ F: hw/virtio/vhost-user-gpio*
 F: include/hw/virtio/vhost-user-gpio.h
 F: tests/qtest/libqos/virtio-gpio.*
 
+vhost-user-scmi
+R: [email protected]
+S: Supported
+F: hw/virtio/vhost-user-scmi*
+F: include/hw/virtio/vhost-user-scmi.h
+
 virtio-crypto
 M: Gonglei <[email protected]>
 S: Supported
hw/virtio/Kconfig +5 -0
index 89e9e426d8..2515d4ff68 100644
@@ -90,3 +90,8 @@ config VHOST_VDPA_DEV
     bool
     default y
     depends on VIRTIO && VHOST_VDPA && LINUX
+
+config VHOST_USER_SCMI
+    bool
+    default y
+    depends on VIRTIO && VHOST_USER
hw/virtio/meson.build +1 -0
index bdec78bfc6..c3eeb23942 100644
@@ -32,6 +32,7 @@ specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user
 specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c'))
 specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-gpio.c'))
 specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO'], if_true: files('vhost-user-gpio-pci.c'))
+specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_SCMI', if_true: files('vhost-user-scmi.c'))
 specific_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c'))
 
 virtio_pci_ss = ss.source_set()
hw/virtio/vhost-user-scmi.c new file +306 -0

306 lines not on this page · raw message

include/hw/virtio/vhost-user-scmi.h new file +30 -0
new file mode 100644
index 0000000000..6175a74ebd
@@ -0,0 +1,30 @@
+/*
+ * Vhost-user SCMI virtio device
+ *
+ * Copyright (c) 2023 Red Hat, Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef _QEMU_VHOST_USER_SCMI_H
+#define _QEMU_VHOST_USER_SCMI_H
+
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/vhost.h"
+#include "hw/virtio/vhost-user.h"
+
+#define TYPE_VHOST_USER_SCMI "vhost-user-scmi"
+OBJECT_DECLARE_SIMPLE_TYPE(VHostUserSCMI, VHOST_USER_SCMI);
+
+struct VHostUserSCMI {
+    VirtIODevice parent;
+    CharBackend chardev;
+    struct vhost_virtqueue *vhost_vqs;
+    struct vhost_dev vhost_dev;
+    VhostUserState vhost_user;
+    VirtQueue *cmd_vq;
+    VirtQueue *event_vq;
+    bool connected;
+};
+
+#endif /* _QEMU_VHOST_USER_SCMI_H */
Signature · 1 line
2.38.5
#2 lore raw

PATCH 2/4 hw/virtio: Add vhost-user-scmi-pci boilerplate

In reply to Milan Zamazal

This allows is to instantiate a vhost-user-scmi device as part of a PCI bus. It is mostly boilerplate similar to the other vhost-user-*-pci boilerplates of similar devices.

---
 hw/virtio/meson.build           |  1 +
 hw/virtio/vhost-user-scmi-pci.c | 68 +++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)
 create mode 100644 hw/virtio/vhost-user-scmi-pci.c
hw/virtio/meson.build +1 -0
index c3eeb23942..bdea57b2ef 100644
@@ -33,6 +33,7 @@ specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user
 specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-gpio.c'))
 specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO'], if_true: files('vhost-user-gpio-pci.c'))
 specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_SCMI', if_true: files('vhost-user-scmi.c'))
+specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_SCMI'], if_true: files('vhost-user-scmi-pci.c'))
 specific_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c'))
 
 virtio_pci_ss = ss.source_set()
hw/virtio/vhost-user-scmi-pci.c new file +68 -0

68 lines not on this page · raw message

Signature · 1 line
2.38.5
#3 lore raw

PATCH 3/4 tests/qtest: Fix a comment typo in vhost-user-test.c

In reply to Milan Zamazal
---
 tests/qtest/vhost-user-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/vhost-user-test.c +1 -1
index e4f95b2858..8ab10732f8 100644
@@ -281,7 +281,7 @@ static void read_guest_mem_server(QTestState *qts, TestServer *s)
     /* iterate all regions */
     for (i = 0; i < s->fds_num; i++) {
 
-        /* We'll check only the region statring at 0x0*/
+        /* We'll check only the region starting at 0x0*/
         if (s->memory.regions[i].guest_phys_addr != 0x0) {
             continue;
         }
Signature · 1 line
2.38.5
Reviewed-by on v1 3/4
#4 lore raw

Re: [PATCH 3/4] tests/qtest: Fix a comment typo in vhost-user-test.c

Quoted 10 lines · Milan Zamazal
---
  tests/qtest/vhost-user-test.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/vhost-user-test.c +0 -0
index e4f95b2858..8ab10732f8 100644

tests/qtest/vhost-user-test.c static void read_guest_mem_server(QTestState *qts, TestServer *s) · line 284

Quoted 5 lines
tests/qtest/vhost-user-test.c +1 -1
@@ -281,7 +281,7 @@ static void read_guest_mem_server(QTestState *qts, TestServer *s)
      /* iterate all regions */
      for (i = 0; i < s->fds_num; i++) {
 
-        /* We'll check only the region statring at 0x0*/
+        /* We'll check only the region starting at 0x0*/

While you're at it, I'd also add a space between the "0x0" and the "*/".

Anyway:

Quoted 3 lines
tests/qtest/vhost-user-test.c +0 -0
          if (s->memory.regions[i].guest_phys_addr != 0x0) {
              continue;
          }
#5 lore raw

Re: [PATCH 3/4] tests/qtest: Fix a comment typo in vhost-user-test.c

Quoted 4 lines · Thomas Huth
Quoted 2 lines · Milan Zamazal

---

Quoted 14 lines

tests/qtest/vhost-user-test.c static void read_guest_mem_server(QTestState *qts, TestServer *s) · line 284

Quoted 12 lines
  tests/qtest/vhost-user-test.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/vhost-user-test.c +1 -0
index e4f95b2858..8ab10732f8 100644
@@ -281,7 +281,7 @@ static void read_guest_mem_server(QTestState *qts, TestServer *s)
      /* iterate all regions */
      for (i = 0; i < s->fds_num; i++) {
  -        /* We'll check only the region statring at 0x0*/
+        /* We'll check only the region starting at 0x0*/

While you're at it, I'd also add a space between the "0x0" and the "*/".

I'll add it in the next patch iteration, thanks for pointing this out.

Quoted 6 lines

Anyway:

Quoted 3 lines
tests/qtest/vhost-user-test.c +0 -0
          if (s->memory.regions[i].guest_phys_addr != 0x0) {
              continue;
          }
#6 lore raw

PATCH 4/4 tests/qtest: enable tests for virtio-scmi

In reply to Milan Zamazal

We don't have a virtio-scmi implementation in QEMU and only support a vhost-user backend. This is very similar to virtio-gpio and we add the same set of tests, just passing some vhost-user messages over the control socket.

---
 MAINTAINERS                      |   1 +
 tests/qtest/libqos/meson.build   |   1 +
 tests/qtest/libqos/virtio-scmi.c | 174 +++++++++++++++++++++++++++++++
 tests/qtest/libqos/virtio-scmi.h |  34 ++++++
 tests/qtest/vhost-user-test.c    |  44 ++++++++
 5 files changed, 254 insertions(+)
 create mode 100644 tests/qtest/libqos/virtio-scmi.c
 create mode 100644 tests/qtest/libqos/virtio-scmi.h
MAINTAINERS +1 -0
index 1ce2f3dabe..26a5bad736 100644
@@ -2207,6 +2207,7 @@ R: [email protected]
 S: Supported
 F: hw/virtio/vhost-user-scmi*
 F: include/hw/virtio/vhost-user-scmi.h
+F: tests/qtest/libqos/virtio-scmi.*
 
 virtio-crypto
 M: Gonglei <[email protected]>
tests/qtest/libqos/meson.build +1 -0
index cc209a8de5..90aae42a22 100644
@@ -46,6 +46,7 @@ libqos_srcs = files(
         'virtio-serial.c',
         'virtio-iommu.c',
         'virtio-gpio.c',
+        'virtio-scmi.c',
         'generic-pcihost.c',
 
         # qgraph machines:
tests/qtest/libqos/virtio-scmi.c new file +174 -0

174 lines not on this page · raw message

tests/qtest/libqos/virtio-scmi.h new file +34 -0
new file mode 100644
index 0000000000..cb5670da6e
@@ -0,0 +1,34 @@
+/*
+ * virtio-scmi structures
+ *
+ * SPDX-FileCopyrightText: Red Hat, Inc.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef TESTS_LIBQOS_VIRTIO_SCMI_H
+#define TESTS_LIBQOS_VIRTIO_SCMI_H
+
+#include "qgraph.h"
+#include "virtio.h"
+#include "virtio-pci.h"
+
+typedef struct QVhostUserSCMI QVhostUserSCMI;
+typedef struct QVhostUserSCMIPCI QVhostUserSCMIPCI;
+typedef struct QVhostUserSCMIDevice QVhostUserSCMIDevice;
+
+struct QVhostUserSCMI {
+    QVirtioDevice *vdev;
+    QVirtQueue **queues;
+};
+
+struct QVhostUserSCMIPCI {
+    QVirtioPCIDevice pci_vdev;
+    QVhostUserSCMI scmi;
+};
+
+struct QVhostUserSCMIDevice {
+    QOSGraphObject obj;
+    QVhostUserSCMI scmi;
+};
+
+#endif
tests/qtest/vhost-user-test.c +44 -0

59 lines not on this page · raw message

Signature · 1 line
2.38.5
Acked-by on v1 4/4
#7 lore raw

Re: [PATCH 4/4] tests/qtest: enable tests for virtio-scmi

Quoted 12 lines · Milan Zamazal

We don't have a virtio-scmi implementation in QEMU and only support a vhost-user backend. This is very similar to virtio-gpio and we add the same set of tests, just passing some vhost-user messages over the control socket.

---
  MAINTAINERS                      |   1 +
  tests/qtest/libqos/meson.build   |   1 +
  tests/qtest/libqos/virtio-scmi.c | 174 +++++++++++++++++++++++++++++++
  tests/qtest/libqos/virtio-scmi.h |  34 ++++++
  tests/qtest/vhost-user-test.c    |  44 ++++++++
  5 files changed, 254 insertions(+)
Quoted 2 lines

create mode 100644 tests/qtest/libqos/virtio-scmi.c create mode 100644 tests/qtest/libqos/virtio-scmi.h

#8 lore raw
In reply to Milan Zamazal
Quoted 7 lines · Milan Zamazal

This patch series adds a vhost-user VIRTIO device for SCMI. It's similar to other similar vhost-user VIRTIO devices.

I'm aware of the work in progress by Alex Bennée to simplify similar devices and avoid excessive code duplication. I think the SCMI device support doesn't bring anything special and it can be rebased on the given work if/once it is merged.

\o/ - I'll try and get the next iteration done in the next few weeks. Out of interest have you tested your scmi backend with those patches? Oh and also which backend are you using?

Vincent did a bunch of work over the last year or so on SCMI although in his case the backend was a RTOS running in a separate domain using some shared memory between the SCMI domain and a couple of guests.

Quoted 22 lines

Milan Zamazal (4):
hw/virtio: Add boilerplate for vhost-user-scmi device hw/virtio: Add vhost-user-scmi-pci boilerplate tests/qtest: Fix a comment typo in vhost-user-test.c tests/qtest: enable tests for virtio-scmi

 MAINTAINERS                         |   7 +
 hw/virtio/Kconfig                   |   5 +
 hw/virtio/meson.build               |   2 +
 hw/virtio/vhost-user-scmi-pci.c     |  68 +++++++
 hw/virtio/vhost-user-scmi.c         | 306 ++++++++++++++++++++++++++++
 include/hw/virtio/vhost-user-scmi.h |  30 +++
 tests/qtest/libqos/meson.build      |   1 +
 tests/qtest/libqos/virtio-scmi.c    | 174 ++++++++++++++++
 tests/qtest/libqos/virtio-scmi.h    |  34 ++++
 tests/qtest/vhost-user-test.c       |  46 ++++-
 10 files changed, 672 insertions(+), 1 deletion(-)
 create mode 100644 hw/virtio/vhost-user-scmi-pci.c
 create mode 100644 hw/virtio/vhost-user-scmi.c
 create mode 100644 include/hw/virtio/vhost-user-scmi.h
 create mode 100644 tests/qtest/libqos/virtio-scmi.c
 create mode 100644 tests/qtest/libqos/virtio-scmi.h
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#9 lore raw
Quoted 11 lines · Alex Bennée
Quoted 7 lines · Milan Zamazal

This patch series adds a vhost-user VIRTIO device for SCMI. It's similar to other similar vhost-user VIRTIO devices.

I'm aware of the work in progress by Alex Bennée to simplify similar devices and avoid excessive code duplication. I think the SCMI device support doesn't bring anything special and it can be rebased on the given work if/once it is merged.

\o/ - I'll try and get the next iteration done in the next few weeks.

Great, looking forward.

Quoted 2 lines

Out of interest have you tested your scmi backend with those patches? Oh and also which backend are you using?

I have tested the patches with my proof-of-concept SCMI backend (emulating a fake sensor) based on rust-vmm and a Linux guest OS. I plan to change the prototype into something publishable in the next weeks and to post patches to rust-vmm/vhost-device.

Quoted 3 lines

Vincent did a bunch of work over the last year or so on SCMI although in his case the backend was a RTOS running in a separate domain using some shared memory between the SCMI domain and a couple of guests.

I have seen recordings of some related presentations. The work is primarily based on crosvm, right? I'd be interested in what kind of SCMI interface the domain provides and whether it would make sense to be able to connect it with the QEMU SCMI device via some vhost-user daemon, an already existing one, if any, and/or the one I work on.

Quoted 22 lines
Quoted 22 lines

Milan Zamazal (4):
hw/virtio: Add boilerplate for vhost-user-scmi device hw/virtio: Add vhost-user-scmi-pci boilerplate tests/qtest: Fix a comment typo in vhost-user-test.c tests/qtest: enable tests for virtio-scmi

 MAINTAINERS                         |   7 +
 hw/virtio/Kconfig                   |   5 +
 hw/virtio/meson.build               |   2 +
 hw/virtio/vhost-user-scmi-pci.c     |  68 +++++++
 hw/virtio/vhost-user-scmi.c         | 306 ++++++++++++++++++++++++++++
 include/hw/virtio/vhost-user-scmi.h |  30 +++
 tests/qtest/libqos/meson.build      |   1 +
 tests/qtest/libqos/virtio-scmi.c    | 174 ++++++++++++++++
 tests/qtest/libqos/virtio-scmi.h    |  34 ++++
 tests/qtest/vhost-user-test.c       |  46 ++++-
 10 files changed, 672 insertions(+), 1 deletion(-)
 create mode 100644 hw/virtio/vhost-user-scmi-pci.c
 create mode 100644 hw/virtio/vhost-user-scmi.c
 create mode 100644 include/hw/virtio/vhost-user-scmi.h
 create mode 100644 tests/qtest/libqos/virtio-scmi.c
 create mode 100644 tests/qtest/libqos/virtio-scmi.h
#10 lore raw
Quoted 25 lines · Milan Zamazal
Quoted 11 lines · Alex Bennée
Quoted 7 lines · Milan Zamazal

This patch series adds a vhost-user VIRTIO device for SCMI. It's similar to other similar vhost-user VIRTIO devices.

I'm aware of the work in progress by Alex Bennée to simplify similar devices and avoid excessive code duplication. I think the SCMI device support doesn't bring anything special and it can be rebased on the given work if/once it is merged.

\o/ - I'll try and get the next iteration done in the next few weeks.

Great, looking forward.

Quoted 2 lines

Out of interest have you tested your scmi backend with those patches? Oh and also which backend are you using?

I have tested the patches with my proof-of-concept SCMI backend (emulating a fake sensor) based on rust-vmm and a Linux guest OS. I plan to change the prototype into something publishable in the next weeks and to post patches to rust-vmm/vhost-device.

Quoted 6 lines
Quoted 3 lines

Vincent did a bunch of work over the last year or so on SCMI although in his case the backend was a RTOS running in a separate domain using some shared memory between the SCMI domain and a couple of guests.

I have seen recordings of some related presentations. The work is primarily based on crosvm, right? I'd be interested in what kind of

I have used qemu for my tests

Quoted 3 lines

SCMI interface the domain provides and whether it would make sense to be able to connect it with the QEMU SCMI device via some vhost-user daemon, an already existing one, if any, and/or the one I work on.

My PoC is based on the SCP-firmware that is usually running on a dedicated power coprocessor. We have extended it to run in several env. The PoC runs the SCP firmware in a VM and uses a vhost user scmi bridge to connect the guest vm with this virtual power coprocessor. One reason for using SCP-firmware is that It follows SCMI specs and its updates so I don't have to re-implement it myself and can leverage on their devs

For test purpose I also have enabled it as a simple linux vhost user daemon

Quoted 24 lines
Quoted 23 lines
Quoted 23 lines

Milan Zamazal (4):
hw/virtio: Add boilerplate for vhost-user-scmi device hw/virtio: Add vhost-user-scmi-pci boilerplate tests/qtest: Fix a comment typo in vhost-user-test.c tests/qtest: enable tests for virtio-scmi

 MAINTAINERS                         |   7 +
 hw/virtio/Kconfig                   |   5 +
 hw/virtio/meson.build               |   2 +
 hw/virtio/vhost-user-scmi-pci.c     |  68 +++++++
 hw/virtio/vhost-user-scmi.c         | 306 ++++++++++++++++++++++++++++
 include/hw/virtio/vhost-user-scmi.h |  30 +++
 tests/qtest/libqos/meson.build      |   1 +
 tests/qtest/libqos/virtio-scmi.c    | 174 ++++++++++++++++
 tests/qtest/libqos/virtio-scmi.h    |  34 ++++
 tests/qtest/vhost-user-test.c       |  46 ++++-
 10 files changed, 672 insertions(+), 1 deletion(-)
 create mode 100644 hw/virtio/vhost-user-scmi-pci.c
 create mode 100644 hw/virtio/vhost-user-scmi.c
 create mode 100644 include/hw/virtio/vhost-user-scmi.h
 create mode 100644 tests/qtest/libqos/virtio-scmi.c
 create mode 100644 tests/qtest/libqos/virtio-scmi.h