Skip to contentSkip to conversation

toolstack support for generic virtio devices on Arm

PATCH Superseded Viresh Kumar 2 participants 8 messages Dec 7, 2022 – Dec 9, 2022

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v7 cover toolstack support for generic virtio devices on Arm

Hello,

This patchset adds toolstack support for I2C, GPIO and generic virtio devices. This is inspired from the work done by Oleksandr for the Disk device.

This is developed as part of Linaro's Project Stratos, where we are working towards Hypervisor agnostic Rust based backends [1].

This is based of Julien's for-next/4.18 branch [2].

V6->V7:
- Support generic virtio devices too. They are passed with type=virtio,device, and we only create the MMIO DT node for them.
- Add links to DT bindings of I2C and GPIO, in code and documentation.
- Call libxl__device_add() for all hypervisor types.
- Add (0, "UNKNOWN") for libxl_virtio_transport.
- Removed libxl_virtio_backend and libxl_virtioinfo, as they were unused.
- Remove unnecessary stuff from libxl__virtio_from_xenstore() and add support for type and transport.
- Add backend=domid in documentation and replace compatible with type.
- Improved commit logs.

V5->V6:
- The cleanup patches are sent separately [2].
- We don't add I2C or GPIO specific device changes anymore, rather we create generic "virtio" devices. The "type" of a virtio devices helps us identify the right device, and create an entry in the DT node. The same can be used for all Virtio devices now.
- Update man page xl.cfg.

V4->V5:
- Fixed indentation at few places.
- Removed/added blank lines.
- Added few comments.
- Added review tags from Oleksandr.
- Rebased over latest staging branch.

V3->V4:
- Update virtio_enabled independently of all devices, so we don't miss setting it to true.

- Add iommu handling for i2c/gpio and move it as part of make_virtio_mmio_node_common(), which gets backend_domid parameter as a result.

V2->V3:
- Rebased over latest tree and made changes according to changes in Oleksandr's patches from sometime back.
- Minor cleanups.

V1->V2:
- Patches 3/6 and 4/6 are new.
- Patches 5/6 and 6/6 updated based on the above two patches.
- Added link to the bindings for I2C and GPIO.
- Rebased over latest master branch.

Thanks.

--
Viresh

[1] https://lore.kernel.org/xen-devel/20220414092358.kepxbmnrtycz7mhe@vireshk-i7/
[2] https://xenbits.xen.org/gitweb/?p=people/julieng/xen-unstable.git;a=shortlog;h=refs/heads/for-next/4.18

Viresh Kumar (3):
libxl: Add support for generic virtio device
xl: Add support to parse generic virtio device
docs: Add documentation for generic virtio devices

 docs/man/xl.cfg.5.pod.in                  |  28 +++++
 tools/libs/light/Makefile                 |   1 +
 tools/libs/light/libxl_arm.c              | 103 ++++++++++++++++
 tools/libs/light/libxl_create.c           |   4 +
 tools/libs/light/libxl_internal.h         |   1 +
 tools/libs/light/libxl_types.idl          |  18 +++
 tools/libs/light/libxl_types_internal.idl |   1 +
 tools/libs/light/libxl_virtio.c           | 144 ++++++++++++++++++++++
 tools/ocaml/libs/xl/genwrap.py            |   1 +
 tools/ocaml/libs/xl/xenlight_stubs.c      |   1 +
 tools/xl/xl_parse.c                       |  80 ++++++++++++
 11 files changed, 382 insertions(+)
 create mode 100644 tools/libs/light/libxl_virtio.c
Signature · 1 line
2.31.1.272.g89b43f80a514
#1 lore raw

PATCH v7 1/3 libxl: Add support for generic virtio device

This patch adds basic support for configuring and assisting generic Virtio backends, which could run in any domain.

An example of domain configuration for mmio based Virtio I2C device is:
virtio = ["type=virtio,device22,transport=mmio"]

To make this work on Arm, allocate Virtio MMIO params (IRQ and memory region) and pass them to the backend and update guest device-tree to create a DT node for the Virtio devices.

Add special support for I2C and GPIO devices, which require the "compatible" DT property to be set, among other device specific properties. Support for generic virtio devices is also added, which just need a MMIO node but not any special DT properties, for such devices the user needs to pass "virtio,devices" in the "type" string.

