From: Hangbin Liu <liuhangbin@gmail.com>
To: Jianbo Liu <jianbol@nvidia.com>
Cc: Jakub Kicinski <kuba@kernel.org>,
netdev@vger.kernel.org, Jay Vosburgh <jv@jvosburgh.net>,
Andy Gospodarek <andy@greyhouse.net>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Nikolay Aleksandrov <razor@blackwall.org>,
Simon Horman <horms@kernel.org>, Tariq Toukan <tariqt@nvidia.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
Shuah Khan <shuah@kernel.org>,
Steffen Klassert <steffen.klassert@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Sabrina Dubroca <sd@queasysnail.net>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net 0/2] bond: fix xfrm offload feature during init
Date: Thu, 9 Jan 2025 08:37:25 +0000 [thread overview]
Message-ID: <Z3-KxbofkhOrWin7@fedora> (raw)
In-Reply-To: <e01bae5f-30b5-4ec4-8c4b-5c133dd4552a@nvidia.com>
On Thu, Jan 09, 2025 at 09:26:38AM +0800, Jianbo Liu wrote:
>
>
> On 1/8/2025 3:14 PM, Hangbin Liu wrote:
> > On Wed, Jan 08, 2025 at 11:40:05AM +0800, Jianbo Liu wrote:
> > >
> > >
> > > On 1/8/2025 10:46 AM, Hangbin Liu wrote:
> > > > On Mon, Jan 06, 2025 at 10:47:16AM +0000, Hangbin Liu wrote:
> > > > > On Thu, Jan 02, 2025 at 11:33:34AM +0800, Jianbo Liu wrote:
> > > > > > > > Re-locking doesn't look great, glancing at the code I don't see any
> > > > > > > > obvious better workarounds. Easiest fix would be to don't let the
> > > > > > > > drivers sleep in the callbacks and then we can go back to a spin lock.
> > > > > > > > Maybe nvidia people have better ideas, I'm not familiar with this
> > > > > > > > offload.
> > > > > > >
> > > > > > > I don't know how to disable bonding sleeping since we use mutex_lock now.
> > > > > > > Hi Jianbo, do you have any idea?
> > > > > > >
> > > > > >
> > > > > > I think we should allow drivers to sleep in the callbacks. So, maybe it's
> > > > > > better to move driver's xdo_dev_state_delete out of state's spin lock.
> > > > >
> > > > > I just check the code, xfrm_dev_state_delete() and later
> > > > > dev->xfrmdev_ops->xdo_dev_state_delete(x) have too many xfrm_state x
> > > > > checks. Can we really move it out of spin lock from xfrm_state_delete()
> > > >
> > > > I tried to move the mutex lock code to a work queue, but found we need to
> > > > check (ipsec->xs == xs) in bonding. So we still need xfrm_state x during bond
> > >
> > > Maybe I miss something, but why need to hold spin lock. You can keep xfrm
> > > state by its refcnt.
> >
> > Do you mean move the xfrm_dev_state_delete() out of spin lock directly like:
> >
>
> Yes. Not feasible?
>
> > diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
> > index 67ca7ac955a3..6881ddeb4360 100644
> > --- a/net/xfrm/xfrm_state.c
> > +++ b/net/xfrm/xfrm_state.c
> > @@ -766,13 +766,6 @@ int __xfrm_state_delete(struct xfrm_state *x)
> > if (x->encap_sk)
> > sock_put(rcu_dereference_raw(x->encap_sk));
> > - xfrm_dev_state_delete(x);
> > -
> > - /* All xfrm_state objects are created by xfrm_state_alloc.
> > - * The xfrm_state_alloc call gives a reference, and that
> > - * is what we are dropping here.
> > - */
> > - xfrm_state_put(x);
> > err = 0;
> > }
> > @@ -787,8 +780,20 @@ int xfrm_state_delete(struct xfrm_state *x)
> > spin_lock_bh(&x->lock);
> > err = __xfrm_state_delete(x);
> > spin_unlock_bh(&x->lock);
> > + if (err)
> > + return err;
> > - return err;
> > + if (x->km.state == XFRM_STATE_DEAD) {
> > + xfrm_dev_state_delete(x);
> > +
> > + /* All xfrm_state objects are created by xfrm_state_alloc.
> > + * The xfrm_state_alloc call gives a reference, and that
> > + * is what we are dropping here.
> > + */
> > + xfrm_state_put(x);
> > + }
> > +
> > + return 0;
> > }
> > EXPORT_SYMBOL(xfrm_state_delete);
> >
> > Then why we need the spin lock in xfrm_state_delete?
> >
>
> No, we don't need. But I am trying to understand what you said in your last
> email about adding a new lock, or unlocking spin lock in
I *thought* we need the spin lock in xfrm_state_delete(). So to protect xfrm_state,
we need a new lock. Although it looks redundant. e.g.
int xfrm_state_delete(struct xfrm_state *x)
{
int err;
spin_lock_bh(&x->lock);
err = __xfrm_state_delete(x);
spin_unlock_bh(&x->lock);
if (err)
return err;
another_lock(&x->other_lock)
if (x->km.state == XFRM_STATE_DEAD) {
xfrm_dev_state_delete(x);
xfrm_state_put(x);
}
another_unlock(&x->other_lock)
return 0;
}
> bond_ipsec_del_sa(). Anything I missed?
The unlock spin lock in bond_ipsec_del_sa looks like
https://lore.kernel.org/netdev/Z1vfsAyuxcohT7th@fedora/
Thanks
Hangbin
next prev parent reply other threads:[~2025-01-09 8:37 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-11 7:11 [PATCH net 0/2] bond: fix xfrm offload feature during init Hangbin Liu
2024-12-11 7:11 ` [PATCH net 1/2] bonding: fix xfrm offload feature setup on active-backup mode Hangbin Liu
2024-12-12 9:19 ` Nikolay Aleksandrov
2024-12-12 9:39 ` Hangbin Liu
2024-12-12 9:43 ` Nikolay Aleksandrov
2024-12-13 3:10 ` Hangbin Liu
2024-12-11 7:11 ` [PATCH net 2/2] selftests: bonding: add ipsec offload test Hangbin Liu
2024-12-12 14:27 ` [PATCH net 0/2] bond: fix xfrm offload feature during init Jakub Kicinski
2024-12-13 7:18 ` Hangbin Liu
2024-12-14 3:31 ` Jakub Kicinski
2025-01-02 2:44 ` Hangbin Liu
2025-01-02 3:33 ` Jianbo Liu
2025-01-03 11:05 ` Hangbin Liu
2025-01-06 10:47 ` Hangbin Liu
2025-01-08 2:46 ` Hangbin Liu
2025-01-08 3:40 ` Jianbo Liu
2025-01-08 7:14 ` Hangbin Liu
2025-01-09 1:26 ` Jianbo Liu
2025-01-09 8:37 ` Hangbin Liu [this message]
2025-01-09 9:51 ` Jianbo Liu
2025-01-09 10:17 ` Hangbin Liu
2025-01-09 12:21 ` Jianbo Liu
2025-01-15 9:19 ` Hangbin Liu
2025-01-17 7:54 ` Steffen Klassert
2025-01-20 16:16 ` Cosmin Ratiu
2025-01-20 23:59 ` Hangbin Liu
2025-02-20 10:48 ` Cosmin Ratiu
2025-02-20 11:18 ` Hangbin Liu
2025-02-20 11:33 ` Cosmin Ratiu
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=Z3-KxbofkhOrWin7@fedora \
--to=liuhangbin@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=andy@greyhouse.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=jianbol@nvidia.com \
--cc=jv@jvosburgh.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
--cc=sd@queasysnail.net \
--cc=shuah@kernel.org \
--cc=steffen.klassert@secunet.com \
--cc=tariqt@nvidia.com \
/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;
as well as URLs for NNTP newsgroup(s).