Re: [RFC PATCH net-next v2 2/2] selftests: net: add XDP socket tests for virtio-net

2025-06-03 Thread Bui Quang Minh

On 6/2/25 22:55, Maciej Fijalkowski wrote:

On Sat, May 31, 2025 at 03:51:57PM +0700, Bui Quang Minh wrote:

On 5/30/25 18:45, Maciej Fijalkowski wrote:

On Thu, May 29, 2025 at 09:29:14PM +0700, Bui Quang Minh wrote:

On 5/29/25 18:18, Maciej Fijalkowski wrote:

On Tue, May 27, 2025 at 11:19:04PM +0700, Bui Quang Minh wrote:

This adds a test to test the virtio-net rx when there is a XDP socket
bound to it. There are tests for both copy mode and zerocopy mode, both
cases when XDP program returns XDP_PASS and XDP_REDIRECT to a XDP socket.

Signed-off-by: Bui Quang Minh 

Hi Bui,

have you considered adjusting xskxceiver for your needs? If yes and you
decided to go with another test app then what were the issues around it?

This is yet another approach for xsk testing where we already have a
test framework.

Hi,

I haven't tried much hard to adapt xskxceiver. I did have a look at
xskxceiver but I felt the supported topology is not suitable for my need. To
test the receiving side in virtio-net, I use Qemu to set up virtio-net in
the guest and vhost-net in the host side. The sending side is in the host
and the receiving is in the guest so I can't figure out how to do that with
xskxceiver.

I see - couldn't the python side be executing xdpsock then instead of your
own app?

I'm not aware of xdpsock. Could you give the path to that file?

https://github.com/xdp-project/bpf-examples/tree/main/AF_XDP-example

this is our go-to app side of AF_XDP.


Thanks, I'll take a look at it and try to use it for selftest if 
possible in next version.


Quang Minh.



Re: [RFC PATCH net-next v2 2/2] selftests: net: add XDP socket tests for virtio-net

2025-06-02 Thread Maciej Fijalkowski
On Sat, May 31, 2025 at 03:51:57PM +0700, Bui Quang Minh wrote:
> On 5/30/25 18:45, Maciej Fijalkowski wrote:
> > On Thu, May 29, 2025 at 09:29:14PM +0700, Bui Quang Minh wrote:
> > > On 5/29/25 18:18, Maciej Fijalkowski wrote:
> > > > On Tue, May 27, 2025 at 11:19:04PM +0700, Bui Quang Minh wrote:
> > > > > This adds a test to test the virtio-net rx when there is a XDP socket
> > > > > bound to it. There are tests for both copy mode and zerocopy mode, 
> > > > > both
> > > > > cases when XDP program returns XDP_PASS and XDP_REDIRECT to a XDP 
> > > > > socket.
> > > > > 
> > > > > Signed-off-by: Bui Quang Minh 
> > > > Hi Bui,
> > > > 
> > > > have you considered adjusting xskxceiver for your needs? If yes and you
> > > > decided to go with another test app then what were the issues around it?
> > > > 
> > > > This is yet another approach for xsk testing where we already have a
> > > > test framework.
> > > Hi,
> > > 
> > > I haven't tried much hard to adapt xskxceiver. I did have a look at
> > > xskxceiver but I felt the supported topology is not suitable for my need. 
> > > To
> > > test the receiving side in virtio-net, I use Qemu to set up virtio-net in
> > > the guest and vhost-net in the host side. The sending side is in the host
> > > and the receiving is in the guest so I can't figure out how to do that 
> > > with
> > > xskxceiver.
> > I see - couldn't the python side be executing xdpsock then instead of your
> > own app?
> 
> I'm not aware of xdpsock. Could you give the path to that file?

https://github.com/xdp-project/bpf-examples/tree/main/AF_XDP-example

this is our go-to app side of AF_XDP.

> 
> > I wouldn't like to end up with several xsk tools for testing data path on
> > different environments.



Re: [RFC PATCH net-next v2 2/2] selftests: net: add XDP socket tests for virtio-net

2025-05-31 Thread Bui Quang Minh

On 5/30/25 18:45, Maciej Fijalkowski wrote:

On Thu, May 29, 2025 at 09:29:14PM +0700, Bui Quang Minh wrote:

On 5/29/25 18:18, Maciej Fijalkowski wrote:

On Tue, May 27, 2025 at 11:19:04PM +0700, Bui Quang Minh wrote:

This adds a test to test the virtio-net rx when there is a XDP socket
bound to it. There are tests for both copy mode and zerocopy mode, both
cases when XDP program returns XDP_PASS and XDP_REDIRECT to a XDP socket.

Signed-off-by: Bui Quang Minh 

Hi Bui,

have you considered adjusting xskxceiver for your needs? If yes and you
decided to go with another test app then what were the issues around it?

This is yet another approach for xsk testing where we already have a
test framework.

Hi,

I haven't tried much hard to adapt xskxceiver. I did have a look at
xskxceiver but I felt the supported topology is not suitable for my need. To
test the receiving side in virtio-net, I use Qemu to set up virtio-net in
the guest and vhost-net in the host side. The sending side is in the host
and the receiving is in the guest so I can't figure out how to do that with
xskxceiver.

I see - couldn't the python side be executing xdpsock then instead of your
own app?


I'm not aware of xdpsock. Could you give the path to that file?


I wouldn't like to end up with several xsk tools for testing data path on
different environments.




Re: [RFC PATCH net-next v2 2/2] selftests: net: add XDP socket tests for virtio-net

2025-05-30 Thread Maciej Fijalkowski
On Thu, May 29, 2025 at 09:29:14PM +0700, Bui Quang Minh wrote:
> On 5/29/25 18:18, Maciej Fijalkowski wrote:
> > On Tue, May 27, 2025 at 11:19:04PM +0700, Bui Quang Minh wrote:
> > > This adds a test to test the virtio-net rx when there is a XDP socket
> > > bound to it. There are tests for both copy mode and zerocopy mode, both
> > > cases when XDP program returns XDP_PASS and XDP_REDIRECT to a XDP socket.
> > > 
> > > Signed-off-by: Bui Quang Minh 
> > Hi Bui,
> > 
> > have you considered adjusting xskxceiver for your needs? If yes and you
> > decided to go with another test app then what were the issues around it?
> > 
> > This is yet another approach for xsk testing where we already have a
> > test framework.
> 
> Hi,
> 
> I haven't tried much hard to adapt xskxceiver. I did have a look at
> xskxceiver but I felt the supported topology is not suitable for my need. To
> test the receiving side in virtio-net, I use Qemu to set up virtio-net in
> the guest and vhost-net in the host side. The sending side is in the host
> and the receiving is in the guest so I can't figure out how to do that with
> xskxceiver.

I see - couldn't the python side be executing xdpsock then instead of your
own app?

I wouldn't like to end up with several xsk tools for testing data path on
different environments.

> 
> Thanks,
> Quang Minh.
> 
> > 



Re: [RFC PATCH net-next v2 2/2] selftests: net: add XDP socket tests for virtio-net

2025-05-29 Thread Bui Quang Minh

On 5/29/25 18:18, Maciej Fijalkowski wrote:

On Tue, May 27, 2025 at 11:19:04PM +0700, Bui Quang Minh wrote:

This adds a test to test the virtio-net rx when there is a XDP socket
bound to it. There are tests for both copy mode and zerocopy mode, both
cases when XDP program returns XDP_PASS and XDP_REDIRECT to a XDP socket.

Signed-off-by: Bui Quang Minh 

Hi Bui,

have you considered adjusting xskxceiver for your needs? If yes and you
decided to go with another test app then what were the issues around it?

This is yet another approach for xsk testing where we already have a
test framework.


Hi,

I haven't tried much hard to adapt xskxceiver. I did have a look at 
xskxceiver but I felt the supported topology is not suitable for my 
need. To test the receiving side in virtio-net, I use Qemu to set up 
virtio-net in the guest and vhost-net in the host side. The sending side 
is in the host and the receiving is in the guest so I can't figure out 
how to do that with xskxceiver.


Thanks,
Quang Minh.




---
  .../selftests/drivers/net/hw/.gitignore   |   3 +
  .../testing/selftests/drivers/net/hw/Makefile |  12 +-
  .../drivers/net/hw/xsk_receive.bpf.c  |  43 ++
  .../selftests/drivers/net/hw/xsk_receive.c| 398 ++
  .../selftests/drivers/net/hw/xsk_receive.py   |  75 
  5 files changed, 530 insertions(+), 1 deletion(-)
  create mode 100644 tools/testing/selftests/drivers/net/hw/xsk_receive.bpf.c
  create mode 100644 tools/testing/selftests/drivers/net/hw/xsk_receive.c
  create mode 100755 tools/testing/selftests/drivers/net/hw/xsk_receive.py

