Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2421143lqt; Mon, 22 Apr 2024 10:08:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXuogSekS0k+O0UaLwY9I4Y8mOXxHTK6ai63SgBpoZUzuc/7wJuMrSqYmoEMg2WA2VJBqEQ4Ng3Y5FcWZGVAegDDz0GkQNZo0OeFf+vzg== X-Google-Smtp-Source: AGHT+IEFSCZSzmt60jF436mfFXPvpIC/1jImMkaBGHrcmxd4172PEhC/PRjI2bT2l5SICQNn40Cr X-Received: by 2002:a05:622a:190f:b0:434:b04a:20d1 with SMTP id w15-20020a05622a190f00b00434b04a20d1mr12746827qtc.36.1713805695817; Mon, 22 Apr 2024 10:08:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713805695; cv=pass; d=google.com; s=arc-20160816; b=QCw3uE8VOsUND+TM0nrZqpUt1OcCHnY7kVUqMEm74ZDWW+LP86sPVQ6Qo1LwzyO2lc QONJHMqXvcwRfEYvh61nimrOYCrpAbhoViEX+5Z+B8VbdOvwHJTDyuY31m0i3Ie9qpEo pX/W3oNY/eB24uCwD8q8Aj9Rt1Clexx5R8iudzCu5v6XORl7RtPnQruVrIPTWJRsypQ4 DNs4wU/oif+s/YU6rgAvrRZT8iEVIHGHKhPwxpFDx6+PvyHuKM+F5GCsoszjXTP3BaPy 4s0P81eRqnuMGO9YLUiIlIKnxPKpEHimJ2aQ/03avBJrkRsYYLDKS8B4+knMjCLLYx0L IfyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=BXbpW81GY2mMRd3zznZlPjRz/M5Vr1mVUe0+9JrYiR8=; fh=BKgJk8FfeqxAa6aBIN50vkzPOgG2BOqQNd1bfrSAtpc=; b=eHFzyKnM0JM7P4q6oae7qsfps3Jc0kNqgnbs9W7Ri6gcPqfxHHFJy3yGHYNVF2BaOz 48iXAXqQR1lUUrAzv0+nK8aP4QDAhK8ZK99ZKUZmqYS9xlfvKRoirsqBRkEqwQqRzZg4 tXCMlpt8trROG120kYktOY7fj2svzJBLGHI1DcfAUpCE0X9xXt/r8vfQYrl2cVFxKmgs mOZNA4M63vhbzXIE/5RbMmlkguD3FkBc2xVT9T+NEc8iQcwd/blHjdVNqxmhixljAXKH NrFVuz0nIbEmAo8SCiDz7UmJb2m2weSHq3bKuhcHokXpWeHg97S9bizoJQsAu48p38rP Dc1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=j7oYDdyT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-153784-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153784-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ay3-20020a05622a228300b00439c285a352si2020417qtb.142.2024.04.22.10.08.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 10:08:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153784-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=@kernel.org header.s=k20201202 header.b=j7oYDdyT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-153784-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153784-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 88C091C21672 for ; Mon, 22 Apr 2024 17:08:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE1D3153BD5; Mon, 22 Apr 2024 17:08:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="j7oYDdyT" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D195115383C; Mon, 22 Apr 2024 17:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713805684; cv=none; b=rou6jhFeomncZg0+pkZkXLF+kmqi0vMWQfig2ShyZGu+WtYFGhECFdF7ErcCwRw59xABPDr8xx37Q9n2w+EqKW24vRu7uLs+INGuYqF7tyuyI5vxz1nCoR/cohzdlECFuXE8TDtCwCD0XW2d88ZIcOq6RPk2ea7yzpO4emcERZY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713805684; c=relaxed/simple; bh=w0hxzmG1gYn8WGCfF/7Fupn+EIiThl4LxR3lirgjX8o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QkhIdlwbf6tp2960EZ1BpUR2bR9fFK2zjJpJ7qsjuVA/if9UfHcU40Ns5ODlHSdMNEuSa/ej68teUYhRMQKVVn1b0mwRbhnudhUMjFLcrPyF1JwigK7KflAu1Qxn1s/HW4woQLsidYl27TC/Tq3l3E4Iwv5N32+gCIk8GI6FCUU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j7oYDdyT; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71B20C113CC; Mon, 22 Apr 2024 17:08:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713805684; bh=w0hxzmG1gYn8WGCfF/7Fupn+EIiThl4LxR3lirgjX8o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=j7oYDdyTpVj7IpdCj9j2ZvxONjy4/oU3wQgK7vu9dTvAqK7cbaVXGyXpbEEHmKlVx UiavVa39FL5HJ8NPsACJVANWleEtb0+I+hu7dgs9g7KKlmj9eskdOpejgGsHWJaSJ1 xMjB/8sL+nxRE8BhnAl4C4sgFreF+qhCAFDDPfaOj56BCziZMq45JYV93oEg6hrSlK ytIhvh5OknxA6W84y+XbKnH4moYtnDCocgv/lNrp/M3HBqQn/Lvg7auIybwa7M1G2K cnoGoVk+kmSHgynilWb7QkwToK89ovB+3CEf+pO9a+jS08QfHX7MvI4lS9PqQsb6pt 4Pr5JFwK+nysg== Date: Mon, 22 Apr 2024 19:07:58 +0200 From: Benjamin Tissoires To: Daniel Borkmann Cc: Alexei Starovoitov , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] bpf: verifier: allow arrays of progs to be used in sleepable context Message-ID: References: <20240422-sleepable_array_progs-v1-1-7c46ccbaa6e2@kernel.org> <7344022a-6f59-7cbf-ee45-6b7d59114be6@iogearbox.net> 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=us-ascii Content-Disposition: inline In-Reply-To: <7344022a-6f59-7cbf-ee45-6b7d59114be6@iogearbox.net> On Apr 22 2024, Daniel Borkmann wrote: > On 4/22/24 9:16 AM, Benjamin Tissoires wrote: > > Arrays of progs are underlying using regular arrays, but they can only > > be updated from a syscall. > > Therefore, they should be safe to use while in a sleepable context. > > > > This is required to be able to call bpf_tail_call() from a sleepable > > tracing bpf program. > > > > Signed-off-by: Benjamin Tissoires > > --- > > Hi, > > > > a small patch to allow to have: > > > > ``` > > SEC("fmod_ret.s/__hid_bpf_tail_call_sleepable") > > int BPF_PROG(hid_tail_call_sleepable, struct hid_bpf_ctx *hctx) > > { > > bpf_tail_call(ctx, &hid_jmp_table, hctx->index); > > > > return 0; > > } > > ``` > > > > This should allow me to add bpf hooks to functions that communicate with > > the hardware. > > Could you also add selftests to it? In particular, I'm thinking that this is not > sufficient given also bpf_prog_map_compatible() needs to be extended to check on > prog->sleepable. For example we would need to disallow calling sleepable programs > in that map from non-sleepable context. Just to be sure, if I have to change bpf_prog_map_compatible(), that means that a prog array map can only have sleepable or non-sleepable programs, but not both at the same time? FWIW, indeed, I just tested and the BPF verifier/core is happy with this patch only if the bpf_tail_call is issued from a non-sleepable context (and crashes as expected). But that seems to be a different issue TBH: I can store a sleepable BPF program in a prog array and run it from a non sleepable context. I don't need the patch at all as bpf_tail_call() is normally declared. I assume your suggestion to change bpf_prog_map_compatible() will fix that part. I'll digg some more tomorrow. Cheers, Benjamin > > > kernel/bpf/verifier.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > > index 68cfd6fc6ad4..880b32795136 100644 > > --- a/kernel/bpf/verifier.c > > +++ b/kernel/bpf/verifier.c > > @@ -18171,6 +18171,7 @@ static int check_map_prog_compatibility(struct bpf_verifier_env *env, > > case BPF_MAP_TYPE_QUEUE: > > case BPF_MAP_TYPE_STACK: > > case BPF_MAP_TYPE_ARENA: > > + case BPF_MAP_TYPE_PROG_ARRAY: > > break; > > default: > > verbose(env, > > > > --- > > base-commit: 735f5b8a7ccf383e50d76f7d1c25769eee474812 > > change-id: 20240422-sleepable_array_progs-e0c07b17cabb > > > > Best regards, > > >