* [PATCH v5 1/3] selftests: net: move xdp_helper to net/lib
2025-04-24 10:47 [PATCH v5 0/3] virtio-net: disable delayed refill when pausing rx Bui Quang Minh
@ 2025-04-24 10:47 ` Bui Quang Minh
2025-04-24 10:47 ` [PATCH v5 2/3] selftests: net: add flag to force zerocopy mode in xdp_helper Bui Quang Minh
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Bui Quang Minh @ 2025-04-24 10:47 UTC (permalink / raw)
To: virtualization
Cc: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Andrew Lunn,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Eugenio Pérez, David S. Miller, netdev, linux-kernel, bpf,
Bui Quang Minh
Move xdp_helper to net/lib to make it easier for other selftests to use
the helper.
Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
---
tools/testing/selftests/drivers/net/Makefile | 2 --
tools/testing/selftests/drivers/net/queues.py | 4 ++--
tools/testing/selftests/net/lib/.gitignore | 1 +
tools/testing/selftests/net/lib/Makefile | 1 +
tools/testing/selftests/{drivers/net => net/lib}/xdp_helper.c | 0
5 files changed, 4 insertions(+), 4 deletions(-)
rename tools/testing/selftests/{drivers/net => net/lib}/xdp_helper.c (100%)
diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile
index 0c95bd944d56..cd74f1eb3193 100644
--- a/tools/testing/selftests/drivers/net/Makefile
+++ b/tools/testing/selftests/drivers/net/Makefile
@@ -6,8 +6,6 @@ TEST_INCLUDES := $(wildcard lib/py/*.py) \
../../net/net_helper.sh \
../../net/lib.sh \
-TEST_GEN_FILES := xdp_helper
-
TEST_PROGS := \
netcons_basic.sh \
netcons_fragmented_msg.sh \
diff --git a/tools/testing/selftests/drivers/net/queues.py b/tools/testing/selftests/drivers/net/queues.py
index 06abd3f233e1..236005290a33 100755
--- a/tools/testing/selftests/drivers/net/queues.py
+++ b/tools/testing/selftests/drivers/net/queues.py
@@ -26,13 +26,13 @@ def nl_get_queues(cfg, nl, qtype='rx'):
def check_xsk(cfg, nl, xdp_queue_id=0) -> None:
# Probe for support
- xdp = cmd(f'{cfg.test_dir / "xdp_helper"} - -', fail=False)
+ xdp = cmd(f'{cfg.net_lib_dir / "xdp_helper"} - -', fail=False)
if xdp.ret == 255:
raise KsftSkipEx('AF_XDP unsupported')
elif xdp.ret > 0:
raise KsftFailEx('unable to create AF_XDP socket')
- with bkg(f'{cfg.test_dir / "xdp_helper"} {cfg.ifindex} {xdp_queue_id}',
+ with bkg(f'{cfg.net_lib_dir / "xdp_helper"} {cfg.ifindex} {xdp_queue_id}',
ksft_wait=3):
rx = tx = False
diff --git a/tools/testing/selftests/net/lib/.gitignore b/tools/testing/selftests/net/lib/.gitignore
index 1ebc6187f421..bbc97d6bf556 100644
--- a/tools/testing/selftests/net/lib/.gitignore
+++ b/tools/testing/selftests/net/lib/.gitignore
@@ -1,2 +1,3 @@
# SPDX-License-Identifier: GPL-2.0-only
csum
+xdp_helper
diff --git a/tools/testing/selftests/net/lib/Makefile b/tools/testing/selftests/net/lib/Makefile
index c22623b9a2a5..88c4bc461459 100644
--- a/tools/testing/selftests/net/lib/Makefile
+++ b/tools/testing/selftests/net/lib/Makefile
@@ -10,6 +10,7 @@ TEST_FILES += ../../../../net/ynl
TEST_GEN_FILES += csum
TEST_GEN_FILES += $(patsubst %.c,%.o,$(wildcard *.bpf.c))
+TEST_GEN_FILES += xdp_helper
TEST_INCLUDES := $(wildcard py/*.py sh/*.sh)
diff --git a/tools/testing/selftests/drivers/net/xdp_helper.c b/tools/testing/selftests/net/lib/xdp_helper.c
similarity index 100%
rename from tools/testing/selftests/drivers/net/xdp_helper.c
rename to tools/testing/selftests/net/lib/xdp_helper.c
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v5 2/3] selftests: net: add flag to force zerocopy mode in xdp_helper
2025-04-24 10:47 [PATCH v5 0/3] virtio-net: disable delayed refill when pausing rx Bui Quang Minh
2025-04-24 10:47 ` [PATCH v5 1/3] selftests: net: move xdp_helper to net/lib Bui Quang Minh
@ 2025-04-24 10:47 ` Bui Quang Minh
2025-04-24 10:47 ` [PATCH v5 3/3] selftests: net: add a virtio_net deadlock selftest Bui Quang Minh
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Bui Quang Minh @ 2025-04-24 10:47 UTC (permalink / raw)
To: virtualization
Cc: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Andrew Lunn,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Eugenio Pérez, David S. Miller, netdev, linux-kernel, bpf,
Bui Quang Minh
This commit adds an optional -z flag to xdp_helper. When this flag is
provided, the XDP socket binding is forced to be in zerocopy mode.
Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
---
tools/testing/selftests/net/lib/xdp_helper.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/net/lib/xdp_helper.c b/tools/testing/selftests/net/lib/xdp_helper.c
index aeed25914104..f21536ab95ba 100644
--- a/tools/testing/selftests/net/lib/xdp_helper.c
+++ b/tools/testing/selftests/net/lib/xdp_helper.c
@@ -62,6 +62,12 @@ static void ksft_wait(void)
close(fd);
}
+static void print_usage(const char *bin)
+{
+ fprintf(stderr, "Usage: %s ifindex queue_id [-z]\n\n"
+ "where:\n\t-z: force zerocopy mode", bin);
+}
+
/* this is a simple helper program that creates an XDP socket and does the
* minimum necessary to get bind() to succeed.
*
@@ -81,8 +87,8 @@ int main(int argc, char **argv)
int sock_fd;
int queue;
- if (argc != 3) {
- fprintf(stderr, "Usage: %s ifindex queue_id\n", argv[0]);
+ if (argc != 3 && argc != 4) {
+ print_usage(argv[0]);
return 1;
}
@@ -132,6 +138,15 @@ int main(int argc, char **argv)
sxdp.sxdp_queue_id = queue;
sxdp.sxdp_flags = 0;
+ if (argc > 3) {
+ if (!strcmp(argv[3], "-z")) {
+ sxdp.sxdp_flags = XDP_ZEROCOPY;
+ } else {
+ print_usage(argv[0]);
+ return 1;
+ }
+ }
+
if (bind(sock_fd, (struct sockaddr *)&sxdp, sizeof(sxdp)) != 0) {
munmap(umem_area, UMEM_SZ);
perror("bind failed");
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v5 3/3] selftests: net: add a virtio_net deadlock selftest
2025-04-24 10:47 [PATCH v5 0/3] virtio-net: disable delayed refill when pausing rx Bui Quang Minh
2025-04-24 10:47 ` [PATCH v5 1/3] selftests: net: move xdp_helper to net/lib Bui Quang Minh
2025-04-24 10:47 ` [PATCH v5 2/3] selftests: net: add flag to force zerocopy mode in xdp_helper Bui Quang Minh
@ 2025-04-24 10:47 ` Bui Quang Minh
2025-04-24 11:03 ` [PATCH v5 0/3] virtio-net: disable delayed refill when pausing rx Michael S. Tsirkin
2025-04-25 1:34 ` Jakub Kicinski
4 siblings, 0 replies; 7+ messages in thread
From: Bui Quang Minh @ 2025-04-24 10:47 UTC (permalink / raw)
To: virtualization
Cc: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Andrew Lunn,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Eugenio Pérez, David S. Miller, netdev, linux-kernel, bpf,
Bui Quang Minh
The selftest reproduces the deadlock scenario when binding/unbinding XDP
program, XDP socket, rx ring resize on virtio_net interface.
Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
---
.../testing/selftests/drivers/net/hw/Makefile | 1 +
.../selftests/drivers/net/hw/xsk_reconfig.py | 68 +++++++++++++++++++
2 files changed, 69 insertions(+)
create mode 100755 tools/testing/selftests/drivers/net/hw/xsk_reconfig.py
diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile
index 07cddb19ba35..5447785c286e 100644
--- a/tools/testing/selftests/drivers/net/hw/Makefile
+++ b/tools/testing/selftests/drivers/net/hw/Makefile
@@ -21,6 +21,7 @@ TEST_PROGS = \
rss_ctx.py \
rss_input_xfrm.py \
tso.py \
+ xsk_reconfig.py \
#
TEST_FILES := \
diff --git a/tools/testing/selftests/drivers/net/hw/xsk_reconfig.py b/tools/testing/selftests/drivers/net/hw/xsk_reconfig.py
new file mode 100755
index 000000000000..031de97a974d
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/hw/xsk_reconfig.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+# This is intended to be run on a virtio-net guest interface.
+# The test binds the XDP socket to the interface without setting
+# the fill ring to trigger delayed refill_work. This helps to
+# make it easier to reproduce the deadlock when XDP program,
+# XDP socket bind/unbind, rx ring resize race with refill_work on
+# the buggy kernel.
+#
+# The Qemu command to setup virtio-net
+# -netdev tap,id=hostnet1,vhost=on,script=no,downscript=no
+# -device virtio-net-pci,netdev=hostnet1,iommu_platform=on,disable-legacy=on
+
+from lib.py import ksft_exit, ksft_run
+from lib.py import KsftSkipEx, KsftFailEx
+from lib.py import NetDrvEnv
+from lib.py import bkg, ip, cmd, ethtool
+import time
+
+def _get_rx_ring_entries(cfg):
+ output = ethtool(f"-g {cfg.ifname}", json=True)
+ return output[0]["rx"]
+
+def setup_xsk(cfg, xdp_queue_id = 0) -> bkg:
+ # Probe for support
+ xdp = cmd(f'{cfg.net_lib_dir / "xdp_helper"} - -', fail=False)
+ if xdp.ret == 255:
+ raise KsftSkipEx('AF_XDP unsupported')
+ elif xdp.ret > 0:
+ raise KsftFailEx('unable to create AF_XDP socket')
+
+ # Retry xsk setup 3 times
+ i = 0
+ while True:
+ try:
+ return bkg(f'{cfg.net_lib_dir / "xdp_helper"} {cfg.ifindex} ' \
+ '{xdp_queue_id} -z', ksft_wait=3)
+ except:
+ if i == 3:
+ raise KsftSkipEx('Failed to bind XDP socket in zerocopy.\n' \
+ 'Please consider adding iommu_platform=on ' \
+ 'when setting up virtio-net-pci')
+ else:
+ i += 1
+ time.sleep(1)
+ continue
+
+def check_xdp_bind(cfg):
+ with setup_xsk(cfg):
+ ip(f"link set dev %s xdp obj %s sec xdp" %
+ (cfg.ifname, cfg.net_lib_dir / "xdp_dummy.bpf.o"))
+ ip(f"link set dev %s xdp off" % cfg.ifname)
+
+def check_rx_resize(cfg):
+ with setup_xsk(cfg):
+ rx_ring = _get_rx_ring_entries(cfg)
+ ethtool(f"-G %s rx %d" % (cfg.ifname, rx_ring // 2))
+ ethtool(f"-G %s rx %d" % (cfg.ifname, rx_ring))
+
+def main():
+ with NetDrvEnv(__file__, nsim_test=False) as cfg:
+ ksft_run([check_xdp_bind, check_rx_resize],
+ args=(cfg, ))
+ ksft_exit()
+
+if __name__ == "__main__":
+ main()
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v5 0/3] virtio-net: disable delayed refill when pausing rx
2025-04-24 10:47 [PATCH v5 0/3] virtio-net: disable delayed refill when pausing rx Bui Quang Minh
` (2 preceding siblings ...)
2025-04-24 10:47 ` [PATCH v5 3/3] selftests: net: add a virtio_net deadlock selftest Bui Quang Minh
@ 2025-04-24 11:03 ` Michael S. Tsirkin
2025-04-25 1:34 ` Jakub Kicinski
4 siblings, 0 replies; 7+ messages in thread
From: Michael S. Tsirkin @ 2025-04-24 11:03 UTC (permalink / raw)
To: Bui Quang Minh
Cc: virtualization, Jason Wang, Xuan Zhuo, Andrew Lunn, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Eugenio Pérez,
David S. Miller, netdev, linux-kernel, bpf
On Thu, Apr 24, 2025 at 05:47:13PM +0700, Bui Quang Minh wrote:
> Hi everyone,
>
> This only includes the selftest for virtio-net deadlock bug. The fix
> commit has been applied already.
>
> Link: https://lore.kernel.org/virtualization/174537302875.2111809.8543884098526067319.git-patchwork-notify@kernel.org/T/
Acked-by: Michael S. Tsirkin <mst@redhat.com>
> Version 5 changes:
> - Refactor the selftest
>
> Version 4 changes:
> - Add force zerocopy mode to xdp_helper
> - Make virtio_net selftest use force zerocopy mode
> - Move virtio_net selftest to drivers/net/hw
>
> Version 3 changes:
> - Patch 1: refactor to avoid code duplication
>
> Version 2 changes:
> - Add selftest for deadlock scenario
>
> Thanks,
> Quang Minh.
>
> Bui Quang Minh (3):
> selftests: net: move xdp_helper to net/lib
> selftests: net: add flag to force zerocopy mode in xdp_helper
> selftests: net: add a virtio_net deadlock selftest
>
> tools/testing/selftests/drivers/net/Makefile | 2 -
> .../testing/selftests/drivers/net/hw/Makefile | 1 +
> .../selftests/drivers/net/hw/xsk_reconfig.py | 68 +++++++++++++++++++
> tools/testing/selftests/drivers/net/queues.py | 4 +-
> tools/testing/selftests/net/lib/.gitignore | 1 +
> tools/testing/selftests/net/lib/Makefile | 1 +
> .../{drivers/net => net/lib}/xdp_helper.c | 19 +++++-
> 7 files changed, 90 insertions(+), 6 deletions(-)
> create mode 100755 tools/testing/selftests/drivers/net/hw/xsk_reconfig.py
> rename tools/testing/selftests/{drivers/net => net/lib}/xdp_helper.c (90%)
>
> --
> 2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v5 0/3] virtio-net: disable delayed refill when pausing rx
2025-04-24 10:47 [PATCH v5 0/3] virtio-net: disable delayed refill when pausing rx Bui Quang Minh
` (3 preceding siblings ...)
2025-04-24 11:03 ` [PATCH v5 0/3] virtio-net: disable delayed refill when pausing rx Michael S. Tsirkin
@ 2025-04-25 1:34 ` Jakub Kicinski
2025-04-25 4:21 ` Bui Quang Minh
4 siblings, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2025-04-25 1:34 UTC (permalink / raw)
To: Bui Quang Minh
Cc: virtualization, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Andrew Lunn, Eric Dumazet, Paolo Abeni, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Eugenio Pérez, David S. Miller, netdev, linux-kernel, bpf
On Thu, 24 Apr 2025 17:47:13 +0700 Bui Quang Minh wrote:
> This only includes the selftest for virtio-net deadlock bug. The fix
> commit has been applied already.
This conflicts with Joe's series slightly:
https://lore.kernel.org/all/20250424002746.16891-1-jdamato@fastly.com/
Could you rebase on latest net-next and perhaps follow the comment
I left on v4 ?
--
pw-bot: cr
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v5 0/3] virtio-net: disable delayed refill when pausing rx
2025-04-25 1:34 ` Jakub Kicinski
@ 2025-04-25 4:21 ` Bui Quang Minh
0 siblings, 0 replies; 7+ messages in thread
From: Bui Quang Minh @ 2025-04-25 4:21 UTC (permalink / raw)
To: Jakub Kicinski
Cc: virtualization, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Andrew Lunn, Eric Dumazet, Paolo Abeni, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Eugenio Pérez, David S. Miller, netdev, linux-kernel, bpf
On 4/25/25 08:34, Jakub Kicinski wrote:
> On Thu, 24 Apr 2025 17:47:13 +0700 Bui Quang Minh wrote:
>> This only includes the selftest for virtio-net deadlock bug. The fix
>> commit has been applied already.
> This conflicts with Joe's series slightly:
> https://lore.kernel.org/all/20250424002746.16891-1-jdamato@fastly.com/
> Could you rebase on latest net-next and perhaps follow the comment
> I left on v4 ?
Sure, I'll do it. Thanks for your review :)
Quang Minh.
^ permalink raw reply [flat|nested] 7+ messages in thread