Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp520969lqh; Tue, 7 May 2024 06:33:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUsw5/mu4nnW26OGKFU6zYR7SP18ErW2PyzDVc3QCY5KoschqoqwfnA4G0BQZ2j/fpluvOx+kHNDP6gEX4S40OTMsY5tLoyrG3ZRF5WlA== X-Google-Smtp-Source: AGHT+IHO48292SL++poOS6YGATT7MXdFwqj0hj48tShk48cuiJ6xIeAtO/DF/VJicNRIS5zUpH/C X-Received: by 2002:a17:907:2d2a:b0:a59:d1c0:3df with SMTP id gs42-20020a1709072d2a00b00a59d1c003dfmr5602944ejc.24.1715088795979; Tue, 07 May 2024 06:33:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715088795; cv=pass; d=google.com; s=arc-20160816; b=IUsSOkfMKJ0v3HPFzWyV0FFc+tPnJ9TB6whuWD672s0ZUCDDhmC0cYtl9dff13XpBK ZaTCUCUo7i8+MHVTLBK6Au3DXzw7T8H/w7DQjSVFPelbQaiYJraxuNhj/57zezMvrWbQ img45ypRwwbB8t7SR6gSe6ecGZIAVMnakI+1hEty5FYYYe3yreelx0hKAstfeM6Oj48l F2khvNgXE6R9BE6EPs9bpkn4K1BOOuuYvAHuB2MaMAYTfIeXX1xGqnLQixe+CSe4MgNl Mv0tHVJNqYoopjyTWKr5Yk+Mkl4JO4QFQq9yLIliZUJ7ZW6K80nfXA8BbjvXJ88I3PP+ QKDQ== 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=We3N55lHEtExzNQWXON5IDqoWKvSvanTEy3w29GLtgw=; fh=+xF1049tVypekkjShp17fvMlvSr2JIl/AO2WK77YLJ4=; b=YmQ7CJ1uY9BC1IlgmAta8uZJ7Uj7cy3dE7oM++0SEV7POLOR9McWwBmRJNZffRon69 pyibWAzjhFrMIGmwF22MdeucgABgzLeM0tVuz0RGocC8vYz+Fz1ATgR/NhWjGQugSXy6 uOEIR0lfPmg4irg9GMHqeJGdmiK+3sRa3foV/+6mHHwe0q1QEWDnLcnuFPEfiEXOnfxN t2a17nLvOkbgolJukVOPGQ93JHne1dSnecx/KHGqqsFXgreZbkGp79bhGhb9PXd8cDi4 N3Xdc54ys/YEusXq5ajZVv8J+Qw8aINQGXTL6iwfRQXQB1TPB/DXDsu9VkQSvqwaMKum c8DA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QP86DZPw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171421-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171421-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id md13-20020a170906ae8d00b00a59c0bf5bd5si3216809ejb.192.2024.05.07.06.33.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 06:33:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171421-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QP86DZPw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171421-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171421-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8F1741F211C0 for ; Tue, 7 May 2024 13:33:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24EAA15F336; Tue, 7 May 2024 13:19:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QP86DZPw" 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 00754156F20; Tue, 7 May 2024 13:19:51 +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=1715087992; cv=none; b=jeEO1aZ8rs0VMfBDYzsI/MMynYHdJWI72N4rBseDVd9hLmrb8sByn2QxQQK+eiF1sswcWv+mbjObTFNZt5Nhm9bApNgdRRaqPm9GWIH7AUU7ahe0s3HDD6+VR7wVzSDaqVnqU0lL036Hd8V6CtJbf8f9oD6RCQeoavQFl2rRL88= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715087992; c=relaxed/simple; bh=mdcaTx8cr4EuijO3f+G4VMa/INC+vC+0vs1NUy/G+t8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ayi+d8AIM4UwNX1EvxaYP94MDKMXfBxlEk9PdY+cfKc1fotkRl34xVhapj3a6e9qGAgp4YSIkYHfdlqnwPgo1KvL3z2B7ONehKFpXWab9gIkkiCYFtaICEyM+VxNTs4YhjB3mTjx8Ohf51jsaxtPXTTlWOcoy+xowRuffPGYmfY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QP86DZPw; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 501FEC2BBFC; Tue, 7 May 2024 13:19:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715087991; bh=mdcaTx8cr4EuijO3f+G4VMa/INC+vC+0vs1NUy/G+t8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QP86DZPwbNGpLP/IHwk/hD+pHWOwxkfMY+j24l9Nlc1+J/aJsU20LCEzGuHHDsDo3 RhiGP4IFGt9oNBtFWq05qHp9mwA2775Obrtb8yy2h900P/B4MJ1hZqwVR3hRirMFXE /Ka3aIxdQg6fIv0DhPVxsr8Zl6MaP6yC8oexq0IKX3Ic5b7ljomH2QDWvvxtZ9JLzR NnGWrmVni74xvdDnuaftOlXKwXcjAoLcHhorJ3Yh/EZ9Y1O/WADQuBHIdkNcIswiFG AILgL8lFz6W5sBWf6x6iGPkqKNbXd902tHTTkYU+dlnMvC9YiF5zDh89e8yzMtMLRS xw8zuZ/9vGEdQ== From: Benjamin Tissoires Date: Tue, 07 May 2024 15:19:30 +0200 Subject: [PATCH RFC bpf-next 2/8] bpf: add kfunc_meta parameter to push_callback_call() 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: <20240507-bpf_async-v1-2-b4df966096d8@kernel.org> References: <20240507-bpf_async-v1-0-b4df966096d8@kernel.org> In-Reply-To: <20240507-bpf_async-v1-0-b4df966096d8@kernel.org> To: 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 , Mykola Lysenko , Shuah Khan Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715087980; l=8241; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=mdcaTx8cr4EuijO3f+G4VMa/INC+vC+0vs1NUy/G+t8=; b=1aGaI5o+lluCosEjLMQWR4X1KGGi0U1ytDRio/8X9irdTXH0RUpFLDy1DY/NzAX1F8ZGSOUft vxj90jRUoWGBBf14Ds+M/u/44zvYS1eIg0UQlefxV9yI7fAZsdCNBGj X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= No code change but is a preparatory patch for being able to declare async callbacks from bpf kfuncs. Signed-off-by: Benjamin Tissoires --- This is an RFC, and is not meant to be fully reviewed/applied as it is. I'm posting this to show what I wanted to explain in https://lore.kernel.org/bpf/mhkzkf4e23uvljtmwizwcxyuyat2tmfxn33xb4t7waafgmsa66@mcrzpj3b6ssx/ --- kernel/bpf/verifier.c | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 856cb77d0f87..2b1e24c440c5 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9339,11 +9339,13 @@ static void clear_caller_saved_regs(struct bpf_verifier_env *env, typedef int (*set_callee_state_fn)(struct bpf_verifier_env *env, struct bpf_func_state *caller, struct bpf_func_state *callee, - int insn_idx); + int insn_idx, + struct bpf_kfunc_call_arg_meta *meta); static int set_callee_state(struct bpf_verifier_env *env, struct bpf_func_state *caller, - struct bpf_func_state *callee, int insn_idx); + struct bpf_func_state *callee, int insn_idx, + struct bpf_kfunc_call_arg_meta *meta); static int setup_func_entry(struct bpf_verifier_env *env, int subprog, int callsite, set_callee_state_fn set_callee_state_cb, @@ -9381,7 +9383,7 @@ static int setup_func_entry(struct bpf_verifier_env *env, int subprog, int calls subprog /* subprog number within this prog */); /* Transfer references to the callee */ err = copy_reference_state(callee, caller); - err = err ?: set_callee_state_cb(env, caller, callee, callsite); + err = err ?: set_callee_state_cb(env, caller, callee, callsite, NULL); if (err) goto err_out; @@ -9518,7 +9520,8 @@ static int btf_check_subprog_call(struct bpf_verifier_env *env, int subprog, static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *insn, int insn_idx, int subprog, - set_callee_state_fn set_callee_state_cb) + set_callee_state_fn set_callee_state_cb, + struct bpf_kfunc_call_arg_meta *kfunc_meta) { struct bpf_verifier_state *state = env->cur_state, *callback_state; struct bpf_func_state *caller, *callee; @@ -9560,7 +9563,7 @@ static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *ins callee->async_entry_cnt = caller->async_entry_cnt + 1; /* Convert bpf_timer_set_callback() args into timer callback args */ - err = set_callee_state_cb(env, caller, callee, insn_idx); + err = set_callee_state_cb(env, caller, callee, insn_idx, kfunc_meta); if (err) return err; @@ -9691,7 +9694,8 @@ int map_set_for_each_callback_args(struct bpf_verifier_env *env, static int set_callee_state(struct bpf_verifier_env *env, struct bpf_func_state *caller, - struct bpf_func_state *callee, int insn_idx) + struct bpf_func_state *callee, int insn_idx, + struct bpf_kfunc_call_arg_meta *meta) { int i; @@ -9706,7 +9710,8 @@ static int set_callee_state(struct bpf_verifier_env *env, static int set_map_elem_callback_state(struct bpf_verifier_env *env, struct bpf_func_state *caller, struct bpf_func_state *callee, - int insn_idx) + int insn_idx, + struct bpf_kfunc_call_arg_meta *meta) { struct bpf_insn_aux_data *insn_aux = &env->insn_aux_data[insn_idx]; struct bpf_map *map; @@ -9732,7 +9737,8 @@ static int set_map_elem_callback_state(struct bpf_verifier_env *env, static int set_loop_callback_state(struct bpf_verifier_env *env, struct bpf_func_state *caller, struct bpf_func_state *callee, - int insn_idx) + int insn_idx, + struct bpf_kfunc_call_arg_meta *meta) { /* bpf_loop(u32 nr_loops, void *callback_fn, void *callback_ctx, * u64 flags); @@ -9754,7 +9760,8 @@ static int set_loop_callback_state(struct bpf_verifier_env *env, static int set_timer_callback_state(struct bpf_verifier_env *env, struct bpf_func_state *caller, struct bpf_func_state *callee, - int insn_idx) + int insn_idx, + struct bpf_kfunc_call_arg_meta *meta) { struct bpf_map *map_ptr = caller->regs[BPF_REG_1].map_ptr; @@ -9784,7 +9791,8 @@ static int set_timer_callback_state(struct bpf_verifier_env *env, static int set_find_vma_callback_state(struct bpf_verifier_env *env, struct bpf_func_state *caller, struct bpf_func_state *callee, - int insn_idx) + int insn_idx, + struct bpf_kfunc_call_arg_meta *meta) { /* bpf_find_vma(struct task_struct *task, u64 addr, * void *callback_fn, void *callback_ctx, u64 flags) @@ -9812,7 +9820,8 @@ static int set_find_vma_callback_state(struct bpf_verifier_env *env, static int set_user_ringbuf_callback_state(struct bpf_verifier_env *env, struct bpf_func_state *caller, struct bpf_func_state *callee, - int insn_idx) + int insn_idx, + struct bpf_kfunc_call_arg_meta *meta) { /* bpf_user_ringbuf_drain(struct bpf_map *map, void *callback_fn, void * callback_ctx, u64 flags); @@ -9835,7 +9844,8 @@ static int set_user_ringbuf_callback_state(struct bpf_verifier_env *env, static int set_rbtree_add_callback_state(struct bpf_verifier_env *env, struct bpf_func_state *caller, struct bpf_func_state *callee, - int insn_idx) + int insn_idx, + struct bpf_kfunc_call_arg_meta *meta) { /* void bpf_rbtree_add_impl(struct bpf_rb_root *root, struct bpf_rb_node *node, * bool (less)(struct bpf_rb_node *a, const struct bpf_rb_node *b)); @@ -10411,15 +10421,15 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn break; case BPF_FUNC_for_each_map_elem: err = push_callback_call(env, insn, insn_idx, meta.subprogno, - set_map_elem_callback_state); + set_map_elem_callback_state, NULL); break; case BPF_FUNC_timer_set_callback: err = push_callback_call(env, insn, insn_idx, meta.subprogno, - set_timer_callback_state); + set_timer_callback_state, NULL); break; case BPF_FUNC_find_vma: err = push_callback_call(env, insn, insn_idx, meta.subprogno, - set_find_vma_callback_state); + set_find_vma_callback_state, NULL); break; case BPF_FUNC_snprintf: err = check_bpf_snprintf_call(env, regs); @@ -10434,7 +10444,7 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn return err; if (cur_func(env)->callback_depth < regs[BPF_REG_1].umax_value) { err = push_callback_call(env, insn, insn_idx, meta.subprogno, - set_loop_callback_state); + set_loop_callback_state, NULL); } else { cur_func(env)->callback_depth = 0; if (env->log.level & BPF_LOG_LEVEL2) @@ -10537,7 +10547,7 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn } case BPF_FUNC_user_ringbuf_drain: err = push_callback_call(env, insn, insn_idx, meta.subprogno, - set_user_ringbuf_callback_state); + set_user_ringbuf_callback_state, NULL); break; } @@ -12285,7 +12295,7 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, if (meta.func_id == special_kfunc_list[KF_bpf_rbtree_add_impl]) { err = push_callback_call(env, insn, insn_idx, meta.subprogno, - set_rbtree_add_callback_state); + set_rbtree_add_callback_state, &meta); if (err) { verbose(env, "kfunc %s#%d failed callback verification\n", func_name, meta.func_id); @@ -12295,7 +12305,7 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, if (is_bpf_wq_set_callback_impl_kfunc(meta.func_id)) { err = push_callback_call(env, insn, insn_idx, meta.subprogno, - set_timer_callback_state); + set_timer_callback_state, &meta); if (err) { verbose(env, "kfunc %s#%d failed callback verification\n", func_name, meta.func_id); -- 2.44.0