Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp899904rdb; Tue, 23 Jan 2024 20:37:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzbiQweh9i88rK3OIPeIN/iWUMI0CR91RYuXSNaWE6BnoeK7Nfr7w3VCoQvOrNAE63rM5n X-Received: by 2002:a05:6512:3d25:b0:510:f78:b4d0 with SMTP id d37-20020a0565123d2500b005100f78b4d0mr300468lfv.12.1706071045159; Tue, 23 Jan 2024 20:37:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706071045; cv=pass; d=google.com; s=arc-20160816; b=h4Vd+vCOtoOTKN/ub2ixnFJ3Gznbr0Z8pibEjsVJsFRcDar86V3LU0eYmjazgbUxXz UxCPiLU+xk0gQnTDZTldhLHJlFDL9dGede6e6/j48aVFXFsDFQ2keJagxJ3a1LCNwgmD SxsdCKRL66tUfCyeQjn1K+Db7nbQYE4CKLpxpyxmzGqxBzHVavG2dZAtj1bmlEhw1Y/H t8QuXOM53Sy+3U2gtMhHHxVQbdXzEOr5LGcrGnfkcdmta+CTlHn02rMDh0hoLKwH5xwj hp/HfJZnLLTGoNNTfZ9RzZ9lNRB+45/5VmDaV3aBCCZRBkGHtNbvGby9kn1xXHPn3vYl VR5Q== 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=JLmj7MysHRx2l1EP+DjhWCBE3phDUFYCOnPwerSOkKk=; fh=j7Lj4D96ERQSont+5C8jwuZWHNsQx9iIx7MI9a4x2ck=; b=dcqaSjD4lGVy95yqp2uydnW6NAukZf9QfCZO3AmLpjyKhRl3fG7G9/PDWQe1hszINn LOPa0Jk4qBYo1QHFn3Y4MA9lOEs6wq/RNfgikXRBrASssJaGjU3XWqRQAYVz6FYpUiGW Y9nsqRr0DeqdKMmGhVKAocAkpQk5PlMIKN1TVhON2n7XfJryZJniYT5OSE9rzS19GWQP tUkZE1MUo9Ioc7tjrdn1E8NtEBgXJFYf22vgPSWb1Pn38Fy0DEpmlss1Nf2Z2gTjeizu xSdignaOg4hnqzaQnNbDjQ2us5EYDlJgDN7tWRBPJukSHF8RvpcBi+F1+Ezlx67kMsLc F8Rg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=d+oau75T; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-36433-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36433-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id kl20-20020a170907995400b00a26dcaa21d1si12547545ejc.534.2024.01.23.20.37.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 20:37:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36433-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=d+oau75T; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-36433-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36433-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id D56B81F23FC2 for ; Wed, 24 Jan 2024 04:37:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB769C2C7; Wed, 24 Jan 2024 04:37:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="d+oau75T" Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 3057FE549 for ; Wed, 24 Jan 2024 04:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706071035; cv=none; b=UboegQzGNs4HG7pB0439qAxb5XIoGCA8n4HDfnDPhky5wWSFGIXVXjIu+YISGF+vLscca/AoNZw01wer+FdpjMRfUiJza7IkfBJJUMvd/2ghk3GPv0yZnOnLPh0tdF7ILnkvtCG6wI61hAjAJmW67Iwd7qMXXTH1OtJowI5spms= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706071035; c=relaxed/simple; bh=0+7QEnrtEA0ThnqoDJsGvCABoGBmYULuTyuQ7ehrnKI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=BrdczoScBAulmEZLUmLiG/+0fWsqQyOox15jTH3ZEd92/dITjiCTkAI5Fbt31dpRroie1uwXqjS7VGpe995c2II79YZRyqWObqyxky+g3joyklZYFs/C7rSADGEby2//Z0ikrTFissTN3Z7j4/K2R4EOTrP7+n4EYuFTRN0c3wE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=d+oau75T; arc=none smtp.client-ip=209.85.214.172 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=google.com Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1d5ce88b51cso110575ad.0 for ; Tue, 23 Jan 2024 20:37:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706071033; x=1706675833; 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=JLmj7MysHRx2l1EP+DjhWCBE3phDUFYCOnPwerSOkKk=; b=d+oau75TqWqnYt4vAl3ZPK/fO6yD4W3l+BHJpiyITSw6GEFdlADnt4Mb/h2qooic5q tuU8MkVpUbXmvJEV4qGuTZ5BiXa7wnr1885YUiN88DyWFKqX4r2EQ62jE+tsjs8LiZkx Cydbfcyh19Zl/7ag+aZcLciOOlSg9ow/gYe3k64eMToTsySXZytjTYdIoZGUuQOpeyQ+ NKh9STky56kjOCPbrWWw1IKPKbP+evq1W39gpa9Dosydu3DNEGnMzjfOntfO1b8EaZmz 8gMtipm+1hRrA6SHBMCKtjgdY7BrhoSHN6hgRcw9SRkX0wa0NjVG05t1+Y515pNc+60d ftqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706071033; x=1706675833; 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=JLmj7MysHRx2l1EP+DjhWCBE3phDUFYCOnPwerSOkKk=; b=tano0EeysC4FhwLFW8LddrGJe4XRPfOBnUZSaLluXK3mxJhBBRk1s3Tq/+XDv6tmtH Qb4Cp62CFJKny4WjUYjRD9ZIQSJMwDsxqTxRDL1LvI5EX2mqixu5CJZHitzwfzyOA3fx xVtQ6vYYNZpki0IfBtcTKQCB305NK32JQNX1zxJc0zHOndXOcKHTtpkMsDHtswEdoi5l /J0tBK2DCAFvLDPRfFDPB/c1w51QmWpKB8kuQ5crf235KmcW113VWViLRHkHPFBzsH3K QvyJDlC8wxnSbyhip5k8/pfP0NpGnGIXORX+4GhKvYRaAU/j5cXp92JJl/uE+XkdSO8g 4JzA== X-Gm-Message-State: AOJu0Yyr3qCp4PNBM0li0/+UqU05HSEg1OTXFbrjIRWjPsN01xv7Us/J wiOC8BwvT+nP/jGgu14ZhV/XXL52NGt1qyLS3LE8JFCY1wPItkb6TpqJXuFNyxvleTm1NUAasoI ezC1qPVGw3QOv8oo/WioEIi1ztewZw3H1zlZt X-Received: by 2002:a17:902:ea06:b0:1d7:48ef:e239 with SMTP id s6-20020a170902ea0600b001d748efe239mr49166plg.18.1706071033047; Tue, 23 Jan 2024 20:37:13 -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: Ian Rogers Date: Tue, 23 Jan 2024 20:37:01 -0800 Message-ID: Subject: Re: [PATCH v2] libbpf: Add some details for BTF parsing failures To: Andrii Nakryiko 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: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 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/vml= inux > > 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 CO= NFIG_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=3DY4gtELUsJxKNDDCO= vJzPHvjUVaUoeFAzNnig@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_ded= up *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 ju= st > > 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 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[] =3D { > > - /* try canonical vmlinux BTF through sysfs first */ > > - "/sys/kernel/btf/vmlinux", > > - /* fall back to trying to find vmlinux on disk otherwis= e */ > > "/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 CONFIG= _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. > > + } 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.release)= ; > > > > + 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 CONFIG= _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? Thanks, Ian > > return libbpf_err_ptr(-ESRCH); > > } > > > > -- > > 2.43.0.429.g432eaa2c6b-goog > >