Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1531344lqt; Sat, 8 Jun 2024 02:04:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWoAt5ZnoScw1ove2C8WuKsn+rpk0hMDUy6fSQTsNn66MDtmDqmlmvgo+Fa7Pk/JQO0KDvdu4IxESYWS6Gd//WOAXTAvE+nlkfU3DZSIw== X-Google-Smtp-Source: AGHT+IGuXdzz+gGckeZVljokSbxeXldpYCDH8inXmjtm6KhlFnFRAYFS3wkcWU93Wk3JpfJrvbL8 X-Received: by 2002:a17:902:e842:b0:1f3:2f9c:bb72 with SMTP id d9443c01a7336-1f6d010ac6dmr73909185ad.5.1717837459207; Sat, 08 Jun 2024 02:04:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717837459; cv=pass; d=google.com; s=arc-20160816; b=tHxH1jYp/G+liMY9zzSNE+bVrR6Z4YV0tJ+9nYKRW/BnSXvSfDb6Gs8am/I8TmQTPY xtPSP9lQSnE/2sScfbXcdywpl7J4gkxLblLcjSjpxhNRNLUckw6LwKKNDWvQRRZNHqia 6y6Z4Xkc1fjVxpF00mGqUAUAZYTVxe5th6jyhQU+y7PnugQizz2tpR7kMQHE0xfKo2FV qOqTIscoHzd4hDrCAI8fnURPtM/CF+R3CkrQzMPm3tHm3L5qbA4fpDnJz1AkK9Xc40W6 RFl++zNS/zrj79vy+5kgR9A2QtPTf3CcnIpeTF6NUqzLbTBu7FYzC9kdEKx1olKilLEy Tkuw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:from :dkim-signature; bh=ecxqSA9V3RiE07pL8RQBi8hZKBVgRvlR8tiHkZyk90s=; fh=GHislm9NjheIzAtmFXE9wjIiJoQITOj4lgcgXUd2vD4=; b=dVYoiHUT60xup6JBo6UK/l0HvE5mJXkRdVRZCGTg7q+HWTlSgT4XRjAUNJbYuAxTFu Lynxj5bhLJMlmyvmvmKTi5JQ53o/ji/UCp6fT09cBXp5mQp7bJbMoKImyX05iRBXP7th j7U24YHYBgi0DRFzTfgqyCFO4G77soqK6YyY6WNP3GnPxZh7NQIFoO6GxQ2/Ql34RYcb qnggfuwrlAQbq+doI3P+WIngi8w6kMlHePHarU3Axnwiosrni5jeTD4gPgQxU/kc9JAj VOvbo5EUh1H9zOQvJNub+PrWY2QoM61AV8I6sKt438qxqY6SDaHvyZ7u55+No2POg5CT yP3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="hH1p/iri"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-206964-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206964-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f6bd76cc9bsi44407475ad.146.2024.06.08.02.04.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jun 2024 02:04:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206964-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="hH1p/iri"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-206964-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206964-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 3371DB20AF0 for ; Sat, 8 Jun 2024 09:01:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 639EB176FB3; Sat, 8 Jun 2024 09:01:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hH1p/iri" 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 6702B14286; Sat, 8 Jun 2024 09:01:22 +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=1717837282; cv=none; b=WKD/1ZOWj78d4S2bBNgPAlIsBglqoTHJtReZrwOC7zxCbUT+Il7H3151AXYKTHeL02t30rpR1lTNBouUeuHv7tOyTTnEcgLswqqJZYfr0G1iUKlmVyxx920yRggrol5WMKCBwVc5VD57+Il4ErGj1zLzDTCfHii0Qa128rC0Zvw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717837282; c=relaxed/simple; bh=1/f02kDBw63jQMXEE2MyvrNXy9Fmrvsga5uyBueYldU=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=VJW6X5TPYxdr4j0bV/mTR4dRSg9WIlHI4/BZF7VCo7ua6H9yUc5ksACzw16jqFsfP6knKrnzkUQTqAFkAQznlWd6lTxSaz33z4DDx7dKFDhoEjqHOu8YOkbpBKJjC3284G7Q98W47vto40dzNVucfhKQ/x0S8palH/3JOAv7+2w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hH1p/iri; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E931CC2BD11; Sat, 8 Jun 2024 09:01:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717837282; bh=1/f02kDBw63jQMXEE2MyvrNXy9Fmrvsga5uyBueYldU=; h=From:Subject:Date:To:Cc:From; b=hH1p/irimyi6Aj8+wOmhstheuhfSQ3HXxSHL/C82sJETZiZW77Ng+spiOtlHkKje3 Yd9tgYpPUbhe+VGLSeJNF2gG8x4iAJ6Wy/yMY4I9WzHVNklgx26KpJpCk6fhZAH4rO XHrzQKQA1jSjINJ5cnMJRQ5bpMhR0FkmNarwqwcl2ZdTJ4PVUsgehGc0NIk9Yy+OI1 c2dzrbfS3Cav5wBDy6XcFjIDOK3+Z4662XWEanY45HVrMFaoip2dRzsVCTx4ZmiICw 8B4j1JOT56EMMbt2HNWl+UGMgz7qyvaiK+NtkFbOpM7Dew6Raq2vg8bJiqbeVuIzUn pBMMt5e8S9oGw== From: Benjamin Tissoires Subject: [PATCH HID v3 00/16] HID: convert HID-BPF into using bpf_struct_ops Date: Sat, 08 Jun 2024 11:01:12 +0200 Message-Id: <20240608-hid_bpf_struct_ops-v3-0-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-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIANgdZGYC/23NQQ6CMBAF0KuQrq0pU1rQlQsXegZjCNIpNBpKW mw0hLvb1IUxYfnnZ96fiUdn0JN9NhOHwXhjhxj4JiNt3wwdUqNiJsCgYCLntDeqvo269pN7tlN tR0+RQw4NQCGEIPFxdKjNK6EXcjofyTUee+Mn695pKOSp+ppQrZkhp4xWrZSSKw2lqg53dAM+t tZ1yQvwMyQrVw2IBtc7oQvFAHbwZyzL8gETBKvu/gAAAA== To: Shuah Khan , Jiri Kosina , Jonathan Corbet , Alexei Starovoitov Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-input@vger.kernel.org, linux-doc@vger.kernel.org, Benjamin Tissoires , Peter Hutterer X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1717837279; l=4865; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=1/f02kDBw63jQMXEE2MyvrNXy9Fmrvsga5uyBueYldU=; b=WYrQH5UV88GmVipTdAZc3S7c0BkQKr494z3iEGoXNbpCnBRmEByfWsmN4fjuPtYo3Nz5PiwPz +cJFmmeI30ACDzALB/OnLLVNPfntXCi43L0dAEtzNaK4RetlkO8SGoB X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= The purpose of this series is to rethink how HID-BPF is invoked. Currently it implies a jmp table, a prog fd bpf_map, a preloaded tracing bpf program and a lot of manual work for handling the bpf program lifetime and addition/removal. OTOH, bpf_struct_ops take care of most of the bpf handling leaving us with a simple list of ops pointers, and we can directly call the struct_ops program from the kernel as a regular function. The net gain right now is in term of code simplicity and lines of code removal (though is an API breakage), but udev-hid-bpf is able to handle such breakages. In the near future, we will be able to extend the HID-BPF struct_ops with entrypoints for hid_hw_raw_request() and hid_hw_output_report(), allowing for covering all of the initial use cases: - firewalling a HID device - fixing all of the HID device interactions (not just device events as it is right now). The matching user-space loader (udev-hid-bpf) MR is at https://gitlab.freedesktop.org/libevdev/udev-hid-bpf/-/merge_requests/86 I'll put it out of draft once this is merged. Cheers, Benjamin Signed-off-by: Benjamin Tissoires --- Changes in v3: - took Alexei's review into account - Link to v2: https://lore.kernel.org/r/20240607-hid_bpf_struct_ops-v2-0-3f95f4d02292@kernel.org Changes in v2: - drop HID_BPF_FLAGS enum and use BPF_F_BEFORE instead - fix .init_members to not open code member->offset - allow struct hid_device to be writeable from HID-BPF for its name, uniq and phys - Link to v1: https://lore.kernel.org/r/20240528-hid_bpf_struct_ops-v1-0-8c6663df27d8@kernel.org --- Benjamin Tissoires (16): HID: rename struct hid_bpf_ops into hid_ops HID: bpf: add hid_get/put_device() helpers HID: bpf: implement HID-BPF through bpf_struct_ops selftests/hid: convert the hid_bpf selftests with struct_ops HID: samples: convert the 2 HID-BPF samples into struct_ops HID: bpf: add defines for HID-BPF SEC in in-tree bpf fixes HID: bpf: convert in-tree fixes into struct_ops HID: bpf: remove tracing HID-BPF capability selftests/hid: add subprog call test Documentation: HID: amend HID-BPF for struct_ops Documentation: HID: add a small blurb on udev-hid-bpf HID: bpf: Artist24: remove unused variable HID: bpf: error on warnings when compiling bpf objects bpf: allow bpf helpers to be used into HID-BPF struct_ops HID: bpf: rework hid_bpf_ops_btf_struct_access HID: bpf: make part of struct hid_device writable Documentation/hid/hid-bpf.rst | 173 ++++--- drivers/hid/bpf/Makefile | 2 +- drivers/hid/bpf/entrypoints/Makefile | 93 ---- drivers/hid/bpf/entrypoints/README | 4 - drivers/hid/bpf/entrypoints/entrypoints.bpf.c | 25 - drivers/hid/bpf/entrypoints/entrypoints.lskel.h | 248 --------- drivers/hid/bpf/hid_bpf_dispatch.c | 266 +++------- drivers/hid/bpf/hid_bpf_dispatch.h | 12 +- drivers/hid/bpf/hid_bpf_jmp_table.c | 565 --------------------- drivers/hid/bpf/hid_bpf_struct_ops.c | 298 +++++++++++ drivers/hid/bpf/progs/FR-TEC__Raptor-Mach-2.bpf.c | 9 +- drivers/hid/bpf/progs/HP__Elite-Presenter.bpf.c | 6 +- drivers/hid/bpf/progs/Huion__Kamvas-Pro-19.bpf.c | 9 +- .../hid/bpf/progs/IOGEAR__Kaliber-MMOmentum.bpf.c | 6 +- drivers/hid/bpf/progs/Makefile | 2 +- .../hid/bpf/progs/Microsoft__XBox-Elite-2.bpf.c | 6 +- drivers/hid/bpf/progs/Wacom__ArtPen.bpf.c | 6 +- drivers/hid/bpf/progs/XPPen__Artist24.bpf.c | 10 +- drivers/hid/bpf/progs/XPPen__ArtistPro16Gen2.bpf.c | 24 +- drivers/hid/bpf/progs/hid_bpf.h | 5 + drivers/hid/hid-core.c | 6 +- include/linux/hid_bpf.h | 119 +++-- samples/hid/Makefile | 5 +- samples/hid/hid_bpf_attach.bpf.c | 18 - samples/hid/hid_bpf_attach.h | 14 - samples/hid/hid_mouse.bpf.c | 26 +- samples/hid/hid_mouse.c | 39 +- samples/hid/hid_surface_dial.bpf.c | 10 +- samples/hid/hid_surface_dial.c | 53 +- tools/testing/selftests/hid/hid_bpf.c | 100 +++- tools/testing/selftests/hid/progs/hid.c | 100 +++- .../testing/selftests/hid/progs/hid_bpf_helpers.h | 19 +- 32 files changed, 800 insertions(+), 1478 deletions(-) --- base-commit: 70ec81c2e2b4005465ad0d042e90b36087c36104 change-id: 20240513-hid_bpf_struct_ops-e3212a224555 Best regards, -- Benjamin Tissoires