Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp608657rdb; Tue, 23 Jan 2024 09:06:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGE+bT/9DTVswKeArdI2Uh96uOzHc9tHmlpoHa6c8E53t2ShygKWxFN79KNyE8f9qNM/sy9 X-Received: by 2002:a17:906:35db:b0:a28:bdbb:dca7 with SMTP id p27-20020a17090635db00b00a28bdbbdca7mr115505ejb.15.1706029580917; Tue, 23 Jan 2024 09:06:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706029580; cv=pass; d=google.com; s=arc-20160816; b=bmMuw9ISF2EDvHustcVwLsa5HpztgG+8DoX1bJzw52AbGMUv4Qn5WBXIJ5uNn8pO+7 Yzaex0e5ROCJdBlgbWCuoWmB8tEzFpkanujTppuH2OtMIa0CvY1MrQS3/zgSGTIcvpXR mfwOvl0Mz7ZQWFMn6UIGKg2ae/tB8c9uCw5X5KgncZdg92uiFQO7lmQ4+uTkrw0uRc9Y 0r7+IAGyzOx8JYPhyCt3BzSqXwad+6TSi+vaxB84HW2E9ui5/v9nBZAlIDARHc0F4OoJ iuBMm9VK2yEPz3+fbQmFecnQNqRuxlzSnXvMU3XEYnnM+vCOSy1N/WL9wJirFDRfHZmQ lqQQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=TJEXGqSDxZVVXZGm0PyWWhJuh0DDp8fcvHzsCgYuhd8=; fh=i2t4Sb1GRO14SyJTVefqTyUif9vFoNbaO4e8Hmm6C8I=; b=hqlKpMm+gfmYOpcASkEHXnqvmctGGP8zAXldrjuX57NOzaPZGFOHQaxpxbyUe7B/MB t9bggOEer36FZorTjtGUpzo4TrzxkdyeACrBjNSmxf99RKNgQVkocfg4psea9GV6qcFy pxfw0vfLgjei2OUtpVOuDtjZ4c/f14DJPaB5PZKbhhPMa81ZxRZigRCDhiFUGxHwI08S 9Hfa0KnjZsT/XRLHXdOBqSn3uLv/Kuaf4g9VBa2RLMUYe8NnQvA8jpoTcHaAKwUs38O8 yhzWYua/ET8L8ALjY9nrIhinOfLT9T+2WKiBLti8xnYS/MZIJhOPw8e/bbSCC6zJqUZZ VuSQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Zfhb0bcm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-35688-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35688-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id oz26-20020a170906cd1a00b00a28cdc12db6si11596752ejb.494.2024.01.23.09.06.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 09:06:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35688-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Zfhb0bcm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-35688-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35688-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DB4BD1F27261 for ; Tue, 23 Jan 2024 16:47:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 46CDA82D95; Tue, 23 Jan 2024 16:41:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Zfhb0bcm" 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 55E2F82D7C; Tue, 23 Jan 2024 16:41:03 +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=1706028063; cv=none; b=EnG0X/8qw6dLaRzL/zEjVQ2SrAT+5IM5VpJ2yu4AGUVHOsYf8ZeGXTHeon8wKnESOsDq7GZtoHg2J1cNZZelY0F/EsVTTniFjjcXsQKTOYy+cUNqt4xbR/E7lo0r+WK0SWsW0hga7S7q6vlvXAFsJ7OsKC7uP3J3vToVy3SPW/I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706028063; c=relaxed/simple; bh=k8S+SH5DCWnhTkXa53WVFA61i4bptiV+YN7U96SThXg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eteccKHG5XfjUJCNJJobhcZc3N12WkfgXZNMbY9yKBXpudJk5AVXGB8cIjsrAUkxQvulXYfmSGSBzMumqI5nt59Jh613f8MkJESbhvC2R+KHbVtlgtpDK+Lj4H8g3f1FU+XCsOwfSjJdOavpp+zX66dgjBmKf+6qiTS1iQLr+nY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Zfhb0bcm; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D597C43394; Tue, 23 Jan 2024 16:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706028062; bh=k8S+SH5DCWnhTkXa53WVFA61i4bptiV+YN7U96SThXg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Zfhb0bcmmpNNXl1tRUjGGrIxhWExV75hs6steNvB46IBMMwsJtf/0gv+gnLnMfAov eNSonxBFI7udiXbyi88HCdnylw06odPVuK01sIRFLtjRlyuLYI4Z215ghLpAti5zxR FhxAb6DekkMMfB+loBiaqPC0zA72IkRBy3t0nmOqz1lrzdl+7dgZ/o6Q8FreAW5Vuq Cw/2lIPsKyGZ64Bn0vFWNaPsstOfbjTNeyyDkCXrBPnATOhpfQIWQxiBDLJezVcXIO 5gJlqc6c/hJGwXMPfCX4cOqmx6pjf4ktY6wpfgJa0EoqFtmXhlFC0k8eckAKgmWQjZ 1yjGX+9jjm27w== From: Benjamin Tissoires Date: Tue, 23 Jan 2024 17:40:44 +0100 Subject: [PATCH 2/2] HID: bpf: use __bpf_kfunc instead of noinline Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240123-b4-hid-bpf-fixes-v1-2-aa1fac734377@kernel.org> References: <20240123-b4-hid-bpf-fixes-v1-0-aa1fac734377@kernel.org> In-Reply-To: <20240123-b4-hid-bpf-fixes-v1-0-aa1fac734377@kernel.org> To: Jiri Kosina , Benjamin Tissoires , Dan Carpenter , Daniel Borkmann Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706028056; l=4626; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=k8S+SH5DCWnhTkXa53WVFA61i4bptiV+YN7U96SThXg=; b=Inil0fQhKQFZtbu547ZVCCFw83S3vcuZ5g+odjPhLN7Fq//HjtK3YoCZ7xV6xbvHSaTQWy9wm 2navsiW7JaSAFcpU1GuMeRJEsJ2CYXKwNIBW4toGoRedOlB5xdtFvUM X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= Follow the docs at Documentation/bpf/kfuncs.rst: - declare the function with `__bpf_kfunc` - disables missing prototype warnings, which allows to remove them from include/linux/hid-bpf.h Removing the prototypes is not an issue because we currently have to redeclare them when writing the BPF program. They will eventually be generated by bpftool directly AFAIU. Signed-off-by: Benjamin Tissoires --- drivers/hid/bpf/hid_bpf_dispatch.c | 22 +++++++++++++++++----- include/linux/hid_bpf.h | 11 ----------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c index 5111d1fef0d3..119e4f03df55 100644 --- a/drivers/hid/bpf/hid_bpf_dispatch.c +++ b/drivers/hid/bpf/hid_bpf_dispatch.c @@ -143,6 +143,11 @@ u8 *call_hid_bpf_rdesc_fixup(struct hid_device *hdev, u8 *rdesc, unsigned int *s } EXPORT_SYMBOL_GPL(call_hid_bpf_rdesc_fixup); +/* Disables missing prototype warnings */ +__diag_push(); +__diag_ignore_all("-Wmissing-prototypes", + "Global kfuncs as their definitions will be in BTF"); + /** * hid_bpf_get_data - Get the kernel memory pointer associated with the context @ctx * @@ -152,7 +157,7 @@ EXPORT_SYMBOL_GPL(call_hid_bpf_rdesc_fixup); * * @returns %NULL on error, an %__u8 memory pointer on success */ -noinline __u8 * +__bpf_kfunc __u8 * hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, const size_t rdwr_buf_size) { struct hid_bpf_ctx_kern *ctx_kern; @@ -167,6 +172,7 @@ hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, const size_t rdwr return ctx_kern->data + offset; } +__diag_pop(); /* missing prototype warnings */ /* * The following set contains all functions we agree BPF programs @@ -274,6 +280,11 @@ static int do_hid_bpf_attach_prog(struct hid_device *hdev, int prog_fd, struct b return fd; } +/* Disables missing prototype warnings */ +__diag_push(); +__diag_ignore_all("-Wmissing-prototypes", + "Global kfuncs as their definitions will be in BTF"); + /** * hid_bpf_attach_prog - Attach the given @prog_fd to the given HID device * @@ -286,7 +297,7 @@ static int do_hid_bpf_attach_prog(struct hid_device *hdev, int prog_fd, struct b * is pinned to the BPF file system). */ /* called from syscall */ -noinline int +__bpf_kfunc int hid_bpf_attach_prog(unsigned int hid_id, int prog_fd, __u32 flags) { struct hid_device *hdev; @@ -328,7 +339,7 @@ hid_bpf_attach_prog(unsigned int hid_id, int prog_fd, __u32 flags) * * @returns A pointer to &struct hid_bpf_ctx on success, %NULL on error. */ -noinline struct hid_bpf_ctx * +__bpf_kfunc struct hid_bpf_ctx * hid_bpf_allocate_context(unsigned int hid_id) { struct hid_device *hdev; @@ -359,7 +370,7 @@ hid_bpf_allocate_context(unsigned int hid_id) * @ctx: the HID-BPF context to release * */ -noinline void +__bpf_kfunc void hid_bpf_release_context(struct hid_bpf_ctx *ctx) { struct hid_bpf_ctx_kern *ctx_kern; @@ -380,7 +391,7 @@ hid_bpf_release_context(struct hid_bpf_ctx *ctx) * * @returns %0 on success, a negative error code otherwise. */ -noinline int +__bpf_kfunc int hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz, enum hid_report_type rtype, enum hid_class_request reqtype) { @@ -448,6 +459,7 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz, kfree(dma_data); return ret; } +__diag_pop(); /* missing prototype warnings */ /* our HID-BPF entrypoints */ BTF_SET8_START(hid_bpf_fmodret_ids) diff --git a/include/linux/hid_bpf.h b/include/linux/hid_bpf.h index 840cd254172d..7118ac28d468 100644 --- a/include/linux/hid_bpf.h +++ b/include/linux/hid_bpf.h @@ -77,17 +77,6 @@ enum hid_bpf_attach_flags { int hid_bpf_device_event(struct hid_bpf_ctx *ctx); int hid_bpf_rdesc_fixup(struct hid_bpf_ctx *ctx); -/* Following functions are kfunc that we export to BPF programs */ -/* available everywhere in HID-BPF */ -__u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, const size_t __sz); - -/* only available in syscall */ -int hid_bpf_attach_prog(unsigned int hid_id, int prog_fd, __u32 flags); -int hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz, - enum hid_report_type rtype, enum hid_class_request reqtype); -struct hid_bpf_ctx *hid_bpf_allocate_context(unsigned int hid_id); -void hid_bpf_release_context(struct hid_bpf_ctx *ctx); - /* * Below is HID internal */ -- 2.43.0