mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: jianbol@nvidia.com
Cc: netdev@vger.kernel.org, ipsec@lists.linux.dev,
	steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, fw@strlen.de,
	linux-kernel@vger.kernel.org, cjubran@nvidia.com
Subject: Re: [PATCH ipsec 4/4] Revert "xfrm: serialize state GC with device state flush"
Date: Sun, 29 Nov 2026 02:14:43 +0000	[thread overview]
Message-ID: <179591848374.3135.14266299641095938448@kernel.org> (raw)
In-Reply-To: <20261125013412.1123866-5-jianbol@nvidia.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] xfrm_dev_state_flush() (net/xfrm/xfrm_state.c:1018-1044) now
  skips any matching state on xfrm_state_dev_gc_list whose refcount is…

--

Revert "xfrm: serialize state GC with device state flush"

This reverts the mutex that serialized xfrm_state_gc_task() with the
dev_gclist pass in xfrm_dev_state_flush(). It depends on "xfrm: Serialize
device state teardown". In that patch the flush takes a reference on each
state it frees and skips states whose refcount has already reached zero.

Link: https://lore.kernel.org/netdev/aqfZNeR58HLm2x1o@secunet.com/

> diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
> index 9883fb3545f8f..717c0bdb95597 100644
> --- a/net/xfrm/xfrm_state.c
> +++ b/net/xfrm/xfrm_state.c

[ ... ]

> @@ -1018,7 +1015,6 @@ int xfrm_dev_state_flush(struct net *net, struct net_device *dev, bool task_vali
>  out:
>  	spin_unlock_bh(&net->xfrm.xfrm_state_lock);
>  
> -	mutex_lock(&xfrm_state_gc_mutex);
>  	spin_lock_bh(&xfrm_state_dev_gc_lock);
>  	hlist_for_each_entry_safe(x, tmp, &xfrm_state_dev_gc_list, dev_gclist) {
>  		xso = &x->xso;
> @@ -1035,7 +1031,6 @@ int xfrm_dev_state_flush(struct net *net, struct net_device *dev, bool task_vali
>  		}
>  	}
>  	spin_unlock_bh(&xfrm_state_dev_gc_lock);
> -	mutex_unlock(&xfrm_state_gc_mutex);
>  
>  	if (!hlist_empty(&flush_list))
>  		synchronize_rcu();

[Severity: Medium]
Without the mutex, the dev_gclist pass in xfrm_dev_state_flush() relies
on the refcount skip added by "xfrm: Serialize device state teardown":

net/xfrm/xfrm_state.c:xfrm_dev_state_flush() {
    ...
		if (xso->dev == dev) {
			if (!refcount_inc_not_zero(&x->refcnt))
				continue;
    ...
	xfrm_flush_gc();
}

A skipped state is left to the state GC. The only wait is xfrm_flush_gc(),
which is just flush_work(&xfrm_state_gc_work).

Can that wait miss the skipped state? xfrm_state_put() makes the zero
refcount visible before the state is queued for GC:

xfrm_state_put()
    refcount_dec_and_test(&x->refcnt)
    __xfrm_state_destroy()
        spin_lock_bh(&xfrm_state_gc_lock);
        hlist_add_head(&x->gclist, &xfrm_state_gc_list);
        spin_unlock_bh(&xfrm_state_gc_lock);
        schedule_work(&xfrm_state_gc_work);

Another context can drop the last reference, for example a dst bundle
destroy, a secpath free, or a netlink getsa put. Suppose it is preempted
or delayed between refcount_dec_and_test() and schedule_work() while the
flush is running. The flush then skips the state, and flush_work() finds
the work idle and returns at once.

In that case the NETDEV_DOWN or NETDEV_UNREGISTER notifier returns while
xdo_dev_state_free() and netdev_put(dev, &xso->dev_tracker) for that SA
are still waiting to run from the GC work.

For NETDEV_UNREGISTER, unregister_netdevice_many_notify() calls
ndo_uninit right after the notifiers. For bonding that is bond_uninit(),
which does:

	mutex_destroy(&bond->ipsec_lock);

A late call chain
xfrm_state_gc_task()->xfrm_state_gc_destroy()->xfrm_dev_state_free()->bond_ipsec_free_sa()
would then lock bond->ipsec_lock after it has been destroyed.

Before the series, the device state of every matching dev_gclist entry
was freed synchronously, whatever its refcount. The series says skipped
states are freed by the state GC and that xfrm_flush_gc() waits for them.

Does that wait only hold when the flush itself dropped the last
reference?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125013412.1123866-1-jianbol%40nvidia.com

      reply	other threads:[~2026-11-29  2:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  1:34 [PATCH ipsec 0/4] xfrm: Fix device state teardown races Jianbo Liu
2026-11-25  1:34 ` [PATCH ipsec 1/4] xfrm: Give GC list nodes their own storage Jianbo Liu
2026-11-29  2:14   ` netdev-bot+sashiko
2026-11-25  1:34 ` [PATCH ipsec 2/4] xfrm: Serialize device state teardown Jianbo Liu
2026-11-29  2:14   ` netdev-bot+sashiko
2026-11-25  1:34 ` [PATCH ipsec 3/4] xfrm: Wait for an RCU grace period before freeing device state Jianbo Liu
2026-11-29  2:14   ` netdev-bot+sashiko
2026-11-25  1:34 ` [PATCH ipsec 4/4] Revert "xfrm: serialize state GC with device state flush" Jianbo Liu
2026-11-29  2:14   ` netdev-bot+sashiko [this message]

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=179591848374.3135.14266299641095938448@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=cjubran@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=ipsec@lists.linux.dev \
    --cc=jianbol@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=steffen.klassert@secunet.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

all inboxes | Powered by JetHome®