From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 175048BF0; Sat, 17 Aug 2024 14:51:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723906268; cv=none; b=DInFCgbhtifXZtJ/D6qFnaySWK/1+U3GxTpIswbdEuCANkf4mmAEupu/sbQe73waCKPk5w3S49YCHxqTlXOMvtsa1NjuY5eZ0kx4bhYn5wyCee0H2q+JUGO0RVt82IVd1VDn1XSa12l82RxtkMoUF1pE3RlP4mGCgsgpG96PwZM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723906268; c=relaxed/simple; bh=xX30yY9QWtJC/hwv9MWYyIBUgw+j0dFH2V19RSTRVXQ=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=lQrLxYOgXVkgxN/qjGH3Rffg2/i1f6gIY/t1JRefaz7gXfBLWHKXFZH2B0Op5ooBfndXw+DsAMjf0jvh+bKDScIVeaiOGVUppuzOEyYAmv54WvBNKO6QB7dXgWca9VxONZEW5kby1fMJ1ArEIj/GcvZ0vds2fAYzJsgXkZ8LE/w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gRPV0IqE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gRPV0IqE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01618C116B1; Sat, 17 Aug 2024 14:51:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723906267; bh=xX30yY9QWtJC/hwv9MWYyIBUgw+j0dFH2V19RSTRVXQ=; h=Date:From:Subject:To:Cc:References:In-Reply-To:From; b=gRPV0IqEqa4Qs27n1S195VCMTcTx1mU2J1tALiRBfzU4kdk3zWYo1JaCTfgdRgSSM o2+48dM/thpP5UgxRqVkZH5v3b567X7G4cZMd3fu7mndSjkiCyBF/+RGuCrJmgnmSo QgyXSjP7Q/wb6YTPnU910/lfRtbwita8W6/AI9o2+9bHwEcSIdTyUYLNn2pmUqbG1b +3PQ0adzHY8YsjngYiqqdVEDTm0a9j5A/bBtkRW8GTIqA/0iBof6X/kcizhbqgSenw DKviEBhdKNcs2v0fFAI4e0hpMlY4hMbsEf5D3ZTfAv78W0yE7jqXqtu7p5/W+rKu3P RXQQU2qfA+Leg== Message-ID: <6a693ad6-f145-48c1-b3a7-d441d3764e73@kernel.org> Date: Sat, 17 Aug 2024 16:50:58 +0200 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta From: Matthieu Baerts Subject: Re: [PATCH bpf-next 1/2] selftests: bpf: use KHDR_INCLUDES for the UAPI headers To: Alexei Starovoitov Cc: MPTCP Upstream , Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , bpf , "open list:KERNEL SELFTEST FRAMEWORK" , LKML , Network Development References: <20240816-ups-bpf-next-selftests-use-khdr-v1-0-1e19f3d5b17a@kernel.org> <20240816-ups-bpf-next-selftests-use-khdr-v1-1-1e19f3d5b17a@kernel.org> Content-Language: en-GB Autocrypt: addr=matttbe@kernel.org; keydata= xsFNBFXj+ekBEADxVr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6AJCW9cKpC25+zxQqD2Zy0dK3u2RuKErajKBa/YWzuSaKAOkneFxG3LJIv Hl7iqPF+JDCjB5sAEQEAAcLBXwQYAQIACQUCVeP56QIbDAAKCRD2t4JPQmmgc5VnD/9YgbCr HR1FbMbm7td54UrYvZV/i7m3dIQNXK2e+Cbv5PXf19ce3XluaE+wA8D+vnIW5mbAAiojt3Mb 6p0WJS3QzbObzHNgAp3zy/L4lXwc6WW5vnpWAzqXFHP8D9PTpqvBALbXqL06smP47JqbyQxj Xf7D2rrPeIqbYmVY9da1KzMOVf3gReazYa89zZSdVkMojfWsbq05zwYU+SCWS3NiyF6QghbW voxbFwX1i/0xRwJiX9NNbRj1huVKQuS4W7rbWA87TrVQPXUAdkyd7FRYICNW+0gddysIwPoa KrLfx3Ba6Rpx0JznbrVOtXlihjl4KV8mtOPjYDY9u+8x412xXnlGl6AC4HLu2F3ECkamY4G6 UxejX+E6vW6Xe4n7H+rEX5UFgPRdYkS1TA/X3nMen9bouxNsvIJv7C6adZmMHqu/2azX7S7I vrxxySzOw9GxjoVTuzWMKWpDGP8n71IFeOot8JuPZtJ8omz+DZel+WCNZMVdVNLPOd5frqOv mpz0VhFAlNTjU1Vy0CnuxX3AM51J8dpdNyG0S8rADh6C8AKCDOfUstpq28/6oTaQv7QZdge0 JY6dglzGKnCi/zsmp2+1w559frz4+IC7j/igvJGX4KDDKUs0mlld8J2u2sBXv7CGxdzQoHaz lzVbFe7fduHbABmYz9cefQpO7wDE/Q== Organization: NGI0 Core In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi Alexei, Thank you for the review. On 17/08/2024 09:22, Alexei Starovoitov wrote: > On Fri, Aug 16, 2024 at 7:56 PM Matthieu Baerts (NGI0) > wrote: >> >> Instead of duplicating UAPI header files in 'tools/include/uapi', the >> BPF selftests can also look at the header files inside the kernel >> source. >> >> To do that, the kernel selftests infrastructure provides the >> 'KHDR_INCLUDES' variable. This is what is being used in most selftests, >> because it is what is recommended in the documentation [1]. If the >> selftests are not executed from the kernel sources, it is possible to >> override the variable, e.g. >> >> make KHDR_INCLUDES="-I${HDR_DIR}/include" -C "${KSFT_DIR}" >> >> ... where ${HDR_DIR} has been generated by this command: >> >> make headers_install INSTALL_HDR_PATH="${HDR_DIR}" >> >> Thanks to 'KHDR_INCLUDES', it is no longer needed to duplicate header >> files for userspace test programs, and these programs can include UAPI >> header files without the 'uapi' prefix. >> >> Note that it is still required to use 'tools/include/uapi' -- APIDIR, >> which corresponds to TOOLS_INCLUDES from lib.mk -- for the BPF programs, >> not to conflict with what is already defined in vmlinux.h. >> >> Link: https://docs.kernel.org/dev-tools/kselftest.html#contributing-new-tests-details [1] >> Signed-off-by: Matthieu Baerts (NGI0) >> --- >> tools/testing/selftests/bpf/Makefile | 2 +- >> tools/testing/selftests/bpf/prog_tests/assign_reuse.c | 2 +- >> tools/testing/selftests/bpf/prog_tests/tc_links.c | 4 ++-- >> tools/testing/selftests/bpf/prog_tests/tc_netkit.c | 2 +- >> tools/testing/selftests/bpf/prog_tests/tc_opts.c | 2 +- >> tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 2 +- >> tools/testing/selftests/bpf/prog_tests/xdp_bonding.c | 2 +- >> tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c | 2 +- >> tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c | 2 +- >> tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c | 2 +- >> tools/testing/selftests/bpf/prog_tests/xdp_link.c | 2 +- >> tools/testing/selftests/bpf/xdp_features.c | 4 ++-- >> 12 files changed, 14 insertions(+), 14 deletions(-) >> >> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile >> index 4eceb491a8ae..6a7aeae7e206 100644 >> --- a/tools/testing/selftests/bpf/Makefile >> +++ b/tools/testing/selftests/bpf/Makefile >> @@ -37,7 +37,7 @@ CFLAGS += -g $(OPT_FLAGS) -rdynamic \ >> -Wall -Werror -fno-omit-frame-pointer \ >> $(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS) \ >> -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \ >> - -I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUTPUT) >> + -I$(TOOLSINCDIR) $(KHDR_INCLUDES) -I$(OUTPUT) >> LDFLAGS += $(SAN_LDFLAGS) >> LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread >> >> diff --git a/tools/testing/selftests/bpf/prog_tests/assign_reuse.c b/tools/testing/selftests/bpf/prog_tests/assign_reuse.c >> index 989ee4d9785b..3d06bf5a1ba4 100644 >> --- a/tools/testing/selftests/bpf/prog_tests/assign_reuse.c >> +++ b/tools/testing/selftests/bpf/prog_tests/assign_reuse.c >> @@ -1,6 +1,6 @@ >> // SPDX-License-Identifier: GPL-2.0 >> /* Copyright (c) 2023 Isovalent */ >> -#include >> +#include > > No. This is not an option. > User space shouldn't include kernel headers like this. > Long ago tools/include directory was specifically > created to break such dependency. > Back then it was done for perf. I'm sorry, but I think we are not talking about the same thing here: here, I'm only modifying the "normal" userspace programs, not the ones used to generate the BPF objects. Perf is a special case I suppose, it needs to know the kernel internals. It is the same with BPF programs requiring vmlinux.h. But I think "normal" userspace programs in the sefltests can use the UAPI headers, no? Here, the BPF userspace programs will take the kernel headers generated by 'make headers', not directly from 'include/uapi' in the source. That's what is done in other kernel selftests, and what is documented in the kselftests doc [1]. With this modification, I'm able to compile the BPF selftests. I see that the BPF CI didn't manage to build them, but I think that's because it sets 'KBUILD_OUTPUT', and build the BPF selftests directly, not via the 'tools/testing/selftests/Makefile', which is the recommended way, which supports 'KBUILD_OUTPUT'. Please see [2] for a fix for the BPF CI. A bit of context: my goal here is to be able to add new BPF selftests to cover cases where BPF is used to modify MPTCP sockets and subflows. To setup these tests, we need to communicate with the kernel, either by using IPRoute2 -- but the BPF CI is still using IPRoute2 5.5 from pre-COVID time -- or with a dedicated userspace program. This program [2] has nothing special, it needs to include to get the value of some defines and enums to be able to communicate with the kernel via Netlink. If I want to compile this program on my system, outside the kselftest, the compiler will use the file from '/usr/include/linux/mptcp.h', coming from the kernel UAPI. When validating new features in the selftests, it will use the version from the kernel source, the result of a 'make headers'. That works fine, we don't have to duplicate the MPTCP UAPI header file when building the MPTCP selftests. Same with the other selftests. Without this patch, I would need to duplicate the 'mptcp.h' header if I want to use the same program in the BPF selftests, because KHDR_INCLUDES is not used in the CFLAGS when compiling the userspace programs like everywhere else in the selftests. I understand that I could indeed fix my initial problem by duplicating mptcp.h in tools/include/uapi/linux/, but this doesn't look to be allowed any more by the Netdev maintainers, e.g. recently, 'ethtool.h' has been duplicated there in commit 7effe3fdc049 ("tools: Add ethtool.h header to tooling infra"), but removed quickly after in commit bbe91a9f6889 ("tools: remove redundant ethtool.h from tooling infra"). In this case, it was fine to simply drop it, because the linked test doesn't require a recent version. Jakub mentioned [4] that these duplicated headers should be avoided, and the ones generated by 'make headers' should be used instead: what is being suggested here. Do you think it would not work? If not, any idea what I can do? Duplicating the defines and enums I need in the .c file doesn't seem like a nice solution either. [1] https://docs.kernel.org/dev-tools/kselftest.html [2] https://github.com/libbpf/ci/pull/131 [3] https://elixir.bootlin.com/linux/v6.10.5/source/tools/testing/selftests/net/mptcp/pm_nl_ctl.c [4] https://lore.kernel.org/netdev/20240429132207.58ecf430@kernel.org/T/#u Cheers, Matt -- Sponsored by the NGI0 Core fund.