linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/bpf: Add arm target register definitions
@ 2019-03-04 20:50 Adrian Ratiu
  2019-03-04 22:59 ` Song Liu
  0 siblings, 1 reply; 2+ messages in thread
From: Adrian Ratiu @ 2019-03-04 20:50 UTC (permalink / raw)
  To: bpf, Shuah Khan; +Cc: linux-kernel, netdev, linux-kselftest

eBPF "restricted C" code can be compiled with LLVM/clang using target
triplets like armv7l-unknown-linux-gnueabihf and loaded/run with small
cross-compiled gobpf/elf [1] programs without requiring a full BCC
port which is also undesirable on small embedded systems due to its
size footprint. The only missing pieces are these helper macros which
otherwise have to be redefined by each eBPF arm program.

[1] https://github.com/iovisor/gobpf/tree/master/elf

Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
---
 tools/testing/selftests/bpf/bpf_helpers.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tools/testing/selftests/bpf/bpf_helpers.h b/tools/testing/selftests/bpf/bpf_helpers.h
index 6c77cf7bedce..f7883576f445 100644
--- a/tools/testing/selftests/bpf/bpf_helpers.h
+++ b/tools/testing/selftests/bpf/bpf_helpers.h
@@ -232,6 +232,9 @@ static int (*bpf_skb_pull_data)(void *, int len) =
 #elif defined(__TARGET_ARCH_s930x)
 	#define bpf_target_s930x
 	#define bpf_target_defined
+#elif defined(__TARGET_ARCH_arm)
+	#define bpf_target_arm
+	#define bpf_target_defined
 #elif defined(__TARGET_ARCH_arm64)
 	#define bpf_target_arm64
 	#define bpf_target_defined
@@ -254,6 +257,8 @@ static int (*bpf_skb_pull_data)(void *, int len) =
 	#define bpf_target_x86
 #elif defined(__s390x__)
 	#define bpf_target_s930x
+#elif defined(__arm__)
+	#define bpf_target_arm
 #elif defined(__aarch64__)
 	#define bpf_target_arm64
 #elif defined(__mips__)
@@ -291,6 +296,19 @@ static int (*bpf_skb_pull_data)(void *, int len) =
 #define PT_REGS_SP(x) ((x)->gprs[15])
 #define PT_REGS_IP(x) ((x)->psw.addr)
 
+#elif defined(bpf_target_arm)
+
+#define PT_REGS_PARM1(x) ((x)->uregs[0])
+#define PT_REGS_PARM2(x) ((x)->uregs[1])
+#define PT_REGS_PARM3(x) ((x)->uregs[2])
+#define PT_REGS_PARM4(x) ((x)->uregs[3])
+#define PT_REGS_PARM5(x) ((x)->uregs[4])
+#define PT_REGS_RET(x) ((x)->uregs[14])
+#define PT_REGS_FP(x) ((x)->uregs[11]) /* Works only with CONFIG_FRAME_POINTER */
+#define PT_REGS_RC(x) ((x)->uregs[0])
+#define PT_REGS_SP(x) ((x)->uregs[13])
+#define PT_REGS_IP(x) ((x)->uregs[12])
+
 #elif defined(bpf_target_arm64)
 
 #define PT_REGS_PARM1(x) ((x)->regs[0])
-- 
2.20.1


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

* Re: [PATCH] selftests/bpf: Add arm target register definitions
  2019-03-04 20:50 [PATCH] selftests/bpf: Add arm target register definitions Adrian Ratiu
@ 2019-03-04 22:59 ` Song Liu
  0 siblings, 0 replies; 2+ messages in thread
From: Song Liu @ 2019-03-04 22:59 UTC (permalink / raw)
  To: Adrian Ratiu; +Cc: bpf, Shuah Khan, open list, Networking, linux-kselftest

On Mon, Mar 4, 2019 at 12:50 PM Adrian Ratiu <adrian.ratiu@collabora.com> wrote:
>
> eBPF "restricted C" code can be compiled with LLVM/clang using target
> triplets like armv7l-unknown-linux-gnueabihf and loaded/run with small
> cross-compiled gobpf/elf [1] programs without requiring a full BCC
> port which is also undesirable on small embedded systems due to its
> size footprint. The only missing pieces are these helper macros which
> otherwise have to be redefined by each eBPF arm program.
>
> [1] https://github.com/iovisor/gobpf/tree/master/elf
>
> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>

I think this is for bpf-next tree, which is closed during the merge window.
Please resubmit when the bpf-next trees is opened (usually in 2 weeks).

Thanks,
Song

> ---
>  tools/testing/selftests/bpf/bpf_helpers.h | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/bpf_helpers.h b/tools/testing/selftests/bpf/bpf_helpers.h
> index 6c77cf7bedce..f7883576f445 100644
> --- a/tools/testing/selftests/bpf/bpf_helpers.h
> +++ b/tools/testing/selftests/bpf/bpf_helpers.h
> @@ -232,6 +232,9 @@ static int (*bpf_skb_pull_data)(void *, int len) =
>  #elif defined(__TARGET_ARCH_s930x)
>         #define bpf_target_s930x
>         #define bpf_target_defined
> +#elif defined(__TARGET_ARCH_arm)
> +       #define bpf_target_arm
> +       #define bpf_target_defined
>  #elif defined(__TARGET_ARCH_arm64)
>         #define bpf_target_arm64
>         #define bpf_target_defined
> @@ -254,6 +257,8 @@ static int (*bpf_skb_pull_data)(void *, int len) =
>         #define bpf_target_x86
>  #elif defined(__s390x__)
>         #define bpf_target_s930x
> +#elif defined(__arm__)
> +       #define bpf_target_arm
>  #elif defined(__aarch64__)
>         #define bpf_target_arm64
>  #elif defined(__mips__)
> @@ -291,6 +296,19 @@ static int (*bpf_skb_pull_data)(void *, int len) =
>  #define PT_REGS_SP(x) ((x)->gprs[15])
>  #define PT_REGS_IP(x) ((x)->psw.addr)
>
> +#elif defined(bpf_target_arm)
> +
> +#define PT_REGS_PARM1(x) ((x)->uregs[0])
> +#define PT_REGS_PARM2(x) ((x)->uregs[1])
> +#define PT_REGS_PARM3(x) ((x)->uregs[2])
> +#define PT_REGS_PARM4(x) ((x)->uregs[3])
> +#define PT_REGS_PARM5(x) ((x)->uregs[4])
> +#define PT_REGS_RET(x) ((x)->uregs[14])
> +#define PT_REGS_FP(x) ((x)->uregs[11]) /* Works only with CONFIG_FRAME_POINTER */
> +#define PT_REGS_RC(x) ((x)->uregs[0])
> +#define PT_REGS_SP(x) ((x)->uregs[13])
> +#define PT_REGS_IP(x) ((x)->uregs[12])
> +
>  #elif defined(bpf_target_arm64)
>
>  #define PT_REGS_PARM1(x) ((x)->regs[0])
> --
> 2.20.1
>

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

end of thread, other threads:[~2019-03-04 22:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-04 20:50 [PATCH] selftests/bpf: Add arm target register definitions Adrian Ratiu
2019-03-04 22:59 ` Song Liu

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).