From patchwork Wed Jul 7 22:16:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zvi Effron X-Patchwork-Id: 12364097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32E8EC07E95 for ; Wed, 7 Jul 2021 22:17:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D65461CDD for ; Wed, 7 Jul 2021 22:17:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231153AbhGGWTr (ORCPT ); Wed, 7 Jul 2021 18:19:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230127AbhGGWTr (ORCPT ); Wed, 7 Jul 2021 18:19:47 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E15ACC06175F for ; Wed, 7 Jul 2021 15:17:06 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id j199so3582186pfd.7 for ; Wed, 07 Jul 2021 15:17:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riotgames.com; s=riotgames; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vCJ2vjtmZHMCWsNz6Dr7+zk1JKTc+6CNVa3EJes2r6Y=; b=WybaUxC/xyGUNVzUnR1rSwmeNOau1hF3Yrv4B2EEDVO30piMHQsX0ISX6AsVdxUdcm p15cu3Em7oEKP/FxoSUdvq0/1gtEvJ6TN4uqNV7CRC3McngwGFlB+/xSlVL7FjTrNDqf Yi4iWYHb3qHTXUSIjhN9f9KVLGNyhqTwZq86I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vCJ2vjtmZHMCWsNz6Dr7+zk1JKTc+6CNVa3EJes2r6Y=; b=T1yHsbjPNZe/q4Yh1zG64eLW4mfVc3K5x/epPurcmTNcsh3AxhtkHJi4/G4e3WjYCy XHhtsSRLC2CqxKPdxnXgEnK7AXTXZvcorhzKq/y7LviZD3sA1Y+2++aWvB5MMTo350/F XQZul0mu3nxainv2lZhRe110PIOPAZtcJqYvekkAuEl5ctZxDCGisR08IiBkvwfQq1U8 5Tk5gDuZ4zeT0MArkJIKGuD/VP6USgB1NoIMM2Klipf2kxwPc2z68yWCzYitLAOCWye2 KWBWWYhqh0K5aLeC9ZIjQ1ZPlPWWIQ5mUAvynfYNJH+zKI507p8GNn39iA45xtEKv+Xj 3+Sw== X-Gm-Message-State: AOAM532KrC7GwL3vRflcMKgMnFvpXbZPUCLDCw0EPtdA89sVwuzA2LVl Bjm0Hu7bo6Ecf+MhPwAOYii4/c+9FcXDbSqM X-Google-Smtp-Source: ABdhPJy4myl+qui+gZm2zXFdoecY2JHnmovCajXaqly5YXsJrtfTJ+lxDTMsVsC6LxHknQmvlwK63A== X-Received: by 2002:a62:ed0b:0:b029:30c:7193:68f6 with SMTP id u11-20020a62ed0b0000b029030c719368f6mr28342189pfh.73.1625696226069; Wed, 07 Jul 2021 15:17:06 -0700 (PDT) Received: from ip-10-184-182-114.us-west-2.compute.internal (ec2-54-191-147-77.us-west-2.compute.amazonaws.com. [54.191.147.77]) by smtp.gmail.com with ESMTPSA id 75sm203748pfx.71.2021.07.07.15.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 15:17:05 -0700 (PDT) From: Zvi Effron To: bpf@vger.kernel.org Cc: Alexei Starovoitov , "David S. Miller" , Daniel Borkmann , Jesper Dangaard Brouer , Andrii Nakryiko , Maciej Fijalkowski , Martin KaFai Lau , Yonghong Song , netdev@vger.kernel.org, KP Singh , Andrii Nakryiko , John Fastabend , Song Liu , Jakub Kicinski , Zvi Effron Subject: [PATCH bpf-next v8 0/4] bpf: support input xdp_md context in BPF_PROG_TEST_RUN Date: Wed, 7 Jul 2021 22:16:53 +0000 Message-Id: <20210707221657.3985075-1-zeffron@riotgames.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net This patchset adds support for passing an xdp_md via ctx_in/ctx_out in bpf_attr for BPF_PROG_TEST_RUN of XDP programs. Patch 1 adds a function to validate XDP meta data lengths. Patch 2 adds initial support for passing XDP meta data in addition to packet data. Patch 3 adds support for also specifying the ingress interface and rx queue. Patch 4 adds selftests to ensure functionality is correct. Changelog: ---------- v7->v8 v7: https://lore.kernel.org/bpf/20210624211304.90807-1-zeffron@riotgames.com/ * Fix too long comment line in patch 3 v6->v7 v6: https://lore.kernel.org/bpf/20210617232904.1899-1-zeffron@riotgames.com/ * Add Yonghong Song's Acked-by to commit message in patch 1 * Add Yonghong Song's Acked-by to commit message in patch 2 * Extracted the post-update of the xdp_md context into a function (again) * Validate that the rx queue was registered with XDP info * Decrement the reference count on a found netdevice on failure to find a valid rx queue * Decrement the reference count on a found netdevice after the XDP program is run * Drop Yonghong Song's Acked-By for patch 3 because of patch changes * Improve a comment in the selftests * Drop Yonghong Song's Acked-By for patch 4 because of patch changes v5->v6 v5: https://lore.kernel.org/bpf/20210616224712.3243-1-zeffron@riotgames.com/ * Correct commit messages in patches 1 and 3 * Add Acked-by to commit message in patch 4 * Use gotos instead of returns to correctly free resources in bpf_prog_test_run_xdp * Rename xdp_metalen_valid to xdp_metalen_invalid * Improve the function signature for xdp_metalen_invalid * Merged declaration of ingress_ifindex and rx_queue_index into one line v4->v5 v4: https://lore.kernel.org/bpf/20210604220235.6758-1-zeffron@riotgames.com/ * Add new patch to introduce xdp_metalen_valid inline function to avoid duplicated code from net/core/filter.c * Correct size of bad_ctx in selftests * Make all declarations reverse Christmas tree * Move data check from xdp_convert_md_to_buff to bpf_prog_test_run_xdp * Merge xdp_convert_buff_to_md into bpf_prog_test_run_xdp * Fix line too long * Extracted common checks in selftests to a helper function * Removed redundant assignment in selftests * Reordered test cases in selftests * Check data against 0 instead of data_meta in selftests * Made selftests use EINVAL instead of hardcoded 22 * Dropped "_" from XDP function name * Changed casts in XDP program from unsigned long to long * Added a comment explaining the use of the loopback interface in selftests * Change parameter order in xdp_convert_md_to_buff to be input first * Assigned xdp->ingress_ifindex and xdp->rx_queue_index to local variables in xdp_convert_md_to_buff * Made use of "meta data" versus "metadata" consistent in comments and commit messages v3->v4 v3: https://lore.kernel.org/bpf/20210602190815.8096-1-zeffron@riotgames.com/ * Clean up nits * Validate xdp_md->data_end in bpf_prog_test_run_xdp * Remove intermediate metalen variables v2 -> v3 v2: https://lore.kernel.org/bpf/20210527201341.7128-1-zeffron@riotgames.com/ * Check errno first in selftests * Use DECLARE_LIBBPF_OPTS * Rename tattr to opts in selftests * Remove extra new line * Rename convert_xdpmd_to_xdpb to xdp_convert_md_to_buff * Rename convert_xdpb_to_xdpmd to xdp_convert_buff_to_md * Move declaration of device and rxqueue in xdp_convert_md_to_buff to patch 2 * Reorder the kfree calls in bpf_prog_test_run_xdp v1 -> v2 v1: https://lore.kernel.org/bpf/20210524220555.251473-1-zeffron@riotgames.com * Fix null pointer dereference with no context * Use the BPF skeleton and replace CHECK with ASSERT macros Zvi Effron (4): bpf: add function for XDP meta data length check bpf: support input xdp_md context in BPF_PROG_TEST_RUN bpf: support specifying ingress via xdp_md context in BPF_PROG_TEST_RUN selftests/bpf: Add test for xdp_md context in BPF_PROG_TEST_RUN include/net/xdp.h | 5 + include/uapi/linux/bpf.h | 3 - net/bpf/test_run.c | 109 ++++++++++++++++-- net/core/filter.c | 4 +- .../bpf/prog_tests/xdp_context_test_run.c | 105 +++++++++++++++++ .../bpf/progs/test_xdp_context_test_run.c | 20 ++++ 6 files changed, 233 insertions(+), 13 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_context_test_run.c base-commit: 5e437416ff66981d8154687cfdf7de50b1d82bfc