All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Jean-Philippe Brucker <jean-philippe@linaro.org>,
	ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org
Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com,
	john.fastabend@gmail.com, kpsingh@kernel.org, dxu@dxuuu.xyz,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	shuah@kernel.org, Andrii Nakryiko <andrii.nakryiko@gmail.com>
Subject: Re: [PATCH bpf-next v2] selftests/bpf: Fix build of task_pt_regs test for arm64
Date: Tue, 07 Sep 2021 12:26:51 +0200	[thread overview]
Message-ID: <bdfabd343bdec7e27ff92bc0145d813011227f8f.camel@linux.ibm.com> (raw)
In-Reply-To: <20210906163635.302307-1-jean-philippe@linaro.org>

On Mon, 2021-09-06 at 17:36 +0100, Jean-Philippe Brucker wrote:
> struct pt_regs is not exported to userspace on all archs. arm64 and
> s390
> export "user_pt_regs" instead, which causes build failure at the
> moment:
> 
>   progs/test_task_pt_regs.c:8:16: error: variable has incomplete type
> 'struct pt_regs'
>   struct pt_regs current_regs = {};
> 
> Instead of using pt_regs from ptrace.h, use the larger kernel struct
> from vmlinux.h directly. Since the test runner task_pt_regs.c does not
> have access to the kernel struct definition, copy it into a char array.
> 
> Fixes: 576d47bb1a92 ("bpf: selftests: Add bpf_task_pt_regs() selftest")
> Suggested-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> ---
> v2: Work on struct pt_regs from vmlinux.h
> v1:
> https://lore.kernel.org/bpf/20210902090925.2010528-1-jean-philippe@linaro.org/
> ---
>  .../selftests/bpf/prog_tests/task_pt_regs.c   |  1 -
>  .../selftests/bpf/progs/test_task_pt_regs.c   | 19 +++++++++++++------
>  2 files changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/task_pt_regs.c
> b/tools/testing/selftests/bpf/prog_tests/task_pt_regs.c
> index 53f0e0fa1a53..37c20b5ffa70 100644
> --- a/tools/testing/selftests/bpf/prog_tests/task_pt_regs.c
> +++ b/tools/testing/selftests/bpf/prog_tests/task_pt_regs.c
> @@ -1,7 +1,6 @@
>  // SPDX-License-Identifier: GPL-2.0
>  #define _GNU_SOURCE
>  #include <test_progs.h>
> -#include <linux/ptrace.h>
>  #include "test_task_pt_regs.skel.h"
>  
>  void test_task_pt_regs(void)
> diff --git a/tools/testing/selftests/bpf/progs/test_task_pt_regs.c
> b/tools/testing/selftests/bpf/progs/test_task_pt_regs.c
> index 6c059f1cfa1b..e6cb09259408 100644
> --- a/tools/testing/selftests/bpf/progs/test_task_pt_regs.c
> +++ b/tools/testing/selftests/bpf/progs/test_task_pt_regs.c
> @@ -1,12 +1,17 @@
>  // SPDX-License-Identifier: GPL-2.0
>  
> -#include <linux/ptrace.h>
> -#include <linux/bpf.h>
> +#include "vmlinux.h"
>  #include <bpf/bpf_helpers.h>
>  #include <bpf/bpf_tracing.h>
>  
> -struct pt_regs current_regs = {};
> -struct pt_regs ctx_regs = {};
> +#define PT_REGS_SIZE sizeof(struct pt_regs)
> +
> +/*
> + * The kernel struct pt_regs isn't exported in its entirety to
> userspace.
> + * Pass it as an array to task_pt_regs.c
> + */
> +char current_regs[PT_REGS_SIZE] = {};
> +char ctx_regs[PT_REGS_SIZE] = {};
>  int uprobe_res = 0;
>  
>  SEC("uprobe/trigger_func")
> @@ -17,8 +22,10 @@ int handle_uprobe(struct pt_regs *ctx)
>  
>         current = bpf_get_current_task_btf();
>         regs = (struct pt_regs *) bpf_task_pt_regs(current);
> -       __builtin_memcpy(&current_regs, regs, sizeof(*regs));
> -       __builtin_memcpy(&ctx_regs, ctx, sizeof(*ctx));
> +       if (bpf_probe_read_kernel(current_regs, PT_REGS_SIZE, regs))
> +               return 0;
> +       if (bpf_probe_read_kernel(ctx_regs, PT_REGS_SIZE, ctx))
> +               return 0;
>  
>         /* Prove that uprobe was run */
>         uprobe_res = 1;

I've tested this patch on s390 and it does indeed fix the build issue.
Thanks!

Tested-by: Ilya Leoshkevich <iii@linux.ibm.com>
Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>


  reply	other threads:[~2021-09-07 10:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-06 16:36 [PATCH bpf-next v2] selftests/bpf: Fix build of task_pt_regs test for arm64 Jean-Philippe Brucker
2021-09-07 10:26 ` Ilya Leoshkevich [this message]
2021-09-07 15:30 ` patchwork-bot+netdevbpf

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=bdfabd343bdec7e27ff92bc0145d813011227f8f.camel@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dxu@dxuuu.xyz \
    --cc=jean-philippe@linaro.org \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.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.