Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2017799rdb; Mon, 9 Oct 2023 09:51:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjKPgl92XSB7RD+lXBVBqnlekaly2FtVWSEwvBuegjkUvLBkcBkwdpJ6z5WKf871Jc6gkV X-Received: by 2002:a05:6a00:1a0c:b0:68e:2478:d6c9 with SMTP id g12-20020a056a001a0c00b0068e2478d6c9mr14018288pfv.2.1696870266819; Mon, 09 Oct 2023 09:51:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696870266; cv=none; d=google.com; s=arc-20160816; b=XWnr0VF4w2AjAsOWgf9Ki2RVtPIoflQUVu/k4qflRyvwd+0iWIy/0j5cY0JQkDd7ge RE/zhCa4PzHgxjMGcX+nfYkR0Gj5usjT52c92vPGzMJQDFb3iwBQpIqxU6gxReCItt4I ZVUBkEaxt6Ko1ArvjizZ4wNlepgG1sC8Wk9soegiXRMkihrfbfLYy4A1dz6fZi8XJuQL BGksfjukqjQq7WiX31EUS45MHN1no54IfxHDwhXtEfIvIVC5iObQRM8P0CHoKg8WNUes c1arRCOIWQ9Gei4VYbtEGYINI8DHi6oe5Eu2lFyNyR6CBab4cOiR0vuRTZ5HVLbJPWKe 8saw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=bMIkGjyRYQaniwgX1VwN1yvNzp3XWIxIueEXO1Vjz9g=; fh=vMZkKjPzijNOSAH46OQ/HcPOrb3V8PI+gwGsvJoITII=; b=e6rpd0xGmNmP74+/MfQ17tc3VtxRBAcFlZ/zTsZDpeM19vOReXT/Lfc4FHm+Wz8XZ8 4GpikRelUhmZNKrHYQ3bB20P9bDBrQzaQGYieROOhnpEad8K44l6JBj6zXIXPfUn6s70 1lHAJJxSDjlG0F6jDdZzLPkc/77EdGJVtZ/qlwLVptyXAiO7pG8cK++DX7MFYZDGLloX yoXegvp+qvQokjtDamyn+YyTFh3FYHbJ3BoQMNFdcJtMbCZbfE9Qw2bv8iyt4FDEXAMN zgGia1LeTim1saGmId9VGRMeUkGpNUvRrPh1A7arrvKBkahhkKmCIJbsRhGis+vEpNZW H9IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="SbCb84N/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id fc6-20020a056a002e0600b0068fcca7b3f7si7750312pfb.2.2023.10.09.09.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 09:51:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="SbCb84N/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 063028098491; Mon, 9 Oct 2023 09:50:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377245AbjJIQt7 (ORCPT + 99 others); Mon, 9 Oct 2023 12:49:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376275AbjJIQt6 (ORCPT ); Mon, 9 Oct 2023 12:49:58 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B53F9C for ; Mon, 9 Oct 2023 09:49:56 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-59963a317fcso349819a12.2 for ; Mon, 09 Oct 2023 09:49:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696870196; x=1697474996; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bMIkGjyRYQaniwgX1VwN1yvNzp3XWIxIueEXO1Vjz9g=; b=SbCb84N/VZPkkbxRHTTJct06OI1YV2Af1WXCHtHn3hqWNfswBvZeQKDSIz0czJa1Me ISRKtX3lG6/DYSQo2OhNvJzRq9Hpizwh+df5qYhCom8db6wU8aKteEXwPyEYjQJDv4pr AmOaG4i9WV8nESu6HnpFYpe9knvdjFIJJVvwGn/APA8g3YLOo2nkvoOlElsyGIP9z4Wj 87/NCb1fETEo+CYtPno6rDGiHRa8mL6lOlA3VxTEeZQKIS3SMIz1myeb6UKH9RX0qKJm SAMrjH9xnFRuS9VXu9YZiYmFWOCsvepv7f2Rin08WwxWRp7ytA2216ez6+WLXQJSq5AC SByw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696870196; x=1697474996; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bMIkGjyRYQaniwgX1VwN1yvNzp3XWIxIueEXO1Vjz9g=; b=wxaMaSaqkAtqRhUR+ErgFh6hiFKX8GFVp7bE2ulonlSAyjZcJEdL0NyRSb0k9xUd8x 41i6C1xXF4tobBl1SVwqiHn9Z50uI50/3zPCDeQRO8Jdy3Pq1Yo/SxRATUr3ccpmJ7J/ efPGIzAuKiQLINBvIjO7k/BjaIOWtK1lJmH9QBLKEhCSHNwrIqTv+EJAoErCwdiYVaXG IcC7xOaQKtVpS3QmUhTDDp330/SY/G6mIsFtKh57acciAR6UeA6sKcsSxAepwqasI2o0 tGUBxGz3mhYrxd/v8HzMDWRwYaVYm9DxLgkEGB0pNrXDf3btI6wXQBVl6rv2ChHlYi1m iYcg== X-Gm-Message-State: AOJu0YxlEvG7uHNRmxaOEkZHP4Rn+/c3GR77V/BWQrFMNRLky1D9M0ep 3eYugb15a/DChOf4WSAzmaPcWP4Egij9WXvqYb0R7UzTfqsLOqftImXa0YuJ11uKl5sXz3g65qL ApSTw3u3LdZEUE3+l X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a63:7b4a:0:b0:577:6bf1:499b with SMTP id k10-20020a637b4a000000b005776bf1499bmr253491pgn.10.1696870196036; Mon, 09 Oct 2023 09:49:56 -0700 (PDT) Date: Mon, 9 Oct 2023 09:49:54 -0700 In-Reply-To: <20231009160520.20831-1-larysa.zaremba@intel.com> Mime-Version: 1.0 References: <20231009160520.20831-1-larysa.zaremba@intel.com> Message-ID: Subject: Re: [PATCH bpf-next] selftests/bpf: add options and frags to xdp_hw_metadata From: Stanislav Fomichev To: Larysa Zaremba Cc: bpf@vger.kernel.org, Martin KaFai Lau , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , linux-kernel@vger.kernel.org, Maciej Fijalkowski Content-Type: text/plain; charset="utf-8" X-ccpol: medium X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 09 Oct 2023 09:50:09 -0700 (PDT) On 10/09, Larysa Zaremba wrote: > This is a follow-up to the commit 9b2b86332a9b ("bpf: Allow to use kfunc > XDP hints and frags together"). > > The are some possible implementations problems that may arise when > providing metadata specifically for multi-buffer packets, therefore there > must be a possibility to test such option separately. > > Add an option to use multi-buffer AF_XDP xdp_hw_metadata and mark used XDP > program as capable to use frags. > > As for now, xdp_hw_metadata accepts no options, so add simple option > parsing logic and a help message. > > For quick reference, also add an ingress packet generation command to the > help message. The command comes from [0]. > > Example of output for multi-buffer packet: > > xsk_ring_cons__peek: 1 > 0xead018: rx_desc[15]->addr=10000000000f000 addr=f100 comp_addr=f000 > rx_hash: 0x5789FCBB with RSS type:0x29 > rx_timestamp: 1696856851535324697 (sec:1696856851.5353) > XDP RX-time: 1696856843158256391 (sec:1696856843.1583) > delta sec:-8.3771 (-8377068.306 usec) > AF_XDP time: 1696856843158413078 (sec:1696856843.1584) > delta sec:0.0002 (156.687 usec) > 0xead018: complete idx=23 addr=f000 > xsk_ring_cons__peek: 1 > 0xead018: rx_desc[16]->addr=100000000008000 addr=8100 comp_addr=8000 > 0xead018: complete idx=24 addr=8000 > xsk_ring_cons__peek: 1 > 0xead018: rx_desc[17]->addr=100000000009000 addr=9100 comp_addr=9000 EoP > 0xead018: complete idx=25 addr=9000 > > Metadata is printed for the first packet only. > > [0] https://lore.kernel.org/all/20230119221536.3349901-18-sdf@google.com/ > > Signed-off-by: Larysa Zaremba > --- > .../selftests/bpf/progs/xdp_hw_metadata.c | 2 +- > tools/testing/selftests/bpf/xdp_hw_metadata.c | 92 ++++++++++++++++--- > 2 files changed, 79 insertions(+), 15 deletions(-) > > diff --git a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c > index 63d7de6c6bbb..8767d919c881 100644 > --- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c > +++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c > @@ -21,7 +21,7 @@ extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx, > extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash, > enum xdp_rss_hash_type *rss_type) __ksym; > > -SEC("xdp") > +SEC("xdp.frags") > int rx(struct xdp_md *ctx) > { > void *data, *data_meta, *data_end; > diff --git a/tools/testing/selftests/bpf/xdp_hw_metadata.c b/tools/testing/selftests/bpf/xdp_hw_metadata.c > index 17c980138796..25225720346b 100644 > --- a/tools/testing/selftests/bpf/xdp_hw_metadata.c > +++ b/tools/testing/selftests/bpf/xdp_hw_metadata.c > @@ -26,6 +26,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -49,19 +50,29 @@ struct xsk { > struct xdp_hw_metadata *bpf_obj; > struct xsk *rx_xsk; > const char *ifname; > +bool use_frags; > int ifindex; > int rxq; > > void test__fail(void) { /* for network_helpers.c */ } > > -static int open_xsk(int ifindex, struct xsk *xsk, __u32 queue_id) > +static struct xsk_socket_config gen_socket_config(void) > { > - int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE; > - const struct xsk_socket_config socket_config = { > + struct xsk_socket_config socket_config = { > .rx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, > .tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, > .bind_flags = XDP_COPY, > }; > + > + if (use_frags) > + socket_config.bind_flags |= XDP_USE_SG; > + return socket_config; > +} nit: why not drop const from socket_config and add this 'if (use_frags)' directly to open_xsk? Not sure separate function really buys us anything? > +static int open_xsk(int ifindex, struct xsk *xsk, __u32 queue_id) > +{ > + int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE; > + struct xsk_socket_config socket_config = gen_socket_config(); > const struct xsk_umem_config umem_config = { > .fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, > .comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS, > @@ -263,11 +274,14 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_t > verify_skb_metadata(server_fd); > > for (i = 0; i < rxq; i++) { > + bool first_seg = true; > + bool is_eop = true; > + > if (fds[i].revents == 0) > continue; > > struct xsk *xsk = &rx_xsk[i]; > - > +peek: > ret = xsk_ring_cons__peek(&xsk->rx, 1, &idx); > printf("xsk_ring_cons__peek: %d\n", ret); > if (ret != 1) > @@ -276,12 +290,19 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_t > rx_desc = xsk_ring_cons__rx_desc(&xsk->rx, idx); > comp_addr = xsk_umem__extract_addr(rx_desc->addr); > addr = xsk_umem__add_offset_to_addr(rx_desc->addr); > - printf("%p: rx_desc[%u]->addr=%llx addr=%llx comp_addr=%llx\n", > - xsk, idx, rx_desc->addr, addr, comp_addr); > - verify_xdp_metadata(xsk_umem__get_data(xsk->umem_area, addr), > - clock_id); > + is_eop = !(rx_desc->options & XDP_PKT_CONTD); > + printf("%p: rx_desc[%u]->addr=%llx addr=%llx comp_addr=%llx%s\n", > + xsk, idx, rx_desc->addr, addr, comp_addr, is_eop ? " EoP" : ""); > + if (first_seg) { > + verify_xdp_metadata(xsk_umem__get_data(xsk->umem_area, addr), > + clock_id); > + first_seg = false; > + } > + > xsk_ring_cons__release(&xsk->rx, 1); > refill_rx(xsk, comp_addr); > + if (!is_eop) > + goto peek; > } > } > > @@ -404,6 +425,54 @@ static void timestamping_enable(int fd, int val) > error(1, errno, "setsockopt(SO_TIMESTAMPING)"); > } > > +static void print_usage(void) > +{ > + const char *usage = > + " Usage: xdp_hw_metadata [OPTIONS] [IFNAME]\n" > + " Options:\n" > + " -m Enable multi-buffer XDP for larger MTU\n" > + " -h Display this help and exit\n\n" > + " Generate test packets on the other machine with:\n" > + " echo -n xdp | nc -u -q1 9091\n"; nit: any reason we have two spaces in the help description? I don't think it's a standard practice, so maybe drop them?