Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp128200rdh; Tue, 13 Feb 2024 11:24:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWH6O/NT1OL8If/MjEDOtrL6ka3doGLEPxAw035PR6Fm9/yWQLRkZtj+AmSk8Ztpu+6fycTey8Bx4WI4b9WA8OSbEf76vFoy+wVy3iPxQ== X-Google-Smtp-Source: AGHT+IH9T/jUitxfK9nsMj6zITi7xQzqZE5VE9oeQ4GH6269Yagw0FJKRFeJ9h8SpWgudXy2V3jq X-Received: by 2002:a1f:e742:0:b0:4c0:237a:3842 with SMTP id e63-20020a1fe742000000b004c0237a3842mr560380vkh.10.1707852260052; Tue, 13 Feb 2024 11:24:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707852260; cv=pass; d=google.com; s=arc-20160816; b=eQgQxwD9c0CBdgs4ej1yq/PBmmYsd2Wlh6W26h96Ppa7vpFPLTHb+WvVhMq5y8JE+p PQ0nmqX/6noSW0esekQjeBpv2cUGfHbQPzBX53ysMGTYJkc6iQxv9x7Rrjk3ajCaYvrv yy3LMxJ6vRzP66TrFg1z+jP+eGJ7eqaqPz3GOD0YRqAbtiJ21oU6gJI+kjOTVRTgmPmP mTJsG+ilxks9rguAsAnAkuRpvCW22tBoXEI4j4fr239ROTr7Qw0BVZpHccngrBfUDnvx dr922Ug4jlNZEgAetAnGV5vBkL6rhQI6l+BkHEOsO2vqQv6W/1xNLhinoowKBbjOwoTX y3Cg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=0B3uRJhmyT1XuLMISGiYjXxLVeAFL5LNdwOdq4xlDX4=; fh=/FwWjbXnrZhDxoeZS8U1gs8oJNtNdB+JQ2DklZvHrFw=; b=t+V0uEjOURKSK2tFMSQRT5p10mcF6vKNIgl+ZFjRwC6/+LqiMqLvGaho6sXr4DP4NX 16M+S0/06j5Ep9nC09yCiCXcqSBblBMayRGvWnzwbPCqDPkzOCGpNQDb1ECNySewLSif SFrHPrdakURGPt7O7npD/JQs94zPa3uQebrD4fZKeTh9QeyisGPhA5pgbFy+p4lU4f4R nP7k4tqi23Ew+L2/sGRVi2bc0Wr6aUXRxPrYtHSzb++OAipJt5rybFNdSFHVbsMEwqr0 upklogLuHl5e7VadToS8hjTYg8GalihNc1hKZ4Kx4QkgTmpekTINd5b7yImu1x03ZEkS di+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Vtrd7/o0"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-64159-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64159-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCVJ6cDyEHg3CdB1Zcjm1NDKcG/PrV6eJXQIvUfYaUCT9qvt5ew0W9JLatDf0IpfrHfsUHZXI9zDMGHa/AoQqVlgGH9/txQOHY9TTLpzQw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id hf7-20020a0562140e8700b0068caef783a3si3659091qvb.491.2024.02.13.11.24.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 11:24:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64159-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=@gmail.com header.s=20230601 header.b="Vtrd7/o0"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-64159-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64159-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 A62B21C22E38 for ; Tue, 13 Feb 2024 19:24:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48F4A60875; Tue, 13 Feb 2024 19:23:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vtrd7/o0" Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EF7C6086A; Tue, 13 Feb 2024 19:23:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.67 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707852238; cv=none; b=UqtTi6N+xsMaonvTnk/+INDSXreRLQoSbaYxRJVQw+NVd+O8c1hW4evHCqSehRLA9+CHglPN4n1WKFdNk5YHWuOR0HOw/dfLYPPhD2rQoh2rsKr3YRNJqmiDseNtMY1W1roaoMrD+YGdvxHVMMA7q7SmjslDBqUd74KJMRZ69z8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707852238; c=relaxed/simple; bh=0B3uRJhmyT1XuLMISGiYjXxLVeAFL5LNdwOdq4xlDX4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=n2pc8JAiT8bSpfTcWWuUVlwQtmNNdUCuPa02JLCiEPBcwiH+C7XgTA/9yPPYIB2y03K940WWvhNp0To8CqJP7y8EBmX2ARahN97RiHRDDHrSFKVwOaGESKwZwV4U5eqagmFn1FN6kIt5sqbRYa0cMWbRomGdv9yC7gEvjrBxerM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Vtrd7/o0; arc=none smtp.client-ip=209.85.208.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f67.google.com with SMTP id 4fb4d7f45d1cf-55f50cf2021so6256457a12.1; Tue, 13 Feb 2024 11:23:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707852234; x=1708457034; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0B3uRJhmyT1XuLMISGiYjXxLVeAFL5LNdwOdq4xlDX4=; b=Vtrd7/o0MHexn+sVI9y4b7W1DOy41qDcgXz8TtOEU8F/zSjkBQ0WdS827M+l6tt5iz /yh3fBBDHWpAJJr6polkJJmDOlE0pprPg9GDx0RrsU6gpWoF0tRmALOkWSCjTAb/rmPq HEf61L1TQhbKjFnXdUkFEkuWyBEdhDMXLvoyPoKVxxRljQOrmHl9z0TjxEeWmCC3EYfR jrhgB+mt6Cjj4vzIaXUSrWiiSeBXr8rYo5WfBWhbCsS9v8c5QzVBUZEl8H9U4OWwhow4 YbxwJVBqDIMezyBdMCP6Q/8uwZ7tYInc0x9RX3JzCmNltU4/IFvzZnvf0j4P22l/X9aV WA8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707852234; x=1708457034; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0B3uRJhmyT1XuLMISGiYjXxLVeAFL5LNdwOdq4xlDX4=; b=O7SHAgAl5wgOKH18AYNvGnREaz1q4Gaw4eSX9OZpqZb5JcZmfx7sQRG6SF8m5hCVbQ YtmAOrYanPyUAR6+073Hff+wXFQ7JeQEjCDUjZVb4O+tQprPwo8sVCpRIwQHhxLMYQju 4pKxX0zpOUoGc0MPIv/T9f6TcZzQHC5sogs3fVhPEDd8zOYU2plpbeRKW0MCgED6GMDi i+Txhuqv7Xj9cNqPRJfY94dSSC7VnWNLhHEiu1JdgNcmdhfvZQU6vVKfRAvmP3ystVuN r8J8SnMnIWXhzwqaCNR+KR3NSF5H6sg6rXQ5UbIZ4pT0Iek8FbwjzlZ5Yplxc+TVJE/z Se5g== X-Forwarded-Encrypted: i=1; AJvYcCVUIUzBe3f9e6VMcrM3u09GS8YnhWCcxWCtbx/S7f+PvNqYQsPPFH57LHGdIXHxxGuoVRmzQ3Ve0qrnK6G3+RYcEv7YD31AU1ydesBEUT2JsDvxan9nER0gJNvV2f2b9I09VZzW5VxGLarFPcvxOVinSKLQmttlUXBVLNHUywoFFC+Yy3Y2zUdEXyzAftoPdYV7FADlPWADo+4KMLD/MDn5SFJkQMAD4X+CQr9dgJM6d0ECMn3hTKFhWOw= X-Gm-Message-State: AOJu0YzwNQCQUSPHzfAIO5Sr3ZcKFEf+uXNvNgzu8tJ2WwIgzJoZbXBl iPPfcGFM44bHpU6xkqniKQI0AnU+MJLLjCCyK50l4hg8r9Q2LzOhAdexIm4hh8SzXsJzowFioFN RymorSENgnirFuzWHsYYjVfwHXqY= X-Received: by 2002:a17:906:aad6:b0:a3c:a655:3a3c with SMTP id kt22-20020a170906aad600b00a3ca6553a3cmr210638ejb.16.1707852234355; Tue, 13 Feb 2024 11:23:54 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240209-hid-bpf-sleepable-v1-0-4cc895b5adbd@kernel.org> <87bk8pve2z.fsf@toke.dk> <875xyxva9u.fsf@toke.dk> <87r0hhfudh.fsf@toke.dk> In-Reply-To: From: Kumar Kartikeya Dwivedi Date: Tue, 13 Feb 2024 20:23:17 +0100 Message-ID: Subject: Re: [PATCH RFC bpf-next 0/9] allow HID-BPF to do device IOs To: Benjamin Tissoires Cc: Alexei Starovoitov , Benjamin Tissoires , =?UTF-8?B?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2Vu?= , 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" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 13 Feb 2024 at 18:46, Benjamin Tissoires wrote= : > > 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=B8rgen= sen 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 still= can not > figure it out entirely. > > > All the lessons(bugs) learned with bpf_timer don't need to be re-discov= ered :) > > 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() f= lag? > > > The verifier will set is_async_cb =3D true for it (like it does for reg= ular 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_sleep= able > > 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 impres= sion > that the code of the callback is added at the end of the instruction list= , meaning > that I do not know where it starts, and which subprog index it correspond= s 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). > > > > Overall I think this feature is needed urgently, > > so if you don't have cycles to work on this soon, > > I can prioritize it right after bpf_arena work. > > I can try to spare a few cycles on it. Even if your instructions were on > spot, I still can't make the subprogs recognized as sleepable. > > For reference, this is where I am (probably bogus, but seems to be > working when timer_set_sleepable_cb() is called from a sleepable context > as mentioned by Toke): > I just skimmed the patch but I think it's already 90% there. The only other change I would suggest is switching from helper to kfunc, as originally proposed by Alexei. > [...]