Skip to content

Commit 4b1d362

Browse files
committed
Merge tag 'riscv-for-linus-5.10-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: - SPDX comment style fix - ignore memory that is unusable - avoid setting a kernel text offset for the !MMU kernels, where skipping the first page of memory is both unnecessary and costly - avoid passing the flag bits in satp to pfn_to_virt() - fix __put_kernel_nofault, where we had the arguments to __put_user_nocheck reversed - workaround for a bug in the FU540 to avoid triggering PMP issues during early boot - change to how we pull symbols out of the vDSO. The old mechanism was removed from binutils-2.35 (and has been backported to Debian's 2.34) * tag 'riscv-for-linus-5.10-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: RISC-V: Fix the VDSO symbol generaton for binutils-2.35+ RISC-V: Use non-PGD mappings for early DTB access riscv: uaccess: fix __put_kernel_nofault() riscv: fix pfn_to_virt err in do_page_fault(). riscv: Set text_offset correctly for M-Mode RISC-V: Remove any memblock representing unusable memory area risc-v: kernel: ftrace: Fixes improper SPDX comment style
2 parents 659caaf + c2c81bb commit 4b1d362

8 files changed

Lines changed: 47 additions & 23 deletions

File tree

arch/riscv/include/asm/uaccess.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ do { \
476476
do { \
477477
long __kr_err; \
478478
\
479-
__put_user_nocheck(*((type *)(dst)), (type *)(src), __kr_err); \
479+
__put_user_nocheck(*((type *)(src)), (type *)(dst), __kr_err); \
480480
if (unlikely(__kr_err)) \
481481
goto err_label; \
482482
} while (0)

arch/riscv/kernel/ftrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* SPDX-License-Identifier: GPL-2.0 */
1+
// SPDX-License-Identifier: GPL-2.0
22
/*
33
* Copyright (C) 2013 Linaro Limited
44
* Author: AKASHI Takahiro <takahiro.akashi@linaro.org>

arch/riscv/kernel/head.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@ ENTRY(_start)
3535
.word 0
3636
#endif
3737
.balign 8
38+
#ifdef CONFIG_RISCV_M_MODE
39+
/* Image load offset (0MB) from start of RAM for M-mode */
40+
.dword 0
41+
#else
3842
#if __riscv_xlen == 64
3943
/* Image load offset(2MB) from start of RAM */
4044
.dword 0x200000
4145
#else
4246
/* Image load offset(4MB) from start of RAM */
4347
.dword 0x400000
48+
#endif
4449
#endif
4550
/* Effective size of kernel image */
4651
.dword _end - _start

arch/riscv/kernel/vdso/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
vdso.lds
33
*.tmp
4+
vdso-syms.S

arch/riscv/kernel/vdso/Makefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,14 @@ $(obj)/vdso.o: $(obj)/vdso.so
4343
SYSCFLAGS_vdso.so.dbg = $(c_flags)
4444
$(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso) FORCE
4545
$(call if_changed,vdsold)
46+
SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
47+
-Wl,--build-id -Wl,--hash-style=both
4648

4749
# We also create a special relocatable object that should mirror the symbol
4850
# table and layout of the linked DSO. With ld --just-symbols we can then
4951
# refer to these symbols in the kernel code rather than hand-coded addresses.
50-
51-
SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
52-
-Wl,--build-id=sha1 -Wl,--hash-style=both
53-
$(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/rt_sigreturn.o FORCE
54-
$(call if_changed,vdsold)
55-
56-
LDFLAGS_vdso-syms.o := -r --just-symbols
57-
$(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE
58-
$(call if_changed,ld)
52+
$(obj)/vdso-syms.S: $(obj)/vdso.so FORCE
53+
$(call if_changed,so2s)
5954

6055
# strip rule for the .so file
6156
$(obj)/%.so: OBJCOPYFLAGS := -S
@@ -73,6 +68,11 @@ quiet_cmd_vdsold = VDSOLD $@
7368
$(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \
7469
rm $@.tmp
7570

71+
# Extracts symbol offsets from the VDSO, converting them into an assembly file
72+
# that contains the same symbols at the same offsets.
73+
quiet_cmd_so2s = SO2S $@
74+
cmd_so2s = $(NM) -D $< | $(srctree)/$(src)/so2s.sh > $@
75+
7676
# install commands for the unstripped file
7777
quiet_cmd_vdso_install = INSTALL $@
7878
cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@

arch/riscv/kernel/vdso/so2s.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0+
3+
# Copyright 2020 Palmer Dabbelt <palmerdabbelt@google.com>
4+
5+
sed 's!\([0-9a-f]*\) T \([a-z0-9_]*\)\(@@LINUX_4.15\)*!.global \2\n.set \2,0x\1!' \
6+
| grep '^\.'

arch/riscv/mm/fault.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
8686
pmd_t *pmd, *pmd_k;
8787
pte_t *pte_k;
8888
int index;
89+
unsigned long pfn;
8990

9091
/* User mode accesses just cause a SIGSEGV */
9192
if (user_mode(regs))
@@ -100,7 +101,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
100101
* of a task switch.
101102
*/
102103
index = pgd_index(addr);
103-
pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP)) + index;
104+
pfn = csr_read(CSR_SATP) & SATP_PPN;
105+
pgd = (pgd_t *)pfn_to_virt(pfn) + index;
104106
pgd_k = init_mm.pgd + index;
105107

106108
if (!pgd_present(*pgd_k)) {

arch/riscv/mm/init.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,31 +154,27 @@ static void __init setup_initrd(void)
154154

155155
void __init setup_bootmem(void)
156156
{
157-
phys_addr_t mem_size = 0;
158-
phys_addr_t total_mem = 0;
159-
phys_addr_t mem_start, start, end = 0;
157+
phys_addr_t mem_start = 0;
158+
phys_addr_t start, end = 0;
160159
phys_addr_t vmlinux_end = __pa_symbol(&_end);
161160
phys_addr_t vmlinux_start = __pa_symbol(&_start);
162161
u64 i;
163162

164163
/* Find the memory region containing the kernel */
165164
for_each_mem_range(i, &start, &end) {
166165
phys_addr_t size = end - start;
167-
if (!total_mem)
166+
if (!mem_start)
168167
mem_start = start;
169168
if (start <= vmlinux_start && vmlinux_end <= end)
170169
BUG_ON(size == 0);
171-
total_mem = total_mem + size;
172170
}
173171

174172
/*
175-
* Remove memblock from the end of usable area to the
176-
* end of region
173+
* The maximal physical memory size is -PAGE_OFFSET.
174+
* Make sure that any memory beyond mem_start + (-PAGE_OFFSET) is removed
175+
* as it is unusable by kernel.
177176
*/
178-
mem_size = min(total_mem, (phys_addr_t)-PAGE_OFFSET);
179-
if (mem_start + mem_size < end)
180-
memblock_remove(mem_start + mem_size,
181-
end - mem_start - mem_size);
177+
memblock_enforce_memory_limit(mem_start - PAGE_OFFSET);
182178

183179
/* Reserve from the start of the kernel to the end of the kernel */
184180
memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
@@ -297,6 +293,7 @@ pmd_t fixmap_pmd[PTRS_PER_PMD] __page_aligned_bss;
297293
#define NUM_EARLY_PMDS (1UL + MAX_EARLY_MAPPING_SIZE / PGDIR_SIZE)
298294
#endif
299295
pmd_t early_pmd[PTRS_PER_PMD * NUM_EARLY_PMDS] __initdata __aligned(PAGE_SIZE);
296+
pmd_t early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
300297

301298
static pmd_t *__init get_pmd_virt_early(phys_addr_t pa)
302299
{
@@ -494,13 +491,26 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
494491
load_pa + (va - PAGE_OFFSET),
495492
map_size, PAGE_KERNEL_EXEC);
496493

494+
#ifndef __PAGETABLE_PMD_FOLDED
495+
/* Setup early PMD for DTB */
496+
create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA,
497+
(uintptr_t)early_dtb_pmd, PGDIR_SIZE, PAGE_TABLE);
498+
/* Create two consecutive PMD mappings for FDT early scan */
499+
pa = dtb_pa & ~(PMD_SIZE - 1);
500+
create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA,
501+
pa, PMD_SIZE, PAGE_KERNEL);
502+
create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA + PMD_SIZE,
503+
pa + PMD_SIZE, PMD_SIZE, PAGE_KERNEL);
504+
dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PMD_SIZE - 1));
505+
#else
497506
/* Create two consecutive PGD mappings for FDT early scan */
498507
pa = dtb_pa & ~(PGDIR_SIZE - 1);
499508
create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA,
500509
pa, PGDIR_SIZE, PAGE_KERNEL);
501510
create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA + PGDIR_SIZE,
502511
pa + PGDIR_SIZE, PGDIR_SIZE, PAGE_KERNEL);
503512
dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PGDIR_SIZE - 1));
513+
#endif
504514
dtb_early_pa = dtb_pa;
505515

506516
/*

0 commit comments

Comments
 (0)