Received: by 2002:ab2:6486:0:b0:1ef:eae8:a797 with SMTP id de6csp50224lqb; Fri, 15 Mar 2024 14:52:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWeqIrMuBjX9Am89QWuIqwA98922gvckGLeRVGATxx/4h2o1XbIt5qxhGpGVuzdZm7/nGFZYXu8GBIx5XBVwnyVZtmk0rPAfLCBcMLdUg== X-Google-Smtp-Source: AGHT+IFNkGSewOtskAdAaZeJ+ld/JyqVq2PBodYXi5RVETji4CYSrq4au9zYikB69W2w8w8gmyH5 X-Received: by 2002:a05:6a00:2312:b0:6e5:eab8:4db8 with SMTP id h18-20020a056a00231200b006e5eab84db8mr7424655pfh.17.1710539558743; Fri, 15 Mar 2024 14:52:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710539558; cv=pass; d=google.com; s=arc-20160816; b=UrhyihYwrG0dDow9guuI+LNo+k0R5f8tkzsvBB47LaooXUG50hdi+SPWTIxKGhE1JH 9t5349/2+2fLWOrhEn3zSQPR7sbfhqJ25V36OlmBu+fVfK2pMhGzQNmyIeTDXA54In1B D+1mvw2dTfDlGPx2v75L3IsA2h/KtB8he4u22AnSfjFVQGqlWRqgHU2Fh977I+Aj0GYl YMciHFiyHDSBxxHfa6XxaEJDAd1jbhamZ2Gt91wHfcmhWqeAU0Iu1SFb/Iu5IVHL/oM+ Lt7/myDkwcnD/uan0ADXda+HbtzMeF6a9HBxTlskei00XP+D7y+N2CLoV+l+hrQ36dMr ZDvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=ZVnxJ9g62UEeeePtv4TFZg6ReNxfPFWR59o9aOsZ7X0=; fh=XTyUjB9aYGTasVm+CDcAtk7Px6DIhxl3+I+AjKQ5vTM=; b=0ozpQ/D9Z9akRujJZoSulY+/Z4/vDSToG8jafCfZ+8fEsLFhIeqb2ETUkbSe0AsDYM PKDs6IvNvHtxFu56KhiDbXs9bP6PF1z5MHdhoKncvceCPIlCa/Bry1asNO5bcYpkxl+7 kpY04AasJlrXZU7rTaJG8AdvcY4FaHNdkZrE4/5/usqlOaHxnl0Zyo/W04pwhPhNgIhQ 1fd7Z7lSXVX0JMfB3infFH7GKc/Wb+AVjOZxR0hPCEkpCfNrurR7mijBW5PrIicHiCw7 HNnskYiNWFPZFX1Ff1T4H396F97Xyd6OZBj7HNuZYRHt9ytotdNd+m+ID1vWecscIw/g imBg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=qDHTsKZe; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-104602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104602-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k10-20020aa79d0a000000b006e6cc8f90f5si4031568pfp.274.2024.03.15.14.52.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 14:52:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=qDHTsKZe; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-104602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104602-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8271228365D for ; Fri, 15 Mar 2024 15:55:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1AF440C04; Fri, 15 Mar 2024 15:55:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="qDHTsKZe" Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D37EA3D963; Fri, 15 Mar 2024 15:55:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710518146; cv=none; b=SEwWztWrNx/P2Y04srixVm4wa051GaLiaVWAhJmYSNmAiWFKDD51penysgBFXh+Y9aYmtnzKxM33BKZQY7FXxqHY/JhVmtjPdih5aM0M5O8n9oEHTJ736Ho9BBwjf3i8oeC5kZHse6974+4OwOY9ZZsBggSxv9BXX2IpncK7PgA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710518146; c=relaxed/simple; bh=6ip9Uj32dWRB+V8eh6SOYguo6Df3SxdRX95ROSWdS4M=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=TQg9/lTC/yykVZLerShDi/WtzznzjwflosZkBHaDNRhgKchV494XkpikBL2fBekhHyWigRURgEe2dQPomYgi9eTBaPNGsXrL+VE5Evhv/lLyvzU6EmlHVcifLaqZ92PxlCsyJcmWmU6XPuhoHaOhQbOHoPtpAhdHDP39F7TLG1A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=qDHTsKZe; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Sender:Reply-To:Content-ID:Content-Description; bh=ZVnxJ9g62UEeeePtv4TFZg6ReNxfPFWR59o9aOsZ7X0=; b=qDHTsKZeQqNiiNS+RC206jLqGQ HQEHYVnr9xz2S/5szXSF9n1CpAWNN8q/iN1TeevdT47fI633bcvyd2RDNNSaOHa7SkCaHCcJKNKmk ReyPdTEVYrGCB+Od93cmM+548OAAHUt+RMy3nvVVS9iMcvdNQedk9YU0mXjtqf5YEK2yfz3kRicU7 YoxjoCpJbt0g8gunrCWomp7y5NcSiitgRJBIxSN5FC6H9ItmgQIGHUUq2AjA+qiZzJZAIzwPAYcJB zRwVVgnQQD+XL05J8FHEfx27exG5HburFXdFHh19kyKvGurVQKvfokHrw6rWVSj7Fo0bfesd49uF5 1jEYkcKQ==; Received: from [50.53.2.121] (helo=[192.168.254.15]) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rl9uI-00000000jiF-2tEl; Fri, 15 Mar 2024 15:55:42 +0000 Message-ID: Date: Fri, 15 Mar 2024 08:55:41 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 5/7] HID: bpf: allow to inject HID event from BPF Content-Language: en-US To: Benjamin Tissoires , Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org References: <20240315-b4-hid-bpf-new-funcs-v4-0-079c282469d3@kernel.org> <20240315-b4-hid-bpf-new-funcs-v4-5-079c282469d3@kernel.org> From: Randy Dunlap In-Reply-To: <20240315-b4-hid-bpf-new-funcs-v4-5-079c282469d3@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/15/24 07:44, Benjamin Tissoires wrote: > It can be interesting to inject events from BPF as if the event were > to come from the device. > For example, some multitouch devices do not all the time send a proximity > out event, and we might want to send it for the physical device. > > Compared to uhid, we can now inject events on any physical device, not > just uhid virtual ones. > > Signed-off-by: Benjamin Tissoires > > --- > > no changes in v4 > > no changes in v3 > > no changes in v2 > --- > Documentation/hid/hid-bpf.rst | 2 +- > drivers/hid/bpf/hid_bpf_dispatch.c | 29 +++++++++++++++++++++++++++++ > drivers/hid/hid-core.c | 1 + > include/linux/hid_bpf.h | 2 ++ > 4 files changed, 33 insertions(+), 1 deletion(-) > > diff --git a/Documentation/hid/hid-bpf.rst b/Documentation/hid/hid-bpf.rst > index a575004d9025..0765b3298ecf 100644 > --- a/Documentation/hid/hid-bpf.rst > +++ b/Documentation/hid/hid-bpf.rst > @@ -179,7 +179,7 @@ Available API that can be used in syscall HID-BPF programs: > ----------------------------------------------------------- > > .. kernel-doc:: drivers/hid/bpf/hid_bpf_dispatch.c > - :functions: hid_bpf_attach_prog hid_bpf_hw_request hid_bpf_hw_output_report hid_bpf_allocate_context hid_bpf_release_context > + :functions: hid_bpf_attach_prog hid_bpf_hw_request hid_bpf_hw_output_report hid_bpf_input_report hid_bpf_allocate_context hid_bpf_release_context > > General overview of a HID-BPF program > ===================================== > diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c > index a5b88b491b80..e1a650f4a626 100644 > --- a/drivers/hid/bpf/hid_bpf_dispatch.c > +++ b/drivers/hid/bpf/hid_bpf_dispatch.c > @@ -508,6 +508,34 @@ hid_bpf_hw_output_report(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz) > kfree(dma_data); > return ret; > } > + > +/** > + * hid_bpf_input_report - Inject a HID report in the kernel from a HID device > + * > + * @ctx: the HID-BPF context previously allocated in hid_bpf_allocate_context() > + * @type: the type of the report (%HID_INPUT_REPORT, %HID_FEATURE_REPORT, %HID_OUTPUT_REPORT) > + * @buf: a %PTR_TO_MEM buffer > + * @buf__sz: the size of the data to transfer > + * > + * @returns %0 on success, a negative error code otherwise. Minimum change: @returns: Preferred change: Returns: "@returns" is not documented. > + */ > +__bpf_kfunc int > +hid_bpf_input_report(struct hid_bpf_ctx *ctx, enum hid_report_type type, u8 *buf, > + const size_t buf__sz) > +{ -- #Randy