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

selftests: net: add flag to force zerocopy mode in xdp_helper

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>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Link: https://patch.msgid.link/20250425071018.36078-3-minhquangbui99@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Bui Quang Minh and committed by
Jakub Kicinski
5d346179 59dd07db

+17 -2
+17 -2
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 * ··· 42 36 int sock_fd; 43 37 int queue; 44 38 45 - if (argc != 3) { 46 - fprintf(stderr, "Usage: %s ifindex queue_id\n", argv[0]); 39 + if (argc != 3 && argc != 4) { 40 + print_usage(argv[0]); 47 41 return 1; 48 42 } 49 43 ··· 92 86 sxdp.sxdp_ifindex = ifindex; 93 87 sxdp.sxdp_queue_id = queue; 94 88 sxdp.sxdp_flags = 0; 89 + 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 + } 95 98 96 99 if (bind(sock_fd, (struct sockaddr *)&sxdp, sizeof(sxdp)) != 0) { 97 100 munmap(umem_area, UMEM_SZ);