Message ID | 20230113090935.1763477-1-benjamin.tissoires@redhat.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp166737wrt; Fri, 13 Jan 2023 01:15:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXsaqY0PsKf1Xm5klF2arZJc0iHmlekDjYwR+LQ0HHxFFizVKw1oQyMDCtDDYTDeFsPWnoiY X-Received: by 2002:a05:6402:550a:b0:47f:bc9b:46ec with SMTP id fi10-20020a056402550a00b0047fbc9b46ecmr60448800edb.7.1673601314480; Fri, 13 Jan 2023 01:15:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673601314; cv=none; d=google.com; s=arc-20160816; b=V4ItaRnWADhlrJvqhQWd6E/1y/a5khZYAIVW8v2yljbl61RuxXPuInAx1om9VKzeq9 lRRdKWgMrZJlKTQVQe63xfVV1dLYuIeG27BCXogyo0C5CTHeno74fipj+giLuVFQ7zgA 8b1UBNcAT40TxszrjOHNPDqIhaTDuP+MLY0XbJe3LcK4EEj4OpQXN4FzQqd64tvMzd3b /csh9nPBoL8JzxmZ7xaZfYs5//+jg3wUFEEtLjN5suODzk8dzthWCH7X4YX+BCfSmI/H ol1ZZEopDEk1H/3bhOfOMDUza28b1XQT/JPYdpzlxq3bha30AQGy5uymuYDOVKju4TT2 U27Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=X4OMapMn4DPgQ6a+VqmEJlLUwkXj3/OngbIshLVda8U=; b=BMUqk+LUVa7gkPHKw40TzUrV8BtjKglcT84h2ZKB4h3mAuBEfrtA2fnbZXvBEDBuEZ 6Sar0txFL9xbd7YS3s4O6kgdjdLdXU0w0C8lustSmjTEa/ANriBI/yr1qA1k31lke7Jy //1quifLzmiNeFd4r/9HjeXMaa09smfIjyUpkm2yARnlsg7CwXsASM1O3GGRGe9UAas+ Qmaax3uzUEvEPkWiYlktyJ1KEUUtv2POqrayw7be+pwJfLsP3ybWawUTnWa9DZczmkmW kWMMrCphwSB7TS4lcKxdsJBeNG/Kabs+FPPiP+avvUSRdNGjAZLJXvW/vj7PHvrvwrmf cdlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TtUVPtWn; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y9-20020a056402440900b00489644e8bd0si25792008eda.610.2023.01.13.01.14.50; Fri, 13 Jan 2023 01:15:14 -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=@redhat.com header.s=mimecast20190719 header.b=TtUVPtWn; 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 S241217AbjAMJMb (ORCPT <rfc822;callmefire3@gmail.com> + 99 others); Fri, 13 Jan 2023 04:12:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240987AbjAMJMH (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 13 Jan 2023 04:12:07 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85F8B633E for <linux-kernel@vger.kernel.org>; Fri, 13 Jan 2023 01:09:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673600985; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=X4OMapMn4DPgQ6a+VqmEJlLUwkXj3/OngbIshLVda8U=; b=TtUVPtWnnN87PUcIZ0SOYL4gWxqHv2dHdAuokZm34KTtXQ7uKhmj/ZkFb5dGJNVa5yFY4s rCbSxw3Bjri1pDy/tLU+BKecQfIUXNpdZxskAzUgutVh8RfP1d1N5eaiNXlACoDoHU4s+n wFA49rG7zyAAV83r/agZVtny4jyJ/W4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-577-hrpH9WwZOmmcyoABtpkYUQ-1; Fri, 13 Jan 2023 04:09:40 -0500 X-MC-Unique: hrpH9WwZOmmcyoABtpkYUQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BA3C6858F0E; Fri, 13 Jan 2023 09:09:39 +0000 (UTC) Received: from plouf.redhat.com (ovpn-193-50.brq.redhat.com [10.40.193.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 529D11121314; Fri, 13 Jan 2023 09:09:37 +0000 (UTC) From: Benjamin Tissoires <benjamin.tissoires@redhat.com> To: Greg KH <gregkh@linuxfoundation.org>, Jiri Kosina <jikos@kernel.org>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Andrii Nakryiko <andrii@kernel.org>, Dmitry Torokhov <dmitry.torokhov@gmail.com> Cc: Tero Kristo <tero.kristo@linux.intel.com>, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, Benjamin Tissoires <benjamin.tissoires@redhat.com> Subject: [PATCH HID for-next v2 0/9] HID-BPF LLVM fixes, no more hacks Date: Fri, 13 Jan 2023 10:09:26 +0100 Message-Id: <20230113090935.1763477-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754898172237373470?= X-GMAIL-MSGID: =?utf-8?q?1754898172237373470?= |
Series |
HID-BPF LLVM fixes, no more hacks
|
|
Message
Benjamin Tissoires
Jan. 13, 2023, 9:09 a.m. UTC
Hi, So this is the fix for the bug that actually prevented me to integrate HID-BPF in v6.2. While testing the code base with LLVM, I realized that clang was smarter than I expected it to be, and it sometimes inlined a function or not depending on the branch. This lead to segfaults because my current code in linux-next is messing up the bpf programs refcounts assuming that I had enough observability over the kernel. So I came back to the drawing board and realized that what I was missing was exactly a bpf_link, to represent the attachment of a bpf program to a HID device. This is the bulk of the series, in patch 6/9. The other patches are cleanups, tests, and also the addition of the vmtests.sh script I run locally, largely inspired by the one in the bpf selftests dir. This allows very fast development of HID-BPF, assuming we have tests that cover the bugs :) changes in v2: - took Alexei's remarks into account and renamed the indexes into prog_table_index and hid_table_index - fixed unused function as reported by the Intel kbuild bot Cheers, Benjamin Benjamin Tissoires (9): selftests: hid: add vmtest.sh selftests: hid: allow to compile hid_bpf with LLVM selftests: hid: attach/detach 2 bpf programs, not just one selftests: hid: ensure the program is correctly pinned selftests: hid: prepare tests for HID_BPF API change HID: bpf: rework how programs are attached and stored in the kernel selftests: hid: enforce new attach API HID: bpf: clean up entrypoint HID: bpf: reorder BPF registration Documentation/hid/hid-bpf.rst | 12 +- drivers/hid/bpf/entrypoints/entrypoints.bpf.c | 9 - .../hid/bpf/entrypoints/entrypoints.lskel.h | 188 ++++-------- drivers/hid/bpf/hid_bpf_dispatch.c | 28 +- drivers/hid/bpf/hid_bpf_dispatch.h | 3 - drivers/hid/bpf/hid_bpf_jmp_table.c | 129 ++++---- include/linux/hid_bpf.h | 7 + tools/testing/selftests/hid/.gitignore | 1 + tools/testing/selftests/hid/Makefile | 10 +- tools/testing/selftests/hid/config.common | 241 +++++++++++++++ tools/testing/selftests/hid/config.x86_64 | 4 + tools/testing/selftests/hid/hid_bpf.c | 32 +- tools/testing/selftests/hid/progs/hid.c | 13 + tools/testing/selftests/hid/vmtest.sh | 284 ++++++++++++++++++ 14 files changed, 728 insertions(+), 233 deletions(-) create mode 100644 tools/testing/selftests/hid/config.common create mode 100644 tools/testing/selftests/hid/config.x86_64 create mode 100755 tools/testing/selftests/hid/vmtest.sh
Comments
On Fri, 13 Jan 2023, Benjamin Tissoires wrote: > Hi, > > So this is the fix for the bug that actually prevented me to integrate > HID-BPF in v6.2. > > While testing the code base with LLVM, I realized that clang was smarter > than I expected it to be, and it sometimes inlined a function or not > depending on the branch. This lead to segfaults because my current code > in linux-next is messing up the bpf programs refcounts assuming that I > had enough observability over the kernel. > > So I came back to the drawing board and realized that what I was missing > was exactly a bpf_link, to represent the attachment of a bpf program to > a HID device. This is the bulk of the series, in patch 6/9. > > The other patches are cleanups, tests, and also the addition of the > vmtests.sh script I run locally, largely inspired by the one in the bpf > selftests dir. This allows very fast development of HID-BPF, assuming we > have tests that cover the bugs :) > > > changes in v2: > - took Alexei's remarks into account and renamed the indexes into > prog_table_index and hid_table_index > - fixed unused function as reported by the Intel kbuild bot I've now applied this on top of the previous work in hid.git#for-6.3/hid-bpf