The parsing of generic virtio device configurations will be done in a separate commit.

---
 tools/libs/light/Makefile                 |   1 +
 tools/libs/light/libxl_arm.c              | 103 ++++++++++++++++
 tools/libs/light/libxl_create.c           |   4 +
 tools/libs/light/libxl_internal.h         |   1 +
 tools/libs/light/libxl_types.idl          |  18 +++
 tools/libs/light/libxl_types_internal.idl |   1 +
 tools/libs/light/libxl_virtio.c           | 144 ++++++++++++++++++++++
 7 files changed, 272 insertions(+)
 create mode 100644 tools/libs/light/libxl_virtio.c
tools/libs/light/Makefile +1 -0
index 374be1cfab25..4fddcc6f51d7 100644
@@ -106,6 +106,7 @@ OBJS-y += libxl_vdispl.o
 OBJS-y += libxl_pvcalls.o
 OBJS-y += libxl_vsnd.o
 OBJS-y += libxl_vkb.o
+OBJS-y += libxl_virtio.o
 OBJS-y += libxl_genid.o
 OBJS-y += _libxl_types.o
 OBJS-y += libxl_flask.o
tools/libs/light/libxl_arm.c +103 -0

121 lines not on this page · raw message

tools/libs/light/libxl_create.c +4 -0
index 612eacfc7fac..beec3f6b6fec 100644
@@ -1752,6 +1752,10 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
         libxl__device_add(gc, domid, &libxl__pvcallsif_devtype,
                           &d_config->pvcallsifs[i]);
 
