From: Yue Haibing <yuehaibing@huawei.com>
To: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<pabeni@redhat.com>, <horms@kernel.org>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<yuehaibing@huawei.com>
Subject: [PATCH net-next] net: core: Call netif_get_rxqueue() in get_rps_cpu()
Date: Wed, 29 Apr 2026 20:37:41 +0800 [thread overview]
Message-ID: <20260429123741.3777677-1-yuehaibing@huawei.com> (raw)
Refactor netif_get_rxqueue() return NULL when rxq index checking failed
instead of falling back to first queue, then use it to avoid code
duplication.
Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
---
net/core/dev.c | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index e7bc95cbd1fa..72aef872d03c 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5104,6 +5104,8 @@ set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
return rflow;
}
+static struct netdev_rx_queue *netif_get_rxqueue(struct sk_buff *skb);
+
/*
* get_rps_cpu is called from netif_receive_skb and returns the target
* CPU from the RPS map of the receiving queue for a given skb.
@@ -5112,25 +5114,16 @@ set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
struct rps_dev_flow **rflowp)
{
- struct netdev_rx_queue *rxqueue = dev->_rx;
+ struct netdev_rx_queue *rxqueue;
rps_tag_ptr global_tag_ptr, q_tag_ptr;
struct rps_map *map;
int cpu = -1;
u32 tcpu;
u32 hash;
- if (skb_rx_queue_recorded(skb)) {
- u16 index = skb_get_rx_queue(skb);
-
- if (unlikely(index >= dev->real_num_rx_queues)) {
- WARN_ONCE(dev->real_num_rx_queues > 1,
- "%s received packet on queue %u, but number "
- "of RX queues is %u\n",
- dev->name, index, dev->real_num_rx_queues);
- goto done;
- }
- rxqueue += index;
- }
+ rxqueue = netif_get_rxqueue(skb);
+ if (!rxqueue)
+ goto done;
/* Avoid computing hash if RFS/RPS is not active for this rxqueue */
@@ -5442,8 +5435,7 @@ static struct netdev_rx_queue *netif_get_rxqueue(struct sk_buff *skb)
"%s received packet on queue %u, but number "
"of RX queues is %u\n",
dev->name, index, dev->real_num_rx_queues);
-
- return rxqueue; /* Return first rxqueue */
+ return NULL;
}
rxqueue += index;
}
@@ -5473,6 +5465,8 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp,
frame_sz += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
rxqueue = netif_get_rxqueue(skb);
+ if (!rxqueue)
+ rxqueue = skb->dev->_rx;
xdp_init_buff(xdp, frame_sz, &rxqueue->xdp_rxq);
xdp_prepare_buff(xdp, hard_start, skb_headroom(skb) - mac_len,
skb_headlen(skb) + mac_len, true);
--
2.34.1
next reply other threads:[~2026-04-29 12:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 12:37 Yue Haibing [this message]
2026-04-29 12:31 ` [PATCH net-next] net: core: Call netif_get_rxqueue() in get_rps_cpu() Eric Dumazet
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=20260429123741.3777677-1-yuehaibing@huawei.com \
--to=yuehaibing@huawei.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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).