Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1189116lqp; Fri, 22 Mar 2024 07:57:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW9nzLmwViBbPg0i6vxC2osGxYXSBdwfrJhRC9DL2XE3yTRrhzgzeXf+xy+2mxdPQwjeQ5aW/+nNhAqZk3pzW+5RZ1bmADJ5Uvsb9UGFA== X-Google-Smtp-Source: AGHT+IEhNlaMDdJCIrNe1Ykeu8CUEQil5CUmLEYfNh4FPaHXXb3ISz3uHfNhAY6g0Tl9ulPUZ0mM X-Received: by 2002:ad4:5948:0:b0:696:1e4f:4124 with SMTP id eo8-20020ad45948000000b006961e4f4124mr2251838qvb.26.1711119468786; Fri, 22 Mar 2024 07:57:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711119468; cv=pass; d=google.com; s=arc-20160816; b=dPoC+Hix1NodIFEPMGhTafEc4fnkFVIMFQoZZMakCO7MtEYrrBXrMtK8EvGmh9wPAU 5K944OmFlpUyBwpENHRfSupHA0RvB6VCFaMg/jN460yN8Mcii6Lr3srliUdYQJ9ifh96 NfATK8OA/aQ9Sj6LTNs2UsAXqM7ihzmRjA5LRWHQJsRcquwIaX98OB9kJktFpbynhyE9 lVdn/3RHcKsNxI48ALsQrcDyH0OfFCwlnkd87lW5P04k3gbz62T4Xlj/TgLPDfelobsD 8gzS/55H6uvmZi0vL1XYIim8ZZSGLPS7Aa85KN195ryk96+khNKMt0JozpoLCTf/+6LG jURA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=h+/YGJ2jDVRvaX85tzOoro8pcOU+SyNsepbHiw8ZAeo=; fh=L3UFV6no5Bg+ONjucac5Whrd1OR3maQPkF8kTmP37SU=; b=Lvr++LZYfuKkPK+3Ca+ZVTQZ5pykoVC2Bi6DoJqVheNNpFyRMAwMbxVtRWYSOde+FR be42631gR1aQh9lQxJX4xPGAyvGIbKWmy1+ANt3AODVib9mVOiRlRcjQnL8kS9Cb+cIP zPPifFxsks/UmW+C1hzH5/ESJnrP/idiRWolj2DJnlL9MyzH6gJQ0sfA+jtQRzgD1cHP sbhXy/IaC5uquhtbAFkAS1z9bKDqa4kXMZi/OZ+pDDP66s+CdzvfB0mV2lDiQxyRipn7 65FDepBYQNOgZsNrJ1+rlzsPZmem/PLsJ8THMje4dEgbzKaOho3hLoTJaPvffL/KrrVG QKcw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YFpwMVAe; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-111661-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111661-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. [147.75.199.223]) by mx.google.com with ESMTPS id j14-20020a05621419ce00b0068fda00db1asi2157997qvc.173.2024.03.22.07.57.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 07:57:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111661-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YFpwMVAe; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-111661-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111661-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 842AF1C2216D for ; Fri, 22 Mar 2024 14:57:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53DE656448; Fri, 22 Mar 2024 14:56:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YFpwMVAe" 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 6A03154BD3; Fri, 22 Mar 2024 14:56:52 +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=1711119412; cv=none; b=el1icNNJV9kGnR3tG18eYI3zpKSBrT4ThoKg9/mj9szpby9bswUqrEsBm3rTP7VSRih20anVVzGLk+gidjMSMArCppzr2L7byZYOcZb+v0KtM+4ldZdWmyUbefLGamWKjCPdOi0GmuZqNLxJnYuszUKERljVorJAAiF5UiO1YCg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711119412; c=relaxed/simple; bh=EMT8wfuCy0Cp4lpZJqhJjr7yWdRMYe8cHkGyjxIkFXk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j9hIdgILXXZ2QrdR3bxC4HFWk8kWnBXgnUjz/TRoDfUDAxCQ1oNab9gFsk58WaziTXmVWRJayms9l8/OYjL8aHSbS3jRwKObL8ka0RdGY6gA3OEnfzEGVJGgFsND70hv6gbcxSr2BqJrSbkhPXJb6NnPzRMOcFfL8ifZIWDWNBA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YFpwMVAe; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DF48C43390; Fri, 22 Mar 2024 14:56:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711119412; bh=EMT8wfuCy0Cp4lpZJqhJjr7yWdRMYe8cHkGyjxIkFXk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YFpwMVAew3WlNd6H2QjWYmmR8gst1Bz8D8Jrqo5gJPb1WjXbrz1QuUXpkSfR0iqrC sFiXM1qdlOnPBeYZyxOsKSv71bACWOKjo5MIGAuwfQjHo7eRVA95ee3Gd5TT9t1wu+ KRZgj2piC9sQPirRXTjn76oq/4DWLcVcaFfQtMTXQw2dIr7JAUbktzCyFGSnaIv9OQ Fc8rjuNV1ccK5233yJWi7Xg14HGKizGFc4q/DeXfxmaYY+uxGYKE+e1RfJwZTNi6NN 055tFwWJRMY6kP3wiIM5BP8OzBqXj/KxsIFSZNDGf/eoYMdWmUxay06Jl75w9puTHi hCAYNfj30xkTA== From: Benjamin Tissoires Date: Fri, 22 Mar 2024 15:56:24 +0100 Subject: [PATCH bpf-next v5 4/6] bpf/helpers: mark the callback of bpf_timer_set_sleepable_cb() as sleepable 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: 7bit Message-Id: <20240322-hid-bpf-sleepable-v5-4-179c7b59eaaa@kernel.org> References: <20240322-hid-bpf-sleepable-v5-0-179c7b59eaaa@kernel.org> In-Reply-To: <20240322-hid-bpf-sleepable-v5-0-179c7b59eaaa@kernel.org> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: Benjamin Tissoires , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1711119393; l=3405; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=EMT8wfuCy0Cp4lpZJqhJjr7yWdRMYe8cHkGyjxIkFXk=; b=Q+pAww1hd7Mzs/I8jhGQbY1HTSjHxg0Qq6hqZdKtxhVaoDBziuR8DmlJ3GXIcGbCtfye7Y9Ng tkhNdr9YjY7D5RZsWowHfEAE+kOsbgtjQGg1qT7UmWbj2ZtO8QZoqS1 X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= Now that we have bpf_timer_set_sleepable_cb() available and working, we can tag the attached callback as sleepable, and let the verifier check in the correct context the calls and kfuncs. Signed-off-by: Benjamin Tissoires --- no changes in v5 changes in v4: - use a function parameter to forward the sleepable information new in v3 (split from v2 02/10) --- include/linux/bpf_verifier.h | 1 + kernel/bpf/verifier.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h index 7cb1b75eee38..14e4ee67b694 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -426,6 +426,7 @@ struct bpf_verifier_state { * while they are still in use. */ bool used_as_loop_entry; + bool in_sleepable; /* first and last insn idx of this verifier state */ u32 first_insn_idx; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 458765d881f3..39a16184c0d8 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -1434,6 +1434,7 @@ static int copy_verifier_state(struct bpf_verifier_state *dst_state, } dst_state->speculative = src->speculative; dst_state->active_rcu_lock = src->active_rcu_lock; + dst_state->in_sleepable = src->in_sleepable; dst_state->curframe = src->curframe; dst_state->active_lock.ptr = src->active_lock.ptr; dst_state->active_lock.id = src->active_lock.id; @@ -2407,7 +2408,7 @@ static void init_func_state(struct bpf_verifier_env *env, /* Similar to push_stack(), but for async callbacks */ static struct bpf_verifier_state *push_async_cb(struct bpf_verifier_env *env, int insn_idx, int prev_insn_idx, - int subprog) + int subprog, bool is_sleepable) { struct bpf_verifier_stack_elem *elem; struct bpf_func_state *frame; @@ -2434,6 +2435,7 @@ static struct bpf_verifier_state *push_async_cb(struct bpf_verifier_env *env, * Initialize it similar to do_check_common(). */ elem->st.branches = 1; + elem->st.in_sleepable = is_sleepable; frame = kzalloc(sizeof(*frame), GFP_KERNEL); if (!frame) goto err; @@ -5279,7 +5281,8 @@ static int map_kptr_match_type(struct bpf_verifier_env *env, static bool in_sleepable(struct bpf_verifier_env *env) { - return env->prog->sleepable; + return env->prog->sleepable || + (env->cur_state && env->cur_state->in_sleepable); } /* The non-sleepable programs and sleepable programs with explicit bpf_rcu_read_lock() @@ -9493,7 +9496,8 @@ static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *ins /* there is no real recursion here. timer callbacks are async */ env->subprog_info[subprog].is_async_cb = true; async_cb = push_async_cb(env, env->subprog_info[subprog].start, - insn_idx, subprog); + insn_idx, subprog, + is_bpf_timer_set_sleepable_cb_impl_kfunc(insn->imm)); if (!async_cb) return -EFAULT; callee = async_cb->frame[0]; @@ -16941,6 +16945,9 @@ static bool states_equal(struct bpf_verifier_env *env, if (old->active_rcu_lock != cur->active_rcu_lock) return false; + if (old->in_sleepable != cur->in_sleepable) + return false; + /* for states to be equal callsites have to be the same * and all frame states need to be equivalent */ -- 2.44.0