Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'virtio-net-disable-delayed-refill-when-pausing-rx'

Bui Quang Minh says:

====================
virtio-net: disable delayed refill when pausing rx

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/
====================

Link: https://patch.msgid.link/20250425071018.36078-1-minhquangbui99@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+98 -12
-1
tools/testing/selftests/drivers/net/.gitignore
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 napi_id_helper 3 - xdp_helper
-1
tools/testing/selftests/drivers/net/Makefile
··· 8 8 9 9 TEST_GEN_FILES := \ 10 10 napi_id_helper \ 11 - xdp_helper \ 12 11 # end of TEST_GEN_FILES 13 12 14 13 TEST_PROGS := \
+1
tools/testing/selftests/drivers/net/hw/Makefile
··· 21 21 rss_ctx.py \ 22 22 rss_input_xfrm.py \ 23 23 tso.py \ 24 + xsk_reconfig.py \ 24 25 # 25 26 26 27 TEST_FILES := \
+60
tools/testing/selftests/drivers/net/hw/xsk_reconfig.py
··· 1 + #!/usr/bin/env python3 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + # This is intended to be run on a virtio-net guest interface. 5 + # The test binds the XDP socket to the interface without setting 6 + # the fill ring to trigger delayed refill_work. This helps to 7 + # make it easier to reproduce the deadlock when XDP program, 8 + # XDP socket bind/unbind, rx ring resize race with refill_work on 9 + # the buggy kernel. 10 + # 11 + # The Qemu command to setup virtio-net 12 + # -netdev tap,id=hostnet1,vhost=on,script=no,downscript=no 13 + # -device virtio-net-pci,netdev=hostnet1,iommu_platform=on,disable-legacy=on 14 + 15 + from lib.py import ksft_exit, ksft_run 16 + from lib.py import KsftSkipEx, KsftFailEx 17 + from lib.py import NetDrvEnv 18 + from lib.py import bkg, ip, cmd, ethtool 19 + import time 20 + 21 + def _get_rx_ring_entries(cfg): 22 + output = ethtool(f"-g {cfg.ifname}", json=True) 23 + return output[0]["rx"] 24 + 25 + def setup_xsk(cfg, xdp_queue_id = 0) -> bkg: 26 + # Probe for support 27 + xdp = cmd(f'{cfg.net_lib_dir / "xdp_helper"} - -', fail=False) 28 + if xdp.ret == 255: 29 + raise KsftSkipEx('AF_XDP unsupported') 30 + elif xdp.ret > 0: 31 + raise KsftFailEx('unable to create AF_XDP socket') 32 + 33 + try: 34 + return bkg(f'{cfg.net_lib_dir / "xdp_helper"} {cfg.ifindex} ' \ 35 + '{xdp_queue_id} -z', ksft_wait=3) 36 + except: 37 + raise KsftSkipEx('Failed to bind XDP socket in zerocopy.\n' \ 38 + 'Please consider adding iommu_platform=on ' \ 39 + 'when setting up virtio-net-pci') 40 + 41 + def check_xdp_bind(cfg): 42 + with setup_xsk(cfg): 43 + ip(f"link set dev %s xdp obj %s sec xdp" % 44 + (cfg.ifname, cfg.net_lib_dir / "xdp_dummy.bpf.o")) 45 + ip(f"link set dev %s xdp off" % cfg.ifname) 46 + 47 + def check_rx_resize(cfg): 48 + with setup_xsk(cfg): 49 + rx_ring = _get_rx_ring_entries(cfg) 50 + ethtool(f"-G %s rx %d" % (cfg.ifname, rx_ring // 2)) 51 + ethtool(f"-G %s rx %d" % (cfg.ifname, rx_ring)) 52 + 53 + def main(): 54 + with NetDrvEnv(__file__, nsim_test=False) as cfg: 55 + ksft_run([check_xdp_bind, check_rx_resize], 56 + args=(cfg, )) 57 + ksft_exit() 58 + 59 + if __name__ == "__main__": 60 + main()
tools/testing/selftests/drivers/net/ksft.h tools/testing/selftests/net/lib/ksft.h
+1 -1
tools/testing/selftests/drivers/net/napi_id_helper.c
··· 8 8 #include <arpa/inet.h> 9 9 #include <sys/socket.h> 10 10 11 - #include "ksft.h" 11 + #include "../../net/lib/ksft.h" 12 12 13 13 int main(int argc, char *argv[]) 14 14 {
+2 -2
tools/testing/selftests/drivers/net/queues.py
··· 26 26 27 27 def check_xsk(cfg, nl, xdp_queue_id=0) -> None: 28 28 # Probe for support 29 - xdp = cmd(f'{cfg.test_dir / "xdp_helper"} - -', fail=False) 29 + xdp = cmd(f'{cfg.net_lib_dir / "xdp_helper"} - -', fail=False) 30 30 if xdp.ret == 255: 31 31 raise KsftSkipEx('AF_XDP unsupported') 32 32 elif xdp.ret > 0: 33 33 raise KsftFailEx('unable to create AF_XDP socket') 34 34 35 - with bkg(f'{cfg.test_dir / "xdp_helper"} {cfg.ifindex} {xdp_queue_id}', 35 + with bkg(f'{cfg.net_lib_dir / "xdp_helper"} {cfg.ifindex} {xdp_queue_id}', 36 36 ksft_wait=3): 37 37 38 38 rx = tx = False
+32 -7
tools/testing/selftests/drivers/net/xdp_helper.c tools/testing/selftests/net/lib/xdp_helper.c
··· 17 17 #define NUM_DESC (UMEM_SZ / 2048) 18 18 19 19 20 + static void print_usage(const char *bin) 21 + { 22 + fprintf(stderr, "Usage: %s ifindex queue_id [-z]\n\n" 23 + "where:\n\t-z: force zerocopy mode", bin); 24 + } 25 + 20 26 /* this is a simple helper program that creates an XDP socket and does the 21 27 * minimum necessary to get bind() to succeed. 22 28 * ··· 38 32 struct sockaddr_xdp sxdp = { 0 }; 39 33 int num_desc = NUM_DESC; 40 34 void *umem_area; 35 + int retry = 0; 41 36 int ifindex; 42 37 int sock_fd; 43 38 int queue; 44 39 45 - if (argc != 3) { 46 - fprintf(stderr, "Usage: %s ifindex queue_id\n", argv[0]); 40 + if (argc != 3 && argc != 4) { 41 + print_usage(argv[0]); 47 42 return 1; 48 43 } 49 44 ··· 94 87 sxdp.sxdp_queue_id = queue; 95 88 sxdp.sxdp_flags = 0; 96 89 97 - if (bind(sock_fd, (struct sockaddr *)&sxdp, sizeof(sxdp)) != 0) { 98 - munmap(umem_area, UMEM_SZ); 99 - perror("bind failed"); 100 - close(sock_fd); 101 - return 1; 90 + if (argc > 3) { 91 + if (!strcmp(argv[3], "-z")) { 92 + sxdp.sxdp_flags = XDP_ZEROCOPY; 93 + } else { 94 + print_usage(argv[0]); 95 + return 1; 96 + } 97 + } 98 + 99 + while (1) { 100 + if (bind(sock_fd, (struct sockaddr *)&sxdp, sizeof(sxdp)) == 0) 101 + break; 102 + 103 + if (errno == EBUSY && retry < 3) { 104 + retry++; 105 + sleep(1); 106 + continue; 107 + } else { 108 + perror("bind failed"); 109 + munmap(umem_area, UMEM_SZ); 110 + close(sock_fd); 111 + return 1; 112 + } 102 113 } 103 114 104 115 ksft_ready();
+1
tools/testing/selftests/net/lib/.gitignore
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 csum 3 + xdp_helper
+1
tools/testing/selftests/net/lib/Makefile
··· 10 10 11 11 TEST_GEN_FILES += csum 12 12 TEST_GEN_FILES += $(patsubst %.c,%.o,$(wildcard *.bpf.c)) 13 + TEST_GEN_FILES += xdp_helper 13 14 14 15 TEST_INCLUDES := $(wildcard py/*.py sh/*.sh) 15 16