Skip to content

Commit a30df1e

Browse files
committed
Merge tag 'riscv-for-linus-6.2-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: - A build fix to avoid static branches in cpu_relax(), which greatly inflates the jump tables and breaks at least CONFIG_CC_OPTIMIZE_FOR_SIZE=y. - A fix for a kernel panic when probing impossible instruction positions. - A fix to disable unwind tables, which are enabled by default for GCC-13 and result in unhandled relocations in modules. * tag 'riscv-for-linus-6.2-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: disable generation of unwind tables riscv: kprobe: Fixup kernel panic when probing an illegal position riscv: Fix build with CONFIG_CC_OPTIMIZE_FOR_SIZE=y
2 parents bffede3 + 2f394c0 commit a30df1e

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

arch/riscv/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ ifeq ($(CONFIG_PERF_EVENTS),y)
8080
KBUILD_CFLAGS += -fno-omit-frame-pointer
8181
endif
8282

83+
# Avoid generating .eh_frame sections.
84+
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
85+
8386
KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
8487
KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
8588

arch/riscv/include/asm/hwcap.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ static_assert(RISCV_ISA_EXT_ID_MAX <= RISCV_ISA_EXT_MAX);
7070
*/
7171
enum riscv_isa_ext_key {
7272
RISCV_ISA_EXT_KEY_FPU, /* For 'F' and 'D' */
73-
RISCV_ISA_EXT_KEY_ZIHINTPAUSE,
7473
RISCV_ISA_EXT_KEY_SVINVAL,
7574
RISCV_ISA_EXT_KEY_MAX,
7675
};
@@ -91,8 +90,6 @@ static __always_inline int riscv_isa_ext2key(int num)
9190
return RISCV_ISA_EXT_KEY_FPU;
9291
case RISCV_ISA_EXT_d:
9392
return RISCV_ISA_EXT_KEY_FPU;
94-
case RISCV_ISA_EXT_ZIHINTPAUSE:
95-
return RISCV_ISA_EXT_KEY_ZIHINTPAUSE;
9693
case RISCV_ISA_EXT_SVINVAL:
9794
return RISCV_ISA_EXT_KEY_SVINVAL;
9895
default:

arch/riscv/include/asm/vdso/processor.h

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,26 @@
44

55
#ifndef __ASSEMBLY__
66

7-
#include <linux/jump_label.h>
87
#include <asm/barrier.h>
9-
#include <asm/hwcap.h>
108

119
static inline void cpu_relax(void)
1210
{
13-
if (!static_branch_likely(&riscv_isa_ext_keys[RISCV_ISA_EXT_KEY_ZIHINTPAUSE])) {
1411
#ifdef __riscv_muldiv
15-
int dummy;
16-
/* In lieu of a halt instruction, induce a long-latency stall. */
17-
__asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy));
12+
int dummy;
13+
/* In lieu of a halt instruction, induce a long-latency stall. */
14+
__asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy));
1815
#endif
19-
} else {
20-
/*
21-
* Reduce instruction retirement.
22-
* This assumes the PC changes.
23-
*/
24-
#ifdef CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE
25-
__asm__ __volatile__ ("pause");
16+
17+
#ifdef __riscv_zihintpause
18+
/*
19+
* Reduce instruction retirement.
20+
* This assumes the PC changes.
21+
*/
22+
__asm__ __volatile__ ("pause");
2623
#else
27-
/* Encoding of the pause instruction */
28-
__asm__ __volatile__ (".4byte 0x100000F");
24+
/* Encoding of the pause instruction */
25+
__asm__ __volatile__ (".4byte 0x100000F");
2926
#endif
30-
}
3127
barrier();
3228
}
3329

arch/riscv/kernel/probes/kprobes.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,31 @@ static void __kprobes arch_simulate_insn(struct kprobe *p, struct pt_regs *regs)
4848
post_kprobe_handler(p, kcb, regs);
4949
}
5050

51+
static bool __kprobes arch_check_kprobe(struct kprobe *p)
52+
{
53+
unsigned long tmp = (unsigned long)p->addr - p->offset;
54+
unsigned long addr = (unsigned long)p->addr;
55+
56+
while (tmp <= addr) {
57+
if (tmp == addr)
58+
return true;
59+
60+
tmp += GET_INSN_LENGTH(*(u16 *)tmp);
61+
}
62+
63+
return false;
64+
}
65+
5166
int __kprobes arch_prepare_kprobe(struct kprobe *p)
5267
{
5368
unsigned long probe_addr = (unsigned long)p->addr;
5469

5570
if (probe_addr & 0x1)
5671
return -EILSEQ;
5772

73+
if (!arch_check_kprobe(p))
74+
return -EILSEQ;
75+
5876
/* copy instruction */
5977
p->opcode = *p->addr;
6078

0 commit comments

Comments
 (0)