Skip to content

Commit 8d8d18c

Browse files
daviddaneydavem330
authored andcommitted
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent da6817e commit 8d8d18c

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

arch/mips/net/ebpf_jit.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct jit_ctx {
113113
u64 *reg_val_types;
114114
unsigned int long_b_conversion:1;
115115
unsigned int gen_b_offsets:1;
116+
unsigned int use_bbit_insns:1;
116117
};
117118

118119
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)
655656
return build_int_epilogue(ctx, MIPS_R_T9);
656657
}
657658

658-
static bool use_bbit_insns(void)
659-
{
660-
switch (current_cpu_type()) {
661-
case CPU_CAVIUM_OCTEON:
662-
case CPU_CAVIUM_OCTEON_PLUS:
663-
case CPU_CAVIUM_OCTEON2:
664-
case CPU_CAVIUM_OCTEON3:
665-
return true;
666-
default:
667-
return false;
668-
}
669-
}
670-
671659
static bool is_bad_offset(int b_off)
672660
{
673661
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,
11981186
if (dst < 0)
11991187
return dst;
12001188

1201-
if (use_bbit_insns() && hweight32((u32)insn->imm) == 1) {
1189+
if (ctx->use_bbit_insns && hweight32((u32)insn->imm) == 1) {
12021190
if ((insn + 1)->code == (BPF_JMP | BPF_EXIT) && insn->off == 1) {
12031191
b_off = b_imm(exit_idx, ctx);
12041192
if (is_bad_offset(b_off))
@@ -1853,6 +1841,18 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
18531841

18541842
memset(&ctx, 0, sizeof(ctx));
18551843

1844+
preempt_disable();
1845+
switch (current_cpu_type()) {
1846+
case CPU_CAVIUM_OCTEON:
1847+
case CPU_CAVIUM_OCTEON_PLUS:
1848+
case CPU_CAVIUM_OCTEON2:
1849+
case CPU_CAVIUM_OCTEON3:
1850+
ctx.use_bbit_insns = 1;
1851+
default:
1852+
ctx.use_bbit_insns = 0;
1853+
}
1854+
preempt_enable();
1855+
18561856
ctx.offsets = kcalloc(prog->len + 1, sizeof(*ctx.offsets), GFP_KERNEL);
18571857
if (ctx.offsets == NULL)
18581858
goto out_err;

0 commit comments

Comments
 (0)