From: Mohsin Bashir <mohsin.bashr@gmail.com>
To: netdev@vger.kernel.org
Cc: kuba@kernel.org, andrew+netdev@lunn.ch, davem@davemloft.net,
edumazet@google.com, pabeni@redhat.com, shuah@kernel.org,
horms@kernel.org, cratiu@nvidia.com, noren@nvidia.com,
cjubran@nvidia.com, mbloch@nvidia.com, mohsin.bashr@gmail.com,
jdamato@fastly.com, gal@nvidia.com, sdf@fomichev.me,
ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org,
john.fastabend@gmail.com, nathan@kernel.org,
nick.desaulniers+lkml@gmail.com, morbo@google.com,
justinstitt@google.com, bpf@vger.kernel.org,
linux-kselftest@vger.kernel.org, llvm@lists.linux.dev
Subject: [PATCH net-next V6 1/5] net: netdevsim: hook in XDP handling
Date: Sat, 19 Jul 2025 01:30:55 -0700 [thread overview]
Message-ID: <20250719083059.3209169-2-mohsin.bashr@gmail.com> (raw)
In-Reply-To: <20250719083059.3209169-1-mohsin.bashr@gmail.com>
From: Jakub Kicinski <kuba@kernel.org>
Add basic XDP support by hooking in do_xdp_generic().
This should be enough to validate most basic XDP tests.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <mohsin.bashr@gmail.com>
---
drivers/net/netdevsim/netdev.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index 611e7f65291c..a7628f5c09af 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -387,15 +387,34 @@ static int nsim_get_iflink(const struct net_device *dev)
static int nsim_rcv(struct nsim_rq *rq, int budget)
{
struct net_device *dev = rq->napi.dev;
+ struct bpf_prog *xdp_prog;
+ struct netdevsim *ns;
struct sk_buff *skb;
unsigned int skblen;
int i, ret;
+ ns = netdev_priv(dev);
+ xdp_prog = READ_ONCE(ns->xdp.prog);
+
for (i = 0; i < budget; i++) {
if (skb_queue_empty(&rq->skb_queue))
break;
skb = skb_dequeue(&rq->skb_queue);
+
+ if (xdp_prog) {
+ /* skb might be freed directly by XDP, save the len */
+ skblen = skb->len;
+
+ if (skb->ip_summed == CHECKSUM_PARTIAL)
+ skb_checksum_help(skb);
+ ret = do_xdp_generic(xdp_prog, &skb);
+ if (ret != XDP_PASS) {
+ dev_dstats_rx_add(dev, skblen);
+ continue;
+ }
+ }
+
/* skb might be discard at netif_receive_skb, save the len */
skblen = skb->len;
skb_mark_napi_id(skb, &rq->napi);
@@ -936,7 +955,7 @@ static void nsim_setup(struct net_device *dev)
NETIF_F_TSO;
dev->pcpu_stat_type = NETDEV_PCPU_STAT_DSTATS;
dev->max_mtu = ETH_MAX_MTU;
- dev->xdp_features = NETDEV_XDP_ACT_HW_OFFLOAD;
+ dev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_HW_OFFLOAD;
}
static int nsim_queue_init(struct netdevsim *ns)
--
2.47.1
next prev parent reply other threads:[~2025-07-19 8:31 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-19 8:30 [PATCH net-next V6 0/5] selftests: drv-net: Test XDP native support Mohsin Bashir
2025-07-19 8:30 ` Mohsin Bashir [this message]
2025-07-19 8:30 ` [PATCH net-next V6 2/5] selftests: drv-net: Test XDP_PASS/DROP support Mohsin Bashir
2025-07-21 11:43 ` Nimrod Oren
2025-07-21 15:40 ` Jakub Kicinski
2025-07-21 18:34 ` Gal Pressman
2025-07-21 20:33 ` Jakub Kicinski
2025-07-22 7:21 ` Gal Pressman
2025-07-22 13:49 ` Jakub Kicinski
2025-07-22 15:03 ` Paolo Abeni
2025-07-23 6:17 ` Gal Pressman
2025-07-21 19:43 ` Martin KaFai Lau
2025-07-21 20:24 ` Jakub Kicinski
2025-07-19 8:30 ` [PATCH net-next V6 3/5] selftests: drv-net: Test XDP_TX support Mohsin Bashir
2025-07-19 8:30 ` [PATCH net-next V6 4/5] selftests: drv-net: Test tail-adjustment support Mohsin Bashir
2025-07-19 8:30 ` [PATCH net-next V6 5/5] selftests: drv-net: Test head-adjustment support Mohsin Bashir
2025-07-23 1:30 ` [PATCH net-next V6 0/5] selftests: drv-net: Test XDP native support patchwork-bot+netdevbpf
2025-07-23 7:11 ` Gal Pressman
2025-07-23 14:12 ` Jakub Kicinski
2025-07-23 16:01 ` Gal Pressman
2025-07-24 9:05 ` Simon Horman
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=20250719083059.3209169-2-mohsin.bashr@gmail.com \
--to=mohsin.bashr@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cjubran@nvidia.com \
--cc=cratiu@nvidia.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=jdamato@fastly.com \
--cc=john.fastabend@gmail.com \
--cc=justinstitt@google.com \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=mbloch@nvidia.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=noren@nvidia.com \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
/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).