Skip to content

Commit d8673af

Browse files
committed
Merge branch 'virtio_net-vdpa-update-mac-address-when-it-is-generated-by-virtio-net'
Laurent Vivier says: ==================== virtio_net: vdpa: update MAC address when it is generated by virtio-net When the MAC address is not provided by the vdpa device virtio_net driver assigns a random one without notifying the device. The consequence, in the case of mlx5_vdpa, is the internal routing tables of the device are not updated and this can block the communication between two namespaces. To fix this problem, use virtnet_send_command(VIRTIO_NET_CTRL_MAC) to set the address from virtnet_probe() when the MAC address is not provided by the device. ==================== Link: https://lore.kernel.org/r/20230127204500.51930-1-lvivier@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents ca3daf4 + 9f62d22 commit d8673af

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

drivers/net/virtio_net.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3813,6 +3813,12 @@ static int virtnet_validate(struct virtio_device *vdev)
38133813
__virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);
38143814
}
38153815

3816+
if (virtio_has_feature(vdev, VIRTIO_NET_F_STANDBY) &&
3817+
!virtio_has_feature(vdev, VIRTIO_NET_F_MAC)) {
3818+
dev_warn(&vdev->dev, "device advertises feature VIRTIO_NET_F_STANDBY but not VIRTIO_NET_F_MAC, disabling standby");
3819+
__virtio_clear_bit(vdev, VIRTIO_NET_F_STANDBY);
3820+
}
3821+
38163822
return 0;
38173823
}
38183824

@@ -3925,6 +3931,8 @@ static int virtnet_probe(struct virtio_device *vdev)
39253931
eth_hw_addr_set(dev, addr);
39263932
} else {
39273933
eth_hw_addr_random(dev);
3934+
dev_info(&vdev->dev, "Assigned random MAC address %pM\n",
3935+
dev->dev_addr);
39283936
}
39293937

39303938
/* Set up our device-specific information */
@@ -4052,6 +4060,24 @@ static int virtnet_probe(struct virtio_device *vdev)
40524060

40534061
virtio_device_ready(vdev);
40544062

4063+
/* a random MAC address has been assigned, notify the device.
4064+
* We don't fail probe if VIRTIO_NET_F_CTRL_MAC_ADDR is not there
4065+
* because many devices work fine without getting MAC explicitly
4066+
*/
4067+
if (!virtio_has_feature(vdev, VIRTIO_NET_F_MAC) &&
4068+
virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_MAC_ADDR)) {
4069+
struct scatterlist sg;
4070+
4071+
sg_init_one(&sg, dev->dev_addr, dev->addr_len);
4072+
if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC,
4073+
VIRTIO_NET_CTRL_MAC_ADDR_SET, &sg)) {
4074+
pr_debug("virtio_net: setting MAC address failed\n");
4075+
rtnl_unlock();
4076+
err = -EINVAL;
4077+
goto free_unregister_netdev;
4078+
}
4079+
}
4080+
40554081
rtnl_unlock();
40564082

40574083
err = virtnet_cpu_notif_add(vi);

0 commit comments

Comments
 (0)