bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h
@ 2022-12-31 10:07 Hengqi Chen
  2023-01-03  6:53 ` Huacai Chen
  2023-01-03 15:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 13+ messages in thread
From: Hengqi Chen @ 2022-12-31 10:07 UTC (permalink / raw)
  To: bpf, loongarch, andrii; +Cc: hengqi.chen

Add PT_REGS macros for LoongArch ([0]).

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

Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 tools/lib/bpf/bpf_tracing.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
index 9c1b1689068d..bdb0f6b5be84 100644
--- a/tools/lib/bpf/bpf_tracing.h
+++ b/tools/lib/bpf/bpf_tracing.h
@@ -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

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

* Re: [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h
  2022-12-31 10:07 [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h Hengqi Chen
@ 2023-01-03  6:53 ` Huacai Chen
  2023-01-03 12:28   ` Daniel Borkmann
  2023-01-03 15:50 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 13+ messages in thread
From: Huacai Chen @ 2023-01-03  6:53 UTC (permalink / raw)
  To: Hengqi Chen; +Cc: bpf, loongarch, andrii

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


On Sat, Dec 31, 2022 at 6:08 PM Hengqi Chen <hengqi.chen@gmail.com> wrote:
>
> Add PT_REGS macros for LoongArch ([0]).
>
>   [0]: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
>
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> ---
>  tools/lib/bpf/bpf_tracing.h | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
> index 9c1b1689068d..bdb0f6b5be84 100644
> --- a/tools/lib/bpf/bpf_tracing.h
> +++ b/tools/lib/bpf/bpf_tracing.h
> @@ -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
>

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

* Re: [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h
  2023-01-03  6:53 ` Huacai Chen
@ 2023-01-03 12:28   ` Daniel Borkmann
  2023-01-03 12:31     ` Huacai Chen
  0 siblings, 1 reply; 13+ messages in thread
From: Daniel Borkmann @ 2023-01-03 12:28 UTC (permalink / raw)
  To: Huacai Chen, Hengqi Chen; +Cc: bpf, loongarch, andrii

On 1/3/23 7:53 AM, Huacai Chen wrote:
> 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

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

