From patchwork Mon Dec 4 20:56:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 173558 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3033312vqy; Mon, 4 Dec 2023 12:57:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFAji2U60At4abfgZQxqwZqjCjkX11sjbR4GVNSCGKczzfcsC6k821cg9Z6hSEvPSlc1Ynm X-Received: by 2002:a17:902:aa96:b0:1cc:5db8:7e92 with SMTP id d22-20020a170902aa9600b001cc5db87e92mr21654938plr.58.1701723453526; Mon, 04 Dec 2023 12:57:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701723453; cv=none; d=google.com; s=arc-20160816; b=eKmSnng7coZ7KfG3P12EGEK4xhGtnAHeF2R5EuxafSKTeO6y1fv7qOqxdoiNsZSVdY N/VGaZZy3/QvgoFw8j34XnVKL9+ZMfvB4FYxZAIlrG0M/Czgbc4pK+X/PysqLXW/i3EQ DQxsVdfVC1bYrV9Oni2BiahiOGeZDEX5c856TTzxE6awLuSfiHtMNYLUrJgg4AJGB8Lo hyC8opcHvMC0N++5Ss1KGf+PJkEj0D6iyoGRV+FVn5WyIjKdPI59YIj52IRxD/uMxZcK rBmaBT+yEYPVnvZ5727Pgk10L0mCeQoNVvyUY1NQQ1jCRPetODkKtkwGuTFM7gD9KTKi /hrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=Z+7Afm7t3HxDVtoQyXLZsXvB2QVInlcd4KmkW3EtfRk=; fh=ZAfxtzMnp2hdRZglVL8+/tHyTizX7HwNltmSipEX0vA=; b=mLQovPAj2wMwqiGznbBzviMHXJMwBD0k3onWGxpF2YMP4awaaK85Dl+gRSjXCPbRES fZIOZByeP/oWEnfIRHHXHd3cutIkD8BVU59/388H0gIqynfQiq8yB20DZGUvKbfYtzUx ac9juLIASGP/0LTU29PRDwpJAxvLa6NgHlynDLY3TBTg1wNqJmSbgw3SxEJc6ZZelREx 2565wK6lAW5h4E/ppX9YPvixMv7S/vQLRdUPyaF1ZXuH6PoPn3a8lJ2sW9grt/BWnlCv 9dDE8y0ObNqVki++ftA+w+JYe0Fk5Lonb2RkLkd7u9/zW0TS/aXczsHlOu7MmEh9MRRU Velw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=BHnJ+fx+; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=X8zDzbql; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id x22-20020a170902821600b001cfd52a2266si5419935pln.403.2023.12.04.12.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 12:57:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=BHnJ+fx+; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=X8zDzbql; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 22CB480ADF2E; Mon, 4 Dec 2023 12:57:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346134AbjLDU5W (ORCPT + 99 others); Mon, 4 Dec 2023 15:57:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234021AbjLDU5G (ORCPT ); Mon, 4 Dec 2023 15:57:06 -0500 Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5AEED65; Mon, 4 Dec 2023 12:57:02 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id 23A39580A13; Mon, 4 Dec 2023 15:57:02 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 04 Dec 2023 15:57:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1701723422; x= 1701730622; bh=Z+7Afm7t3HxDVtoQyXLZsXvB2QVInlcd4KmkW3EtfRk=; b=B HnJ+fx+0FdYXhJNFTepTS8dgk8/FV5xe82ChHPFkZM0vgsOl7kqB/LJGQNwKSEgQ gWnEcUfwsJWB3q7ylWh9bqsyiw0G0azF415Y70zo/7h8fZfhQUCSNjuJroHHjdDY yjqiDbvYRQ6ojKe0QH48phnhnqjYcDunfnyr1VK+mraWa8JB6s6dE8F9NrgC/Oqx LZIiP8x8f6tnuHqAEMtpn6K6z1/UiVw7hxr0Mx0Maf0kUXIK00y3unwl5ptm/xmV zmrmpf7YNAwqrPu50dOAZ07Uui10fF6SzqG7z/xDSIELv7Fvmu4p7vLwzJ8XpqN8 eIltoRmlbaXEdBRteIdvA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1701723422; x= 1701730622; bh=Z+7Afm7t3HxDVtoQyXLZsXvB2QVInlcd4KmkW3EtfRk=; b=X 8zDzbqlktm9phtZLiEx7t2HmUnqILJP9B7xAZglUWUssyZU6OyfOHH+K9FOUdvuZ VI6kxzuXEX52AuAmUgdKD7XK8QVsqJYqvxORM+k130h8dUuNckTF5R6iKwc0sC84 WOMu0/skQER+Gm7d55kc2/6TxgYwztXxlS66LoXAVXTkf/hHERS5eHQJKwEakNgj OB/eNCzZMzLyroQEKXeBL1nzJIdbj09iSqjZxNKcE9bVIx7L7SRe+JVhjKB0C2nc rID7r3Y9U7uEat3dQ4jY2pnlUHFh39Ry55RCd3y+SGIf4/TObNsrGB54Ju55Hf5Q KOeF6jyYw53IuHvKg4E7g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudejiedgudeggecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdefhedmnecujfgurhephf fvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgrnhhivghlucgiuhcu oegugihusegugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpefgfefggeejhfduie ekvdeuteffleeifeeuvdfhheejleejjeekgfffgefhtddtteenucevlhhushhtvghrufhi iigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 4 Dec 2023 15:57:00 -0500 (EST) From: Daniel Xu To: daniel@iogearbox.net, shuah@kernel.org, andrii@kernel.org, ast@kernel.org, steffen.klassert@secunet.com, antony.antony@secunet.com, alexei.starovoitov@gmail.com, yonghong.song@linux.dev, eddyz87@gmail.com Cc: mykolal@fb.com, martin.lau@linux.dev, song@kernel.org, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, devel@linux-ipsec.org, netdev@vger.kernel.org Subject: [PATCH bpf-next v4 05/10] bpf: selftests: test_loader: Support __btf_path() annotation Date: Mon, 4 Dec 2023 13:56:25 -0700 Message-ID: <16ffaa4173791228ed2274c1d06c0eaf159f5d9c.1701722991.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 12:57:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784386371963610466 X-GMAIL-MSGID: 1784386371963610466 This commit adds support for per-prog btf_custom_path. This is necessary for testing CO-RE relocations on non-vmlinux types using test_loader infrastructure. Acked-by: Andrii Nakryiko Signed-off-by: Daniel Xu --- tools/testing/selftests/bpf/progs/bpf_misc.h | 1 + tools/testing/selftests/bpf/test_loader.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/bpf_misc.h b/tools/testing/selftests/bpf/progs/bpf_misc.h index 799fff4995d8..2fd59970c43a 100644 --- a/tools/testing/selftests/bpf/progs/bpf_misc.h +++ b/tools/testing/selftests/bpf/progs/bpf_misc.h @@ -71,6 +71,7 @@ #define __retval_unpriv(val) __attribute__((btf_decl_tag("comment:test_retval_unpriv="#val))) #define __auxiliary __attribute__((btf_decl_tag("comment:test_auxiliary"))) #define __auxiliary_unpriv __attribute__((btf_decl_tag("comment:test_auxiliary_unpriv"))) +#define __btf_path(path) __attribute__((btf_decl_tag("comment:test_btf_path=" path))) /* Convenience macro for use with 'asm volatile' blocks */ #define __naked __attribute__((naked)) diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c index a350ecdfba4a..74ceb7877ae2 100644 --- a/tools/testing/selftests/bpf/test_loader.c +++ b/tools/testing/selftests/bpf/test_loader.c @@ -27,6 +27,7 @@ #define TEST_TAG_RETVAL_PFX_UNPRIV "comment:test_retval_unpriv=" #define TEST_TAG_AUXILIARY "comment:test_auxiliary" #define TEST_TAG_AUXILIARY_UNPRIV "comment:test_auxiliary_unpriv" +#define TEST_BTF_PATH "comment:test_btf_path=" /* Warning: duplicated in bpf_misc.h */ #define POINTER_VALUE 0xcafe4all @@ -58,6 +59,7 @@ struct test_spec { const char *prog_name; struct test_subspec priv; struct test_subspec unpriv; + const char *btf_custom_path; int log_level; int prog_flags; int mode_mask; @@ -288,6 +290,8 @@ static int parse_test_spec(struct test_loader *tester, goto cleanup; update_flags(&spec->prog_flags, flags, clear); } + } else if (str_has_pfx(s, TEST_BTF_PATH)) { + spec->btf_custom_path = s + sizeof(TEST_BTF_PATH) - 1; } } @@ -578,6 +582,9 @@ void run_subtest(struct test_loader *tester, } } + /* Implicitly reset to NULL if next test case doesn't specify */ + open_opts->btf_custom_path = spec->btf_custom_path; + tobj = bpf_object__open_mem(obj_bytes, obj_byte_cnt, open_opts); if (!ASSERT_OK_PTR(tobj, "obj_open_mem")) /* shouldn't happen */ goto subtest_cleanup;