BPF List
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: Add missing btf_put to register_btf_id_dtor_kfuncs
@ 2023-01-19 14:13 Jiri Olsa
  2023-01-19 17:01 ` Kumar Kartikeya Dwivedi
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2023-01-19 14:13 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Kumar Kartikeya Dwivedi, bpf, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo

We take the BTF reference before we register dtors and we need
to put it back when it's done.

We probably won't se a problem with kernel BTF, but module BTF
would stay loaded (because of the extra ref) even when its module
is removed.

Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Fixes: 5ce937d613a4 ("bpf: Populate pairs of btf_id and destructor kfunc in btf")
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 kernel/bpf/btf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index f7dd8af06413..b7017cae6fd1 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -7782,9 +7782,9 @@ int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_c
 
 	sort(tab->dtors, tab->cnt, sizeof(tab->dtors[0]), btf_id_cmp_func, NULL);
 
-	return 0;
 end:
-	btf_free_dtor_kfunc_tab(btf);
+	if (ret)
+		btf_free_dtor_kfunc_tab(btf);
 	btf_put(btf);
 	return ret;
 }
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] bpf: Add missing btf_put to register_btf_id_dtor_kfuncs
  2023-01-19 14:13 [PATCH bpf] bpf: Add missing btf_put to register_btf_id_dtor_kfuncs Jiri Olsa
@ 2023-01-19 17:01 ` Kumar Kartikeya Dwivedi
  2023-01-19 22:36   ` Alexei Starovoitov
  0 siblings, 1 reply; 3+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2023-01-19 17:01 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo

On Thu, 19 Jan 2023 at 19:43, Jiri Olsa <jolsa@kernel.org> wrote:
>
> We take the BTF reference before we register dtors and we need
> to put it back when it's done.
>
> We probably won't se a problem with kernel BTF, but module BTF
> would stay loaded (because of the extra ref) even when its module
> is removed.
>
> Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> Fixes: 5ce937d613a4 ("bpf: Populate pairs of btf_id and destructor kfunc in btf")
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---

Thanks for the fix.
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>

>  kernel/bpf/btf.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index f7dd8af06413..b7017cae6fd1 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -7782,9 +7782,9 @@ int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_c
>
>         sort(tab->dtors, tab->cnt, sizeof(tab->dtors[0]), btf_id_cmp_func, NULL);
>
> -       return 0;
>  end:
> -       btf_free_dtor_kfunc_tab(btf);
> +       if (ret)
> +               btf_free_dtor_kfunc_tab(btf);
>         btf_put(btf);
>         return ret;
>  }
> --
> 2.39.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] bpf: Add missing btf_put to register_btf_id_dtor_kfuncs
  2023-01-19 17:01 ` Kumar Kartikeya Dwivedi
@ 2023-01-19 22:36   ` Alexei Starovoitov
  0 siblings, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2023-01-19 22:36 UTC (permalink / raw)
  To: Kumar Kartikeya Dwivedi
  Cc: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	bpf, Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo

On Thu, Jan 19, 2023 at 9:02 AM Kumar Kartikeya Dwivedi
<memxor@gmail.com> wrote:
>
> On Thu, 19 Jan 2023 at 19:43, Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > We take the BTF reference before we register dtors and we need
> > to put it back when it's done.
> >
> > We probably won't se a problem with kernel BTF, but module BTF
> > would stay loaded (because of the extra ref) even when its module
> > is removed.
> >
> > Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> > Fixes: 5ce937d613a4 ("bpf: Populate pairs of btf_id and destructor kfunc in btf")
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
>
> Thanks for the fix.
> Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>

Jiri,

lore and patchwork didn't receive this patch.
Only Kumar's reply is in lore.
Please resend.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-20  5:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-19 14:13 [PATCH bpf] bpf: Add missing btf_put to register_btf_id_dtor_kfuncs Jiri Olsa
2023-01-19 17:01 ` Kumar Kartikeya Dwivedi
2023-01-19 22:36   ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox