From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379389; b=uF/fjUsIYVVn1SPIDoTi9bEKirSR2opjuDUj1QBuNWnR331venI26q9WqFkKnWFwMtiR 095/sUfYBFApcX61tQgB8Zw6cuCqXrDDrmFueR2yQk7C9sdV7b5dgja4B0d7VAT60KKM3 6dGz52sIYAoqC7lT9ymEXrHujIo8jyJwKRHYnZhNKuc4gqwPqIoUKR8ok9VZhUwtqq7Og 3ONn782W86+x2AlGsEOdIP9BBgT7PH1VblYHVy+0Z1FxS4N7vTxzd+vcLrLQz9z/SQCfu im0H4J0eJJCwRRc/Wp2y0cmjHArcDMZoAh+XqpQ05OVsTWzu1hKAXcH15NYjGDt8OGQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379389; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=pByqE4Ogt65/iDeKHn09l64ip1ZSVFKG8C6Q7QEXQ0M=; b=uw/eSHeXNdvqTUa2fCHInmDp2k/AqjQ2iCKN0YHTEBDDEh3PFpxYPK1GtDqfN4sWcDNQ 1wbudOeW9TG7Y061xTwKZZ/iMW0WtUf67h8ZIoZ73kD01mWlX2dLLnQr+kdqh2b0kTZOk FkGFiPl29jGgtXvuziv2Snrs/rbAFEYNET0vuA9T3BhT3uGVvolGT+ISgn/6JzB+c1Z7N dZOtuCiazRJGu9QHq3zB8EEPewYAW9H95/n9YAYEQov9xu7q3/wM2GViu00VWabt5UQV0 wd7BUwi97HfnvYzdAKywFxSpb0csMwGOAaZgcNVXPicd+zDsBN7tbxo0HB2/T+S7Ezg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=gu9pkkUp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39920606A322; Fri, 4 Dec 2026 10:16:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=gu9pkkUp Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAB071F000C2; Fri, 4 Dec 2026 10:16:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379389; bh=pByqE4Ogt65/iDeKHn09l64ip1ZSVFKG8C6Q7QEXQ0M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gu9pkkUpgAGZHggOYmt+3x5wUtvOuUncK28PirKdlnF5gwkaqRtJBAY21mZ7YPzUI jCG/Y4Ga+92f+Ws0SEE/z+40u8k79A+TnKHkVYALxgbH1CmGzBUlrlWrwkvycAgFQu 7VllwBKYWvqm+GtQ6IMsV4W5DcQexSpQYAUdQJPE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Dumazet , Kris Pan , Jakub Kicinski , Artem Dinaburg , Sasha Levin Subject: [PATCH 6.18 011/703] net: flush skb_defer_nodes in dev_cpu_dead() Date: Fri, 4 Dec 2026 18:58:30 +0900 Message-ID: <20261204100627.849041986@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 06e3f54e8b22040ada01a28343badf1990b4dd7d ] When a CPU goes offline, dev_cpu_dead() drains its softnet queues (completion_queue, output_queue, poll_list, process_queue, and input_pkt_queue), but leaves net_hotdata.skb_defer_nodes untouched. If oldcpu goes offline while holding pending skbs in its skb_defer_nodes lists (e.g. below the sysctl_skb_defer_max >> 1 IPI threshold, or if the IPI races with CPU teardown), those skbs remain stranded until oldcpu is brought back online. If any of these skbs hold page_pool fragments, page_pool_destroy() will stall indefinitely waiting for inflight pages to be returned when a netdev or driver is torn down while oldcpu is offline. Additionally, if smp_call_function_single_async() fails in kick_defer_list_purge() because the target CPU went offline, reset defer_ipi_scheduled to 0 so future IPI kicks are not blocked when the CPU comes back online. Also, if oldcpu was the last online CPU on its NUMA node, drain that node's slot across all CPUs so no skbs deferred from that node remain stranded on idle remote CPUs (or if the node itself is subsequently offlined). Finally, in skb_attempt_defer_free(), re-check cpu_online(cpu) and whether the caller migrated CPUs after llist_add(), flushing the node list if so, to close the preemption TOCTOU race against CPU/node teardown. Fixes: 68822bdf76f1 ("net: generalize skb freeing deferral to per-cpu lists") Fixes: 5628f3fe3b16 ("net: add NUMA awareness to skb_attempt_defer_free()") Closes: https://lore.kernel.org/netdev/20260916003430.3612956-1-kris.pan@intel.com/ Signed-off-by: Eric Dumazet Cc: Kris Pan Link: https://patch.msgid.link/20260923130318.607255-1-edumazet@google.com Signed-off-by: Jakub Kicinski [ Backport to 6.18.y: 6.18.y loads skb->alloc_cpu in the declaration of cpu and lacks the upstream skb_defer_disable_key and skb_zcopy() bypasses, so my_cpu is declared separately and the remaining hunks are adjusted for context. The 6.18.y flush loop has no prefetch(); the new __skb_defer_free_flush() helper adds it as upstream does. skb_defer_free_flush() keeps the for_each_online_node() iteration from commit 58fb1e2a33ea ("net: iterate online nodes in skb_defer_free_flush()"), already in 6.18.y. ] Signed-off-by: Artem Dinaburg Signed-off-by: Sasha Levin --- net/core/dev.c | 46 +++++++++++++++++++++++++++++++++++----------- net/core/dev.h | 2 ++ net/core/skbuff.c | 11 +++++++++-- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index c0aa4e8625b5d..f7e672a4a39f7 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5327,7 +5327,8 @@ void kick_defer_list_purge(unsigned int cpu) backlog_unlock_irq_restore(sd, flags); } else if (!cmpxchg(&sd->defer_ipi_scheduled, 0, 1)) { - smp_call_function_single_async(cpu, &sd->defer_csd); + if (smp_call_function_single_async(cpu, &sd->defer_csd)) + WRITE_ONCE(sd->defer_ipi_scheduled, 0); } } @@ -6865,24 +6866,35 @@ bool napi_complete_done(struct napi_struct *n, int work_done) } EXPORT_SYMBOL(napi_complete_done); -static void skb_defer_free_flush(void) +static void __skb_defer_free_flush(struct skb_defer_node *sdn, int budget) { struct llist_node *free_list; struct sk_buff *skb, *next; + + if (llist_empty(&sdn->defer_list)) + return; + atomic_long_set(&sdn->defer_count, 0); + free_list = llist_del_all(&sdn->defer_list); + + llist_for_each_entry_safe(skb, next, free_list, ll_node) { + prefetch(next); + napi_consume_skb(skb, budget); + } +} + +void skb_defer_node_flush(struct skb_defer_node *sdn) +{ + __skb_defer_free_flush(sdn, 0); +} + +static void skb_defer_free_flush(void) +{ struct skb_defer_node *sdn; int node; for_each_online_node(node) { sdn = this_cpu_ptr(net_hotdata.skb_defer_nodes) + node; - - if (llist_empty(&sdn->defer_list)) - continue; - atomic_long_set(&sdn->defer_count, 0); - free_list = llist_del_all(&sdn->defer_list); - - llist_for_each_entry_safe(skb, next, free_list, ll_node) { - napi_consume_skb(skb, 1); - } + __skb_defer_free_flush(sdn, 1); } } @@ -12704,6 +12716,7 @@ static int dev_cpu_dead(unsigned int oldcpu) struct sk_buff **list_skb; struct sk_buff *skb; unsigned int cpu; + int node; struct softnet_data *sd, *oldsd, *remsd = NULL; local_irq_disable(); @@ -12764,6 +12777,17 @@ static int dev_cpu_dead(unsigned int oldcpu) rps_input_queue_head_incr(oldsd); } + for_each_node(node) + skb_defer_node_flush(per_cpu_ptr(net_hotdata.skb_defer_nodes, + oldcpu) + node); + node = cpu_to_node(oldcpu); + if (node_possible(node) && + !cpumask_intersects(cpumask_of_node(node), cpu_online_mask)) { + for_each_possible_cpu(cpu) + skb_defer_node_flush(per_cpu_ptr(net_hotdata.skb_defer_nodes, + cpu) + node); + } + return 0; } diff --git a/net/core/dev.h b/net/core/dev.h index 6a84413e673ae..7e5bce3c78e3a 100644 --- a/net/core/dev.h +++ b/net/core/dev.h @@ -360,6 +360,8 @@ static inline void napi_assert_will_not_race(const struct napi_struct *napi) WARN_ON(READ_ONCE(napi->list_owner) != -1); } +struct skb_defer_node; +void skb_defer_node_flush(struct skb_defer_node *sdn); void kick_defer_list_purge(unsigned int cpu); int dev_set_hwtstamp_phylib(struct net_device *dev, diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 07df2030ccf2a..60eb8b4328f89 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -7324,10 +7324,12 @@ void skb_attempt_defer_free(struct sk_buff *skb) struct skb_defer_node *sdn; unsigned long defer_count; int cpu = skb->alloc_cpu; + int my_cpu; unsigned int defer_max; bool kick; - if (cpu == raw_smp_processor_id() || + my_cpu = raw_smp_processor_id(); + if (cpu == my_cpu || WARN_ON_ONCE(cpu >= nr_cpu_ids) || !cpu_online(cpu)) { nodefer: kfree_skb_napi_cache(skb); @@ -7338,7 +7340,7 @@ nodefer: kfree_skb_napi_cache(skb); DEBUG_NET_WARN_ON_ONCE(skb->destructor); DEBUG_NET_WARN_ON_ONCE(skb_nfct(skb)); - sdn = per_cpu_ptr(net_hotdata.skb_defer_nodes, cpu) + numa_node_id(); + sdn = per_cpu_ptr(net_hotdata.skb_defer_nodes, cpu) + cpu_to_node(my_cpu); defer_max = READ_ONCE(net_hotdata.sysctl_skb_defer_max); defer_count = atomic_long_inc_return(&sdn->defer_count); @@ -7348,6 +7350,11 @@ nodefer: kfree_skb_napi_cache(skb); llist_add(&skb->ll_node, &sdn->defer_list); + if (unlikely(!cpu_online(cpu) || my_cpu != raw_smp_processor_id())) { + skb_defer_node_flush(sdn); + return; + } + /* Send an IPI every time queue reaches half capacity. */ kick = (defer_count - 1) == (defer_max >> 1); -- 2.53.0