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 <lulu@redhat.com>
Message-Id: <20210225165506.18321-2-lulu@redhat.com>

mst: rewritten code comments, message printed and the commit log.

Cc: Eli Cohen <elic@nvidia.com>
Cc: Parav Pandit <parav@nvidia.com>
Tested-by: Adrian Moreno <amorenoz@redhat.com>
Tested-by: Sean Mooney <smooney@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Cindy Lu 2021-02-26 00:55:06 +08:00 committed by Michael S. Tsirkin
parent 0a343a5add
commit fb59288239

View File

@ -126,6 +126,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
VirtIONet *n = VIRTIO_NET(vdev);
struct virtio_net_config netcfg;
NetClientState *nc = qemu_get_queue(n->nic);
static const MACAddr zero = { .a = { 0, 0, 0, 0, 0, 0 } };
int ret = 0;
memset(&netcfg, 0 , sizeof(struct virtio_net_config));
@ -151,6 +152,17 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
ret = vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg,
n->config_size);
if (ret != -1) {
/*
* Some NIC/kernel combinations present 0 as the mac address. As
* that is not a legal address, try to proceed with the
* address from the QEMU command line in the hope that the
* address has been configured correctly elsewhere - just not
* reported by the device.
*/
if (memcmp(&netcfg.mac, &zero, sizeof(zero)) == 0) {
info_report("Zero hardware mac address detected. Ignoring.");
memcpy(netcfg.mac, n->mac, ETH_ALEN);
}
memcpy(config, &netcfg, n->config_size);
}
}