From patchwork Tue Jan 23 20:44:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 191191 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp595378dyi; Tue, 23 Jan 2024 12:45:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IEj9yurye9kEAkB3f14OAttWf/rZzeZm0RjRM345yEKA6IPMnswt31J7/Oze7ZDjKQOVk0j X-Received: by 2002:a05:6a20:1aa9:b0:19a:da1c:dad8 with SMTP id ci41-20020a056a201aa900b0019ada1cdad8mr3197304pzb.54.1706042701917; Tue, 23 Jan 2024 12:45:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706042701; cv=pass; d=google.com; s=arc-20160816; b=WZHQyPpb6eA290Jz6OWI4wxWUHua3K9U3g3Qre8fBHvUkNo0eB/jYd6fnWrhz7OgWg 7nPXakJE43t+Btn0UQT0npHh8p6S0EnUdBG66XYVnwpRtLren6i41gj14sEJxjQnpH65 Ve7YmInx07nyk8TCyuFbcfCh5gVpUbhIefw5NupuRUHZJQgmeeLCU/nSHGpV2m4eAZLB MTszZPcRSkcTTrY/cwNjwQ2m1Y8kLNRQ9YzjoeJ0kLcpzoZLBaOTlfnsfQteiudGrwah ukv0sfmAlMfKr6kijW3RCdKl3AIimYJ2NeHHy1nfoKtlDdOske/XzQRPHgTI4fc6POyZ mGrA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date:dkim-signature; bh=gY0AJEtwU5pTI4pJWheKjEqkk5Hi/1V7D+eNS/EusLQ=; fh=xutJfxrk0t+SuXtR9TxDu0VafzqB14zLe0hQOZNruiQ=; b=VdJQJMn1lB0rshSbDRUWzSG67Kx9XhotDmPOn88D/dKCDwSzsk8u+c2FH9gztV5OVf X5y/hNZi+GY3v3r7bblGnqteFo0a8LSf3+c5y6MD9IQgaiXsytRD3I6/Lb1SI6xnXwxB y8UZ4gUYsHIbmQ4GN9eE1FGRElElnx0o1176r740JAe4Vpz4OEDwxoB63Gky9IkwsX/e Hw7vKECUnCuqQMEGJg18PaJxYB9/GIXZGO94olkv9usj27zCgG/3unduuKxAruRApWLT tphueRyb5Kr+3zzIBLeTmM0Ngsk0awLLmNyOXeG0SfYPAuVRSEPdG8vzWQeGfYZSHShI nDnQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=o1apjl9m; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-36037-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36037-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g130-20020a636b88000000b005b99697d854si10118604pgc.673.2024.01.23.12.45.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 12:45:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36037-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=o1apjl9m; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-36037-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36037-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9CDFA28C313 for ; Tue, 23 Jan 2024 20:45:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB5D053BA; Tue, 23 Jan 2024 20:44:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="o1apjl9m" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 830672109 for ; Tue, 23 Jan 2024 20:44:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706042684; cv=none; b=Up56T4Bd1a07sBhvzeOrVmi51XaWNp8Mf7/pN93MVn/F9b/+77ehjh+wbnIhNtAXF38Rp5KIBn5+kPAn5wxbwNGFU+mcTwSoRondxWyG+Qd9fX8j/RcdekNK7tCDpEhLB5elZb+cXGh8Mo3w1KMH7tlcuMQGZ+XrDeMu8iUZZKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706042684; c=relaxed/simple; bh=3jCvRB4HD/I2qU3Zjc5yS28yBs6yYnwm+im0L/hbAtA=; h=Date:Message-Id:Mime-Version:Subject:From:To:Cc:Content-Type; b=Tv3Ffd3+vn6gnRhvhQm+UrHCN6qMVBrcbbDMuPWHr0/X+YAHKH6uATS0d1SzD9Qk5mTQEm1OFsZbcwwoU0PvCxQU+mPEM0yz1EPgZJboJI2cg2TvxiZjrDIy9ImvEOTHTnb1lOFSvWM+bon9hYqlkyVxcvkfuddCVgOt64h7Pps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=o1apjl9m; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc22f3426aeso7944461276.1 for ; Tue, 23 Jan 2024 12:44:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706042681; x=1706647481; darn=vger.kernel.org; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=gY0AJEtwU5pTI4pJWheKjEqkk5Hi/1V7D+eNS/EusLQ=; b=o1apjl9mHfWS6GeE0NOEvNp5Scywe71cfAi+6ducGQrN71mEGRRqDk9MnxIDz+Sb2R pYrVV3raux06gu3x2MOWSG00DVgDCO9BD6NkZ3dmeDFJ4UUu9r8dn832NluHRoWIi59O vjJBB8BOpekTpU8LU39tAhDtojaHpnXa5C4FKuOAO2JNd+UEnDdVBk1Lq9GyPwXzSfQ2 3WJ+B5W+UkxM46niXyD5SsM+wzf5T6nZLzkvCIwt/lwiO6tyhAXfLSqTCniLofM+wArM y8qHLmwhupjRxgtq9w2COW3MtUAFiggvWEoMyYl26GQcHxDxiD/Zgiej2PV1CLJqcLKy z/8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706042681; x=1706647481; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gY0AJEtwU5pTI4pJWheKjEqkk5Hi/1V7D+eNS/EusLQ=; b=kU/8ABLHAFsAEYxcGK1bYE8+KtWLwWkalZUIMUDoFya8ZKGyrE/UTAJ3XBDlmsOtgk 9qlRy7KOcjC2mViNPn5/Stp4kjWFrRffJ5zKJ4F9Fctzl6uxBlQ+9qOpd5RAuNd8vTB1 b1rm6AquRsMfOjCFCBsNAxLB+3xE1BKgqjy3FId1AEXzFzEHIlKWII2Mc+Oc6iv4HPK+ jsjEJe4o/5NX/KMqCZdhWz916IasJ6ztJWaIJgMwR0R4q4mOVTY+5qabX0Tl/NwDNbVK W7nuM9GHZMWOpwy7QkyaT0yHGyyW/7Ro1kdHJf1koMH4E2DeHPGntvcrbOaSGuJ0WkA7 chlg== X-Gm-Message-State: AOJu0YzqFcTk9xOwsx8pJDE4kbbU7PeillHMYLpxl+SXMRver0IcBrL9 N4nB3jPOtN9ieiYOFLKFXnJGToGGXWTp39qnAIowBYU7btw9ZR4T7aCFZJj5t4ehrb+rkObgNUw Ktbtmnw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:b37:2438:2b2f:daae]) (user=irogers job=sendgmr) by 2002:a25:c3c7:0:b0:dbf:4359:326a with SMTP id t190-20020a25c3c7000000b00dbf4359326amr55841ybf.1.1706042681557; Tue, 23 Jan 2024 12:44:41 -0800 (PST) Date: Tue, 23 Jan 2024 12:44:37 -0800 Message-Id: <20240123204437.1322700-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v2] libbpf: Add some details for BTF parsing failures From: Ian Rogers To: Alan Maguire , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ian Rogers X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788915432615608347 X-GMAIL-MSGID: 1788915432615608347 As CONFIG_DEBUG_INFO_BTF is default off the existing "failed to find valid kernel BTF" message makes diagnosing the kernel build issue some what cryptic. Add a little more detail with the hope of helping users. Before: ``` libbpf: failed to find valid kernel BTF libbpf: Error loading vmlinux BTF: -3 libbpf: failed to load object 'lock_contention_bpf' libbpf: failed to load BPF skeleton 'lock_contention_bpf': -3 ``` After no access /sys/kernel/btf/vmlinux: ``` libbpf: Unable to access canonical vmlinux BTF from /sys/kernel/btf/vmlinux libbpf: Error loading vmlinux BTF: -3 libbpf: failed to load object 'lock_contention_bpf' libbpf: failed to load BPF skeleton 'lock_contention_bpf': -3 ``` After no BTF /sys/kernel/btf/vmlinux: ``` libbpf: Failed to load vmlinux BTF from /sys/kernel/btf/vmlinux, was CONFIG_DEBUG_INFO_BTF enabled? libbpf: Error loading vmlinux BTF: -3 libbpf: failed to load object 'lock_contention_bpf' libbpf: failed to load BPF skeleton 'lock_contention_bpf': -3 ``` Closes: https://lore.kernel.org/bpf/CAP-5=fU+DN_+Y=Y4gtELUsJxKNDDCOvJzPHvjUVaUoeFAzNnig@mail.gmail.com/ Signed-off-by: Ian Rogers --- v2. Try to address review comments from Andrii Nakryiko. --- tools/lib/bpf/btf.c | 49 ++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index ee95fd379d4d..d8a05dda0836 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -4920,16 +4920,25 @@ static int btf_dedup_remap_types(struct btf_dedup *d) return 0; } +static struct btf *btf__load_vmlinux_btf_path(const char *path) +{ + struct btf *btf; + int err; + + btf = btf__parse(path, NULL); + err = libbpf_get_error(btf); + pr_debug("loading kernel BTF '%s': %d\n", path, err); + return err ? NULL : btf; +} + /* * Probe few well-known locations for vmlinux kernel image and try to load BTF * data out of it to use for target BTF. */ struct btf *btf__load_vmlinux_btf(void) { + /* fall back locations, trying to find vmlinux on disk */ const char *locations[] = { - /* try canonical vmlinux BTF through sysfs first */ - "/sys/kernel/btf/vmlinux", - /* fall back to trying to find vmlinux on disk otherwise */ "/boot/vmlinux-%1$s", "/lib/modules/%1$s/vmlinux-%1$s", "/lib/modules/%1$s/build/vmlinux", @@ -4938,29 +4947,41 @@ struct btf *btf__load_vmlinux_btf(void) "/usr/lib/debug/boot/vmlinux-%1$s.debug", "/usr/lib/debug/lib/modules/%1$s/vmlinux", }; - char path[PATH_MAX + 1]; + const char *location; struct utsname buf; struct btf *btf; - int i, err; + int i; - uname(&buf); + /* try canonical vmlinux BTF through sysfs first */ + location = "/sys/kernel/btf/vmlinux"; + if (faccessat(AT_FDCWD, location, R_OK, AT_EACCESS) == 0) { + btf = btf__load_vmlinux_btf_path(location); + if (btf) + return btf; + + pr_warn("Failed to load vmlinux BTF from %s, was CONFIG_DEBUG_INFO_BTF enabled?\n", + location); + } else + pr_warn("Unable to access canonical vmlinux BTF from %s\n", location); + uname(&buf); for (i = 0; i < ARRAY_SIZE(locations); i++) { - snprintf(path, PATH_MAX, locations[i], buf.release); + char path[PATH_MAX + 1]; + + snprintf(path, sizeof(path), locations[i], buf.release); + btf = btf__load_vmlinux_btf_path(path); if (faccessat(AT_FDCWD, path, R_OK, AT_EACCESS)) continue; - btf = btf__parse(path, NULL); - err = libbpf_get_error(btf); - pr_debug("loading kernel BTF '%s': %d\n", path, err); - if (err) - continue; + btf = btf__load_vmlinux_btf_path(location); + if (btf) + return btf; - return btf; + pr_warn("Failed to load vmlinux BTF from %s, was CONFIG_DEBUG_INFO_BTF enabled?\n", + path); } - pr_warn("failed to find valid kernel BTF\n"); return libbpf_err_ptr(-ESRCH); }