2023-06-28 17:05:14

by SeongJae Park

[permalink] [raw]
Subject: [PATCH v2] btf: warn but return no error for NULL btf from __register_btf_kfunc_id_set()

__register_btf_kfunc_id_set() assumes .BTF to be part of the module's
.ko file if CONFIG_DEBUG_INFO_BTF is enabled. If that's not the case,
the function prints an error message and return an error. As a result,
such modules cannot be loaded.

However, the section could be stripped out during a build process. It
would be better to let the modules loaded, because their basic
functionalities have no problem[1], though the BTF functionalities will
not be supported. Make the function to lower the level of the message
from error to warn, and return no error.

[1] https://lore.kernel.org/bpf/[email protected]/

Reported-by: Alexander Egorenkov <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]/
Suggested-by: Kumar Kartikeya Dwivedi <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]/
Fixes: c446fdacb10d ("bpf: fix register_btf_kfunc_id_set for !CONFIG_DEBUG_INFO_BTF")
Cc: <[email protected]> # 5.18.x
Signed-off-by: SeongJae Park <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
---
Changes from v1
(https://lore.kernel.org/all/[email protected]/)
- Fix Fixes: tag (Jiri Olsa)
- Add 'Acked-by: ' from Jiri Olsa

kernel/bpf/btf.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 6b682b8e4b50..d683f034996f 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -7848,14 +7848,10 @@ static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,

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_err("missing module BTF, cannot register kfuncs\n");
- return -ENOENT;
- }
+ if (!kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF))
+ pr_warn("missing vmlinux BTF, cannot register kfuncs\n");
+ if (kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
+ pr_warn("missing module BTF, cannot register kfuncs\n");
return 0;
}
if (IS_ERR(btf))
--
2.25.1



2023-06-30 15:04:34

by Daniel Borkmann

[permalink] [raw]
Subject: Re: [PATCH v2] btf: warn but return no error for NULL btf from __register_btf_kfunc_id_set()

On 6/28/23 6:46 PM, SeongJae Park wrote:
> __register_btf_kfunc_id_set() assumes .BTF to be part of the module's
> .ko file if CONFIG_DEBUG_INFO_BTF is enabled. If that's not the case,
> the function prints an error message and return an error. As a result,
> such modules cannot be loaded.
>
> However, the section could be stripped out during a build process. It
> would be better to let the modules loaded, because their basic
> functionalities have no problem[1], though the BTF functionalities will
> not be supported. Make the function to lower the level of the message
> from error to warn, and return no error.
>
> [1] https://lore.kernel.org/bpf/[email protected]/
>
> Reported-by: Alexander Egorenkov <[email protected]>
> Link: https://lore.kernel.org/bpf/[email protected]/
> Suggested-by: Kumar Kartikeya Dwivedi <[email protected]>
> Link: https://lore.kernel.org/bpf/[email protected]/
> Fixes: c446fdacb10d ("bpf: fix register_btf_kfunc_id_set for !CONFIG_DEBUG_INFO_BTF")
> Cc: <[email protected]> # 5.18.x
> Signed-off-by: SeongJae Park <[email protected]>
> Acked-by: Jiri Olsa <[email protected]>

I presume this one is targeted at bpf (rather than bpf-next) tree, right?

> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 6b682b8e4b50..d683f034996f 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -7848,14 +7848,10 @@ static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,
>
> 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;
> - }

Why the above one needs to be changed? Do you also run into this case? vmlinux BTF
should be built-in in this case. I understand it's rather the one below for BTF +
modules instead, no?

> - if (kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES)) {
> - pr_err("missing module BTF, cannot register kfuncs\n");
> - return -ENOENT;
> - }
> + if (!kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF))
> + pr_warn("missing vmlinux BTF, cannot register kfuncs\n");
> + if (kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
> + pr_warn("missing module BTF, cannot register kfuncs\n");
> return 0;
> }
> if (IS_ERR(btf))
>


2023-06-30 19:58:30

by SeongJae Park

[permalink] [raw]
Subject: Re: [PATCH v2] btf: warn but return no error for NULL btf from __register_btf_kfunc_id_set()

Hi Daniel,

On Fri, 30 Jun 2023 16:53:38 +0200 Daniel Borkmann <[email protected]> wrote:

