All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v2] net: virtio: use eth_hw_addr_set()
@ 2021-10-27 15:20 Jakub Kicinski
  2021-10-27 15:30   ` Michael S. Tsirkin
  2021-10-28 15:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 6+ messages in thread
From: Jakub Kicinski @ 2021-10-27 15:20 UTC (permalink / raw)
  To: davem; +Cc: netdev, Jakub Kicinski, mst, jasowang, virtualization

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@kernel.org>
---
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@redhat.com
CC: jasowang@redhat.com
CC: virtualization@lists.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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2] net: virtio: use eth_hw_addr_set()
  2021-10-27 15:20 [PATCH net-next v2] net: virtio: use eth_hw_addr_set() Jakub Kicinski
@ 2021-10-27 15:30   ` Michael S. Tsirkin
  2021-10-28 15:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2021-10-27 15:30 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: davem, netdev, jasowang, virtualization

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@kernel.org>

Acked-by: Michael S. Tsirkin <mst@redhat.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@redhat.com
> CC: jasowang@redhat.com
> CC: virtualization@lists.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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2] net: virtio: use eth_hw_addr_set()
@ 2021-10-27 15:30   ` Michael S. Tsirkin
  0 siblings, 0 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2021-10-27 15:30 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: netdev, davem, virtualization

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@kernel.org>

Acked-by: Michael S. Tsirkin <mst@redhat.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@redhat.com
> CC: jasowang@redhat.com
> CC: virtualization@lists.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

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2] net: virtio: use eth_hw_addr_set()
  2021-10-27 15:30   ` Michael S. Tsirkin
@ 2021-10-28  2:30     ` Jason Wang
  -1 siblings, 0 replies; 6+ messages in thread
From: Jason Wang @ 2021-10-28  2:30 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Jakub Kicinski, davem, netdev, virtualization

On Wed, Oct 27, 2021 at 11:31 PM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> 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@kernel.org>
>
> Acked-by: Michael S. Tsirkin <mst@redhat.com>

Acked-by: Jason Wang <jasowang@redhat.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@redhat.com
> > CC: jasowang@redhat.com
> > CC: virtualization@lists.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
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2] net: virtio: use eth_hw_addr_set()
@ 2021-10-28  2:30     ` Jason Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Jason Wang @ 2021-10-28  2:30 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Jakub Kicinski, virtualization, davem, netdev

On Wed, Oct 27, 2021 at 11:31 PM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> 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@kernel.org>
>
> Acked-by: Michael S. Tsirkin <mst@redhat.com>

Acked-by: Jason Wang <jasowang@redhat.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@redhat.com
> > CC: jasowang@redhat.com
> > CC: virtualization@lists.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
>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2] net: virtio: use eth_hw_addr_set()
  2021-10-27 15:20 [PATCH net-next v2] net: virtio: use eth_hw_addr_set() Jakub Kicinski
  2021-10-27 15:30   ` Michael S. Tsirkin
@ 2021-10-28 15:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-10-28 15:20 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: davem, netdev, mst, jasowang, virtualization

Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

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.
> 
> 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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-28 15:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 15:20 [PATCH net-next v2] net: virtio: use eth_hw_addr_set() Jakub Kicinski
2021-10-27 15:30 ` Michael S. Tsirkin
2021-10-27 15:30   ` Michael S. Tsirkin
2021-10-28  2:30   ` Jason Wang
2021-10-28  2:30     ` Jason Wang
2021-10-28 15:20 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.