From patchwork Fri Jun 17 22:07:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Gospodarek X-Patchwork-Id: 12886052 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5233DC43334 for ; Fri, 17 Jun 2022 22:07:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244217AbiFQWHx (ORCPT ); Fri, 17 Jun 2022 18:07:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230245AbiFQWHw (ORCPT ); Fri, 17 Jun 2022 18:07:52 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2FBC1EAC7 for ; Fri, 17 Jun 2022 15:07:48 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id 31so5088900pgv.11 for ; Fri, 17 Jun 2022 15:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:mime-version; bh=Lcw11kKN0B0AOmYUAOoyK3Jql9n8xcmyqWWeaz2fjD0=; b=CbMhVf/eIbpEXIOZNw0vqbebQWyTfqZ/GBzrImsnzVAvN+1G9nvQvOs46eIzfO7Wz/ PjdwHK/SMsqb+rZqWbtrkvOu2kMGRTcYFEAFmRkLM5Gx0uHfepBgLKSO7XzzYHml4wPM 4s7O7TKVqoNKXH3HWv+x7V2jbVly1Gkh1hFd8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version; bh=Lcw11kKN0B0AOmYUAOoyK3Jql9n8xcmyqWWeaz2fjD0=; b=yWJEro7HAig828dcD1HdcKLuEw+le6o2kpCZdRkN3/Y5GtoAlDTauU+xRCxcjYEMFu 9H6TBRbKbyrspItpAWU2FjZ2Xvq3+bjxfcZMems9ClIlDltF8va8k4Ygxz4+L2vWfMyw tM9mXThMy9R12jaMN7j+K+5PxOTmSAxbMBUSpTEv07Ll94QoEGQ/6Iirp3TTX2hd5qqg HrbKgBGuqWYyKxtViLv53cbOqLH/8n/8JoT7zKtU5dy8ephBsX6WezaftGB8iUPviaoC jnNVi2pLyGglz2hn4NsOB2XkthLl9en+tLUa+Do0EJ7LQGzmrMwxsdG29q1zc7g7QI+M YnJw== X-Gm-Message-State: AJIora/ucHh5w008cuq7shCfTlfZnAqU4dDz7ZwRTG+jpW56JSwnHnxT aC2OPVV+oJojwfYDTHat1QfuhQ== X-Google-Smtp-Source: AGRyM1sja3tS/EBBuNcebQck0Kw8hBryWN0rGahtDRe5D0TBnZt2tXsovm4mStLZEKnP7NZqRIskMg== X-Received: by 2002:a63:9dc9:0:b0:408:dcec:d291 with SMTP id i192-20020a639dc9000000b00408dcecd291mr10835425pgd.592.1655503668259; Fri, 17 Jun 2022 15:07:48 -0700 (PDT) Received: from driver-testing.dhcp.broadcom.net ([192.19.144.250]) by smtp.gmail.com with ESMTPSA id p15-20020a1709027ecf00b00165103c9903sm4026239plb.113.2022.06.17.15.07.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 15:07:47 -0700 (PDT) From: Andy Gospodarek X-Google-Original-From: Andy Gospodarek To: ast@kernel.org, daniel@iogearbox.net, davem@davemloft.net, kuba@kernel.org, hawk@kernel.org, john.fastabend@gmail.com, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, kpsingh@kernel.org, toke@redhat.com, lorenzo.bianconi@redhat.com, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Andy Gospodarek Subject: [PATCH net-next] samples/bpf: fixup some xdp progs to be able to support xdp multibuffer Date: Fri, 17 Jun 2022 22:07:38 +0000 Message-Id: <20220617220738.3593-1-gospo@broadcom.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This changes the section name for the bpf program embedded in these files to "xdp.frags" to allow the programs to be loaded on drivers that are using an MTU greater than PAGE_SIZE. Rather than directly accessing the buffers, the packet data is now accessed via xdp helper functions to provide an example for those who may need to write more complex programs. Signed-off-by: Andy Gospodarek Acked-by: John Fastabend Acked-by: Lorenzo Bianconi --- samples/bpf/xdp1_kern.c | 13 ++++++++++--- samples/bpf/xdp2_kern.c | 13 ++++++++++--- samples/bpf/xdp_tx_iptunnel_kern.c | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/samples/bpf/xdp1_kern.c b/samples/bpf/xdp1_kern.c index f0c5d95084de..a798553fca3b 100644 --- a/samples/bpf/xdp1_kern.c +++ b/samples/bpf/xdp1_kern.c @@ -39,17 +39,24 @@ static int parse_ipv6(void *data, u64 nh_off, void *data_end) return ip6h->nexthdr; } -SEC("xdp1") +#define XDPBUFSIZE 64 +SEC("xdp.frags") int xdp_prog1(struct xdp_md *ctx) { - void *data_end = (void *)(long)ctx->data_end; - void *data = (void *)(long)ctx->data; + __u8 pkt[XDPBUFSIZE] = {}; + void *data_end = &pkt[XDPBUFSIZE-1]; + void *data = pkt; struct ethhdr *eth = data; int rc = XDP_DROP; long *value; u16 h_proto; u64 nh_off; u32 ipproto; + int err; + + err = bpf_xdp_load_bytes(ctx, 0, pkt, sizeof(pkt)); + if (err < 0) + return rc; nh_off = sizeof(*eth); if (data + nh_off > data_end) diff --git a/samples/bpf/xdp2_kern.c b/samples/bpf/xdp2_kern.c index d8a64ab077b0..1502ef820aed 100644 --- a/samples/bpf/xdp2_kern.c +++ b/samples/bpf/xdp2_kern.c @@ -55,17 +55,24 @@ static int parse_ipv6(void *data, u64 nh_off, void *data_end) return ip6h->nexthdr; } -SEC("xdp1") +#define XDPBUFSIZE 64 +SEC("xdp.frags") int xdp_prog1(struct xdp_md *ctx) { - void *data_end = (void *)(long)ctx->data_end; - void *data = (void *)(long)ctx->data; + __u8 pkt[XDPBUFSIZE] = {}; + void *data_end = &pkt[XDPBUFSIZE-1]; + void *data = pkt; struct ethhdr *eth = data; int rc = XDP_DROP; long *value; u16 h_proto; u64 nh_off; u32 ipproto; + int err; + + err = bpf_xdp_load_bytes(ctx, 0, pkt, sizeof(pkt)); + if (err < 0) + return rc; nh_off = sizeof(*eth); if (data + nh_off > data_end) diff --git a/samples/bpf/xdp_tx_iptunnel_kern.c b/samples/bpf/xdp_tx_iptunnel_kern.c index 575d57e4b8d6..0e2bca3a3fff 100644 --- a/samples/bpf/xdp_tx_iptunnel_kern.c +++ b/samples/bpf/xdp_tx_iptunnel_kern.c @@ -212,7 +212,7 @@ static __always_inline int handle_ipv6(struct xdp_md *xdp) return XDP_TX; } -SEC("xdp_tx_iptunnel") +SEC("xdp.frags") int _xdp_tx_iptunnel(struct xdp_md *xdp) { void *data_end = (void *)(long)xdp->data_end;