From patchwork Thu Oct 5 15:55:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 13410360 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 1E994E772A5 for ; Thu, 5 Oct 2023 16:11:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240660AbjJEQKr (ORCPT ); Thu, 5 Oct 2023 12:10:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238017AbjJEQJu (ORCPT ); Thu, 5 Oct 2023 12:09:50 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BCBEB2A7; Thu, 5 Oct 2023 08:55:57 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4099C433CD; Thu, 5 Oct 2023 15:55:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696521356; bh=Bys1WVOEmDbhQYrXkqjsHDKHnLJh8N2r8hiIygj+vZk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VNbm8RBF3c0TqiaXfPc8LeNS/yAMhTg3vGsxI/kgPjQWTDTS2MkL8a406qeiqXgAc LUfd2xVr0p4lf+LVIAs9w95jovFNwY6uZGLABjCUItlRw9jJUNUZwQBYszCHZTfnDd UAOo4M59IRwGDgOptxpK1icCLKXrQCMZ85mGAwi/+3LTrNFAfhJW1DKmEFau0FNY6m /NNbRIz7vzpFqbuMgRfmlXubpLoA14MKVdlqR8P2rsJe2T1ntT8OStCN1YGONBRL6I oY+hMsJgs2dkdLG+BcppQRFNLgJcIIXaxV7fQ1UOJEf6ArhbyMXQnMrwaBCRkoJd2r BiBi1LhfHRq4A== From: Benjamin Tissoires Date: Thu, 05 Oct 2023 17:55:32 +0200 Subject: [PATCH v3 1/3] selftests/hid: ensure we can compile the tests on kernels pre-6.3 MIME-Version: 1.0 Message-Id: <20230825-wip-selftests-v3-1-639963c54109@kernel.org> References: <20230825-wip-selftests-v3-0-639963c54109@kernel.org> In-Reply-To: <20230825-wip-selftests-v3-0-639963c54109@kernel.org> To: Jiri Kosina , Benjamin Tissoires , Shuah Khan , Justin Stitt , Nick Desaulniers , Eduard Zingerman Cc: linux-input@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1696521351; l=4601; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=Bys1WVOEmDbhQYrXkqjsHDKHnLJh8N2r8hiIygj+vZk=; b=A3WDQOElTVS7RO+kzoxx9v3yEz4D62ho7M/szwJvz4Qu8mi9GzdHe66ADW1uECvTlOIKiGNYi bVyoxabpFlrBUNu92TtLm38lVWnrnYiZvQRziVxkls6nhn2lVIiUf/e X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org For the hid-bpf tests to compile, we need to have the definition of struct hid_bpf_ctx. This definition is an internal one from the kernel and it is supposed to be defined in the generated vmlinux.h. This vmlinux.h header is generated based on the currently running kernel or if the kernel was already compiled in the tree. If you just compile the selftests without compiling the kernel beforehand and you are running on a 6.2 kernel, you'll end up with a vmlinux.h without the hid_bpf_ctx definition. Use the clever trick from tools/testing/selftests/bpf/progs/bpf_iter.h to force the definition of that symbol in case we don't find it in the BTF and also add __attribute__((preserve_access_index)) to further support CO-RE functionality for these tests. Signed-off-by: Justin Stitt Tested-by: Nick Desaulniers # Build Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/progs/hid.c | 3 - .../testing/selftests/hid/progs/hid_bpf_helpers.h | 77 ++++++++++++++++++++++ 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/hid/progs/hid.c b/tools/testing/selftests/hid/progs/hid.c index 88c593f753b5..1e558826b809 100644 --- a/tools/testing/selftests/hid/progs/hid.c +++ b/tools/testing/selftests/hid/progs/hid.c @@ -1,8 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2022 Red hat */ -#include "vmlinux.h" -#include -#include #include "hid_bpf_helpers.h" char _license[] SEC("license") = "GPL"; diff --git a/tools/testing/selftests/hid/progs/hid_bpf_helpers.h b/tools/testing/selftests/hid/progs/hid_bpf_helpers.h index 4fff31dbe0e7..65e657ac1198 100644 --- a/tools/testing/selftests/hid/progs/hid_bpf_helpers.h +++ b/tools/testing/selftests/hid/progs/hid_bpf_helpers.h @@ -5,6 +5,83 @@ #ifndef __HID_BPF_HELPERS_H #define __HID_BPF_HELPERS_H +/* "undefine" structs and enums in vmlinux.h, because we "override" them below */ +#define hid_bpf_ctx hid_bpf_ctx___not_used +#define hid_report_type hid_report_type___not_used +#define hid_class_request hid_class_request___not_used +#define hid_bpf_attach_flags hid_bpf_attach_flags___not_used +#define HID_INPUT_REPORT HID_INPUT_REPORT___not_used +#define HID_OUTPUT_REPORT HID_OUTPUT_REPORT___not_used +#define HID_FEATURE_REPORT HID_FEATURE_REPORT___not_used +#define HID_REPORT_TYPES HID_REPORT_TYPES___not_used +#define HID_REQ_GET_REPORT HID_REQ_GET_REPORT___not_used +#define HID_REQ_GET_IDLE HID_REQ_GET_IDLE___not_used +#define HID_REQ_GET_PROTOCOL HID_REQ_GET_PROTOCOL___not_used +#define HID_REQ_SET_REPORT HID_REQ_SET_REPORT___not_used +#define HID_REQ_SET_IDLE HID_REQ_SET_IDLE___not_used +#define HID_REQ_SET_PROTOCOL HID_REQ_SET_PROTOCOL___not_used +#define HID_BPF_FLAG_NONE HID_BPF_FLAG_NONE___not_used +#define HID_BPF_FLAG_INSERT_HEAD HID_BPF_FLAG_INSERT_HEAD___not_used +#define HID_BPF_FLAG_MAX HID_BPF_FLAG_MAX___not_used + +#include "vmlinux.h" + +#undef hid_bpf_ctx +#undef hid_report_type +#undef hid_class_request +#undef hid_bpf_attach_flags +#undef HID_INPUT_REPORT +#undef HID_OUTPUT_REPORT +#undef HID_FEATURE_REPORT +#undef HID_REPORT_TYPES +#undef HID_REQ_GET_REPORT +#undef HID_REQ_GET_IDLE +#undef HID_REQ_GET_PROTOCOL +#undef HID_REQ_SET_REPORT +#undef HID_REQ_SET_IDLE +#undef HID_REQ_SET_PROTOCOL +#undef HID_BPF_FLAG_NONE +#undef HID_BPF_FLAG_INSERT_HEAD +#undef HID_BPF_FLAG_MAX + +#include +#include +#include + +enum hid_report_type { + HID_INPUT_REPORT = 0, + HID_OUTPUT_REPORT = 1, + HID_FEATURE_REPORT = 2, + + HID_REPORT_TYPES, +}; + +struct hid_bpf_ctx { + __u32 index; + const struct hid_device *hid; + __u32 allocated_size; + enum hid_report_type report_type; + union { + __s32 retval; + __s32 size; + }; +} __attribute__((preserve_access_index)); + +enum hid_class_request { + HID_REQ_GET_REPORT = 0x01, + HID_REQ_GET_IDLE = 0x02, + HID_REQ_GET_PROTOCOL = 0x03, + HID_REQ_SET_REPORT = 0x09, + HID_REQ_SET_IDLE = 0x0A, + HID_REQ_SET_PROTOCOL = 0x0B, +}; + +enum hid_bpf_attach_flags { + HID_BPF_FLAG_NONE = 0, + HID_BPF_FLAG_INSERT_HEAD = _BITUL(0), + HID_BPF_FLAG_MAX, +}; + /* following are kfuncs exported by HID for HID-BPF */ extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, From patchwork Thu Oct 5 15:55:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 13410361 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 75022E772AA for ; Thu, 5 Oct 2023 16:11:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240689AbjJEQKr (ORCPT ); Thu, 5 Oct 2023 12:10:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238453AbjJEQJ7 (ORCPT ); Thu, 5 Oct 2023 12:09:59 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D696E7D00D; Thu, 5 Oct 2023 08:55:59 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47217C433C9; Thu, 5 Oct 2023 15:55:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696521359; bh=kepJfzWT2D89KAm/FDIV534BRNofr3W/Lz1wk8g0krs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HnUuOuzjNB341ryqf37ET9waEJFD4OEbRSkt58uo71aNC1WoiXy7is9q72cbwS5Tz SZ50W1L08BUJ/edZCoLF4UOwRx5Zt4xWotbQFJLxP1OGqC4JarwYi55Masjfbefb9S GFifXWrWEAbpbck2iBnj+P8lemYql/QHhfmW+e6kbdexb7e+kIYqssod9ufTTTyYgB fPPQ5loVxqlSCW+B90qS4C4AloshshD19pkhMoAfXCSK8WeerCkE7xC4EIXInN5Go/ V56k38HZ4JkB8TiRhS4DB8U7Qv2yeM1FSksk3hrmKnU/OFivm3JN/b4E9BKV+HXrgI 9YU2jeRNrTCTw== From: Benjamin Tissoires Date: Thu, 05 Oct 2023 17:55:33 +0200 Subject: [PATCH v3 2/3] selftests/hid: do not manually call headers_install MIME-Version: 1.0 Message-Id: <20230825-wip-selftests-v3-2-639963c54109@kernel.org> References: <20230825-wip-selftests-v3-0-639963c54109@kernel.org> In-Reply-To: <20230825-wip-selftests-v3-0-639963c54109@kernel.org> To: Jiri Kosina , Benjamin Tissoires , Shuah Khan , Justin Stitt , Nick Desaulniers , Eduard Zingerman Cc: linux-input@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Benjamin Tissoires , Shuah Khan X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1696521351; l=2048; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=kepJfzWT2D89KAm/FDIV534BRNofr3W/Lz1wk8g0krs=; b=3Bfa0moweoyJ3qG17TuFnAal4lGdBVWJl4DArxBAd0uyM+iv6oT+49A+bz0vOaTutlhSNd3ej 5Mr7rMhGV02Dli/kpbWgaihnS3rKk5PHBj1kPouo4ijqH4KRYe3sW2N X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org "make headers" is a requirement before calling make on the selftests dir, so we should not have to manually install those headers Acked-by: Shuah Khan Tested-by: Nick Desaulniers # Build Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/Makefile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/hid/Makefile b/tools/testing/selftests/hid/Makefile index 2e986cbf1a46..a28054113f47 100644 --- a/tools/testing/selftests/hid/Makefile +++ b/tools/testing/selftests/hid/Makefile @@ -21,7 +21,7 @@ CXX ?= $(CROSS_COMPILE)g++ HOSTPKG_CONFIG := pkg-config -CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(KHDR_INCLUDES) -I$(OUTPUT) +CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(OUTPUT) LDLIBS += -lelf -lz -lrt -lpthread # Silence some warnings when compiled with clang @@ -65,7 +65,6 @@ BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool SCRATCH_DIR := $(OUTPUT)/tools BUILD_DIR := $(SCRATCH_DIR)/build INCLUDE_DIR := $(SCRATCH_DIR)/include -KHDR_INCLUDES := $(SCRATCH_DIR)/uapi/include BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a ifneq ($(CROSS_COMPILE),) HOST_BUILD_DIR := $(BUILD_DIR)/host @@ -151,9 +150,6 @@ else $(Q)cp "$(VMLINUX_H)" $@ endif -$(KHDR_INCLUDES)/linux/hid.h: $(top_srcdir)/include/uapi/linux/hid.h - $(MAKE) -C $(top_srcdir) INSTALL_HDR_PATH=$(SCRATCH_DIR)/uapi headers_install - $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \ $(TOOLSDIR)/bpf/resolve_btfids/main.c \ $(TOOLSDIR)/lib/rbtree.c \ @@ -231,7 +227,7 @@ $(BPF_SKELS): %.skel.h: %.bpf.o $(BPFTOOL) | $(OUTPUT) $(Q)$(BPFTOOL) gen object $(<:.o=.linked1.o) $< $(Q)$(BPFTOOL) gen skeleton $(<:.o=.linked1.o) name $(notdir $(<:.bpf.o=)) > $@ -$(OUTPUT)/%.o: %.c $(BPF_SKELS) $(KHDR_INCLUDES)/linux/hid.h +$(OUTPUT)/%.o: %.c $(BPF_SKELS) $(call msg,CC,,$@) $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@ From patchwork Thu Oct 5 15:55:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 13410362 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 C10A2E772AE for ; Thu, 5 Oct 2023 16:11:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237635AbjJEQKs (ORCPT ); Thu, 5 Oct 2023 12:10:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238367AbjJEQJ7 (ORCPT ); Thu, 5 Oct 2023 12:09:59 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DBD57D015; Thu, 5 Oct 2023 08:56:02 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E13C4C433CC; Thu, 5 Oct 2023 15:55:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696521361; bh=3yQpTAu+sxNfHSN9OgsgXUOtauvkvvEyt8XXZhf2+8Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QeBzDi88VBkjZ7kWlDKDGeGHaEjWV1lZkkcsCVKn4dR86Bo+SCfF6chKzIqn7DKRV b9XYa8UC0xp3HXw60hOVdxCN9bKqUQXNtk/wRMsmTZRefN+Ihl7uysL6Qx7y/ayFzM bizhHSa5OfWRTiQ0koQ/OXHjiaKnWcnqDE0HD3NlKKugmCfC5EObuOsgWNih/ajW+Y j0R+Shhw8tStRzMawg2I592r9SBWd8Ifps/l96BWPUWD4Hg0nSiPODvTbDGXAbcKjJ r4yUriACcMWAhvsep2awIgcHgRqFi0FOmJSCOADOjZbLgh1cIdRoTTV35Q0Dy09HP1 oZK9daysQ5s1A== From: Benjamin Tissoires Date: Thu, 05 Oct 2023 17:55:34 +0200 Subject: [PATCH v3 3/3] selftests/hid: force using our compiled libbpf headers MIME-Version: 1.0 Message-Id: <20230825-wip-selftests-v3-3-639963c54109@kernel.org> References: <20230825-wip-selftests-v3-0-639963c54109@kernel.org> In-Reply-To: <20230825-wip-selftests-v3-0-639963c54109@kernel.org> To: Jiri Kosina , Benjamin Tissoires , Shuah Khan , Justin Stitt , Nick Desaulniers , Eduard Zingerman Cc: linux-input@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1696521351; l=861; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=3yQpTAu+sxNfHSN9OgsgXUOtauvkvvEyt8XXZhf2+8Q=; b=eIdtTxiPAfLwDHc48vMYIjkvNAImwnjNSqDn15AmjAiyy7B9UA+gvMuOv21ud5O/eowiKvU08 bAxL8sik++/B3aUqy31juWFTeDemZbh3/XHcdEvYyoq7jXXpJ20+jXq X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Turns out that we were relying on the globally installed headers, not the ones we freshly compiled. Add a manual include in CFLAGS to sort this out. Tested-by: Nick Desaulniers # Build Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/hid/Makefile b/tools/testing/selftests/hid/Makefile index a28054113f47..2b5ea18bde38 100644 --- a/tools/testing/selftests/hid/Makefile +++ b/tools/testing/selftests/hid/Makefile @@ -22,6 +22,8 @@ CXX ?= $(CROSS_COMPILE)g++ HOSTPKG_CONFIG := pkg-config CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(OUTPUT) +CFLAGS += -I$(OUTPUT)/tools/include + LDLIBS += -lelf -lz -lrt -lpthread # Silence some warnings when compiled with clang