Skip to contentSkip to conversation

libxl: fix matching of generic virtio device

PATCH In review Viresh Kumar 2 participants 2 messages Mar 30, 2023 – Apr 4, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: fix matching of generic virtio device

The strings won't be an exact match, and we are only looking to match the prefix here, i.e. "virtio,device". This is already done properly in libxl_virtio.c file, lets do the same here too.

---
 tools/libs/light/libxl_arm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
tools/libs/light/libxl_arm.c +8 -4
index ddc7b2a15975..97c80d7ed0fa 100644
@@ -1033,10 +1033,14 @@ static int make_virtio_mmio_node_device(libxl__gc *gc, void *fdt, uint64_t base,
     } else if (!strcmp(type, VIRTIO_DEVICE_TYPE_GPIO)) {
         res = make_virtio_mmio_node_gpio(gc, fdt);
         if (res) return res;
-    } 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;
+    } else {
+        int len = sizeof(VIRTIO_DEVICE_TYPE_GENERIC) - 1;
+
+        if (strncmp(type, VIRTIO_DEVICE_TYPE_GENERIC, len)) {
+            /* Doesn't match generic virtio device */
+            LOG(ERROR, "Invalid type for virtio device: %s", type);
+            return -EINVAL;
+        }
     }
 
     return fdt_end_node(fdt);
Signature · 1 line
2.31.1.272.g89b43f80a514
#1 lore raw

On 30.03.23 10:35, Viresh Kumar wrote:

Hello Viresh

Quoted 5 lines

The strings won't be an exact match, and we are only looking to match the prefix here, i.e. "virtio,device". This is already done properly in libxl_virtio.c file, lets do the same here too.

It feels to me this patch wants to gain the following tag:

Fixes 43ba5202e2ee ("libxl: add support for generic virtio device")
Quoted 14 lines
---
  tools/libs/light/libxl_arm.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
tools/libs/light/libxl_arm.c +0 -2
index ddc7b2a15975..97c80d7ed0fa 100644
@@ -1033,10 +1033,14 @@ static int make_virtio_mmio_node_device(libxl__gc *gc, void *fdt, uint64_t base,
      } else if (!strcmp(type, VIRTIO_DEVICE_TYPE_GPIO)) {
          res = make_virtio_mmio_node_gpio(gc, fdt);
          if (res) return res;
-    } else if (strcmp(type, VIRTIO_DEVICE_TYPE_GENERIC)) {
-        /* Doesn't match generic virtio device */

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

Quoted 10 lines
tools/libs/light/libxl_arm.c +8 -2
-        LOG(ERROR, "Invalid type for virtio device: %s", type);
-        return -EINVAL;
+    } else {
+        int len = sizeof(VIRTIO_DEVICE_TYPE_GENERIC) - 1;
+
+        if (strncmp(type, VIRTIO_DEVICE_TYPE_GENERIC, len)) {
+            /* Doesn't match generic virtio device */
+            LOG(ERROR, "Invalid type for virtio device: %s", type);
+            return -EINVAL;
+        }

I agree that now code is aligned with what we have in libxl_virtio.c file, but I am afraid I cannot connect the sentence from the commit description:
"The strings won't be an exact match, and we are only looking to match
the prefix here, i.e. "virtio,device"."

with the sentence from docs/man/xl.cfg.5.pod.in:

"For generic virtio devices, where we don't need to set special or compatible properties in the Device Tree, the type field must be set to "virtio,device"."

I might miss something, but shouldn't we clarify the documentation?

Quoted 3 lines
tools/libs/light/libxl_arm.c +0 -0
      }
 
      return fdt_end_node(fdt);