From patchwork Wed Jan 24 11:26:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 191499 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp922424dyi; Wed, 24 Jan 2024 03:28:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoRCg0OQZUvQ+TmyB8BYvNNjeKbW2IFepbRetopCxKjHYSq8fO9l90/BttXmpsCy+hB1J0 X-Received: by 2002:a05:6402:3553:b0:55c:c76b:b985 with SMTP id f19-20020a056402355300b0055cc76bb985mr479090edd.63.1706095715466; Wed, 24 Jan 2024 03:28:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706095715; cv=pass; d=google.com; s=arc-20160816; b=PQLKcpZ8/3TjE+6ZQZSQXfz3f/oistIrPpWevFFACajqA6cTA2VlWGvrrh84ol9rdc oymM8Rj9V8Xm1oIZB5bJ9/Ta5Pb+A5I1PedPHxijgPvgznS1Da8pLT1AXIFRJDiAY2Hp XaEKcC48HXKa8F24d/TGWV77N3P6oFjy2ph2qovO3auRYnjgUBMmsjaPCguwPJi1aHp+ jhFVIQvCPcMDHRhH0AUT9QhmMlS0Bsc+oiouSTGigShcHAdwDKoeAJ+08dejaP8fAM1c mIjOOJ3SJkCt7mor3hLz0wxCSpXDplyrQZHNj2pM9mv+0ZHilBK6ZYlvoUhK02RcENzP /yHg== 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=K265FR+b6bddW66/bKmG/pNNrdUslgqlSdUTYo2EluQ=; fh=CDl9gmstOssd+DeJX8EvQoWPHIZZjDoVBoXAnA35OBk=; b=bZZ3Gra41gWU+nKsYASb9HmVkKCvNgryXp/Yl8mNoKi4lZNAacGW7yfkRqdKQmgYAE xVlaCYfTMk+GxOnyw8MSQE+tkD6esgB09MDp5koTU8XQILwtLTnNd5utr3ly8q1mAX8a q3FrgAe3Tz23f/V7G22RBBO24IXl+MmOqqc+vaPMSFWFfXd1ZWC/GLWwFbex1nXmRp+w EwuuL4J1h/BzjFAsHjrQu/otpMDCRUZqV3YR8L7V8LhB7xFQe5VdQMPDk7C3bfeqXHco WA8OdGh1FubSwPVdoEA+2BoTA7YMYl/CKy4sSSVHHq4WvyLSuNXlRd1+wXA774G8qDRH E+Cw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hFTewJR7; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-36860-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36860-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id et15-20020a056402378f00b00559c9ce511bsi8200314edb.147.2024.01.24.03.28.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 03:28:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36860-ouuuleilei=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=hFTewJR7; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-36860-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36860-ouuuleilei=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 1BA881F2318E for ; Wed, 24 Jan 2024 11:28:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 945494E1D8; Wed, 24 Jan 2024 11:27:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hFTewJR7" 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 8A1613D54A; Wed, 24 Jan 2024 11:27:17 +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=1706095637; cv=none; b=DObVoqnkuifpc6FDYFM7D9t2daKbmlnnxYpRvZ7RMlxLIjvvwS33SyROAq7DryXWNK1nR9ykjVKWgN23UIyL9SGr+ZzUitkAdJq9Ei8KPPMevM2GUda988VG0GRtgMxcA5LnrPlOueMh9gzoHpajgtyzmsDb7kpCHpf/DJ+ROYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706095637; c=relaxed/simple; bh=dGDGJfQ1/YOqkdVRAJq8/8+jBm6SKZV3XfZreXxVhLQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AgquhhAHxZptP3KxxIC51GPm2RB5nap06dX6D5kjY28ESqdkHLe6Q+piE/mPoEJ35vbNm7bOYT8Ug3J1nKBebE2aEA4+TpwaixdkzVQ2NPGmtP3CMLZdjcg7Mw4zl94EPR1yCthgMFdeTtM/HOdTlX2/fcZGujmM8m8YtVam0PA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hFTewJR7; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A327C43601; Wed, 24 Jan 2024 11:27:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706095637; bh=dGDGJfQ1/YOqkdVRAJq8/8+jBm6SKZV3XfZreXxVhLQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hFTewJR7PgKsNh6FbdQiZu8+lLazPC/r+NN85as5kYCwrNSOoVpQo3JeEcvEKwXde REGnRUfUoytxjVjQdQR69ZMWJ27/v++Aw+guX65up6rJOJGx721MC+JcGJEz5oSxcA yw18GJTb9m77US8JEW1+An4/WEyj6kRRKlky99mtBTeP5TBfFOfoIob9UqKHlf25Od B/6Rfl/6+zgj/5/CT8SJIGJpmAKP/O4N62hYKNGj1DqXRr7U30KpPMXbbtPyOOpmCM BjwbieNYNZA3ZVIWj8EbtvTPNWUtw+WsJSEwvnRiOK9Hn4L8TdIDpeCjpPBFe+jkf8 40QMvqGX4sBqw== From: Benjamin Tissoires Date: Wed, 24 Jan 2024 12:26:59 +0100 Subject: [PATCH v2 3/3] 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 Message-Id: <20240124-b4-hid-bpf-fixes-v2-3-052520b1e5e6@kernel.org> References: <20240124-b4-hid-bpf-fixes-v2-0-052520b1e5e6@kernel.org> In-Reply-To: <20240124-b4-hid-bpf-fixes-v2-0-052520b1e5e6@kernel.org> To: Jiri Kosina , Benjamin Tissoires , Dan Carpenter , Daniel Borkmann , Andrii Nakryiko 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=1706095628; l=4484; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=dGDGJfQ1/YOqkdVRAJq8/8+jBm6SKZV3XfZreXxVhLQ=; b=YeshQWAua7ciYLBibudWBI4ndN1lYooAtSocUnUWnzHG0O5owiDcz8YmHvoUiF0N0eeOCRNG9 kpi3FyjLL1dBG0cEcjJ+cCwwPWu7CD5SZazwqAItOJoGKuPXKw4t1Am X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788971021223808560 X-GMAIL-MSGID: 1788971021223808560 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 --- changes in v2: * make use of __bpf_kfunc_start/end_defs() instead of manual push/pop --- drivers/hid/bpf/hid_bpf_dispatch.c | 18 +++++++++++++----- include/linux/hid_bpf.h | 11 ----------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c index 7903c8638e81..470ae2c29c94 100644 --- a/drivers/hid/bpf/hid_bpf_dispatch.c +++ b/drivers/hid/bpf/hid_bpf_dispatch.c @@ -143,6 +143,9 @@ 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 */ +__bpf_kfunc_start_defs(); + /** * hid_bpf_get_data - Get the kernel memory pointer associated with the context @ctx * @@ -152,7 +155,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 +170,7 @@ hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, const size_t rdwr return ctx_kern->data + offset; } +__bpf_kfunc_end_defs(); /* * The following set contains all functions we agree BPF programs @@ -274,6 +278,9 @@ static int do_hid_bpf_attach_prog(struct hid_device *hdev, int prog_fd, struct b return fd; } +/* Disables missing prototype warnings */ +__bpf_kfunc_start_defs(); + /** * hid_bpf_attach_prog - Attach the given @prog_fd to the given HID device * @@ -286,7 +293,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; @@ -338,7 +345,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; @@ -371,7 +378,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; @@ -397,7 +404,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) { @@ -465,6 +472,7 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz, kfree(dma_data); return ret; } +__bpf_kfunc_end_defs(); /* 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 */