diff --git a/tools/testing/selftests/drivers/net/hw/.gitignore 
b/tools/testing/selftests/drivers/net/hw/.gitignore
index 6942bf575497..c32271faecff 100644
--- a/tools/testing/selftests/drivers/net/hw/.gitignore
+++ b/tools/testing/selftests/drivers/net/hw/.gitignore
@@ -1,3 +1,6 @@
  # SPDX-License-Identifier: GPL-2.0-only
  iou-zcrx
  ncdevmem
+xsk_receive.skel.h
+xsk_receive
+tools
diff --git a/tools/testing/selftests/drivers/net/hw/Makefile 
b/tools/testing/selftests/drivers/net/hw/Makefile
index df2c047ffa90..964edbb3b79f 100644
--- a/tools/testing/selftests/drivers/net/hw/Makefile
+++ b/tools/testing/selftests/drivers/net/hw/Makefile
@@ -1,6 +1,9 @@
  # SPDX-License-Identifier: GPL-2.0+ OR MIT
  
-TEST_GEN_FILES = iou-zcrx

+TEST_GEN_FILES = \
+   iou-zcrx \
+   xsk_receive \
+   #
  
  TEST_PROGS = \

csum.py \
@@ -20,6 +23,7 @@ TEST_PROGS = \
rss_input_xfrm.py \
tso.py \
xsk_reconfig.py \
+   xsk_receive.py \
#
  
  TEST_FILES := \

@@ -48,3 +52,9 @@ include ../../../net/ynl.mk
  include ../../../net/bpf.mk
  
  $(OUTPUT)/iou-zcrx: LDLIBS += -luring

+
+$(OUTPUT)/xsk_receive.skel.h: xsk_receive.bpf.o
+   bpftool gen skeleton xsk_receive.bpf.o > xsk_receive.skel.h
+
+$(OUTPUT)/xsk_receive: xsk_receive.skel.h
+$(OUTPUT)/xsk_receive: LDLIBS += -lbpf
diff --git a/tools/testing/selftests/drivers/net/hw/xsk_receive.bpf.c 
b/tools/testing/selftests/drivers/net/hw/xsk_receive.bpf.c
new file mode 100644
index ..462046d95bfe
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/hw/xsk_receive.bpf.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct {
+   __uint(type, BPF_MAP_TYPE_XSKMAP);
+   __uint(max_entries, 1);
+   __uint(key_size, sizeof(__u32));
+   __uint(value_size, sizeof(__u32));
+} xsk_map SEC(".maps");
+
+SEC("xdp.frags")
+int dummy_prog(struct xdp_md *ctx)
+{
+   return XDP_PASS;
+}
+
+SEC("xdp.frags")
+int redirect_xsk_prog(struct xdp_md *ctx)
+{
+   void *data_end = (void *)(long)ctx->data_end;
+   void *data = (void *)(long)ctx->data;
+   struct ethhdr *eth = data;
+   struct iphdr *iph;
+
+   if (data + sizeof(*eth) + sizeof(*iph) > data_end)
+   return XDP_PASS;
+
+   if (bpf_htons(eth->h_proto) != ETH_P_IP)
+   return XDP_PASS;
+
+   iph = data + sizeof(*eth);
+   if (iph->protocol != IPPROTO_UDP)
+   return XDP_PASS;
+
+   return bpf_redirect_map(&xsk_map, 0, XDP_DROP);
+}
+
+char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/drivers/net/hw/xsk_receive.c 
b/tools/testing/selftests/drivers/net/hw/xsk_receive.c
new file mode 100644
index ..96213ceeda5c
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/hw/xsk_receive.c
@@ -0,0 +1,398 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "xsk_receive.skel.h"
+
+#define load_acquire(p) \
+   atomic_load_explicit((_Atomic typeof(*(p)) *)(p), memory_order_acquire)
+
+#define store_release(p, v) \
+   atomic_store_explicit((_Atomic typeof(*(p)) *)(p), v, \
+ memory_order_release)
+
+#define UMEM_CHUNK_SI

