Skip to content

Commit 0b6684b

Browse files
committed
Merge tag 'riscv-for-linus-5.14-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: - avoid dereferencing a null task pointer while walking the stack - fix the memory size in the HiFive Unleashed device tree - disable stack protectors when randstruct is enabled, which results in non-deterministic offsets during module builds - a pair of fixes to avoid relying on a constant physical memory base for the non-XIP builds * tag 'riscv-for-linus-5.14-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: Revert "riscv: Remove CONFIG_PHYS_RAM_BASE_FIXED" riscv: Get rid of CONFIG_PHYS_RAM_BASE in kernel physical address conversion riscv: Disable STACKPROTECTOR_PER_TASK if GCC_PLUGIN_RANDSTRUCT is enabled riscv: dts: fix memory size for the SiFive HiFive Unmatched riscv: stacktrace: Fix NULL pointer dereference
2 parents 4972bb9 + 867432b commit 0b6684b

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

arch/riscv/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,16 @@ config CC_HAVE_STACKPROTECTOR_TLS
492492

493493
config STACKPROTECTOR_PER_TASK
494494
def_bool y
495+
depends on !GCC_PLUGIN_RANDSTRUCT
495496
depends on STACKPROTECTOR && CC_HAVE_STACKPROTECTOR_TLS
496497

498+
config PHYS_RAM_BASE_FIXED
499+
bool "Explicitly specified physical RAM address"
500+
default n
501+
497502
config PHYS_RAM_BASE
498503
hex "Platform Physical RAM address"
504+
depends on PHYS_RAM_BASE_FIXED
499505
default "0x80000000"
500506
help
501507
This is the physical address of RAM in the system. It has to be
@@ -508,6 +514,7 @@ config XIP_KERNEL
508514
# This prevents XIP from being enabled by all{yes,mod}config, which
509515
# fail to build since XIP doesn't support large kernels.
510516
depends on !COMPILE_TEST
517+
select PHYS_RAM_BASE_FIXED
511518
help
512519
Execute-In-Place allows the kernel to run from non-volatile storage
513520
directly addressable by the CPU, such as NOR flash. This saves RAM

arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
memory@80000000 {
2626
device_type = "memory";
27-
reg = <0x0 0x80000000 0x2 0x00000000>;
27+
reg = <0x0 0x80000000 0x4 0x00000000>;
2828
};
2929

3030
soc {

arch/riscv/include/asm/page.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct kernel_mapping {
103103
};
104104

105105
extern struct kernel_mapping kernel_map;
106+
extern phys_addr_t phys_ram_base;
106107

107108
#ifdef CONFIG_64BIT
108109
#define is_kernel_mapping(x) \
@@ -113,9 +114,9 @@ extern struct kernel_mapping kernel_map;
113114
#define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + kernel_map.va_pa_offset))
114115
#define kernel_mapping_pa_to_va(y) ({ \
115116
unsigned long _y = y; \
116-
(_y >= CONFIG_PHYS_RAM_BASE) ? \
117-
(void *)((unsigned long)(_y) + kernel_map.va_kernel_pa_offset + XIP_OFFSET) : \
118-
(void *)((unsigned long)(_y) + kernel_map.va_kernel_xip_pa_offset); \
117+
(IS_ENABLED(CONFIG_XIP_KERNEL) && _y < phys_ram_base) ? \
118+
(void *)((unsigned long)(_y) + kernel_map.va_kernel_xip_pa_offset) : \
119+
(void *)((unsigned long)(_y) + kernel_map.va_kernel_pa_offset + XIP_OFFSET); \
119120
})
120121
#define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x)
121122

arch/riscv/kernel/stacktrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
2727
fp = frame_pointer(regs);
2828
sp = user_stack_pointer(regs);
2929
pc = instruction_pointer(regs);
30-
} else if (task == current) {
30+
} else if (task == NULL || task == current) {
3131
fp = (unsigned long)__builtin_frame_address(1);
3232
sp = (unsigned long)__builtin_frame_address(0);
3333
pc = (unsigned long)__builtin_return_address(0);

arch/riscv/mm/init.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ EXPORT_SYMBOL(kernel_map);
3636
#define kernel_map (*(struct kernel_mapping *)XIP_FIXUP(&kernel_map))
3737
#endif
3838

39+
phys_addr_t phys_ram_base __ro_after_init;
40+
EXPORT_SYMBOL(phys_ram_base);
41+
3942
#ifdef CONFIG_XIP_KERNEL
4043
extern char _xiprom[], _exiprom[];
4144
#endif
@@ -160,7 +163,7 @@ static void __init setup_bootmem(void)
160163
phys_addr_t vmlinux_end = __pa_symbol(&_end);
161164
phys_addr_t vmlinux_start = __pa_symbol(&_start);
162165
phys_addr_t __maybe_unused max_mapped_addr;
163-
phys_addr_t dram_end;
166+
phys_addr_t phys_ram_end;
164167

165168
#ifdef CONFIG_XIP_KERNEL
166169
vmlinux_start = __pa_symbol(&_sdata);
@@ -181,9 +184,12 @@ static void __init setup_bootmem(void)
181184
#endif
182185
memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
183186

184-
dram_end = memblock_end_of_DRAM();
185187

188+
phys_ram_end = memblock_end_of_DRAM();
186189
#ifndef CONFIG_64BIT
190+
#ifndef CONFIG_XIP_KERNEL
191+
phys_ram_base = memblock_start_of_DRAM();
192+
#endif
187193
/*
188194
* memblock allocator is not aware of the fact that last 4K bytes of
189195
* the addressable memory can not be mapped because of IS_ERR_VALUE
@@ -194,12 +200,12 @@ static void __init setup_bootmem(void)
194200
* be done in create_kernel_page_table.
195201
*/
196202
max_mapped_addr = __pa(~(ulong)0);
197-
if (max_mapped_addr == (dram_end - 1))
203+
if (max_mapped_addr == (phys_ram_end - 1))
198204
memblock_set_current_limit(max_mapped_addr - 4096);
199205
#endif
200206

201-
min_low_pfn = PFN_UP(memblock_start_of_DRAM());
202-
max_low_pfn = max_pfn = PFN_DOWN(dram_end);
207+
min_low_pfn = PFN_UP(phys_ram_base);
208+
max_low_pfn = max_pfn = PFN_DOWN(phys_ram_end);
203209

204210
dma32_phys_limit = min(4UL * SZ_1G, (unsigned long)PFN_PHYS(max_low_pfn));
205211
set_max_mapnr(max_low_pfn - ARCH_PFN_OFFSET);
@@ -558,6 +564,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
558564
kernel_map.xiprom = (uintptr_t)CONFIG_XIP_PHYS_ADDR;
559565
kernel_map.xiprom_sz = (uintptr_t)(&_exiprom) - (uintptr_t)(&_xiprom);
560566

567+
phys_ram_base = CONFIG_PHYS_RAM_BASE;
561568
kernel_map.phys_addr = (uintptr_t)CONFIG_PHYS_RAM_BASE;
562569
kernel_map.size = (uintptr_t)(&_end) - (uintptr_t)(&_sdata);
563570

0 commit comments

Comments
 (0)