Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp145906pxm; Fri, 4 Mar 2022 18:26:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJygVCio7yhKT62fTiSt4JuIWa9unr5ykzTDaMI/1Lkm0vXDL2IRiuOPdfuDtSlNFwTg0VSP X-Received: by 2002:a17:90a:3e83:b0:1bf:3160:7f45 with SMTP id k3-20020a17090a3e8300b001bf31607f45mr1642501pjc.224.1646447167916; Fri, 04 Mar 2022 18:26:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646447167; cv=none; d=google.com; s=arc-20160816; b=KsJO537YXYcpWRuQ5V1/qb596gebVjJdAAR+IHmPXaRPRSfmxojj7iNgRWtXVJucUP lBpb0MmLMusOE9l5K4FUzrbYxzS2VPKGfL4KOFfavF3DXvTaFkL39oGBp1QB+L41ldWk 7TqbY4QQirIT09I7drl3LmhK8z69R7Wnx67eesWqbd1Lkniv3XgoSX0JcTPoUkij/4GX XVbJmxDpZVy0eZ0kbAXW/hxCyLJqtoaJ1CsPOsjE0WAM3SpOaelBKjirD/M7XLR6CjXs GkB5NTZCwij06FstfSTCCPkrapHrJdlT/AYMAQXhktvZEBTP2hemzfpVSfM5FE9Z3AZh xNhA== 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=Q7x15V5ZATyPDjTYGLcbLW8YNulA6g82+v54ib7KSCc=; b=xThwU3qVLGkOxQf70ZomI3a5UxjgUzZ7wG2WpFsWJJ6LgLbQYCPYlPUBazJwaMEswt ffn9lCRtHr6lwHX0xKrzTngVHjyMYBupasyA9Vz3SLgzvYZ141IEqRgFIYMTWfDVlzHa or1AcU7FtUCYN+2mzsWlw0uyVaSiKY4bLPIK68MD2wkQrf07xMM35f7SanGrKnpUUi0e 7vOubWl2zh/Lmq3Ad+JD2gNr7UcKNkK+9AwXlaEqaC81BfNcTVdB03PhSjjYCOihFzOO WUPW1OdvzDfdhWsN3/4JSmeK9Ol/N4hBWwoyNrzhaNeYswNwRS5zd1/5F048gWrTnhEf w43w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="c5/LqdcZ"; 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 y22-20020a634956000000b00375689989e8si6219791pgk.420.2022.03.04.18.25.51; Fri, 04 Mar 2022 18:26:07 -0800 (PST) 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="c5/LqdcZ"; 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 S230352AbiCEBO7 (ORCPT + 99 others); Fri, 4 Mar 2022 20:14:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbiCEBO6 (ORCPT ); Fri, 4 Mar 2022 20:14:58 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A57222452A; Fri, 4 Mar 2022 17:14:09 -0800 (PST) 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 1478D61760; Sat, 5 Mar 2022 01:14:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F6C9C340F3; Sat, 5 Mar 2022 01:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646442848; bh=vaBaHCp9DaFEapWiEZFao3YLd11lfyjPtyNq2m5VXs4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=c5/LqdcZfLOG1K7x4z+crxSvHxys5Zkw7f9QXyqpzs26ZTePy8t+0WwfcqMrN/+bL 7OU3ZWZcPFSiJEdUWxHxUilezuEjcF4oQsSLWZDefw7RU7+yQf6JYFeBiiFwNpBL+5 zheDWBqq8w34KXW1DeQAcMPyVzSlLEo/C5OUqeffQlUhhh+OQpkVI0aMAEyQVvGbcx 090qHvUTuLVHE08zvSEF4KwMRunGPqFd4srcdIieMD2n5NJ9xHH/NMUk5w1fQb/HQ6 9b+o7Dum29DB5legGE+aLzgcZ9HbFaFQmb4t6kAzbVMOL7UCGJcFGpDC4c8PC+k3jU 14wIbWL4XQElw== Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-2dc28791ecbso96077867b3.4; Fri, 04 Mar 2022 17:14:08 -0800 (PST) X-Gm-Message-State: AOAM530yzNX9zSgQtcryoFISWLCal/6lCu7vaUOsPUktTI/EPz/VN4+h aCZR/6uH6VpYMtFQ6xl3bUTbHHS7OYrGElk8Ud8= X-Received: by 2002:a81:23ce:0:b0:2dc:b20:cc73 with SMTP id j197-20020a8123ce000000b002dc0b20cc73mr1211954ywj.130.1646442847422; Fri, 04 Mar 2022 17:14:07 -0800 (PST) MIME-Version: 1.0 References: <20220304172852.274126-1-benjamin.tissoires@redhat.com> In-Reply-To: <20220304172852.274126-1-benjamin.tissoires@redhat.com> From: Song Liu Date: Fri, 4 Mar 2022 17:13:56 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next v2 00/28] Introduce eBPF support for HID devices 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 , Tero Kristo , open list , "open list:HID CORE LAYER" , Networking , bpf , linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.5 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 4, 2022 at 9:29 AM Benjamin Tissoires wrote: > > Hi, > > This is a followup of my v1 at [0]. > > The short summary of the previous cover letter and discussions is that > HID could benefit from BPF for the following use cases: > > - simple fixup of report descriptor: > benefits are faster development time and testing, with the produced > bpf program being shipped in the kernel directly (the shipping part > is *not* addressed here). > > - Universal Stylus Interface: > allows a user-space program to define its own kernel interface > > - Surface Dial: > somehow similar to the previous one except that userspace can decide > to change the shape of the exported device > > - firewall: > still partly missing there, there is not yet interception of hidraw > calls, but it's coming in a followup series, I promise > > - tracing: > well, tracing. > > > I tried to address as many comments as I could and here is the short log > of changes: > > v2: > === > > - split the series by subsystem (bpf, HID, libbpf, selftests and > samples) > > - Added an extra patch at the beginning to not require CAP_NET_ADMIN for > BPF_PROG_TYPE_LIRC_MODE2 (please shout if this is wrong) > > - made the bpf context attached to HID program of dynamic size: > * the first 1 kB will be able to be addressed directly > * the rest can be retrieved through bpf_hid_{set|get}_data > (note that I am definitivey not happy with that API, because there > is part of it in bits and other in bytes. ouch) > > - added an extra patch to prevent non GPL HID bpf programs to be loaded > of type BPF_PROG_TYPE_HID > * same here, not really happy but I don't know where to put that check > in verifier.c > > - added a new flag BPF_F_INSERT_HEAD for BPF_LINK_CREATE syscall when in > used with HID program types. > * this flag is used for tracing, to be able to load a program before > any others that might already have been inserted and that might > change the data stream. > > Cheers, > Benjamin > The set looks good so far. I will review the rest later. [...] A quick note about how we organize these patches. Maybe we can merge some of these patches like: > bpf: introduce hid program type > bpf/hid: add a new attach type to change the report descriptor > bpf/hid: add new BPF type to trigger commands from userspace I guess the three can merge into one. > HID: hook up with bpf > HID: allow to change the report descriptor from an eBPF program > HID: bpf: compute only the required buffer size for the device > HID: bpf: only call hid_bpf_raw_event() if a ctx is available I haven't read through all of them, but I guess they can probably merge as well. > libbpf: add HID program type and API > libbpf: add new attach type BPF_HID_RDESC_FIXUP > libbpf: add new attach type BPF_HID_USER_EVENT There 3 can merge, and maybe also the one below > libbpf: add handling for BPF_F_INSERT_HEAD in HID programs > samples/bpf: add new hid_mouse example > samples/bpf: add a report descriptor fixup > samples/bpf: fix bpf_program__attach_hid() api change Maybe it makes sense to merge these 3? > bpf/hid: add hid_{get|set}_data helpers > HID: bpf: implement hid_bpf_get|set_data > bpf/hid: add bpf_hid_raw_request helper function > HID: add implementation of bpf_hid_raw_request We can have 1 or 2 patches for these helpers > selftests/bpf: add tests for the HID-bpf initial implementation > selftests/bpf: add report descriptor fixup tests > selftests/bpf: add tests for hid_{get|set}_data helpers > selftests/bpf: add test for user call of HID bpf programs > selftests/bpf: hid: rely on uhid event to know if a test device is > ready > selftests/bpf: add tests for bpf_hid_hw_request > selftests/bpf: Add a test for BPF_F_INSERT_HEAD These selftests could also merge into 1 or 2 patches I guess. I understand rearranging these patches may take quite some effort. But I do feel that's a cleaner approach (from someone doesn't know much about HID). If you really hate it that way, we can discuss... Thanks, Song