Skip to content

Commit 856b600

Browse files
committed
virtio_net: notify MAC address change on device initialization
Bugzilla: http://bugzilla.redhat.com/2153210 commit 9f62d22 Author: Laurent Vivier <lvivier@redhat.com> Date: Fri Jan 27 21:45:00 2023 +0100 virtio_net: notify MAC address change on device initialization In virtnet_probe(), if the device doesn't provide a MAC address the driver assigns a random one. As we modify the MAC address we need to notify the device to allow it to update all the related information. The problem can be seen with vDPA and mlx5_vdpa driver as it doesn't assign a MAC address by default. The virtio_net device uses a random MAC address (we can see it with "ip link"), but we can't ping a net namespace from another one using the virtio-vdpa device because the new MAC address has not been provided to the hardware: RX packets are dropped since they don't go through the receive filters, TX packets go through unaffected. Signed-off-by: Laurent Vivier <lvivier@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Conflict in the context because of missing commit: f2edaa4 ("net: virtio: use eth_hw_addr_set()") Signed-off-by: Laurent Vivier <lvivier@redhat.com>
1 parent a643a29 commit 856b600

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

drivers/net/virtio_net.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3186,8 +3186,11 @@ static int virtnet_probe(struct virtio_device *vdev)
31863186
virtio_cread_bytes(vdev,
31873187
offsetof(struct virtio_net_config, mac),
31883188
dev->dev_addr, dev->addr_len);
3189-
else
3189+
else {
31903190
eth_hw_addr_random(dev);
3191+
dev_info(&vdev->dev, "Assigned random MAC address %pM\n",
3192+
dev->dev_addr);
3193+
}
31913194

31923195
/* Set up our device-specific information */
31933196
vi = netdev_priv(dev);
@@ -3287,6 +3290,24 @@ static int virtnet_probe(struct virtio_device *vdev)
32873290

32883291
virtio_device_ready(vdev);
32893292

3293+
/* a random MAC address has been assigned, notify the device.
3294+
* We don't fail probe if VIRTIO_NET_F_CTRL_MAC_ADDR is not there
3295+
* because many devices work fine without getting MAC explicitly
3296+
*/
3297+
if (!virtio_has_feature(vdev, VIRTIO_NET_F_MAC) &&
3298+
virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_MAC_ADDR)) {
3299+
struct scatterlist sg;
3300+
3301+
sg_init_one(&sg, dev->dev_addr, dev->addr_len);
3302+
if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC,
3303+
VIRTIO_NET_CTRL_MAC_ADDR_SET, &sg)) {
3304+
pr_debug("virtio_net: setting MAC address failed\n");
3305+
rtnl_unlock();
3306+
err = -EINVAL;
3307+
goto free_unregister_netdev;
3308+
}
3309+
}
3310+
32903311
rtnl_unlock();
32913312

32923313
err = virtnet_cpu_notif_add(vi);

0 commit comments

Comments
 (0)