* Re: [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h
  2023-01-03 12:28   ` Daniel Borkmann
@ 2023-01-03 12:31     ` Huacai Chen
  0 siblings, 0 replies; 13+ messages in thread
From: Huacai Chen @ 2023-01-03 12:31 UTC (permalink / raw)
  To: Daniel Borkmann; +Cc: Hengqi Chen, bpf, loongarch, andrii

OK, bpf-next is also fine for me.
Acked-by: Huacai Chen <chenhuacai@loongson.cn>

On Tue, Jan 3, 2023 at 8:28 PM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> On 1/3/23 7:53 AM, Huacai Chen wrote:
> > 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

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

* Re: [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h
  2022-12-31 10:07 [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h Hengqi Chen
  2023-01-03  6:53 ` Huacai Chen
@ 2023-01-03 15:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 13+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-01-03 15:50 UTC (permalink / raw)
  To: Hengqi Chen; +Cc: bpf, loongarch, andrii

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

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
> 
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> ---
>  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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h
  2022-12-25 12:01 Hengqi Chen
  2022-12-27  0:13 ` WANG Xuerui
@ 2022-12-29 23:11 ` Andrii Nakryiko
  1 sibling, 0 replies; 13+ messages in thread
From: Andrii Nakryiko @ 2022-12-29 23:11 UTC (permalink / raw)
  To: Hengqi Chen; +Cc: bpf, loongarch, andrii

On Sun, Dec 25, 2022 at 4:02 AM Hengqi Chen <hengqi.chen@gmail.com> wrote:
>
> Add PT_REGS macros for LoongArch64 ([0]).
>
>   [0]: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
>
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> ---
>  tools/lib/bpf/bpf_tracing.h | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
> index 2972dc25ff72..5a8a0830d133 100644
> --- a/tools/lib/bpf/bpf_tracing.h
> +++ b/tools/lib/bpf/bpf_tracing.h
> @@ -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)
> +

please put https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
in a comment somewhere here


> +#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

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

* Re: [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h
  2022-12-25 12:01 Hengqi Chen
@ 2022-12-27  0:13 ` WANG Xuerui
  2022-12-29 23:11 ` Andrii Nakryiko
  1 sibling, 0 replies; 13+ messages in thread
From: WANG Xuerui @ 2022-12-27  0:13 UTC (permalink / raw)
  To: Hengqi Chen, bpf, loongarch, andrii

Hi,

On 12/25/22 20:01, Hengqi Chen wrote:
> Add PT_REGS macros for LoongArch64 ([0]).
>
>    [0]: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
>
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> ---
>   tools/lib/bpf/bpf_tracing.h | 21 +++++++++++++++++++++
>   1 file changed, 21 insertions(+)
>
> diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
> index 2972dc25ff72..5a8a0830d133 100644
> --- a/tools/lib/bpf/bpf_tracing.h
> +++ b/tools/lib/bpf/bpf_tracing.h
> @@ -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

Isn't the whole patch independent of bitness? I'd suggest just removing 
this GRLen check so we don't need another change when we want 
LoongArch32 too.

Please adjust the commit message wording accordingly too.

> +	#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[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
>
-- 
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/


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

* [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h
@ 2022-12-25 12:01 Hengqi Chen
  2022-12-27  0:13 ` WANG Xuerui
  2022-12-29 23:11 ` Andrii Nakryiko
  0 siblings, 2 replies; 13+ messages in thread
From: Hengqi Chen @ 2022-12-25 12:01 UTC (permalink / raw)
  To: bpf, loongarch, andrii; +Cc: hengqi.chen

Add PT_REGS macros for LoongArch64 ([0]).

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

Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 tools/lib/bpf/bpf_tracing.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
index 2972dc25ff72..5a8a0830d133 100644
--- a/tools/lib/bpf/bpf_tracing.h
+++ b/tools/lib/bpf/bpf_tracing.h
@@ -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[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

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

* Re: [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h
  2022-12-13 22:09   ` Andrii Nakryiko
@ 2022-12-14  2:07     ` Hengqi Chen
  0 siblings, 0 replies; 13+ messages in thread
From: Hengqi Chen @ 2022-12-14  2:07 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, andrii, yangtiezhu



On 2022/12/14 06:09, Andrii Nakryiko wrote:
> On Mon, Dec 12, 2022 at 4:17 PM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
>>
>> On Mon, Dec 12, 2022 at 1:11 AM Hengqi Chen <hengqi.chen@gmail.com> wrote:
>>>
>>> Add PT_REGS macros for LoongArch64.
>>>
>>> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
>>> ---
>>>  tools/lib/bpf/bpf_tracing.h | 21 +++++++++++++++++++++
>>>  1 file changed, 21 insertions(+)
>>>
>>> diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
>>> index 2972dc25ff72..2d7da1caa961 100644
>>> --- a/tools/lib/bpf/bpf_tracing.h
>>> +++ b/tools/lib/bpf/bpf_tracing.h
>>> @@ -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
>>
>> 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?
>>
> 
> 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.

> 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
> 
> 
>>> +
>>>  #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.

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

* Re: [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h
  2022-12-13  0:17 ` Andrii Nakryiko
@ 2022-12-13 22:09   ` Andrii Nakryiko
  2022-12-14  2:07     ` Hengqi Chen
  0 siblings, 1 reply; 13+ messages in thread
From: Andrii Nakryiko @ 2022-12-13 22:09 UTC (permalink / raw)
  To: Hengqi Chen; +Cc: bpf, andrii, yangtiezhu

On Mon, Dec 12, 2022 at 4:17 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Mon, Dec 12, 2022 at 1:11 AM Hengqi Chen <hengqi.chen@gmail.com> wrote:
> >
> > Add PT_REGS macros for LoongArch64.
> >
> > Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> > ---
> >  tools/lib/bpf/bpf_tracing.h | 21 +++++++++++++++++++++
> >  1 file changed, 21 insertions(+)
> >
> > diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
> > index 2972dc25ff72..2d7da1caa961 100644
> > --- a/tools/lib/bpf/bpf_tracing.h
> > +++ b/tools/lib/bpf/bpf_tracing.h
> > @@ -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
>
> 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?
>

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


> > +
> >  #endif
> >
> >  #if defined(bpf_target_defined)
> > --
> > 2.31.1

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

* Re: [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h
  2022-12-12  9:11 Hengqi Chen
@ 2022-12-13  0:17 ` Andrii Nakryiko
  2022-12-13 22:09   ` Andrii Nakryiko
  0 siblings, 1 reply; 13+ messages in thread
From: Andrii Nakryiko @ 2022-12-13  0:17 UTC (permalink / raw)
  To: Hengqi Chen; +Cc: bpf, andrii, yangtiezhu

On Mon, Dec 12, 2022 at 1:11 AM Hengqi Chen <hengqi.chen@gmail.com> wrote:
>
> Add PT_REGS macros for LoongArch64.
>
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> ---
>  tools/lib/bpf/bpf_tracing.h | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
> index 2972dc25ff72..2d7da1caa961 100644
> --- a/tools/lib/bpf/bpf_tracing.h
> +++ b/tools/lib/bpf/bpf_tracing.h
> @@ -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

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?

> +
>  #endif
>
>  #if defined(bpf_target_defined)
> --
> 2.31.1

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

* [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h
@ 2022-12-12  9:11 Hengqi Chen
  2022-12-13  0:17 ` Andrii Nakryiko
  0 siblings, 1 reply; 13+ messages in thread
From: Hengqi Chen @ 2022-12-12  9:11 UTC (permalink / raw)
  To: bpf, andrii; +Cc: hengqi.chen, yangtiezhu

Add PT_REGS macros for LoongArch64.

Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 tools/lib/bpf/bpf_tracing.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
index 2972dc25ff72..2d7da1caa961 100644
--- a/tools/lib/bpf/bpf_tracing.h
+++ b/tools/lib/bpf/bpf_tracing.h
@@ -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

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

* [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h
@ 2022-12-11  7:16 Hengqi Chen
  0 siblings, 0 replies; 13+ messages in thread
From: Hengqi Chen @ 2022-12-11  7:16 UTC (permalink / raw)
  To: bpf, andrii; +Cc: hengqi.chen, yangtiezhu

Add PT_REGS macros for LoongArch64.

Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 src/bpf_tracing.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/bpf_tracing.h b/src/bpf_tracing.h
index 2972dc2..2d7da1c 100644
--- a/src/bpf_tracing.h
+++ b/src/bpf_tracing.h
@@ -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

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

end of thread, other threads:[~2023-01-03 15:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-31 10:07 [PATCH bpf-next] libbpf: Add LoongArch support to bpf_tracing.h Hengqi Chen
2023-01-03  6:53 ` Huacai Chen
2023-01-03 12:28   ` Daniel Borkmann
2023-01-03 12:31     ` Huacai Chen
2023-01-03 15:50 ` patchwork-bot+netdevbpf
  -- strict thread matches above, loose matches on Subject: below --
2022-12-25 12:01 Hengqi Chen
2022-12-27  0:13 ` WANG Xuerui
2022-12-29 23:11 ` Andrii Nakryiko
2022-12-12  9:11 Hengqi Chen
2022-12-13  0:17 ` Andrii Nakryiko
2022-12-13 22:09   ` Andrii Nakryiko
2022-12-14  2:07     ` Hengqi Chen
2022-12-11  7:16 Hengqi Chen

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