Skip to contentSkip to conversation

libbpf: Add LoongArch support to bpf_tracing.h

PATCH Applied Hengqi Chen 4 participants 5 messages Dec 31, 2022 – Jan 3, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbpf: Add LoongArch support to bpf_tracing.h

Add PT_REGS macros for LoongArch ([0]).

[0]: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html

---
 tools/lib/bpf/bpf_tracing.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
tools/lib/bpf/bpf_tracing.h +23 -0
index 9c1b1689068d..bdb0f6b5be84 100644
@@ -32,6 +32,9 @@
 #elif defined(__TARGET_ARCH_arc)
 	#define bpf_target_arc
 	#define bpf_target_defined
+#elif defined(__TARGET_ARCH_loongarch)
+	#define bpf_target_loongarch
+	#define bpf_target_defined
 #else
 
 /* Fall back to what the compiler says */
@@ -62,6 +65,9 @@
 #elif defined(__arc__)
 	#define bpf_target_arc
 	#define bpf_target_defined
+#elif defined(__loongarch__)
+	#define bpf_target_loongarch
+	#define bpf_target_defined
 #endif /* no compiler target */
 
 #endif
@@ -258,6 +264,23 @@ struct pt_regs___arm64 {
 /* arc does not select ARCH_HAS_SYSCALL_WRAPPER. */
 #define PT_REGS_SYSCALL_REGS(ctx) ctx
 
+#elif defined(bpf_target_loongarch)
+
+/* https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html */
+
+#define __PT_PARM1_REG regs[4]
+#define __PT_PARM2_REG regs[5]
+#define __PT_PARM3_REG regs[6]
+#define __PT_PARM4_REG regs[7]
+#define __PT_PARM5_REG regs[8]
+#define __PT_RET_REG regs[1]
+#define __PT_FP_REG regs[22]
+#define __PT_RC_REG regs[4]
+#define __PT_SP_REG regs[3]
+#define __PT_IP_REG csr_era
+/* loongarch does not select ARCH_HAS_SYSCALL_WRAPPER. */
+#define PT_REGS_SYSCALL_REGS(ctx) ctx
+
 #endif
 
 #if defined(bpf_target_defined)

--
2.31.1

maintainer
#1 lore raw

LGTM, I will queue this patch for loongarch-next if no one has objections. Thank you.

Quoted 61 lines · Hengqi Chen

Add PT_REGS macros for LoongArch ([0]).

[0]: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html

---
 tools/lib/bpf/bpf_tracing.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
tools/lib/bpf/bpf_tracing.h +23 -1
index 9c1b1689068d..bdb0f6b5be84 100644
@@ -32,6 +32,9 @@
 #elif defined(__TARGET_ARCH_arc)
        #define bpf_target_arc
        #define bpf_target_defined
+#elif defined(__TARGET_ARCH_loongarch)
+       #define bpf_target_loongarch
+       #define bpf_target_defined
 #else
 
 /* Fall back to what the compiler says */
@@ -62,6 +65,9 @@
 #elif defined(__arc__)
        #define bpf_target_arc
        #define bpf_target_defined
+#elif defined(__loongarch__)
+       #define bpf_target_loongarch
+       #define bpf_target_defined
 #endif /* no compiler target */
 
 #endif
@@ -258,6 +264,23 @@ struct pt_regs___arm64 {
 /* arc does not select ARCH_HAS_SYSCALL_WRAPPER. */
 #define PT_REGS_SYSCALL_REGS(ctx) ctx
 
+#elif defined(bpf_target_loongarch)
+
+/* https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html */
+
+#define __PT_PARM1_REG regs[4]
+#define __PT_PARM2_REG regs[5]
+#define __PT_PARM3_REG regs[6]
+#define __PT_PARM4_REG regs[7]
+#define __PT_PARM5_REG regs[8]
+#define __PT_RET_REG regs[1]
+#define __PT_FP_REG regs[22]
+#define __PT_RC_REG regs[4]
+#define __PT_SP_REG regs[3]
+#define __PT_IP_REG csr_era
+/* loongarch does not select ARCH_HAS_SYSCALL_WRAPPER. */
+#define PT_REGS_SYSCALL_REGS(ctx) ctx
+
 #endif
 
 #if defined(bpf_target_defined)
--

2.31.1

maintainer
#2 lore raw
Quoted 2 lines · Huacai Chen

LGTM, I will queue this patch for loongarch-next if no one has objections. Thank you.

To avoid potential merge conflicts for the next dev cycle, any objections if you could Ack it and we'd take it via bpf-next tree instead?

Thanks,
Daniel

maintainer Acked-by
#3 lore raw

OK, bpf-next is also fine for me.

Quoted 10 lines · Daniel Borkmann
Quoted 2 lines · Huacai Chen

LGTM, I will queue this patch for loongarch-next if no one has objections. Thank you.

To avoid potential merge conflicts for the next dev cycle, any objections if you could Ack it and we'd take it via bpf-next tree instead?

Thanks,
Daniel

#4 lore raw
In reply to Hengqi Chen
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 10 lines · On Sat, 31 Dec 2022 18:07:57 +0800 you wrote:

Add PT_REGS macros for LoongArch ([0]).

[0]: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html

---
 tools/lib/bpf/bpf_tracing.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

[...]

Here is the summary with links:
- [bpf-next] libbpf: Add LoongArch support to bpf_tracing.h

    https://git.kernel.org/bpf/bpf-next/c/00883922ab40

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html