Skip to contentSkip to conversation

vdpa: Allow VDPA to work on big-endian machine

PATCH In review Konstantin Shkolnyy 4 participants 4 messages Jun 14, 2025 – Jun 16, 2025 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vdpa: Allow VDPA to work on big-endian machine

After commit 0caed25cd171 vhost_vdpa_net_load_vlan() started seeing VIRTIO_NET_F_CTRL_VLAN flag and making 4096 calls to the kernel with VIRTIO_NET_CTRL_VLAN_ADD command. However, it forgot to convert the 16-bit VLAN IDs to LE format. On BE machine, the kernel calls failed when they saw "VLAN IDs" greater than 4095, and QEMU then said:
"unable to start vhost net: 5: falling back on userspace virtio", and VDPA became disabled.

Convert the VLAN ID to LE before putting it into virtio queue.

---
 net/vhost-vdpa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/vhost-vdpa.c +3 -2
index 58d738945d..99c9eb42b9 100644
@@ -1173,9 +1173,10 @@ static int vhost_vdpa_net_load_single_vlan(VhostVDPAState *s,
                                            struct iovec *in_cursor,
                                            uint16_t vid)
 {
+    __le16 vid_le = cpu_to_le16(vid);
     const struct iovec data = {
-        .iov_base = &vid,
-        .iov_len = sizeof(vid),
+        .iov_base = &vid_le,
+        .iov_len = sizeof(vid_le),
     };
     ssize_t r = vhost_vdpa_net_load_cmd(s, out_cursor, in_cursor,
                                         VIRTIO_NET_CTRL_VLAN,
Signature · 1 line
2.34.1
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Konstantin Shkolnyy

After commit 0caed25cd171 vhost_vdpa_net_load_vlan() started seeing VIRTIO_NET_F_CTRL_VLAN flag and making 4096 calls to the kernel with VIRTIO_NET_CTRL_VLAN_ADD command. However, it forgot to convert the 16-bit VLAN IDs to LE format. On BE machine, the kernel calls failed when they saw "VLAN IDs" greater than 4095, and QEMU then said:
"unable to start vhost net: 5: falling back on userspace virtio", and VDPA became disabled.

Quoted 4 lines

Convert the VLAN ID to LE before putting it into virtio queue.

---

Thanks

Acked-by on v1 1/1
#2 lore raw
In reply to Konstantin Shkolnyy
Quoted 9 lines · Konstantin Shkolnyy

After commit 0caed25cd171 vhost_vdpa_net_load_vlan() started seeing VIRTIO_NET_F_CTRL_VLAN flag and making 4096 calls to the kernel with VIRTIO_NET_CTRL_VLAN_ADD command. However, it forgot to convert the 16-bit VLAN IDs to LE format. On BE machine, the kernel calls failed when they saw "VLAN IDs" greater than 4095, and QEMU then said:
"unable to start vhost net: 5: falling back on userspace virtio", and VDPA became disabled.

Quoted 3 lines

Convert the VLAN ID to LE before putting it into virtio queue.

Good catch! You should add the Fixes: tag though :). With that,

Quoted 25 lines
---
 net/vhost-vdpa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/vhost-vdpa.c +3 -3
index 58d738945d..99c9eb42b9 100644
@@ -1173,9 +1173,10 @@ static int vhost_vdpa_net_load_single_vlan(VhostVDPAState *s,
                                            struct iovec *in_cursor,
                                            uint16_t vid)
 {
+    __le16 vid_le = cpu_to_le16(vid);
     const struct iovec data = {
-        .iov_base = &vid,
-        .iov_len = sizeof(vid),
+        .iov_base = &vid_le,
+        .iov_len = sizeof(vid_le),
     };
     ssize_t r = vhost_vdpa_net_load_cmd(s, out_cursor, in_cursor,
                                         VIRTIO_NET_CTRL_VLAN,
--

2.34.1

#3 lore raw
In reply to Konstantin Shkolnyy
Quoted 7 lines · Konstantin Shkolnyy

After commit 0caed25cd171 vhost_vdpa_net_load_vlan() started seeing VIRTIO_NET_F_CTRL_VLAN flag and making 4096 calls to the kernel with VIRTIO_NET_CTRL_VLAN_ADD command. However, it forgot to convert the 16-bit VLAN IDs to LE format. On BE machine, the kernel calls failed when they saw "VLAN IDs" greater than 4095, and QEMU then said:
"unable to start vhost net: 5: falling back on userspace virtio", and VDPA became disabled.

Please add the Fixes: tag to refer the commit; see:
docs/devel/submitting-a-patch.rst

Quoted 13 lines

Convert the VLAN ID to LE before putting it into virtio queue.

---
  net/vhost-vdpa.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
net/vhost-vdpa.c +0 -0
index 58d738945d..99c9eb42b9 100644

net/vhost-vdpa.c static int vhost_vdpa_net_load_single_vlan(VhostVDPAState *s, · line 1176

Quoted 4 lines
net/vhost-vdpa.c +1 -0
@@ -1173,9 +1173,10 @@ static int vhost_vdpa_net_load_single_vlan(VhostVDPAState *s,
                                             struct iovec *in_cursor,
                                             uint16_t vid)
  {
+    __le16 vid_le = cpu_to_le16(vid);

docs/devel/style.rst says:

Quoted 1 line

Don't use Linux kernel internal types like u32, __u32 or __le32.

It's unfortunate that QEMU lacks endian types and a checker for them; such a checker could not have caught this particular case, but can catch other similar bugs.

Regards,
Akihiko Odaki

Quoted 8 lines
      const struct iovec data = {
net/vhost-vdpa.c +2 -2
-        .iov_base = &vid,
-        .iov_len = sizeof(vid),
+        .iov_base = &vid_le,
+        .iov_len = sizeof(vid_le),
      };
      ssize_t r = vhost_vdpa_net_load_cmd(s, out_cursor, in_cursor,
                                          VIRTIO_NET_CTRL_VLAN,