All of lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: steffen.klassert@secunet.com
Cc: davem@davemloft.net, kuba@kernel.org,
	herbert@gondor.apana.org.au, netdev@vger.kernel.org
Subject: Re: [PATCH 21/22] Revert "xfrm: serialize state GC with device state flush"
Date: Wed, 02 Dec 2026 13:12:34 +0000	[thread overview]
Message-ID: <179621715417.3146.5170339497297011327@kernel.org> (raw)
In-Reply-To: <20261201124252.1163254-22-steffen.klassert@secunet.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() in net/xfrm/xfrm_state.c no longer
  guarantees that all device offload state for `dev` has been freed when…

--

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

This reverts the xfrm_state_gc_mutex. That mutex serialized
xfrm_state_gc_task() with the dev_gclist walk in xfrm_dev_state_flush().
The flush now takes a reference on each state it frees, and it relies on
"xfrm: Serialize device state teardown" so that only one caller frees the
device state.

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

> diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
> index 92c3631a43bf7..d48c88f2df64f 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]

The commit message says "Nothing is left for the mutex to protect".
With "xfrm: Serialize device state teardown" applied, can
xfrm_dev_state_flush() still return before all of the device state for dev
has been freed?

The dev_gclist walk in xfrm_dev_state_flush() skips any matching state
whose refcount is already zero:

	if (xso->dev == dev) {
		if (!refcount_inc_not_zero(&x->refcnt))
			continue;

This relies on the state GC freeing that state, and on the trailing
xfrm_flush_gc() waiting for it. However, xfrm_state_put() drops the count
to zero before the GC work is queued:

include/net/xfrm.h:xfrm_state_put() {
	if (refcount_dec_and_test(&x->refcnt))
		__xfrm_state_destroy(x);
}

net/xfrm/xfrm_state.c:__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);
}

Consider this interleaving:

CPU B (e.g. netlink delete, process context)
xfrm_state_put(x)
    refcount_dec_and_test() -> refcnt == 0
    <preempted before __xfrm_state_destroy()>

CPU A (NETDEV_DOWN or NETDEV_UNREGISTER for the same dev)
xfrm_dev_state_flush()
    refcount_inc_not_zero() fails, x is skipped
    flush_list is empty, so synchronize_rcu() is skipped
    xfrm_flush_gc()
        flush_work() returns at once, nothing is queued yet

Even when synchronize_rcu() does run because other states were collected,
it doesn't wait for a preemptible process-context putter.

In that case the flush returns while x->xso.dev, the netdev tracker
reference and the driver offload context are all still live. The driver's
xdo_dev_state_free() and netdev_put() then run later from
xfrm_state_gc_task(). That is after xfrm_dev_down(), xfrm_dev_unregister()
or bond_master_netdev_event() has already finished.

At the series base, the flush called xfrm_dev_state_free() on every
matching dev_gclist entry whatever its refcount was, and the mutex kept
the GC from destroying it at the same time.

The mutex didn't cover this gap either. The window comes from the
skip-on-refcnt==0 logic added in "xfrm: Serialize device state teardown",
which this revert depends on. The code is unchanged at the end of the
series.

If a driver tears down its offload resources once the notifier returns,
could xdo_dev_state_free() then run against that torn-down state? On
unregister, would netdev_wait_allrefs() also be delayed until the GC work
runs?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201124252.1163254-2-steffen.klassert%40secunet.com

  reply	other threads:[~2026-12-02 13:12 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 12:41 [PATCH 0/22] pull request (net): ipsec 2026-12-01 Steffen Klassert
2026-12-01 12:41 ` [PATCH 01/22] xfrm: ipcomp: account full fragment pages in truesize Steffen Klassert
2026-12-01 13:36   ` bot+bpf-ci
2026-12-01 12:41 ` [PATCH 02/22] xfrm: esp: reset outer TCP GSO metadata on espintcp input Steffen Klassert
2026-12-01 12:41 ` [PATCH 03/22] xfrm: keep the mode module pinned until destroy_state returns Steffen Klassert
2026-12-01 12:41 ` [PATCH 04/22] xfrm: serialize SA activation with state deletion Steffen Klassert
2026-12-01 12:41 ` [PATCH 05/22] xfrm: keep old state references until migration deletion completes Steffen Klassert
2026-12-01 12:41 ` [PATCH 06/22] xfrm: hold migrated states through rollback Steffen Klassert
2026-12-01 12:41 ` [PATCH 07/22] xfrm: check inner family via skb_dst for small_ipv6 DF clearing Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 08/22] xfrm: account XFRMA_MARK in xfrm_sa_len() Steffen Klassert
2026-12-01 12:41 ` [PATCH 09/22] xfrm: replay: Fix late packet handling with ESN crypto offload Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 10/22] xfrm: fix IPv6 first-fragment protocol decode Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 11/22] xfrm: fix selector matching for IPv6 atomic fragments Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 12/22] xfrm: espintcp: read the socket error queue for MSG_ERRQUEUE Steffen Klassert
2026-12-01 12:41 ` [PATCH 13/22] xfrm: iptfs: force a dst reference before queueing an skb Steffen Klassert
2026-12-01 13:36   ` bot+bpf-ci
2026-12-01 12:41 ` [PATCH 14/22] xfrm: espintcp: select receive path by skb protocol Steffen Klassert
2026-12-01 12:41 ` [PATCH 15/22] net: xfrm: interface: restore dst_orig on every xfrm interface Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 16/22] xfrm: iptfs: make room before copying a continuation in reassembly Steffen Klassert
2026-12-01 12:41 ` [PATCH 17/22] xfrm/compat: pass on the translated length of a socket policy Steffen Klassert
2026-12-01 12:41 ` [PATCH 18/22] xfrm: Give GC list nodes their own storage Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 19/22] xfrm: Serialize device state teardown Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 20/22] xfrm: Wait for an RCU grace period before freeing device state Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 21/22] Revert "xfrm: serialize state GC with device state flush" Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko [this message]
2026-12-01 12:41 ` [PATCH 22/22] xfrm: Serialize offload stats updates with x->lock Steffen Klassert

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=179621715417.3146.5170339497297011327@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.