Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1897939pxp; Mon, 21 Mar 2022 07:15:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvv6yh0CskyThbJHjc7EynyeFMfsUC4zjbhB85JvkJC2DrvxhD2mLWFir1HcX5mGTK96Aa X-Received: by 2002:a17:902:daca:b0:154:3d06:9c2f with SMTP id q10-20020a170902daca00b001543d069c2fmr9671614plx.0.1647872155223; Mon, 21 Mar 2022 07:15:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647872155; cv=none; d=google.com; s=arc-20160816; b=j94I2pkCULSD8M0vUkkeTt/wbUFtLQtErH2RFTzA/rG2HW118MwCedWiHCysyeKnws bd4Kp5PiyheM+1siOWtvZcRYlNHcMCHK0ID2xenILYAcpKh/1jDVZqiFwH2JCMFR7Gxy xWbr600T/rA0jJ65vPVWtVtuvUZJLDeQ1UrmnwOFOFjZMy744z7cGS7ZkmODGqsqVRF8 8fqguE6GuZQQhH2CHwH0jJyhnAsiujENFyzgiXEFgWyC69u4K01iqSNz7EQ1hyFPIgpO mrL1k7REtr7A6w9DoH+uFecDxAPQ2ADyo72k4VdHK7HYoUN434vGsXIMiMj0+wGL8L7h FBCQ== 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=wmMzuATztGpgPV+tKAjKAoO0ohO3+84+NzvwIrxFZhA=; b=KBf9D/0DpGfzXzeCpLFoL+y7J9eA6tQcGpxvQT3oXNfFSMVrhN5e1XBvvq2x3dGHQy V74QlSJms4lxJ9XtVkr0YTRPrrX96oFX8DOD8j+U/KS4H+m7DgIeIJzyR0T1zfY3VRrd DSrbMHon9wzk7AAeEw8zb6elOwh7E4/SWtQjQqDhkjeCQvulXkInaR7Xrs7mP/BTr6tu wZnynY9DLY8Qb2r7DfRUnHUwQLNimNLc21TapDDGz9svg+3AO3tBrzLQRrzVpJ3jQRTi DNek2BuuvKagz1Qlu850xW7USzjjYD96PcagkEyvZANLqmhcs32wGlGI8VWVQzgIFMZv F+Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bHrLverK; 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 b29-20020a63715d000000b003816043eee7si13280225pgn.220.2022.03.21.07.15.40; Mon, 21 Mar 2022 07:15:55 -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=bHrLverK; 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 S240001AbiCRSHN (ORCPT + 99 others); Fri, 18 Mar 2022 14:07:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239969AbiCRSHL (ORCPT ); Fri, 18 Mar 2022 14:07:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C56E2BD23E; Fri, 18 Mar 2022 11:05:52 -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 ams.source.kernel.org (Postfix) with ESMTPS id 4D609B82519; Fri, 18 Mar 2022 18:05:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEA95C340F5; Fri, 18 Mar 2022 18:05:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647626750; bh=zIkEvsZc/kt2D5So3dCzeb7vp7iTdkL0bnV/3Yh8e6o=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=bHrLverKp3mcWzc1G29Sb/a1reCKciGcsMTF1EDF2zrLXmvg6DkYO+pfabwrx7aIM XNcbRfZ7mfkQf1NfRH3CxdG9oIhkPkUluzdp1I8DlBEkX0HZuMopArqj9d0c/v4VKY uS0Ve7y5J2MNgd297ck+IGgl70X/MkJjVhGrz1+uLUi2uXf88Av0PCTUU0RqB3Ivwb oyaXLOPDjQSfkB84vopOizd4hjySbGbzI13W/0/6jtu3RJIl5cGRYo7liaUC9qWFsy f042OPdcM8WSEKU2F2OR7OTdSdDG9hKVfxBf6KNxxo4Q0Vj3ukRU90WaUuyiqZ7JTX kGqWp/Nm4jyDw== Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-2dbd97f9bfcso99068487b3.9; Fri, 18 Mar 2022 11:05:49 -0700 (PDT) X-Gm-Message-State: AOAM533j/W5XU6R0myNtfS4lqq4QNu5SKxrnoZvz0sDbM0TIO4iJ6D5o TsD0VkngYZLR01IGdna9vkXR42G3gZ/93KFMzuw= X-Received: by 2002:a81:951:0:b0:2e5:9e38:147c with SMTP id 78-20020a810951000000b002e59e38147cmr12482496ywj.211.1647626748837; Fri, 18 Mar 2022 11:05:48 -0700 (PDT) MIME-Version: 1.0 References: <20220318161528.1531164-1-benjamin.tissoires@redhat.com> <20220318161528.1531164-18-benjamin.tissoires@redhat.com> In-Reply-To: <20220318161528.1531164-18-benjamin.tissoires@redhat.com> From: Song Liu Date: Fri, 18 Mar 2022 11:05:37 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next v3 17/17] Documentation: add HID-BPF docs 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:22 AM Benjamin Tissoires wrote: > > Gives a primer on HID-BPF. > > Signed-off-by: Benjamin Tissoires > > --- > > new in v3 > --- > Documentation/hid/hid-bpf.rst | 444 ++++++++++++++++++++++++++++++++++ > Documentation/hid/index.rst | 1 + > include/uapi/linux/bpf_hid.h | 54 ++++- > 3 files changed, 492 insertions(+), 7 deletions(-) > create mode 100644 Documentation/hid/hid-bpf.rst > > diff --git a/Documentation/hid/hid-bpf.rst b/Documentation/hid/hid-bpf.rst > new file mode 100644 > index 000000000000..0bf0d937b0e1 > --- /dev/null > +++ b/Documentation/hid/hid-bpf.rst > @@ -0,0 +1,444 @@ > +.. SPDX-License-Identifier: GPL-2.0 > + > +======= > +HID-BPF > +======= > + > +HID is a standard protocol for input devices and it can greatly make use > +of the eBPF capabilities to speed up development and add new capabilities > +to the existing HID interfaces. > + > +.. contents:: > + :local: > + :depth: 2 > + > + > +When (and why) using HID-BPF > +============================ > + > +We can enumerate several use cases for when using HID-BPF is better than > +using a standard kernel driver fix. > + > +dead zone of a joystick > +----------------------- > + > +Assuming you have a joystick that is getting older, it is common to see it > +wobbling around its neutral point. This is usually filtered at the application > +level by adding a *dead zone* for this specific axis. > + > +With HID-BPF, we can put the filtering of this dead zone in the kernel directly > +so we don't wake up userspace when nothing else is happening on the input > +controller. > + > +Of course, given that this dead zone is device specific, we can not create a nit: s/can not/cannot There are a few more "can not" below. [...] > +firewall > +-------- > + > +What if we want to prevent other users to access a specific feature of a > +device? (think a possibly bonker firmware update entry popint) nit: point > + > +With eBPF, we can intercept any HID command emitted to the device and > +validate it or not. > + > +This also allows to sync the state between the userspace and the > +kernel/bpf program because we can intercept any incoming command. > + [...] > + > +The main idea behind HID-BPF is that it works at an array of bytes level. > +Thus, all of the parsing of the HID report and the HID report descriptor > +must be implemented in the userspace component that loads the eBPF > +program. > + > +For example, in the dead zone joystick from above, knowing which fields > +in the data stream needs to be set to ``0`` needs to be computed by userspace. > + > +A corrolar of this is that HID-BPF doesn't know about the other subsystems nit: corollary? > +available in the kernel. *You can not directly emit input event through the > +input API from eBPF*. > + > +When a BPF program need to emit input events, it needs to talk HID, and rely > +on the HID kernel processing to translate the HID data into input events. > + > +Available types of programs > +=========================== [...] > + > +``BPF_HID_RDESC_FIXUP`` > +~~~~~~~~~~~~~~~~~~~~~~~ > + > +Last, the ``BPF_HID_RDESC_FIXUP`` program works in the similar maneer than nit: manner. > +``.report_fixup`` of ``struct hid_driver``. > + [...]