All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
To: Alexander Gordeev <agordeev@linux.ibm.com>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Ilya Leoshkevich <iii@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Paul Walmsley <paul.walmsley@sifive.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 04/11] libbpf: Add __PT_PARM1_REG_SYSCALL macro
Date: Fri, 04 Feb 2022 16:15:56 +0000	[thread overview]
Message-ID: <1643990954.fs9q9mrdxt.naveen@linux.ibm.com> (raw)
In-Reply-To: <20220204145018.1983773-5-iii@linux.ibm.com>

Ilya Leoshkevich wrote:
> Some architectures have a special way to access the first syscall
> argument. There already exists __PT_PARM4_REG_SYSCALL for the
> fourth argument, so define a similar macro for the first one.
> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  tools/lib/bpf/bpf_tracing.h | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
> index 032ba809f3e5..30f0964f8c9e 100644
> --- a/tools/lib/bpf/bpf_tracing.h
> +++ b/tools/lib/bpf/bpf_tracing.h
> @@ -265,7 +265,11 @@ struct pt_regs;
> 
>  #endif
> 
> +#ifdef __PT_PARM1_REG_SYSCALL
> +#define PT_REGS_PARM1_SYSCALL(x) (__PT_REGS_CAST(x)->__PT_PARM1_REG_SYSCALL)
> +#else /* __PT_PARM1_REG_SYSCALL */
>  #define PT_REGS_PARM1_SYSCALL(x) PT_REGS_PARM1(x)
> +#endif
>  #define PT_REGS_PARM2_SYSCALL(x) PT_REGS_PARM2(x)
>  #define PT_REGS_PARM3_SYSCALL(x) PT_REGS_PARM3(x)
>  #ifdef __PT_PARM4_REG_SYSCALL
> @@ -275,7 +279,11 @@ struct pt_regs;
>  #endif
>  #define PT_REGS_PARM5_SYSCALL(x) PT_REGS_PARM5(x)
> 
> +#ifdef __PT_PARM1_REG_SYSCALL
> +#define PT_REGS_PARM1_CORE_SYSCALL(x) BPF_CORE_READ(__PT_REGS_CAST(x), __PT_PARM1_REG_SYSCALL)
> +#else /* __PT_PARM1_REG_SYSCALL */
>  #define PT_REGS_PARM1_CORE_SYSCALL(x) PT_REGS_PARM1_CORE(x)
> +#endif
>  #define PT_REGS_PARM2_CORE_SYSCALL(x) PT_REGS_PARM2_CORE(x)
>  #define PT_REGS_PARM3_CORE_SYSCALL(x) PT_REGS_PARM3_CORE(x)
>  #ifdef __PT_PARM4_REG_SYSCALL

When I was contemplating implementing this for powerpc, I came up with 
the below patch which looked cleaner to me, and also makes it easy for 
architectures to over-ride any other syscall parameter in future. Feel 
free to include this in your series if it makes sense.

- Naveen

--
libbpf: Generalize overriding syscall parameter access macros

Instead of conditionally overriding PT_REGS_PARM4_SYSCALL, provide
default fallback for all _REG_SYSCALL macros so that architectures can
simply override a specific syscall parameter macro.

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
 tools/lib/bpf/bpf_tracing.h | 40 ++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
index 032ba809f3e57a..2e2f057c7ec7c5 100644
--- a/tools/lib/bpf/bpf_tracing.h
+++ b/tools/lib/bpf/bpf_tracing.h
@@ -265,25 +265,33 @@ struct pt_regs;
 
 #endif
 
-#define PT_REGS_PARM1_SYSCALL(x) PT_REGS_PARM1(x)
-#define PT_REGS_PARM2_SYSCALL(x) PT_REGS_PARM2(x)
-#define PT_REGS_PARM3_SYSCALL(x) PT_REGS_PARM3(x)
-#ifdef __PT_PARM4_REG_SYSCALL
-#define PT_REGS_PARM4_SYSCALL(x) (__PT_REGS_CAST(x)->__PT_PARM4_REG_SYSCALL)
-#else /* __PT_PARM4_REG_SYSCALL */
-#define PT_REGS_PARM4_SYSCALL(x) PT_REGS_PARM4(x)
+#ifndef __PT_PARM1_REG_SYSCALL
+#define __PT_PARM1_REG_SYSCALL __PT_PARM1_REG
+#endif
+#ifndef __PT_PARM2_REG_SYSCALL
+#define __PT_PARM2_REG_SYSCALL __PT_PARM2_REG
+#endif
+#ifndef __PT_PARM3_REG_SYSCALL
+#define __PT_PARM3_REG_SYSCALL __PT_PARM3_REG
+#endif
+#ifndef __PT_PARM4_REG_SYSCALL
+#define __PT_PARM4_REG_SYSCALL __PT_PARM4_REG
 #endif
