mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	bpf: Enable private stack for eligible subprogs
If private stack is used by any subprog, set that subprog prog->aux->jits_use_priv_stack to be true so later jit can allocate private stack for that subprog properly. Also set env->prog->aux->jits_use_priv_stack to be true if any subprog uses private stack. This is a use case for a single main prog (no subprogs) to use private stack, and also a use case for later struct-ops progs where env->prog->aux->jits_use_priv_stack will enable recursion check if any subprog uses private stack. Signed-off-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20241112163912.2224007-1-yonghong.song@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
		
							parent
							
								
									a76ab5731e
								
							
						
					
					
						commit
						e00931c025
					
				
					 2 changed files with 12 additions and 0 deletions
				
			
		| 
						 | 
					@ -1523,6 +1523,7 @@ struct bpf_prog_aux {
 | 
				
			||||||
	bool exception_cb;
 | 
						bool exception_cb;
 | 
				
			||||||
	bool exception_boundary;
 | 
						bool exception_boundary;
 | 
				
			||||||
	bool is_extended; /* true if extended by freplace program */
 | 
						bool is_extended; /* true if extended by freplace program */
 | 
				
			||||||
 | 
						bool jits_use_priv_stack;
 | 
				
			||||||
	u64 prog_array_member_cnt; /* counts how many times as member of prog_array */
 | 
						u64 prog_array_member_cnt; /* counts how many times as member of prog_array */
 | 
				
			||||||
	struct mutex ext_mutex; /* mutex for is_extended and prog_array_member_cnt */
 | 
						struct mutex ext_mutex; /* mutex for is_extended and prog_array_member_cnt */
 | 
				
			||||||
	struct bpf_arena *arena;
 | 
						struct bpf_arena *arena;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6334,6 +6334,14 @@ static int check_max_stack_depth(struct bpf_verifier_env *env)
 | 
				
			||||||
				return ret;
 | 
									return ret;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (int i = 0; i < env->subprog_cnt; i++) {
 | 
				
			||||||
 | 
							if (si[i].priv_stack_mode == PRIV_STACK_ADAPTIVE) {
 | 
				
			||||||
 | 
								env->prog->aux->jits_use_priv_stack = true;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20274,6 +20282,9 @@ static int jit_subprogs(struct bpf_verifier_env *env)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		func[i]->aux->name[0] = 'F';
 | 
							func[i]->aux->name[0] = 'F';
 | 
				
			||||||
		func[i]->aux->stack_depth = env->subprog_info[i].stack_depth;
 | 
							func[i]->aux->stack_depth = env->subprog_info[i].stack_depth;
 | 
				
			||||||
 | 
							if (env->subprog_info[i].priv_stack_mode == PRIV_STACK_ADAPTIVE)
 | 
				
			||||||
 | 
								func[i]->aux->jits_use_priv_stack = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		func[i]->jit_requested = 1;
 | 
							func[i]->jit_requested = 1;
 | 
				
			||||||
		func[i]->blinding_requested = prog->blinding_requested;
 | 
							func[i]->blinding_requested = prog->blinding_requested;
 | 
				
			||||||
		func[i]->aux->kfunc_tab = prog->aux->kfunc_tab;
 | 
							func[i]->aux->kfunc_tab = prog->aux->kfunc_tab;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue