Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1060659rdb; Fri, 9 Feb 2024 09:06:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVAtzA1Td1pIaVQJly/MOzgcX7+ayK3eeGxsrMk5LxcXzhe7yxKpeUU6+9vnCb3dOpbKiUwLdf1WjMR8YQ3SCjRvtDFlDTEVtUjZ3IGjQ== X-Google-Smtp-Source: AGHT+IFVVvY8EId9k1D/vQakjl2J9w8I47JwItY8k+vtA+knD/O2R6/PmiNi5/ZywukWubgmjD6N X-Received: by 2002:a05:6870:d628:b0:219:b896:ce4d with SMTP id a40-20020a056870d62800b00219b896ce4dmr1967422oaq.50.1707498387105; Fri, 09 Feb 2024 09:06:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707498387; cv=pass; d=google.com; s=arc-20160816; b=TbR9MJ5mtx+uaExNbUpDG1DNx4VcZfIoJj1lY6CN+aBSdgsggdG1iTWuNJAxQKYbDg BuFoeQdIeI+a+y/VQdIdpoCmsmvxibaRmGp454ImPBC6Rs/gDu9qbAWIK4vT+KbJQKiW 5bltNbjqOokTRd6vbVXLr6zQZCPRNFeyIB8enGAdlEsWf+Zn0BNMt0i5Ok3hXfMRjBYq QrSE4s1NhgrT3MRgLzbndEg3YMPBfReZ1vVnyW4Kb1R5uAPGjNr+anyekgAWGfyFSt72 xUW3o2JzpVFTjD8qeAfcKuZEwgbr8tnX93n/+ojm8PMYe1Cj3SvUmcAn9f3IAC+A5Bpb Fctw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=xwZzEC5N9Tk3OxSnesPK34/6ccpOLSW0y1TDD6td8Xw=; fh=mnriUz0xYNtKdpx7YNZ8TEh52ioYXlkVlE5Z3YerACo=; b=oT++2LxdEUh0l1Qkkz6OFtatdQWxwQThaGqzif8P6bDmqQCfhMtKTuZ9e1l6j2H7ik A3SxCvqYKdikhojI/mSJqbfApWpePuu5lCPdlgERRjK9GRMp/hFtSflCz6TVkw8/za1j uq6OxK0p2vKrqF7GEeJ7WoVqtspyNk1NynPfpdzolALD2o108ubtt7e8TVOLh8RgkmIR E5WYStnuOXqL5k9BZAzTiWEdFuFWS+pD27TnVFkj8zVc1wIRis6iNCQtYOUac5+47/Zb JmmmC+cVUsoDTURRdExpPXRlC3UHls+b4NYaVOI0/twMOY53KAxdQz8PPpalYl5Zy4KO PWjA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MolCB3u5; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-59693-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59693-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCXIg7FkB6DW36MPLH7jppoa2oedQFUbrRmkJviZ2pJXxBiN/ZxKFaFzhNJ5JPcsMuX07iNy8BgN478ayUwr4WLLxbijp/M3BSaw428/fw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f22-20020ac5c5b6000000b004c030afda02si361183vkl.109.2024.02.09.09.06.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 09:06:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59693-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MolCB3u5; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-59693-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59693-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3690B1C233DB for ; Fri, 9 Feb 2024 17:05:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0F407B3F3; Fri, 9 Feb 2024 17:05:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MolCB3u5" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 EBEE56DD18 for ; Fri, 9 Feb 2024 17:05:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707498307; cv=none; b=bircHRMCgxoX2kDrmFgnDtn/IjW79Y5DmRW5A0KX4WJCZ3I4WnfLQC3zacrmoQzSidXEyXKZQ4jAd+bEpsWjwVyXXiW/T6PPHXk5VsZ4GlLkebB1ETVKjFx9pr1044Z3dGTzD5uIeJCfxjoDueeo/szQ7dGcLXl4Zb81BkGYkkc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707498307; c=relaxed/simple; bh=xwZzEC5N9Tk3OxSnesPK34/6ccpOLSW0y1TDD6td8Xw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=FyU2EcbL2WgkUnk3hkxMYvkQxaOmsze6209Wcys9pDOrWZFmm0HcA+TNgIr1HZQfd4Acn7K5EzgYkhlo0oWaX1LdMH3r+rbfT76q3GV+IGP56gbDhK4oxIdukKGwUR40ZrN/vPQtGwEwDnnL6brp0Mmt4lMhQwtBhymattO3WYw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MolCB3u5; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707498305; 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=xwZzEC5N9Tk3OxSnesPK34/6ccpOLSW0y1TDD6td8Xw=; b=MolCB3u5n3esnUxXIp5joKwlBCnoCGPa00qFc+0Hcx7CKRORULMQzH+y4xZWXAx+CJsH0K A52KNONQ+m//szDwxbEa5TzjD1/xdtK6B47JaJGyaQSsSi/dZ+kB5MAXHcahlQPQPooFIj FcAeUCu/XE5WpU5KPga8Yw8OifMNC5I= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-674-26uNdTjhPyK-d7WEkV5CyQ-1; Fri, 09 Feb 2024 12:05:03 -0500 X-MC-Unique: 26uNdTjhPyK-d7WEkV5CyQ-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a383b9555d3so53781066b.3 for ; Fri, 09 Feb 2024 09:05:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707498302; x=1708103102; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xwZzEC5N9Tk3OxSnesPK34/6ccpOLSW0y1TDD6td8Xw=; b=ShlSJVM6K8KjZtyCjrqyArpP7Fm2U01Dta/8X7uMOyNnnKnr2qvFByNeEXcEgDmKev b6Sh6vRJtD3cr4Y5PTioFuSC4vMP+Upy/Yszvm3KiuYXL8iBbPQmFuzNsiyTpIi/HxTu LqEJ7Zcn2gBkJbLe/SFxOP8Q2Y1OVfFsHm3MB2SFUmGdYACckDMaBArzAaIX/yX9EZ4B ke13PBRMe7y4bUzNilcX+ib7kLWrChmO5rK3k/l27SEXDwDJfug1L4T87fg9roDxdOJM kJuGyjR8TeCN5UTvKz9Ep86WOddU3k2D6nFIk96+VW3dQoz1LhYPL/VX+Wzq7uRQRE4+ x4mQ== X-Forwarded-Encrypted: i=1; AJvYcCXNjZ6zto26EGg1ZZAoVBQOLSZlm+liLiSh1Hu1eqbRWo3gK7GaLy1hscYYUupO/pVcqufv5MTx/wxluE85zYPaZgrq2sv3gKn6LYWd X-Gm-Message-State: AOJu0YyU6EvGd5+6PjxkAF8YjyuOGpNPItBhKuxGPh3OGtqFVPfOAklg ZBPN2kX4bsZdkLyuHsAYpMOMZjKB9V+V/FHCkYHFw9ZPrJdM9m07eSE2A8GjobxghJnEqXlDh1G nyC3CC9ACl1hgqsTsHwfgdb6egOTBMLbNGYhGA99MO4wq3qn+vcInlSmq+SskSQ== X-Received: by 2002:a17:906:3b44:b0:a38:7d12:60dc with SMTP id h4-20020a1709063b4400b00a387d1260dcmr1702930ejf.57.1707498302249; Fri, 09 Feb 2024 09:05:02 -0800 (PST) X-Received: by 2002:a17:906:3b44:b0:a38:7d12:60dc with SMTP id h4-20020a1709063b4400b00a387d1260dcmr1702892ejf.57.1707498301861; Fri, 09 Feb 2024 09:05:01 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUOtGsAvv6QdC70PwwyWekW7wdIJz0/cucB80WRTV4+ZgCv+AHZZmjEVwpXyjm9muc1IGcLJofTiSKgLMhO+71pOKkmCHsmgprSc6gN44WovL+T+IE3bc31WnJs6BAjOkBj4fQEAqfoT5ow/rXzVpCO/hSbbIE9Dt4jY1ZtqDzVyLDh0yytbtbpjtq/2OTIBFeqi5ROaH5lUSSx6/9LLUYqZe+E2PsXzaiMfcWn3yl7hphwOsEc/KeyIU99E32NsaDh9nBHJX1xYe5bl8KpmdXQKFfqP3z4NxkokPbuLxWfXkaKaFg4rWPmr7ishQsxF+qk+gUk9Rc3CidaDhDZ0HTXQk7el6HF07YCDWrNrjl6KLwJ08E84AeGFf4j2+0hb1Ft7f4NMXox3PxUIoCZmWlwurPz52zAfk138lNe/A7QbAo4EA3HBNgKtzd9N3YdxKpRH070aztcW8JVA7X0mxtWrbj18Oqdld4FSaPOYRdezUN/WtCnlNzEECMqavl/BdctSzTUWCNVpo6P24VEL6BwNlixXKvrR5Oy2KQk95EwhI/K4R8//D0GdaRHBjI4pPYQxMhfJ8x4GiQAocuisPJTkppbOi7bBkyy76dlXs96ysVgn+e8LeW2+/4Xjrw= Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id fj7-20020a1709069c8700b00a3875804883sm925259ejc.124.2024.02.09.09.05.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 09:05:01 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 23A0810F505E; Fri, 9 Feb 2024 18:05:01 +0100 (CET) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Benjamin Tissoires Cc: Benjamin Tissoires , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jiri Kosina , Jonathan Corbet , Shuah Khan , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH RFC bpf-next 0/9] allow HID-BPF to do device IOs In-Reply-To: References: <20240209-hid-bpf-sleepable-v1-0-4cc895b5adbd@kernel.org> <87bk8pve2z.fsf@toke.dk> X-Clacks-Overhead: GNU Terry Pratchett Date: Fri, 09 Feb 2024 18:05:01 +0100 Message-ID: <875xyxva9u.fsf@toke.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Benjamin Tissoires writes: > On Fri, Feb 9, 2024 at 4:42=E2=80=AFPM Toke H=C3=B8iland-J=C3=B8rgensen <= toke@redhat.com> wrote: >> >> Benjamin Tissoires writes: >> >> > [Putting this as a RFC because I'm pretty sure I'm not doing the things >> > correctly at the BPF level.] >> > [Also using bpf-next as the base tree as there will be conflicting >> > changes otherwise] >> > >> > Ideally I'd like to have something similar to bpf_timers, but not >> > in soft IRQ context. So I'm emulating this with a sleepable >> > bpf_tail_call() (see "HID: bpf: allow to defer work in a delayed >> > workqueue"). >> >> Why implement a new mechanism? Sounds like what you need is essentially >> the bpf_timer functionality, just running in a different context, right? > > Heh, that's exactly why I put in a RFC :) > > So yes, the bpf_timer approach is cleaner, but I need it in a > workqueue, as a hrtimer in a softIRQ would prevent me to kzalloc and > wait for the device. Right, makes sense. >> So why not just add a flag to the timer setup that controls the callback >> context? I've been toying with something similar for restarting XDP TX >> for my queueing patch series (though I'm not sure if this will actually >> end up being needed in the end): >> >> https://git.kernel.org/pub/scm/linux/kernel/git/toke/linux.git/commit/?h= =3Dxdp-queueing-08&id=3D54bc201a358d1ac6ebfe900099315bbd0a76e862 >> > > Oh, nice. Good idea. But would it be OK to have a "timer-like" where > it actually defers the job in a workqueue instead of using an hrtimer? That's conceptually still a timer, though, isn't it? I.e., it's a mechanism whereby you specify a callback and a delay, and bpf_timer ensures that your callback is called after that delay. IMO it's totally congruent with that API to be able to specify a different execution context as part of the timer setup. As for how to implement it, I suspect the easiest may be something similar to what the patch I linked above does: keep the hrtimer, and just have a different (kernel) callback function when the timer fires which does an immediate schedule_work() (without the _delayed) and then runs the BPF callback in that workqueue. I.e., keep the delay handling the way the existing bpf_timer implementation does it, and just add an indirection to start the workqueue in the kernel dispatch code. > I thought I would have to rewrite the entire bpf_timer approach > without the softIRQ, but if I can just add a new flag, that will make > things way simpler for me. IMO that would be fine. You may want to wait for the maintainers to chime in before going down this route, though :) > This however raises another issue if I were to use the bpf_timers: now > the HID-BPF kfuncs will not be available as they are only available to > tracing prog types. And when I tried to call them from a bpf_timer (in > softIRQ) they were not available. IIUC, the bpf_timer callback is just a function (subprog) from the verifier PoV, so it is verified as whatever program type is creating the timer. So in other words, as long as you setup the timer from inside a tracing prog type, you should have access to all the same kfuncs, I think? -Toke