> On 6/28/23 6:46 PM, SeongJae Park wrote:
> > __register_btf_kfunc_id_set() assumes .BTF to be part of the module's
> > .ko file if CONFIG_DEBUG_INFO_BTF is enabled. If that's not the case,
> > the function prints an error message and return an error. As a result,
> > such modules cannot be loaded.
> >
> > However, the section could be stripped out during a build process. It
> > would be better to let the modules loaded, because their basic
> > functionalities have no problem[1], though the BTF functionalities will
> > not be supported. Make the function to lower the level of the message
> > from error to warn, and return no error.
> >
> > [1] https://lore.kernel.org/bpf/[email protected]/
> >
> > Reported-by: Alexander Egorenkov <[email protected]>
> > Link: https://lore.kernel.org/bpf/[email protected]/
> > Suggested-by: Kumar Kartikeya Dwivedi <[email protected]>
> > Link: https://lore.kernel.org/bpf/[email protected]/
> > Fixes: c446fdacb10d ("bpf: fix register_btf_kfunc_id_set for !CONFIG_DEBUG_INFO_BTF")
> > Cc: <[email protected]> # 5.18.x
> > Signed-off-by: SeongJae Park <[email protected]>
> > Acked-by: Jiri Olsa <[email protected]>
>
> I presume this one is targeted at bpf (rather than bpf-next) tree, right?

You're correct. It's not urgent for us, but I would prefer it to be merged
into all affected kernels as early as possible.

>
> > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> > index 6b682b8e4b50..d683f034996f 100644
> > --- a/kernel/bpf/btf.c
> > +++ b/kernel/bpf/btf.c
> > @@ -7848,14 +7848,10 @@ static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,
> >
> > 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;
> > - }
>
> Why the above one needs to be changed? Do you also run into this case? vmlinux BTF
> should be built-in in this case. I understand it's rather the one below for BTF +
> modules instead, no?

Again, you're correct. This change is not really needed. I was interpreting
Kumar's suggestion merely into code without thinking about his real meaning,
sorry. I will restore this in the next spin.


Thanks,
SJ

>
> > - if (kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES)) {
> > - pr_err("missing module BTF, cannot register kfuncs\n");
> > - return -ENOENT;
> > - }
> > + if (!kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF))
> > + pr_warn("missing vmlinux BTF, cannot register kfuncs\n");
> > + if (kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
> > + pr_warn("missing module BTF, cannot register kfuncs\n");
> > return 0;
> > }
> > if (IS_ERR(btf))
> >
>
>

2023-06-30 21:21:22

by Daniel Borkmann

[permalink] [raw]
Subject: Re: [PATCH v2] btf: warn but return no error for NULL btf from __register_btf_kfunc_id_set()

On 6/30/23 9:48 PM, SeongJae Park wrote:
> On Fri, 30 Jun 2023 16:53:38 +0200 Daniel Borkmann <[email protected]> wrote:
>> On 6/28/23 6:46 PM, SeongJae Park wrote:
>>> __register_btf_kfunc_id_set() assumes .BTF to be part of the module's
>>> .ko file if CONFIG_DEBUG_INFO_BTF is enabled. If that's not the case,
>>> the function prints an error message and return an error. As a result,
>>> such modules cannot be loaded.
>>>
>>> However, the section could be stripped out during a build process. It
>>> would be better to let the modules loaded, because their basic
>>> functionalities have no problem[1], though the BTF functionalities will
>>> not be supported. Make the function to lower the level of the message
>>> from error to warn, and return no error.
>>>
>>> [1] https://lore.kernel.org/bpf/[email protected]/
>>>
>>> Reported-by: Alexander Egorenkov <[email protected]>
>>> Link: https://lore.kernel.org/bpf/[email protected]/
>>> Suggested-by: Kumar Kartikeya Dwivedi <[email protected]>
>>> Link: https://lore.kernel.org/bpf/[email protected]/
>>> Fixes: c446fdacb10d ("bpf: fix register_btf_kfunc_id_set for !CONFIG_DEBUG_INFO_BTF")
>>> Cc: <[email protected]> # 5.18.x
>>> Signed-off-by: SeongJae Park <[email protected]>
>>> Acked-by: Jiri Olsa <[email protected]>
>>
>> I presume this one is targeted at bpf (rather than bpf-next) tree, right?
>
> You're correct. It's not urgent for us, but I would prefer it to be merged
> into all affected kernels as early as possible.

Ok, sounds good, bpf tree it is then.

