Skip to content

Commit 486b0d2

Browse files
author
Herton R. Krzesinski
committed
Merge: virtio_net: notify MAC address change on device initialization
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2037 # Merge Request Required Information Bugzilla: https://bugzilla.redhat.com/2153210 Tested: by QE Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=50667660 Upstream: git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git In maintainer's branch, not yet merged in master ## Summary of Changes Update virtio-net driver to forward MAC address change to the backend, in our case vdpa. The bug has been found with mlx5_vdpa driver. The first patch is needed to add the netlink lock around the virtnet_send_command() call. Signed-off-by: Laurent Vivier <lvivier@redhat.com> Approved-by: Eugenio Pérez <eperezma@redhat.com> Approved-by: Cindy Lu <lulu@redhat.com> Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2 parents af08f54 + 856b600 commit 486b0d2

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

drivers/net/virtio_net.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3100,6 +3100,12 @@ static int virtnet_validate(struct virtio_device *vdev)
31003100
__virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);
31013101
}
31023102

3103+
if (virtio_has_feature(vdev, VIRTIO_NET_F_STANDBY) &&
3104+
!virtio_has_feature(vdev, VIRTIO_NET_F_MAC)) {
3105+
dev_warn(&vdev->dev, "device advertises feature VIRTIO_NET_F_STANDBY but not VIRTIO_NET_F_MAC, disabling standby");
3106+
__virtio_clear_bit(vdev, VIRTIO_NET_F_STANDBY);
3107+
}
3108+
31033109
return 0;
31043110
}
31053111

@@ -3180,8 +3186,11 @@ static int virtnet_probe(struct virtio_device *vdev)
31803186
virtio_cread_bytes(vdev,
31813187
offsetof(struct virtio_net_config, mac),
31823188
dev->dev_addr, dev->addr_len);
3183-
else
3189+
else {
31843190
eth_hw_addr_random(dev);
3191+
dev_info(&vdev->dev, "Assigned random MAC address %pM\n",
3192+
dev->dev_addr);
3193+
}
31853194

31863195
/* Set up our device-specific information */
31873196
vi = netdev_priv(dev);
@@ -3269,14 +3278,38 @@ static int virtnet_probe(struct virtio_device *vdev)
32693278
}
32703279
}
32713280

3272-
err = register_netdev(dev);
3281+
/* serialize netdev register + virtio_device_ready() with ndo_open() */
3282+
rtnl_lock();
3283+
3284+
err = register_netdevice(dev);
32733285
if (err) {
32743286
pr_debug("virtio_net: registering device failed\n");
3287+
rtnl_unlock();
32753288
goto free_failover;
32763289
}
32773290

32783291
virtio_device_ready(vdev);
32793292

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+
3311+
rtnl_unlock();
3312+
32803313
err = virtnet_cpu_notif_add(vi);
32813314
if (err) {
32823315
pr_debug("virtio_net: registering cpu notifier failed\n");

0 commit comments

Comments
 (0)