Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'riscv-for-linus-6.3-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux

Pull RISC-V fixes from Palmer Dabbelt:

- RISC-V architecture-specific ELF attributes have been disabled in the
kernel builds

- A fix for a locking failure while during errata patching that
manifests on SiFive-based systems

- A fix for a KASAN failure during stack unwinding

- A fix for some lockdep failures during text patching

* tag 'riscv-for-linus-6.3-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux:
RISC-V: Don't check text_mutex during stop_machine
riscv: Use READ_ONCE_NOCHECK in imprecise unwinding stack mode
RISC-V: fix taking the text_mutex twice during sifive errata patching
RISC-V: Stop emitting attributes

+52 -8
+7
arch/riscv/Makefile
··· 84 84 # Avoid generating .eh_frame sections. 85 85 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables 86 86 87 + # The RISC-V attributes frequently cause compatibility issues and provide no 88 + # information, so just turn them off. 89 + KBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute) 90 + KBUILD_AFLAGS += $(call cc-option,-mno-riscv-attribute) 91 + KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr) 92 + KBUILD_AFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr) 93 + 87 94 KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax) 88 95 KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax) 89 96
+1 -1
arch/riscv/errata/sifive/errata.c
··· 111 111 mutex_lock(&text_mutex); 112 112 patch_text_nosync(ALT_OLD_PTR(alt), ALT_ALT_PTR(alt), 113 113 alt->alt_len); 114 - mutex_lock(&text_mutex); 114 + mutex_unlock(&text_mutex); 115 115 cpu_apply_errata |= tmp; 116 116 } 117 117 }
+1 -1
arch/riscv/include/asm/ftrace.h
··· 109 109 #define ftrace_init_nop ftrace_init_nop 110 110 #endif 111 111 112 - #endif 112 + #endif /* CONFIG_DYNAMIC_FTRACE */ 113 113 114 114 #endif /* _ASM_RISCV_FTRACE_H */
+2
arch/riscv/include/asm/patch.h
··· 9 9 int patch_text_nosync(void *addr, const void *insns, size_t len); 10 10 int patch_text(void *addr, u32 *insns, int ninsns); 11 11 12 + extern int riscv_patch_in_stop_machine; 13 + 12 14 #endif /* _ASM_RISCV_PATCH_H */
+4
arch/riscv/kernel/compat_vdso/Makefile
··· 14 14 COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32 15 15 COMPAT_LD_FLAGS := -melf32lriscv 16 16 17 + # Disable attributes, as they're useless and break the build. 18 + COMPAT_CC_FLAGS += $(call cc-option,-mno-riscv-attribute) 19 + COMPAT_CC_FLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr) 20 + 17 21 # Files to link into the compat_vdso 18 22 obj-compat_vdso = $(patsubst %, %.o, $(compat_vdso-syms)) note.o 19 23
+11 -2
arch/riscv/kernel/ftrace.c
··· 15 15 void ftrace_arch_code_modify_prepare(void) __acquires(&text_mutex) 16 16 { 17 17 mutex_lock(&text_mutex); 18 + 19 + /* 20 + * The code sequences we use for ftrace can't be patched while the 21 + * kernel is running, so we need to use stop_machine() to modify them 22 + * for now. This doesn't play nice with text_mutex, we use this flag 23 + * to elide the check. 24 + */ 25 + riscv_patch_in_stop_machine = true; 18 26 } 19 27 20 28 void ftrace_arch_code_modify_post_process(void) __releases(&text_mutex) 21 29 { 30 + riscv_patch_in_stop_machine = false; 22 31 mutex_unlock(&text_mutex); 23 32 } 24 33 ··· 116 107 { 117 108 int out; 118 109 119 - ftrace_arch_code_modify_prepare(); 110 + mutex_lock(&text_mutex); 120 111 out = ftrace_make_nop(mod, rec, MCOUNT_ADDR); 121 - ftrace_arch_code_modify_post_process(); 112 + mutex_unlock(&text_mutex); 122 113 123 114 return out; 124 115 }
+25 -3
arch/riscv/kernel/patch.c
··· 11 11 #include <asm/kprobes.h> 12 12 #include <asm/cacheflush.h> 13 13 #include <asm/fixmap.h> 14 + #include <asm/ftrace.h> 14 15 #include <asm/patch.h> 15 16 16 17 struct patch_insn { ··· 20 19 int ninsns; 21 20 atomic_t cpu_count; 22 21 }; 22 + 23 + int riscv_patch_in_stop_machine = false; 23 24 24 25 #ifdef CONFIG_MMU 25 26 /* ··· 63 60 * Before reaching here, it was expected to lock the text_mutex 64 61 * already, so we don't need to give another lock here and could 65 62 * ensure that it was safe between each cores. 63 + * 64 + * We're currently using stop_machine() for ftrace & kprobes, and while 65 + * that ensures text_mutex is held before installing the mappings it 66 + * does not ensure text_mutex is held by the calling thread. That's 67 + * safe but triggers a lockdep failure, so just elide it for that 68 + * specific case. 66 69 */ 67 - lockdep_assert_held(&text_mutex); 70 + if (!riscv_patch_in_stop_machine) 71 + lockdep_assert_held(&text_mutex); 68 72 69 73 if (across_pages) 70 74 patch_map(addr + len, FIX_TEXT_POKE1); ··· 135 125 136 126 int patch_text(void *addr, u32 *insns, int ninsns) 137 127 { 128 + int ret; 138 129 struct patch_insn patch = { 139 130 .addr = addr, 140 131 .insns = insns, ··· 143 132 .cpu_count = ATOMIC_INIT(0), 144 133 }; 145 134 146 - return stop_machine_cpuslocked(patch_text_cb, 147 - &patch, cpu_online_mask); 135 + /* 136 + * kprobes takes text_mutex, before calling patch_text(), but as we call 137 + * calls stop_machine(), the lockdep assertion in patch_insn_write() 138 + * gets confused by the context in which the lock is taken. 139 + * Instead, ensure the lock is held before calling stop_machine(), and 140 + * set riscv_patch_in_stop_machine to skip the check in 141 + * patch_insn_write(). 142 + */ 143 + lockdep_assert_held(&text_mutex); 144 + riscv_patch_in_stop_machine = true; 145 + ret = stop_machine_cpuslocked(patch_text_cb, &patch, cpu_online_mask); 146 + riscv_patch_in_stop_machine = false; 147 + return ret; 148 148 } 149 149 NOKPROBE_SYMBOL(patch_text);
+1 -1
arch/riscv/kernel/stacktrace.c
··· 101 101 while (!kstack_end(ksp)) { 102 102 if (__kernel_text_address(pc) && unlikely(!fn(arg, pc))) 103 103 break; 104 - pc = (*ksp++) - 0x4; 104 + pc = READ_ONCE_NOCHECK(*ksp++) - 0x4; 105 105 } 106 106 } 107 107