From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
"Paul E. McKenney" <paulmck@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Linux-Fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH v3] bpf: Remove in_atomic() from bpf_link_put().
Date: Mon, 5 Jun 2023 18:37:33 +0200 [thread overview]
Message-ID: <20230605163733.LD-UCcso@linutronix.de> (raw)
In-Reply-To: <CAEf4Bzawgrn2DhR9uvXwFFiLR9g+j4RYC6cr3n+eRD_RoKBAJA@mail.gmail.com>
On 2023-05-31 12:00:56 [-0700], Andrii Nakryiko wrote:
> > On 2023-05-25 10:51:23 [-0700], Andrii Nakryiko wrote:
> > v2…v3:
> > - Drop bpf_link_put_direct(). Let bpf_link_put() do the direct free
> > and add bpf_link_put_from_atomic() to do the delayed free via the
> > worker.
>
> This seems like an unsafe "default put" choice. I think it makes more
> sense to have bpf_link_put() do a safe scheduled put, and then having
> a separate bpf_link_put_direct() for those special cases where we care
> the most (in kernel/bpf/inode.c and kernel/bpf/syscall.c).
I audited them and ended up with them all being safe except for the one
from inode.c. I can reverse the logic if you want.
> > diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c
> > index 9948b542a470e..2e1e9f3c7f701 100644
> > --- a/kernel/bpf/inode.c
> > +++ b/kernel/bpf/inode.c
> > @@ -59,7 +59,10 @@ static void bpf_any_put(void *raw, enum bpf_type type)
> > bpf_map_put_with_uref(raw);
> > break;
> > case BPF_TYPE_LINK:
> > - bpf_link_put(raw);
> > + if (may_sleep)
> > + bpf_link_put(raw);
> > + else
> > + bpf_link_put_from_atomic(raw);
>
> Do we need to do this in two different ways here? The only situation
> that has may_sleep=false is when called from superblock->free_inode.
> According to documentation:
>
> Freeing memory in the callback is fine; doing
> more than that is possible, but requires a lot of care and is best
> avoided.
>
> So it feels like cleaning up link should be safe to do from this
> context as well? I've cc'ed linux-fsdevel@, hopefully they can advise.
This is invoked from the RCU callback (which is usually softirq):
destroy_inode()
-> call_rcu(&inode->i_rcu, i_callback);
Freeing memory is fine but there is a mutex that is held in the process.
Sebastian
next parent reply other threads:[~2023-06-05 16:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230509132433.2FSY_6t7@linutronix.de>
[not found] ` <CAEf4BzZcPKsRJDQfdVk9D1Nt6kgT4STpEUrsQ=UD3BDZnNp8eQ@mail.gmail.com>
[not found] ` <CAADnVQLzZyZ+cPqBFfrqa8wtQ8ZhWvTSN6oD9z4Y2gtrfs8Vdg@mail.gmail.com>
[not found] ` <CAEf4BzY-MRYnzGiZmW7AVJYgYdHW1_jOphbipRrHRTtdfq3_wQ@mail.gmail.com>
[not found] ` <20230525141813.TFZLWM4M@linutronix.de>
[not found] ` <CAEf4Bzaipoo6X_2Fh5WTV-m0yjP0pvhqi7-FPFtGOrSzNpdGJQ@mail.gmail.com>
[not found] ` <20230526112356.fOlWmeOF@linutronix.de>
[not found] ` <CAEf4Bzawgrn2DhR9uvXwFFiLR9g+j4RYC6cr3n+eRD_RoKBAJA@mail.gmail.com>
2023-06-05 16:37 ` Sebastian Andrzej Siewior [this message]
2023-06-05 22:47 ` [PATCH v3] bpf: Remove in_atomic() from bpf_link_put() Andrii Nakryiko
2023-06-09 14:19 ` Sebastian Andrzej Siewior
2023-06-14 8:34 ` [PATCH v4] " Sebastian Andrzej Siewior
2023-06-15 16:43 ` Paul E. McKenney
2023-06-15 19:13 ` Sebastian Andrzej Siewior
2023-06-15 19:32 ` Paul E. McKenney
2023-06-16 16:30 ` patchwork-bot+netdevbpf
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=20230605163733.LD-UCcso@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).