net: virtio: use eth_hw_addr_set()
Subsystems (4)
Jakub Kicinski
maintainerPATCH 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
@@ -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
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 maintainnetdev->dev_addrin 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_lenthe we can switch toeth_hw_addr_set()instead ofdev_addr_set(). The netdev is always allocated byalloc_etherdev_mq()and there are at least two places which assume Ethernet address:
- the line below callingeth_hw_addr_random()
-virtnet_set_mac_address()->eth_commit_mac_addr_change()Signed-off-by Jakub Kicinski <[email protected]>
Quoted 38 lines
---
v2: - actually switch toeth_hw_addr_set()notdev_addr_set()
- resize the buffer toETH_ALEN
- passETH_ALENinstead ofdev->dev_addrtovirtio_cread_bytes()--- drivers/net/virtio_net.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/net/virtio_net.c +7
-3@@ -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
Jason Wang
Acked-byQuoted 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 maintainnetdev->dev_addrin this tree we need to make all the writes to it go through appropriate helpers.Even though the current code uses
dev->addr_lenthe we can switch toeth_hw_addr_set()instead ofdev_addr_set(). The netdev is always allocated byalloc_etherdev_mq()and there are at least two places which assume Ethernet address:
- the line below callingeth_hw_addr_random()
-virtnet_set_mac_address()->eth_commit_mac_addr_change()
Quoted 3 lines
Quoted 1 line
Signed-off-by Jakub Kicinski <[email protected]>
Quoted 40 lines
Quoted 39 lines
---
v2: - actually switch toeth_hw_addr_set()notdev_addr_set()
- resize the buffer toETH_ALEN
- passETH_ALENinstead ofdev->dev_addrtovirtio_cread_bytes()--- drivers/net/virtio_net.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/net/virtio_net.c +7
-4@@ -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
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 maintainnetdev->dev_addrin 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_lenthe we can switch toeth_hw_addr_set()instead ofdev_addr_set(). The netdev is always allocated byalloc_etherdev_mq()and there are at least two places which assume Ethernet address:
- the line below callingeth_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