diff mbox series

IB/ipoib: No need to hold the lock while printing the warning

Message ID 20231211131051.1500834-1-neelx@redhat.com (mailing list archive)
State Superseded
Headers show
Series IB/ipoib: No need to hold the lock while printing the warning | expand

Commit Message

Daniel Vacek Dec. 11, 2023, 1:10 p.m. UTC
Signed-off-by: Daniel Vacek <neelx@redhat.com>
---
 drivers/infiniband/ulp/ipoib/ipoib_multicast.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Leon Romanovsky Dec. 11, 2023, 1:22 p.m. UTC | #1
On Mon, Dec 11, 2023 at 02:10:50PM +0100, Daniel Vacek wrote:
> Signed-off-by: Daniel Vacek <neelx@redhat.com>

Please fill some text in commit message.

Thanks

> ---
>  drivers/infiniband/ulp/ipoib/ipoib_multicast.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
> index 5b3154503bf4..ae2c05806dcc 100644
> --- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
> +++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
> @@ -536,17 +536,17 @@ static int ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast)
>  	multicast = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port,
>  					 &rec, comp_mask, GFP_KERNEL,
>  					 ipoib_mcast_join_complete, mcast);
> -	spin_lock_irq(&priv->lock);
>  	if (IS_ERR(multicast)) {
>  		ret = PTR_ERR(multicast);
>  		ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret);
> +		spin_lock_irq(&priv->lock);
>  		/* Requeue this join task with a backoff delay */
>  		__ipoib_mcast_schedule_join_thread(priv, mcast, 1);
>  		clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
>  		spin_unlock_irq(&priv->lock);
>  		complete(&mcast->done);
> -		spin_lock_irq(&priv->lock);
>  	}
> +	spin_lock_irq(&priv->lock);
>  	return 0;
>  }
>  
> -- 
> 2.43.0
>
Jason Gunthorpe Dec. 11, 2023, 1:25 p.m. UTC | #2
On Mon, Dec 11, 2023 at 03:22:17PM +0200, Leon Romanovsky wrote:
 
> Please fill some text in commit message.

Yes, explain *why* you are doing this
 
> > diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
> > index 5b3154503bf4..ae2c05806dcc 100644
> > --- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
> > +++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
> > @@ -536,17 +536,17 @@ static int ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast)
> >  	multicast = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port,
> >  					 &rec, comp_mask, GFP_KERNEL,
> >  					 ipoib_mcast_join_complete, mcast);
> > -	spin_lock_irq(&priv->lock);
> >  	if (IS_ERR(multicast)) {
> >  		ret = PTR_ERR(multicast);
> >  		ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret);
> > +		spin_lock_irq(&priv->lock);
> >  		/* Requeue this join task with a backoff delay */
> >  		__ipoib_mcast_schedule_join_thread(priv, mcast, 1);
> >  		clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
> >  		spin_unlock_irq(&priv->lock);
> >  		complete(&mcast->done);
> > -		spin_lock_irq(&priv->lock);

It is super weird to unlock just around complete.

Jason
Daniel Vacek Dec. 11, 2023, 2:09 p.m. UTC | #3
On Mon, Dec 11, 2023 at 2:25 PM Jason Gunthorpe <jgg@ziepe.ca> wrote:
>
> On Mon, Dec 11, 2023 at 03:22:17PM +0200, Leon Romanovsky wrote:
>
> > Please fill some text in commit message.
>
> Yes, explain *why* you are doing this

Oh, sorry. I did not mention it but there's no particular reason
really. The @Subject says it all. There should be no logical or
functional change other than reducing the span of that critical
section. In other words, just nitpicking, not a big deal.

While checking the code (and past changes) related to the other issue
I also sent today I just noticed the way 08bc327629cbd added the
spin_lock before returning from this function and it appeared to me
it's clearer the way I'm proposing here.

Honestly, I was not looking into why the lock is released for that
completion. And I'm not changing that logic.

If this complete() can be called with priv->lock held, the cleanup
would look different, of course.

That said, If you'd like to keep this patch I can send a v2 with the
above details in the message body. Otherwise feel free to drop this.

--nX

> > > diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
> > > index 5b3154503bf4..ae2c05806dcc 100644
> > > --- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
> > > +++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
> > > @@ -536,17 +536,17 @@ static int ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast)
> > >     multicast = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port,
> > >                                      &rec, comp_mask, GFP_KERNEL,
> > >                                      ipoib_mcast_join_complete, mcast);
> > > -   spin_lock_irq(&priv->lock);
> > >     if (IS_ERR(multicast)) {
> > >             ret = PTR_ERR(multicast);
> > >             ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret);
> > > +           spin_lock_irq(&priv->lock);
> > >             /* Requeue this join task with a backoff delay */
> > >             __ipoib_mcast_schedule_join_thread(priv, mcast, 1);
> > >             clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
> > >             spin_unlock_irq(&priv->lock);
> > >             complete(&mcast->done);
> > > -           spin_lock_irq(&priv->lock);
>
> It is super weird to unlock just around complete.
>
> Jason
>
Jason Gunthorpe Dec. 11, 2023, 3:25 p.m. UTC | #4
On Mon, Dec 11, 2023 at 03:09:13PM +0100, Daniel Vacek wrote:
> On Mon, Dec 11, 2023 at 2:25 PM Jason Gunthorpe <jgg@ziepe.ca> wrote:
> >
> > On Mon, Dec 11, 2023 at 03:22:17PM +0200, Leon Romanovsky wrote:
> >
> > > Please fill some text in commit message.
> >
> > Yes, explain *why* you are doing this
> 
> Oh, sorry. I did not mention it but there's no particular reason
> really. The @Subject says it all. There should be no logical or
> functional change other than reducing the span of that critical
> section. In other words, just nitpicking, not a big deal.
> 
> While checking the code (and past changes) related to the other issue
> I also sent today I just noticed the way 08bc327629cbd added the
> spin_lock before returning from this function and it appeared to me
> it's clearer the way I'm proposing here.
> 
> Honestly, I was not looking into why the lock is released for that
> completion. And I'm not changing that logic.
> 
> If this complete() can be called with priv->lock held, the cleanup
> would look different, of course.

complete() can be called under spinlocks just fine, AFAIK..

Jason
Daniel Vacek Dec. 11, 2023, 4:08 p.m. UTC | #5
On Mon, Dec 11, 2023 at 4:27 PM Jason Gunthorpe <jgg@ziepe.ca> wrote:
>
> On Mon, Dec 11, 2023 at 03:09:13PM +0100, Daniel Vacek wrote:
> > On Mon, Dec 11, 2023 at 2:25 PM Jason Gunthorpe <jgg@ziepe.ca> wrote:
> > >
> > > On Mon, Dec 11, 2023 at 03:22:17PM +0200, Leon Romanovsky wrote:
> > >
> > > > Please fill some text in commit message.
> > >
> > > Yes, explain *why* you are doing this
> >
> > Oh, sorry. I did not mention it but there's no particular reason
> > really. The @Subject says it all. There should be no logical or
> > functional change other than reducing the span of that critical
> > section. In other words, just nitpicking, not a big deal.
> >
> > While checking the code (and past changes) related to the other issue
> > I also sent today I just noticed the way 08bc327629cbd added the
> > spin_lock before returning from this function and it appeared to me
> > it's clearer the way I'm proposing here.
> >
> > Honestly, I was not looking into why the lock is released for that
> > completion. And I'm not changing that logic.
> >
> > If this complete() can be called with priv->lock held, the cleanup
> > would look different, of course.
>
> complete() can be called under spinlocks just fine, AFAIK..

Yup, agreed. We ended up removing the lock completely in this function
with the other patch. This patch can be discarded.

--nX

> Jason
>
diff mbox series

Patch

diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index 5b3154503bf4..ae2c05806dcc 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -536,17 +536,17 @@  static int ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast)
 	multicast = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port,
 					 &rec, comp_mask, GFP_KERNEL,
 					 ipoib_mcast_join_complete, mcast);
-	spin_lock_irq(&priv->lock);
 	if (IS_ERR(multicast)) {
 		ret = PTR_ERR(multicast);
 		ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret);
+		spin_lock_irq(&priv->lock);
 		/* Requeue this join task with a backoff delay */
 		__ipoib_mcast_schedule_join_thread(priv, mcast, 1);
 		clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
 		spin_unlock_irq(&priv->lock);
 		complete(&mcast->done);
-		spin_lock_irq(&priv->lock);
 	}
+	spin_lock_irq(&priv->lock);
 	return 0;
 }