>>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
>>> index 6b682b8e4b50..d683f034996f 100644
>>> --- a/kernel/bpf/btf.c
>>> +++ b/kernel/bpf/btf.c
>>> @@ -7848,14 +7848,10 @@ static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,
>>>
>>> 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;
>>> - }
>>
>> Why the above one needs to be changed? Do you also run into this case? vmlinux BTF
>> should be built-in in this case. I understand it's rather the one below for BTF +
>> modules instead, no?
>
> Again, you're correct. This change is not really needed. I was interpreting
> Kumar's suggestion merely into code without thinking about his real meaning,
> sorry. I will restore this in the next spin.

Perfect, I think after your v3 respin it should be good to land.

Thanks,
Daniel

2023-06-30 21:49:37

by SeongJae Park

[permalink] [raw]
Subject: Re: [PATCH v2] btf: warn but return no error for NULL btf from __register_btf_kfunc_id_set()

On Fri, 30 Jun 2023 22:52:24 +0200 Daniel Borkmann <[email protected]> wrote:

> On 6/30/23 9:48 PM, SeongJae Park wrote:
> > On Fri, 30 Jun 2023 16:53:38 +0200 Daniel Borkmann <[email protected]> wrote:
> >> On 6/28/23 6:46 PM, SeongJae Park wrote:
> >>> __register_btf_kfunc_id_set() assumes .BTF to be part of the module's
> >>> .ko file if CONFIG_DEBUG_INFO_BTF is enabled. If that's not the case,
> >>> the function prints an error message and return an error. As a result,
> >>> such modules cannot be loaded.
> >>>
> >>> However, the section could be stripped out during a build process. It
> >>> would be better to let the modules loaded, because their basic
> >>> functionalities have no problem[1], though the BTF functionalities will
> >>> not be supported. Make the function to lower the level of the message
> >>> from error to warn, and return no error.
> >>>
> >>> [1] https://lore.kernel.org/bpf/[email protected]/
> >>>
> >>> Reported-by: Alexander Egorenkov <[email protected]>
> >>> Link: https://lore.kernel.org/bpf/[email protected]/
> >>> Suggested-by: Kumar Kartikeya Dwivedi <[email protected]>
> >>> Link: https://lore.kernel.org/bpf/[email protected]/
> >>> Fixes: c446fdacb10d ("bpf: fix register_btf_kfunc_id_set for !CONFIG_DEBUG_INFO_BTF")
> >>> Cc: <[email protected]> # 5.18.x
> >>> Signed-off-by: SeongJae Park <[email protected]>
> >>> Acked-by: Jiri Olsa <[email protected]>
> >>
> >> I presume this one is targeted at bpf (rather than bpf-next) tree, right?
> >
> > You're correct. It's not urgent for us, but I would prefer it to be merged
> > into all affected kernels as early as possible.
>
> Ok, sounds good, bpf tree it is then.
>
> >>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> >>> index 6b682b8e4b50..d683f034996f 100644
> >>> --- a/kernel/bpf/btf.c
> >>> +++ b/kernel/bpf/btf.c
> >>> @@ -7848,14 +7848,10 @@ static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,
> >>>
> >>> 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;
> >>> - }
> >>
> >> Why the above one needs to be changed? Do you also run into this case? vmlinux BTF
> >> should be built-in in this case. I understand it's rather the one below for BTF +
> >> modules instead, no?
> >
> > Again, you're correct. This change is not really needed. I was interpreting
> > Kumar's suggestion merely into code without thinking about his real meaning,
> > sorry. I will restore this in the next spin.
>
> Perfect, I think after your v3 respin it should be good to land.

Thank you! I will send it by tomorrow, to give people enough time to comment.
If you don't want to wait, please let me know :)

Also, please note that this will not cleanly applicable on 6.1.y. I will
provide the backport to stable@ as soon as this is merged into the mainline.


Thanks,
SJ

>
> Thanks,
> Daniel
>

2023-07-03 17:19:25

by Daniel Borkmann

[permalink] [raw]
Subject: Re: [PATCH v2] btf: warn but return no error for NULL btf from __register_btf_kfunc_id_set()

On 6/30/23 11:02 PM, SeongJae Park wrote:
[...]
> Also, please note that this will not cleanly applicable on 6.1.y. I will
> provide the backport to stable@ as soon as this is merged into the mainline.

Perfect, thanks!