Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1266842 > unrolled thread
| Started by | Yang Shi <yang.shi@linaro.org> |
|---|---|
| First post | 2015-11-11 00:10 +0100 |
| Last post | 2015-11-11 20:10 +0100 |
| Articles | 20 on this page of 34 — 10 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 2/2] arm64: bpf: add BPF XADD instruction Yang Shi <yang.shi@linaro.org> - 2015-11-11 00:10 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Eric Dumazet <eric.dumazet@gmail.com> - 2015-11-11 01:10 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction "Shi, Yang" <yang.shi@linaro.org> - 2015-11-11 01:30 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2015-11-11 01:50 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Z Lim <zlim.lnx@gmail.com> - 2015-11-11 04:00 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Arnd Bergmann <arnd@arndb.de> - 2015-11-11 10:00 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Will Deacon <will.deacon@arm.com> - 2015-11-11 11:30 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Daniel Borkmann <daniel@iogearbox.net> - 2015-11-11 11:50 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Will Deacon <will.deacon@arm.com> - 2015-11-11 13:00 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Daniel Borkmann <daniel@iogearbox.net> - 2015-11-11 13:30 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Will Deacon <will.deacon@arm.com> - 2015-11-11 13:40 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Peter Zijlstra <peterz@infradead.org> - 2015-11-11 14:00 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Daniel Borkmann <daniel@iogearbox.net> - 2015-11-11 17:00 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Will Deacon <will.deacon@arm.com> - 2015-11-11 17:30 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2015-11-11 18:30 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction David Miller <davem@davemloft.net> - 2015-11-11 18:40 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Will Deacon <will.deacon@arm.com> - 2015-11-11 18:50 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction David Miller <davem@davemloft.net> - 2015-11-11 20:10 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Peter Zijlstra <peterz@infradead.org> - 2015-11-11 19:00 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2015-11-11 19:20 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Peter Zijlstra <peterz@infradead.org> - 2015-11-11 19:40 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Peter Zijlstra <peterz@infradead.org> - 2015-11-11 19:50 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Peter Zijlstra <peterz@infradead.org> - 2015-11-11 19:50 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Peter Zijlstra <peterz@infradead.org> - 2015-11-11 20:00 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2015-11-11 21:00 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Peter Zijlstra <peterz@infradead.org> - 2015-11-11 23:30 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2015-11-12 00:50 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Peter Zijlstra <peterz@infradead.org> - 2015-11-12 10:00 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Daniel Borkmann <daniel@iogearbox.net> - 2015-11-11 20:00 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction David Miller <davem@davemloft.net> - 2015-11-11 20:10 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Peter Zijlstra <peterz@infradead.org> - 2015-11-11 20:30 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Daniel Borkmann <daniel@iogearbox.net> - 2015-11-11 20:50 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Will Deacon <will.deacon@arm.com> - 2015-11-11 19:50 +0100
Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction David Miller <davem@davemloft.net> - 2015-11-11 20:10 +0100
Page 1 of 2 [1] 2 Next page →
| From | Yang Shi <yang.shi@linaro.org> |
|---|---|
| Date | 2015-11-11 00:10 +0100 |
| Subject | [PATCH 2/2] arm64: bpf: add BPF XADD instruction |
| Message-ID | <qtqd4-36K-5@gated-at.bofh.it> |
aarch64 doesn't have native support for XADD instruction, implement it by
the below instruction sequence:
Load (dst + off) to a register
Add src to it
Store it back to (dst + off)
Signed-off-by: Yang Shi <yang.shi@linaro.org>
CC: Zi Shen Lim <zlim.lnx@gmail.com>
CC: Xi Wang <xi.wang@gmail.com>
---
arch/arm64/net/bpf_jit_comp.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 49c1f1b..0b1d2d3 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -609,7 +609,21 @@ emit_cond_jmp:
case BPF_STX | BPF_XADD | BPF_W:
/* STX XADD: lock *(u64 *)(dst + off) += src */
case BPF_STX | BPF_XADD | BPF_DW:
- goto notyet;
+ ctx->tmp_used = 1;
+ emit_a64_mov_i(1, tmp2, off, ctx);
+ switch (BPF_SIZE(code)) {
+ case BPF_W:
+ emit(A64_LDR32(tmp, dst, tmp2), ctx);
+ emit(A64_ADD(is64, tmp, tmp, src), ctx);
+ emit(A64_STR32(tmp, dst, tmp2), ctx);
+ break;
+ case BPF_DW:
+ emit(A64_LDR64(tmp, dst, tmp2), ctx);
+ emit(A64_ADD(is64, tmp, tmp, src), ctx);
+ emit(A64_STR64(tmp, dst, tmp2), ctx);
+ break;
+ }
+ break;
/* R0 = ntohx(*(size *)(((struct sk_buff *)R6)->data + imm)) */
case BPF_LD | BPF_ABS | BPF_W:
@@ -679,9 +693,6 @@ emit_cond_jmp:
}
break;
}
-notyet:
- pr_info_once("*** NOT YET: opcode %02x ***\n", code);
- return -EFAULT;
default:
pr_err_once("unknown opcode %02x\n", code);
--
2.0.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Eric Dumazet <eric.dumazet@gmail.com> |
|---|---|
| Date | 2015-11-11 01:10 +0100 |
| Message-ID | <qtr97-3J0-1@gated-at.bofh.it> |
| In reply to | #1266842 |
On Tue, 2015-11-10 at 14:41 -0800, Yang Shi wrote: > aarch64 doesn't have native support for XADD instruction, implement it by > the below instruction sequence: > > Load (dst + off) to a register > Add src to it > Store it back to (dst + off) Not really what is needed ? See this BPF_XADD as an atomic_add() equivalent. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | "Shi, Yang" <yang.shi@linaro.org> |
|---|---|
| Date | 2015-11-11 01:30 +0100 |
| Message-ID | <qtrsu-3Qd-3@gated-at.bofh.it> |
| In reply to | #1266880 |
On 11/10/2015 4:08 PM, Eric Dumazet wrote: > On Tue, 2015-11-10 at 14:41 -0800, Yang Shi wrote: >> aarch64 doesn't have native support for XADD instruction, implement it by >> the below instruction sequence: >> >> Load (dst + off) to a register >> Add src to it >> Store it back to (dst + off) > > Not really what is needed ? > > See this BPF_XADD as an atomic_add() equivalent. I see. Thanks. The documentation doesn't say too much about "exclusive" add. If so it should need load-acquire/store-release. I will rework it. Yang > > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Alexei Starovoitov <alexei.starovoitov@gmail.com> |
|---|---|
| Date | 2015-11-11 01:50 +0100 |
| Message-ID | <qtrLP-3YD-9@gated-at.bofh.it> |
| In reply to | #1266884 |
On Tue, Nov 10, 2015 at 04:26:02PM -0800, Shi, Yang wrote: > On 11/10/2015 4:08 PM, Eric Dumazet wrote: > >On Tue, 2015-11-10 at 14:41 -0800, Yang Shi wrote: > >>aarch64 doesn't have native support for XADD instruction, implement it by > >>the below instruction sequence: > >> > >>Load (dst + off) to a register > >>Add src to it > >>Store it back to (dst + off) > > > >Not really what is needed ? > > > >See this BPF_XADD as an atomic_add() equivalent. > > I see. Thanks. The documentation doesn't say too much about "exclusive" add. > If so it should need load-acquire/store-release. I think doc is clear enough, but it can always be improved. Pls suggest a patch. It's quite hard to write a test for atomicity in test_bpf framework, so code review is the key. Eric, thanks for catching it! -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Z Lim <zlim.lnx@gmail.com> |
|---|---|
| Date | 2015-11-11 04:00 +0100 |
| Message-ID | <qttNE-5dn-7@gated-at.bofh.it> |
| In reply to | #1266905 |
Yang, On Tue, Nov 10, 2015 at 4:42 PM, Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote: > On Tue, Nov 10, 2015 at 04:26:02PM -0800, Shi, Yang wrote: >> On 11/10/2015 4:08 PM, Eric Dumazet wrote: >> >On Tue, 2015-11-10 at 14:41 -0800, Yang Shi wrote: >> >>aarch64 doesn't have native support for XADD instruction, implement it by >> >>the below instruction sequence: aarch64 supports atomic add in ARMv8.1. For ARMv8(.0), please consider using LDXR/STXR sequence. >> >> >> >>Load (dst + off) to a register >> >>Add src to it >> >>Store it back to (dst + off) >> > >> >Not really what is needed ? >> > >> >See this BPF_XADD as an atomic_add() equivalent. >> >> I see. Thanks. The documentation doesn't say too much about "exclusive" add. >> If so it should need load-acquire/store-release. > > I think doc is clear enough, but it can always be improved. Pls suggest a patch. > It's quite hard to write a test for atomicity in test_bpf framework, so > code review is the key. Eric, thanks for catching it! > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| Date | 2015-11-11 10:00 +0100 |
| Message-ID | <qtzq2-t6-17@gated-at.bofh.it> |
| In reply to | #1266948 |
On Tuesday 10 November 2015 18:52:45 Z Lim wrote: > On Tue, Nov 10, 2015 at 4:42 PM, Alexei Starovoitov > <alexei.starovoitov@gmail.com> wrote: > > On Tue, Nov 10, 2015 at 04:26:02PM -0800, Shi, Yang wrote: > >> On 11/10/2015 4:08 PM, Eric Dumazet wrote: > >> >On Tue, 2015-11-10 at 14:41 -0800, Yang Shi wrote: > >> >>aarch64 doesn't have native support for XADD instruction, implement it by > >> >>the below instruction sequence: > > aarch64 supports atomic add in ARMv8.1. > For ARMv8(.0), please consider using LDXR/STXR sequence. Is it worth optimizing for the 8.1 case? It would add a bit of complexity to make the code depend on the CPU feature, but it's certainly doable. Arnd -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Will Deacon <will.deacon@arm.com> |
|---|---|
| Date | 2015-11-11 11:30 +0100 |
| Message-ID | <qtAP8-1we-23@gated-at.bofh.it> |
| In reply to | #1267046 |
On Wed, Nov 11, 2015 at 09:49:48AM +0100, Arnd Bergmann wrote: > On Tuesday 10 November 2015 18:52:45 Z Lim wrote: > > On Tue, Nov 10, 2015 at 4:42 PM, Alexei Starovoitov > > <alexei.starovoitov@gmail.com> wrote: > > > On Tue, Nov 10, 2015 at 04:26:02PM -0800, Shi, Yang wrote: > > >> On 11/10/2015 4:08 PM, Eric Dumazet wrote: > > >> >On Tue, 2015-11-10 at 14:41 -0800, Yang Shi wrote: > > >> >>aarch64 doesn't have native support for XADD instruction, implement it by > > >> >>the below instruction sequence: > > > > aarch64 supports atomic add in ARMv8.1. > > For ARMv8(.0), please consider using LDXR/STXR sequence. > > Is it worth optimizing for the 8.1 case? It would add a bit of complexity > to make the code depend on the CPU feature, but it's certainly doable. What's the atomicity required for? Put another way, what are we racing with (I thought bpf was single-threaded)? Do we need to worry about memory barriers? Apologies if these are stupid questions, but all I could find was samples/bpf/sock_example.c and it didn't help much :( Will -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Daniel Borkmann <daniel@iogearbox.net> |
|---|---|
| Date | 2015-11-11 11:50 +0100 |
| Message-ID | <qtB8t-1CY-5@gated-at.bofh.it> |
| In reply to | #1267091 |
On 11/11/2015 11:24 AM, Will Deacon wrote: > On Wed, Nov 11, 2015 at 09:49:48AM +0100, Arnd Bergmann wrote: >> On Tuesday 10 November 2015 18:52:45 Z Lim wrote: >>> On Tue, Nov 10, 2015 at 4:42 PM, Alexei Starovoitov >>> <alexei.starovoitov@gmail.com> wrote: >>>> On Tue, Nov 10, 2015 at 04:26:02PM -0800, Shi, Yang wrote: >>>>> On 11/10/2015 4:08 PM, Eric Dumazet wrote: >>>>>> On Tue, 2015-11-10 at 14:41 -0800, Yang Shi wrote: >>>>>>> aarch64 doesn't have native support for XADD instruction, implement it by >>>>>>> the below instruction sequence: >>> >>> aarch64 supports atomic add in ARMv8.1. >>> For ARMv8(.0), please consider using LDXR/STXR sequence. >> >> Is it worth optimizing for the 8.1 case? It would add a bit of complexity >> to make the code depend on the CPU feature, but it's certainly doable. > > What's the atomicity required for? Put another way, what are we racing > with (I thought bpf was single-threaded)? Do we need to worry about > memory barriers? > > Apologies if these are stupid questions, but all I could find was > samples/bpf/sock_example.c and it didn't help much :( The equivalent code more readable in restricted C syntax (that can be compiled by llvm) can be found in samples/bpf/sockex1_kern.c. So the built-in __sync_fetch_and_add() will be translated into a BPF_XADD insn variant. What you can race against is that an eBPF map can be _shared_ by multiple eBPF programs that are attached somewhere in the system, and they could all update a particular entry/counter from the map at the same time. Best, Daniel -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Will Deacon <will.deacon@arm.com> |
|---|---|
| Date | 2015-11-11 13:00 +0100 |
| Message-ID | <qtCef-2hA-11@gated-at.bofh.it> |
| In reply to | #1267101 |
Hi Daniel, On Wed, Nov 11, 2015 at 11:42:11AM +0100, Daniel Borkmann wrote: > On 11/11/2015 11:24 AM, Will Deacon wrote: > >On Wed, Nov 11, 2015 at 09:49:48AM +0100, Arnd Bergmann wrote: > >>On Tuesday 10 November 2015 18:52:45 Z Lim wrote: > >>>On Tue, Nov 10, 2015 at 4:42 PM, Alexei Starovoitov > >>><alexei.starovoitov@gmail.com> wrote: > >>>>On Tue, Nov 10, 2015 at 04:26:02PM -0800, Shi, Yang wrote: > >>>>>On 11/10/2015 4:08 PM, Eric Dumazet wrote: > >>>>>>On Tue, 2015-11-10 at 14:41 -0800, Yang Shi wrote: > >>>>>>>aarch64 doesn't have native support for XADD instruction, implement it by > >>>>>>>the below instruction sequence: > >>> > >>>aarch64 supports atomic add in ARMv8.1. > >>>For ARMv8(.0), please consider using LDXR/STXR sequence. > >> > >>Is it worth optimizing for the 8.1 case? It would add a bit of complexity > >>to make the code depend on the CPU feature, but it's certainly doable. > > > >What's the atomicity required for? Put another way, what are we racing > >with (I thought bpf was single-threaded)? Do we need to worry about > >memory barriers? > > > >Apologies if these are stupid questions, but all I could find was > >samples/bpf/sock_example.c and it didn't help much :( > > The equivalent code more readable in restricted C syntax (that can be > compiled by llvm) can be found in samples/bpf/sockex1_kern.c. So the > built-in __sync_fetch_and_add() will be translated into a BPF_XADD > insn variant. Yikes, so the memory-model for BPF is based around the deprecated GCC __sync builtins, that inherit their semantics from ia64? Any reason not to use the C11-compatible __atomic builtins[1] as a base? > What you can race against is that an eBPF map can be _shared_ by > multiple eBPF programs that are attached somewhere in the system, and > they could all update a particular entry/counter from the map at the > same time. Ok, so it does sound like eBPF needs to define/choose a memory-model and I worry that riding on the back of __sync isn't necessarily the right thing to do, particularly as its fallen out of favour with the compiler folks. On weakly-ordered architectures, it's also going to result in heavy-weight barriers for all atomic operations. Will [1] https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Daniel Borkmann <daniel@iogearbox.net> |
|---|---|
| Date | 2015-11-11 13:30 +0100 |
| Message-ID | <qtCHh-2HY-11@gated-at.bofh.it> |
| In reply to | #1267121 |
On 11/11/2015 12:58 PM, Will Deacon wrote: > On Wed, Nov 11, 2015 at 11:42:11AM +0100, Daniel Borkmann wrote: >> On 11/11/2015 11:24 AM, Will Deacon wrote: >>> On Wed, Nov 11, 2015 at 09:49:48AM +0100, Arnd Bergmann wrote: >>>> On Tuesday 10 November 2015 18:52:45 Z Lim wrote: >>>>> On Tue, Nov 10, 2015 at 4:42 PM, Alexei Starovoitov >>>>> <alexei.starovoitov@gmail.com> wrote: >>>>>> On Tue, Nov 10, 2015 at 04:26:02PM -0800, Shi, Yang wrote: >>>>>>> On 11/10/2015 4:08 PM, Eric Dumazet wrote: >>>>>>>> On Tue, 2015-11-10 at 14:41 -0800, Yang Shi wrote: >>>>>>>>> aarch64 doesn't have native support for XADD instruction, implement it by >>>>>>>>> the below instruction sequence: >>>>> >>>>> aarch64 supports atomic add in ARMv8.1. >>>>> For ARMv8(.0), please consider using LDXR/STXR sequence. >>>> >>>> Is it worth optimizing for the 8.1 case? It would add a bit of complexity >>>> to make the code depend on the CPU feature, but it's certainly doable. >>> >>> What's the atomicity required for? Put another way, what are we racing >>> with (I thought bpf was single-threaded)? Do we need to worry about >>> memory barriers? >>> >>> Apologies if these are stupid questions, but all I could find was >>> samples/bpf/sock_example.c and it didn't help much :( >> >> The equivalent code more readable in restricted C syntax (that can be >> compiled by llvm) can be found in samples/bpf/sockex1_kern.c. So the >> built-in __sync_fetch_and_add() will be translated into a BPF_XADD >> insn variant. > > Yikes, so the memory-model for BPF is based around the deprecated GCC > __sync builtins, that inherit their semantics from ia64? Any reason not > to use the C11-compatible __atomic builtins[1] as a base? Hmm, gcc doesn't have an eBPF compiler backend, so this won't work on gcc at all. The eBPF backend in LLVM recognizes the __sync_fetch_and_add() keyword and maps that to a BPF_XADD version (BPF_W or BPF_DW). In the interpreter (__bpf_prog_run()), as Eric mentioned, this maps to atomic_add() and atomic64_add(), respectively. So the struct bpf_insn prog[] you saw from sock_example.c can be regarded as one possible equivalent program section output from the compiler. >> What you can race against is that an eBPF map can be _shared_ by >> multiple eBPF programs that are attached somewhere in the system, and >> they could all update a particular entry/counter from the map at the >> same time. > > Ok, so it does sound like eBPF needs to define/choose a memory-model and > I worry that riding on the back of __sync isn't necessarily the right > thing to do, particularly as its fallen out of favour with the compiler > folks. On weakly-ordered architectures, it's also going to result in > heavy-weight barriers for all atomic operations. > > Will > > [1] https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Will Deacon <will.deacon@arm.com> |
|---|---|
| Date | 2015-11-11 13:40 +0100 |
| Message-ID | <qtCQW-2Lk-1@gated-at.bofh.it> |
| In reply to | #1267154 |
On Wed, Nov 11, 2015 at 01:21:04PM +0100, Daniel Borkmann wrote: > On 11/11/2015 12:58 PM, Will Deacon wrote: > >On Wed, Nov 11, 2015 at 11:42:11AM +0100, Daniel Borkmann wrote: > >>On 11/11/2015 11:24 AM, Will Deacon wrote: > >>>On Wed, Nov 11, 2015 at 09:49:48AM +0100, Arnd Bergmann wrote: > >>>>On Tuesday 10 November 2015 18:52:45 Z Lim wrote: > >>>>>On Tue, Nov 10, 2015 at 4:42 PM, Alexei Starovoitov > >>>>><alexei.starovoitov@gmail.com> wrote: > >>>>>>On Tue, Nov 10, 2015 at 04:26:02PM -0800, Shi, Yang wrote: > >>>>>>>On 11/10/2015 4:08 PM, Eric Dumazet wrote: > >>>>>>>>On Tue, 2015-11-10 at 14:41 -0800, Yang Shi wrote: > >>>>>>>>>aarch64 doesn't have native support for XADD instruction, implement it by > >>>>>>>>>the below instruction sequence: > >>>>> > >>>>>aarch64 supports atomic add in ARMv8.1. > >>>>>For ARMv8(.0), please consider using LDXR/STXR sequence. > >>>> > >>>>Is it worth optimizing for the 8.1 case? It would add a bit of complexity > >>>>to make the code depend on the CPU feature, but it's certainly doable. > >>> > >>>What's the atomicity required for? Put another way, what are we racing > >>>with (I thought bpf was single-threaded)? Do we need to worry about > >>>memory barriers? > >>> > >>>Apologies if these are stupid questions, but all I could find was > >>>samples/bpf/sock_example.c and it didn't help much :( > >> > >>The equivalent code more readable in restricted C syntax (that can be > >>compiled by llvm) can be found in samples/bpf/sockex1_kern.c. So the > >>built-in __sync_fetch_and_add() will be translated into a BPF_XADD > >>insn variant. > > > >Yikes, so the memory-model for BPF is based around the deprecated GCC > >__sync builtins, that inherit their semantics from ia64? Any reason not > >to use the C11-compatible __atomic builtins[1] as a base? > > Hmm, gcc doesn't have an eBPF compiler backend, so this won't work on > gcc at all. The eBPF backend in LLVM recognizes the __sync_fetch_and_add() > keyword and maps that to a BPF_XADD version (BPF_W or BPF_DW). In the > interpreter (__bpf_prog_run()), as Eric mentioned, this maps to atomic_add() > and atomic64_add(), respectively. So the struct bpf_insn prog[] you saw > from sock_example.c can be regarded as one possible equivalent program > section output from the compiler. Ok, so if I understand you correctly, then __sync_fetch_and_add() has different semantics depending on the backend target. That seems counter to the LLVM atomics Documentation: http://llvm.org/docs/Atomics.html which specifically calls out the __sync_* primitives as being sequentially-consistent and requiring barriers on ARM (which isn't the case for atomic[64]_add in the kernel). If we re-use the __sync_* naming scheme in the source language, I don't think we can overlay our own semantics in the backend. The __sync_fetch_and_add primitive is also expected to return the old value, which doesn't appear to be the case for BPF_XADD. Will -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2015-11-11 14:00 +0100 |
| Message-ID | <qtDai-2Sb-1@gated-at.bofh.it> |
| In reply to | #1267158 |
On Wed, Nov 11, 2015 at 12:38:31PM +0000, Will Deacon wrote: > > Hmm, gcc doesn't have an eBPF compiler backend, so this won't work on > > gcc at all. The eBPF backend in LLVM recognizes the __sync_fetch_and_add() > > keyword and maps that to a BPF_XADD version (BPF_W or BPF_DW). In the > > interpreter (__bpf_prog_run()), as Eric mentioned, this maps to atomic_add() > > and atomic64_add(), respectively. So the struct bpf_insn prog[] you saw > > from sock_example.c can be regarded as one possible equivalent program > > section output from the compiler. > > Ok, so if I understand you correctly, then __sync_fetch_and_add() has > different semantics depending on the backend target. That seems counter > to the LLVM atomics Documentation: > > http://llvm.org/docs/Atomics.html > > which specifically calls out the __sync_* primitives as being > sequentially-consistent and requiring barriers on ARM (which isn't the > case for atomic[64]_add in the kernel). > > If we re-use the __sync_* naming scheme in the source language, I don't > think we can overlay our own semantics in the backend. The > __sync_fetch_and_add primitive is also expected to return the old value, > which doesn't appear to be the case for BPF_XADD. Yikes. That's double fail. Please don't do this. If you use the __sync stuff (and I agree with Will, you should not) it really _SHOULD_ be sequentially consistent, which means full barriers all over the place. And if you name something XADD (exchange and add, or fetch-add) then it had better return the previous value. atomic*_add() does neither. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Daniel Borkmann <daniel@iogearbox.net> |
|---|---|
| Date | 2015-11-11 17:00 +0100 |
| Message-ID | <qtFYv-4IH-25@gated-at.bofh.it> |
| In reply to | #1267169 |
On 11/11/2015 01:58 PM, Peter Zijlstra wrote:
> On Wed, Nov 11, 2015 at 12:38:31PM +0000, Will Deacon wrote:
>>> Hmm, gcc doesn't have an eBPF compiler backend, so this won't work on
>>> gcc at all. The eBPF backend in LLVM recognizes the __sync_fetch_and_add()
>>> keyword and maps that to a BPF_XADD version (BPF_W or BPF_DW). In the
>>> interpreter (__bpf_prog_run()), as Eric mentioned, this maps to atomic_add()
>>> and atomic64_add(), respectively. So the struct bpf_insn prog[] you saw
>>> from sock_example.c can be regarded as one possible equivalent program
>>> section output from the compiler.
>>
>> Ok, so if I understand you correctly, then __sync_fetch_and_add() has
>> different semantics depending on the backend target. That seems counter
>> to the LLVM atomics Documentation:
>>
>> http://llvm.org/docs/Atomics.html
>>
>> which specifically calls out the __sync_* primitives as being
>> sequentially-consistent and requiring barriers on ARM (which isn't the
>> case for atomic[64]_add in the kernel).
>>
>> If we re-use the __sync_* naming scheme in the source language, I don't
>> think we can overlay our own semantics in the backend. The
>> __sync_fetch_and_add primitive is also expected to return the old value,
>> which doesn't appear to be the case for BPF_XADD.
>
> Yikes. That's double fail. Please don't do this.
>
> If you use the __sync stuff (and I agree with Will, you should not) it
> really _SHOULD_ be sequentially consistent, which means full barriers
> all over the place.
>
> And if you name something XADD (exchange and add, or fetch-add) then it
> had better return the previous value.
>
> atomic*_add() does neither.
unsigned int ui;
unsigned long long ull;
void foo(void)
{
(void) __sync_fetch_and_add(&ui, 1);
(void) __sync_fetch_and_add(&ull, 1);
}
So clang front-end translates this snippet into intermediate
representation of ...
clang test.c -S -emit-llvm -o -
[...]
define void @foo() #0 {
%1 = atomicrmw add i32* @ui, i32 1 seq_cst
%2 = atomicrmw add i64* @ull, i64 1 seq_cst
ret void
}
[...]
... which, if I see this correctly, then maps atomicrmw add {i32,i64}
in the BPF target into BPF_XADD as mentioned:
// Atomics
class XADD<bits<2> SizeOp, string OpcodeStr, PatFrag OpNode>
: InstBPF<(outs GPR:$dst), (ins MEMri:$addr, GPR:$val),
!strconcat(OpcodeStr, "\t$dst, $addr, $val"),
[(set GPR:$dst, (OpNode ADDRri:$addr, GPR:$val))]> {
bits<3> mode;
bits<2> size;
bits<4> src;
bits<20> addr;
let Inst{63-61} = mode;
let Inst{60-59} = size;
let Inst{51-48} = addr{19-16}; // base reg
let Inst{55-52} = src;
let Inst{47-32} = addr{15-0}; // offset
let mode = 6; // BPF_XADD
let size = SizeOp;
let BPFClass = 3; // BPF_STX
}
let Constraints = "$dst = $val" in {
def XADD32 : XADD<0, "xadd32", atomic_load_add_32>;
def XADD64 : XADD<3, "xadd64", atomic_load_add_64>;
// undefined def XADD16 : XADD<1, "xadd16", atomic_load_add_16>;
// undefined def XADD8 : XADD<2, "xadd8", atomic_load_add_8>;
}
I played a bit around with eBPF code to assign the __sync_fetch_and_add()
return value to a var and dump it to trace pipe, or use it as return code.
llvm compiles it (with the result assignment) and it looks like:
[...]
206: (b7) r3 = 3
207: (db) lock *(u64 *)(r0 +0) += r3
208: (bf) r1 = r10
209: (07) r1 += -16
210: (b7) r2 = 10
211: (85) call 6 // r3 dumped here
[...]
[...]
206: (b7) r5 = 3
207: (db) lock *(u64 *)(r0 +0) += r5
208: (bf) r1 = r10
209: (07) r1 += -16
210: (b7) r2 = 10
211: (b7) r3 = 43
212: (b7) r4 = 42
213: (85) call 6 // r5 dumped here
[...]
[...]
11: (b7) r0 = 3
12: (db) lock *(u64 *)(r1 +0) += r0
13: (95) exit // r0 returned here
[...]
What it seems is that we 'get back' the value (== 3 here in r3, r5, r0)
that we're adding, at least that's what seems to be generated wrt
register assignments. Hmm, the semantic differences of bpf target
should be documented somewhere for people writing eBPF programs to
be aware of.
Best,
Daniel
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Will Deacon <will.deacon@arm.com> |
|---|---|
| Date | 2015-11-11 17:30 +0100 |
| Message-ID | <qtGrw-592-19@gated-at.bofh.it> |
| In reply to | #1267269 |
Hi Daniel,
Thanks for investigating this further.
On Wed, Nov 11, 2015 at 04:52:00PM +0100, Daniel Borkmann wrote:
> I played a bit around with eBPF code to assign the __sync_fetch_and_add()
> return value to a var and dump it to trace pipe, or use it as return code.
> llvm compiles it (with the result assignment) and it looks like:
>
> [...]
> 206: (b7) r3 = 3
> 207: (db) lock *(u64 *)(r0 +0) += r3
> 208: (bf) r1 = r10
> 209: (07) r1 += -16
> 210: (b7) r2 = 10
> 211: (85) call 6 // r3 dumped here
> [...]
>
> [...]
> 206: (b7) r5 = 3
> 207: (db) lock *(u64 *)(r0 +0) += r5
> 208: (bf) r1 = r10
> 209: (07) r1 += -16
> 210: (b7) r2 = 10
> 211: (b7) r3 = 43
> 212: (b7) r4 = 42
> 213: (85) call 6 // r5 dumped here
> [...]
>
> [...]
> 11: (b7) r0 = 3
> 12: (db) lock *(u64 *)(r1 +0) += r0
> 13: (95) exit // r0 returned here
> [...]
>
> What it seems is that we 'get back' the value (== 3 here in r3, r5, r0)
> that we're adding, at least that's what seems to be generated wrt
> register assignments. Hmm, the semantic differences of bpf target
> should be documented somewhere for people writing eBPF programs to
> be aware of.
If we're going to document it, a bug tracker might be a good place to
start. The behaviour, as it stands, is broken wrt the definition of the
__sync primitives. That is, there is no way to build __sync_fetch_and_add
out of BPF_XADD without changing its semantics.
We could fix this by either:
(1) Defining BPF_XADD to match __sync_fetch_and_add (including memory
barriers).
(2) Introducing some new BPF_ atomics, that map to something like the
C11 __atomic builtins and deprecating BPF_XADD in favour of these.
(3) Introducing new source-language intrinsics to match what BPF can do
(unlikely to be popular).
As it stands, I'm not especially keen on adding BPF_XADD to the arm64
JIT backend until we have at least (1) and preferably (2) as well.
Will
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Alexei Starovoitov <alexei.starovoitov@gmail.com> |
|---|---|
| Date | 2015-11-11 18:30 +0100 |
| Message-ID | <qtHnz-5Ks-7@gated-at.bofh.it> |
| In reply to | #1267291 |
On Wed, Nov 11, 2015 at 04:23:41PM +0000, Will Deacon wrote: > > If we're going to document it, a bug tracker might be a good place to > start. The behaviour, as it stands, is broken wrt the definition of the > __sync primitives. That is, there is no way to build __sync_fetch_and_add > out of BPF_XADD without changing its semantics. BPF_XADD == atomic_add() in kernel. period. we are not going to deprecate it or introduce something else. Semantics of __sync* or atomic in C standard and/or gcc/llvm has nothing to do with this. arm64 JIT needs to JIT bpf_xadd insn equivalent to the code of atomic_add() which is 'stadd' in armv8.1. The cpu check can be done by jit and for older cpus just fall back to interpreter. trivial. > We could fix this by either: > > (1) Defining BPF_XADD to match __sync_fetch_and_add (including memory > barriers). nope. > (2) Introducing some new BPF_ atomics, that map to something like the > C11 __atomic builtins and deprecating BPF_XADD in favour of these. nope. > (3) Introducing new source-language intrinsics to match what BPF can do > (unlikely to be popular). llvm's __sync intrinsic is used temporarily until we have time to do new intrinsic in llvm that matches kernel's atomic_add() properly. It will be done similar to llvm-bpf load_byte/word intrinsics. Note that we've been hiding it under lock_xadd() wrapper, like here: https://github.com/iovisor/bcc/blob/master/examples/networking/tunnel_monitor/monitor.c#L130 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | David Miller <davem@davemloft.net> |
|---|---|
| Date | 2015-11-11 18:40 +0100 |
| Message-ID | <qtHxg-5NS-33@gated-at.bofh.it> |
| In reply to | #1267333 |
From: Alexei Starovoitov <alexei.starovoitov@gmail.com> Date: Wed, 11 Nov 2015 09:27:00 -0800 > BPF_XADD == atomic_add() in kernel. period. > we are not going to deprecate it or introduce something else. Agreed, it makes no sense to try and tie C99 or whatever atomic semantics to something that is already clearly defined to have exactly kernel atomic_add() semantics. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Will Deacon <will.deacon@arm.com> |
|---|---|
| Date | 2015-11-11 18:50 +0100 |
| Message-ID | <qtHGW-5Rq-19@gated-at.bofh.it> |
| In reply to | #1267343 |
On Wed, Nov 11, 2015 at 12:35:48PM -0500, David Miller wrote: > From: Alexei Starovoitov <alexei.starovoitov@gmail.com> > Date: Wed, 11 Nov 2015 09:27:00 -0800 > > > BPF_XADD == atomic_add() in kernel. period. > > we are not going to deprecate it or introduce something else. > > Agreed, it makes no sense to try and tie C99 or whatever atomic > semantics to something that is already clearly defined to have > exactly kernel atomic_add() semantics. ... and which is emitted by LLVM when asked to compile __sync_fetch_and_add, which has clearly defined (yet conflicting) semantics. If the discrepancy is in LLVM (and it sounds like it is), then I'll raise a bug over there instead. Will -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | David Miller <davem@davemloft.net> |
|---|---|
| Date | 2015-11-11 20:10 +0100 |
| Message-ID | <qtIWm-6Rf-29@gated-at.bofh.it> |
| In reply to | #1267347 |
From: Will Deacon <will.deacon@arm.com> Date: Wed, 11 Nov 2015 17:44:01 +0000 > On Wed, Nov 11, 2015 at 12:35:48PM -0500, David Miller wrote: >> From: Alexei Starovoitov <alexei.starovoitov@gmail.com> >> Date: Wed, 11 Nov 2015 09:27:00 -0800 >> >> > BPF_XADD == atomic_add() in kernel. period. >> > we are not going to deprecate it or introduce something else. >> >> Agreed, it makes no sense to try and tie C99 or whatever atomic >> semantics to something that is already clearly defined to have >> exactly kernel atomic_add() semantics. > > ... and which is emitted by LLVM when asked to compile __sync_fetch_and_add, > which has clearly defined (yet conflicting) semantics. Alexei clearly stated that he knows about this issue and will fully fix this up in LLVM. What more do you need to hear from him once he's stated that he is aware and is working on it? Meanwhile you should make your JIT emit what is expected, rather than arguing to change the semantics. Thanks. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2015-11-11 19:00 +0100 |
| Message-ID | <qtHQD-5Vc-31@gated-at.bofh.it> |
| In reply to | #1267343 |
On Wed, Nov 11, 2015 at 12:35:48PM -0500, David Miller wrote: > From: Alexei Starovoitov <alexei.starovoitov@gmail.com> > Date: Wed, 11 Nov 2015 09:27:00 -0800 > > > BPF_XADD == atomic_add() in kernel. period. > > we are not going to deprecate it or introduce something else. > > Agreed, it makes no sense to try and tie C99 or whatever atomic > semantics to something that is already clearly defined to have > exactly kernel atomic_add() semantics. Dave, this really doesn't make any sense to me. __sync primitives have well defined semantics and (e)BPF is violating this. Furthermore, the fetch_and_add (or XADD) name has well defined semantics, which (e)BPF also violates. Atomicy is hard enough as it is, backends giving random interpretations to them isn't helping anybody. It also baffles me that Alexei is seemingly unwilling to change/rev the (e)BPF instructions, which would be invisible to the regular user, he does want to change the language itself, which will impact all 'scripts'. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Alexei Starovoitov <alexei.starovoitov@gmail.com> |
|---|---|
| Date | 2015-11-11 19:20 +0100 |
| Message-ID | <qtI9X-6iG-7@gated-at.bofh.it> |
| In reply to | #1267353 |
On Wed, Nov 11, 2015 at 06:57:41PM +0100, Peter Zijlstra wrote: > On Wed, Nov 11, 2015 at 12:35:48PM -0500, David Miller wrote: > > From: Alexei Starovoitov <alexei.starovoitov@gmail.com> > > Date: Wed, 11 Nov 2015 09:27:00 -0800 > > > > > BPF_XADD == atomic_add() in kernel. period. > > > we are not going to deprecate it or introduce something else. > > > > Agreed, it makes no sense to try and tie C99 or whatever atomic > > semantics to something that is already clearly defined to have > > exactly kernel atomic_add() semantics. > > Dave, this really doesn't make any sense to me. __sync primitives have > well defined semantics and (e)BPF is violating this. bpf_xadd was never meant to be __sync_fetch_and_add equivalent. From the day one it meant to be atomic_add() as kernel does it. I did piggy back on __sync in the llvm backend because it was the quick and dirty way to move forward. In retrospect I should have introduced a clean intrinstic for that instead, but it's not too late to do it now. user space we can change at any time unlike kernel. > Furthermore, the fetch_and_add (or XADD) name has well defined > semantics, which (e)BPF also violates. bpf_xadd also didn't meant to be 'fetch'. It was void return from the beginning. > Atomicy is hard enough as it is, backends giving random interpretations > to them isn't helping anybody. no randomness. bpf_xadd == atomic_add() in kernel. imo that is the simplest and cleanest intepretantion one can have, no? > It also baffles me that Alexei is seemingly unwilling to change/rev the > (e)BPF instructions, which would be invisible to the regular user, he > does want to change the language itself, which will impact all > 'scripts'. well, we cannot change it in kernel because it's ABI. I'm not against adding new insns. We definitely can, but let's figure out why? Is anything broken? No. So what new insns make sense? Add new one that does 'fetch_and_add' ? What is the real use case it will be used for? Adding new intrinsic to llvm is not a big deal. I'll add it as soon as I have time to work on it or if somebody beats me to it I would be glad to test it and apply it. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | linux.kernel
csiph-web