[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211027113033-mutt-send-email-mst@kernel.org>
Date: Wed, 27 Oct 2021 11:30:59 -0400
From: "Michael S. Tsirkin" <mst@...hat.com>
To: Jakub Kicinski <kuba@...nel.org>
Cc: davem@...emloft.net, netdev@...r.kernel.org, jasowang@...hat.com,
virtualization@...ts.linux-foundation.org
Subject: Re: [PATCH net-next v2] net: virtio: use eth_hw_addr_set()
On Wed, Oct 27, 2021 at 08:20:12AM -0700, Jakub Kicinski wrote:
> Commit 406f42fa0d3c ("net-next: When a bond have a massive amount
> of VLANs...") introduced a rbtree for faster Ethernet address look
> up. To maintain netdev->dev_addr in this tree we need to make all
> the writes to it go through appropriate helpers.
>
> Even though the current code uses dev->addr_len the we can switch
> to eth_hw_addr_set() instead of dev_addr_set(). The netdev is
> always allocated by alloc_etherdev_mq() and there are at least two
> places which assume Ethernet address:
> - the line below calling eth_hw_addr_random()
> - virtnet_set_mac_address() -> eth_commit_mac_addr_change()
>
> Signed-off-by: Jakub Kicinski <kuba@...nel.org>
Acked-by: Michael S. Tsirkin <mst@...hat.com>
> ---
> v2: - actually switch to eth_hw_addr_set() not dev_addr_set()
> - resize the buffer to ETH_ALEN
> - pass ETH_ALEN instead of dev->dev_addr to virtio_cread_bytes()
>
> CC: mst@...hat.com
> CC: jasowang@...hat.com
> CC: virtualization@...ts.linux-foundation.org
> ---
> drivers/net/virtio_net.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index c501b5974aee..cc79343cd220 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -3177,12 +3177,16 @@ static int virtnet_probe(struct virtio_device *vdev)
> dev->max_mtu = MAX_MTU;
>
> /* Configuration may specify what MAC to use. Otherwise random. */
> - if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC))
> + if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC)) {
> + u8 addr[ETH_ALEN];
> +
> virtio_cread_bytes(vdev,
> offsetof(struct virtio_net_config, mac),
> - dev->dev_addr, dev->addr_len);
> - else
> + addr, ETH_ALEN);
> + eth_hw_addr_set(dev, addr);
> + } else {
> eth_hw_addr_random(dev);
> + }
>
> /* Set up our device-specific information */
> vi = netdev_priv(dev);
> --
> 2.31.1
Powered by blists - more mailing lists