All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <kafai@fb.com>
To: KP Singh <kpsingh@kernel.org>
Cc: <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	"Paul E. McKenney" <paulmck@kernel.org>
Subject: Re: [PATCH v2 bpf-next 1/2] bpf: Allow bpf_local_storage to be used by sleepable programs
Date: Wed, 8 Dec 2021 23:00:04 -0800	[thread overview]
Message-ID: <20211209070004.gj5b4ybrcdxqblbp@kafai-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <CACYkzJ77G4f_FJ=q7BKCta-rodWiescgEnkqE5U+kAW+=bw5_w@mail.gmail.com>

On Thu, Dec 09, 2021 at 03:18:21AM +0100, KP Singh wrote:
> On Thu, Dec 9, 2021 at 3:00 AM Martin KaFai Lau <kafai@fb.com> wrote:
> >
> > On Mon, Dec 06, 2021 at 03:19:08PM +0000, KP Singh wrote:
> > [ ... ]
> >
> > > diff --git a/kernel/bpf/bpf_inode_storage.c b/kernel/bpf/bpf_inode_storage.c
> > > index 96ceed0e0fb5..20604d904d14 100644
> > > --- a/kernel/bpf/bpf_inode_storage.c
> > > +++ b/kernel/bpf/bpf_inode_storage.c
> > > @@ -17,6 +17,7 @@
> > >  #include <linux/bpf_lsm.h>
> > >  #include <linux/btf_ids.h>
> > >  #include <linux/fdtable.h>
> > > +#include <linux/rcupdate_trace.h>
> > >
> > >  DEFINE_BPF_STORAGE_CACHE(inode_cache);
> > >
> > > @@ -44,7 +45,8 @@ static struct bpf_local_storage_data *inode_storage_lookup(struct inode *inode,
> > >       if (!bsb)
> > >               return NULL;
> > >
> > > -     inode_storage = rcu_dereference(bsb->storage);
> > > +     inode_storage =
> > > +             rcu_dereference_check(bsb->storage, bpf_rcu_lock_held());
> > >       if (!inode_storage)
> > >               return NULL;
> > >
> > > @@ -97,7 +99,8 @@ void bpf_inode_storage_free(struct inode *inode)
> > >        * local_storage->list was non-empty.
> > >        */
> > >       if (free_inode_storage)
> > > -             kfree_rcu(local_storage, rcu);
> > > +             call_rcu_tasks_trace(&local_storage->rcu,
> > > +                                  bpf_local_storage_free_rcu);
> > It is not clear to me why bpf_inode_storage_free() needs this change
> > but not in bpf_task_storage_free() and bpf_sk_storage_free().
> > Could you explain the reason here?
> 
> I think I carried this forward from my older version and messed it up
> while applying diffs, I tested on the linux-next branch which has it
> for the other storages as well.
> 
> We will need to free all these under trace RCU. Will fix it in v3.
For sk, bpf_sk_storage_free() is called when sk is about to be kfree.
My understanding is the sleepable bpf_lsm should not be running
with this sk in parallel at this point when the sk has already reached
the bpf_sk_storage_free().  iow, call_rcu_tasks_trace should not
be needed here.  The existing kfree_rcu() is for the
bpf_local_storage_map_free.

I was not sure for inode since the inode's storage life time
is not obvious to me, so the earlier question.

After another thought, the synchronize_rcu_mult changes in
bpf_local_storage_map_free() is also not needed.  The first
existing synchronize_rcu() is for the bpf_sk_storage_clone().
The second one is for the bpf_(sk|task|inode)_storage_free().

  reply	other threads:[~2021-12-09  7:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 15:19 [PATCH v2 bpf-next 0/2] Sleepable local storage KP Singh
2021-12-06 15:19 ` [PATCH v2 bpf-next 1/2] bpf: Allow bpf_local_storage to be used by sleepable programs KP Singh
2021-12-08  7:42   ` Martin KaFai Lau
2021-12-09  1:59   ` Martin KaFai Lau
2021-12-09  2:18     ` KP Singh
2021-12-09  7:00       ` Martin KaFai Lau [this message]
2021-12-20 18:59         ` Martin KaFai Lau
2021-12-22  4:43           ` KP Singh
2021-12-24 14:38         ` KP Singh
2021-12-06 15:19 ` [PATCH v2 bpf-next 2/2] bpf/selftests: Update local storage selftest for " KP Singh
2021-12-09  2:10   ` Martin KaFai Lau

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=20211209070004.gj5b4ybrcdxqblbp@kafai-mbp.dhcp.thefacebook.com \
    --to=kafai@fb.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kpsingh@kernel.org \
    --cc=paulmck@kernel.org \
    /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.