From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mail.toke.dk (Postfix) with ESMTPS id 04E38982BA7 for ; Tue, 28 Jun 2022 21:49:06 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=gLurwpuR DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656445747; x=1687981747; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RBYELKLN8xHT64H2SZNXxit0NQ+8Jyn2q2/+cMeDt7I=; b=gLurwpuRq71QP2gARel0lyWzxYeFAIXBhYsI64LyK9/yzgCCDrm8kXOq YawRIRyZ4eyHdAWpLxk6D7pwKf1rMmrEKUmMKhpS67FYWdgVMNmEGmb+j rWeNMUF6LHXbjG/B5yeEH9Qco2ykVr+llmSPuvUM3VqbzvVrIdwmAw8RG qzF1HRfQt2QZMzoIeuA4K58psXkxwu6UpFa0oj66M0c1TE1QX4o301VeW zSl/K+GNC39Owknz6zB4ywWUpyxLGRC3z1MdbxmNpB/XGO5JOSYBlAZTE AxYswttNrpzUABzeC8yZpFLINRmoywlXRbjugDlKlWfEi5AxmCvTdq4hs g==; X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="279378817" X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="279378817" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 12:49:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="565181145" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga006.jf.intel.com with ESMTP; 28 Jun 2022 12:48:58 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 25SJmr92022013; Tue, 28 Jun 2022 20:48:56 +0100 From: Alexander Lobakin To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Date: Tue, 28 Jun 2022 21:47:22 +0200 Message-Id: <20220628194812.1453059-3-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220628194812.1453059-1-alexandr.lobakin@intel.com> References: <20220628194812.1453059-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 7FUB7JI4YI4MP6JWYC3TVHVXBX3CEWGZ X-Message-ID-Hash: 7FUB7JI4YI4MP6JWYC3TVHVXBX3CEWGZ X-MailFrom: alexandr.lobakin@intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Alexander Lobakin , Larysa Zaremba , Michal Swiatkowski , Jesper Dangaard Brouer , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , Toke Hoiland-Jorgensen , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesse Brandeburg , John Fastabend , Yajun Deng , Willem de Bruijn , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, xdp-hints@xdp-project.net X-Mailman-Version: 3.3.5 Precedence: list Subject: [xdp-hints] [PATCH RFC bpf-next 02/52] libbpf: try to load vmlinux BTF from the kernel first List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Larysa Zaremba Try to acquire vmlinux BTF the same way it's being done for module BTFs. Use btf_load_next_with_info() and resort to the filesystem lookup only if it fails. Also, adjust debug messages in btf__load_vmlinux_btf() to reflect that it actually tries to load vmlinux BTF. Signed-off-by: Larysa Zaremba Signed-off-by: Alexander Lobakin --- tools/lib/bpf/btf.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 7e4dbf71fd52..8ecd50923fab 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -4927,6 +4927,25 @@ struct btf *btf_load_next_with_info(__u32 start_id, struct bpf_btf_info *info, } } +static struct btf *btf_load_vmlinux_from_kernel(void) +{ + char name[BTF_NAME_BUF_LEN] = { }; + struct bpf_btf_info info; + struct btf *btf; + + memset(&info, 0, sizeof(info)); + info.name = ptr_to_u64(name); + info.name_len = sizeof(name); + + btf = btf_load_next_with_info(0, &info, NULL, true); + if (!libbpf_get_error(btf)) { + close(btf->fd); + btf__set_fd(btf, -1); + } + + return btf; +} + /* * Probe few well-known locations for vmlinux kernel image and try to load BTF * data out of it to use for target BTF. @@ -4953,6 +4972,15 @@ struct btf *btf__load_vmlinux_btf(void) struct btf *btf; int i, err; + btf = btf_load_vmlinux_from_kernel(); + err = libbpf_get_error(btf); + pr_debug("loading vmlinux BTF from kernel: %d\n", err); + if (!err) + return btf; + + pr_info("failed to load vmlinux BTF from kernel: %d, will look through filesystem\n", + err); + uname(&buf); for (i = 0; i < ARRAY_SIZE(locations); i++) { @@ -4966,14 +4994,14 @@ struct btf *btf__load_vmlinux_btf(void) else btf = btf__parse_elf(path, NULL); err = libbpf_get_error(btf); - pr_debug("loading kernel BTF '%s': %d\n", path, err); + pr_debug("loading vmlinux BTF '%s': %d\n", path, err); if (err) continue; return btf; } - pr_warn("failed to find valid kernel BTF\n"); + pr_warn("failed to find valid vmlinux BTF\n"); return libbpf_err_ptr(-ESRCH); } -- 2.36.1