diff mbox series

[net-next,V6,4/4] virtio-net: synchronize probe with ndo_set_features

Message ID 20240806022224.71779-5-jasowang@redhat.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series virtio-net: synchronize op/admin state | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 29 this patch: 29
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 29 this patch: 29
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 29 this patch: 29
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 22 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-06--15-00 (tests: 707)

Commit Message

Jason Wang Aug. 6, 2024, 2:22 a.m. UTC
We calculate guest offloads during probe without the protection of
rtnl_lock. This lead to race between probe and ndo_set_features. Fix
this by moving the calculation under the rtnl_lock.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/net/virtio_net.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Michael S. Tsirkin Aug. 6, 2024, 12:24 p.m. UTC | #1
On Tue, Aug 06, 2024 at 10:22:24AM +0800, Jason Wang wrote:
> We calculate guest offloads during probe without the protection of
> rtnl_lock. This lead to race between probe and ndo_set_features. Fix
> this by moving the calculation under the rtnl_lock.
> 
> Signed-off-by: Jason Wang <jasowang@redhat.com>

Fixes tag pls?

> ---
>  drivers/net/virtio_net.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index fc5196ca8d51..1d86aa07c871 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -6596,6 +6596,11 @@ static int virtnet_probe(struct virtio_device *vdev)
>  		netif_carrier_on(dev);
>  	}
>  
> +	for (i = 0; i < ARRAY_SIZE(guest_offloads); i++)
> +		if (virtio_has_feature(vi->vdev, guest_offloads[i]))
> +			set_bit(guest_offloads[i], &vi->guest_offloads);
> +	vi->guest_offloads_capable = vi->guest_offloads;
> +
>  	rtnl_unlock();
>  
>  	err = virtnet_cpu_notif_add(vi);
> @@ -6604,11 +6609,6 @@ static int virtnet_probe(struct virtio_device *vdev)
>  		goto free_unregister_netdev;
>  	}
>  
> -	for (i = 0; i < ARRAY_SIZE(guest_offloads); i++)
> -		if (virtio_has_feature(vi->vdev, guest_offloads[i]))
> -			set_bit(guest_offloads[i], &vi->guest_offloads);
> -	vi->guest_offloads_capable = vi->guest_offloads;
> -
>  	pr_debug("virtnet: registered device %s with %d RX and TX vq's\n",
>  		 dev->name, max_queue_pairs);
>  
> -- 
> 2.31.1
Jason Wang Aug. 13, 2024, 3:45 a.m. UTC | #2
On Tue, Aug 6, 2024 at 8:25 PM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Tue, Aug 06, 2024 at 10:22:24AM +0800, Jason Wang wrote:
> > We calculate guest offloads during probe without the protection of
> > rtnl_lock. This lead to race between probe and ndo_set_features. Fix
> > this by moving the calculation under the rtnl_lock.
> >
> > Signed-off-by: Jason Wang <jasowang@redhat.com>
>
> Fixes tag pls?

Fixes: 3f93522ffab2 ("virtio-net: switch off offloads on demand if
possible on XDP set")

Thanks


>
> > ---
> >  drivers/net/virtio_net.c | 10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index fc5196ca8d51..1d86aa07c871 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -6596,6 +6596,11 @@ static int virtnet_probe(struct virtio_device *vdev)
> >               netif_carrier_on(dev);
> >       }
> >
> > +     for (i = 0; i < ARRAY_SIZE(guest_offloads); i++)
> > +             if (virtio_has_feature(vi->vdev, guest_offloads[i]))
> > +                     set_bit(guest_offloads[i], &vi->guest_offloads);
> > +     vi->guest_offloads_capable = vi->guest_offloads;
> > +
> >       rtnl_unlock();
> >
> >       err = virtnet_cpu_notif_add(vi);
> > @@ -6604,11 +6609,6 @@ static int virtnet_probe(struct virtio_device *vdev)
> >               goto free_unregister_netdev;
> >       }
> >
> > -     for (i = 0; i < ARRAY_SIZE(guest_offloads); i++)
> > -             if (virtio_has_feature(vi->vdev, guest_offloads[i]))
> > -                     set_bit(guest_offloads[i], &vi->guest_offloads);
> > -     vi->guest_offloads_capable = vi->guest_offloads;
> > -
> >       pr_debug("virtnet: registered device %s with %d RX and TX vq's\n",
> >                dev->name, max_queue_pairs);
> >
> > --
> > 2.31.1
>
diff mbox series

Patch

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index fc5196ca8d51..1d86aa07c871 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -6596,6 +6596,11 @@  static int virtnet_probe(struct virtio_device *vdev)
 		netif_carrier_on(dev);
 	}
 
+	for (i = 0; i < ARRAY_SIZE(guest_offloads); i++)
+		if (virtio_has_feature(vi->vdev, guest_offloads[i]))
+			set_bit(guest_offloads[i], &vi->guest_offloads);
+	vi->guest_offloads_capable = vi->guest_offloads;
+
 	rtnl_unlock();
 
 	err = virtnet_cpu_notif_add(vi);
@@ -6604,11 +6609,6 @@  static int virtnet_probe(struct virtio_device *vdev)
 		goto free_unregister_netdev;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(guest_offloads); i++)
-		if (virtio_has_feature(vi->vdev, guest_offloads[i]))
-			set_bit(guest_offloads[i], &vi->guest_offloads);
-	vi->guest_offloads_capable = vi->guest_offloads;
-
 	pr_debug("virtnet: registered device %s with %d RX and TX vq's\n",
 		 dev->name, max_queue_pairs);