From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDFB635674F for ; Tue, 7 Jul 2026 15:49:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783439350; cv=none; b=YP7jm50ynYeUYMR1b6Grk6kkB6oinIknWcwZYWh7Fh2g0lVN8d2coNROJMxkU1h5smLKBaNHcy5Gp1VcMPSJAe5bx+Yy8kmZJ45s5bJ5jWl8CEwFZ0RMGFvGlOeSHe/XetI2JjRmu+sDEhgrk64CDRwOehMncO2SaplT56tLXew= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783439350; c=relaxed/simple; bh=dYXESmoZyq6+W/erTtepBlbqYIfMAToFJFCgX3m7wrc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y/Xq4y9siDsadO4GPbp1MKMNXADbY9ylyemIXySSzZQ0bW+L5ogRVa+7jSm5UwTsQuOvLUymfKyZnHYUK5E7Y4pEShm4pNHiZdbfVVAkWaksqdY7zTI+8u76yVAcNsV6/7T+a2EqGf0FMUnPoTSePBNzhpgobFjsjLrj57ginpA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bhx3VxuL; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bhx3VxuL" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2cc61541f8cso12258015ad.0 for ; Tue, 07 Jul 2026 08:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783439348; x=1784044148; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nX55HcCIgXeNDSs6UhoDWW9a/lSkFkcblQdBU0BYucI=; b=bhx3VxuLFtcR9s3Lw2T8b2vycj4p3tzVgjpZ3rXjYtlZ2J54WcBrbD8t8ezps805sz dOgo3VkqbLSTtpOXwlQRGL2TPLhCYi81Vupj0yivhtuU9euJBxLPDRKvH4F8HrsloMkb OwqnjwyjZGYfrISSKLE2ayo6X3wgAkqj5uTZpcuJ3WWUjf1C5pdZu4YK4LfStKvZUkUR qRvftOYF2Wzp7Mv5ce7YT6xuVzC0ASJdmHUJlsce34uD3Sm0x1Uznf8cubUmhtxWL9uD HclEiPlNHsZv+QSOH/Se4eIOEVPLRy70g4P4zJwmXbPfial9RXcBUFy1Totxhwe1nkQl 31hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783439348; x=1784044148; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nX55HcCIgXeNDSs6UhoDWW9a/lSkFkcblQdBU0BYucI=; b=XsqzDItNxouPp8dZKBNeUXyNFh77CmQet+XwLEFIspQWSfaX3JON/2hDZbPaHehdK1 6ih48O45JrCXkMxe7+MHk9r2vwi/CVL4L75srdtwk+nQdwTsGv6AZNOEEBBbpDcSTXXY hZpMvziPmvV7LRk1RQ5NnSPuqAzkXql/E0Xk/Wlrco5sEXe2EXtMUtRgwj5yUCQ779p5 Bd2LXCqDQnwYgSg0G1/it4shw+xxHEfEAqLrTUdT5CoJdMAp8IVC3SteT4Q6e1wz+hF7 9IgvumiySP4RD5e6MnDdS5LLlY8NzHY5t4OF94ukv55lLRWV7Mc09ZUqfLQ+I/vUBogt 4H8w== X-Gm-Message-State: AOJu0YzfJdDqJjWUuyhPuXccE5wmfTYkB/ukRgyRX4SryHZ+iv9pDEs5 qw+T2G5qdLDlPLFlV76G4aEXfAtc3w5YqT4q0+xP1Xj+JRqL/8plk3Gp X-Gm-Gg: AfdE7cl996mUsRhr9GiZJ3hb+EfjGP3GybBV5y7W3arWEneq6sehbQGafppuOTx+a5+ vGvi2/FxyKwcMwcb+kcGIOXTmGduWeLC5bEdlnn20rYjgWJik0Kc0VQEzBSaEqxqfs0gCCb2M2U UIfNwjMpFITAg0jbe/nCO2PJFpmtyAy4+geFTyN/2Na8HGQVAsWLJnJvtHfHs/7Gs/iOzX91ncA EWk2ZVkRYJAYlpW96GgnP1h1/nSRi+IB6L5gFA6UvR+ONkxep23L3NGtjhXHLiIbToiXZ1J249l zpVYbdEWxwEbIybJhM26PUiAxKw8k6lGo+p+FURKXxK/L7YXzEf0ezPdZByfC6rxo5/8qIPD2S9 Lj+/c5rMNc5wHQlkwpHjgrN1dBxMOW289BIHQJbet9NHFj+we5+0f7/VFi9A9781qheUcLuNvb0 Cy/5/AMje9Q8TeSHn+PID/yGcUqPo= X-Received: by 2002:a17:903:17c5:b0:2cc:6410:91b0 with SMTP id d9443c01a7336-2cccab18af2mr29269575ad.8.1783439348000; Tue, 07 Jul 2026 08:49:08 -0700 (PDT) Received: from localhost.localdomain ([202.8.105.118]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ccc9d3da55sm14315465ad.71.2026.07.07.08.49.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 07 Jul 2026 08:49:07 -0700 (PDT) From: Jemmy Wong To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, "Jemmy Wong" Subject: [RESEND PATCH] net/core: consolidate RPS dispatch into netif_rps() helpers Date: Tue, 7 Jul 2026 23:48:55 +0800 Message-ID: <20260707154855.12134-1-jemmywong512@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260702152830.39065-1-jemmywong512@gmail.com> References: <20260702152830.39065-1-jemmywong512@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Jemmy Wong" The RPS steering logic in netif_rx_internal(), netif_receive_skb_internal() and netif_receive_skb_list_internal() was open-coded three times, each with its own #ifdef CONFIG_RPS block and manual rcu_read_lock()/unlock() pairs. Factor it into two helpers, netif_rps() for the single-skb path and netif_rps_list() for the list path, and switch the callers to guard(rcu)/scoped_guard(rcu). A new internal NET_RX_UNHANDLED sentinel lets a helper report "RPS did not take this skb" so the caller falls back to the local enqueue / __netif_receive_skb() path; it never escapes to callers. netif_rps_list() keeps the early static_branch_unlikely(&rps_needed) bail out so the list is not needlessly walked and re-spliced when RPS is compiled in but disabled. No functional change intended. Signed-off-by: Jemmy Wong --- include/linux/netdevice.h | 5 ++- net/core/dev.c | 94 +++++++++++++++++++-------------------- 2 files changed, 48 insertions(+), 51 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 9981d637f8b5..c265b78082e3 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -93,8 +93,9 @@ void netdev_set_default_ethtool_ops(struct net_device *dev, void netdev_sw_irq_coalesce_default_on(struct net_device *dev); /* Backlog congestion levels */ -#define NET_RX_SUCCESS 0 /* keep 'em coming, baby */ -#define NET_RX_DROP 1 /* packet dropped */ +#define NET_RX_UNHANDLED -1 +#define NET_RX_SUCCESS 0 +#define NET_RX_DROP 1 #define MAX_NEST_DEV 8 diff --git a/net/core/dev.c b/net/core/dev.c index 4b3d5cfdf6e0..259f8c8e5657 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5426,6 +5426,38 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu, return NET_RX_DROP; } +static inline int netif_rps(struct sk_buff *skb) +{ +#ifdef CONFIG_RPS + if (static_branch_unlikely(&rps_needed)) { + struct rps_dev_flow voidflow, *rflow = &voidflow; + int cpu = get_rps_cpu(skb->dev, skb, &rflow); + + if (cpu >= 0) + return enqueue_to_backlog(skb, cpu, &rflow->last_qtail); + } +#endif + return NET_RX_UNHANDLED; +} + +static inline void netif_rps_list(struct list_head *head) +{ +#ifdef CONFIG_RPS + struct sk_buff *skb, *next; + LIST_HEAD(undo_list); + + if (!static_branch_unlikely(&rps_needed)) + return; + + list_for_each_entry_safe(skb, next, head, list) { + skb_list_del_init(skb); + if (netif_rps(skb) == NET_RX_UNHANDLED) + list_add_tail(&skb->list, &undo_list); + } + list_splice_init(&undo_list, head); +#endif +} + static struct netdev_rx_queue *netif_get_rxqueue(struct sk_buff *skb) { struct net_device *dev = skb->dev; @@ -5695,33 +5727,20 @@ EXPORT_SYMBOL_GPL(do_xdp_generic); static int netif_rx_internal(struct sk_buff *skb) { - int ret; + int ret = NET_RX_UNHANDLED; + unsigned int qtail; net_timestamp_check(READ_ONCE(net_hotdata.tstamp_prequeue), skb); trace_netif_rx(skb); -#ifdef CONFIG_RPS - if (static_branch_unlikely(&rps_needed)) { - struct rps_dev_flow voidflow, *rflow = &voidflow; - int cpu; - - rcu_read_lock(); - - cpu = get_rps_cpu(skb->dev, skb, &rflow); - if (cpu < 0) - cpu = smp_processor_id(); + scoped_guard(rcu) + ret = netif_rps(skb); + if (ret != NET_RX_UNHANDLED) + return ret; - ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail); + ret = enqueue_to_backlog(skb, smp_processor_id(), &qtail); - rcu_read_unlock(); - } else -#endif - { - unsigned int qtail; - - ret = enqueue_to_backlog(skb, smp_processor_id(), &qtail); - } return ret; } @@ -6389,21 +6408,12 @@ static int netif_receive_skb_internal(struct sk_buff *skb) if (skb_defer_rx_timestamp(skb)) return NET_RX_SUCCESS; - rcu_read_lock(); -#ifdef CONFIG_RPS - if (static_branch_unlikely(&rps_needed)) { - struct rps_dev_flow voidflow, *rflow = &voidflow; - int cpu = get_rps_cpu(skb->dev, skb, &rflow); + guard(rcu)(); + ret = netif_rps(skb); + if (ret != NET_RX_UNHANDLED) + return ret; - if (cpu >= 0) { - ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail); - rcu_read_unlock(); - return ret; - } - } -#endif ret = __netif_receive_skb(skb); - rcu_read_unlock(); return ret; } @@ -6421,23 +6431,9 @@ void netif_receive_skb_list_internal(struct list_head *head) } list_splice_init(&sublist, head); - rcu_read_lock(); -#ifdef CONFIG_RPS - if (static_branch_unlikely(&rps_needed)) { - list_for_each_entry_safe(skb, next, head, list) { - struct rps_dev_flow voidflow, *rflow = &voidflow; - int cpu = get_rps_cpu(skb->dev, skb, &rflow); - - if (cpu >= 0) { - /* Will be handled, remove from list */ - skb_list_del_init(skb); - enqueue_to_backlog(skb, cpu, &rflow->last_qtail); - } - } - } -#endif + guard(rcu)(); + netif_rps_list(head); __netif_receive_skb_list(head); - rcu_read_unlock(); } /** -- 2.25.1