Re: [RFC PATCH net-next v2 2/2] selftests: net: add XDP socket tests for virtio-net

2025-05-29 Thread Maciej Fijalkowski
On Tue, May 27, 2025 at 11:19:04PM +0700, Bui Quang Minh wrote:
> This adds a test to test the virtio-net rx when there is a XDP socket
> bound to it. There are tests for both copy mode and zerocopy mode, both
> cases when XDP program returns XDP_PASS and XDP_REDIRECT to a XDP socket.
> 
> Signed-off-by: Bui Quang Minh 

Hi Bui,

have you considered adjusting xskxceiver for your needs? If yes and you
decided to go with another test app then what were the issues around it?

This is yet another approach for xsk testing where we already have a
test framework.

> ---
>  .../selftests/drivers/net/hw/.gitignore   |   3 +
>  .../testing/selftests/drivers/net/hw/Makefile |  12 +-
>  .../drivers/net/hw/xsk_receive.bpf.c  |  43 ++
>  .../selftests/drivers/net/hw/xsk_receive.c| 398 ++
>  .../selftests/drivers/net/hw/xsk_receive.py   |  75 
>  5 files changed, 530 insertions(+), 1 deletion(-)
>  create mode 100644 tools/testing/selftests/drivers/net/hw/xsk_receive.bpf.c
>  create mode 100644 tools/testing/selftests/drivers/net/hw/xsk_receive.c
>  create mode 100755 tools/testing/selftests/drivers/net/hw/xsk_receive.py
> 
> diff --git a/tools/testing/selftests/drivers/net/hw/.gitignore 
> b/tools/testing/selftests/drivers/net/hw/.gitignore
> index 6942bf575497..c32271faecff 100644
> --- a/tools/testing/selftests/drivers/net/hw/.gitignore
> +++ b/tools/testing/selftests/drivers/net/hw/.gitignore
> @@ -1,3 +1,6 @@
>  # SPDX-License-Identifier: GPL-2.0-only
>  iou-zcrx
>  ncdevmem
> +xsk_receive.skel.h
> +xsk_receive
> +tools
> diff --git a/tools/testing/selftests/drivers/net/hw/Makefile 
> b/tools/testing/selftests/drivers/net/hw/Makefile
> index df2c047ffa90..964edbb3b79f 100644
> --- a/tools/testing/selftests/drivers/net/hw/Makefile
> +++ b/tools/testing/selftests/drivers/net/hw/Makefile
> @@ -1,6 +1,9 @@
>  # SPDX-License-Identifier: GPL-2.0+ OR MIT
>  
> -TEST_GEN_FILES = iou-zcrx
> +TEST_GEN_FILES = \
> + iou-zcrx \
> + xsk_receive \
> + #
>  
>  TEST_PROGS = \
>   csum.py \
> @@ -20,6 +23,7 @@ TEST_PROGS = \
>   rss_input_xfrm.py \
>   tso.py \
>   xsk_reconfig.py \
> + xsk_receive.py \
>   #
>  
>  TEST_FILES := \
> @@ -48,3 +52,9 @@ include ../../../net/ynl.mk
>  include ../../../net/bpf.mk
>  
>  $(OUTPUT)/iou-zcrx: LDLIBS += -luring
> +
> +$(OUTPUT)/xsk_receive.skel.h: xsk_receive.bpf.o
> + bpftool gen skeleton xsk_receive.bpf.o > xsk_receive.skel.h
> +
> +$(OUTPUT)/xsk_receive: xsk_receive.skel.h
> +$(OUTPUT)/xsk_receive: LDLIBS += -lbpf
> diff --git a/tools/testing/selftests/drivers/net/hw/xsk_receive.bpf.c 
> b/tools/testing/selftests/drivers/net/hw/xsk_receive.bpf.c
> new file mode 100644
> index ..462046d95bfe
> --- /dev/null
> +++ b/tools/testing/selftests/drivers/net/hw/xsk_receive.bpf.c
> @@ -0,0 +1,43 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +struct {
> + __uint(type, BPF_MAP_TYPE_XSKMAP);
> + __uint(max_entries, 1);
> + __uint(key_size, sizeof(__u32));
> + __uint(value_size, sizeof(__u32));
> +} xsk_map SEC(".maps");
> +
> +SEC("xdp.frags")
> +int dummy_prog(struct xdp_md *ctx)
> +{
> + return XDP_PASS;
> +}
> +
> +SEC("xdp.frags")
> +int redirect_xsk_prog(struct xdp_md *ctx)
> +{
> + void *data_end = (void *)(long)ctx->data_end;
> + void *data = (void *)(long)ctx->data;
> + struct ethhdr *eth = data;
> + struct iphdr *iph;
> +
> + if (data + sizeof(*eth) + sizeof(*iph) > data_end)
> + return XDP_PASS;
> +
> + if (bpf_htons(eth->h_proto) != ETH_P_IP)
> + return XDP_PASS;
> +
> + iph = data + sizeof(*eth);
> + if (iph->protocol != IPPROTO_UDP)
> + return XDP_PASS;
> +
> + return bpf_redirect_map(&xsk_map, 0, XDP_DROP);
> +}
> +
> +char _license[] SEC("license") = "GPL";
> diff --git a/tools/testing/selftests/drivers/net/hw/xsk_receive.c 
> b/tools/testing/selftests/drivers/net/hw/xsk_receive.c
> new file mode 100644
> index ..96213ceeda5c
> --- /dev/null
> +++ b/tools/testing/selftests/drivers/net/hw/xsk_receive.c
> @@ -0,0 +1,398 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "xsk_receive.skel.h"
> +
> +#define load_acquire(p) \
> + atomic_load_explicit((_Atomic typeof(*(p)) *)(p), memory_order_acquire)
> +
> +#define store_release(p, v) \
> + atomic_store_explicit((_Atomic typeof(*(p)) *)(p), v, \
> +   memory_order_release)
> +
> +#define UMEM_CHUNK_SIZE 0x1000
> +#define BUFFER_SIZE 0x2000
> +
> +#define SERVER_PORT 
> +#define CLIENT_PORT 
> +
> +const int num_entries = 256;
> +const char *pass_msg = "PASS";
> +
> +int cfg_client;
> +int cfg_server;
> +char *cfg_server_ip;
> +char *cfg_client_ip;

