mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	MIPS,bpf: Fix using smp_processor_id() in preemptible splat.
If the kernel is configured with preemption enabled we were getting warning stack traces for use of current_cpu_type(). Fix by moving the test between preempt_disable()/preempt_enable() and caching the results of the CPU type tests for use during code generation. Signed-off-by: David Daney <david.daney@cavium.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									da6817ebc3
								
							
						
					
					
						commit
						8d8d18c328
					
				
					 1 changed files with 14 additions and 14 deletions
				
			
		| 
						 | 
					@ -113,6 +113,7 @@ struct jit_ctx {
 | 
				
			||||||
	u64 *reg_val_types;
 | 
						u64 *reg_val_types;
 | 
				
			||||||
	unsigned int long_b_conversion:1;
 | 
						unsigned int long_b_conversion:1;
 | 
				
			||||||
	unsigned int gen_b_offsets:1;
 | 
						unsigned int gen_b_offsets:1;
 | 
				
			||||||
 | 
						unsigned int use_bbit_insns:1;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void set_reg_val_type(u64 *rvt, int reg, enum reg_val_type type)
 | 
					static void set_reg_val_type(u64 *rvt, int reg, enum reg_val_type type)
 | 
				
			||||||
| 
						 | 
					@ -655,19 +656,6 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int this_idx)
 | 
				
			||||||
	return build_int_epilogue(ctx, MIPS_R_T9);
 | 
						return build_int_epilogue(ctx, MIPS_R_T9);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool use_bbit_insns(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	switch (current_cpu_type()) {
 | 
					 | 
				
			||||||
	case CPU_CAVIUM_OCTEON:
 | 
					 | 
				
			||||||
	case CPU_CAVIUM_OCTEON_PLUS:
 | 
					 | 
				
			||||||
	case CPU_CAVIUM_OCTEON2:
 | 
					 | 
				
			||||||
	case CPU_CAVIUM_OCTEON3:
 | 
					 | 
				
			||||||
		return true;
 | 
					 | 
				
			||||||
	default:
 | 
					 | 
				
			||||||
		return false;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static bool is_bad_offset(int b_off)
 | 
					static bool is_bad_offset(int b_off)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return b_off > 0x1ffff || b_off < -0x20000;
 | 
						return b_off > 0x1ffff || b_off < -0x20000;
 | 
				
			||||||
| 
						 | 
					@ -1198,7 +1186,7 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
 | 
				
			||||||
		if (dst < 0)
 | 
							if (dst < 0)
 | 
				
			||||||
			return dst;
 | 
								return dst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (use_bbit_insns() && hweight32((u32)insn->imm) == 1) {
 | 
							if (ctx->use_bbit_insns && hweight32((u32)insn->imm) == 1) {
 | 
				
			||||||
			if ((insn + 1)->code == (BPF_JMP | BPF_EXIT) && insn->off == 1) {
 | 
								if ((insn + 1)->code == (BPF_JMP | BPF_EXIT) && insn->off == 1) {
 | 
				
			||||||
				b_off = b_imm(exit_idx, ctx);
 | 
									b_off = b_imm(exit_idx, ctx);
 | 
				
			||||||
				if (is_bad_offset(b_off))
 | 
									if (is_bad_offset(b_off))
 | 
				
			||||||
| 
						 | 
					@ -1853,6 +1841,18 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memset(&ctx, 0, sizeof(ctx));
 | 
						memset(&ctx, 0, sizeof(ctx));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						preempt_disable();
 | 
				
			||||||
 | 
						switch (current_cpu_type()) {
 | 
				
			||||||
 | 
						case CPU_CAVIUM_OCTEON:
 | 
				
			||||||
 | 
						case CPU_CAVIUM_OCTEON_PLUS:
 | 
				
			||||||
 | 
						case CPU_CAVIUM_OCTEON2:
 | 
				
			||||||
 | 
						case CPU_CAVIUM_OCTEON3:
 | 
				
			||||||
 | 
							ctx.use_bbit_insns = 1;
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							ctx.use_bbit_insns = 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						preempt_enable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ctx.offsets = kcalloc(prog->len + 1, sizeof(*ctx.offsets), GFP_KERNEL);
 | 
						ctx.offsets = kcalloc(prog->len + 1, sizeof(*ctx.offsets), GFP_KERNEL);
 | 
				
			||||||
	if (ctx.offsets == NULL)
 | 
						if (ctx.offsets == NULL)
 | 
				
			||||||
		goto out_err;
 | 
							goto out_err;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue