Windows drivers from 22 Jan 2013 and older fail when config size != 32, which was the size before max_virtqueue_pairs was added. Force config size to a value these drivers expect to avoid breakage unless we really need max_virtqueue_pairs.
Signed-off-by: Michael S. Tsirkin <m...@redhat.com> --- hw/virtio-net.c | 15 ++++++++++++--- hw/virtio-net.h | 6 +++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index 510a0f6..2464cd5 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -1287,9 +1287,18 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf, { VirtIONet *n; int i; - - n = (VirtIONet *)virtio_common_init("virtio-net", VIRTIO_ID_NET, - sizeof(struct virtio_net_config), + size_t config_size; + + /* + * Windows drivers from 22 Jan 2013 and older fail when config size != 32, + * which was the size before max_virtqueue_pairs was added. + * Force config size to a value these drivers expect to avoid + * breakage unless we really need max_virtqueue_pairs. + */ + config_size = conf->queues > 1 ? sizeof(struct virtio_net_config) : + offsetof(struct virtio_net_config, max_virtqueue_pairs); + + n = (VirtIONet *)virtio_common_init("virtio-net", VIRTIO_ID_NET, config_size, sizeof(VirtIONet)); n->vdev.get_config = virtio_net_get_config; diff --git a/hw/virtio-net.h b/hw/virtio-net.h index 414365d..799b2ca 100644 --- a/hw/virtio-net.h +++ b/hw/virtio-net.h @@ -75,7 +75,11 @@ struct virtio_net_config uint8_t mac[ETH_ALEN]; /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */ uint16_t status; - /* Max virtqueue pairs supported by the device */ + /* + * Fields below need special handling because of driver bugs. + * See virtio_net_init. + * Max virtqueue pairs supported by the device. + */ uint16_t max_virtqueue_pairs; } QEMU_PACKED; -- MST