All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Geliang Tang <geliang@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Matthieu Baerts <matttbe@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Geliang Tang <tanggeliang@kylinos.cn>,
	bpf@vger.kernel.org, mptcp@lists.linux.dev
Subject: Re: [PATCH bpf-next v5 2/3] bpf, btf: Add check_btf_kconfigs helper
Date: Thu, 8 Feb 2024 11:07:23 +0100	[thread overview]
Message-ID: <ZcSn24Isfsg45jBJ@krava> (raw)
In-Reply-To: <fa5537fc55f1e4d0bfd686598c81b7ab9dbd82b7.1707373307.git.tanggeliang@kylinos.cn>

On Thu, Feb 08, 2024 at 02:24:22PM +0800, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> This patch extracts duplicate code on error path when btf_get_module_btf()
> returns NULL from the functions __register_btf_kfunc_id_set() and
> register_btf_id_dtor_kfuncs() into a new helper named check_btf_kconfigs()
> to check CONFIG_DEBUG_INFO_BTF and CONFIG_DEBUG_INFO_BTF_MODULES in it.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  kernel/bpf/btf.c | 33 +++++++++++++++------------------
>  1 file changed, 15 insertions(+), 18 deletions(-)
> 
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 16eb937eca46..e318df7f0071 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -7738,6 +7738,17 @@ static struct btf *btf_get_module_btf(const struct module *module)
>  	return btf;
>  }
>  
> +static int check_btf_kconfigs(const struct module *module)
> +{
> +	if (!module && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {
> +		pr_err("missing vmlinux BTF, cannot register kfuncs\n");
> +		return -ENOENT;
> +	}
> +	if (module && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
> +		pr_warn("missing module BTF, cannot register kfuncs\n");
> +	return 0;
> +}
> +
>  BPF_CALL_4(bpf_btf_find_by_name_kind, char *, name, int, name_sz, u32, kind, int, flags)
>  {
>  	struct btf *btf = NULL;
> @@ -8098,15 +8109,8 @@ static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,
>  	int ret, i;
>  
>  	btf = btf_get_module_btf(kset->owner);
> -	if (!btf) {
> -		if (!kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {
> -			pr_err("missing vmlinux BTF, cannot register kfuncs\n");
> -			return -ENOENT;
> -		}
> -		if (kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
> -			pr_warn("missing module BTF, cannot register kfuncs\n");
> -		return 0;
> -	}
> +	if (!btf)
> +		return check_btf_kconfigs(kset->owner);
>  	if (IS_ERR(btf))
>  		return PTR_ERR(btf);
>  
> @@ -8214,15 +8218,8 @@ int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_c
>  	int ret;
>  
>  	btf = btf_get_module_btf(owner);
> -	if (!btf) {
> -		if (!owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {
> -			pr_err("missing vmlinux BTF, cannot register dtor kfuncs\n");
> -			return -ENOENT;
> -		}
> -		if (owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
> -			pr_warn("missing module BTF, cannot register dtor kfuncs\n");

nit, we do lose the 'dtor' from the message but I think it's ok,
for the patchset:

Acked-by: Jiri Olsa <jolsa@kernel.org>

jirka

> -		return 0;
> -	}
> +	if (!btf)
> +		return check_btf_kconfigs(owner);
>  	if (IS_ERR(btf))
>  		return PTR_ERR(btf);
>  
> -- 
> 2.40.1
> 

  reply	other threads:[~2024-02-08 10:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-08  6:24 [PATCH bpf-next v5 0/3] bpf, btf: Add DEBUG_INFO_BTF checks for __register_bpf_struct_ops Geliang Tang
2024-02-08  6:24 ` [PATCH bpf-next v5 1/3] bpf, btf: Fix return value of register_btf_id_dtor_kfuncs Geliang Tang
2024-02-08  6:24 ` [PATCH bpf-next v5 2/3] bpf, btf: Add check_btf_kconfigs helper Geliang Tang
2024-02-08 10:07   ` Jiri Olsa [this message]
2024-02-08 19:53     ` Martin KaFai Lau
2024-02-08  6:24 ` [PATCH bpf-next v5 3/3] bpf, btf: Check btf for register_bpf_struct_ops Geliang Tang
2024-02-08  7:16   ` bpf, btf: Check btf for register_bpf_struct_ops: Tests Results MPTCP CI
2024-02-08  7:32   ` MPTCP CI
2024-02-08 10:57   ` MPTCP CI
2024-02-08 11:14   ` MPTCP CI
2024-02-08 19:50 ` [PATCH bpf-next v5 0/3] bpf, btf: Add DEBUG_INFO_BTF checks for __register_bpf_struct_ops patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZcSn24Isfsg45jBJ@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=geliang@kernel.org \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=tanggeliang@kylinos.cn \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.