Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp681543lqs; Fri, 14 Jun 2024 02:25:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXbMFYTNS8mhpeXRDebqm38VXVWLm8RCJgb1ZhQhh3E4JjpYmGtkfAHVkBXBNdtvaciAiIx5pCmPslpDIRn3nYl+Sa2CqR6l5cJY1LRXA== X-Google-Smtp-Source: AGHT+IFsy/4tzfbIT/x49nX87ATtt6Fu9SDANkk3Hz2uWfguV5uNeRwqs0sFh/9HpCs6+Y4JbUbU X-Received: by 2002:ac2:41da:0:b0:52c:816c:28cd with SMTP id 2adb3069b0e04-52ca6e6e864mr1517543e87.37.1718357142063; Fri, 14 Jun 2024 02:25:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718357142; cv=pass; d=google.com; s=arc-20160816; b=brVe+fVcqYdbz0z/i2f/x62NrczS85I32gHRwKNPrHMllVvBqYk5n3TJ3c6E2a2xZ6 ySLaV0tO8A+RiTCtMr81n5c99R9P4vl7MMWvDeCubCII0fSF2fXvi7MCk6RwTLqOZoZg PKlArxOqP0Humoobd7mvHGsWb1FpN6TvwEmrA10oXXefLeZpPEiCZxGAzv8Sa2yyVWJg +Do91I9jfoYaqp8De/RCbp0oJ/KNHsKpvSm2Sbmv/+s+P0b4rNTybBqL72xQp4uVPQt1 4kzaEPQ04ZLP5Lj6L2heAw4Z2GpDBDRj5CuJ2muPvyGvy7YL9k7EvOuZusIS7wAuOKqD gbIQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Zwl17t35vtf1cjbyNsgwa5HBF2EWZm1ZqOV/2CdJvU8=; fh=i9RUlcSj9Us95OtlwWEB5vXf2cl/nFzJtTJDFMCv3co=; b=I60VEO1tp674nR/cgRX+ZxE3hD2YmMV4EOOVY9Nugyv2sKOPXAWKiaJOMUqs6WZpFu SZMdzmXR6tXStYKAAfSNUHIjRBFjLlqOfQRHkQWvRZ3o7zHasYuxPaSfVgbOOgnUmYP9 CSkcBUf6pDVm5RfVJ85/rCo/hob1v1FTN76Ql9avboJVHvzCCnJBFT3Ao04zoaytFGl9 9nm1kG7pEGjcfK6JJ9hT6RWG9cP9bdaaZe3dvGaLu4gAel5ywEaGq44Rn8OND6VVWpkp q/ud85ACjHibc54V9I5Ofhk9Pivr3hDUiU6kFbju16+PGtKQgOUDzqoO/TjhwEIcAwCH 8uYg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="AiW/ysVs"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-214630-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214630-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 a640c23a62f3a-a6f56e7ef1dsi160726366b.957.2024.06.14.02.25.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 02:25:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-214630-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="AiW/ysVs"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-214630-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214630-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 BEA321F22FD7 for ; Fri, 14 Jun 2024 09:25:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B274A1922FE; Fri, 14 Jun 2024 09:25:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AiW/ysVs" 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 BB2F9191497; Fri, 14 Jun 2024 09:25:30 +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=1718357130; cv=none; b=L+0VKz4QJEpjyiQ6UgFXA+K6c+wq/P86PYiStTdqRr4QX3gC3ZkBF2EzaTv7d4u0hysMKHk83MhH7PtTaSVGQzWOb0GsCLHuoXHoE2hXEQFZq/Q9jBDeVfT9N0LuhDv7cinZVIKMPa1LTqcJYgfQAkVisFwaHGB5n7f+B35ASVk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718357130; c=relaxed/simple; bh=ahmJ4DUtC/KtQwSFizke71LMBIHWUNU2u1aqPfaaGOY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=B2hXpNcJi+jT5IODBqbSj08joFFAkTk3qXDKqFdC4DiuJq/WPiqeKVHmtcQOOEZ9b/PIqyjDvNcu7aChaI2PpYGtO/wPGWFMUfU8zp1cjWw+4n0jGsxpsLxzdIHQimjwYXyt81hoHLWytXIDDcpFjtMcYZ0FNkSg06XOgE5Bmwc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AiW/ysVs; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FD51C2BD10; Fri, 14 Jun 2024 09:25:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718357130; bh=ahmJ4DUtC/KtQwSFizke71LMBIHWUNU2u1aqPfaaGOY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AiW/ysVs2zmxbYPWOVfdrHnRbJbMLsZe59HM6uL3X+csssJ0WoJccpNbEECekwzGp 17rmMjNSXHR2QosV38XvjUVo6QY0ryRfi+gWAN/aUbBJgTKqDGHQkXBQ6iIk8/mQCp ZxUaDAZrN9TKArfRHvfuvbpM47dB4957kPPkKg1r5vy79U1oWwN/zh8DV7lmDCGiDT ircOzhlpVUe5NVJldmgdsooHiPW2bkFMhshXijdIHZB0ldzhOLJW2X/eGvuf2xKK5i bJ71F+1NaJcHp8r8kJmiSXrpM4EVlJy5aXwkj9TYthsBqD9vcT2CM054Myjpm16h52 uDVy9MKniQVpw== Date: Fri, 14 Jun 2024 11:25:25 +0200 From: Benjamin Tissoires To: Alexei Starovoitov Cc: Shuah Khan , Jiri Kosina , Jonathan Corbet , Alexei Starovoitov , "open list:KERNEL SELFTEST FRAMEWORK" , LKML , bpf , "open list:HID CORE LAYER" , "open list:DOCUMENTATION" Subject: Re: [PATCH HID v3 03/16] HID: bpf: implement HID-BPF through bpf_struct_ops Message-ID: References: <20240608-hid_bpf_struct_ops-v3-0-6ac6ade58329@kernel.org> <20240608-hid_bpf_struct_ops-v3-3-6ac6ade58329@kernel.org> 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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Jun 10 2024, Alexei Starovoitov wrote: > On Sat, Jun 8, 2024 at 2:01 AM Benjamin Tissoires wrote: > > > > + > > +static int hid_bpf_ops_init_member(const struct btf_type *t, > > + const struct btf_member *member, > > + void *kdata, const void *udata) > > +{ > > + u32 moff = __btf_member_bit_offset(t, member) / 8; > > + u32 flags; > > + > > + switch (moff) { > > + case offsetof(struct hid_bpf_ops, hid_id): > > + /* For hid_id and flags fields, this function has to copy it > > + * and return 1 to indicate that the data has been handled by > > + * the struct_ops type, or the verifier will reject the map if > > + * the value of those fields is not zero. > > + */ > > + ((struct hid_bpf_ops *)kdata)->hid_id = ((struct hid_bpf_ops *)udata)->hid_id; > > + return 1; > > + case offsetof(struct hid_bpf_ops, flags): > > + flags = ((struct hid_bpf_ops *)udata)->flags; > > + if (flags & ~BPF_F_BEFORE) > > + return -EINVAL; > > + ((struct hid_bpf_ops *)kdata)->flags = flags; > > minor nit: I'd cast kdata/udate in the beginning of > the function to make the lines shorter and less verbose. > Similar to how bpf_tcp_ca_init_member() does it. The change looks like: --- diff --git a/drivers/hid/bpf/hid_bpf_struct_ops.c b/drivers/hid/bpf/hid_bpf_struct_ops.c index 9192c66cde20..dde547e734ed 100644 --- a/drivers/hid/bpf/hid_bpf_struct_ops.c +++ b/drivers/hid/bpf/hid_bpf_struct_ops.c @@ -97,8 +97,14 @@ static int hid_bpf_ops_init_member(const struct btf_type *t, const struct btf_member *member, void *kdata, const void *udata) { - u32 moff = __btf_member_bit_offset(t, member) / 8; - u32 flags; + const struct hid_bpf_ops *uhid_bpf_ops; + struct hid_bpf_ops *khid_bpf_ops; + u32 moff; + + uhid_bpf_ops = (const struct hid_bpf_ops *)udata; + khid_bpf_ops = (struct hid_bpf_ops *)kdata; + + moff = __btf_member_bit_offset(t, member) / 8; switch (moff) { case offsetof(struct hid_bpf_ops, hid_id): @@ -107,13 +113,12 @@ static int hid_bpf_ops_init_member(const struct btf_type *t, * the struct_ops type, or the verifier will reject the map if * the value of those fields is not zero. */ - ((struct hid_bpf_ops *)kdata)->hid_id = ((struct hid_bpf_ops *)udata)->hid_id; + khid_bpf_ops->hid_id = uhid_bpf_ops->hid_id; return 1; case offsetof(struct hid_bpf_ops, flags): - flags = ((struct hid_bpf_ops *)udata)->flags; - if (flags & ~BPF_F_BEFORE) + if (uhid_bpf_ops->flags & ~BPF_F_BEFORE) return -EINVAL; - ((struct hid_bpf_ops *)kdata)->flags = flags; + khid_bpf_ops->flags = uhid_bpf_ops->flags; return 1; } return 0; --- > > Acked-by: Alexei Starovoitov And I'm going to apply the series now Cheers, Benjamin