+    for (i = 0; i < d_config->num_virtios; i++)
+        libxl__device_add(gc, domid, &libxl__virtio_devtype,
+                          &d_config->virtios[i]);
+
     switch (d_config->c_info.type) {
     case LIBXL_DOMAIN_TYPE_HVM:
     {
tools/libs/light/libxl_internal.h +1 -0
index a7c447c10e5f..cdd155d925c1 100644
@@ -4003,6 +4003,7 @@ static inline int *libxl__device_type_get_num(
 
 extern const libxl__device_type libxl__vfb_devtype;
 extern const libxl__device_type libxl__vkb_devtype;
+extern const libxl__device_type libxl__virtio_devtype;
 extern const libxl__device_type libxl__disk_devtype;
 extern const libxl__device_type libxl__nic_devtype;
 extern const libxl__device_type libxl__vtpm_devtype;
tools/libs/light/libxl_types.idl +18 -0
index 9e3d33cb5a59..0cfad8508dbd 100644
@@ -278,6 +278,11 @@ libxl_vkb_backend = Enumeration("vkb_backend", [
     (2, "LINUX")
     ])
 
+libxl_virtio_transport = Enumeration("virtio_transport", [
+    (0, "UNKNOWN"),
+    (1, "MMIO"),
+    ])
+
 libxl_passthrough = Enumeration("passthrough", [
     (0, "default"),
     (1, "disabled"),
@@ -703,6 +708,18 @@ libxl_device_vkb = Struct("device_vkb", [
     ("multi_touch_num_contacts", uint32)
     ])
 
+libxl_device_virtio = Struct("device_virtio", [
+    ("backend_domid", libxl_domid),
+    ("backend_domname", string),
+    ("type", string),
+    ("transport", libxl_virtio_transport),
+    ("devid", libxl_devid),
+    # Note that virtio-mmio parameters (irq and base) are for internal
+    # use by libxl and can't be modified.
+    ("irq", uint32),
+    ("base", uint64)
+    ])
+
 libxl_device_disk = Struct("device_disk", [
     ("backend_domid", libxl_domid),
     ("backend_domname", string),
@@ -980,6 +997,7 @@ libxl_domain_config = Struct("domain_config", [
     ("dtdevs", Array(libxl_device_dtdev, "num_dtdevs")),
     ("vfbs", Array(libxl_device_vfb, "num_vfbs")),
     ("vkbs", Array(libxl_device_vkb, "num_vkbs")),
+    ("virtios", Array(libxl_device_virtio, "num_virtios")),
     ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),
     ("p9s", Array(libxl_device_p9, "num_p9s")),
     ("pvcallsifs", Array(libxl_device_pvcallsif, "num_pvcallsifs")),
tools/libs/light/libxl_types_internal.idl +1 -0
index fb0f4f23d7c2..e24288f1a59e 100644
@@ -33,6 +33,7 @@ libxl__device_kind = Enumeration("device_kind", [
     (15, "VSND"),
     (16, "VINPUT"),
     (17, "VIRTIO_DISK"),
+    (18, "VIRTIO"),
     ])
 
 libxl__console_backend = Enumeration("console_backend", [
tools/libs/light/libxl_virtio.c new file +144 -0

144 lines not on this page · raw message

Signature · 1 line
2.31.1.272.g89b43f80a514
#5 lore raw

PATCH v7 2/3 xl: Add support to parse generic virtio device

In reply to Viresh Kumar

This patch adds basic support for parsing generic Virtio backend.

An example of domain configuration for mmio based Virtio I2C device is:
virtio = ["type=virtio,device22,transport=mmio"]

---
 tools/ocaml/libs/xl/genwrap.py       |  1 +
 tools/ocaml/libs/xl/xenlight_stubs.c |  1 +
 tools/xl/xl_parse.c                  | 80 ++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+)
tools/ocaml/libs/xl/genwrap.py +1 -0
index 7bf26bdcd831..b188104299b1 100644
@@ -36,6 +36,7 @@ DEVICE_LIST =      [ ("list",           ["ctx", "domid", "t list"]),
 functions = { # ( name , [type1,type2,....] )
     "device_vfb":     DEVICE_FUNCTIONS,
     "device_vkb":     DEVICE_FUNCTIONS,
+    "device_virtio":     DEVICE_FUNCTIONS,
     "device_disk":    DEVICE_FUNCTIONS + DEVICE_LIST +
                       [ ("insert",         ["ctx", "t", "domid", "?async:'a", "unit", "unit"]),
                         ("of_vdev",        ["ctx", "domid", "string", "t"]),
tools/ocaml/libs/xl/xenlight_stubs.c +1 -0
index 45b8af61c74a..8e54f95da7c7 100644
@@ -707,6 +707,7 @@ DEVICE_ADDREMOVE(disk)
 DEVICE_ADDREMOVE(nic)
 DEVICE_ADDREMOVE(vfb)
 DEVICE_ADDREMOVE(vkb)
+DEVICE_ADDREMOVE(virtio)
 DEVICE_ADDREMOVE(pci)
 _DEVICE_ADDREMOVE(disk, cdrom, insert)
 
tools/xl/xl_parse.c +80 -0

100 lines not on this page · raw message

Signature · 1 line
2.31.1.272.g89b43f80a514
#6 lore raw

PATCH v7 3/3 docs: Add documentation for generic virtio devices

In reply to Viresh Kumar

This patch updates xl.cfg man page with details of generic Virtio device related information.

---
 docs/man/xl.cfg.5.pod.in | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
docs/man/xl.cfg.5.pod.in +28 -0
index ec444fb2ba79..2523027ea54c 100644
@@ -1585,6 +1585,34 @@ Set maximum height for pointer device.
 
 =back
 
+=item B<virtio=[ "VIRTIO_DEVICE_STRING", "VIRTIO_DEVICE_STRING", ...]>
+
+Specifies the Virtio devices to be provided to the guest.
+
+Each B<VIRTIO_DEVICE_STRING> is a comma-separated list of C<KEY=VALUE>
+settings from the following list:
+
+=over 4
+
+=item B<backend=domain-id>
+
+Specifies the backend domain name or id, defaults to dom0.
+
+=item B<type=STRING>
+
+Specifies the compatible string for the specific Virtio device. The same will be
+written in the Device Tree compatible property of the Virtio device. For
+example, "type=virtio,device22" for the I2C device, whose device-tree binding is
+present here:
+
+L<https://www.kernel.org/doc/Documentation/devicetree/bindings/i2c/i2c-virtio.yaml>
+
+=item B<transport=STRING>
+
+Specifies the transport mechanism for the Virtio device, like "mmio" or "pci".
+
+=back
+
 =item B<tee="STRING">
 
 B<Arm only.> Set TEE type for the guest. TEE is a Trusted Execution
Signature · 1 line
2.31.1.272.g89b43f80a514
#2 lore raw

Re: [PATCH V7 1/3] libxl: Add support for generic virtio device

In reply to Viresh Kumar
Quoted 5 lines · Viresh Kumar
tools/libs/light/libxl_arm.c +1 -0
index fa3d61f1e882..ab3668b3b8a3 100644
+static int make_virtio_mmio_node_device(libxl__gc *gc, void *fdt, uint64_t base,

tools/libs/light/libxl_arm.c static int make_virtio_mmio_node(libxl__gc *gc, void *fdt, uint64_t base, · line 1030

Quoted 10 lines
tools/libs/light/libxl_arm.c +10 -0
+                                        uint32_t irq, const char *type,
+                                        uint32_t backend_domid)
+{
+    int res, len = strlen(type);
+
+    res = make_virtio_mmio_node_common(gc, fdt, base, irq, backend_domid);
+    if (res) return res;
+
+    /* Add device specific nodes */
+    if (!strncmp(type, "virtio,device22", len)) {

So with len been the strlen() of type, I think that a type "v" or "virtio" or even "virtio,device" is going to create the "i2c" node. So I don't think is going to be possible to create a generic virtio device node.

Using strcmp() would be good enough here I think.

tools/libs/light/libxl_arm.c static int make_virtio_mmio_node(libxl__gc *gc, void *fdt, uint64_t base, · line 1036

Quoted 6 lines
tools/libs/light/libxl_arm.c +6 -0
+        res = make_virtio_mmio_node_i2c(gc, fdt);
+        if (res) return res;
+    } else if (!strncmp(type, "virtio,device29", len)) {
+        res = make_virtio_mmio_node_gpio(gc, fdt);
+        if (res) return res;
+    } else if (!strncmp(type, "virtio,device", len)) {

The example in in the commit message has "virtio,devices" but that would be rejected by this test due to the extra 's'.

tools/libs/light/libxl_arm.c static int make_virtio_mmio_node(libxl__gc *gc, void *fdt, uint64_t base, · line 1038

Quoted 2 lines
tools/libs/light/libxl_arm.c +2 -0
+        /* Generic Virtio Device */
+        res = fdt_end_node(fdt);

Isn't this an extra end_node() call? As there's already one for the return of the function.

Quoted 45 lines
tools/libs/light/libxl_arm.c +9 -0
+        if (res) return res;
+    } else {
+        LOG(ERROR, "Invalid type for virtio device: %s", type);
+        return -EINVAL;
+    }
+
+    return fdt_end_node(fdt);
+}
+
tools/libs/light/libxl_virtio.c new file +31 -0
new file mode 100644
index 000000000000..64cec989c674
+static int libxl__virtio_from_xenstore(libxl__gc *gc, const char *libxl_path,
+                                       libxl_devid devid,
+                                       libxl_device_virtio *virtio)
+{
+    const char *be_path, *tmp = NULL;
+    int rc;
+
+    virtio->devid = devid;
+
+    rc = libxl__xs_read_mandatory(gc, XBT_NULL,
+                                  GCSPRINTF("%s/backend", libxl_path),
+                                  &be_path);
+    if (rc) goto out;
+
+    rc = libxl__backendpath_parse_domid(gc, be_path, &virtio->backend_domid);
+    if (rc) goto out;
+
+    rc = libxl__xs_read_checked(gc, XBT_NULL,
+				GCSPRINTF("%s/irq", be_path), &tmp);
+    if (rc) goto out;
+
+    if (tmp) {
+        virtio->irq = strtoul(tmp, NULL, 0);
+    }
+
+    tmp = NULL;
+    rc = libxl__xs_read_checked(gc, XBT_NULL,
+				GCSPRINTF("%s/base", be_path), &tmp);
+    if (rc) goto out;
+
+    if (tmp) {

tools/libs/light/libxl_virtio.c line 100

Quoted 10 lines
tools/libs/light/libxl_virtio.c new file +10 -0
+        virtio->base = strtoul(tmp, NULL, 0);
+    }
+
+    tmp = NULL;
+    rc = libxl__xs_read_checked(gc, XBT_NULL,
+				GCSPRINTF("%s/transport", be_path), &tmp);
+    if (rc) goto out;
+
+    if (tmp) {
+        if (!strncmp(tmp, "mmio", strlen(tmp))) {

Maybe just use strcmp(), otherwise we have "m" going to be match as MMIO for example.

tools/libs/light/libxl_virtio.c line 103

Quoted 3 lines
tools/libs/light/libxl_virtio.c new file +3 -0
+            virtio->transport = LIBXL_VIRTIO_TRANSPORT_MMIO;
+        } else if (!strncmp(tmp, "unknown", strlen(tmp))) {
+            virtio->transport = LIBXL_VIRTIO_TRANSPORT_UNKNOWN;

I don't think that value should be allowed in xenstore. If transport isn't set to a proper value (only "mmio"), then I think that invalid.

tools/libs/light/libxl_virtio.c line 115

Quoted 12 lines
tools/libs/light/libxl_virtio.c new file +12 -0
+        } else {
+            return ERROR_INVAL;
+        }
+    }
+
+    tmp = NULL;
+    rc = libxl__xs_read_checked(gc, XBT_NULL,
+				GCSPRINTF("%s/type", be_path), &tmp);
+    if (rc) goto out;
+
+    if (tmp) {
+        if (!strncmp(tmp, "virtio,device", strlen("virtio,device"))) {

Nit: Something like:

    const char check[] = "virtio,device";
    const size_t checkl = sizeof(check) - 1;
    ... strncmp(tmp, check, checkl)...
    (or just strncmp(tmp, check, sizeof(check)-1))

would avoid issue with both string "virtio,device" potentially been different.

Quoted 1 line

+ virtio->type = strdup(tmp);

Could you use libxl__strdup(NO_GC, tmp) instead? That function is going to check that strdup() doesn't fail the allocation.

Thanks,

Signature · 1 line
Anthony PERARD
#3 lore raw

Re: [PATCH V7 1/3] libxl: Add support for generic virtio device

Quoted 7 lines · Anthony PERARD

Nit: Something like:

    const char check[] = "virtio,device";
    const size_t checkl = sizeof(check) - 1;
    ... strncmp(tmp, check, checkl)...
    (or just strncmp(tmp, check, sizeof(check)-1))

would avoid issue with both string "virtio,device" potentially been different.

I think that is a generic problem with all the strings I am using. What about this diff over current patch ?

tools/libs/light/libxl_arm.c +7 -10
index ab3668b3b8a3..292b31881210 100644
@@ -981,7 +981,7 @@ static int make_virtio_mmio_node_i2c(libxl__gc *gc, void *fdt)
     res = fdt_begin_node(fdt, "i2c");
     if (res) return res;
 
-    res = fdt_property_compat(gc, fdt, 1, "virtio,device22");
+    res = fdt_property_compat(gc, fdt, 1, VIRTIO_DEVICE_TYPE_I2C);
     if (res) return res;
 
     return fdt_end_node(fdt);
@@ -999,7 +999,7 @@ static int make_virtio_mmio_node_gpio(libxl__gc *gc, void *fdt)
     res = fdt_begin_node(fdt, "gpio");
     if (res) return res;
 
-    res = fdt_property_compat(gc, fdt, 1, "virtio,device29");
+    res = fdt_property_compat(gc, fdt, 1, VIRTIO_DEVICE_TYPE_GPIO);
     if (res) return res;
 
     res = fdt_property(fdt, "gpio-controller", NULL, 0);
@@ -1021,23 +1021,20 @@ static int make_virtio_mmio_node_device(libxl__gc *gc, void *fdt, uint64_t base,
                                         uint32_t irq, const char *type,
                                         uint32_t backend_domid)
 {
-    int res, len = strlen(type);
+    int res;
 
     res = make_virtio_mmio_node_common(gc, fdt, base, irq, backend_domid);
     if (res) return res;
 
     /* Add device specific nodes */
-    if (!strncmp(type, "virtio,device22", len)) {
+    if (!strcmp(type, VIRTIO_DEVICE_TYPE_I2C)) {
         res = make_virtio_mmio_node_i2c(gc, fdt);
         if (res) return res;
-    } else if (!strncmp(type, "virtio,device29", len)) {
+    } else if (!strcmp(type, VIRTIO_DEVICE_TYPE_GPIO)) {
         res = make_virtio_mmio_node_gpio(gc, fdt);
         if (res) return res;
-    } else if (!strncmp(type, "virtio,device", len)) {
-        /* Generic Virtio Device */
-        res = fdt_end_node(fdt);
-        if (res) return res;
-    } else {
+    } else if (strcmp(type, VIRTIO_DEVICE_TYPE_GENERIC)) {
+        /* Doesn't match generic virtio device */
         LOG(ERROR, "Invalid type for virtio device: %s", type);
         return -EINVAL;
     }
tools/libs/light/libxl_internal.h +5 -0
index cdd155d925c1..a062fca0e2bb 100644
@@ -166,6 +166,11 @@
 /* Convert pfn to physical address space. */
 #define pfn_to_paddr(x) ((uint64_t)(x) << XC_PAGE_SHIFT)
 
+/* Virtio device types */
+#define VIRTIO_DEVICE_TYPE_GENERIC   "virtio,device"
+#define VIRTIO_DEVICE_TYPE_GPIO      "virtio,device22"
+#define VIRTIO_DEVICE_TYPE_I2C       "virtio,device29"
+
 /* logging */
 _hidden void libxl__logv(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
              const char *file /* may be 0 */, int line /* ignored if !file */,
tools/libs/light/libxl_virtio.c +4 -6
index 64cec989c674..183d9c906e27 100644
@@ -62,7 +62,7 @@ static int libxl__virtio_from_xenstore(libxl__gc *gc, const char *libxl_path,
                                        libxl_device_virtio *virtio)
 {
     const char *be_path, *tmp = NULL;
-    int rc;
+    int rc, len = sizeof(VIRTIO_DEVICE_TYPE_GENERIC) - 1;
 
     virtio->devid = devid;
 
@@ -97,10 +97,8 @@ static int libxl__virtio_from_xenstore(libxl__gc *gc, const char *libxl_path,
     if (rc) goto out;
 
     if (tmp) {
-        if (!strncmp(tmp, "mmio", strlen(tmp))) {
+        if (!strcmp(tmp, "mmio")) {
             virtio->transport = LIBXL_VIRTIO_TRANSPORT_MMIO;
-        } else if (!strncmp(tmp, "unknown", strlen(tmp))) {
-            virtio->transport = LIBXL_VIRTIO_TRANSPORT_UNKNOWN;
         } else {
             return ERROR_INVAL;
         }
@@ -112,8 +110,8 @@ static int libxl__virtio_from_xenstore(libxl__gc *gc, const char *libxl_path,
     if (rc) goto out;
 
     if (tmp) {
-        if (!strncmp(tmp, "virtio,device", strlen("virtio,device"))) {
-            virtio->type = strdup(tmp);
+        if (!strncmp(tmp, VIRTIO_DEVICE_TYPE_GENERIC, len)) {
+            virtio->type = libxl__strdup(NOGC, tmp);
         } else {
             return ERROR_INVAL;
         }
Signature · 1 line
viresh
#4 lore raw

Re: [PATCH V7 1/3] libxl: Add support for generic virtio device

Quoted 17 lines · Viresh Kumar
Quoted 7 lines · Anthony PERARD

Nit: Something like:

    const char check[] = "virtio,device";
    const size_t checkl = sizeof(check) - 1;
    ... strncmp(tmp, check, checkl)...
    (or just strncmp(tmp, check, sizeof(check)-1))

would avoid issue with both string "virtio,device" potentially been different.

I think that is a generic problem with all the strings I am using. What about this diff over current patch ?

tools/libs/light/libxl_internal.h +0 -0
index cdd155d925c1..a062fca0e2bb 100644

tools/libs/light/libxl_internal.h line 172

Quoted 7 lines
tools/libs/light/libxl_internal.h +4 -0
@@ -166,6 +166,11 @@
 /* Convert pfn to physical address space. */
 #define pfn_to_paddr(x) ((uint64_t)(x) << XC_PAGE_SHIFT)
 
+/* Virtio device types */
+#define VIRTIO_DEVICE_TYPE_GENERIC   "virtio,device"
+#define VIRTIO_DEVICE_TYPE_GPIO      "virtio,device22"
+#define VIRTIO_DEVICE_TYPE_I2C       "virtio,device29"

That a good idea.

tools/libs/light/libxl_virtio.c static int libxl__virtio_from_xenstore(libxl__gc *gc, const char *libxl_path, · line 65

Quoted 13 lines
tools/libs/light/libxl_internal.h +0 -0
 /* logging */
 _hidden void libxl__logv(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
              const char *file /* may be 0 */, int line /* ignored if !file */,
tools/libs/light/libxl_virtio.c +1 -1
index 64cec989c674..183d9c906e27 100644
@@ -62,7 +62,7 @@ static int libxl__virtio_from_xenstore(libxl__gc *gc, const char *libxl_path,
                                        libxl_device_virtio *virtio)
 {
     const char *be_path, *tmp = NULL;
-    int rc;
+    int rc, len = sizeof(VIRTIO_DEVICE_TYPE_GENERIC) - 1;

That len variable is initialized quite far away from where it's used, so ...

tools/libs/light/libxl_virtio.c static int libxl__virtio_from_xenstore(libxl__gc *gc, const char *libxl_path, · line 112

Quoted 7 lines
tools/libs/light/libxl_virtio.c +0 -0
     virtio->devid = devid;
 
@@ -112,8 +110,8 @@ static int libxl__virtio_from_xenstore(libxl__gc *gc, const char *libxl_path,
     if (rc) goto out;
 
     if (tmp) {

... you could declare len here instead.

tools/libs/light/libxl_virtio.c static int libxl__virtio_from_xenstore(libxl__gc *gc, const char *libxl_path, · line 117

Quoted 8 lines
tools/libs/light/libxl_virtio.c +2 -2
-        if (!strncmp(tmp, "virtio,device", strlen("virtio,device"))) {
-            virtio->type = strdup(tmp);
+        if (!strncmp(tmp, VIRTIO_DEVICE_TYPE_GENERIC, len)) {
+            virtio->type = libxl__strdup(NOGC, tmp);
         } else {
             return ERROR_INVAL;
         }

Otherwise, those change looks fine.
Thanks,

Signature · 1 line
Anthony PERARD
#7 lore raw

Re: [PATCH V7 3/3] docs: Add documentation for generic virtio devices

In reply to Viresh Kumar

docs/man/xl.cfg.5.pod.in Set maximum height for pointer device. · line 1593

Quoted 6 lines · Viresh Kumar

+=item B<virtio=[ "VIRTIO_DEVICE_STRING", "VIRTIO_DEVICE_STRING", ...]>

docs/man/xl.cfg.5.pod.in +5 -0
+
+Specifies the Virtio devices to be provided to the guest.
+
+Each B<VIRTIO_DEVICE_STRING> is a comma-separated list of C<KEY=VALUE>
+settings from the following list:

We should probably say something about allowing a comma in the VALUE for "type" when the value starts with "virtio," as otherwise it might be confusing.

Quoted 9 lines
docs/man/xl.cfg.5.pod.in +9 -0
+
+=over 4
+
+=item B<backend=domain-id>
+
+Specifies the backend domain name or id, defaults to dom0.
+
+=item B<type=STRING>
+

docs/man/xl.cfg.5.pod.in Set maximum height for pointer device. · line 1612

Quoted 10 lines
docs/man/xl.cfg.5.pod.in +10 -0
+Specifies the compatible string for the specific Virtio device. The same will be
+written in the Device Tree compatible property of the Virtio device. For
+example, "type=virtio,device22" for the I2C device, whose device-tree binding is
+present here:
+
+L<https://www.kernel.org/doc/Documentation/devicetree/bindings/i2c/i2c-virtio.yaml>
+
+=item B<transport=STRING>
+
+Specifies the transport mechanism for the Virtio device, like "mmio" or "pci".

"pci" doesn't exist, only "mmio" is allowed here at the moment. We can change the man page later when new options become available.

Thanks,

Signature · 1 line
Anthony PERARD