virtio-net vs qemu 1.5.0

Julian Stecklina jsteckli at os.inf.tu-dresden.de
Thu May 23 12:05:05 UTC 2013


Hello,

I just compiled qemu 1.5.0 and noticed that virtio network (on CURRENT as of today) seems to have problems updating the MAC filter table:

vtnet0: error setting host MAC filter table

As far as I understand, if_vtnet.c does the following in vtnet_rx_filter_mac. It appends two full struct vtnet_mac_tables (one for unicast and one for multicast) to the request. Each consists of the number of actual entries in the table and space for 128 (mostly unused) entries in total.

The qemu code parses this differently. It first reads the number of elements in the first table and then skips over so many MAC addresses and then expects the header to the second table (which in our case points to zero'd memory). Then it skips those 0 MAC entries as well and expects that it has consumed the whole request and returns an error, because there is still data left. The relevant code is in qemu/hw/net/virtio-net.c in virtio_net_handle_rx_mode.

Assuming the qemu code is correct (of which I am not sure) the correct solution would be to enqueue only so many MACs in the original requests as are actually used. The following (a bit dirty) patch fixes this for me:


diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c
index ffc349a..6f00dfb 100644
--- a/sys/dev/virtio/network/if_vtnet.c
+++ b/sys/dev/virtio/network/if_vtnet.c
@@ -2470,9 +2470,9 @@ vtnet_rx_filter_mac(struct vtnet_softc *sc)
        sglist_init(&sg, 4, segs);
        error |= sglist_append(&sg, &hdr, sizeof(struct virtio_net_ctrl_hdr));
        error |= sglist_append(&sg, &filter->vmf_unicast,
-           sizeof(struct vtnet_mac_table));
+           sizeof(uint32_t) + ETHER_ADDR_LEN*filter->vmf_unicast.nentries);
        error |= sglist_append(&sg, &filter->vmf_multicast,
-           sizeof(struct vtnet_mac_table));
+           sizeof(uint32_t) + ETHER_ADDR_LEN*filter->vmf_multicast.nentries);
        error |= sglist_append(&sg, &ack, sizeof(uint8_t));
        KASSERT(error == 0 && sg.sg_nseg == 4,
            ("error adding MAC filtering message to sglist"));

Any virtio guru here to comment on this?

Julian



More information about the freebsd-virtualization mailing list