Skip to contentSkip to conversation

net: virtio: use eth_hw_addr_set()

PATCH Applied Jakub Kicinski 4 participants 4 messages Oct 27, 2021 – Oct 28, 2021

Subsystems (4)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH v2 1/1 net: virtio: use eth_hw_addr_set()

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()

---
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()

---
 drivers/net/virtio_net.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +7 -3
index c501b5974aee..cc79343cd220 100644
@@ -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);
Signature · 1 line
2.31.1
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 5 lines · Jakub Kicinski

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.

Quoted 8 lines

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()

Quoted 38 lines

---
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()

---
 drivers/net/virtio_net.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +7 -3
index c501b5974aee..cc79343cd220 100644
@@ -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);
Signature · 1 line
2.31.1
Acked-by
#2 lore raw
Quoted 14 lines · Michael S. Tsirkin
Quoted 12 lines · Jakub Kicinski

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()

Quoted 3 lines
Quoted 1 line
Quoted 40 lines
Quoted 39 lines

---
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()

---
 drivers/net/virtio_net.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +7 -4
index c501b5974aee..cc79343cd220 100644
@@ -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

#3 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 5 lines · On Wed, 27 Oct 2021 08:20:12 -0700 you 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.

Quoted 8 lines

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()

[...]

Here is the summary with links:
- [net-next,v2] net: virtio: use eth_hw_addr_set()

    https://git.kernel.org/netdev/net-next/c/f2edaa4ad5d5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html