Skip to content

Commit fb59288

Browse files
lulu-github-namemstsirkin
authored andcommitted
virtio-net: handle zero mac for a vdpa peer
Some mlx vdpa devices with kernels at least up to 5.11 currently present 0 as their MAC address. This is because they have not been pre-configured with a MAC: they have a learning bridge and only learn the MAC once guest is up. Kernel patches and tools to allow programming the MAC from host are being developed. For now - since these combinations exist in the field - let's detect zero mac and just try to proceed with the mac from the qemu command line. This makes the guest use this MAC to send packets in turn teaching the MAC to the card, and things work. TODO: report the actual MAC from QEMU commad line in the info message. TODO: detect that a (non-zero) hardware MAC does not match QEMU command line and fail init. Signed-off-by: Cindy Lu <[email protected]> Message-Id: <[email protected]> mst: rewritten code comments, message printed and the commit log. Cc: Eli Cohen <[email protected]> Cc: Parav Pandit <[email protected]> Tested-by: Adrian Moreno <[email protected]> Tested-by: Sean Mooney <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 0a343a5 commit fb59288

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

hw/net/virtio-net.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
126126
VirtIONet *n = VIRTIO_NET(vdev);
127127
struct virtio_net_config netcfg;
128128
NetClientState *nc = qemu_get_queue(n->nic);
129+
static const MACAddr zero = { .a = { 0, 0, 0, 0, 0, 0 } };
129130

130131
int ret = 0;
131132
memset(&netcfg, 0 , sizeof(struct virtio_net_config));
@@ -151,6 +152,17 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
151152
ret = vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg,
152153
n->config_size);
153154
if (ret != -1) {
155+
/*
156+
* Some NIC/kernel combinations present 0 as the mac address. As
157+
* that is not a legal address, try to proceed with the
158+
* address from the QEMU command line in the hope that the
159+
* address has been configured correctly elsewhere - just not
160+
* reported by the device.
161+
*/
162+
if (memcmp(&netcfg.mac, &zero, sizeof(zero)) == 0) {
163+
info_report("Zero hardware mac address detected. Ignoring.");
164+
memcpy(netcfg.mac, n->mac, ETH_ALEN);
165+
}
154166
memcpy(config, &netcfg, n->config_size);
155167
}
156168
}

0 commit comments

Comments
 (0)