Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2772008pxp; Tue, 22 Mar 2022 06:00:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxL/og67XA/TQ2lawHKgv1cvaaXIuqP+KAZvSTD/JdetdGDqcSQ8CTrc2+NAp/N4D015p3m X-Received: by 2002:a63:924e:0:b0:382:4fa8:e36d with SMTP id s14-20020a63924e000000b003824fa8e36dmr11670203pgn.426.1647954037874; Tue, 22 Mar 2022 06:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647954037; cv=none; d=google.com; s=arc-20160816; b=NsHU1ZJBK5Cf2lCZ6tv8Blk1QLBLFo5qm8ewbuJnRRHBDNyMpf1+BEwMSpTL2OarSo l5JtifCrzH5tuc/jRFt6/DnXMtT0ZqCAcLcfi2kokXhUFNqiBapIuQ0FVP+Zc3TPxCyB qlR/1ZobLpISVvDORMrqzLtaH+jG3o58fJI9eG/oEkCZLE/pJEWlW3feWAIIZeMKEmms E06QCOh5QhbXwZwA8Ouethn5G6aXbAhl8rAT07TCW+jR3sv/zmFeD3X4Hkj/9iGHza+P Mt2rA6S8jDnE48gfJrucbyqmKSM1LpO++S865FdZZvVDeFYZeR7KLjsCBQxDnd5CgF6+ SN+A== 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=FCN73VojYTO9kljcWQ13H5/nQPlAxw07sJxBf+2VjUA=; b=zpVc00c4Y5BfZkfi5Zqj7RMk2ZjD/4AF9quZKUN1mJJy6D4pnJzJXU0HfskoQUTeUA tazeU7ocRLSTVvMEkGgKXT5p5V5RU2F7F6xZ8Tkl2e5Yaf0/7MZmcVgeXmE7vkHKZ46p 9NfahhFmVxjZ7130+YFjojQsxQi1LnQQLqlA82YjtudkIL8X3CrBxkzqocl0Lt+VHfI2 fD0/GYZP8ZAAJXxghKt1y5cmTdoxV8bImkMny+mQpyZBniLJRS1zbxMSkVhPoNJYopKa /zv9gin6pPSbHF0QxKYtlhb/CU4ltMMWUx9tB7tKPqzRfBDuhTyOs6hS9X4DDkSx86FX 3bTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=H2Zq1cVo; 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 k11-20020a170902f28b00b00153b2d164a6si9233233plc.174.2022.03.22.06.00.19; Tue, 22 Mar 2022 06:00:37 -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=H2Zq1cVo; 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 S231460AbiCVLII (ORCPT + 99 others); Tue, 22 Mar 2022 07:08:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233889AbiCVLHx (ORCPT ); Tue, 22 Mar 2022 07:07:53 -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 ESMTP id D00136B086 for ; Tue, 22 Mar 2022 04:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647947184; 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: in-reply-to:in-reply-to:references:references; bh=FCN73VojYTO9kljcWQ13H5/nQPlAxw07sJxBf+2VjUA=; b=H2Zq1cVoJydixIK2B2CsbTdLcTbRe7kxljmiuqaaW/LETNRDoaPEs7LggRGM2BCptnvRsu kR4fff6qf9H5tuG+QS3noE7GmSOjKKlhHi/niNl4OGpQ/6TOD++N2SbEHqEx4/zml199eg mZaTkVscn6WMo5CEzL0X47N6hygNkF4= Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-251-Jn43R2x8NNKOLxVdmLMrcQ-1; Tue, 22 Mar 2022 07:06:23 -0400 X-MC-Unique: Jn43R2x8NNKOLxVdmLMrcQ-1 Received: by mail-pg1-f197.google.com with SMTP id m8-20020a637d48000000b003820515b5dcso7953586pgn.20 for ; Tue, 22 Mar 2022 04:06:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FCN73VojYTO9kljcWQ13H5/nQPlAxw07sJxBf+2VjUA=; b=Xw+rRqFtF7i6Xh6yuSAEEJxiP9mT4qHXWwi9DCmycMZGeXzMD/oKV7jU69//kPHUNZ bmXIsShSm4DCPFLJXoktK/9T2L+MgQVFdXvXA9O9u1hbVkuapJumAEx899Ck5T7pGX9w ljQ0H5ICm8fXg0x+TC/i5bd9C2afGnWu5hR1UldhzEk4Gtax/UnqjQfQdzfzOvnVoNuw FK1T9iDByAhy6vl3ZtgoijWT8o+SPw6KnkP5GeAxS5F5g1YmML3hLiocz/mBkLniEMxo bJVkzkuWBh/Vx2m8sAfYsWEIgs8g1lIkvXzUpHZ88TtzCyzjRFcwTxbGdVsjQCVJ37jE Iv2w== X-Gm-Message-State: AOAM530T64XRE+Z4W9xmx0thZ3fTGusU0BETVbKVQE+2cItEVyXz8eZT w36C2ZWYQYbk2OX8RMDhkE1eg4MVd17ycDWzQi7589eGWW3/4TTPmw/fyvhYu7QT3neg59Ba8bE 206nm5z0UCHV4tT04omPYj+uo/ii6aKK7KJbtnpsL X-Received: by 2002:a05:6a00:781:b0:4f4:2a:2d89 with SMTP id g1-20020a056a00078100b004f4002a2d89mr28353603pfu.13.1647947182454; Tue, 22 Mar 2022 04:06:22 -0700 (PDT) X-Received: by 2002:a05:6a00:781:b0:4f4:2a:2d89 with SMTP id g1-20020a056a00078100b004f4002a2d89mr28353561pfu.13.1647947182060; Tue, 22 Mar 2022 04:06:22 -0700 (PDT) MIME-Version: 1.0 References: <20220318161528.1531164-1-benjamin.tissoires@redhat.com> <20220318161528.1531164-3-benjamin.tissoires@redhat.com> In-Reply-To: From: Benjamin Tissoires Date: Tue, 22 Mar 2022 12:06:11 +0100 Message-ID: Subject: Re: [PATCH bpf-next v3 02/17] bpf: introduce hid program type To: Song Liu 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 , Jonathan Corbet , Tero Kristo , open list , "open list:HID CORE LAYER" , Networking , bpf , linux-kselftest@vger.kernel.org, Linux Doc Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.9 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_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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 Mon, Mar 21, 2022 at 10:52 PM Song Liu wrote: > > On Mon, Mar 21, 2022 at 9:07 AM Benjamin Tissoires > wrote: > > > > Hi Song, > > > > many thanks for the quick response. > > > > On Fri, Mar 18, 2022 at 9:48 PM Song Liu wrote: > [...] > > > > > > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > > > > > > We need to mirror these changes to tools/include/uapi/linux/bpf.h. > > > > OK. I did that in patch 4/17 but I can bring in the changes there too. > > Let's keep changes to the two files in the same patch. This will make > sure they are back ported together. Ack > > [...] > > > > +enum hid_bpf_event { > > > > + HID_BPF_UNDEF = 0, > > > > + HID_BPF_DEVICE_EVENT, /* when attach type is BPF_HID_DEVICE_EVENT */ > > > > + HID_BPF_RDESC_FIXUP, /* ................... BPF_HID_RDESC_FIXUP */ > > > > + HID_BPF_USER_EVENT, /* ................... BPF_HID_USER_EVENT */ > > > > > > Why don't we have a DRIVER_EVENT type here? > > > > For driver event, I want to have a little bit more of information > > which tells which event we have: > > - HID_BPF_DRIVER_PROBE > > - HID_BPF_DRIVER_SUSPEND > > - HID_BPF_DRIVER_RAW_REQUEST > > - HID_BPF_DRIVER_RAW_REQUEST_ANSWER > > - etc... > > > > However, I am not entirely sure on the implementation of all of those, > > so I left them aside for now. > > > > I'll work on that for v4. > > This set is already pretty big. I guess we can add them in a follow-up set. > > > > > > > > > > > > > [...] [...] > > > > + > > > > +static int hid_bpf_prog_test_run(struct bpf_prog *prog, > > > > + const union bpf_attr *attr, > > > > + union bpf_attr __user *uattr) > > > > +{ > > > > + struct hid_device *hdev = NULL; > > > > + struct bpf_prog_array *progs; > > > > + bool valid_prog = false; > > > > + int i; > > > > + int target_fd, ret; > > > > + void __user *data_out = u64_to_user_ptr(attr->test.data_out); > > > > + void __user *data_in = u64_to_user_ptr(attr->test.data_in); > > > > + u32 user_size_in = attr->test.data_size_in; > > > > + u32 user_size_out = attr->test.data_size_out; > > > > + u32 allocated_size = max(user_size_in, user_size_out); > > > > + struct hid_bpf_ctx_kern ctx = { > > > > + .type = HID_BPF_USER_EVENT, > > > > + .allocated_size = allocated_size, > > > > + }; > > > > + > > > > + if (!hid_hooks.hdev_from_fd) > > > > + return -EOPNOTSUPP; > > > > + > > > > + if (attr->test.ctx_size_in != sizeof(int)) > > > > + return -EINVAL; > > > > > > ctx_size_in is always 4 bytes? > > > > Yes. Basically what I had in mind is that the "ctx" for > > user_prog_test_run is the file descriptor to the sysfs that represent > > the HID device. > > This seemed to me to be the easiest to handle for users. > > > > I'm open to suggestions though. > > How about we use data_in? ctx for test_run usually means the program ctx, > which is struct hid_bpf_ctx here. > I'd rather not use data_in. data_in is forwarded as it is in the ctx of the program, so adding a bulky API where the first byte is the target_fd doesn't make a lot of sense IMO. However, I just managed to achieve what I initially wanted to do without luck: just use the struct bpf_prog as the sole argument. I thought iterating over all hid devices would be painful, but it turns out that is exactly what hid_bpf_fd_to_hdev() was doing, so there is no penalty in doing so. Anyway, I'll drop ctx_in in the next version. Cheers, Benjamin