diff mbox series

[bpf-next,2/3] samples/bpf: Fix test_map_in_map on s390

Message ID 20200728120059.132256-3-iii@linux.ibm.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series samples/bpf: A couple s390 fixes | expand

Commit Message

Ilya Leoshkevich July 28, 2020, noon UTC
s390 uses socketcall multiplexer instead of individual socket syscalls.
Therefore, "kprobe/" SYSCALL(sys_connect) does not trigger and
test_map_in_map fails. Fix by using "kprobe/__sys_connect" instead.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 samples/bpf/test_map_in_map_kern.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Song Liu July 28, 2020, 8:59 p.m. UTC | #1
On Tue, Jul 28, 2020 at 5:14 AM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>
> s390 uses socketcall multiplexer instead of individual socket syscalls.
> Therefore, "kprobe/" SYSCALL(sys_connect) does not trigger and
> test_map_in_map fails. Fix by using "kprobe/__sys_connect" instead.

samples/bpf is in semi-deprecated state. I tried for quite some time, but still
cannot build it all successfully. So I apologize for bounding the
question to you...

From the code, we do the SYSCALL() trick to change the exact name for
different architecture. Would this change break the same file for x86?

Thanks,
Song

>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  samples/bpf/test_map_in_map_kern.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/samples/bpf/test_map_in_map_kern.c b/samples/bpf/test_map_in_map_kern.c
> index 8def45c5b697..b0200c8eac09 100644
> --- a/samples/bpf/test_map_in_map_kern.c
> +++ b/samples/bpf/test_map_in_map_kern.c
> @@ -103,10 +103,9 @@ static __always_inline int do_inline_hash_lookup(void *inner_map, u32 port)
>         return result ? *result : -ENOENT;
>  }
>
> -SEC("kprobe/" SYSCALL(sys_connect))
> +SEC("kprobe/__sys_connect")
>  int trace_sys_connect(struct pt_regs *ctx)
>  {
> -       struct pt_regs *real_regs = (struct pt_regs *)PT_REGS_PARM1_CORE(ctx);
>         struct sockaddr_in6 *in6;
>         u16 test_case, port, dst6[8];
>         int addrlen, ret, inline_ret, ret_key = 0;
> @@ -114,8 +113,8 @@ int trace_sys_connect(struct pt_regs *ctx)
>         void *outer_map, *inner_map;
>         bool inline_hash = false;
>
> -       in6 = (struct sockaddr_in6 *)PT_REGS_PARM2_CORE(real_regs);
> -       addrlen = (int)PT_REGS_PARM3_CORE(real_regs);
> +       in6 = (struct sockaddr_in6 *)PT_REGS_PARM2_CORE(ctx);
> +       addrlen = (int)PT_REGS_PARM3_CORE(ctx);
>
>         if (addrlen != sizeof(*in6))
>                 return 0;
> --
> 2.25.4
>
Ilya Leoshkevich July 28, 2020, 10:05 p.m. UTC | #2
On Tue, 2020-07-28 at 13:59 -0700, Song Liu wrote:
> On Tue, Jul 28, 2020 at 5:14 AM Ilya Leoshkevich <iii@linux.ibm.com>
> wrote:
> > s390 uses socketcall multiplexer instead of individual socket
> > syscalls.
> > Therefore, "kprobe/" SYSCALL(sys_connect) does not trigger and
> > test_map_in_map fails. Fix by using "kprobe/__sys_connect" instead.
> 
> samples/bpf is in semi-deprecated state. I tried for quite some time,
> but still
> cannot build it all successfully. So I apologize for bounding the
> question to you...
> 
> From the code, we do the SYSCALL() trick to change the exact name for
> different architecture. Would this change break the same file for
> x86?

No, it shouldn't - __sys_connect exists on all architectures and gets
control from both regular socket syscalls and socketcall multiplexer.
I tested it on x86 and it worked for me.
It's also already used by
tools/testing/selftests/bpf/progs/test_probe_user.c

Best regards,
Ilya
diff mbox series

Patch

diff --git a/samples/bpf/test_map_in_map_kern.c b/samples/bpf/test_map_in_map_kern.c
index 8def45c5b697..b0200c8eac09 100644
--- a/samples/bpf/test_map_in_map_kern.c
+++ b/samples/bpf/test_map_in_map_kern.c
@@ -103,10 +103,9 @@  static __always_inline int do_inline_hash_lookup(void *inner_map, u32 port)
 	return result ? *result : -ENOENT;
 }
 
-SEC("kprobe/" SYSCALL(sys_connect))
+SEC("kprobe/__sys_connect")
 int trace_sys_connect(struct pt_regs *ctx)
 {
-	struct pt_regs *real_regs = (struct pt_regs *)PT_REGS_PARM1_CORE(ctx);
 	struct sockaddr_in6 *in6;
 	u16 test_case, port, dst6[8];
 	int addrlen, ret, inline_ret, ret_key = 0;
@@ -114,8 +113,8 @@  int trace_sys_connect(struct pt_regs *ctx)
 	void *outer_map, *inner_map;
 	bool inline_hash = false;
 
-	in6 = (struct sockaddr_in6 *)PT_REGS_PARM2_CORE(real_regs);
-	addrlen = (int)PT_REGS_PARM3_CORE(real_regs);
+	in6 = (struct sockaddr_in6 *)PT_REGS_PARM2_CORE(ctx);
+	addrlen = (int)PT_REGS_PARM3_CORE(ctx);
 
 	if (addrlen != sizeof(*in6))
 		return 0;