Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp110438pxm; Fri, 4 Mar 2022 17:23:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyacc+UNjI1RlQuwJUYYIwnJl8+T+u8KO/pbBWrOt/1eoeYN5zxDAemRy8Km9X2eMchrPgR X-Received: by 2002:a05:6402:51cb:b0:409:e99f:bc1c with SMTP id r11-20020a05640251cb00b00409e99fbc1cmr1165211edd.68.1646443405906; Fri, 04 Mar 2022 17:23:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646443405; cv=none; d=google.com; s=arc-20160816; b=TIZyFqJsWX6FbJ0eHcQO05Sl4AptQJ24ul1Tf+YIHpPQh1hhkLwXCNDvrf9sQQMMFI AzH5BKGMuEhgMFlVJ98V39PV7GmZX91XtL2h1EZMqzXCuVF/5W6d4Sx64BGA5KytCdrJ 4wTD/VoPkUoyjgzZsm1kkZcZdAihplKe3rS+mhpPK+nsjbitj6fubBpJNNSiCk2A4NDP KMmYYi1PNNEQ4ssLF4xmmyCs3I1ZB/e2lo8h6kYcPfKPvOWH+/gR+2wDzAUraY7RUZG0 1C6x+EZPDJjASa7GZD/NvVzeW9DcEp5pltjFhia8wB5C2byDJTGTid+dIlRGuTyBBSA/ QvRQ== 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=1Qzkx6U9FdGieiJq6aXivrgI/Tw0mLF35G+UA5D8QTs=; b=DmhjkQGmnDRvTxN2HCM7WfThwqOSScRZZ04Eoui7ACQQek3eo2OWxVJWiU4AzZ78RX CA0eElkBW51xo5Kpdl5s+0klQZvkiDbi/3nf5V3nle/n/h5wjTSTIWL7Xn6OhT/bFfcl E7ETsL+hX2o6Mh6jbFLyOPxNzeFYhWRWedCL9QauGxLz88T1g21MNpvcO3PespXHKyx6 DoYD+dBeUqvnYVTIdw0ZZx5xigFDf2T/+ULWajADJFNWnypAP+bHoX2Qru+Mzgid2j2Q MS2sUeJ6m+Cc7z/SfkDOZYEzD9+05bgiVQu6I8hq1N95xhi/rnK/YM/CUcmkoHAaBUOY gGtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ExYDSE7c; 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 ht14-20020a170907608e00b006da978efc8csi4125267ejc.948.2022.03.04.17.22.47; Fri, 04 Mar 2022 17:23:25 -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=ExYDSE7c; 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 S230170AbiCEAY0 (ORCPT + 99 others); Fri, 4 Mar 2022 19:24:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbiCEAYZ (ORCPT ); Fri, 4 Mar 2022 19:24:25 -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 4A6587B555; Fri, 4 Mar 2022 16:23:37 -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 E670861F46; Sat, 5 Mar 2022 00:23:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57795C340F1; Sat, 5 Mar 2022 00:23:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646439816; bh=oVr0MHcRWA7BlyaKO3wuNIotdRH8J4KNzvrQ/jGVkD8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ExYDSE7cO64LbKB8MMqhdgVwaUEqsVziHk9DUkI6TrMrMdGWB8MweNd2sjAaQPcQA dybytGWsBzuR7B/vjZGVIcj4PAemUd72e06gAYDbQzWu7cIRc/nagMaPAP3B4RPUdX E+js8N6XrcSzImDyOEVwwdT/r3T9mpZC3Al5wbeoO7LqT1njD3pHihxj8SU/oUzI7C CwO5mm6lHFMgCBs3ji2dMn3kdAp4ov3Rm18qkxaWrHGP5JYE4NhGKx8mhfiXmo3xvk Jk2soRi+gzqQFqjRX8GV6yWvCg5ARMZuPi78da9+n27gspEm3iwHqoLxladL2N69ga w8LFjeBRdf9sQ== Received: by mail-yb1-f175.google.com with SMTP id l2so536534ybe.8; Fri, 04 Mar 2022 16:23:36 -0800 (PST) X-Gm-Message-State: AOAM530s/Y7Z9x6qlff4RSS5uF6Mcl/TGdITkGY0ppghpcBf8ahkdZLP 2UJ0B0kl3XJ3t3nGx51zPo98/Mho+jtzk4U85Tw= X-Received: by 2002:a25:8b81:0:b0:629:17d5:68c1 with SMTP id j1-20020a258b81000000b0062917d568c1mr415320ybl.449.1646439815376; Fri, 04 Mar 2022 16:23:35 -0800 (PST) MIME-Version: 1.0 References: <20220304172852.274126-1-benjamin.tissoires@redhat.com> <20220304172852.274126-4-benjamin.tissoires@redhat.com> In-Reply-To: <20220304172852.274126-4-benjamin.tissoires@redhat.com> From: Song Liu Date: Fri, 4 Mar 2022 16:23:24 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next v2 03/28] HID: hook up with bpf 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:31 AM 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 > [...] > + > +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 */ Do we need to show warning and/or return EINVAL here? > + } > + > + return err; > +} > + > +static void hid_bpf_array_detached(struct hid_device *hdev, enum bpf_hid_attach_type type) > +{ > + switch (type) { > + case BPF_HID_ATTACH_DEVICE_EVENT: > + kfree(hdev->bpf.ctx); > + hdev->bpf.ctx = NULL; > + break; > + default: > + /* do nothing */ ditto [...]