Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1269788rdb; Wed, 24 Jan 2024 09:41:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVudt2qOSGeR6H/yFKt4xQoi4lh1sHHe0vkxHB9yNlbz9BicbPhRcrNg9BHbdo5ZmLKDlE X-Received: by 2002:a05:620a:394c:b0:783:8999:51f7 with SMTP id qs12-20020a05620a394c00b00783899951f7mr9304826qkn.79.1706118113745; Wed, 24 Jan 2024 09:41:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706118113; cv=pass; d=google.com; s=arc-20160816; b=f4WWFCXGLJ8EivxXOoAOc1fxe4aehxRxwmx8jFp7iRvlLcPHQhKQYsK3OzeQuAIizE s9dHe+KCnX+0hF1TLKIjTR+qCMvgti5Q5L67/yt3POgTqnpOJoL4+7/GzcS2QXc0pDbF KO/0irsMQ7mSXVQgmyZ4GzIeQyOysznI0y6Fj4mOhOhGjt/MfJQmqAkhdZMtO2deiAPn mZPPol3vFg53Thj0Jc7lBg/UjRV2iKJCGd/be28GcpLP3PQnNWGcg4uaLqh2HzJHCyqM VlMtifUdK2vb9n76uZyhm/j+pGBsaUho1CL+HYpcT3QuydsecRwN6I1tUT5yPO3iu5gd 99Fw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=bgfFSdtZ4BnmOTt2gcIZrv/r5XfBLYy1BOEk6GVFZKM=; fh=9KHQRv4mvLJmX7hhQBAu5462WkI8DoUNLblaB9doETE=; b=wDHPBoUI2BFhgdNtQZDCiScn68g7odcjwATTBIUXBgF1Npvgi4aMyObqYCNMBaDjK0 BfKkLpo2r5MChrfJenmuUq5t0DzlkUKqwhje/FkV3kz0DLUesu3Er01m6YeA5fI8npVg ad7+IRMbKckJqqVr3Ck+CfmSohE4X4a/f2cal796lSvjrx569cevh0+lM6hktsBgQrSN U0It+eUyjqgNtPs1dWpVY0hFm4h00/wc5mickfexSLj0R9fKFQrNI8jWFTLi+9jHlSrz 08maLPlwWQbBLK9aYHr7c4aMeO996SaTk/ghp7GfO1C0I65vehcloh3zyQ4aXQxm633i UGYw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="LX/B281V"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-37449-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37449-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f24-20020a37ad18000000b0078308612decsi10451451qkm.127.2024.01.24.09.41.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 09:41:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37449-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="LX/B281V"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-37449-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37449-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8789C1C23542 for ; Wed, 24 Jan 2024 17:40:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 62CC98612E; Wed, 24 Jan 2024 17:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LX/B281V" Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 A816386128; Wed, 24 Jan 2024 17:40:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706118033; cv=none; b=jTyxrg2yONgD+18Wviv54Qy7som/d7qXqHPg4uwSCWotv9ePmy84ZEvieli65BKn8dPV7M64xiNUvaMF8h7IIHr4T4KCXMl56MF+mi3kqtO0YvK18eZRvQrxfMWPCg8dNWbxl6Ac4y7qL7PIf+Ik1HuxcFNUy8BejSGtuv3aRyg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706118033; c=relaxed/simple; bh=oiL59PKtIuKSxT+2AXCI2xNYKv9ytkBUPHO51PfZedI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=qs+MmjSFwtkbo0nKww80ohOL3ZqOu5yyJSULERSMYGj75frMqZZMwDcWZ9cfuwN334ALG7G3GPyQHSVDsOue/2DpfiEyFUt0ZU4nPfQ5c22rP66PqeSBMtnhb96IHCqKse26rZArfCNOckLUyQCMVvJ71XRIuojVXNWVTd8nEd0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LX/B281V; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6ddc0c02593so390669b3a.3; Wed, 24 Jan 2024 09:40:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706118031; x=1706722831; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=bgfFSdtZ4BnmOTt2gcIZrv/r5XfBLYy1BOEk6GVFZKM=; b=LX/B281V8+zMrIDd1tdBU7vWj7ZdXG5OdxvIRhx8IXk4brzM3NGxzrBGcGtQmS4Tn1 GWKxbpKx5Bm7oa2XnwxocSA4NCnvhh/xM//1WcoyMjc9a+6HCv0SWTLaSuFXl3Mj7Zih skr6gy118rii36kumPGxmZ1Dmr6gtCwK1WLS37mtM+rElUzsZskrpV3kyr14i9ZFpol+ ltd0nhR7FAioMDvpSOE25apSjCIyo0RoWMyqwSh22M7ywGi5G7SdWF5ErnoGViPTxjHw qv1hxUUgIlFAOtUgFBOX/PfH0UsOedwYgJAUwv3EtEQNxxnrSNlzlNkqEIHw9hmYQ5am l4Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706118031; x=1706722831; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bgfFSdtZ4BnmOTt2gcIZrv/r5XfBLYy1BOEk6GVFZKM=; b=Hq5QUI16ACVI06qpWSBaoK/XKSGxpUIErOVvf1CyePzZQdsov/1ukfY73c3SK+pKmh 23pyiGE4ojxg13d9ONIqU8XPjLPLTmj4QnfboKWPsGnSod66Ef63WXwmXnBOJ1PILTe3 polmivI/x3VfWfbtUa+ju8LhTqc2Ge7SjiQ0oW0e8KRG2guPVZMSGgUtTNx30MQifKCC y3QTvLtjZ7D7XZC1AagmtOXaMAdnfLBZ4i8syk1vYplKThSRElo/CFexEPvJLxaSTEn4 W5ho1HjeoK0REvVl2SSVrw/tco0ZkeJbTjqYUExfo72+3diTDj0qehPpMnt9cuJj92A9 OcEQ== X-Gm-Message-State: AOJu0Yw1gg/H/5lddywNIBbYPTY7bqK0iuAQYqAOQV9erzJ96wGFzRWo GG9+rRNkCzeu8yymoDKgmnDPXNzsucEpGek7/FF602KDjNuR7arxMY1KQb9AkmbzndWp+m4xVeA SU/tw65LHJsgC1G4P//PxqCloi7c= X-Received: by 2002:a62:61c7:0:b0:6da:c208:7044 with SMTP id v190-20020a6261c7000000b006dac2087044mr3970269pfb.40.1706118030946; Wed, 24 Jan 2024 09:40:30 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240123204437.1322700-1-irogers@google.com> In-Reply-To: From: Andrii Nakryiko Date: Wed, 24 Jan 2024 09:40:19 -0800 Message-ID: Subject: Re: [PATCH v2] libbpf: Add some details for BTF parsing failures To: Ian Rogers Cc: 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jan 23, 2024 at 8:37=E2=80=AFPM Ian Rogers wro= te: > > On Tue, Jan 23, 2024 at 8:25=E2=80=AFPM Andrii Nakryiko > wrote: > > > > On Tue, Jan 23, 2024 at 12:44=E2=80=AFPM Ian Rogers wrote: > > > > > > As CONFIG_DEBUG_INFO_BTF is default off the existing "failed to find > > > valid kernel BTF" message makes diagnosing the kernel build issue som= e > > > 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/v= mlinux > > > 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=3DfU+DN_+Y=3DY4gtELUsJxKNDD= COvJzPHvjUVaUoeFAzNnig@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_d= edup *d) > > > return 0; > > > } > > > > > > +static struct btf *btf__load_vmlinux_btf_path(const char *path) > > > > I don't think we need this helper, you literally call btf__parse() and > > pr_debug(), that's all > > > > > +{ > > > + struct btf *btf; > > > + int err; > > > + > > > + btf =3D btf__parse(path, NULL); > > > + err =3D libbpf_get_error(btf); > > > > we should stop using libbpf_get_error, in libbpf v1.0+ it's best to do = just > > > > btf =3D btf__parse(path, NULL); > > if (!btf) { > > err =3D -errno; > > pr_debug(...); > > return NULL; > > } > > > > > + 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 t= o 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[] =3D { > > > - /* try canonical vmlinux BTF through sysfs first */ > > > - "/sys/kernel/btf/vmlinux", > > > - /* fall back to trying to find vmlinux on disk otherw= ise */ > > > "/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 =3D "/sys/kernel/btf/vmlinux"; > > > + if (faccessat(AT_FDCWD, location, R_OK, AT_EACCESS) =3D=3D 0)= { > > > + btf =3D btf__load_vmlinux_btf_path(location); > > > + if (btf) > > > + return btf; > > > + > > > + pr_warn("Failed to load vmlinux BTF from %s, was CONF= IG_DEBUG_INFO_BTF enabled?\n", > > > + location); > > > > Mentioning CONFIG_DEBUG_INFO_BTF seems inappropriate here, > > /sys/kernel/btf/vmlinux exists, we just failed to parse its data, > > right? So it's not about CONFIG_DEBUG_INFO_BTF, we just don't support > > something in BTF data. Just pr_warn("Failed to load vmlinux BTF from > > %s: %d", location, err); should be good > > I think that assumes a lot about a user, they understand what BTF > means, they know it is controlled by a kernel config option, and that > the config option needs to be overridden (as it is defaulted off) for > BTF to work. Given this escaped Raspberry Pi OS the potential for this > mistake seems high - hence wanting to highlight the config option. But there is nothing wrong with CONFIG_DEBUG_INFO_BTF, it is enabled, and hence there is /sys/kernel/btf/vmlinux on the system. With CONFIG_DEBUG_INFO_BTF suggestion you'll just lead users astray. What am I missing? > > > > + } else > > > + pr_warn("Unable to access canonical vmlinux BTF from = %s\n", location); > > > > here the question of CONFIG_DEBUG_INFO_BTF is more appropriate, if > > /sys/kernel/btf/vmlinux (on modern enough kernels) is missing, then > > CONFIG_DEBUG_INFO_BTF is missing, probably. But I'd emit this only > > after trying all the fallback paths and not finding anything. > > > > also stylistical nit: if one side of if has {}, the other has to have > > {} as well, even if it's just one line > > > > > > > > + uname(&buf); > > > for (i =3D 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.releas= e); > > > > > > + btf =3D btf__load_vmlinux_btf_path(path); > > > if (faccessat(AT_FDCWD, path, R_OK, AT_EACCESS)) > > > continue; > > > > > > - btf =3D btf__parse(path, NULL); > > > - err =3D libbpf_get_error(btf); > > > - pr_debug("loading kernel BTF '%s': %d\n", path, err); > > > - if (err) > > > - continue; > > > + btf =3D btf__load_vmlinux_btf_path(location); > > > + if (btf) > > > + return btf; > > > > > > - return btf; > > > + pr_warn("Failed to load vmlinux BTF from %s, was CONF= IG_DEBUG_INFO_BTF enabled?\n", > > > > we should do better here as well. We should distinguish between "there > > is vmlinux image, but it has no BTF" vs "there is no vmlinux image" vs > > "vmlinux image is there, there is BTF, but we can't parse it". See > > btf__parse(). We return -ENODATA if ELF doesn't have BTF, that's the > > first situation. We can probably use faccessat() check for second > > situation. Everything else can be reported as pr_debug() with location > > (but still no CONFIG_DEBUG_INFO_BTF, it's meaningless for fallback BTF > > locations) > > > > > + path); > > > } > > > > > > - pr_warn("failed to find valid kernel BTF\n"); > > > > and then here we can probably warn that we failed to find any kernel > > BTF, and suggest CONFIG_DEBUG_INFO_BTF > > Andrii, you've basically written this patch, can I pass this over to you? I think it would be great if you can finish thi, thanks. > > Thanks, > Ian > > > > return libbpf_err_ptr(-ESRCH); > > > } > > > > > > -- > > > 2.43.0.429.g432eaa2c6b-goog > > >