From patchwork Tue Jun 21 17:54:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Gospodarek X-Patchwork-Id: 12889591 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 E3071CCA473 for ; Tue, 21 Jun 2022 17:54:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352796AbiFURyR (ORCPT ); Tue, 21 Jun 2022 13:54:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238923AbiFURyO (ORCPT ); Tue, 21 Jun 2022 13:54:14 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 186981C92F for ; Tue, 21 Jun 2022 10:54:14 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id 73-20020a17090a0fcf00b001eaee69f600so14203872pjz.1 for ; Tue, 21 Jun 2022 10:54:14 -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=BsxaUYR0KU+mllgw/KLVw+aYPcGgZDBql4d2uzAFGcg=; b=Fk3VpQaS921p/E7BU/aOMd3n4V/7Th0JVikc9jYIHpe4YRQPWD5//tamnelJ34hAZC NCdfKYYAmbEykUYhioY9xjSAW4FvcBXE6Xz+1hRnnB33M/KQeRbnMQv/v4VEUbDr39+h Wr4FmcS/yJEp5zScQz0GvKmJtrJDRaFW2J1/o= 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=BsxaUYR0KU+mllgw/KLVw+aYPcGgZDBql4d2uzAFGcg=; b=RtQNLUUwEqP79SYNDgjO62ZLGrgXeFy6BS5TNf3w44Dsi91u2rRwKbWGIHR4HnQyol cps+UKXvtka6rZQ/i2LwFNuMqZV/vPzt/td97OtjZjlGQF2RQUaZlBK1brgRMy7ZEME9 wuIu3W1BnUufup4dinLaKCldUflFwJ7NQO2W8u6VrNX6QetIODnkMUBdKJVGQ/UZ/ECo H6Xccgsk74ZbFJKv9xw8ppQr74NgqJIgpjJkQZw/VYUoyNK0jZBDnWul7jp3ofu/WCe2 Ep96X4aw0dtov+leomcIeoBt0z9jNFSKuXqVRl337IJF0eeZJkchi2KhDMapO0WWlyE1 5qIA== X-Gm-Message-State: AJIora+CVObbVZaGkYOU8BNfnKAruyLFq7bjhQy0A+5EgzgCVoeX/cYB OJamVg02JzkZdQIc2rI2P5VAsQ== X-Google-Smtp-Source: AGRyM1tuZrQJlxghPeRNsQGZlbKytq2s/RUis1pZFNX5jwx91AWKK9hoWy9T3yzdaMV72mqrfxxqhg== X-Received: by 2002:a17:903:2012:b0:16a:856:96a7 with SMTP id s18-20020a170903201200b0016a085696a7mr22549922pla.109.1655834053565; Tue, 21 Jun 2022 10:54:13 -0700 (PDT) Received: from driver-testing.dhcp.broadcom.net ([192.19.144.250]) by smtp.gmail.com with ESMTPSA id z14-20020a17090a540e00b001e095a5477bsm12694558pjh.33.2022.06.21.10.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 10:54:13 -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 , Lorenzo Bianconi Subject: [PATCH net-next v2] samples/bpf: fixup some tools to be able to support xdp multibuffer Date: Tue, 21 Jun 2022 17:54:02 +0000 Message-Id: <20220621175402.35327-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. v2: remove new unnecessary variable Signed-off-by: Andy Gospodarek Acked-by: John Fastabend Acked-by: Lorenzo Bianconi --- samples/bpf/xdp1_kern.c | 11 ++++++++--- samples/bpf/xdp2_kern.c | 11 ++++++++--- samples/bpf/xdp_tx_iptunnel_kern.c | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/samples/bpf/xdp1_kern.c b/samples/bpf/xdp1_kern.c index f0c5d95084de..0a5c704badd0 100644 --- a/samples/bpf/xdp1_kern.c +++ b/samples/bpf/xdp1_kern.c @@ -39,11 +39,13 @@ 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; @@ -51,6 +53,9 @@ int xdp_prog1(struct xdp_md *ctx) u64 nh_off; u32 ipproto; + if (bpf_xdp_load_bytes(ctx, 0, pkt, sizeof(pkt))) + return rc; + nh_off = sizeof(*eth); if (data + nh_off > data_end) return rc; diff --git a/samples/bpf/xdp2_kern.c b/samples/bpf/xdp2_kern.c index d8a64ab077b0..3332ba6bb95f 100644 --- a/samples/bpf/xdp2_kern.c +++ b/samples/bpf/xdp2_kern.c @@ -55,11 +55,13 @@ 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; @@ -67,6 +69,9 @@ int xdp_prog1(struct xdp_md *ctx) u64 nh_off; u32 ipproto; + if (bpf_xdp_load_bytes(ctx, 0, pkt, sizeof(pkt))) + return rc; + nh_off = sizeof(*eth); if (data + nh_off > data_end) return rc; 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;