Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp140376rdh; Tue, 13 Feb 2024 11:51:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWyg0Gzz4luMad9xFUbyft986k/wmOIENYW1c4A1hT9zFWL+0SLAEYHw7RbP9UyHQBeOgFvhDZcS4Ek1hhsaFelNmRhy5hL2L9k64u3JQ== X-Google-Smtp-Source: AGHT+IG8NxB/AW2H25EYMD+lc42RqcM7fiRnGgD2nVmOMjB8a5aMzuSJKm6LvWTTSyDKO7dAy/yW X-Received: by 2002:a50:fa93:0:b0:55e:ea35:1da4 with SMTP id w19-20020a50fa93000000b0055eea351da4mr475321edr.4.1707853919601; Tue, 13 Feb 2024 11:51:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707853919; cv=pass; d=google.com; s=arc-20160816; b=r6F+6vykSUu17qDcb014WZmOERQnFqdl5kzOyl/gL/12Ck1rhkYI3se5bijFG6ACiQ FXgI1FTgpWguEdutsAgWGhhEtr2OkVV1ExalTB/jnIqZbV14ejSVKbvvoHJ+9xWcgq3W HYazwjJGBfQ9l8KBRREQbQGxkaAcgF8ZXRPiJg29HegczwIKw+9510QTtX61jDmpcOkM 42/yXrLtzj9O4YUUHTgJXgRy0e7H23SZh2/PQQCeDen3GPZA0NK684yN4aSfMPWCZVzb KqBqGzCGrw+unCtqsPmNB+CcR/7nGf/wYMoM1R4RHrL/eM/CCHbKzygG1DNMvrC6jWBO Wwyw== 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=Tg5MsaFqKcll3WJwQ+ui4v5KYHONfl+5tZRSv1SPzR0=; fh=RV4mwRFk5plas9/TqsHexlNmlX6JIxLCdcYwtU/vcUM=; b=k6bO5SB7zaeZC1owSfB4/P645gUpDjRths+JiTtpDgId85NNkjFacqJEvMh15euZal Io2ztNc+9rTYWgF96YOEUwXF8habRcGpCGnM0fYFNxxUfzaBf+bDUqVXh2b3zDPcEMIz beHldRIKjJMXOLcLn+de0B9b2V3NKf6H+6JyCtOaMz8t17mUkKAvUkCV1r4ADgYYpNif pkrfF1VPiH/PiN4Bz4XuPIPG3abYORCfiRdIaPA+ayXvV/tLZKveGeQvy9y0ouFmBQyL jmJ+OQp3SqlCNZHrxSe1KTuubnRMdP/VCe+0UJ2VaHGi6v8EGTC7O9JQeBTewr7ZB63m HaWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gDEY51uA; 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-64194-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64194-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; AJvYcCX2/V4KJj70DyTo5A2phDQBRQqwYJuiEa1w2uallqmZ2lMrsqSbFkaa3XjrC2NjUbD1qpQ2ywJ4OYrvJY5HOEvW9Sf82VfJghMK2eSy1w== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w21-20020aa7cb55000000b005605adde36fsi4141752edt.616.2024.02.13.11.51.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 11:51:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64194-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gDEY51uA; 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-64194-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64194-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3016A1F244E3 for ; Tue, 13 Feb 2024 19:51:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33B3560BA3; Tue, 13 Feb 2024 19:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gDEY51uA" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 377E21CAA9 for ; Tue, 13 Feb 2024 19:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707853894; cv=none; b=pC9IXnnyrww8h4tGnYJahG82WNyegm0d2BArQ8pq9eRcjxNMsjLpyAKSbN/eSRY8xFCSIuRaoFSL/bV3n4vi8TL+fwT3U5Gt3i4YQ22JgXOXs1W4AqDz3BALcPscZhG6iT+Iplj4F5PmeDy5k1sEMxH8lxymEzt5Tbt/NCHnaRY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707853894; c=relaxed/simple; bh=Tg5MsaFqKcll3WJwQ+ui4v5KYHONfl+5tZRSv1SPzR0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=uaqpLOOkY72583yapXjMmM3hdyECBCGkTOTp8uzouMAVnsYCGw/o9rEMbu3/jkGyC/gHqnlvc53+dTApnJgQ8BlRjbEHIYUs/APK+6f3rCTus2IlU2pKoqFCl/Ilck49L12vJ0G0DEh3y/6JOq1GX+3ILo2zEmNaJktjTtEW9Y8= 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=gDEY51uA; arc=none smtp.client-ip=170.10.129.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=1707853890; 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=Tg5MsaFqKcll3WJwQ+ui4v5KYHONfl+5tZRSv1SPzR0=; b=gDEY51uAgp6iNPEsGD3Mb8bsLgypd6QFtgz3kXcnzFdyehoOPpVuHk0b8nXpmaxfiPYodU jwgZfVOC9dGMq9KEKRzGEm3MBfOqrwEwfH2dd06ah/pUxI0H+2VFU6MWaxK+FdfveXD6Kw gziTozI/3le0dr7BxWOQbJC72h9ecOA= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-8xRE3NBiNQGo7ZieiSddoA-1; Tue, 13 Feb 2024 14:51:28 -0500 X-MC-Unique: 8xRE3NBiNQGo7ZieiSddoA-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-562111cbefcso272873a12.2 for ; Tue, 13 Feb 2024 11:51:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707853887; x=1708458687; 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=Tg5MsaFqKcll3WJwQ+ui4v5KYHONfl+5tZRSv1SPzR0=; b=MJhQTFu0KL2eIdR0ZYPnHea4uX/QsSAOPghzSfi3KskOA/p7ItW8kp1StnMoQqNgZA 5/b6bVx0pnHnxA4rhsMbpORtsVqke2jVk669mJFKEvOFcRKMfyb8OCx9Cf5nhwgYQdlZ SJU8MwdIRtQMbP/SUwt2jZS8ufN0PL966nnGf3ZmAcPmF5+bRxF5SswIAiLl703J/UjD 6Joq0xaje+qEQ5cjy8H43IqgK/82JhaJ+is6lagAdVFoy/5CsHsefsm03b1H2UvsRaN0 bwnzhu48fK1XGN2SpPGVttschY3vwOelP9VpKmORGLmBubs1VkhVm0FINaSfCWs582GX XMKA== X-Forwarded-Encrypted: i=1; AJvYcCUFLBZErk0TnKpn2uL1CrL3PJusknUL0OX8JXRaH+fiK2v2hCUU8TlbNS2S8mlDFdb5opuyOMDky50RZ0isMrh/Eg0ILdDtKkoPmDRr X-Gm-Message-State: AOJu0YzF+bYz+le6dFuA+3hk1TBOH+VVED525HA6pNjk5trN48ZMq1rO BFlupTRYVlTXmEW9ysS03/N6xnXnUdodRY+Ir8B+UtkCEkNVjjK9+/NYlfuglrndvn65TmK2lm9 /TH9HnEBTlAXAP2JUghgkpejhxvvcwAdfuLQU5nMsjZCyOh0uzkRvz1Xd1B1E6g== X-Received: by 2002:a05:6402:1cb8:b0:562:50e8:6ee4 with SMTP id cz24-20020a0564021cb800b0056250e86ee4mr40877edb.35.1707853887542; Tue, 13 Feb 2024 11:51:27 -0800 (PST) X-Received: by 2002:a05:6402:1cb8:b0:562:50e8:6ee4 with SMTP id cz24-20020a0564021cb800b0056250e86ee4mr40854edb.35.1707853887208; Tue, 13 Feb 2024 11:51:27 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUi1vpllgnapDRdjcC78q+niYoasUsrFPOAiQ6LkfiADjrKhfTJiHmOobSo4WalnyZDiF+/YuSFXFCH7aQHVMo2n+AHz5/KpW64Ssb7y+33PzSHOFOhYnbFA1+FxRbrbuqEQ7J419oJzeOwfpdfaQ3OYNt4iA9CM4LVhANOmauuzt2RR/8TV24lXnLEgATzcUFsXfus/4WLI8PW2esejO5PFgMjA+wfAi9rywr4X8dTW7ugTBVU/Pnk1BX797PfMJA8QBJP0Pl5ZrXnwHOMv/jqOwOXd5kng2OSppY1E8CfdU13/sx+4Cz0zx4fplhwCVAr53NcY0jgV50NTAyZOXm+ZRf4s5ZwUW64IDZzThvRx+OGRw81x1Qv8jLiQuElQd5DvkC3YRw0k+my/b0T84+zBvaKgv5FQBa8YPA8jMdbGeJOsTVtkTfGuQBCCVnvd7EgNv2QVTuKCrulgThFTWcqJG4emd0f+fC8tQ7onXZcu52rqY/ff7VNqpIBFVlTjQ1nJYjuKFAGAc4Pralja7cffAYhTYXZkzHWLGyqysRHCjcDmJm12yB+n7HST4f/BItbu4p4o0O1g4463WbrggfFHFTPuEhn8MaPsQs4EslkwSJulnDsAh9vCg4KwOSKqWv2MQi/sYJhgdgFwHe0swP6QxeE99I/PzDxIb/+7DeRayeeB5CYiX2v0rEr6MJnW3M= Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id j2-20020aa7de82000000b005621b45daffsm138386edv.28.2024.02.13.11.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 11:51:26 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 620B010F56C8; Tue, 13 Feb 2024 20:51:26 +0100 (CET) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Kumar Kartikeya Dwivedi , Benjamin Tissoires Cc: Alexei Starovoitov , 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 , LKML , "open list:HID CORE LAYER" , "open list:DOCUMENTATION" , "open list:KERNEL SELFTEST FRAMEWORK" 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> <875xyxva9u.fsf@toke.dk> <87r0hhfudh.fsf@toke.dk> X-Clacks-Overhead: GNU Terry Pratchett Date: Tue, 13 Feb 2024 20:51:26 +0100 Message-ID: <877cj8f8ht.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 Kumar Kartikeya Dwivedi writes: > On Tue, 13 Feb 2024 at 18:46, Benjamin Tissoires wro= te: >> >> On Feb 12 2024, Alexei Starovoitov wrote: >> > On Mon, Feb 12, 2024 at 10:21=E2=80=AFAM Benjamin Tissoires >> > wrote: >> > > >> > > On Mon, Feb 12, 2024 at 6:46=E2=80=AFPM Toke H=C3=B8iland-J=C3=B8rge= nsen wrote: >> > > > >> > > > Benjamin Tissoires writes: >> > > > >> [...] >> > I agree that workqueue delegation fits into the bpf_timer concept and >> > a lot of code can and should be shared. >> >> Thanks Alexei for the detailed answer. I've given it an attempt but stil= l can not >> figure it out entirely. >> >> > All the lessons(bugs) learned with bpf_timer don't need to be re-disco= vered :) >> > Too bad, bpf_timer_set_callback() doesn't have a flag argument, >> > so we need a new kfunc to set a sleepable callback. >> > Maybe >> > bpf_timer_set_sleepable_cb() ? >> >> OK. So I guess I should drop Toke's suggestion with the bpf_timer_ini() = flag? >> >> > The verifier will set is_async_cb =3D true for it (like it does for re= gular cb-s). >> > And since prog->aux->sleepable is kinda "global" we need another >> > per subprog flag: >> > bool is_sleepable: 1; >> >> done (in push_callback_call()) >> >> > >> > We can factor out a check "if (prog->aux->sleepable)" into a helper >> > that will check that "global" flag and another env->cur_state->in_slee= pable >> > flag that will work similar to active_rcu_lock. >> >> done (I think), cf patch 2 below >> >> > Once the verifier starts processing subprog->is_sleepable >> > it will set cur_state->in_sleepable =3D true; >> > to make all subprogs called from that cb to be recognized as sleepable= too. >> >> That's the point I don't know where to put the new code. >> > > I think that would go in the already existing special case for > push_async_cb where you get the verifier state of the async callback. > You can make setting the boolean in that verifier state conditional on > whether it's your kfunc/helper you're processing taking a sleepable > callback. > >> It seems the best place would be in do_check(), but I am under the impre= ssion >> that the code of the callback is added at the end of the instruction lis= t, meaning >> that I do not know where it starts, and which subprog index it correspon= ds to. >> >> > >> > A bit of a challenge is what to do with global subprogs, >> > since they're verified lazily. They can be called from >> > sleepable and non-sleepable contex. Should be solvable. >> >> I must confess this is way over me (and given that I didn't even managed= to make >> the "easy" case working, that might explain things a little :-P ) >> > > I think it will be solvable but made somewhat difficult by the fact > that even if we mark subprog_info of some global_func A as > in_sleepable, so that we explore it as sleepable during its > verification, we might encounter later another global_func that calls > a global func, already explored as non-sleepable, in sleepable > context. In this case I think we need to redo the verification of that > global func as sleepable once again. It could be that it is called > from both non-sleepable and sleepable contexts, so both paths > (in_sleepable =3D true, and in_sleepable =3D false) need to be explored, > or we could reject such cases, but it might be a little restrictive. > > Some common helper global func unrelated to caller context doing some > auxiliary work, called from sleepable timer callback and normal main > subprog might be an example where rejection will be prohibitive. > > An approach might be to explore main and global subprogs once as we do > now, and then keep a list of global subprogs that need to be revisited > as in_sleepable (due to being called from a sleepable context) and > trigger do_check_common for them again, this might have to be repeated > as the list grows on each iteration, but eventually we will have > explored all of them as in_sleepable if need be, and the loop will > end. Surely, this trades off logical simplicity of verifier code with > redoing verification of global subprogs again. > > To add items to such a list, for each global subprog we encounter that > needs to be analyzed as in_sleepable, we will also collect all its > callee global subprogs by walking its instructions (a bit like > check_max_stack_depth does). Sorry if I'm being dense, but why is all this needed if it's already possible to just define the timer callback from a program type that allows sleeping, and then set the actual timeout from a different program that is not sleepable? Isn't the set_sleepable_cb() kfunc just a convenience then? Or did I misunderstand and it's not actually possible to mix callback/timer arming from different program types? -Toke