All of lore.kernel.org
 help / color / mirror / Atom feed
* [bpf PATCH 1/2] bpf: Document sockmap '-target bpf' requirement for PROG_TYPE_SK_MSG
@ 2018-04-23 19:11 John Fastabend
  2018-04-23 19:11 ` [bpf PATCH 2/2] bpf: sockmap sample use clang flag, -target bpf John Fastabend
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: John Fastabend @ 2018-04-23 19:11 UTC (permalink / raw)
  To: ast, daniel; +Cc: netdev

BPF_PROG_TYPE_SK_MSG programs use a 'void *' for both data and the
data_end pointers. Additionally, the verifier ensures that every
accesses into the values is a __u64 read. This correctly maps on
to the BPF 64-bit architecture.

However, to ensure that when building on 32bit architectures that
clang uses correct types the '-target bpf' option _must_ be
specified. To make this clear add a note to the Documentation.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 0 files changed

diff --git a/Documentation/bpf/bpf_devel_QA.txt b/Documentation/bpf/bpf_devel_QA.txt
index 1a0b704..da57601 100644
--- a/Documentation/bpf/bpf_devel_QA.txt
+++ b/Documentation/bpf/bpf_devel_QA.txt
@@ -557,6 +557,14 @@ A: Although LLVM IR generation and optimization try to stay architecture
        pulls in some header files containing file scope host assembly codes.
      - You can add "-fno-jump-tables" to work around the switch table issue.
 
-   Otherwise, you can use bpf target.
+   Otherwise, you can use bpf target. Additionally, you _must_ use bpf target
+   when:
+
+     - Your program uses data structures with pointer or long / unsigned long
+       types that interface with BPF helpers or context data structures. Access
+       into these structures is verified by the BPF verifier and may result
+       in verification failures if the native architecture is not aligned with
+       the BPF architecture, e.g. 64-bit. An example of this is
+       BPF_PROG_TYPE_SK_MSG require '-target bpf'
 
 Happy BPF hacking!

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [bpf PATCH 2/2] bpf: sockmap sample use clang flag, -target bpf
  2018-04-23 19:11 [bpf PATCH 1/2] bpf: Document sockmap '-target bpf' requirement for PROG_TYPE_SK_MSG John Fastabend
@ 2018-04-23 19:11 ` John Fastabend
  2018-04-23 19:35   ` Alexei Starovoitov
  2018-04-23 19:35 ` [bpf PATCH 1/2] bpf: Document sockmap '-target bpf' requirement for PROG_TYPE_SK_MSG Alexei Starovoitov
  2018-04-23 21:44 ` Daniel Borkmann
  2 siblings, 1 reply; 5+ messages in thread
From: John Fastabend @ 2018-04-23 19:11 UTC (permalink / raw)
  To: ast, daniel; +Cc: netdev

Per Documentation/bpf/bpf_devel_QA.txt add the -target flag to the
sockmap Makefile. Relevant text quoted here,

   Otherwise, you can use bpf target. Additionally, you _must_ use
   bpf target when:

 - Your program uses data structures with pointer or long / unsigned
   long types that interface with BPF helpers or context data
   structures. Access into these structures is verified by the BPF
   verifier and may result in verification failures if the native
   architecture is not aligned with the BPF architecture, e.g. 64-bit.
   An example of this is BPF_PROG_TYPE_SK_MSG require '-target bpf'

Fixes: 69e8cc134bcb ("bpf: sockmap sample program")
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 samples/sockmap/Makefile |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/samples/sockmap/Makefile b/samples/sockmap/Makefile
index 9bf2881..fa53f4d 100644
--- a/samples/sockmap/Makefile
+++ b/samples/sockmap/Makefile
@@ -65,11 +65,14 @@ $(src)/*.c: verify_target_bpf
 # asm/sysreg.h - inline assembly used by it is incompatible with llvm.
 # But, there is no easy way to fix it, so just exclude it since it is
 # useless for BPF samples.
+#
+# -target bpf option required with SK_MSG programs, this is to ensure
+#  reading 'void *' data types for data and data_end are __u64 reads.
 $(obj)/%.o: $(src)/%.c
 	$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
 		-D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
 		-Wno-compare-distinct-pointer-types \
 		-Wno-gnu-variable-sized-type-not-at-end \
 		-Wno-address-of-packed-member -Wno-tautological-compare \
-		-Wno-unknown-warning-option \
-		-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
+		-Wno-unknown-warning-option -O2 -target bpf \
+		-emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [bpf PATCH 1/2] bpf: Document sockmap '-target bpf' requirement for PROG_TYPE_SK_MSG
  2018-04-23 19:11 [bpf PATCH 1/2] bpf: Document sockmap '-target bpf' requirement for PROG_TYPE_SK_MSG John Fastabend
  2018-04-23 19:11 ` [bpf PATCH 2/2] bpf: sockmap sample use clang flag, -target bpf John Fastabend
