Message ID | 20221215005315.186787-1-connoro@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp65620wrn; Wed, 14 Dec 2022 17:10:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf4IS51Et62e3bXvYd21XXPuCV0UpjDZo6AcbnSreJvpIDOKItAmHg9Inm8e45h0KiczgEBD X-Received: by 2002:a17:906:369a:b0:7c1:381a:c000 with SMTP id a26-20020a170906369a00b007c1381ac000mr20426530ejc.58.1671066614205; Wed, 14 Dec 2022 17:10:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671066614; cv=none; d=google.com; s=arc-20160816; b=uSOzjSSIzN/d67ad7d/kQq8JJz+ZA7kkLtwjiPg0mbY4bwFuU13U5SEXNeWGxW60D6 0Y1wlEtU7yOMuGV3REsk6w/BMLDk7MMiLszZV1G3xWilkZOsR24WOif7paOL21JZMTp8 vQ+FpLk4VI9kfOMfkEgSG//5rY2+u9DDZxr1UpJ/5sSJ0rR8vyjirWx3usXBdc4VT1Bg evXFnpdgocouxMGlnAiqf65haPDPGgdd3Z/Z9F539+ram4KHNoSd/piaUWe7JcPFXnej AnYWeXVqYA8Gxvgn66iXre2NPvRIkimZWVOQDdGvcgyR/23M2Z3lxdsswwYHJmmYCDa9 1NOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=rBQYa4W8A+AJiUwNOuc8Q7CyuPP2yMOoaSr+CBtkpMs=; b=sYngwVNcLY8iRBx5owZdHthrEnuYIuutgS8yAOn8z1zTXzzhlcUxyI+/F913YeVbpD 2vo6nM0eORbSY7qaQCG6DHwOWAEp52hgOGFGrKEiQ32iVwe+mTN0qqj6EVVsPg56cZ/P Bq5mI5XTXw24xRHNLn5dcreiAORQQB5mcDsa1XKTVzpOczuV5CClqK4QW+sPA7o05x4f 1LQrHQdJBrtU5s7IqWJQQYIUF26DLpkEV4QQ/mdS5oyVu3REl+KtXKCkP3zDVrnhS9Ir ybKZBw/3Ma96HMngAgZLC6qAe0SNaO8n46PUQz10iLNS093kwoeFADoy3NI8Tx1dIOfk DzFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GdN50OAH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg35-20020a170907a42300b007c10b6790bfsi12541264ejc.68.2022.12.14.17.09.25; Wed, 14 Dec 2022 17:10:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GdN50OAH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229785AbiLOAxs (ORCPT <rfc822;jeantsuru.cumc.mandola@gmail.com> + 99 others); Wed, 14 Dec 2022 19:53:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229786AbiLOAxo (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 14 Dec 2022 19:53:44 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C77E31EDC for <linux-kernel@vger.kernel.org>; Wed, 14 Dec 2022 16:53:43 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id x17-20020a17090a8a9100b002196a3b190cso624550pjn.6 for <linux-kernel@vger.kernel.org>; Wed, 14 Dec 2022 16:53:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=rBQYa4W8A+AJiUwNOuc8Q7CyuPP2yMOoaSr+CBtkpMs=; b=GdN50OAHp+Whl7EboNBqIJn7oMiw0wMD07/V3yhXDi6aM7BuLjNewzP+7YDBpsBJ+t tJUZGFjcK+BXqCOAE5KeHD+NIjcRVsaGFUAxZJcZjE0kPoWv8u59DtRW6I8kOtHpzhKI +HhVWr7TCZM6RyQbe9z3q6nIWW96S2SgUnyv9GkLnPtSFh5MypWdIpt4l4MHD59sm8FZ QMDrkivQiAhZ7MHgT89D20umdttHAvZUFQnvyhXjR4PPagWsOwQTtnNLKHUibA4PzFgJ qqP9K1gIEbt5z5ffT3bfajfodA37Rs56abzXE28EyLy3FX/hlHtL5BQcqPHbupdC2HdE 9PuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rBQYa4W8A+AJiUwNOuc8Q7CyuPP2yMOoaSr+CBtkpMs=; b=o3OocnuIV8YZEJiJwTXsgw5YzoEKKjf3q0+c8XlUmWZd62oNKUUbp2O/kFFeie3XgV mGAkFdtss8vUR54QCW6Rx5xtyGtm/KCNkF9lJreGh5DZla8wUWfp7JGARDieacnMA1Lq kunLUayQal5Czf+jBPDIvaK9BtHOvTVWcjvbXqUZAsY0DgNUXgvibEhBrjJp4f4sUPrR ssiHSHiQA8fefXiOyzJxY2QV6dTTtVUBKgririmwcd86TxAsuuvtDQ6wOINmC5O0smOk zoTBaT/ezwE9jZ8ByCgGYCmFSRvkrNzMDMbJR59k0a4iXpEbVJZEW/3WUuOtSDyb4nW4 Js3w== X-Gm-Message-State: ANoB5pmyF509uNXy3BxkjBx8yRwgsBEbwSv/4eqJ/jpzfgQTro3tvQB2 rnv1/7HW50mpKVYaM1R8XpmIFW3+JpJK X-Received: from connoro.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:a99]) (user=connoro job=sendgmr) by 2002:a05:6a00:e17:b0:576:1d9e:caa0 with SMTP id bq23-20020a056a000e1700b005761d9ecaa0mr35297738pfb.81.1671065622919; Wed, 14 Dec 2022 16:53:42 -0800 (PST) Date: Thu, 15 Dec 2022 00:53:15 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog Message-ID: <20221215005315.186787-1-connoro@google.com> Subject: [PATCH bpf-next v2] bpf: btf: limit logging of ignored BTF mismatches From: "Connor O'Brien" <connoro@google.com> To: bpf@vger.kernel.org Cc: Martin KaFai Lau <martin.lau@linux.dev>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Andrii Nakryiko <andrii@kernel.org>, Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>, John Fastabend <john.fastabend@gmail.com>, KP Singh <kpsingh@kernel.org>, Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>, linux-kernel@vger.kernel.org, "Connor O'Brien" <connoro@google.com> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752240345889638843?= X-GMAIL-MSGID: =?utf-8?q?1752240345889638843?= |
Series |
[bpf-next,v2] bpf: btf: limit logging of ignored BTF mismatches
|
|
Commit Message
Connor O'Brien
Dec. 15, 2022, 12:53 a.m. UTC
Enabling CONFIG_MODULE_ALLOW_BTF_MISMATCH is an indication that BTF
mismatches are expected and module loading should proceed
anyway. Logging with pr_warn() on every one of these "benign"
mismatches creates unnecessary noise when many such modules are
loaded. Instead, handle this case with a single log warning that BTF
info may be unavailable.
Mismatches also result in calls to __btf_verifier_log() via
__btf_verifier_log_type() or btf_verifier_log_member(), adding several
additional lines of logging per mismatched module. Add checks to these
paths to skip logging for module BTF mismatches in the "allow
mismatch" case.
All existing logging behavior is preserved in the default
CONFIG_MODULE_ALLOW_BTF_MISMATCH=n case.
Signed-off-by: Connor O'Brien <connoro@google.com>
---
v2:
- Use pr_warn_once instead of skipping logging entirely
- Also skip btf verifier logs for ignored mismatches
v1: https://lore.kernel.org/bpf/20221109024155.2810410-1-connoro@google.com/
---
kernel/bpf/btf.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
Comments
On 12/14/22 4:53 PM, Connor O'Brien wrote: > Enabling CONFIG_MODULE_ALLOW_BTF_MISMATCH is an indication that BTF > mismatches are expected and module loading should proceed > anyway. Logging with pr_warn() on every one of these "benign" > mismatches creates unnecessary noise when many such modules are > loaded. Instead, handle this case with a single log warning that BTF > info may be unavailable. > > Mismatches also result in calls to __btf_verifier_log() via > __btf_verifier_log_type() or btf_verifier_log_member(), adding several > additional lines of logging per mismatched module. Add checks to these > paths to skip logging for module BTF mismatches in the "allow > mismatch" case. > > All existing logging behavior is preserved in the default > CONFIG_MODULE_ALLOW_BTF_MISMATCH=n case. > > Signed-off-by: Connor O'Brien <connoro@google.com> Ack with a few nits below. Acked-by: Yonghong Song <yhs@fb.com> > --- > v2: > - Use pr_warn_once instead of skipping logging entirely > - Also skip btf verifier logs for ignored mismatches > > v1: https://lore.kernel.org/bpf/20221109024155.2810410-1-connoro@google.com/ > --- > kernel/bpf/btf.c | 24 +++++++++++++++++++++--- > 1 file changed, 21 insertions(+), 3 deletions(-) > > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c > index f7dd8af06413..16b959b49595 100644 > --- a/kernel/bpf/btf.c > +++ b/kernel/bpf/btf.c > @@ -1404,6 +1404,13 @@ __printf(4, 5) static void __btf_verifier_log_type(struct btf_verifier_env *env, > if (log->level == BPF_LOG_KERNEL && !fmt) > return; > > + /* > + * Skip logging when loading module BTF with mismatches permitted > + */ Just use one line for the above comment. > + if (env->btf->base_btf && env->btf->kernel_btf && > + IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) > + return; I believe env->btf->base_btf alone is enough to test it should be a module btf. If env->btf->base_btf is true, env->btf->kernel_btf should also be true. The other way is not true, env->btf->kernel_btf is true, the btf could be vmlinux (env->btf->base_btf == NULL) or be a module. > + > __btf_verifier_log(log, "[%u] %s %s%s", > env->log_type_id, > btf_type_str(t), > @@ -1443,6 +1450,14 @@ static void btf_verifier_log_member(struct btf_verifier_env *env, > > if (log->level == BPF_LOG_KERNEL && !fmt) > return; > + > + /* > + * Skip logging when loading module BTF with mismatches permitted > + */ Same, just use one line for the above comments. > + if (env->btf->base_btf && env->btf->kernel_btf && > + IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) > + return; > + > /* The CHECK_META phase already did a btf dump. > * > * If member is logged again, it must hit an error in > @@ -7260,11 +7275,14 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op, > } > btf = btf_parse_module(mod->name, mod->btf_data, mod->btf_data_size); > if (IS_ERR(btf)) { > - pr_warn("failed to validate module [%s] BTF: %ld\n", > - mod->name, PTR_ERR(btf)); > kfree(btf_mod); > - if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) > + if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) { > + pr_warn("failed to validate module [%s] BTF: %ld\n", > + mod->name, PTR_ERR(btf)); > err = PTR_ERR(btf); > + } else { > + pr_warn_once("Kernel module BTF mismatch detected, BTF debug info may be unavailable for some modules\n"); > + } > goto out; > } > err = btf_alloc_id(btf);
On Thu, Dec 15, 2022 at 9:06 PM Yonghong Song <yhs@meta.com> wrote: > > > > On 12/14/22 4:53 PM, Connor O'Brien wrote: > > Enabling CONFIG_MODULE_ALLOW_BTF_MISMATCH is an indication that BTF > > mismatches are expected and module loading should proceed > > anyway. Logging with pr_warn() on every one of these "benign" > > mismatches creates unnecessary noise when many such modules are > > loaded. Instead, handle this case with a single log warning that BTF > > info may be unavailable. > > > > Mismatches also result in calls to __btf_verifier_log() via > > __btf_verifier_log_type() or btf_verifier_log_member(), adding several > > additional lines of logging per mismatched module. Add checks to these > > paths to skip logging for module BTF mismatches in the "allow > > mismatch" case. > > > > All existing logging behavior is preserved in the default > > CONFIG_MODULE_ALLOW_BTF_MISMATCH=n case. > > > > Signed-off-by: Connor O'Brien <connoro@google.com> > > Ack with a few nits below. > > Acked-by: Yonghong Song <yhs@fb.com> > > > --- > > v2: > > - Use pr_warn_once instead of skipping logging entirely > > - Also skip btf verifier logs for ignored mismatches > > > > v1: https://lore.kernel.org/bpf/20221109024155.2810410-1-connoro@google.com/ > > --- > > kernel/bpf/btf.c | 24 +++++++++++++++++++++--- > > 1 file changed, 21 insertions(+), 3 deletions(-) > > > > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c > > index f7dd8af06413..16b959b49595 100644 > > --- a/kernel/bpf/btf.c > > +++ b/kernel/bpf/btf.c > > @@ -1404,6 +1404,13 @@ __printf(4, 5) static void __btf_verifier_log_type(struct btf_verifier_env *env, > > if (log->level == BPF_LOG_KERNEL && !fmt) > > return; > > > > + /* > > + * Skip logging when loading module BTF with mismatches permitted > > + */ > > Just use one line for the above comment. > > > + if (env->btf->base_btf && env->btf->kernel_btf && > > + IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) > > + return; > > I believe env->btf->base_btf alone is enough to test it should be a > module btf. If env->btf->base_btf is true, env->btf->kernel_btf should > also be true. The other way is not true, env->btf->kernel_btf is true, > the btf could be vmlinux (env->btf->base_btf == NULL) or be a module. > Seems like we are also using log->level == BPF_LOG_KERNEL check for when working with kernel BTFs, so let's stick to the same pattern? > > + > > __btf_verifier_log(log, "[%u] %s %s%s", > > env->log_type_id, > > btf_type_str(t), > > @@ -1443,6 +1450,14 @@ static void btf_verifier_log_member(struct btf_verifier_env *env, > > > > if (log->level == BPF_LOG_KERNEL && !fmt) > > return; > > + > > + /* > > + * Skip logging when loading module BTF with mismatches permitted > > + */ > > Same, just use one line for the above comments. > > > + if (env->btf->base_btf && env->btf->kernel_btf && > > + IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) > > + return; > > + > > /* The CHECK_META phase already did a btf dump. > > * > > * If member is logged again, it must hit an error in > > @@ -7260,11 +7275,14 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op, > > } > > btf = btf_parse_module(mod->name, mod->btf_data, mod->btf_data_size); > > if (IS_ERR(btf)) { > > - pr_warn("failed to validate module [%s] BTF: %ld\n", > > - mod->name, PTR_ERR(btf)); > > kfree(btf_mod); > > - if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) > > + if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) { > > + pr_warn("failed to validate module [%s] BTF: %ld\n", > > + mod->name, PTR_ERR(btf)); > > err = PTR_ERR(btf); > > + } else { > > + pr_warn_once("Kernel module BTF mismatch detected, BTF debug info may be unavailable for some modules\n"); > > + } > > goto out; > > } > > err = btf_alloc_id(btf);
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index f7dd8af06413..16b959b49595 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -1404,6 +1404,13 @@ __printf(4, 5) static void __btf_verifier_log_type(struct btf_verifier_env *env, if (log->level == BPF_LOG_KERNEL && !fmt) return; + /* + * Skip logging when loading module BTF with mismatches permitted + */ + if (env->btf->base_btf && env->btf->kernel_btf && + IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) + return; + __btf_verifier_log(log, "[%u] %s %s%s", env->log_type_id, btf_type_str(t), @@ -1443,6 +1450,14 @@ static void btf_verifier_log_member(struct btf_verifier_env *env, if (log->level == BPF_LOG_KERNEL && !fmt) return; + + /* + * Skip logging when loading module BTF with mismatches permitted + */ + if (env->btf->base_btf && env->btf->kernel_btf && + IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) + return; + /* The CHECK_META phase already did a btf dump. * * If member is logged again, it must hit an error in @@ -7260,11 +7275,14 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op, } btf = btf_parse_module(mod->name, mod->btf_data, mod->btf_data_size); if (IS_ERR(btf)) { - pr_warn("failed to validate module [%s] BTF: %ld\n", - mod->name, PTR_ERR(btf)); kfree(btf_mod); - if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) + if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) { + pr_warn("failed to validate module [%s] BTF: %ld\n", + mod->name, PTR_ERR(btf)); err = PTR_ERR(btf); + } else { + pr_warn_once("Kernel module BTF mismatch detected, BTF debug info may be unavailable for some modules\n"); + } goto out; } err = btf_alloc_id(btf);