[PATCH] bpf, btf: Add DEBUG_INFO_BTF checks for __register_bpf_struct_ops

Geliang Tang posted 1 patch 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/multipath-tcp/mptcp_net-next tags/patchew/beca71007a184b2d199f404a471f020fd4359823.1706863036.git.tanggeliang@kylinos.cn
There is a newer version of this series
kernel/bpf/btf.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
[PATCH] bpf, btf: Add DEBUG_INFO_BTF checks for __register_bpf_struct_ops
Posted by Geliang Tang 9 months ago
From: Geliang Tang <tanggeliang@kylinos.cn>

Similar to the handling in the functions __register_btf_kfunc_id_set() and
register_btf_id_dtor_kfuncs(), this patch adds CONFIG_DEBUG_INFO_BTF and
CONFIG_DEBUG_INFO_BTF_MODULES checks for __register_bpf_struct_ops() on
error path too when btf_get_module_btf() returns NULL.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 kernel/bpf/btf.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index ef380e546952..381676add335 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -8880,8 +8880,15 @@ int __register_bpf_struct_ops(struct bpf_struct_ops *st_ops)
 	int err = 0;
 
 	btf = btf_get_module_btf(st_ops->owner);
-	if (!btf)
-		return -EINVAL;
+	if (!btf) {
+		if (!st_ops->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {
+			pr_err("missing vmlinux BTF, cannot register structs\n");
+			return -EINVAL;
+		}
+		if (st_ops->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
+			pr_warn("missing module BTF, cannot register structs\n");
+		return 0;
+	}
 
 	log = kzalloc(sizeof(*log), GFP_KERNEL | __GFP_NOWARN);
 	if (!log) {
-- 
2.40.1
Re: [PATCH] bpf, btf: Add DEBUG_INFO_BTF checks for __register_bpf_struct_ops
Posted by Jiri Olsa 9 months ago
On Fri, Feb 02, 2024 at 05:18:48PM +0800, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> Similar to the handling in the functions __register_btf_kfunc_id_set() and
> register_btf_id_dtor_kfuncs(), this patch adds CONFIG_DEBUG_INFO_BTF and
> CONFIG_DEBUG_INFO_BTF_MODULES checks for __register_bpf_struct_ops() on
> error path too when btf_get_module_btf() returns NULL.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  kernel/bpf/btf.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index ef380e546952..381676add335 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -8880,8 +8880,15 @@ int __register_bpf_struct_ops(struct bpf_struct_ops *st_ops)
>  	int err = 0;
>  
>  	btf = btf_get_module_btf(st_ops->owner);
> -	if (!btf)
> -		return -EINVAL;
> +	if (!btf) {
> +		if (!st_ops->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {
> +			pr_err("missing vmlinux BTF, cannot register structs\n");
> +			return -EINVAL;
> +		}
> +		if (st_ops->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
> +			pr_warn("missing module BTF, cannot register structs\n");
> +		return 0;

given that we have the same code in 2 other functions
would it make sense to add function for that?

jirka

> +	}
>  
>  	log = kzalloc(sizeof(*log), GFP_KERNEL | __GFP_NOWARN);
>  	if (!log) {
> -- 
> 2.40.1
>