Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1726825pxp; Mon, 21 Mar 2022 03:49:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBEV2ayt9seOY2W2SlS4RQ8CUseoEJOECQEf1HGeikMVw/c/YOr8o5WH61I0vmdSTxGSyi X-Received: by 2002:a63:e117:0:b0:381:7672:f24 with SMTP id z23-20020a63e117000000b0038176720f24mr17392204pgh.290.1647859790238; Mon, 21 Mar 2022 03:49:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647859790; cv=none; d=google.com; s=arc-20160816; b=jACnNWO6bg8gLF9/HM3B4IdGgQQinc6nPcrUbzl1+Roq9ue52Op8yzJlWr0y4xW4T+ GwwmJe4SVLc14vMymSr/+W8G2DYa/lzC1Q0Zjf4XFeHLotZJui4AR3TDoCHOw1HsIboh MTn/AExAbOlIak63bwQlOregzL5IfWagZAr/Gz4eADPB4D/B4IbVT0ey7jhl0wKTfOVP m0Hl0IdDqyWONmT5AQrdJpdrjF6wZ2Nb4JV9QLaDmsRWBpfnKhpII3ZFf18tcmUAJ/vl lLHaUxFQDTM7IT8oc6lrJcdcighszVM8QTQUyDm5TKSuYOA9jpf1PvoY3O55Db0tjlu5 +rKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/Dt4cvTyD+jXAiDwbu0JEw0y72Wfe0JHwqR7LtY+0RE=; b=iwlLTsZ46+6tcHyMacnf0aLvlsC7m7vmmYYMS7mB07SNrDvkh8wUE/32J45Wrpi/7T V7ZpA9HdoA9aaS7E9QCH2qsQ/KRipRFRqnb8XeQCrBz9WsbzP26/SQDGbCLo8ZjZeoHj FSFQAbm4HHi9O9HCMexPDuVWtITh24WUpPEopJ17opY6j/w9DfpuxdgR6qxBaaeX75Lg YUA/NDWyLNBcsPA9J62xex+TTEGKdIjWNytaOZhUOjq1U3tGcOrkYZaM0446rnjtlIug fkAZuasvGUrx4Oh5DSzgAbuK6dgu2ZiMMBvgaF8EcbmsYOu06PP2T2FKvvdEq1/yxM38 Jd/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ELbYGJ5s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r9-20020a655089000000b003816043f074si12374956pgp.617.2022.03.21.03.49.38; Mon, 21 Mar 2022 03:49:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ELbYGJ5s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241110AbiCRVW2 (ORCPT + 99 others); Fri, 18 Mar 2022 17:22:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241103AbiCRVW1 (ORCPT ); Fri, 18 Mar 2022 17:22:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACEC421FC6F; Fri, 18 Mar 2022 14:21:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4AE6B612AC; Fri, 18 Mar 2022 21:21:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8EF4C36AE3; Fri, 18 Mar 2022 21:21:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647638467; bh=Vk5mzHbIg17vZ6G2aaaTRJ/qc3wtRp4U3dpTA+mQTzk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ELbYGJ5s13fJLbEKv95M5pVw7hO7DtSYZ0YpTw3usN05tXHbv2RI/LMOrZ9RvazFC LKvWI9DHFrTXTdQ5NF2TNzFoQuiFV6G24Br9GEyC8hQHayVOTzJDPf+w1s2IMdy6yU wqF+2/LEOGg59KR03baTx/feAPOiwR72Cu1smHzVen/JSY4ll7IJwKloDR1RUnuTLT VhrSdPTUQt8lLE52izSQjSw/0mKq7ehBlQSqMiyXv70d3eNWHEPv3ZQT6CKSIbG/Sj DYF2fr/vqXxhPOxtVSzMbHqaZm5yjFlwapmRWSrtHJHkI9yDBsyOZH82JGzw9qNIDQ B+0vj43BUdwXQ== Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-2e5a8a8c1cdso95489317b3.3; Fri, 18 Mar 2022 14:21:07 -0700 (PDT) X-Gm-Message-State: AOAM533GGYVhVaqQnOb4korkjuBryjjBMfznHfUsdMGF1bnP4djVeMdf ZLWUzWnKjaszKkuxcQGEnm4POyxOMHcn3X9XavU= X-Received: by 2002:a81:a006:0:b0:2e5:963a:4c42 with SMTP id x6-20020a81a006000000b002e5963a4c42mr12976417ywg.73.1647638466787; Fri, 18 Mar 2022 14:21:06 -0700 (PDT) MIME-Version: 1.0 References: <20220318161528.1531164-1-benjamin.tissoires@redhat.com> <20220318161528.1531164-14-benjamin.tissoires@redhat.com> In-Reply-To: <20220318161528.1531164-14-benjamin.tissoires@redhat.com> From: Song Liu Date: Fri, 18 Mar 2022 14:20:56 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next v3 13/17] HID: bpf: implement hid_bpf_get|set_bits To: Benjamin Tissoires Cc: Greg KH , Jiri Kosina , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Shuah Khan , Dave Marchevsky , Joe Stringer , Jonathan Corbet , Tero Kristo , open list , "open list:HID CORE LAYER" , Networking , bpf , linux-kselftest@vger.kernel.org, Linux Doc Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 18, 2022 at 9:18 AM Benjamin Tissoires wrote: > > Export implement() outside of hid-core.c and use this and Maybe rename implement() to something that makes sense? > hid_field_extract() to implement the helprs for hid-bpf. > > Signed-off-by: Benjamin Tissoires > > --- > > changes in v3: > - renamed hid_{get|set}_data into hid_{get|set}_bits > > changes in v2: > - split the series by bpf/libbpf/hid/selftests and samples > - allow for n > 32, by relying on memcpy > --- > drivers/hid/hid-bpf.c | 29 +++++++++++++++++++++++++++++ > drivers/hid/hid-core.c | 4 ++-- > include/linux/hid.h | 2 ++ > 3 files changed, 33 insertions(+), 2 deletions(-) > > diff --git a/drivers/hid/hid-bpf.c b/drivers/hid/hid-bpf.c > index 45c87ff47324..650dd5e54919 100644 > --- a/drivers/hid/hid-bpf.c > +++ b/drivers/hid/hid-bpf.c > @@ -122,6 +122,33 @@ static void hid_bpf_array_detach(struct hid_device *hdev, enum bpf_hid_attach_ty > } > } > > +static int hid_bpf_get_bits(struct hid_device *hdev, u8 *buf, size_t buf_size, u64 offset, u32 n, > + u32 *data) > +{ > + if (n > 32) > + return -EINVAL; > + > + if (((offset + n) >> 3) >= buf_size) > + return -E2BIG; > + > + *data = hid_field_extract(hdev, buf, offset, n); > + return n; > +} > + > +static int hid_bpf_set_bits(struct hid_device *hdev, u8 *buf, size_t buf_size, u64 offset, u32 n, > + u32 data) > +{ > + if (n > 32) > + return -EINVAL; > + > + if (((offset + n) >> 3) >= buf_size) > + return -E2BIG; > + > + /* data must be a pointer to a u32 */ > + implement(hdev, buf, offset, n, data); > + return n; > +} > + > static int hid_bpf_run_progs(struct hid_device *hdev, struct hid_bpf_ctx_kern *ctx) > { > enum bpf_hid_attach_type type; > @@ -223,6 +250,8 @@ int __init hid_bpf_module_init(void) > .pre_link_attach = hid_bpf_pre_link_attach, > .post_link_attach = hid_bpf_post_link_attach, > .array_detach = hid_bpf_array_detach, > + .hid_get_bits = hid_bpf_get_bits, > + .hid_set_bits = hid_bpf_set_bits, > }; > > bpf_hid_set_hooks(&hooks); > diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c > index 3182c39db006..4f669dcddc08 100644 > --- a/drivers/hid/hid-core.c > +++ b/drivers/hid/hid-core.c > @@ -1416,8 +1416,8 @@ static void __implement(u8 *report, unsigned offset, int n, u32 value) > } > } > > -static void implement(const struct hid_device *hid, u8 *report, > - unsigned offset, unsigned n, u32 value) > +void implement(const struct hid_device *hid, u8 *report, unsigned int offset, unsigned int n, > + u32 value) > { > if (unlikely(n > 32)) { > hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n", > diff --git a/include/linux/hid.h b/include/linux/hid.h > index 66d949d10b78..7454e844324c 100644 > --- a/include/linux/hid.h > +++ b/include/linux/hid.h > @@ -944,6 +944,8 @@ bool hid_compare_device_paths(struct hid_device *hdev_a, > s32 hid_snto32(__u32 value, unsigned n); > __u32 hid_field_extract(const struct hid_device *hid, __u8 *report, > unsigned offset, unsigned n); > +void implement(const struct hid_device *hid, u8 *report, unsigned int offset, unsigned int n, > + u32 value); > > #ifdef CONFIG_PM > int hid_driver_suspend(struct hid_device *hdev, pm_message_t state); > -- > 2.35.1 >