[10/14] bpf: Re-initialize lnode in bpf_ksym_del
diff mbox series

Message ID 20200208154209.1797988-11-jolsa@kernel.org
State Superseded
Delegated to: BPF Maintainers
Headers show
Series
  • bpf: Add trampoline and dispatcher to /proc/kallsyms
Related show

Commit Message

Jiri Olsa Feb. 8, 2020, 3:42 p.m. UTC
When bpf_prog is removed from kallsyms it's on the way
out to be removed, so we don't care about lnode state.

However the bpf_ksym_del will be used also by bpf_trampoline
and bpf_dispatcher objects, which stay allocated even when
they are not in kallsyms list, hence the lnode re-init.

The list_del_rcu commentary states that we need to call
synchronize_rcu, before we can change/re-init the list_head
pointers.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 kernel/bpf/core.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Andrii Nakryiko Feb. 11, 2020, 6:28 p.m. UTC | #1
On Sat, Feb 8, 2020 at 7:43 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> When bpf_prog is removed from kallsyms it's on the way
> out to be removed, so we don't care about lnode state.
>
> However the bpf_ksym_del will be used also by bpf_trampoline
> and bpf_dispatcher objects, which stay allocated even when
> they are not in kallsyms list, hence the lnode re-init.
>
> The list_del_rcu commentary states that we need to call
> synchronize_rcu, before we can change/re-init the list_head
> pointers.
>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---

Wouldn't it make more sense to have patches 7 though 10 as a one
patch? It's a generalization of ksym from being bpf_prog-specific to
be more general (which this initialization fix is part of, arguably).

>  kernel/bpf/core.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 73242fd07893..66b17bea286e 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -676,6 +676,13 @@ void bpf_ksym_del(struct bpf_ksym *ksym)
>         spin_lock_bh(&bpf_lock);
>         __bpf_ksym_del(ksym);
>         spin_unlock_bh(&bpf_lock);
> +
> +       /*
> +        * As explained in list_del_rcu, We must call synchronize_rcu
> +        * before changing list_head pointers.
> +        */
> +       synchronize_rcu();
> +       INIT_LIST_HEAD_RCU(&ksym->lnode);
>  }
>
>  static bool bpf_prog_kallsyms_candidate(const struct bpf_prog *fp)
> --
> 2.24.1
>
Jiri Olsa Feb. 12, 2020, 10:43 a.m. UTC | #2
On Tue, Feb 11, 2020 at 10:28:50AM -0800, Andrii Nakryiko wrote:
> On Sat, Feb 8, 2020 at 7:43 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > When bpf_prog is removed from kallsyms it's on the way
> > out to be removed, so we don't care about lnode state.
> >
> > However the bpf_ksym_del will be used also by bpf_trampoline
> > and bpf_dispatcher objects, which stay allocated even when
> > they are not in kallsyms list, hence the lnode re-init.
> >
> > The list_del_rcu commentary states that we need to call
> > synchronize_rcu, before we can change/re-init the list_head
> > pointers.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> 
> Wouldn't it make more sense to have patches 7 though 10 as a one
> patch? It's a generalization of ksym from being bpf_prog-specific to
> be more general (which this initialization fix is part of, arguably).

it was my initial change ;-) but then I realized I have to explain
several things in the changelog, and that's usually the sign that
you need to split the patch.. also I think now it's easier for review
and backporting

so I prefer it split like this, but if you guys want to squash it
together, I'll do it ;-)

jirka

> 
> >  kernel/bpf/core.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> > index 73242fd07893..66b17bea286e 100644
> > --- a/kernel/bpf/core.c
> > +++ b/kernel/bpf/core.c
> > @@ -676,6 +676,13 @@ void bpf_ksym_del(struct bpf_ksym *ksym)
> >         spin_lock_bh(&bpf_lock);
> >         __bpf_ksym_del(ksym);
> >         spin_unlock_bh(&bpf_lock);
> > +
> > +       /*
> > +        * As explained in list_del_rcu, We must call synchronize_rcu
> > +        * before changing list_head pointers.
> > +        */
> > +       synchronize_rcu();
> > +       INIT_LIST_HEAD_RCU(&ksym->lnode);
> >  }
> >
> >  static bool bpf_prog_kallsyms_candidate(const struct bpf_prog *fp)
> > --
> > 2.24.1
> >
>

Patch
diff mbox series

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 73242fd07893..66b17bea286e 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -676,6 +676,13 @@  void bpf_ksym_del(struct bpf_ksym *ksym)
 	spin_lock_bh(&bpf_lock);
 	__bpf_ksym_del(ksym);
 	spin_unlock_bh(&bpf_lock);
+
+	/*
+	 * As explained in list_del_rcu, We must call synchronize_rcu
+	 * before changing list_head pointers.
+	 */
+	synchronize_rcu();
+	INIT_LIST_HEAD_RCU(&ksym->lnode);
 }
 
 static bool bpf_prog_kallsyms_candidate(const struct bpf_prog *fp)