Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: David Ahern <dsahern@kernel.org>
Cc: linux-rdma@vger.kernel.org, jgg@ziepe.ca
Subject: Re: [PATCH v2] RDMA: Fix netdev tracker in ib_device_set_netdev
Date: Thu, 11 Jul 2024 13:17:29 +0300	[thread overview]
Message-ID: <20240711101729.GQ6668@unreal> (raw)
In-Reply-To: <20240711101237.GP6668@unreal>

On Thu, Jul 11, 2024 at 01:12:37PM +0300, Leon Romanovsky wrote:
> On Wed, Jul 10, 2024 at 01:33:10PM -0700, David Ahern wrote:
> > If a netdev has already been assigned, ib_device_set_netdev needs to
> > release the reference on the older netdev but it is mistakenly being
> > called for the new netdev. Fix it and in the process use netdev_put
> > to be symmetrical with the netdev_hold.
> > 
> > Fixes: 09f530f0c6d6 ("RDMA: Add netdevice_tracker to ib_device_set_netdev()")
> > Signed-off-by: David Ahern <dsahern@kernel.org>
> > ---
> > v2
> > - remove __dev_put now that netdev_put is used
> > 
> >  drivers/infiniband/core/device.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
> > index 55aa7aa32d4a..9b99112baf47 100644
> > --- a/drivers/infiniband/core/device.c
> > +++ b/drivers/infiniband/core/device.c
> > @@ -2167,14 +2167,13 @@ int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
> >  	}
> >  
> >  	if (old_ndev)
> > -		netdev_tracker_free(ndev, &pdata->netdev_tracker);
> > +		netdev_put(old_ndev, &pdata->netdev_tracker);
> >  	if (ndev)
> >  		netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
> >  	rcu_assign_pointer(pdata->netdev, ndev);
> >  	spin_unlock_irqrestore(&pdata->netdev_lock, flags);
> >  
> >  	add_ndev_hash(pdata);
> > -	__dev_put(old_ndev);
> 
> I applied with the following change:
> diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
> index 49a2ddaf5a38..1f867b7f7020 100644
> --- a/drivers/infiniband/core/device.c
> +++ b/drivers/infiniband/core/device.c
> @@ -2184,14 +2184,12 @@ int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
>                 return 0;
>         }
> 
> -       if (old_ndev)
> -               netdev_put(old_ndev, &pdata->netdev_tracker);
> -       if (ndev)
> -               netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
> +       netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
>         rcu_assign_pointer(pdata->netdev, ndev);
>         spin_unlock_irqrestore(&pdata->netdev_lock, flags);
> 
>         add_ndev_hash(pdata);
> +       netdev_put(old_ndev, &pdata->netdev_tracker);
> 
>         return 0;
>  }

The final version is:
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 49a2ddaf5a38..9c31eef9f590 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -2184,15 +2184,12 @@ int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
                return 0;
        }

-       if (old_ndev)
-               netdev_put(old_ndev, &pdata->netdev_tracker);
-       if (ndev)
-               netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
+       netdev_put(old_ndev, &pdata->netdev_tracker);
+       netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
        rcu_assign_pointer(pdata->netdev, ndev);
        spin_unlock_irqrestore(&pdata->netdev_lock, flags);

        add_ndev_hash(pdata);
-
        return 0;
 }
 EXPORT_SYMBOL(ib_device_set_netdev);


> 
> 
> >  
> >  	return 0;
> >  }
> > -- 
> > 2.39.3 (Apple Git-146)
> > 
> > 
> 

  reply	other threads:[~2024-07-11 10:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-10 20:33 [PATCH v2] RDMA: Fix netdev tracker in ib_device_set_netdev David Ahern
2024-07-11 10:12 ` Leon Romanovsky
2024-07-11 10:17   ` Leon Romanovsky [this message]
2024-07-11 10:18 ` Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240711101729.GQ6668@unreal \
    --to=leon@kernel.org \
    --cc=dsahern@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=linux-rdma@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox