]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/drivers/virtio: Fix virtio read write
authorXingjian Zhang <zhxj9823@qq.com>
Thu, 10 Aug 2023 12:01:46 +0000 (20:01 +0800)
committerUnikraft <monkey@unikraft.io>
Fri, 11 Aug 2023 06:01:43 +0000 (06:01 +0000)
Add support for variable length of virtio read and write. The original
error message is replaced by a warning message.

Two cases in virtio_net and virtio_9p uses this feature and the comments
are added to note the usage.

Signed-off-by: Xingjian Zhang <zhxj9823@qq.com>
Reviewed-by: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Approved-by: Michalis Pappas <michalis.unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #970

plat/drivers/virtio/virtio_9p.c
plat/drivers/virtio/virtio_mmio.c
plat/drivers/virtio/virtio_net.c

index b5135b89f44e22eb049823f4fdee5465a822079b..233cb9f575a354f4aaaef52fbeb6b920f38e9ba0 100644 (file)
@@ -356,7 +356,10 @@ static int virtio_9p_feature_negotiate(struct virtio_9p_device *d)
                goto out;
        }
 
-
+       /**
+        * The tag field read may result in unaligned read.
+        * Currently, unaligned read is supported in the underlying function.
+        */
        if (virtio_config_get(d->vdev,
                          __offsetof(struct virtio_9p_config, tag),
                          d->tag, tag_len, 1) < 0) {
index 98d7cce6d86add9a7013701fc038dc3c5deb12cb..66802f00472d028cb14749255b5387ece9055eca 100644 (file)
@@ -162,8 +162,8 @@ static int vm_get(struct virtio_dev *vdev, __u16 offset,
                memcpy(buf + sizeof(l), &l, sizeof(l));
                break;
        default:
-               uk_pr_err("Not supported length(%d) for io read\n", len);
-               UK_BUG();
+               _virtio_cread_bytes(base, offset, buf, len, 1);
+               uk_pr_warn("Unaligned io read: %d bytes\n", len);
        }
 
        return len;
@@ -207,8 +207,8 @@ static int vm_set(struct virtio_dev *vdev, __u16 offset,
                virtio_cwrite32(base, offset + sizeof(l), l);
                break;
        default:
-               uk_pr_err("Not supported length(%d) for io write\n", len);
-               UK_BUG();
+               _virtio_cwrite_bytes(base, offset, buf, len, 1);
+               uk_pr_warn("Unaligned io write: %d bytes\n", len);
        }
 
        return 0;
index e6e7082431c7268d80c54da7af27165c5790c6ec..fb0e6b4134776e7f944c24d1d8193415f069e77a 100644 (file)
@@ -934,6 +934,7 @@ static int virtio_netdev_feature_negotiate(struct uk_netdev *n)
         * reconsider providing generic read/write function for all these
         * virtio device in a separate header file which could be reused across
         * different virtio devices.
+        * Currently, unaligned read is supported in the underlying function.
         */
        virtio_config_get(vndev->vdev,
                                   __offsetof(struct virtio_net_config, mac),