Re: [RFC PATCH net-next v2 2/2] selftests: net: add XDP socket tests for virtio-net

2025-05-28 Thread Bui Quang Minh

On 5/29/25 00:04, ALOK TIWARI wrote:



On 27-05-2025 21:49, Bui Quang Minh wrote:

+def main():
+    with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+    cfg.bin_local = path.abspath(path.dirname(__file__)
+    + "/../../../drivers/net/hw/xsk_receive")
+    cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
+
+    server_cmd = f"{cfg.bin_remote} -s -i {cfg.remote_ifname} "
+    server_cmd += f"-r {cfg.remote_addr_v["4"]} -l 
{cfg.addr_v["4"]}"

+    client_cmd = f"{cfg.bin_local} -c -r {cfg.remote_addr_v["4"]} "
+    client_cmd += f"-l {cfg.addr_v["4"]}"
+
+    ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, 
server_cmd, client_cmd))

+    ksft_exit()


SyntaxError ?
inner ["4"] uses double quotes, which clash with the outer double 
quotes of the f-string


This works just fine because the ["4"] is inside {}. But I can fix this 
to avoid confusion.


Thanks,
Quang Minh.




Re: [RFC PATCH net-next v2 2/2] selftests: net: add XDP socket tests for virtio-net

2025-05-28 Thread ALOK TIWARI




On 27-05-2025 21:49, Bui Quang Minh wrote:

+def main():
+with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+cfg.bin_local = path.abspath(path.dirname(__file__)
++ "/../../../drivers/net/hw/xsk_receive")
+cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
+
+server_cmd = f"{cfg.bin_remote} -s -i {cfg.remote_ifname} "
+server_cmd += f"-r {cfg.remote_addr_v["4"]} -l {cfg.addr_v["4"]}"
+client_cmd = f"{cfg.bin_local} -c -r {cfg.remote_addr_v["4"]} "
+client_cmd += f"-l {cfg.addr_v["4"]}"
+
+ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, server_cmd, 
client_cmd))
+ksft_exit()


SyntaxError ?
inner ["4"] uses double quotes, which clash with the outer double quotes 
of the f-string


Thanks,
Alok