Skip to content

Commit 998b17d

Browse files
oleg-nesterovchenhuacai
authored andcommitted
LoongArch: Make the users of larch_insn_gen_break() constant
LoongArch defines UPROBE_SWBP_INSN as a function call and this breaks arch_uprobe_trampoline() which uses it to initialize a static variable. Add the new "__builtin_constant_p" helper, __emit_break(), and redefine the current users of larch_insn_gen_break() to use it. Fixes: ff474a7 ("uprobe: Add uretprobe syscall to speed up return probe") Reported-by: Nathan Chancellor <nathan@kernel.org> Closes: https://lore.kernel.org/all/20240614174822.GA1185149@thelio-3990X/ Suggested-by: Andrii Nakryiko <andrii@kernel.org> Tested-by: Tiezhu Yang <yangtiezhu@loongson.cn> Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 3892b11 commit 998b17d

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

arch/loongarch/include/asm/inst.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,9 @@ static inline void emit_##NAME(union loongarch_instruction *insn, \
532532

533533
DEF_EMIT_REG0I15_FORMAT(break, break_op)
534534

535+
/* like emit_break(imm) but returns a constant expression */
536+
#define __emit_break(imm) ((u32)((imm) | (break_op << 15)))
537+
535538
#define DEF_EMIT_REG0I26_FORMAT(NAME, OP) \
536539
static inline void emit_##NAME(union loongarch_instruction *insn, \
537540
int offset) \

arch/loongarch/include/asm/uprobes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ typedef u32 uprobe_opcode_t;
99
#define MAX_UINSN_BYTES 8
1010
#define UPROBE_XOL_SLOT_BYTES MAX_UINSN_BYTES
1111

12-
#define UPROBE_SWBP_INSN larch_insn_gen_break(BRK_UPROBE_BP)
12+
#define UPROBE_SWBP_INSN __emit_break(BRK_UPROBE_BP)
1313
#define UPROBE_SWBP_INSN_SIZE LOONGARCH_INSN_SIZE
1414

15-
#define UPROBE_XOLBP_INSN larch_insn_gen_break(BRK_UPROBE_XOLBP)
15+
#define UPROBE_XOLBP_INSN __emit_break(BRK_UPROBE_XOLBP)
1616

1717
struct arch_uprobe {
1818
unsigned long resume_era;

arch/loongarch/kernel/kprobes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <linux/preempt.h>
55
#include <asm/break.h>
66

7-
#define KPROBE_BP_INSN larch_insn_gen_break(BRK_KPROBE_BP)
8-
#define KPROBE_SSTEPBP_INSN larch_insn_gen_break(BRK_KPROBE_SSTEPBP)
7+
#define KPROBE_BP_INSN __emit_break(BRK_KPROBE_BP)
8+
#define KPROBE_SSTEPBP_INSN __emit_break(BRK_KPROBE_SSTEPBP)
99

1010
DEFINE_PER_CPU(struct kprobe *, current_kprobe);
1111
DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);

0 commit comments

Comments
 (0)