Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1013433rdb; Tue, 30 Jan 2024 05:42:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrA1TEzJxKC7op1QvTEUBcLcSmd7kY4jcQt32jXp9csx4wE989uYVbSI91kS6W5cYlBWHf X-Received: by 2002:ad4:5c8e:0:b0:68c:50fd:97b5 with SMTP id o14-20020ad45c8e000000b0068c50fd97b5mr4431822qvh.4.1706622131508; Tue, 30 Jan 2024 05:42:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706622131; cv=pass; d=google.com; s=arc-20160816; b=c61W06MEaEir23n2f4fDlTmuUYDnYKgjcNUxSB2qRAmx8bj0mIFtN0/Y+JI6Dh1I8E IVQlAuBK//ErSloDMzAKuadHUbBLVyIcNjF+Cuv4YXhr9vmqjnnhjVoaRowSHi9M0+dG 1vGtSkQ8p8OmaE39UIjXtJPtcCibw2Mge5WPZ5z7FVpTzpOyYLzjw4uEhn5bXe6PrJe3 nRaOmbmoILgK+4nJ5zpc4aabI3QuJ1fPzgRxKqRDymqyQ+HdO90vCaW7iKFzPjHBqGiy Xa1UnFMxnaT+T4cBTOvY2O2b82BcCch0oganTS69r1dApIngM2u5UCxwBm+g8UQWwOT1 kHAw== 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=EbgyJimBDL2xlM1FoVUE3T9sFVvozDsEdx2g1TNsrH8=; fh=j7Lj4D96ERQSont+5C8jwuZWHNsQx9iIx7MI9a4x2ck=; b=u3dsf2OeGqkJicMQIZn4+2f7cVxoGat+/IjMZetUdI6a4s1x/7S9TdlnCqVTHU9F+N 7s2eIhJTLcL4aRQ0k0fXr4bg4uTD8EZfV6QqUZFtOokyO/M9OV9jah5OJe4i0KlX8odM YPEyS0EybcE/oPIwr/iwAp93EMBzfMYNy6dqoj19MEbydjlT06a9qpY+ayA83+mHZ6uW p4ZhgCxMxrNYtR+4Oy0DuKaIYB4Xuvs5NLzajyg+1Q4q2IWJktOSsgO0IbdTA/PsOub2 uecZS+yV9bYu/i5U3xbTRaoDHxHFIIIiqPzbH8p7tPo4ek1gthkhTzCHriQpd8x2Z1ZU vDaA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=K1ohGfaW; 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-44708-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44708-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z21-20020a056214041500b0067f955d1353si10031266qvx.566.2024.01.30.05.42.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 05:42:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44708-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=K1ohGfaW; 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-44708-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44708-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3562F1C23735 for ; Tue, 30 Jan 2024 13:42:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F187A6D1BA; Tue, 30 Jan 2024 13:42:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="K1ohGfaW" Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) (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 6EE186BB36 for ; Tue, 30 Jan 2024 13:41:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706622121; cv=none; b=FzH4GtBpbF737qsJ4/Q3JDgQJgjEjzB9hCJ3nN28w6iqulpmWnqUQp5qGtzNOSZq18AS+ckHtl2Y9BuFu/2IWpwAzcs2e6O7Ic3+ah6Aj17Wcq93Qovh52V6GPvb1lOyT5WZ3QPLuuNwlGxklMaZKuQkjurv+uU3AUPXX1w9ljw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706622121; c=relaxed/simple; bh=0BeGZI2lfjCwg/wzly1hzEkL+SQ37NX3sQSXaRiSC/Q=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=VX1ISi+t4X0EAMQ+kKVL3/WK+9m7BZr7geW38wM5sxdMTnGdI7UV1mt3o5XfE0AuJ8fh1770216wuoMKxec3XyuQXY6vCy3IjraDYjTDRztrRZ/XFxkFt7XvKBvDLM6uof1z6WxuOlBXuI/PBfQ53KEIwi/K92Fn30MToMid2qA= 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=K1ohGfaW; arc=none smtp.client-ip=209.85.166.179 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-il1-f179.google.com with SMTP id e9e14a558f8ab-3638bd37107so192585ab.0 for ; Tue, 30 Jan 2024 05:41:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706622118; x=1707226918; 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=EbgyJimBDL2xlM1FoVUE3T9sFVvozDsEdx2g1TNsrH8=; b=K1ohGfaWtW9fnSR1o1Y5YWNOvXogVL9sK7bZ2uPuNMJ2JOkOXqzMWCLe0C0hpRvm5J 859OqDhlBmX+o8uy367x6oamtJdIo+X6bhzfT/ahZF60Xv3QoteS409g/NCMLYp+BGYR nlg6tEG62Pe6KJ8Cil+K6otY8x4cNFD7w5M3GC7j/eYsv3sOqYjaAxKzOUivcMJtYq9i YtjZAxB6QO2Tqd+X0eN+pCW36TfyM8vaHTZqYzVjnOkI7NUbFczxLQSt9qFsqHZ65tMX yUgxNelp6/AksrW1N4OubufGQkgAArwsg6/jUw7fWJhyg2Cm9sd1Ctk8m8oEXUtnSa44 eZpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706622118; x=1707226918; 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=EbgyJimBDL2xlM1FoVUE3T9sFVvozDsEdx2g1TNsrH8=; b=PruD0PvBI5ZwYZ6FLxSQigYyVK+6xTZkgBllcrdAFLBKxXWLAD3kF2gU8GbiTNZJ+N VWf21RJ6odDeIwIL464mIxelaG+1Cma3Pu6TSidVcgmzNNS/veeUugsC5sFb6P2om4Qu MQRLtx2HGCLX4/5IGlWtipA85Byl+LkhL7rNHWuq/quGjhxmLa6thCopmtLoT8FE9siR 785jSlut1oueZjYr8ReDlMO9GcMKv4yxTny9Ynl2tS0D2PoWCHc9k40qriM8Kq4suNUJ 7MrQOmA+cRR2Mq5P8RXaH4AycKnQ3elc7Fqz65BnEvq5lcLOC5Eu8TvZvCct5nURI6ug Hu9g== X-Gm-Message-State: AOJu0YwmdTSm4VIPswXc9TALEGV+WzmpM2TfhsKyaFaM8GLXc26wfV8B KTBMrwThb4Xh5TZEN2UQUokOcZbpNRap4K/5lpBsaXdqvZAAb9Tr1CvG4FcwA3WqruAA9DkaAEk M9pokDLKoP4LNitaGpO7w4IWs9am6mfOmav9b X-Received: by 2002:a92:d483:0:b0:363:7b27:283b with SMTP id p3-20020a92d483000000b003637b27283bmr183068ilg.11.1706622118267; Tue, 30 Jan 2024 05:41:58 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240125231840.1647951-1-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Tue, 30 Jan 2024 05:41:47 -0800 Message-ID: Subject: Re: [PATCH v3] 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 Mon, Jan 29, 2024 at 4:43=E2=80=AFPM Andrii Nakryiko wrote: > > On Thu, Jan 25, 2024 at 3:18=E2=80=AFPM Ian Rogers w= rote: > > > > 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 > > ``` > > > > After not accessible: > > ``` > > libbpf: access to canonical vmlinux (/sys/kernel/btf/vmlinux) to load B= TF failed: No such file or directory > > libbpf: was CONFIG_DEBUG_INFO_BTF enabled? > > libbpf: failed to find valid kernel BTF > > libbpf: Error loading vmlinux BTF: -3 > > ``` > > > > After not readable: > > ``` > > libbpf: unable to read canonical vmlinux (/sys/kernel/btf/vmlinux): Per= mission denied > > libbpf: failed to find valid kernel BTF > > libbpf: Error loading vmlinux BTF: -3 > > ``` > > > > Closes: https://lore.kernel.org/bpf/CAP-5=3DfU+DN_+Y=3DY4gtELUsJxKNDDCO= vJzPHvjUVaUoeFAzNnig@mail.gmail.com/ > > Signed-off-by: Ian Rogers > > > > --- > > v3. Try to address review comments from Andrii Nakryiko. > > I did some further simplifications and clean ups while applying. > > I dropped an extra faccessat(R_OK) check for /sys/kernel/btf/vmlinux > and instead if F_OK passes, just go ahead and try to parse > /sys/kernel/btf/vmlinux. If we have no access, we should get -EPERM or > -EACCESS (I didn't check which), otherwise we'll either parse or won't > find any BTF, both are errors. If /sys/kernel/btf/vmlinux exists, > there seems to be little point nowadays to try fallback locations, > kernel clearly is modern enough to generate /sys/kernel/btf/vmlinux, > so we just bail out with error. > > Please check the landed commit in bpf-next and let me know if it > doesn't cover your use case properly. It does, thanks Andrii! Ian > > --- > > tools/lib/bpf/btf.c | 35 +++++++++++++++++++++++++++-------- > > 1 file changed, 27 insertions(+), 8 deletions(-) > > > > diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c > > index ec92b87cae01..45983f42aba9 100644 > > --- a/tools/lib/bpf/btf.c > > +++ b/tools/lib/bpf/btf.c > > @@ -4932,10 +4932,9 @@ static int btf_dedup_remap_types(struct btf_dedu= p *d) > > */ > > struct btf *btf__load_vmlinux_btf(void) > > { > > + const char *canonical_vmlinux =3D "/sys/kernel/btf/vmlinux"; > > + /* 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", > > @@ -4946,14 +4945,34 @@ struct btf *btf__load_vmlinux_btf(void) > > }; > > char path[PATH_MAX + 1]; > > struct utsname buf; > > - struct btf *btf; > > + struct btf *btf =3D NULL; > > int i, err; > > > > - uname(&buf); > > + /* is canonical sysfs location accessible? */ > > + err =3D faccessat(AT_FDCWD, canonical_vmlinux, F_OK, AT_EACCESS= ); > > + if (err) { > > + pr_warn("access to canonical vmlinux (%s) to load BTF f= ailed: %s\n", > > + canonical_vmlinux, strerror(errno)); > > + pr_warn("was CONFIG_DEBUG_INFO_BTF enabled?\n"); > > + } else { > > + err =3D faccessat(AT_FDCWD, canonical_vmlinux, R_OK, AT= _EACCESS); > > + if (err) { > > + pr_warn("unable to read canonical vmlinux (%s):= %s\n", > > + canonical_vmlinux, strerror(errno)); > > + } > > + } > > + if (!err) { > > + /* load canonical and return any parsing failures */ > > + btf =3D btf__parse(canonical_vmlinux, NULL); > > + err =3D libbpf_get_error(btf); > > + pr_debug("loading kernel BTF '%s': %d\n", canonical_vml= inux, err); > > + return btf; > > + } > > > > + /* try fallback locations */ > > + uname(&buf); > > for (i =3D 0; i < ARRAY_SIZE(locations); i++) { > > snprintf(path, PATH_MAX, locations[i], buf.release); > > - > > if (faccessat(AT_FDCWD, path, R_OK, AT_EACCESS)) > > continue; > > > > @@ -4965,9 +4984,9 @@ struct btf *btf__load_vmlinux_btf(void) > > > > return btf; > > } > > - > > pr_warn("failed to find valid kernel BTF\n"); > > - return libbpf_err_ptr(-ESRCH); > > + /* return the last error or ESRCH if no fallback locations were= found */ > > + return btf ?: libbpf_err_ptr(-ESRCH); > > } > > > > struct btf *libbpf_find_kernel_btf(void) __attribute__((alias("btf__lo= ad_vmlinux_btf"))); > > -- > > 2.43.0.429.g432eaa2c6b-goog > >