-#define PT_REGS_PARM5_SYSCALL(x) PT_REGS_PARM5(x)
+#ifndef __PT_PARM5_REG_SYSCALL
+#define __PT_PARM5_REG_SYSCALL __PT_PARM5_REG
+#endif
+
+#define PT_REGS_PARM1_SYSCALL(x) (__PT_REGS_CAST(x)->__PT_PARM1_REG_SYSCALL)
+#define PT_REGS_PARM2_SYSCALL(x) (__PT_REGS_CAST(x)->__PT_PARM2_REG_SYSCALL)
+#define PT_REGS_PARM3_SYSCALL(x) (__PT_REGS_CAST(x)->__PT_PARM3_REG_SYSCALL)
+#define PT_REGS_PARM4_SYSCALL(x) (__PT_REGS_CAST(x)->__PT_PARM4_REG_SYSCALL)
+#define PT_REGS_PARM5_SYSCALL(x) (__PT_REGS_CAST(x)->__PT_PARM5_REG_SYSCALL)
 
-#define PT_REGS_PARM1_CORE_SYSCALL(x) PT_REGS_PARM1_CORE(x)
-#define PT_REGS_PARM2_CORE_SYSCALL(x) PT_REGS_PARM2_CORE(x)
-#define PT_REGS_PARM3_CORE_SYSCALL(x) PT_REGS_PARM3_CORE(x)
-#ifdef __PT_PARM4_REG_SYSCALL
+#define PT_REGS_PARM1_CORE_SYSCALL(x) BPF_CORE_READ(__PT_REGS_CAST(x), __PT_PARM1_REG_SYSCALL)
+#define PT_REGS_PARM2_CORE_SYSCALL(x) BPF_CORE_READ(__PT_REGS_CAST(x), __PT_PARM2_REG_SYSCALL)
+#define PT_REGS_PARM3_CORE_SYSCALL(x) BPF_CORE_READ(__PT_REGS_CAST(x), __PT_PARM3_REG_SYSCALL)
 #define PT_REGS_PARM4_CORE_SYSCALL(x) BPF_CORE_READ(__PT_REGS_CAST(x), __PT_PARM4_REG_SYSCALL)
-#else /* __PT_PARM4_REG_SYSCALL */
-#define PT_REGS_PARM4_CORE_SYSCALL(x) PT_REGS_PARM4_CORE(x)
-#endif
-#define PT_REGS_PARM5_CORE_SYSCALL(x) PT_REGS_PARM5_CORE(x)
+#define PT_REGS_PARM5_CORE_SYSCALL(x) BPF_CORE_READ(__PT_REGS_CAST(x), __PT_PARM5_REG_SYSCALL)
 
 #else /* defined(bpf_target_defined) */
 
-- 
2.34.1



  reply	other threads:[~2022-02-04 16:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-04 14:50 [PATCH bpf-next v3 00/11] libbpf: Fix accessing syscall arguments Ilya Leoshkevich
2022-02-04 14:50 ` [PATCH bpf-next v3 01/11] arm64/bpf: Add orig_x0 to user_pt_regs Ilya Leoshkevich
2022-02-04 14:50 ` [PATCH bpf-next v3 02/11] s390/bpf: Add orig_gpr2 " Ilya Leoshkevich
2022-02-05  0:36   ` Heiko Carstens
2022-02-05 12:37   ` Vasily Gorbik
2022-02-04 14:50 ` [PATCH bpf-next v3 03/11] selftests/bpf: Fix an endianness issue in bpf_syscall_macro test Ilya Leoshkevich
2022-02-04 14:50 ` [PATCH bpf-next v3 04/11] libbpf: Add __PT_PARM1_REG_SYSCALL macro Ilya Leoshkevich
2022-02-04 16:15   ` Naveen N. Rao [this message]
2022-02-04 14:50 ` [PATCH bpf-next v3 05/11] libbpf: Add PT_REGS_SYSCALL_REGS macro Ilya Leoshkevich
2022-02-04 16:46   ` Naveen N. Rao
2022-02-04 18:15     ` Andrii Nakryiko
2022-02-05  7:04       ` Naveen N. Rao
2022-02-04 14:50 ` [PATCH bpf-next v3 06/11] selftests/bpf: Use PT_REGS_SYSCALL_REGS in bpf_syscall_macro Ilya Leoshkevich
2022-02-04 14:50 ` [PATCH bpf-next v3 07/11] libbpf: Fix accessing the first syscall argument on arm64 Ilya Leoshkevich
2022-02-04 14:50 ` [PATCH bpf-next v3 08/11] libbpf: Fix accessing syscall arguments on powerpc Ilya Leoshkevich
2022-02-05  7:05   ` Naveen N. Rao
2022-02-04 14:50 ` [PATCH bpf-next v3 09/11] libbpf: Fix accessing program counter on riscv Ilya Leoshkevich
2022-02-04 14:50 ` [PATCH bpf-next v3 10/11] libbpf: Fix accessing syscall arguments " Ilya Leoshkevich
2022-02-04 14:50 ` [PATCH bpf-next v3 11/11] libbpf: Fix accessing the first syscall argument on s390 Ilya Leoshkevich
2022-02-05 20:30 ` [PATCH bpf-next v3 00/11] libbpf: Fix accessing syscall arguments patchwork-bot+netdevbpf
2022-02-07 16:10   ` Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1643990954.fs9q9mrdxt.naveen@linux.ibm.com \
    --to=naveen.n.rao@linux.vnet.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=daniel@iogearbox.net \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=paul.walmsley@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.