summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-11-22 12:50:24 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2026-11-22 12:50:24 -0800
commit2681617eb9317444247380298564f58142fc4ff8 (patch)
treeda4b8c13e8a3d89c10dc103808946be5d06f72de
parent1fadec005439186c67ca7be35c4e90727bc38fae (diff)
parentfc91dacd0c2b4f9ca7e0ce30016f5aee6256cba5 (diff)
Merge tag 'riscv-for-linus-7.4-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Paul Walmsley: - Fix a bug in the context switch code that can allow the switched-to task to inadvertently inherit the supervisor user memory access privilege from the switched-from task - Protect the regs->status RMW sequences in the vector register context switch code, to fix a potential floating point state corruption bug - Fix the return values from the early boot unaligned access speed detection functions called by __setup() to return 0 on failure, rather than an error code, as 0 is what __setup() expects to receive upon an error - Prevent the DTB from being potentially overwritten early in boot by reserving it in memblock before scanning the /reserved-memory section of the DTB - Fix hugetlb vmemmap optimization and a few other code paths that map kernel pages as read-only by defining PAGE_KERNEL_RO - Fix an error path in kgdb_riscv_notify() to add a missing local_irq_restore() - Fix the RISC-V defconfig to enable heap randomization by default by removing CONFIG_COMPAT_BRK, which shouldn't have been there in the first place; and to enable building onboard USB hub support as a module to better support the SpacemiT K1 - Fix CONFIG_RISCV_ISA_SV{48,57} to depend on CONFIG_MMU, since they are virtual memory configuration options that by definition require MMU support - Fix a missing space in the SpacemiT K1 DTS file * tag 'riscv-for-linus-7.4-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: mm: reserve the DTB before scanning reserved memory riscv: unaligned: fix __setup handlers riscv: dts: spacemit: k1: Correct missing space riscv: defconfig: enable onboard USB hub support riscv: signal: protect regs->status RMW from concurrent preemption riscv: mm: Define PAGE_KERNEL_RO riscv: kgdb: Fix potential missing local_irq_restore() call riscv: RISCV_ISA_SV48 and RISCV_ISA_SV57 should depend on MMU riscv: defconfig: Disable COMPAT_BRK riscv: Fix SR_SUM leakage across context switches
-rw-r--r--arch/riscv/Kconfig4
-rw-r--r--arch/riscv/boot/dts/spacemit/k1.dtsi2
-rw-r--r--arch/riscv/configs/defconfig2
-rw-r--r--arch/riscv/include/asm/pgtable.h1
-rw-r--r--arch/riscv/include/asm/switch_to.h30
-rw-r--r--arch/riscv/include/asm/vector.h2
-rw-r--r--arch/riscv/kernel/entry.S6
-rw-r--r--arch/riscv/kernel/kernel_mode_fpu.c4
-rw-r--r--arch/riscv/kernel/kgdb.c28
-rw-r--r--arch/riscv/kernel/signal.c2
-rw-r--r--arch/riscv/kernel/unaligned_access_speed.c4
-rw-r--r--arch/riscv/mm/init.c14
12 files changed, 66 insertions, 33 deletions
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index e7891a2a89da..d2db8f40c616 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -602,7 +602,7 @@ config RISCV_ISA_SSQOSID
config RISCV_ISA_SV48
bool "Page-Based 48-bit Virtual-Memory System"
- depends on 64BIT
+ depends on 64BIT && MMU
default y
help
Add support for the Page-Based 48-bit Virtual-Memory System.
@@ -614,7 +614,7 @@ config RISCV_ISA_SV48
config RISCV_ISA_SV57
bool "Page-Based 57-bit Virtual-Memory System"
- depends on 64BIT
+ depends on 64BIT && MMU
default y
help
Add support for the Page-Based 57-bit Virtual-Memory System.
diff --git a/arch/riscv/boot/dts/spacemit/k1.dtsi b/arch/riscv/boot/dts/spacemit/k1.dtsi
index 542bfc0d19f5..5d5f7f8a393d 100644
--- a/arch/riscv/boot/dts/spacemit/k1.dtsi
+++ b/arch/riscv/boot/dts/spacemit/k1.dtsi
@@ -948,7 +948,7 @@
resets = <&syscon_apmu RESET_DMA>;
interrupts = <72>;
dma-channels = <16>;
- #dma-cells= <1>;
+ #dma-cells = <1>;
status = "disabled";
};
diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig
index 04ae305d5511..383fdd07a99f 100644
--- a/arch/riscv/configs/defconfig
+++ b/arch/riscv/configs/defconfig
@@ -52,6 +52,7 @@ CONFIG_JUMP_LABEL=y
CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
CONFIG_BLK_DEV_THROTTLING=y
+# CONFIG_COMPAT_BRK is not set
CONFIG_SPARSEMEM_MANUAL=y
CONFIG_NET=y
CONFIG_PACKET=y
@@ -222,6 +223,7 @@ CONFIG_USB_CDNS3_HOST=y
CONFIG_USB_CDNS3_STARFIVE=m
CONFIG_USB_MUSB_HDRC=m
CONFIG_USB_MUSB_SUNXI=m
+CONFIG_USB_ONBOARD_DEV=m
CONFIG_NOP_USB_XCEIV=m
CONFIG_USB_GADGET=y
CONFIG_USB_CONFIGFS=m
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 2ebd5fa5adc5..07ccacd51ab5 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -189,6 +189,7 @@ extern struct pt_alloc_ops pt_ops __meminitdata;
#define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
#define PAGE_KERNEL_READ __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
+#define PAGE_KERNEL_RO PAGE_KERNEL_READ
#define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL | _PAGE_EXEC)
#define PAGE_KERNEL_READ_EXEC __pgprot((_PAGE_KERNEL & ~_PAGE_WRITE) \
| _PAGE_EXEC)
diff --git a/arch/riscv/include/asm/switch_to.h b/arch/riscv/include/asm/switch_to.h
index 123c89b694e8..970f89935f0e 100644
--- a/arch/riscv/include/asm/switch_to.h
+++ b/arch/riscv/include/asm/switch_to.h
@@ -28,11 +28,13 @@ static inline void __fstate_clean(struct pt_regs *regs)
static inline void fstate_off(struct task_struct *task,
struct pt_regs *regs)
{
+ preempt_disable();
regs->status = (regs->status & ~SR_FS) | SR_FS_OFF;
+ preempt_enable();
}
-static inline void fstate_save(struct task_struct *task,
- struct pt_regs *regs)
+static inline void fstate_save_preempt_off(struct task_struct *task,
+ struct pt_regs *regs)
{
if ((regs->status & SR_FS) == SR_FS_DIRTY) {
__fstate_save(task);
@@ -40,8 +42,8 @@ static inline void fstate_save(struct task_struct *task,
}
}
-static inline void fstate_restore(struct task_struct *task,
- struct pt_regs *regs)
+static inline void fstate_restore_preempt_off(struct task_struct *task,
+ struct pt_regs *regs)
{
if ((regs->status & SR_FS) != SR_FS_OFF) {
__fstate_restore(task);
@@ -49,14 +51,30 @@ static inline void fstate_restore(struct task_struct *task,
}
}
+static inline void fstate_save(struct task_struct *task,
+ struct pt_regs *regs)
+{
+ preempt_disable();
+ fstate_save_preempt_off(task, regs);
+ preempt_enable();
+}
+
+static inline void fstate_restore(struct task_struct *task,
+ struct pt_regs *regs)
+{
+ preempt_disable();
+ fstate_restore_preempt_off(task, regs);
+ preempt_enable();
+}
+
static inline void __switch_to_fpu(struct task_struct *prev,
struct task_struct *next)
{
struct pt_regs *regs;
regs = task_pt_regs(prev);
- fstate_save(prev, regs);
- fstate_restore(next, task_pt_regs(next));
+ fstate_save_preempt_off(prev, regs);
+ fstate_restore_preempt_off(next, task_pt_regs(next));
}
static __always_inline bool has_fpu(void)
diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h
index cd09f32e1ea3..3381a535abb4 100644
--- a/arch/riscv/include/asm/vector.h
+++ b/arch/riscv/include/asm/vector.h
@@ -320,6 +320,8 @@ static inline void riscv_v_vstate_save(struct __riscv_v_ext_state *vstate,
static inline void riscv_v_vstate_restore(struct __riscv_v_ext_state *vstate,
struct pt_regs *regs)
{
+ WARN_ON_ONCE(preemptible());
+
if (riscv_v_vstate_query(regs)) {
__riscv_v_vstate_restore(vstate, vstate->datap);
__riscv_v_vstate_clean(regs);
diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index 61b7a7716697..628b85e3915a 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -443,15 +443,15 @@ SYM_FUNC_START(__switch_to)
REG_S s10, TASK_THREAD_S10_RA(a3)
REG_S s11, TASK_THREAD_S11_RA(a3)
- /* save the user space access flag */
- csrr s0, CSR_STATUS
+ /* Save and clear the user space access flag. */
+ li s1, SR_SUM
+ csrrc s0, CSR_STATUS, s1
REG_S s0, TASK_THREAD_SUM_RA(a3)
/* Save the kernel shadow call stack pointer */
scs_save_current
/* Restore context from next->thread */
REG_L s0, TASK_THREAD_SUM_RA(a4)
- li s1, SR_SUM
and s0, s0, s1
csrs CSR_STATUS, s0
REG_L ra, TASK_THREAD_RA_RA(a4)
diff --git a/arch/riscv/kernel/kernel_mode_fpu.c b/arch/riscv/kernel/kernel_mode_fpu.c
index 0ac8348876c4..03d847fbfcf6 100644
--- a/arch/riscv/kernel/kernel_mode_fpu.c
+++ b/arch/riscv/kernel/kernel_mode_fpu.c
@@ -14,7 +14,7 @@
void kernel_fpu_begin(void)
{
preempt_disable();
- fstate_save(current, task_pt_regs(current));
+ fstate_save_preempt_off(current, task_pt_regs(current));
csr_set(CSR_SSTATUS, SR_FS);
}
EXPORT_SYMBOL_GPL(kernel_fpu_begin);
@@ -22,7 +22,7 @@ EXPORT_SYMBOL_GPL(kernel_fpu_begin);
void kernel_fpu_end(void)
{
csr_clear(CSR_SSTATUS, SR_FS);
- fstate_restore(current, task_pt_regs(current));
+ fstate_restore_preempt_off(current, task_pt_regs(current));
preempt_enable();
}
EXPORT_SYMBOL_GPL(kernel_fpu_end);
diff --git a/arch/riscv/kernel/kgdb.c b/arch/riscv/kernel/kgdb.c
index 0bf629204c76..b833408494f9 100644
--- a/arch/riscv/kernel/kgdb.c
+++ b/arch/riscv/kernel/kgdb.c
@@ -319,13 +319,28 @@ static int kgdb_riscv_kgdbbreak(unsigned long addr)
return kgdb_has_hit_break(addr);
}
+static int kgdb_riscv_handle(struct die_args *args, unsigned long cmd,
+ int type)
+{
+ struct pt_regs *regs = args->regs;
+
+ if (kgdb_handle_exception(type == KGDB_SW_SINGLE_STEP ? 0 : 1,
+ args->signr, cmd, regs))
+ return NOTIFY_DONE;
+
+ if (type == KGDB_COMPILED_BREAK)
+ regs->epc += 4;
+
+ return NOTIFY_STOP;
+}
+
static int kgdb_riscv_notify(struct notifier_block *self, unsigned long cmd,
void *ptr)
{
struct die_args *args = (struct die_args *)ptr;
struct pt_regs *regs = args->regs;
unsigned long flags;
- int type;
+ int type, ret;
if (user_mode(regs))
return NOTIFY_DONE;
@@ -335,17 +350,10 @@ static int kgdb_riscv_notify(struct notifier_block *self, unsigned long cmd,
return NOTIFY_DONE;
local_irq_save(flags);
-
- if (kgdb_handle_exception(type == KGDB_SW_SINGLE_STEP ? 0 : 1,
- args->signr, cmd, regs))
- return NOTIFY_DONE;
-
- if (type == KGDB_COMPILED_BREAK)
- regs->epc += 4;
-
+ ret = kgdb_riscv_handle(args, cmd, type);
local_irq_restore(flags);
- return NOTIFY_STOP;
+ return ret;
}
static struct notifier_block kgdb_notifier = {
diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index 59784dc117e4..6f6f3315bc09 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -123,7 +123,9 @@ static long __restore_v_state(struct pt_regs *regs, void __user *sc_vec)
* to avoid getting the vstate incorrectly clobbered by the
* discarded vector state.
*/
+ preempt_disable();
riscv_v_vstate_set_restore(current, regs);
+ preempt_enable();
/* Copy everything of __sc_riscv_v_state except datap. */
err = __copy_from_user(&current->thread.vstate, &state->v_state,
diff --git a/arch/riscv/kernel/unaligned_access_speed.c b/arch/riscv/kernel/unaligned_access_speed.c
index 67f1a0371659..323ccfcfbbb7 100644
--- a/arch/riscv/kernel/unaligned_access_speed.c
+++ b/arch/riscv/kernel/unaligned_access_speed.c
@@ -322,7 +322,7 @@ static int __init set_unaligned_scalar_speed_param(char *str)
else if (!strcmp(str, speed_str[RISCV_HWPROBE_MISALIGNED_SCALAR_UNSUPPORTED]))
unaligned_scalar_speed_param = RISCV_HWPROBE_MISALIGNED_SCALAR_UNSUPPORTED;
else
- return -EINVAL;
+ return 0;
return 1;
}
@@ -337,7 +337,7 @@ static int __init set_unaligned_vector_speed_param(char *str)
else if (!strcmp(str, speed_str[RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED]))
unaligned_vector_speed_param = RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED;
else
- return -EINVAL;
+ return 0;
return 1;
}
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index e822fce0af4b..bbc2d8cb4627 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -295,13 +295,6 @@ static void __init setup_bootmem(void)
reserve_initrd_mem();
/*
- * No allocation should be done before reserving the memory as defined
- * in the device tree, otherwise the allocation could end up in a
- * reserved region.
- */
- early_init_fdt_scan_reserved_mem();
-
- /*
* If DTB is built in, no need to reserve its memblock.
* Otherwise, do reserve it but avoid using
* early_init_fdt_reserve_self() since __pa() does
@@ -309,6 +302,13 @@ static void __init setup_bootmem(void)
*/
if (!IS_ENABLED(CONFIG_BUILTIN_DTB))
memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va));
+
+ /*
+ * No allocation should be done before reserving the memory as defined
+ * in the device tree, otherwise the allocation could end up in a
+ * reserved region.
+ */
+ early_init_fdt_scan_reserved_mem();
}
#ifdef CONFIG_RELOCATABLE