[RFC PATCH bpf-next 2/6] bpf: Add max_acquired_refs to struct bpf_prog

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds max_acquired_refs to struct bpf_prog.

max_acquired_refs is used to record the maximum number of references
that a bpf program may have acquired at the same time.

Signed-off-by: Juntong Deng <juntong.deng@xxxxxxxxxxx>
---
 include/linux/bpf.h   | 1 +
 kernel/bpf/verifier.c | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index f3f50e29d639..3ccc20f936b2 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -1618,6 +1618,7 @@ struct bpf_prog {
 	enum bpf_attach_type	expected_attach_type; /* For some prog types */
 	u32			len;		/* Number of filter blocks */
 	u32			jited_len;	/* Size of jited insns in bytes */
+	u32			max_acquired_refs;
 	u8			tag[BPF_TAG_SIZE];
 	struct bpf_prog_stats __percpu *stats;
 	int __percpu		*active;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 9971c03adfd5..2d7f5aea90df 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1479,6 +1479,9 @@ static struct bpf_reference_state *acquire_reference_state(struct bpf_verifier_e
 		return NULL;
 	state->refs[new_ofs].insn_idx = insn_idx;
 
+	if (env->prog->max_acquired_refs < state->acquired_refs)
+		env->prog->max_acquired_refs = state->acquired_refs;
+
 	return &state->refs[new_ofs];
 }
 
@@ -18927,6 +18930,8 @@ static int do_check(struct bpf_verifier_env *env)
 	bool do_print_state = false;
 	int prev_insn_idx = -1;
 
+	env->prog->max_acquired_refs = 0;
+
 	for (;;) {
 		bool exception_exit = false;
 		struct bpf_insn *insn;
-- 
2.39.5





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux