From: Peilin Ye <yepeilin@google.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Yonghong Song <yonghong.song@linux.dev>,
"Jose E. Marchesi" <jemarch@gnu.org>, bpf <bpf@vger.kernel.org>,
Josh Don <joshdon@google.com>, Barret Rhoden <brho@google.com>,
Neel Natu <neelnatu@google.com>,
Benjamin Segall <bsegall@google.com>,
"Paul E. McKenney" <paulmck@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
David Vernet <dvernet@meta.com>,
Dave Marchevsky <davemarchevsky@meta.com>
Subject: Re: Supporting New Memory Barrier Types in BPF
Date: Tue, 6 Aug 2024 19:22:37 +0000 [thread overview]
Message-ID: <ZrJ3_esc7nBb6k9_@google.com> (raw)
In-Reply-To: <CAADnVQJqGzH+iT9M8ajT62H9+kAw1RXAdB42G3pvcLKPVmy8tg@mail.gmail.com>
Hi Alexei,
Thanks for all the suggestions! Some questions:
On Mon, Jul 29, 2024 at 06:28:16PM -0700, Alexei Starovoitov wrote:
> On Mon, Jul 29, 2024 at 11:33 AM Peilin Ye <yepeilin@google.com> wrote:
> > We need more. During offline discussion with Paul, we agreed we can start
> > from:
> >
> > * load-acquire: __atomic_load_n(... memorder=__ATOMIC_ACQUIRE);
> > * store-release: __atomic_store_n(... memorder=__ATOMIC_RELEASE);
>
> we would need inline asm equivalent too. Similar to kernel
> smp_load_acquire() macro.
I see, so something like:
asm volatile("%0 = load_acquire((u64 *)(%1 + 0x0))" :
"=r"(ret) : "r"(&foo) : "memory");
and e.g. this in disassembly:
r0 = load_acquire((u64 *)(r1 + 0x0))
I agree that we'd better not put the entire e.g.
"r0 = __atomic_load_n((u64 *)(r1 + 0x0), __ATOMIC_ACQUIRE)" into
disassembly.
> > Theoretically, the BPF JIT compiler could also reorder instructions just like
> > Clang or GCC, though it might not currently do so. If we ever developed a more
> > optimizing BPF JIT compiler, it would also be nice to have an optimization
> > barrier for it. However, Alexei Starovoitov has expressed that defining a BPF
> > instruction with 'asm volatile ("" ::: "memory");' semantics might be tricky.
>
> It can be a standalone insn that is a compiler barrier only but that feels like
> a waste of an instruction. So depending how we end up encoding various
> real barriers
> there may be a bit to spend in such a barrier insn that is only a
> compiler barrier.
> In this case optimizing JIT barrier.
[...]
> > Roughly, the scope of this work includes:
> >
> > * decide how to extend the BPF ISA (add new instructions and/or extend
> > current ones)
>
> ldx/stx insns support MEM and MEMSX modifiers.
> Adding MEM_ACQ_REL feels like a natural fit. Better name?
Do we allow aliases? E.g., can we have "MEMACQ" for LDX and "MEMREL"
for STX, but let them share the same numeric value?
Speaking of numeric value, out of curiosity:
IMM 0
ABS 1
IND 2
MEM 3
MEMSX 4
ATOMIC 6
Was there a reason that we skipped 5? Is 5 reserved?
> For barriers we would need a new insn. Not sure which class would fit the best.
> Maybe BPF_LD ?
>
> Another alternative for barriers is to use nocsr kfuncs.
> Then we have the freedom to make mistakes and fix them later.
> One kfunc per barrier would do.
> JITs would inline them into appropriate insns.
> In bpf progs they will be used just like in the kernel code smp_mb(),
> smp_rmb(), etc.
>
> I don't think compilers have to emit barriers from C code, so my
> preference is kfuncs atm.
Ah, I see; we recently supported [1] nocsr BPF helper functions. The
cover letter says:
"""
This patch-set seeks to allow using no_caller_saved_registers
gcc/clang attribute with some BPF helper functions (and kfuncs in the
future).
"""
It seems that nocsr BPF kfuncs are not supported yet. Do we have a
schedule for it?
Thanks,
Peilin Ye
[1] [PATCH bpf-next v4 00/10] no_caller_saved_registers attribute for helper calls
https://lore.kernel.org/bpf/20240722233844.1406874-1-eddyz87@gmail.com/
next prev parent reply other threads:[~2024-08-06 19:22 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-29 18:32 Supporting New Memory Barrier Types in BPF Peilin Ye
2024-07-30 1:28 ` Alexei Starovoitov
2024-07-30 3:49 ` Paul E. McKenney
2024-07-30 4:03 ` Alexei Starovoitov
2024-07-30 5:14 ` Yonghong Song
2024-07-31 1:19 ` Alexei Starovoitov
2024-07-31 3:51 ` Yonghong Song
2024-07-31 20:44 ` Peilin Ye
2024-07-31 23:17 ` Yonghong Song
2024-08-01 0:11 ` Peilin Ye
2024-08-01 12:47 ` Jose E. Marchesi
2024-08-01 14:20 ` Jose E. Marchesi
2024-08-01 16:44 ` Yonghong Song
2024-08-05 16:13 ` Jose E. Marchesi
2024-08-01 22:00 ` Peilin Ye
2024-08-06 19:22 ` Peilin Ye [this message]
2024-08-08 16:33 ` Alexei Starovoitov
2024-08-08 20:59 ` Peilin Ye
2024-09-16 21:14 ` Peilin Ye
2024-09-17 0:08 ` Peilin Ye
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=ZrJ3_esc7nBb6k9_@google.com \
--to=yepeilin@google.com \
--cc=alexei.starovoitov@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brho@google.com \
--cc=bsegall@google.com \
--cc=davemarchevsky@meta.com \
--cc=dvernet@meta.com \
--cc=jemarch@gnu.org \
--cc=joshdon@google.com \
--cc=neelnatu@google.com \
--cc=paulmck@kernel.org \
--cc=yonghong.song@linux.dev \
/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