RISC-V Fixes for 6.3-rc2
* 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. -----BEGIN PGP SIGNATURE----- iQJHBAABCAAxFiEEKzw3R0RoQ7JKlDp6LhMZ81+7GIkFAmQLXKsTHHBhbG1lckBk YWJiZWx0LmNvbQAKCRAuExnzX7sYiTd6D/9QxHDNOEiyrY7bSLkbeLiRvASXyMyx /oKT8fmfsaikJngM/ZttQOiCEqPUDdeFfw0Mg3V9WxvrUsRtKDtfRN+pTUirFKpB yWMAHuQ69QaWUJqaxfRa6JhyjgbnOCp3t/8RM/TywU3O4QG2MWbPg8QENnxtDAUN X4zNis6xx19PCT2508irZNGysgIqlIRcDRJ/x85LQXIQBRREAnNTojgepwUxfDeZ E4iPjlPU/i0eFeqpZkd3vZjjpkAZ91VfqCqmJTKv7JGKg0xeKM4z+EGlhNiS8odF W9YS6Sf1wCa5smhq4vTF4PGEpineK+KrdJ5lPZXLKbbNtv/c1YNVSXBdi88DsWEn jYnptL5mKWXAAIdOKdP50LjmiwDQP3BCqR+Ck9HYvPEST65QRwYC2pvReszsX5Bu guiNSFuh0eEszu6VqJCFjrPKxLGODi0Ug2XeJd5NQ2sd7OkkrUP0wuJaYbn+xnUb RWJNZY5jpKf+euPuJd5VgPiiOiOE+7gfG0X3bOB27f2OJPS4BFT8Z5NTzIx3qUet I7hwuXHhNCCl+loczljNnwDZO1g4ktAvOjrRm42MZ2ERyAAvso9UiaI+zdciATP7 UgWvxybQc8oe+XAPpsnr5UwBl3Hy9o1ELXBY1avV8b5XQy7tAIP5eQW4R7nNYxM7 DvNBcO8rOEFx0w== =goS0 -----END PGP SIGNATURE----- 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
This commit is contained in:
commit
55a21105ec
@ -84,6 +84,13 @@ endif
|
|||||||
# Avoid generating .eh_frame sections.
|
# Avoid generating .eh_frame sections.
|
||||||
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
|
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
|
||||||
|
|
||||||
|
# The RISC-V attributes frequently cause compatibility issues and provide no
|
||||||
|
# information, so just turn them off.
|
||||||
|
KBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute)
|
||||||
|
KBUILD_AFLAGS += $(call cc-option,-mno-riscv-attribute)
|
||||||
|
KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
|
||||||
|
KBUILD_AFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
|
||||||
|
|
||||||
KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
|
KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
|
||||||
KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
|
KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ void __init_or_module sifive_errata_patch_func(struct alt_entry *begin,
|
|||||||
mutex_lock(&text_mutex);
|
mutex_lock(&text_mutex);
|
||||||
patch_text_nosync(ALT_OLD_PTR(alt), ALT_ALT_PTR(alt),
|
patch_text_nosync(ALT_OLD_PTR(alt), ALT_ALT_PTR(alt),
|
||||||
alt->alt_len);
|
alt->alt_len);
|
||||||
mutex_lock(&text_mutex);
|
mutex_unlock(&text_mutex);
|
||||||
cpu_apply_errata |= tmp;
|
cpu_apply_errata |= tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,6 @@ int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
|
|||||||
#define ftrace_init_nop ftrace_init_nop
|
#define ftrace_init_nop ftrace_init_nop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif /* CONFIG_DYNAMIC_FTRACE */
|
||||||
|
|
||||||
#endif /* _ASM_RISCV_FTRACE_H */
|
#endif /* _ASM_RISCV_FTRACE_H */
|
||||||
|
@ -9,4 +9,6 @@
|
|||||||
int patch_text_nosync(void *addr, const void *insns, size_t len);
|
int patch_text_nosync(void *addr, const void *insns, size_t len);
|
||||||
int patch_text(void *addr, u32 *insns, int ninsns);
|
int patch_text(void *addr, u32 *insns, int ninsns);
|
||||||
|
|
||||||
|
extern int riscv_patch_in_stop_machine;
|
||||||
|
|
||||||
#endif /* _ASM_RISCV_PATCH_H */
|
#endif /* _ASM_RISCV_PATCH_H */
|
||||||
|
@ -14,6 +14,10 @@ COMPAT_LD := $(LD)
|
|||||||
COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32
|
COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32
|
||||||
COMPAT_LD_FLAGS := -melf32lriscv
|
COMPAT_LD_FLAGS := -melf32lriscv
|
||||||
|
|
||||||
|
# Disable attributes, as they're useless and break the build.
|
||||||
|
COMPAT_CC_FLAGS += $(call cc-option,-mno-riscv-attribute)
|
||||||
|
COMPAT_CC_FLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
|
||||||
|
|
||||||
# Files to link into the compat_vdso
|
# Files to link into the compat_vdso
|
||||||
obj-compat_vdso = $(patsubst %, %.o, $(compat_vdso-syms)) note.o
|
obj-compat_vdso = $(patsubst %, %.o, $(compat_vdso-syms)) note.o
|
||||||
|
|
||||||
|
@ -15,10 +15,19 @@
|
|||||||
void ftrace_arch_code_modify_prepare(void) __acquires(&text_mutex)
|
void ftrace_arch_code_modify_prepare(void) __acquires(&text_mutex)
|
||||||
{
|
{
|
||||||
mutex_lock(&text_mutex);
|
mutex_lock(&text_mutex);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The code sequences we use for ftrace can't be patched while the
|
||||||
|
* kernel is running, so we need to use stop_machine() to modify them
|
||||||
|
* for now. This doesn't play nice with text_mutex, we use this flag
|
||||||
|
* to elide the check.
|
||||||
|
*/
|
||||||
|
riscv_patch_in_stop_machine = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ftrace_arch_code_modify_post_process(void) __releases(&text_mutex)
|
void ftrace_arch_code_modify_post_process(void) __releases(&text_mutex)
|
||||||
{
|
{
|
||||||
|
riscv_patch_in_stop_machine = false;
|
||||||
mutex_unlock(&text_mutex);
|
mutex_unlock(&text_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,9 +116,9 @@ int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
|
|||||||
{
|
{
|
||||||
int out;
|
int out;
|
||||||
|
|
||||||
ftrace_arch_code_modify_prepare();
|
mutex_lock(&text_mutex);
|
||||||
out = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
|
out = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
|
||||||
ftrace_arch_code_modify_post_process();
|
mutex_unlock(&text_mutex);
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <asm/kprobes.h>
|
#include <asm/kprobes.h>
|
||||||
#include <asm/cacheflush.h>
|
#include <asm/cacheflush.h>
|
||||||
#include <asm/fixmap.h>
|
#include <asm/fixmap.h>
|
||||||
|
#include <asm/ftrace.h>
|
||||||
#include <asm/patch.h>
|
#include <asm/patch.h>
|
||||||
|
|
||||||
struct patch_insn {
|
struct patch_insn {
|
||||||
@ -20,6 +21,8 @@ struct patch_insn {
|
|||||||
atomic_t cpu_count;
|
atomic_t cpu_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int riscv_patch_in_stop_machine = false;
|
||||||
|
|
||||||
#ifdef CONFIG_MMU
|
#ifdef CONFIG_MMU
|
||||||
/*
|
/*
|
||||||
* The fix_to_virt(, idx) needs a const value (not a dynamic variable of
|
* The fix_to_virt(, idx) needs a const value (not a dynamic variable of
|
||||||
@ -60,8 +63,15 @@ static int patch_insn_write(void *addr, const void *insn, size_t len)
|
|||||||
* Before reaching here, it was expected to lock the text_mutex
|
* Before reaching here, it was expected to lock the text_mutex
|
||||||
* already, so we don't need to give another lock here and could
|
* already, so we don't need to give another lock here and could
|
||||||
* ensure that it was safe between each cores.
|
* ensure that it was safe between each cores.
|
||||||
|
*
|
||||||
|
* We're currently using stop_machine() for ftrace & kprobes, and while
|
||||||
|
* that ensures text_mutex is held before installing the mappings it
|
||||||
|
* does not ensure text_mutex is held by the calling thread. That's
|
||||||
|
* safe but triggers a lockdep failure, so just elide it for that
|
||||||
|
* specific case.
|
||||||
*/
|
*/
|
||||||
lockdep_assert_held(&text_mutex);
|
if (!riscv_patch_in_stop_machine)
|
||||||
|
lockdep_assert_held(&text_mutex);
|
||||||
|
|
||||||
if (across_pages)
|
if (across_pages)
|
||||||
patch_map(addr + len, FIX_TEXT_POKE1);
|
patch_map(addr + len, FIX_TEXT_POKE1);
|
||||||
@ -125,6 +135,7 @@ NOKPROBE_SYMBOL(patch_text_cb);
|
|||||||
|
|
||||||
int patch_text(void *addr, u32 *insns, int ninsns)
|
int patch_text(void *addr, u32 *insns, int ninsns)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
struct patch_insn patch = {
|
struct patch_insn patch = {
|
||||||
.addr = addr,
|
.addr = addr,
|
||||||
.insns = insns,
|
.insns = insns,
|
||||||
@ -132,7 +143,18 @@ int patch_text(void *addr, u32 *insns, int ninsns)
|
|||||||
.cpu_count = ATOMIC_INIT(0),
|
.cpu_count = ATOMIC_INIT(0),
|
||||||
};
|
};
|
||||||
|
|
||||||
return stop_machine_cpuslocked(patch_text_cb,
|
/*
|
||||||
&patch, cpu_online_mask);
|
* kprobes takes text_mutex, before calling patch_text(), but as we call
|
||||||
|
* calls stop_machine(), the lockdep assertion in patch_insn_write()
|
||||||
|
* gets confused by the context in which the lock is taken.
|
||||||
|
* Instead, ensure the lock is held before calling stop_machine(), and
|
||||||
|
* set riscv_patch_in_stop_machine to skip the check in
|
||||||
|
* patch_insn_write().
|
||||||
|
*/
|
||||||
|
lockdep_assert_held(&text_mutex);
|
||||||
|
riscv_patch_in_stop_machine = true;
|
||||||
|
ret = stop_machine_cpuslocked(patch_text_cb, &patch, cpu_online_mask);
|
||||||
|
riscv_patch_in_stop_machine = false;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
NOKPROBE_SYMBOL(patch_text);
|
NOKPROBE_SYMBOL(patch_text);
|
||||||
|
@ -101,7 +101,7 @@ void notrace walk_stackframe(struct task_struct *task,
|
|||||||
while (!kstack_end(ksp)) {
|
while (!kstack_end(ksp)) {
|
||||||
if (__kernel_text_address(pc) && unlikely(!fn(arg, pc)))
|
if (__kernel_text_address(pc) && unlikely(!fn(arg, pc)))
|
||||||
break;
|
break;
|
||||||
pc = (*ksp++) - 0x4;
|
pc = READ_ONCE_NOCHECK(*ksp++) - 0x4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user