Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2023230iob; Thu, 19 May 2022 23:10:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOybj5+rUxaTN30QjD3wDvhQG1hpLAxzr3l5L2kaFibvgx4VnLuR0V553XW9f5KcaD/71o X-Received: by 2002:a05:6a00:1903:b0:4fa:fa9e:42e6 with SMTP id y3-20020a056a00190300b004fafa9e42e6mr8285754pfi.1.1653027050838; Thu, 19 May 2022 23:10:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653027050; cv=none; d=google.com; s=arc-20160816; b=zZhggg1MkI+0tuQUd7fG8p3wV8nu9J/t3vR7Io8UG0B2dhgsUvY0FoMEJ+IKm+mxS/ c87RdEd1/AhdCi5MMUUV4D8GXRobVjmRPlW7X2gjnaRheIoZlR1UDufnOWWFTjUGnDiP 1IQLDarzEvo8RdVFF9/njDlewGk3YMoJ9n4/ZlL8JKx/lrcViTaiXfMR41nr/kY4ANFW 2nHh6ukXdEsEoVzvW2aPIXAOP1TuJTr6vl4TQl0pMNU0+bWJIj/dEzMxVLrxNB9mzpzn nV28ruW8X4EvJNoRreYaBjphJO/V+Fzm8HCuG9YKvKi7zDudVgkou0tiUCDsx+Xh9N2W DpOA== 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=uTf4UazsnqFm1w0j9PjtulisgMFh6QzykfXouIHj8FI=; b=Y4YsqDW0BUgDuP+b54RiICQz7Ca9YL1lVtEZ1dJLpop2eEzcnRDpUKBLaXRCK4YetS G10asr2r701BnG7xQLRlAdj35Lc/tstN6nwnzBYD4p2N99It8DKJAySNiwZLQBXgcsK9 QHzb8J7mKxfJBNKCx3ziu63oFlFyzIrtjQq2QplcC0BkXve8SmQ8lkl2ZjVcX5Yggw+p rT8LLTFPGAFdTGQyzuc7nqXvuTWJwZeptTOUBo+ZA/OBsBiqCvhfAhBdXQUryDi4vmpn PAQq3KlqJk4Ha5zL44f4KkKyy3tYvkZ8NZ7PHaFM8eGAoKLFuym5XAiVV3LHl/dK2KVk 0VBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UHQEavkC; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be11-20020a056a001f0b00b004fa3a8e0053si1793878pfb.266.2022.05.19.23.10.38; Thu, 19 May 2022 23:10: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=@redhat.com header.s=mimecast20190719 header.b=UHQEavkC; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236617AbiESKUS (ORCPT + 99 others); Thu, 19 May 2022 06:20:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236612AbiESKUQ (ORCPT ); Thu, 19 May 2022 06:20:16 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 436DDA5AB7 for ; Thu, 19 May 2022 03:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652955614; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uTf4UazsnqFm1w0j9PjtulisgMFh6QzykfXouIHj8FI=; b=UHQEavkCYQ2B+KYfbRWaIYLMVNERwWKvnVBrkSywqBUXRYctQO84g2CjEucUEiXdYJQ6jN G8VN6P7+SZMQJP0fDox14t3Vn+vaiuAjgd8gf5sUKQZQ2LAiPk2aqU3g62CtWT/10BBrjt w6TRbRVVTk1y9V75aTTIWzq3wdrPyoQ= Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-650-oWp86idDN2SBwF3DDeBdlg-1; Thu, 19 May 2022 06:20:13 -0400 X-MC-Unique: oWp86idDN2SBwF3DDeBdlg-1 Received: by mail-pf1-f198.google.com with SMTP id m21-20020aa78a15000000b005182fda1b15so1925055pfa.21 for ; Thu, 19 May 2022 03:20:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uTf4UazsnqFm1w0j9PjtulisgMFh6QzykfXouIHj8FI=; b=H9hxMcRJEDBef7nLkABkrPQAZ6nPM8LOQLofFaMpPTtBwB1EhR/tMvm3WTdnGal21O hO1728zoYA0qmRHIPe1Cs7u0Ea40AOgpb3XXT/imxFwA/u/P5jQQt36tjaJiKLeil3De 0smFJeS0kp2Bq+Nj4l9kWISXannoU5g3ccc/IdH8SZ85gu3SW1ZotzgIs6YSP/JqeU5B NGQEkKyfPe4FeIuAsGNjIuN7DcHImdwEVFfijclNyysMfSi4otkarUc2Qx+dppJIoKck hpy5vKQGoTVPsO++PVcDfFrav1NKLKRoFit7AbU04YShQBzwD0H1GDSxD4JnIpX3e2Jz aGnA== X-Gm-Message-State: AOAM530mgTsz05s9nR1oWxksQFVKwbgw4GNg6Fs2wopFpGSE5HxVv97g lBSZ5xc2VA/lQxZLIpAZBR3fM5IdOtvTPh7M4aMnmq8nmgKLZy7OO4a+W+P5yvN/JnYmau53rN+ Eo3CwS2fKTcBmuXR52gDAUV7CCQK87Zrypn7oYZ+Q X-Received: by 2002:a17:903:22c6:b0:15f:14e1:1518 with SMTP id y6-20020a17090322c600b0015f14e11518mr4080929plg.116.1652955612087; Thu, 19 May 2022 03:20:12 -0700 (PDT) X-Received: by 2002:a17:903:22c6:b0:15f:14e1:1518 with SMTP id y6-20020a17090322c600b0015f14e11518mr4080890plg.116.1652955611775; Thu, 19 May 2022 03:20:11 -0700 (PDT) MIME-Version: 1.0 References: <20220518205924.399291-1-benjamin.tissoires@redhat.com> In-Reply-To: From: Benjamin Tissoires Date: Thu, 19 May 2022 12:20:00 +0200 Message-ID: Subject: Re: [PATCH bpf-next v5 00/17] Introduce eBPF support for HID devices To: Christoph Hellwig 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 , lkml , "open list:HID CORE LAYER" , Networking , bpf , "open list:KERNEL SELFTEST FRAMEWORK" , Linux Doc Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Thu, May 19, 2022 at 10:39 AM Christoph Hellwig wrote: > > On Thu, May 19, 2022 at 10:20:35AM +0200, Greg KH wrote: > > > are written using a hip new VM? > > > > Ugh, don't mention UDI, that's a bad flashback... > > But that is very much what we are doing here. > > > I thought the goal here was to move a lot of the quirk handling and > > "fixup the broken HID decriptors in this device" out of kernel .c code > > and into BPF code instead, which this patchset would allow. Yes, quirks are a big motivation for this work. Right now half of the HID drivers are less than 100 lines of code, and are just trivial fixes (one byte in the report descriptor, one key mapping, etc...). Using eBPF for those would simplify the process from the user point of view: you drop a "firmware fix" as an eBPF program in your system and you can continue working on your existing kernel. The other important aspect is being able to do filtering on the event streams themselves. This would mean for instance that you allow some applications to have access to part of the device features and you reject some of them. The main use case I have is to prevent applications to switch a device into its bootloader mode and mess up with the firmware. > > > > So that would just be exception handling. I don't think you can write a > > real HID driver here at all, but I could be wrong as I have not read the > > new patchset (older versions of this series could not do that.) Well, to be fair, yes and no. HID-BPF can only talk HID, and so we only act on arrays of bytes. You can mess up with the report descriptor or the events themselves, but you don't have access to other kernel APIs. So no, you can not write a HID-BPF driver that would manually create LEDs sysfs endpoints, input endpoints and battery endpoints. However, HID is very versatile in how you can describe a device. And the kernel now supports a lot of those features. So if you really want, you can entirely change the look of the device (its report descriptor), and rely on hid-core to export those LEDs, inputs and battery endpoints. But we already have this available by making use of hidraw+uhid. This involves userspace and there are already projects (for handling Corsair keyboard for example) which are doing exactly that, with a big security whole in the middle because the application is reading *all* events as they are flowing. One of the most important things here is that this work allows for context driven behavior. We can now control how a device is behaving depending on the actual application without having to design and maintain forever kernel APIs. For example, the Surface Dial is a puck that can have some haptic feedback when you turn it. However, when you enable the haptic feedback you have to reduce the resolution to one event every 5 degrees or the haptic feedback feels just wrong. But the device is capable of sub-degrees of event notifications. Which means you want the high resolution mode without haptic, and low res with haptic. Of course, you can use some new FF capabilities to enable/disable haptic, but we have nothing to change the resolution on the fly of a HID device, so we'll likely have to create another kernel API through a sysfs node or a kernel parameter. But then we need to teach userspace to use it and this kernel API is not standard, so it won't be used outside of this particular device. BPF in that case allows the application which needs it to do the changes it requires depending on the context. And when I say application, it is mostly either the compositor or a daemon, not gimp. > > And that "exception handling" is most of the driver. > Well, it depends. If hardware makers would not make crappy decisions based on the fact that it somehow works under Windows, we wouldn't have to do anything to support those devices. But for half of the drivers, we are doing dumb things to fix those devices in the kernel. On the other hand, we do have generic protocols in HID that can not be replaced by BPF. For the exercise, I tried to think about what it would take to rewrite the multitouch logic in eBPF, and trust me, you don't want that. The code would be a lot of spaghetti and would require access to many kernel APIs to handle it properly. Cheers, Benjamin