Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp783918pxp; Fri, 11 Mar 2022 15:03:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRyhJShmIncDfkIfTN3iEi6T7YFfio7c+izW1EELZi1jYzx2I5JHUg9A2jA9CFOY4O2os+ X-Received: by 2002:a05:6808:2008:b0:2da:5b12:83ff with SMTP id q8-20020a056808200800b002da5b1283ffmr7015337oiw.216.1647039812913; Fri, 11 Mar 2022 15:03:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647039812; cv=none; d=google.com; s=arc-20160816; b=lQ3lDq9nyQP23AXnxkw5f3xNjXys9JpfDKd/Hiy8sNc2F5jLF8/lhOu7mcbvNiYV0A p8/lFHK00lW0d0iz780h+tdNxcGR1BXGe+/0M9gpfasP1EDaHfKAAw58QS8TpnFS2xV8 8Lw1+r/FRLu0qBs4kLESvQ4BP0RuCEijQ0Q5gcElNMCxZqHdzTCnlil81dLCC3EHG/od freg7dH6ZDoMvAUegBQ9wD5xGwdL8uh1/8yaHnj6PuEafdyamqeLun3AHfdApjL+DNma Ijj3dJTaUkGimJ0kJ3cR3qp8iI5PuIZsv0EUmaaaKCyUVktRAbsK2r7av1TtXtaBgtvv YgwQ== 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=nTibLaa7VSc2sd97foSLAnz92HytVTF20fOGm+yfyv4=; b=mcZejN3FSjGuRUL0/wbdtJ08a0XjV/R/xQqhSaLIW7sEBoOtQb81N/Tm5tGOwrgBNc gpWlqiObe3IFhwiGtW5locCBpE7IeT5NBIP1eHiRCEd9RYjjvdDolAvL0urfyvVV7b/w Vrz0e9a659oXhLfifjLxo2EW+62rwGXQPoRhPsFfjfzWv4SxDqG1XQ3HRo8bNmCYxVYp MXRYVafTIQMbySHx6UdYDsTS5bVcA67yuB7fuTN4T47DZ+8Wv9r4BYA0i53nvFcqRNcH wrU8O7XLOUHtTkWqXfoZGZS7QDzNgb5hDEXWbTZjLdQ7dBx6DUzCUawzWvavWDf1qxvR +FNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PX6k1L5s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p1-20020a05683003c100b005b249d7941csi6942421otc.194.2022.03.11.15.03.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 15:03:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PX6k1L5s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 743AA383692; Fri, 11 Mar 2022 13:59:54 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245687AbiCKArg (ORCPT + 99 others); Thu, 10 Mar 2022 19:47:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233264AbiCKArd (ORCPT ); Thu, 10 Mar 2022 19:47:33 -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 046211A2726; Thu, 10 Mar 2022 16:46:31 -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 8C24661DED; Fri, 11 Mar 2022 00:46:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED507C36AE2; Fri, 11 Mar 2022 00:46:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646959590; bh=z4PBUXUf97IEqo5TmTB3f5LWOKqJlW54EZ7PXln0eZM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=PX6k1L5s+p98QZGYkwnhIE4SXxnO02U7VG8T1P91HFaNN+gVx8naoi8E5wH2a0jiZ kqhxq4Yk79KPzfTjDmua43R5CS80I+OX9Igyi/N7FPIH1ejrPeDaEzjmLae8wjDMFY sVU7QmUr3ArT/hQD/pTsLQUt5UnbglPRWRkW4s+FtazApzizr/B2L5tUvfjbRU5uzv L2jb8z/kXDwvnNSj9bhcVT/V4PdJ+47wTzewKs26G7TEGV9PpX0O6rOxMCW/jTW28x 4RELUwiOZw9Og22S0DitLXRPEfFg/rsNrFq5jCeeH3zSSAJ/3zXL9SsZTZWfTHik3n qsZSZsCWOVZYA== Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-2db569555d6so77374107b3.12; Thu, 10 Mar 2022 16:46:29 -0800 (PST) X-Gm-Message-State: AOAM531e/V9SJNg8f9nr5M48mLi1ZUsh2MwLX5V29sVPSY1M9d41MhRH qy6cwBReX2P6NL2Mz99preqKjWN5gcaO75w8k80= X-Received: by 2002:a0d:fb45:0:b0:2d0:d09a:576c with SMTP id l66-20020a0dfb45000000b002d0d09a576cmr6506977ywf.447.1646959588931; Thu, 10 Mar 2022 16:46:28 -0800 (PST) MIME-Version: 1.0 References: <20220304172852.274126-1-benjamin.tissoires@redhat.com> <20220304172852.274126-16-benjamin.tissoires@redhat.com> In-Reply-To: <20220304172852.274126-16-benjamin.tissoires@redhat.com> From: Song Liu Date: Thu, 10 Mar 2022 16:46:18 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next v2 15/28] bpf/hid: add new BPF type to trigger commands from userspace 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=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, 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 On Fri, Mar 4, 2022 at 9:33 AM Benjamin Tissoires wrote: > > Given that we can not call bpf_hid_raw_request() from within an IRQ, > userspace needs to have a way to communicate with the device when > it needs. > > Implement a new type that the caller can run at will without being in > an IRQ context. > > Signed-off-by: Benjamin Tissoires > > --- [...] > + if (user_size_out && data_out) { > + user_size_out = min3(user_size_out, (u32)ctx->size, (u32)ctx->allocated_size); > + > + if (copy_to_user(data_out, ctx->data, user_size_out)) { > + ret = -EFAULT; > + goto unlock; > + } > + > + if (copy_to_user(&uattr->test.data_size_out, > + &user_size_out, > + sizeof(user_size_out))) { > + ret = -EFAULT; > + goto unlock; > + } > + } > + > + if (copy_to_user(&uattr->test.retval, &ctx->u.user.retval, sizeof(ctx->u.user.retval))) { > + ret = -EFAULT; > + goto unlock; nit: this goto is not really needed. > + } > + > +unlock: > + kfree(ctx); > + > + mutex_unlock(&bpf_hid_mutex); > + return ret; > +} [...]