BPF List
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>,
	Tejun Heo <tj@kernel.org>
Subject: [PATCH bpf-next v5 2/9] bpf: Support private stack for struct_ops programs
Date: Thu, 17 Oct 2024 15:31:48 -0700	[thread overview]
Message-ID: <20241017223148.3176403-1-yonghong.song@linux.dev> (raw)
In-Reply-To: <20241017223138.3175885-1-yonghong.song@linux.dev>

Add 'priv_stack_allowed()' callback function in bpf_verifier_ops. If the
callback function returns true, the struct_ops are eligible to
use private stack. Otherwise, normal kernel stack is used.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
---
 include/linux/bpf.h   | 1 +
 kernel/bpf/verifier.c | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 6ad8ace7075a..a789cd2f5d6a 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -988,6 +988,7 @@ struct bpf_verifier_ops {
 	int (*btf_struct_access)(struct bpf_verifier_log *log,
 				 const struct bpf_reg_state *reg,
 				 int off, int size);
+	bool (*priv_stack_allowed)(void);
 };
 
 struct bpf_prog_offload_ops {
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index a12f5e823284..a14857015ad4 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -5995,6 +5995,8 @@ static bool bpf_enable_private_stack(struct bpf_verifier_env *env)
 	case BPF_PROG_TYPE_PERF_EVENT:
 	case BPF_PROG_TYPE_RAW_TRACEPOINT:
 		return true;
+	case BPF_PROG_TYPE_STRUCT_OPS:
+		return env->ops->priv_stack_allowed && env->ops->priv_stack_allowed();
 	case BPF_PROG_TYPE_TRACING:
 		if (env->prog->expected_attach_type != BPF_TRACE_ITER)
 			return true;
-- 
2.43.5


  parent reply	other threads:[~2024-10-17 22:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17 22:31 [PATCH bpf-next v5 0/9] bpf: Support private stack for bpf progs Yonghong Song
2024-10-17 22:31 ` [PATCH bpf-next v5 1/9] bpf: Allow each subprog having stack size of 512 bytes Yonghong Song
2024-10-17 22:31 ` Yonghong Song [this message]
2024-10-17 22:31 ` [PATCH bpf-next v5 3/9] sched-ext: Allow sched-ext progs to use private stack Yonghong Song
2024-10-17 22:31 ` [PATCH bpf-next v5 4/9] bpf: Mark each subprog with proper private stack modes Yonghong Song
2024-10-17 22:32 ` [PATCH bpf-next v5 5/9] bpf, x86: Refactor func emit_prologue Yonghong Song
2024-10-17 22:32 ` [PATCH bpf-next v5 6/9] bpf, x86: Create a helper for certain "reg <op>= imm" operations Yonghong Song
2024-10-17 22:32 ` [PATCH bpf-next v5 7/9] bpf, x86: Add jit support for private stack Yonghong Song
2024-10-20 19:52   ` kernel test robot
2024-10-21  4:44     ` Yonghong Song
2024-10-17 22:32 ` [PATCH bpf-next v5 8/9] selftests/bpf: Add tracing prog private stack tests Yonghong Song
2024-10-17 22:32 ` [PATCH bpf-next v5 9/9] selftests/bpf: Add struct_ops " Yonghong Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241017223148.3176403-1-yonghong.song@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox