Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp409669rwe; Wed, 24 Aug 2022 03:12:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR4VIO1+vw1nMfoArBV/hyL9vn9u6EPcsSaCQsbdmuWJhiRFkUFk5ARStyXGTyBhN3s08wtM X-Received: by 2002:a17:907:1c1b:b0:73d:6a20:5664 with SMTP id nc27-20020a1709071c1b00b0073d6a205664mr2409978ejc.583.1661335919856; Wed, 24 Aug 2022 03:11:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661335919; cv=none; d=google.com; s=arc-20160816; b=TtwgGO3pLW9cznr5kM8Rf0i7oDlqqPiD8pr44qXE8dSdX9sIaJUGXl1ojWYgbIBivl 11fUSnrGlvUkoZlkavtp79I8W3Kr1R1Kb0kbEG23TmAMtp+/fzqZEy1CfwlTQGaQ5uEa HMmb69sOQrfNjFQVo82yvKcTSaw4+zRr2/QuLVqOvt47MwGYrnWvti+nxsCXf5igdTQn lqJRRMpXqfV75y1MLSu3xxqKG6us3aXV3pqfjKkyX/u0sndz/363qTMc/K+qCc9HrtT2 iTIX/D68jxmSvXqmbDUJAbP/ds7PBHP1oHgA4W/UWTNmqClTCbFIKubVDLyWXsDb3PnL 2qHg== 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=qiF7/qO+yisg9qjBhsaAka2ZWunzOCu9/3xjQqLrf9U=; b=aeGFWss+0AjI0OHLknmdnnn5XMva04KewMrC+t99Rtseuqk29QUalIdsRE1A/ZTnaf GA4rf4F6Vy2ldlKVJLgIVVHAFPqZE2lIa2Qed1vQFwTMm7asmK9imjLoKKRtN90bm5xY UzYXxZ2GZeJgoqI1S806PwjUAaHlXZJpZk39n7fq5H8tEdZKRmgpolz2sjCi+PKADZHP aXE34nbb1LEBzUER0h6685H9u3sJOBX8vXSfrCWd4yueXhlyWJO2BMz+E4GiVIR5BxCi oHlSiHcQu2s9IYDtHn+GyXzkpa0CBMEplAvhqrrqJ8WovnSr/KF7hF+z6coxIr6i/vTc oOEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="W/bo8nXP"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k5-20020a170906158500b007312789a037si1635642ejd.144.2022.08.24.03.11.33; Wed, 24 Aug 2022 03:11:59 -0700 (PDT) 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="W/bo8nXP"; 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 S232570AbiHXJtB (ORCPT + 99 others); Wed, 24 Aug 2022 05:49:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231569AbiHXJs4 (ORCPT ); Wed, 24 Aug 2022 05:48:56 -0400 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 F238A67461 for ; Wed, 24 Aug 2022 02:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661334533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qiF7/qO+yisg9qjBhsaAka2ZWunzOCu9/3xjQqLrf9U=; b=W/bo8nXPtT+PU5WnRFJIDATmKMhacIvKXHQ2QlE8c7KXZM7ev5BWeRzLafoVF3YY62WmFG BV2+Jjuq8roy29BGbfkcfMz6cen2cca5OzZn9z9nUaMWVuPJ88ffyEIcdgiD04kaH567Ig eRUCAUl7KVuLAiVh/tFVJcPnOgUPnFI= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-621-RXAJFgQlM4OdnAR1CGXRXA-1; Wed, 24 Aug 2022 05:48:52 -0400 X-MC-Unique: RXAJFgQlM4OdnAR1CGXRXA-1 Received: by mail-wr1-f72.google.com with SMTP id v19-20020adf8b53000000b00225728573e6so157432wra.21 for ; Wed, 24 Aug 2022 02:48:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=qiF7/qO+yisg9qjBhsaAka2ZWunzOCu9/3xjQqLrf9U=; b=F/AJda+xd46q2zo/VKb02eqVN1AHdJ+HFmNhyWfdXVFYEvBTlm55RznFIX9e+5+4EY cZuedM/z0csY5qNmjQEOa8nELkUlo5iSXLJZikrwCswPfRN7EVcu6nzt0IAjgrPo+pdr s4TWOJmD2Z3NcijTJLO5sKPeW6FAShV5o1h/iw0pw+NbGhji5KsnmtRuPG1nOsWngnX9 mAOTcZQ/cPaTdftd7T8HykEtIukQZhCB228OZ/ziorEknIe0m7cMqvRuX1nNdsk1jDIn wW/dMBx+vZFoqUDaUyILTiipQUhl6sDOjKuipx3GTrDy6q1bxvOvutOab+b+3UxM/cSI oboQ== X-Gm-Message-State: ACgBeo0N77n11whFYX7fCDrTljk3wEbB2+k6Gc6DHN30HGpFOzSpwhfk /csMJeCD96Weoh9ZhtiCdWjlMcTefYfO51DVH6fsqyDdpFpE+uqtxrn4qUVPDus0hJmdotk/+KI 9Y/bqSI3HFklGABjNrzphUxA8 X-Received: by 2002:a5d:5986:0:b0:225:6216:5a79 with SMTP id n6-20020a5d5986000000b0022562165a79mr5828993wri.594.1661334530994; Wed, 24 Aug 2022 02:48:50 -0700 (PDT) X-Received: by 2002:a5d:5986:0:b0:225:6216:5a79 with SMTP id n6-20020a5d5986000000b0022562165a79mr5828965wri.594.1661334530719; Wed, 24 Aug 2022 02:48:50 -0700 (PDT) Received: from [192.168.110.200] (82-65-22-26.subs.proxad.net. [82.65.22.26]) by smtp.gmail.com with ESMTPSA id n5-20020a05600c4f8500b003a601a1c2f7sm1367229wmq.19.2022.08.24.02.48.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Aug 2022 02:48:50 -0700 (PDT) Message-ID: Date: Wed, 24 Aug 2022 11:48:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH bpf-next v7 13/24] HID: initial BPF implementation Content-Language: en-US To: Greg KH Cc: Jiri Kosina , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , Kumar Kartikeya Dwivedi , John Fastabend , KP Singh , Shuah Khan , Dave Marchevsky , Joe Stringer , Jonathan Corbet , Tero Kristo , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org References: <20220721153625.1282007-1-benjamin.tissoires@redhat.com> <20220721153625.1282007-14-benjamin.tissoires@redhat.com> From: Benjamin Tissoires In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_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 On 7/28/22 16:19, Greg KH wrote: > On Thu, Jul 21, 2022 at 05:36:14PM +0200, Benjamin Tissoires wrote: >> --- /dev/null >> +++ b/include/linux/hid_bpf.h >> @@ -0,0 +1,102 @@ >> +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ > > This is not a uapi .h file, so the "WITH Linux-syscall-note" should not > be here, right? thanks, dropping this syscall note from the series. > > >> + >> +#ifndef __HID_BPF_H >> +#define __HID_BPF_H >> + >> +#include >> +#include >> +#include >> + >> +struct hid_device; >> + >> +/* >> + * The following is the HID BPF API. >> + * >> + * It should be treated as UAPI, so extra care is required >> + * when making change to this file. > > So is this uapi? If so, shouldn't it go into a uapi include directory > so we know this and properly track it and maintain it that way? IMO it's a grey area. It is not "uapi" because it doesn't export anything that userspace can use. A userspace program can not include that and use it in other words. So strictly speaking, it's a normal part of a kernel header file, because it's a description of what other kernel users (though here, eBPF programs) can use. But I really want that part of the API to be considered as "stable" and give some guarantees to the users that I won't change it at every release. Thus the "uapi-like". > >> + */ >> + >> +/** >> + * struct hid_bpf_ctx - User accessible data for all HID programs >> + * >> + * ``data`` is not directly accessible from the context. We need to issue >> + * a call to ``hid_bpf_get_data()`` in order to get a pointer to that field. >> + * >> + * All of these fields are currently read-only. >> + * >> + * @index: program index in the jump table. No special meaning (a smaller index >> + * doesn't mean the program will be executed before another program with >> + * a bigger index). >> + * @hid: the ``struct hid_device`` representing the device itself >> + * @report_type: used for ``hid_bpf_device_event()`` >> + * @size: Valid data in the data field. >> + * >> + * Programs can get the available valid size in data by fetching this field. >> + */ >> +struct hid_bpf_ctx { >> + __u32 index; >> + const struct hid_device *hid; >> + enum hid_report_type report_type; >> + __s32 size; >> +}; >> + >> +/* Following functions are tracepoints that BPF programs can attach to */ >> +int hid_bpf_device_event(struct hid_bpf_ctx *ctx); >> + >> +/* Following functions are kfunc that we export to BPF programs */ >> +/* only available in tracing */ >> +__u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, const size_t __sz); >> + >> +/* only available in syscall */ >> +int hid_bpf_attach_prog(unsigned int hid_id, int prog_fd, __u32 flags); >> + >> +/* >> + * Below is HID internal >> + */ >> + >> +/* internal function to call eBPF programs, not to be used by anybody */ >> +int __hid_bpf_tail_call(struct hid_bpf_ctx *ctx); >> + >> +#define HID_BPF_MAX_PROGS_PER_DEV 64 >> +#define HID_BPF_FLAG_MASK (((HID_BPF_FLAG_MAX - 1) << 1) - 1) >> + >> +/* types of HID programs to attach to */ >> +enum hid_bpf_prog_type { >> + HID_BPF_PROG_TYPE_UNDEF = -1, >> + HID_BPF_PROG_TYPE_DEVICE_EVENT, /* an event is emitted from the device */ >> + HID_BPF_PROG_TYPE_MAX, >> +}; >> + >> +struct hid_bpf_ops { >> + struct module *owner; >> + struct bus_type *bus_type; >> +}; >> + >> +extern struct hid_bpf_ops *hid_bpf_ops; >> + >> +struct hid_bpf_prog_list { >> + u16 prog_idx[HID_BPF_MAX_PROGS_PER_DEV]; >> + u8 prog_cnt; >> +}; >> + >> +/* stored in each device */ >> +struct hid_bpf { >> + struct hid_bpf_prog_list __rcu *progs[HID_BPF_PROG_TYPE_MAX]; /* attached BPF progs */ >> + bool destroyed; /* prevents the assignment of any progs */ >> + >> + spinlock_t progs_lock; /* protects RCU update of progs */ >> +}; >> + >> +#ifdef CONFIG_HID_BPF >> +int dispatch_hid_bpf_device_event(struct hid_device *hid, enum hid_report_type type, u8 *data, >> + u32 size, int interrupt); >> +void hid_bpf_destroy_device(struct hid_device *hid); >> +void hid_bpf_device_init(struct hid_device *hid); >> +#else /* CONFIG_HID_BPF */ >> +static inline int dispatch_hid_bpf_device_event(struct hid_device *hid, enum hid_report_type type, u8 *data, >> + u32 size, int interrupt) { return 0; } >> +static inline void hid_bpf_destroy_device(struct hid_device *hid) {} >> +static inline void hid_bpf_device_init(struct hid_device *hid) {} >> +#endif /* CONFIG_HID_BPF */ >> + >> +#endif /* __HID_BPF_H */ >> diff --git a/include/uapi/linux/hid_bpf.h b/include/uapi/linux/hid_bpf.h >> new file mode 100644 >> index 000000000000..ba8caf9b60ee >> --- /dev/null >> +++ b/include/uapi/linux/hid_bpf.h >> @@ -0,0 +1,25 @@ >> +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ > > This is fine, it is in include/uapi/ > > Other than those minor comments, this all looks good to me! > > Reviewed-by: Greg Kroah-Hartman > Great! And thanks a lot for the other reviews. I finally managed to get some time to work on it after some time off and urgent sh**t happening, so I'll send a new version of the series today. Cheers, Benjamin