Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp545162rdh; Wed, 14 Feb 2024 04:57:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXMowRxvfgRh42w++nEhXOgLMTWZ2b3fmyc6eQT6fDLoKQlvVqPalxmSs6cPTUAS6vd/A57wtvlE4+wD5YjINzA+DW4TvaN0HoE91cv/w== X-Google-Smtp-Source: AGHT+IGrkAJeljJuL51Uii0qeokxYfD+I9bS+hHMQp6NjacNPXh3tIEThDUjCxwg8LA1PtibnPFr X-Received: by 2002:aa7:c54b:0:b0:561:bcbc:7c96 with SMTP id s11-20020aa7c54b000000b00561bcbc7c96mr2030738edr.31.1707915455950; Wed, 14 Feb 2024 04:57:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707915455; cv=pass; d=google.com; s=arc-20160816; b=eG6agLeeZGuPoujoipnV56M2p4c4XxMvadgiv5DZBpOfdLCAJs9p2WfRgMeu0GHIbC VWHcGB8U0m6vIHjDySYbGPtxrDtrSEEc6S42ka5aRRflpA4UQtUdLOX8aVr8cUNfI0ol icwD6eEGocZK3uDspirOEVXX5HbNW9aowWpwjpXV6sMEHbD1Oa6h264wHEN53CT+fD1L vSDzc1Vqz+MWFwgK5nCFfhzNMMBim3qLB9g4jvCYAC1IVv2xLjo3XQ8weBho2ga2NSEM fURgLDqSWqef+VvQvdg4gB82Z+lt8Br5SbuJMqYKPW7gM2lZXDEzvoLn130oUnMOf27l 5IVw== 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=FJp37iTRPYPRDJyHF81G0HZwGNHWM28gXJ/LmpRlD1c=; fh=BGRYaJX2eynv8lJneSopZjRipId71BO+2zMvKNy1m9s=; b=kiYAl4Upp8JNxWNF+W4kvlD9zKmvPNNiqjY02clbQqDYYZjvnrGHyNBzbs47voAKMy 01BKdM28uXpdc62WBIJMU07M1VHZGl0tyrldw1EpBefM/elMilHST3abEeSe4RjPTd2K 9TTorBHKzqK0dIYoZeSYNa1Y+KL5GVpXIeZZ3/REBxkTzMyN52kE7usiuLhw9ubiOKCX ZOfmXml1xOW2Ys52HPEONSo3qzfsxo0z5ZP75NzLMcbwNfRxwvstURN1czIlv+7G+Kgm PQOLUl5GWr63Rv0aECxFKXnzNFRblUIcXLLUlOiNZgAEKEuuBjxmqlgp42sBrwbhKu1/ Aonw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YzMaoC2B; 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-65234-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65234-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; AJvYcCVtu+rRNwnBpCOimRQzTRIFy2eAIt8QfaaHrWCbY+rOkl77hZxTJqNDhTgzAoJk7Vvxx8cdvSkZOuZLMVoJId7gIOoHNGCaEY24vpplnA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m4-20020a50ef04000000b00560dedd6fafsi4663842eds.167.2024.02.14.04.57.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 04:57:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65234-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=YzMaoC2B; 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-65234-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65234-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 893971F2474A for ; Wed, 14 Feb 2024 12:57:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FB7954668; Wed, 14 Feb 2024 12:56:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YzMaoC2B" 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 A909E524CF for ; Wed, 14 Feb 2024 12:56:34 +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=1707915396; cv=none; b=mv+VrDWGZg0BssKbipIgqWrOLEWV19oY7gzNI8rI5cnqlg4FkhnmuEQoLlBpUquyddZAczal1JA8lac9uPMLQ+UAcz9sBtnDefLc4CarVSGph0cWCNVN8kvu3zcacCA3poewMeYtsQfiSCeAzn3aM4+Ve0vNRkERaHFNipuYEpQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707915396; c=relaxed/simple; bh=FJp37iTRPYPRDJyHF81G0HZwGNHWM28gXJ/LmpRlD1c=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=t97YMzWbQysl+ffetY/B5lPSthsVwuzDAuY3QvkePZ1XkrlEe1ING1djmiXexGG9dFAzbH7nFpLbhCbCLvjyhHiyYm5lrnjq8LcQaH0g+5KNzI4mr508dkAo0M7K4DM3+SgC29U8ngn7qQQSh7xNX94HpcVpxcUJCQqZgDSrgu8= 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=YzMaoC2B; 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=1707915393; 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=FJp37iTRPYPRDJyHF81G0HZwGNHWM28gXJ/LmpRlD1c=; b=YzMaoC2BsRjV+QxtjJUieTSlQzt0jlhZ35SDci2FTNzFMefvYMst/s+5xTUPEynb1P6Phg 3xPXwcsZ4IJX/b4IITU/Vk0igcyYsvbJSDgT/iZSohGd2atUnWDFjHyC1ee0gLh8YpHGda mmxpfjgZo2erCgoJiMwdmtTDqGD6WH0= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-537-SlWRdl4aPsW4hWfSWB_jpQ-1; Wed, 14 Feb 2024 07:56:32 -0500 X-MC-Unique: SlWRdl4aPsW4hWfSWB_jpQ-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a3d481c7d8cso32941166b.1 for ; Wed, 14 Feb 2024 04:56:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707915391; x=1708520191; 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=FJp37iTRPYPRDJyHF81G0HZwGNHWM28gXJ/LmpRlD1c=; b=CqGH1RHUjU9m2U5b2FZqtKnaq7Ty1PpcIHKYlQafcZbBZyUKe2hwYJSAz4EmHnQ4Y0 SpZopzc0WcO67qbf6f8WEFsVJq0ZPPlXEWwEUidW0JZVSWLqbgu9fFWeN0cJ6hjto+2A RAnmF5zH7a/aulo32p568LRzJ65HUaHjaK4D14gKOx6fjTMjAwXLfXY+sIscCjNo+JrJ rVY8wAEdHA1OU9xxiExSSWMs2sbdrx133g9rJDGhhV41sNnHNcGbX72H8atADvO3cVhV 0KomEoxQrBojdLBo0t8tlUnEoOi0mSKGGkIDeeCL0ZokyHeN5KLOItAIVTKqncxk09e1 T0lg== X-Forwarded-Encrypted: i=1; AJvYcCVLODLbrg+tHr8GH6u7MClv5QxIy0vtssBdSkF3vc4DoRnuOeM9fQnh3a8gjIQjf1lY0qLV/Kd44Zmoe+jBM8OmjOlhO7rwq3RsJ25k X-Gm-Message-State: AOJu0Ywb8uoYNFc8DbQdpLCrCbveP9kotny0WH/EjUz4cGGw2GRfKuHx vQy+d/SI4tz+jPSY29bCqoeJwfgf49XmrYDOiuKOs0hBC5zUwb3oy5QPnqr0arPlK+979OOnjJc gIQxWPe2SuBYwPCHJNuJqXF0TDlHN+a6TCArPDZS6a5WfghrTVkXzFKm9TOg7Xw== X-Received: by 2002:a17:906:f8cf:b0:a3d:2422:ee73 with SMTP id lh15-20020a170906f8cf00b00a3d2422ee73mr1559811ejb.77.1707915391124; Wed, 14 Feb 2024 04:56:31 -0800 (PST) X-Received: by 2002:a17:906:f8cf:b0:a3d:2422:ee73 with SMTP id lh15-20020a170906f8cf00b00a3d2422ee73mr1559778ejb.77.1707915390722; Wed, 14 Feb 2024 04:56:30 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXeVT566eawAqV4mSiYIM54RSXg8KcFzFeTfM3lTaqYUMHBIUCXS/1t/A3OUh7PJjPlqfAuhmCDkluKHV5tDkoxAwbqEWcsb9OHKXszu9xt1+XsHDsqQR/Gt6oMAJQxj44Rtg1OIEF+AcFruNXTnueqhOSsty1y8hMHV/Q0Hy+vXJQpN0xBV3ghNG/4nguQ2hrqJJDM8MZHSY6bIj5ts1xFNA5MQpgsHrvI1Em0gVn7Y2389Jy3RsiAL7THwe00c2TzV7T7EyOWYKihiAu5o+rtxRs8uXtR/8gGy9RDXg28p1fPZJIaYFZR1R9IsZYukb84tHI0pSYWTJNbTvxqu+j6oHcO43pcoCf5hxkqfgFDAJYr0ELb4pmAHgPMPEFoJrJLDNiCLG16PPatmNBKy1MNPwrf/YGrGwcacXGEO19Jn8Suusnc+ODFM+fkSY0zIFsLdG799C9+nD4ryXbDWIt+ojfqV8NyG0IJdWyrRLa3cNG4+hmXhFUq3zif8GB1EA/FMNM7pf8JVk4YNRjHpH32s+cpFXVMNmhubaIYqYaL8uDYxGAF20wM0VY6oYtaO5GfSYOZhvG4Fuyz/XALrhx2z6Z7dsYB2dG2bUYSeLI8tCQ1YzLYVj6dKMcM3F9nDqm3Ur2Xrh8lMjGM0WTj7OwrpTIo9R78b+zsq8Yv9X+UDIL64djWOPfW1itQBIqU6VQ= Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id vb1-20020a170907d04100b00a3cfe376116sm1673172ejc.57.2024.02.14.04.56.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 04:56:30 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id CF25D10F578E; Wed, 14 Feb 2024 13:56:29 +0100 (CET) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Alexei Starovoitov Cc: Kumar Kartikeya Dwivedi , Benjamin Tissoires , 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: <87bk8pve2z.fsf@toke.dk> <875xyxva9u.fsf@toke.dk> <87r0hhfudh.fsf@toke.dk> <877cj8f8ht.fsf@toke.dk> X-Clacks-Overhead: GNU Terry Pratchett Date: Wed, 14 Feb 2024 13:56:29 +0100 Message-ID: <874jebfblu.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 Alexei Starovoitov writes: > On Tue, Feb 13, 2024 at 08:51:26PM +0100, Toke H=C3=B8iland-J=C3=B8rgense= n wrote: >> Kumar Kartikeya Dwivedi writes: >>=20 >> > 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=B8= rgensen wrote: >> >> > > > >> >> > > > Benjamin Tissoires writes: >> >> > > > >> >> [...] >> >> > I agree that workqueue delegation fits into the bpf_timer concept a= nd >> >> > a lot of code can and should be shared. >> >> >> >> Thanks Alexei for the detailed answer. I've given it an attempt but s= till can not >> >> figure it out entirely. >> >> >> >> > All the lessons(bugs) learned with bpf_timer don't need to be re-di= scovered :) >> >> > 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= regular 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_s= leepable >> >> > 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 sleepa= ble 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 im= pression >> >> 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 corres= ponds 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 mana= ged 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 explore= d, >> > 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). >>=20 >> 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? > > More than just convience. > bpf_set_sleepable_cb() might need to be called from non-sleepable and > there could be no way to hack it around with fake sleepable entry. > bpf_timer_cancel() clears callback_fn. > So if prog wants to bpf_timer_start() and later bpf_timer_cancel() > it would need to bpf_set_sleepable_cb() every time before bpf_timer_start= (). > And at that time it might be in non-sleepable ctx. Ah, right, makes sense; didn't think about bpf_timer_cancel(). Thanks for the explanation :) -Toke