Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7701C4332F for ; Tue, 21 Dec 2021 00:58:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233532AbhLUA6i (ORCPT ); Mon, 20 Dec 2021 19:58:38 -0500 Received: from szxga02-in.huawei.com ([45.249.212.188]:16840 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231254AbhLUA6h (ORCPT ); Mon, 20 Dec 2021 19:58:37 -0500 Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4JHyjj34Gbz91r0; Tue, 21 Dec 2021 08:57:45 +0800 (CST) Received: from dggpemm500019.china.huawei.com (7.185.36.180) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Tue, 21 Dec 2021 08:58:34 +0800 Received: from [10.67.109.184] (10.67.109.184) by dggpemm500019.china.huawei.com (7.185.36.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Tue, 21 Dec 2021 08:58:34 +0800 Subject: Re: [PATCH bpf-next] selftests/bpf: Fix building error when using userspace pt_regs From: Pu Lehui To: Andrii Nakryiko CC: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin Lau , Song Liu , Yonghong Song , john fastabend , KP Singh , Paul Walmsley , Palmer Dabbelt , Albert Ou , Shuah Khan , "open list:KERNEL SELFTEST FRAMEWORK" , Networking , bpf , open list References: <20211214135555.125348-1-pulehui@huawei.com> <50d81d9c-2b5f-9dfd-a284-9778e6273725@huawei.com> Message-ID: <88aa98df-b566-d031-b9f9-2b88a437a810@huawei.com> Date: Tue, 21 Dec 2021 08:58:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <50d81d9c-2b5f-9dfd-a284-9778e6273725@huawei.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.109.184] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500019.china.huawei.com (7.185.36.180) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/12/20 22:02, Pu Lehui wrote: > > > On 2021/12/18 0:45, Andrii Nakryiko wrote: >> On Thu, Dec 16, 2021 at 6:25 PM Pu Lehui wrote: >>> >>> >>> >>> On 2021/12/16 12:06, Andrii Nakryiko wrote: >>>> On Tue, Dec 14, 2021 at 5:54 AM Pu Lehui wrote: >>>>> >>>>> When building bpf selftests on arm64, the following error will 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, which causes build failure when bpf prog use >>>>> macro in bpf_tracing.h. So let's use vmlinux.h directly. >>>> >>>> We could probably also extend bpf_tracing.h to work with >>>> kernel-defined pt_regs, just like we do for x86 (see __KERNEL__ and >>>> __VMLINUX_H__ checks). It's more work, but will benefit other end >>>> users, not just selftests. >>>> >>> It might change a lot. We can use header file directory generated by >>> "make headers_install" to fix it. >> >> We don't have dependency on "make headers_install" and I'd rather not >> add it. >> >> What do you mean by "change a lot"? >> > Maybe I misunderstood your advice. Your suggestion might be to extend > bpf_tracing.h to kernel-space pt_regs, while some archs, like arm64, > only support user-space. So the patch might be like this: > > diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h > index db05a5937105..2c3cb8e9ae92 100644 > --- a/tools/lib/bpf/bpf_tracing.h > +++ b/tools/lib/bpf/bpf_tracing.h > @@ -195,9 +195,13 @@ struct pt_regs; > >  #elif defined(bpf_target_arm64) > > -struct pt_regs; > +#if defined(__KERNEL__) > +#define PT_REGS_ARM64 const volatile struct pt_regs > +#else >  /* arm64 provides struct user_pt_regs instead of struct pt_regs to > userspace */ >  #define PT_REGS_ARM64 const volatile struct user_pt_regs > +#endif > + >  #define PT_REGS_PARM1(x) (((PT_REGS_ARM64 *)(x))->regs[0]) >  #define PT_REGS_PARM2(x) (((PT_REGS_ARM64 *)(x))->regs[1]) >  #define PT_REGS_PARM3(x) (((PT_REGS_ARM64 *)(x))->regs[2]) > Please ignore the last reply. User-space pt_regs of arm64/s390 is the first part of the kernel-space's, it should has covered both kernel and userspace. >>> >>> --- a/tools/testing/selftests/bpf/Makefile >>> +++ b/tools/testing/selftests/bpf/Makefile >>> @@ -294,7 +294,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../../../../usr/include >>>>> >>>>> Signed-off-by: Pu Lehui >>>>> --- >>>>>    tools/testing/selftests/bpf/progs/loop1.c     |  8 ++------ >>>>>    tools/testing/selftests/bpf/progs/loop2.c     |  8 ++------ >>>>>    tools/testing/selftests/bpf/progs/loop3.c     |  8 ++------ >>>>>    tools/testing/selftests/bpf/progs/loop6.c     | 20 >>>>> ++++++------------- >>>>>    .../selftests/bpf/progs/test_overhead.c       |  8 ++------ >>>>>    .../selftests/bpf/progs/test_probe_user.c     |  6 +----- >>>>>    6 files changed, 15 insertions(+), 43 deletions(-) >>>>> >>>> >>>> [...] >>>> . >>>> >> . >> > .