* [PATCH bpf-next] samples/bpf: add BPF_ATOMIC_OP macro for BPF samples
@ 2021-01-18 9:17 Björn Töpel
2021-01-18 10:57 ` Brendan Jackman
2021-01-18 23:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 4+ messages in thread
From: Björn Töpel @ 2021-01-18 9:17 UTC (permalink / raw)
To: ast, daniel, netdev, bpf; +Cc: Björn Töpel, magnus.karlsson, jackmanb
From: Björn Töpel <bjorn.topel@intel.com>
Brendan Jackman added extend atomic operations to the BPF instruction
set in commit 7064a7341a0d ("Merge branch 'Atomics for eBPF'"), which
introduces the BPF_ATOMIC_OP macro. However, that macro was missing
for the BPF samples. Fix that by adding it into bpf_insn.h.
Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
---
samples/bpf/bpf_insn.h | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/samples/bpf/bpf_insn.h b/samples/bpf/bpf_insn.h
index db67a2847395..aee04534483a 100644
--- a/samples/bpf/bpf_insn.h
+++ b/samples/bpf/bpf_insn.h
@@ -134,15 +134,31 @@ struct bpf_insn;
.off = OFF, \
.imm = 0 })
-/* Atomic memory add, *(uint *)(dst_reg + off16) += src_reg */
-
-#define BPF_STX_XADD(SIZE, DST, SRC, OFF) \
+/*
+ * Atomic operations:
+ *
+ * BPF_ADD *(uint *) (dst_reg + off16) += src_reg
+ * BPF_AND *(uint *) (dst_reg + off16) &= src_reg
+ * BPF_OR *(uint *) (dst_reg + off16) |= src_reg
+ * BPF_XOR *(uint *) (dst_reg + off16) ^= src_reg
+ * BPF_ADD | BPF_FETCH src_reg = atomic_fetch_add(dst_reg + off16, src_reg);
+ * BPF_AND | BPF_FETCH src_reg = atomic_fetch_and(dst_reg + off16, src_reg);
+ * BPF_OR | BPF_FETCH src_reg = atomic_fetch_or(dst_reg + off16, src_reg);
+ * BPF_XOR | BPF_FETCH src_reg = atomic_fetch_xor(dst_reg + off16, src_reg);
+ * BPF_XCHG src_reg = atomic_xchg(dst_reg + off16, src_reg)
+ * BPF_CMPXCHG r0 = atomic_cmpxchg(dst_reg + off16, r0, src_reg)
+ */
+
+#define BPF_ATOMIC_OP(SIZE, OP, DST, SRC, OFF) \
((struct bpf_insn) { \
.code = BPF_STX | BPF_SIZE(SIZE) | BPF_ATOMIC, \
.dst_reg = DST, \
.src_reg = SRC, \
.off = OFF, \
- .imm = BPF_ADD })
+ .imm = OP })
+
+/* Legacy alias */
+#define BPF_STX_XADD(SIZE, DST, SRC, OFF) BPF_ATOMIC_OP(SIZE, BPF_ADD, DST, SRC, OFF)
/* Memory store, *(uint *) (dst_reg + off16) = imm32 */
base-commit: 232164e041e925a920bfd28e63d5233cfad90b73
--
2.27.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] samples/bpf: add BPF_ATOMIC_OP macro for BPF samples
2021-01-18 9:17 [PATCH bpf-next] samples/bpf: add BPF_ATOMIC_OP macro for BPF samples Björn Töpel
@ 2021-01-18 10:57 ` Brendan Jackman
2021-01-18 11:00 ` Björn Töpel
2021-01-18 23:00 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 4+ messages in thread
From: Brendan Jackman @ 2021-01-18 10:57 UTC (permalink / raw)
To: Björn Töpel
Cc: Alexei Starovoitov, Daniel Borkmann, netdev, bpf,
Björn Töpel, magnus.karlsson
I actually deliberately skipped this file, thinking that people were
unlikely to want to add assembly-based atomics code under samples/
I guess it's nice for people to be able to e.g. move/copy code from
the selftests.
On Mon, 18 Jan 2021 at 10:18, Björn Töpel <bjorn.topel@gmail.com> wrote:
>
> From: Björn Töpel <bjorn.topel@intel.com>
>
> Brendan Jackman added extend atomic operations to the BPF instruction
> set in commit 7064a7341a0d ("Merge branch 'Atomics for eBPF'"), which
> introduces the BPF_ATOMIC_OP macro. However, that macro was missing
> for the BPF samples. Fix that by adding it into bpf_insn.h.
>
> Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
Reviewed-by: Brendan Jackman <jackmanb@google.com>
> ---
> samples/bpf/bpf_insn.h | 24 ++++++++++++++++++++----
> 1 file changed, 20 insertions(+), 4 deletions(-)
>
> diff --git a/samples/bpf/bpf_insn.h b/samples/bpf/bpf_insn.h
> index db67a2847395..aee04534483a 100644
> --- a/samples/bpf/bpf_insn.h
> +++ b/samples/bpf/bpf_insn.h
> @@ -134,15 +134,31 @@ struct bpf_insn;
> .off = OFF, \
> .imm = 0 })
>
> -/* Atomic memory add, *(uint *)(dst_reg + off16) += src_reg */
> -
> -#define BPF_STX_XADD(SIZE, DST, SRC, OFF) \
> +/*
> + * Atomic operations:
> + *
> + * BPF_ADD *(uint *) (dst_reg + off16) += src_reg
> + * BPF_AND *(uint *) (dst_reg + off16) &= src_reg
> + * BPF_OR *(uint *) (dst_reg + off16) |= src_reg
> + * BPF_XOR *(uint *) (dst_reg + off16) ^= src_reg
> + * BPF_ADD | BPF_FETCH src_reg = atomic_fetch_add(dst_reg + off16, src_reg);
> + * BPF_AND | BPF_FETCH src_reg = atomic_fetch_and(dst_reg + off16, src_reg);
> + * BPF_OR | BPF_FETCH src_reg = atomic_fetch_or(dst_reg + off16, src_reg);
> + * BPF_XOR | BPF_FETCH src_reg = atomic_fetch_xor(dst_reg + off16, src_reg);
> + * BPF_XCHG src_reg = atomic_xchg(dst_reg + off16, src_reg)
> + * BPF_CMPXCHG r0 = atomic_cmpxchg(dst_reg + off16, r0, src_reg)
> + */
> +
> +#define BPF_ATOMIC_OP(SIZE, OP, DST, SRC, OFF) \
> ((struct bpf_insn) { \
> .code = BPF_STX | BPF_SIZE(SIZE) | BPF_ATOMIC, \
> .dst_reg = DST, \
> .src_reg = SRC, \
> .off = OFF, \
> - .imm = BPF_ADD })
> + .imm = OP })
> +
> +/* Legacy alias */
> +#define BPF_STX_XADD(SIZE, DST, SRC, OFF) BPF_ATOMIC_OP(SIZE, BPF_ADD, DST, SRC, OFF)
>
> /* Memory store, *(uint *) (dst_reg + off16) = imm32 */
>
>
> base-commit: 232164e041e925a920bfd28e63d5233cfad90b73
> --
> 2.27.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] samples/bpf: add BPF_ATOMIC_OP macro for BPF samples
2021-01-18 10:57 ` Brendan Jackman
@ 2021-01-18 11:00 ` Björn Töpel
0 siblings, 0 replies; 4+ messages in thread
From: Björn Töpel @ 2021-01-18 11:00 UTC (permalink / raw)
To: Brendan Jackman, Björn Töpel
Cc: Alexei Starovoitov, Daniel Borkmann, netdev, bpf, magnus.karlsson
On 2021-01-18 11:57, Brendan Jackman wrote:
> I actually deliberately skipped this file, thinking that people were
> unlikely to want to add assembly-based atomics code under samples/
>
> I guess it's nice for people to be able to e.g. move/copy code from
> the selftests.
>
Yes, that, and the fact that one sample broke w/o the BPF_ATOMIC_OP.
> On Mon, 18 Jan 2021 at 10:18, Björn Töpel <bjorn.topel@gmail.com> wrote:
>>
>> From: Björn Töpel <bjorn.topel@intel.com>
>>
>> Brendan Jackman added extend atomic operations to the BPF instruction
>> set in commit 7064a7341a0d ("Merge branch 'Atomics for eBPF'"), which
>> introduces the BPF_ATOMIC_OP macro. However, that macro was missing
>> for the BPF samples. Fix that by adding it into bpf_insn.h.
>>
>> Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
>
> Reviewed-by: Brendan Jackman <jackmanb@google.com>
>
Thanks!
Björn
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] samples/bpf: add BPF_ATOMIC_OP macro for BPF samples
2021-01-18 9:17 [PATCH bpf-next] samples/bpf: add BPF_ATOMIC_OP macro for BPF samples Björn Töpel
2021-01-18 10:57 ` Brendan Jackman
@ 2021-01-18 23:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-01-18 23:00 UTC (permalink / raw)
To: =?utf-8?b?QmrDtnJuIFTDtnBlbCA8Ympvcm4udG9wZWxAZ21haWwuY29tPg==?=
Cc: ast, daniel, netdev, bpf, bjorn.topel, magnus.karlsson, jackmanb
Hello:
This patch was applied to bpf/bpf-next.git (refs/heads/master):
On Mon, 18 Jan 2021 10:17:53 +0100 you wrote:
> From: Björn Töpel <bjorn.topel@intel.com>
>
> Brendan Jackman added extend atomic operations to the BPF instruction
> set in commit 7064a7341a0d ("Merge branch 'Atomics for eBPF'"), which
> introduces the BPF_ATOMIC_OP macro. However, that macro was missing
> for the BPF samples. Fix that by adding it into bpf_insn.h.
>
> [...]
Here is the summary with links:
- [bpf-next] samples/bpf: add BPF_ATOMIC_OP macro for BPF samples
https://git.kernel.org/bpf/bpf-next/c/af6953b633b3
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-01-18 23:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-18 9:17 [PATCH bpf-next] samples/bpf: add BPF_ATOMIC_OP macro for BPF samples Björn Töpel
2021-01-18 10:57 ` Brendan Jackman
2021-01-18 11:00 ` Björn Töpel
2021-01-18 23:00 ` patchwork-bot+netdevbpf
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).