Skip to contentSkip to conversation

virtio-net: count VIRTIO_NET_F_MAC when calculating config_len

PATCH Applied Jason Wang 3 participants 3 messages Apr 25, 2013 – May 2, 2013

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH v2 1/1 virtio-net: count VIRTIO_NET_F_MAC when calculating config_len

Commit 14f9b664 (hw/virtio-net.c: set config size using host features) tries to calculate config size based on the host features. But it forgets the VIRTIO_NET_F_MAC were always set for qemu later. This will lead a zero config len for virtio-net device when both VIRTIO_NET_F_STATUS and VIRTIO_NET_F_MQ were disabled form command line. Then qemu will crash when user tries to read the config of virtio-net.

Fix this by counting VIRTIO_NET_F_MAC and make sure the config at least contains the mac address.

---
Changes from V1:
- Set VIRTIO_NET_F_MAC bit in host_features instead of initializing config_size

---
 hw/net/virtio-net.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/net/virtio-net.c +1 -0
index 1662f46..d4533d5 100644
@@ -1266,6 +1266,7 @@ static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx,
 void virtio_net_set_config_size(VirtIONet *n, uint32_t host_features)
 {
     int i, config_size = 0;
+    host_features |= (1 << VIRTIO_NET_F_MAC);
     for (i = 0; feature_sizes[i].flags != 0; i++) {
         if (host_features & feature_sizes[i].flags) {
             config_size = MAX(feature_sizes[i].end, config_size);
Signature · 1 line
1.7.1
Acked-by Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Jason Wang

Commit 14f9b664 (hw/virtio-net.c: set config size using host features) tries to calculate config size based on the host features. But it forgets the VIRTIO_NET_F_MAC were always set for qemu later. This will lead a zero config len for virtio-net device when both VIRTIO_NET_F_STATUS and VIRTIO_NET_F_MQ were disabled form command line. Then qemu will crash when user tries to read the config of virtio-net.

Quoted 5 lines

Fix this by counting VIRTIO_NET_F_MAC and make sure the config at least contains the mac address.

Not sure which tag is needed anymore ...
Anthony, pick this up for 1.5?

Quoted 21 lines

---
Changes from V1:
- Set VIRTIO_NET_F_MAC bit in host_features instead of initializing config_size

---
 hw/net/virtio-net.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/net/virtio-net.c +1 -0
index 1662f46..d4533d5 100644
@@ -1266,6 +1266,7 @@ static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx,
 void virtio_net_set_config_size(VirtIONet *n, uint32_t host_features)
 {
     int i, config_size = 0;
+    host_features |= (1 << VIRTIO_NET_F_MAC);
     for (i = 0; feature_sizes[i].flags != 0; i++) {
         if (host_features & feature_sizes[i].flags) {
             config_size = MAX(feature_sizes[i].end, config_size);
Signature · 1 line
1.7.1