Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+26
+26
drivers/net/virtio_net.c
··· 3813 3813 __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU); 3814 3814 } 3815 3815 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 + 3816 3822 return 0; 3817 3823 } 3818 3824 ··· 3931 3925 eth_hw_addr_set(dev, addr); 3932 3926 } else { 3933 3927 eth_hw_addr_random(dev); 3928 + dev_info(&vdev->dev, "Assigned random MAC address %pM\n", 3929 + dev->dev_addr); 3934 3930 } 3935 3931 3936 3932 /* Set up our device-specific information */ ··· 4059 4051 } 4060 4052 4061 4053 virtio_device_ready(vdev); 4054 + 4055 + /* a random MAC address has been assigned, notify the device. 4056 + * We don't fail probe if VIRTIO_NET_F_CTRL_MAC_ADDR is not there 4057 + * because many devices work fine without getting MAC explicitly 4058 + */ 4059 + if (!virtio_has_feature(vdev, VIRTIO_NET_F_MAC) && 4060 + virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_MAC_ADDR)) { 4061 + struct scatterlist sg; 4062 + 4063 + sg_init_one(&sg, dev->dev_addr, dev->addr_len); 4064 + if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC, 4065 + VIRTIO_NET_CTRL_MAC_ADDR_SET, &sg)) { 4066 + pr_debug("virtio_net: setting MAC address failed\n"); 4067 + rtnl_unlock(); 4068 + err = -EINVAL; 4069 + goto free_unregister_netdev; 4070 + } 4071 + } 4062 4072 4063 4073 rtnl_unlock(); 4064 4074