diff mbox series

[bpf-next,v2] selftests/bpf: Fix cross compiling error when using userspace pt_regs

Message ID 20211223052007.4111674-1-pulehui@huawei.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf-next,v2] selftests/bpf: Fix cross compiling error when using userspace pt_regs | expand

Checks

Context Check Description
bpf/vmtest-bpf-next fail VM_Test
bpf/vmtest-bpf-next-PR fail PR summary
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 9 maintainers not CCed: ndesaulniers@google.com llvm@lists.linux.dev paul.walmsley@sifive.com kpsingh@kernel.org palmer@dabbelt.com nathan@kernel.org linux-riscv@lists.infradead.org aou@eecs.berkeley.edu shuah@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Pu Lehui Dec. 23, 2021, 5:20 a.m. UTC
When cross compiling arm64 bpf selftests in x86_64 host, the following
error occur:

progs/loop2.c:20:7: error: incomplete definition of type 'struct
user_pt_regs'

Some archs, like arm64 and riscv, use userspace pt_regs in bpf_tracing.h.
When arm64 bpf selftests cross compiling in x86_64 host, clang cannot
find the arch specific uapi ptrace.h. We can add arch specific header
file directory to fix this issue.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
v1->v2:
- use vmlinux.h directly might lead to verifier fail.
- use source arch header file directory suggested by Andrii Nakryiko.

 tools/testing/selftests/bpf/Makefile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Andrii Nakryiko Dec. 23, 2021, 6:21 p.m. UTC | #1
On Wed, Dec 22, 2021 at 8:56 PM Pu Lehui <pulehui@huawei.com> wrote:
>
> When cross compiling arm64 bpf selftests in x86_64 host, the following
> error occur:
>
> progs/loop2.c:20:7: error: incomplete definition of type 'struct
> user_pt_regs'
>
> Some archs, like arm64 and riscv, use userspace pt_regs in bpf_tracing.h.
> When arm64 bpf selftests cross compiling in x86_64 host, clang cannot
> find the arch specific uapi ptrace.h. We can add arch specific header
> file directory to fix this issue.
>
> Signed-off-by: Pu Lehui <pulehui@huawei.com>
> ---
> v1->v2:
> - use vmlinux.h directly might lead to verifier fail.
> - use source arch header file directory suggested by Andrii Nakryiko.
>
>  tools/testing/selftests/bpf/Makefile | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index 42ffc24e9e71..1ecb6d192953 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -12,6 +12,7 @@ BPFDIR := $(LIBDIR)/bpf
>  TOOLSINCDIR := $(TOOLSDIR)/include
>  BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool
>  APIDIR := $(TOOLSINCDIR)/uapi
> +ARCH_APIDIR := $(abspath ../../../../arch/$(SRCARCH)/include/uapi)
>  GENDIR := $(abspath ../../../../include/generated)
>  GENHDR := $(GENDIR)/autoconf.h
>
> @@ -294,7 +295,8 @@ MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
>  CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
>  BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN)                  \
>              -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR)                   \
> -            -I$(abspath $(OUTPUT)/../usr/include)
> +            -I$(abspath $(OUTPUT)/../usr/include)                      \
> +            -I$(ARCH_APIDIR)
>

This causes compilation error, see [0]. I think we'll have to wait for
my patch ([1]) to land and then add kernel-side variants for accessing
pt_regs.

  [0] https://github.com/kernel-patches/bpf/runs/4614606900?check_suite_focus=true
  [1] https://patchwork.kernel.org/project/netdevbpf/patch/20211222213924.1869758-1-andrii@kernel.org/


>  CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
>                -Wno-compare-distinct-pointer-types
> --
> 2.25.1
>
Pu Lehui Dec. 24, 2021, 2:57 a.m. UTC | #2
On 2021/12/24 2:21, Andrii Nakryiko wrote:
> On Wed, Dec 22, 2021 at 8:56 PM Pu Lehui <pulehui@huawei.com> wrote:
>>
>> When cross compiling arm64 bpf selftests in x86_64 host, the following
>> error occur:
>>
>> progs/loop2.c:20:7: error: incomplete definition of type 'struct
>> user_pt_regs'
>>
>> Some archs, like arm64 and riscv, use userspace pt_regs in bpf_tracing.h.
>> When arm64 bpf selftests cross compiling in x86_64 host, clang cannot
>> find the arch specific uapi ptrace.h. We can add arch specific header
>> file directory to fix this issue.
>>
>> Signed-off-by: Pu Lehui <pulehui@huawei.com>
>> ---
>> v1->v2:
>> - use vmlinux.h directly might lead to verifier fail.
>> - use source arch header file directory suggested by Andrii Nakryiko.
>>
>>   tools/testing/selftests/bpf/Makefile | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
>> index 42ffc24e9e71..1ecb6d192953 100644
>> --- a/tools/testing/selftests/bpf/Makefile
>> +++ b/tools/testing/selftests/bpf/Makefile
>> @@ -12,6 +12,7 @@ BPFDIR := $(LIBDIR)/bpf
>>   TOOLSINCDIR := $(TOOLSDIR)/include
>>   BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool
>>   APIDIR := $(TOOLSINCDIR)/uapi
>> +ARCH_APIDIR := $(abspath ../../../../arch/$(SRCARCH)/include/uapi)
>>   GENDIR := $(abspath ../../../../include/generated)
>>   GENHDR := $(GENDIR)/autoconf.h
>>
>> @@ -294,7 +295,8 @@ MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
>>   CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
>>   BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN)                  \
>>               -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR)                   \
>> -            -I$(abspath $(OUTPUT)/../usr/include)
>> +            -I$(abspath $(OUTPUT)/../usr/include)                      \
>> +            -I$(ARCH_APIDIR)
>>
> 
> This causes compilation error, see [0]. I think we'll have to wait for
> my patch ([1]) to land and then add kernel-side variants for accessing
> pt_regs.
> 
>    [0] https://github.com/kernel-patches/bpf/runs/4614606900?check_suite_focus=true
>    [1] https://patchwork.kernel.org/project/netdevbpf/patch/20211222213924.1869758-1-andrii@kernel.org/
> 
> 
OK, I'll keep follow it.
>>   CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
>>                 -Wno-compare-distinct-pointer-types
>> --
>> 2.25.1
>>
> .
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 42ffc24e9e71..1ecb6d192953 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -12,6 +12,7 @@  BPFDIR := $(LIBDIR)/bpf
 TOOLSINCDIR := $(TOOLSDIR)/include
 BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool
 APIDIR := $(TOOLSINCDIR)/uapi
+ARCH_APIDIR := $(abspath ../../../../arch/$(SRCARCH)/include/uapi)
 GENDIR := $(abspath ../../../../include/generated)
 GENHDR := $(GENDIR)/autoconf.h
 
@@ -294,7 +295,8 @@  MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
 CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
 BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) 			\
 	     -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR)			\
-	     -I$(abspath $(OUTPUT)/../usr/include)
+	     -I$(abspath $(OUTPUT)/../usr/include)			\
+	     -I$(ARCH_APIDIR)
 
 CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
 	       -Wno-compare-distinct-pointer-types