Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp971382pxp; Wed, 16 Mar 2022 23:03:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoS7z57BMr8yDFXn/RiAytwqYR7YIiK5yhlsMAdlLOP5eHOpusXDmyQvLq359qSKJDOPWi X-Received: by 2002:a65:6382:0:b0:381:353c:8b39 with SMTP id h2-20020a656382000000b00381353c8b39mr2383622pgv.574.1647497034880; Wed, 16 Mar 2022 23:03:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647497034; cv=none; d=google.com; s=arc-20160816; b=d4w4Ya4sHhh5uEeMWtl5iKzaIdab7yoog41YuFeIDeGE1ABugqt1sK0JjT7QCTl3bj gq+00X+h92NXQgZU5V8t5sZ1qEi4lzyunE9K40TXpkLYunsrd5o5uNpbKO9pAoREHEAp GyB61e3artcHGR97Dv9qNvTKwyk02VF+U7ysheiYMRgAfHl0q9/D2+xRluF537xa20jA vLgwN+rJiy1SX8j/qCdpS5ZMfS6eDPR0lSvplyY/WgvZdomx/NRNyMxoqzBXMDe64Smg xH4GqR8BdIWyZj694GG7HVaARDc0GLAy1FzHAekYhq+4Maiz6W1KH/4Fqd5v54ywDPSZ zaFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=2+yfikDquq7TwpldmJYQCLvRUqC9fi3nsx25U4VkZPg=; b=RautXG/IQ6opHmYEZETihdVpwDjhTQpQSXQz44OMVDmkjky9e5yh1FDEKnuMFFtZw9 ho2zkXcaS8VI3QYi6Wgpxd4u7elqmFueqPjmAoYbQI9+KjgzgdD2P9f8aza1h/bvkuX6 T8cyvEcf+ycg5bHdfOveTe2Q54X4gGEr1QndTW5YZQwb1e3HoWJb2PshrKSdwapUR4uZ NDX5tc25CQgNnFdYaxlrjJCSZ9Ts06RfDAT46SYCtpnjjyHzNoEbQnnV03rAt6W2RanL RePC3UjA+E2S0LfH10/MKhgWKAlh58IdlwE5SR58cbh0IWE1AH+Uijf+/BnBtUDHYwK9 EoAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KvA5YrFx; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b9-20020a170902d50900b0015254d1bb93si3903808plg.61.2022.03.16.23.03.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 23:03:54 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KvA5YrFx; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C811A1BD99A; Wed, 16 Mar 2022 22:07:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350064AbiCOQaq (ORCPT + 99 others); Tue, 15 Mar 2022 12:30:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350010AbiCOQap (ORCPT ); Tue, 15 Mar 2022 12:30:45 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80D4A56C3E; Tue, 15 Mar 2022 09:29:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647361773; x=1678897773; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=5bWJ1aLHhnxNHrTHdW/lDQbheo4ws+MyK4EncLb5sbM=; b=KvA5YrFx2G3CWHBYBaMaGVg4YJiB5keas9t0cFEsg/KYBk8nj5f7PlT2 pTCIQ7j8m+XRM8oC835CmeZM8gnjMyO1r3U3VP4MXdtk/ZQTA0iNoxp1l T5P+S5Gi+cpz2HQZCgmL+Cf7Kbj6MFDvl7QK6gMsTMXOQKiP/6+FC/OH9 jsD1BM6kQdHqPlbqg1Qwr8skEi7CKPhYpsq0+SSM5itpK5fwgEwahJF0I WFPGzUQ4GkpC1fxAoCGRxN3POkrJ9irLvVlh0b39sqv/y8zfDjXbmMmcQ tVBVg8VveMqafE/jyMWbVJ/WTR2MB2DErzTgbUDHzicxDL2OXBjJ1qTCR A==; X-IronPort-AV: E=McAfee;i="6200,9189,10286"; a="281125062" X-IronPort-AV: E=Sophos;i="5.90,184,1643702400"; d="scan'208";a="281125062" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2022 09:29:19 -0700 X-IronPort-AV: E=Sophos;i="5.90,184,1643702400"; d="scan'208";a="690255507" Received: from lepple-mobl1.ger.corp.intel.com (HELO [10.252.56.30]) ([10.252.56.30]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2022 09:29:14 -0700 Message-ID: Date: Tue, 15 Mar 2022 18:29:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH bpf-next v2 03/28] HID: hook up with bpf Content-Language: en-US To: Benjamin Tissoires , 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 Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org References: <20220304172852.274126-1-benjamin.tissoires@redhat.com> <20220304172852.274126-4-benjamin.tissoires@redhat.com> From: Tero Kristo In-Reply-To: <20220304172852.274126-4-benjamin.tissoires@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_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 Hi Benjamin, On 04/03/2022 19:28, Benjamin Tissoires wrote: > Now that BPF can be compatible with HID, add the capability into HID. > drivers/hid/hid-bpf.c takes care of the glue between bpf and HID, and > hid-core can then inject any incoming event from the device into a BPF > program to filter/analyze it. > > Signed-off-by: Benjamin Tissoires > > --- > > changes in v2: > - split the series by bpf/libbpf/hid/selftests and samples > - addressed review comments from v1 > --- > drivers/hid/Makefile | 1 + > drivers/hid/hid-bpf.c | 157 +++++++++++++++++++++++++++++++++++++++++ > drivers/hid/hid-core.c | 21 +++++- > include/linux/hid.h | 11 +++ > 4 files changed, 187 insertions(+), 3 deletions(-) > create mode 100644 drivers/hid/hid-bpf.c > > diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile > index 6d3e630e81af..08d2d7619937 100644 > --- a/drivers/hid/Makefile > +++ b/drivers/hid/Makefile > @@ -4,6 +4,7 @@ > # > hid-y := hid-core.o hid-input.o hid-quirks.o > hid-$(CONFIG_DEBUG_FS) += hid-debug.o > +hid-$(CONFIG_BPF) += hid-bpf.o > > obj-$(CONFIG_HID) += hid.o > obj-$(CONFIG_UHID) += uhid.o > diff --git a/drivers/hid/hid-bpf.c b/drivers/hid/hid-bpf.c > new file mode 100644 > index 000000000000..8120e598de9f > --- /dev/null > +++ b/drivers/hid/hid-bpf.c > @@ -0,0 +1,157 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * BPF in HID support for Linux > + * > + * Copyright (c) 2022 Benjamin Tissoires > + */ > + > +#include > +#include > +#include > + > +#include > +#include > + > +static int __hid_bpf_match_sysfs(struct device *dev, const void *data) > +{ > + struct kernfs_node *kn = dev->kobj.sd; > + struct kernfs_node *uevent_kn; > + > + uevent_kn = kernfs_find_and_get_ns(kn, "uevent", NULL); > + > + return uevent_kn == data; > +} > + > +static struct hid_device *hid_bpf_fd_to_hdev(int fd) > +{ > + struct device *dev; > + struct hid_device *hdev; > + struct fd f = fdget(fd); > + struct inode *inode; > + struct kernfs_node *node; > + > + if (!f.file) { > + hdev = ERR_PTR(-EBADF); > + goto out; > + } > + > + inode = file_inode(f.file); > + node = inode->i_private; > + > + dev = bus_find_device(&hid_bus_type, NULL, node, __hid_bpf_match_sysfs); > + > + if (dev) > + hdev = to_hid_device(dev); > + else > + hdev = ERR_PTR(-EINVAL); > + > + out: > + fdput(f); > + return hdev; > +} > + > +static int hid_bpf_link_attach(struct hid_device *hdev, enum bpf_hid_attach_type type) > +{ > + int err = 0; > + > + switch (type) { > + case BPF_HID_ATTACH_DEVICE_EVENT: > + if (!hdev->bpf.ctx) { > + hdev->bpf.ctx = bpf_hid_allocate_ctx(hdev, HID_BPF_MAX_BUFFER_SIZE); > + if (IS_ERR(hdev->bpf.ctx)) { > + err = PTR_ERR(hdev->bpf.ctx); > + hdev->bpf.ctx = NULL; > + } > + } > + break; > + default: > + /* do nothing */ These cause following error:   CC      drivers/hid/hid-bpf.o drivers/hid/hid-bpf.c: In function ‘hid_bpf_link_attach’: drivers/hid/hid-bpf.c:88:2: error: label at end of compound statement    88 |  default:       |  ^~~~~~~ drivers/hid/hid-bpf.c: In function ‘hid_bpf_link_attached’: drivers/hid/hid-bpf.c:101:2: error: label at end of compound statement   101 |  default:       |  ^~~~~~~ drivers/hid/hid-bpf.c: In function ‘hid_bpf_array_detached’: drivers/hid/hid-bpf.c:116:2: error: label at end of compound statement   116 |  default:       |  ^~~~~~~ make[2]: *** [scripts/Makefile.build:288: drivers/hid/hid-bpf.o] Error 1 make[1]: *** [scripts/Makefile.build:550: drivers/hid] Error 2 make[1]: *** Waiting for unfinished jobs.... make: *** [Makefile:1831: drivers] Error 2 To fix that, you need to add a break statement at end: default:     /* do nothing */     break; Same for couple of other occurrences in the file. -Tero