libbpf: Add LoongArch support to bpf_tracing.h
PATCH 1/1 libbpf: Add LoongArch support to bpf_tracing.h
Add PT_REGS macros for LoongArch64.
--- tools/lib/bpf/bpf_tracing.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
tools/lib/bpf/bpf_tracing.h +21 -0
@@ -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__) && __loongarch_grlen ==64 +#define bpf_target_loongarch +#define bpf_target_defined#endif /* no compiler target */ #endif
@@ -258,6 +264,21 @@ struct pt_regs___arm64 {/* arc does not select ARCH_HAS_SYSCALL_WRAPPER. */ #define PT_REGS_SYSCALL_REGS (ctx) ctx +#elif defined(bpf_target_loongarch) + +#define __PT_PARM1_REG regs[5] +#define __PT_PARM2_REG regs[6] +#define __PT_PARM3_REG regs[7] +#define __PT_PARM4_REG regs[8] +#define __PT_PARM5_REG regs[9] +#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
Quoted 40 lines · Hengqi Chen
Add
PT_REGSmacros for LoongArch64.Signed-off-by Hengqi Chen <[email protected]>--- tools/lib/bpf/bpf_tracing.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)tools/lib/bpf/bpf_tracing.h +10
-0@@ -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__) && __loongarch_grlen ==64 +#define bpf_target_loongarch +#define bpf_target_defined#endif /* no compiler target */ #endif @@ -258,6 +264,21 @@ struct pt_regs___arm64 {/* arc does not select ARCH_HAS_SYSCALL_WRAPPER. */ #define PT_REGS_SYSCALL_REGS (ctx) ctx +#elif defined(bpf_target_loongarch) + +#define __PT_PARM1_REG regs[5] +#define __PT_PARM2_REG regs[6]
tools/lib/bpf/bpf_tracing.h struct pt_regs___arm64 { · line 280
Quoted 10 lines
tools/lib/bpf/bpf_tracing.h +10
-0+#define __PT_PARM3_REG regs[7] +#define __PT_PARM4_REG regs[8] +#define __PT_PARM5_REG regs[9] +#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
Is there some online documentation explaining this architecture's calling conventions? It would be useful to include that as a comment to be able to refer back to it. On a related note, are there any syscall specific calling convention differences, similar to PT_REGS_PARM1_SYSCALL for arm64 or PT_REGS_PARM4_SYSCALL for x86-64?
Quoted 6 lines
tools/lib/bpf/bpf_tracing.h +1
-1+#endif #if defined(bpf_target_defined) --2.31.1
Quoted 50 lines · Andrii Nakryiko
Quoted 48 lines · Hengqi Chen
Add
PT_REGSmacros for LoongArch64.Signed-off-by Hengqi Chen <[email protected]>--- tools/lib/bpf/bpf_tracing.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)tools/lib/bpf/bpf_tracing.h +18
-0@@ -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__) && __loongarch_grlen ==64 +#define bpf_target_loongarch +#define bpf_target_defined#endif /* no compiler target */ #endif @@ -258,6 +264,21 @@ struct pt_regs___arm64 {/* arc does not select ARCH_HAS_SYSCALL_WRAPPER. */ #define PT_REGS_SYSCALL_REGS (ctx) ctx +#elif defined(bpf_target_loongarch) + +#define __PT_PARM1_REG regs[5] +#define __PT_PARM2_REG regs[6] +#define __PT_PARM3_REG regs[7] +#define __PT_PARM4_REG regs[8] +#define __PT_PARM5_REG regs[9] +#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
Quoted 9 lines
tools/lib/bpf/bpf_tracing.h struct pt_regs___arm64 { · line 280
Quoted 2 lines
tools/lib/bpf/bpf_tracing.h +2
-0+/* loongarch does not select ARCH_HAS_SYSCALL_WRAPPER. */ +#define PT_REGS_SYSCALL_REGS (ctx) ctxIs there some online documentation explaining this architecture's calling conventions? It would be useful to include that as a comment to be able to refer back to it. On a related note, are there any syscall specific calling convention differences, similar to
PT_REGS_PARM1_SYSCALLfor arm64 orPT_REGS_PARM4_SYSCALLfor x86-64?
Ok, I think [0] would be a good resource, please add a link to it in the comment. But also it seems like PARM1-5 should map to regs[6] through regs[10] (not regs[5] - regs[9] that you have here). And BTW, seems like architecture supports passing more than five, PARM6 would be regs[11]. I've been wanting to add 6th+ argument to libbpf macros' for a while (it came up in x86-64 world for uprobes as well), so if you have cycles, please consider helping with that as well.
Also I see orig_a0 in struct pt_regs, which seems suspiciously similar to arm64's PT_REGS_PARM1_SYSCALL's use of orig_x0, please check about that as well. As I said, syscalls usually have some additional quirks.
[0] https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
Quoted 6 lines
Quoted 6 lines
tools/lib/bpf/bpf_tracing.h +1
-1+#endif #if defined(bpf_target_defined) --2.31.1
Quoted 62 lines · Andrii Nakryiko
Quoted 50 lines · Andrii Nakryiko
Quoted 48 lines · Hengqi Chen
Add
PT_REGSmacros for LoongArch64.Signed-off-by Hengqi Chen <[email protected]>--- tools/lib/bpf/bpf_tracing.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)tools/lib/bpf/bpf_tracing.h +18
-0@@ -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__) && __loongarch_grlen ==64 +#define bpf_target_loongarch +#define bpf_target_defined#endif /* no compiler target */ #endif @@ -258,6 +264,21 @@ struct pt_regs___arm64 {/* arc does not select ARCH_HAS_SYSCALL_WRAPPER. */ #define PT_REGS_SYSCALL_REGS (ctx) ctx +#elif defined(bpf_target_loongarch) + +#define __PT_PARM1_REG regs[5] +#define __PT_PARM2_REG regs[6] +#define __PT_PARM3_REG regs[7] +#define __PT_PARM4_REG regs[8] +#define __PT_PARM5_REG regs[9] +#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_eraQuoted 9 lines
tools/lib/bpf/bpf_tracing.h struct pt_regs___arm64 { · line 280
Quoted 2 lines
tools/lib/bpf/bpf_tracing.h +2
-0+/* loongarch does not select ARCH_HAS_SYSCALL_WRAPPER. */ +#define PT_REGS_SYSCALL_REGS (ctx) ctxIs there some online documentation explaining this architecture's calling conventions? It would be useful to include that as a comment to be able to refer back to it. On a related note, are there any syscall specific calling convention differences, similar to
PT_REGS_PARM1_SYSCALLfor arm64 orPT_REGS_PARM4_SYSCALLfor x86-64?
Quoted 8 lines
Ok, I think [0] would be a good resource, please add a link to it in the comment. But also it seems like PARM1-5 should map to regs[6] through regs[10] (not regs[5] - regs[9] that you have here). And BTW, seems like architecture supports passing more than five, PARM6 would be regs[11]. I've been wanting to add 6th+ argument to libbpf macros' for a while (it came up in x86-64 world for uprobes as well), so if you have cycles, please consider helping with that as well.
I've seen this on GitHub. Let me have a try.
Quoted 5 lines
Also I see
orig_a0in structpt_regs, which seems suspiciously similar to arm64's PT_REGS_PARM1_SYSCALL's use oforig_x0, please check about that as well. As I said, syscalls usually have some additional quirks.
Quoted 9 lines
[0] https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
Quoted 6 lines
Quoted 6 lines
tools/lib/bpf/bpf_tracing.h +1
-1+#endif #if defined(bpf_target_defined) --2.31.1
Thanks, Andrii.
After some investigation, I do find some quirks on syscalls. Will update this patch.