From patchwork Wed Feb 21 16:25:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 204313 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1150771dyc; Wed, 21 Feb 2024 08:34:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUddg1VCh6ln9aitJ5sCmAwKGl97R1/p8JsJvRYX86FSnUZSLgOP2+dZToQbemZN62MmjkIpOcehWjaL4WQrrmA+hVOoA== X-Google-Smtp-Source: AGHT+IFduDM0IwtWIFsdeKhtPY+YUL3dzG/l152aoBvp+tDoFVCC9+VVU0KV9BuZNSfizT4M9pmO X-Received: by 2002:a17:90a:ce04:b0:299:34b4:2ea7 with SMTP id f4-20020a17090ace0400b0029934b42ea7mr10321748pju.47.1708533261413; Wed, 21 Feb 2024 08:34:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708533261; cv=pass; d=google.com; s=arc-20160816; b=RVBkx+qxT5VUR9kGuRvqzxCmsGobKProVMNlnAYsm6ohvyQccoBJbLMNhwvKbNBYSH vEI4LeLEa80dD9yxLz1gdX1uiWfvSLu4aoCxMo8+ClLTUH6iVQikz0/28+kDf4W9s8ou QwrER5dMJUhkIsAR1Jz+eEMrimNpGX2NPp/ifrSTKNYHAD9T6wo6MQ77L099rcPNXHOC BgQwoK3KKYb71Re2w/2swWJpziLtmi/aKdV8OolfNIGILnsy37Q4/f46GWibKC06C0Kz /pPDpt04X2sb5Dw/x+VIldwbR0+DPPKpx+Z3ukVzhd10c0DjtQf3aqCrKpHBKZjid9tb j64w== 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=y6IeKtLMXpVi0lqKw3sXmdW12OBr2MyJuC4Yw7a1CEg=; fh=hc4Y6F7QBSV+XcCZzl4ZOgjmnikSFu9Au/ny4/yLvAg=; b=hIymaXXAwfazd4mcPWWCoSJG2uMiBP1MG6lE6L987DvpKaNsKok/kKOW0KnHowmk2i AyZzuTyzyGR43dL5yfrBIV4zRe/J+dVskGJCA9BTEcvPFceDp0/td3qLkAg72VSWHgc5 ODBKJ/dfzxv0oryVNT9skpZGLPAQSk9liU4Qq2pusJTNkNe6O39yB00F3lNQiZ3cqeNt PSyuTsBPsvhDX9usEfyiIjDHsyIU17MQyVQ/BSvKM9Ayl9VV/+qURMovcl656j9HZKBn v3vMDXo9iUkfV3fezj+DFQSQ0plx9tk9fxdyes9QItz7/HlM9IHwVCFWNIxh/KnTEBfu Oc7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J4NLUfJm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-75106-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75106-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id ls16-20020a17090b351000b0029a39ecc6efsi260083pjb.56.2024.02.21.08.34.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 08:34:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75106-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J4NLUfJm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-75106-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75106-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8A813B20FD7 for ; Wed, 21 Feb 2024 16:28:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5370D8287D; Wed, 21 Feb 2024 16:26:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="J4NLUfJm" 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 996D081AA3; Wed, 21 Feb 2024 16:26:04 +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=1708532764; cv=none; b=KtcJuhsb2YpAQ/OEBTDH8KYhVwAcG3jYn6geiS5/nw84HixPLyCyVVxG9PzSM7P4CoWceP2xBlb4tuRn3OUNc6IyL85kwS+nM6aNQmbhggoEwu7qjqCvxDF85oLVnVR5Pn4Bw+x3NjybNgpzDTWURD9yz/wQhk3v5PDTypa2MzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708532764; c=relaxed/simple; bh=TtpobMMu80H5N4HlAwS872e0X6zIMx4ZXZINEqECFG0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ogU8edUS8ngyk3AVK8gMEZVeMprQlXr6q3TRX0BwKfnOyr7Q2tssIgs9WQe53IBTql9tKvU3hiTxZkM9RqPXQYpjYZlYeSkG+6JF6bqnRagbmLxysBsSjYBR0gtd/aMbNlisVmSFtPgoxG8M1BA7jLJNkeax54s2XQUo+sofTqc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J4NLUfJm; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AE7EC43601; Wed, 21 Feb 2024 16:25:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708532764; bh=TtpobMMu80H5N4HlAwS872e0X6zIMx4ZXZINEqECFG0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=J4NLUfJmXHd/29pu0o91PmvPaBM7350lH59pHtHwEvmFthvtFmklHRcfBK9d36ggv kcmtcWf2dwCVQlexKW3Too2HIvL24/kkbeCLWgkxq2F8z7ThNSYX6wINhPQUy1OVPj ZFftLnvxlg2z7K6PYoHDbY/MxDVXZEwHx7EU20gvgYFmuA5iWQh4Hmf7Qq42s4tUs1 kbKv70zo9sdLbub67NwaPz8Jl0Fsq5fjquMf5rXATC69ZbrkBY2QusxZMapR6YaCmn mhQYm/7qOzVCdeNMq4qTDpILesI6ks96BHGKkVcf9rbbIEv8tj2jbdVF4SbK1/moGH cAPEJnK6wFMog== From: Benjamin Tissoires Date: Wed, 21 Feb 2024 17:25:25 +0100 Subject: [PATCH RFC bpf-next v3 09/16] HID: bpf/dispatch: regroup kfuncs definitions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240221-hid-bpf-sleepable-v3-9-1fb378ca6301@kernel.org> References: <20240221-hid-bpf-sleepable-v3-0-1fb378ca6301@kernel.org> In-Reply-To: <20240221-hid-bpf-sleepable-v3-0-1fb378ca6301@kernel.org> To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1708532719; l=3521; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=TtpobMMu80H5N4HlAwS872e0X6zIMx4ZXZINEqECFG0=; b=T33LfFftYVbRgn8ui1NAZaKDxcIcF6nO+CzP83MtS0HpUbPOCpJ/D50R/OgWDqPW35i3EGMvT noF8L43G4s4ByXqsa9Tnmx6vjw6FZXDr6fjECinHtfnfXGAC6mB5TUs X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791526973107374028 X-GMAIL-MSGID: 1791526973107374028 No code change, just move down the hid_bpf_get_data() kfunc definition so we have only one block of __bpf_kfunc_start/end_defs() Signed-off-by: Benjamin Tissoires --- no changes in v3 no changes in v2 --- drivers/hid/bpf/hid_bpf_dispatch.c | 80 ++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c index e630caf644e8..52abb27426f4 100644 --- a/drivers/hid/bpf/hid_bpf_dispatch.c +++ b/drivers/hid/bpf/hid_bpf_dispatch.c @@ -143,48 +143,6 @@ 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 - * - * @ctx: The HID-BPF context - * @offset: The offset within the memory - * @rdwr_buf_size: the const size of the buffer - * - * @returns %NULL on error, an %__u8 memory pointer on success - */ -__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; - - if (!ctx) - return NULL; - - ctx_kern = container_of(ctx, struct hid_bpf_ctx_kern, ctx); - - if (rdwr_buf_size + offset > ctx->allocated_size) - return NULL; - - return ctx_kern->data + offset; -} -__bpf_kfunc_end_defs(); - -/* - * The following set contains all functions we agree BPF programs - * can use. - */ -BTF_KFUNCS_START(hid_bpf_kfunc_ids) -BTF_ID_FLAGS(func, hid_bpf_get_data, KF_RET_NULL) -BTF_KFUNCS_END(hid_bpf_kfunc_ids) - -static const struct btf_kfunc_id_set hid_bpf_kfunc_set = { - .owner = THIS_MODULE, - .set = &hid_bpf_kfunc_ids, -}; - static int device_match_id(struct device *dev, const void *id) { struct hid_device *hdev = to_hid_device(dev); @@ -281,6 +239,31 @@ static int do_hid_bpf_attach_prog(struct hid_device *hdev, int prog_fd, struct b /* Disables missing prototype warnings */ __bpf_kfunc_start_defs(); +/** + * hid_bpf_get_data - Get the kernel memory pointer associated with the context @ctx + * + * @ctx: The HID-BPF context + * @offset: The offset within the memory + * @rdwr_buf_size: the const size of the buffer + * + * @returns %NULL on error, an %__u8 memory pointer on success + */ +__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; + + if (!ctx) + return NULL; + + ctx_kern = container_of(ctx, struct hid_bpf_ctx_kern, ctx); + + if (rdwr_buf_size + offset > ctx->allocated_size) + return NULL; + + return ctx_kern->data + offset; +} + /** * hid_bpf_attach_prog - Attach the given @prog_fd to the given HID device * @@ -474,6 +457,19 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz, } __bpf_kfunc_end_defs(); +/* + * The following set contains all functions we agree BPF programs + * can use. + */ +BTF_KFUNCS_START(hid_bpf_kfunc_ids) +BTF_ID_FLAGS(func, hid_bpf_get_data, KF_RET_NULL) +BTF_KFUNCS_END(hid_bpf_kfunc_ids) + +static const struct btf_kfunc_id_set hid_bpf_kfunc_set = { + .owner = THIS_MODULE, + .set = &hid_bpf_kfunc_ids, +}; + /* our HID-BPF entrypoints */ BTF_SET8_START(hid_bpf_fmodret_ids) BTF_ID_FLAGS(func, hid_bpf_device_event)