@ 2018-04-23 19:35 ` Alexei Starovoitov
  2018-04-23 21:44 ` Daniel Borkmann
  2 siblings, 0 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2018-04-23 19:35 UTC (permalink / raw)
  To: John Fastabend; +Cc: ast, daniel, netdev

On Mon, Apr 23, 2018 at 12:11:02PM -0700, John Fastabend wrote:
> BPF_PROG_TYPE_SK_MSG programs use a 'void *' for both data and the
> data_end pointers. Additionally, the verifier ensures that every
> accesses into the values is a __u64 read. This correctly maps on
> to the BPF 64-bit architecture.
> 
> However, to ensure that when building on 32bit architectures that
> clang uses correct types the '-target bpf' option _must_ be
> specified. To make this clear add a note to the Documentation.
> 
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>

Acked-by: Alexei Starovoitov <ast@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [bpf PATCH 2/2] bpf: sockmap sample use clang flag, -target bpf
  2018-04-23 19:11 ` [bpf PATCH 2/2] bpf: sockmap sample use clang flag, -target bpf John Fastabend
@ 2018-04-23 19:35   ` Alexei Starovoitov
  0 siblings, 0 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2018-04-23 19:35 UTC (permalink / raw)
  To: John Fastabend; +Cc: ast, daniel, netdev

On Mon, Apr 23, 2018 at 12:11:08PM -0700, John Fastabend wrote:
> Per Documentation/bpf/bpf_devel_QA.txt add the -target flag to the
> sockmap Makefile. Relevant text quoted here,
> 
>    Otherwise, you can use bpf target. Additionally, you _must_ use
>    bpf target when:
> 
>  - Your program uses data structures with pointer or long / unsigned
>    long types that interface with BPF helpers or context data
>    structures. Access into these structures is verified by the BPF
>    verifier and may result in verification failures if the native
>    architecture is not aligned with the BPF architecture, e.g. 64-bit.
>    An example of this is BPF_PROG_TYPE_SK_MSG require '-target bpf'
> 
> Fixes: 69e8cc134bcb ("bpf: sockmap sample program")
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>

Acked-by: Alexei Starovoitov <ast@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [bpf PATCH 1/2] bpf: Document sockmap '-target bpf' requirement for PROG_TYPE_SK_MSG
  2018-04-23 19:11 [bpf PATCH 1/2] bpf: Document sockmap '-target bpf' requirement for PROG_TYPE_SK_MSG John Fastabend
  2018-04-23 19:11 ` [bpf PATCH 2/2] bpf: sockmap sample use clang flag, -target bpf John Fastabend
  2018-04-23 19:35 ` [bpf PATCH 1/2] bpf: Document sockmap '-target bpf' requirement for PROG_TYPE_SK_MSG Alexei Starovoitov
@ 2018-04-23 21:44 ` Daniel Borkmann
  2 siblings, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2018-04-23 21:44 UTC (permalink / raw)
  To: John Fastabend, ast; +Cc: netdev

Applied both to bpf tree, thanks John!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-04-23 21:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-23 19:11 [bpf PATCH 1/2] bpf: Document sockmap '-target bpf' requirement for PROG_TYPE_SK_MSG John Fastabend
2018-04-23 19:11 ` [bpf PATCH 2/2] bpf: sockmap sample use clang flag, -target bpf John Fastabend
2018-04-23 19:35   ` Alexei Starovoitov
2018-04-23 19:35 ` [bpf PATCH 1/2] bpf: Document sockmap '-target bpf' requirement for PROG_TYPE_SK_MSG Alexei Starovoitov
2018-04-23 21:44 ` Daniel Borkmann

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.