Skip to content

Commit 7a934f4

Browse files
committed
Merge tag 'riscv-for-linus-6.3-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: - A fix for a missing fence when generating the NOMMU sigreturn trampoline - A set of fixes for early DTB handling of reserved memory nodes * tag 'riscv-for-linus-6.3-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: No need to relocate the dtb as it lies in the fixmap region riscv: Do not set initial_boot_params to the linear address of the dtb riscv: Move early dtb mapping into the fixmap region riscv: add icache flush for nommu sigreturn trampoline
2 parents 95abc81 + 1b50f95 commit 7a934f4

6 files changed

Lines changed: 62 additions & 57 deletions

File tree

Documentation/riscv/vm-layout.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ RISC-V Linux Kernel SV39
4747
| Kernel-space virtual memory, shared between all processes:
4848
____________________________________________________________|___________________________________________________________
4949
| | | |
50-
ffffffc6fee00000 | -228 GB | ffffffc6feffffff | 2 MB | fixmap
50+
ffffffc6fea00000 | -228 GB | ffffffc6feffffff | 6 MB | fixmap
5151
ffffffc6ff000000 | -228 GB | ffffffc6ffffffff | 16 MB | PCI io
5252
ffffffc700000000 | -228 GB | ffffffc7ffffffff | 4 GB | vmemmap
5353
ffffffc800000000 | -224 GB | ffffffd7ffffffff | 64 GB | vmalloc/ioremap space
@@ -83,7 +83,7 @@ RISC-V Linux Kernel SV48
8383
| Kernel-space virtual memory, shared between all processes:
8484
____________________________________________________________|___________________________________________________________
8585
| | | |
86-
ffff8d7ffee00000 | -114.5 TB | ffff8d7ffeffffff | 2 MB | fixmap
86+
ffff8d7ffea00000 | -114.5 TB | ffff8d7ffeffffff | 6 MB | fixmap
8787
ffff8d7fff000000 | -114.5 TB | ffff8d7fffffffff | 16 MB | PCI io
8888
ffff8d8000000000 | -114.5 TB | ffff8f7fffffffff | 2 TB | vmemmap
8989
ffff8f8000000000 | -112.5 TB | ffffaf7fffffffff | 32 TB | vmalloc/ioremap space
@@ -119,7 +119,7 @@ RISC-V Linux Kernel SV57
119119
| Kernel-space virtual memory, shared between all processes:
120120
____________________________________________________________|___________________________________________________________
121121
| | | |
122-
ff1bfffffee00000 | -57 PB | ff1bfffffeffffff | 2 MB | fixmap
122+
ff1bfffffea00000 | -57 PB | ff1bfffffeffffff | 6 MB | fixmap
123123
ff1bffffff000000 | -57 PB | ff1bffffffffffff | 16 MB | PCI io
124124
ff1c000000000000 | -57 PB | ff1fffffffffffff | 1 PB | vmemmap
125125
ff20000000000000 | -56 PB | ff5fffffffffffff | 16 PB | vmalloc/ioremap space

arch/riscv/include/asm/fixmap.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
*/
2323
enum fixed_addresses {
2424
FIX_HOLE,
25+
/*
26+
* The fdt fixmap mapping must be PMD aligned and will be mapped
27+
* using PMD entries in fixmap_pmd in 64-bit and a PGD entry in 32-bit.
28+
*/
29+
FIX_FDT_END,
30+
FIX_FDT = FIX_FDT_END + FIX_FDT_SIZE / PAGE_SIZE - 1,
31+
32+
/* Below fixmaps will be mapped using fixmap_pte */
2533
FIX_PTE,
2634
FIX_PMD,
2735
FIX_PUD,

arch/riscv/include/asm/pgtable.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,13 @@
8787

8888
#define FIXADDR_TOP PCI_IO_START
8989
#ifdef CONFIG_64BIT
90-
#define FIXADDR_SIZE PMD_SIZE
90+
#define MAX_FDT_SIZE PMD_SIZE
91+
#define FIX_FDT_SIZE (MAX_FDT_SIZE + SZ_2M)
92+
#define FIXADDR_SIZE (PMD_SIZE + FIX_FDT_SIZE)
9193
#else
92-
#define FIXADDR_SIZE PGDIR_SIZE
94+
#define MAX_FDT_SIZE PGDIR_SIZE
95+
#define FIX_FDT_SIZE MAX_FDT_SIZE
96+
#define FIXADDR_SIZE (PGDIR_SIZE + FIX_FDT_SIZE)
9397
#endif
9498
#define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
9599

arch/riscv/kernel/setup.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,8 @@ void __init setup_arch(char **cmdline_p)
278278
#if IS_ENABLED(CONFIG_BUILTIN_DTB)
279279
unflatten_and_copy_device_tree();
280280
#else
281-
if (early_init_dt_verify(__va(XIP_FIXUP(dtb_early_pa))))
282-
unflatten_device_tree();
283-
else
284-
pr_err("No DTB found in kernel mappings\n");
281+
unflatten_device_tree();
285282
#endif
286-
early_init_fdt_scan_reserved_mem();
287283
misc_mem_init();
288284

289285
init_resources();

arch/riscv/kernel/signal.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <asm/signal32.h>
2020
#include <asm/switch_to.h>
2121
#include <asm/csr.h>
22+
#include <asm/cacheflush.h>
2223

2324
extern u32 __user_rt_sigreturn[2];
2425

@@ -181,6 +182,7 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
181182
{
182183
struct rt_sigframe __user *frame;
183184
long err = 0;
185+
unsigned long __maybe_unused addr;
184186

185187
frame = get_sigframe(ksig, regs, sizeof(*frame));
186188
if (!access_ok(frame, sizeof(*frame)))
@@ -209,7 +211,12 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
209211
if (copy_to_user(&frame->sigreturn_code, __user_rt_sigreturn,
210212
sizeof(frame->sigreturn_code)))
211213
return -EFAULT;
212-
regs->ra = (unsigned long)&frame->sigreturn_code;
214+
215+
addr = (unsigned long)&frame->sigreturn_code;
216+
/* Make sure the two instructions are pushed to icache. */
217+
flush_icache_range(addr, addr + sizeof(frame->sigreturn_code));
218+
219+
regs->ra = addr;
213220
#endif /* CONFIG_MMU */
214221

215222
/*

arch/riscv/mm/init.c

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]
5757
EXPORT_SYMBOL(empty_zero_page);
5858

5959
extern char _start[];
60-
#define DTB_EARLY_BASE_VA PGDIR_SIZE
6160
void *_dtb_early_va __initdata;
6261
uintptr_t _dtb_early_pa __initdata;
6362

@@ -236,31 +235,22 @@ static void __init setup_bootmem(void)
236235
set_max_mapnr(max_low_pfn - ARCH_PFN_OFFSET);
237236

238237
reserve_initrd_mem();
238+
239+
/*
240+
* No allocation should be done before reserving the memory as defined
241+
* in the device tree, otherwise the allocation could end up in a
242+
* reserved region.
243+
*/
244+
early_init_fdt_scan_reserved_mem();
245+
239246
/*
240247
* If DTB is built in, no need to reserve its memblock.
241248
* Otherwise, do reserve it but avoid using
242249
* early_init_fdt_reserve_self() since __pa() does
243250
* not work for DTB pointers that are fixmap addresses
244251
*/
245-
if (!IS_ENABLED(CONFIG_BUILTIN_DTB)) {
246-
/*
247-
* In case the DTB is not located in a memory region we won't
248-
* be able to locate it later on via the linear mapping and
249-
* get a segfault when accessing it via __va(dtb_early_pa).
250-
* To avoid this situation copy DTB to a memory region.
251-
* Note that memblock_phys_alloc will also reserve DTB region.
252-
*/
253-
if (!memblock_is_memory(dtb_early_pa)) {
254-
size_t fdt_size = fdt_totalsize(dtb_early_va);
255-
phys_addr_t new_dtb_early_pa = memblock_phys_alloc(fdt_size, PAGE_SIZE);
256-
void *new_dtb_early_va = early_memremap(new_dtb_early_pa, fdt_size);
257-
258-
memcpy(new_dtb_early_va, dtb_early_va, fdt_size);
259-
early_memunmap(new_dtb_early_va, fdt_size);
260-
_dtb_early_pa = new_dtb_early_pa;
261-
} else
262-
memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va));
263-
}
252+
if (!IS_ENABLED(CONFIG_BUILTIN_DTB))
253+
memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va));
264254

265255
dma_contiguous_reserve(dma32_phys_limit);
266256
if (IS_ENABLED(CONFIG_64BIT))
@@ -279,9 +269,6 @@ pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
279269
static pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss;
280270

281271
pgd_t early_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
282-
static p4d_t __maybe_unused early_dtb_p4d[PTRS_PER_P4D] __initdata __aligned(PAGE_SIZE);
283-
static pud_t __maybe_unused early_dtb_pud[PTRS_PER_PUD] __initdata __aligned(PAGE_SIZE);
284-
static pmd_t __maybe_unused early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
285272

286273
#ifdef CONFIG_XIP_KERNEL
287274
#define pt_ops (*(struct pt_alloc_ops *)XIP_FIXUP(&pt_ops))
@@ -626,17 +613,13 @@ static void __init create_p4d_mapping(p4d_t *p4dp,
626613
#define trampoline_pgd_next (pgtable_l5_enabled ? \
627614
(uintptr_t)trampoline_p4d : (pgtable_l4_enabled ? \
628615
(uintptr_t)trampoline_pud : (uintptr_t)trampoline_pmd))
629-
#define early_dtb_pgd_next (pgtable_l5_enabled ? \
630-
(uintptr_t)early_dtb_p4d : (pgtable_l4_enabled ? \
631-
(uintptr_t)early_dtb_pud : (uintptr_t)early_dtb_pmd))
632616
#else
633617
#define pgd_next_t pte_t
634618
#define alloc_pgd_next(__va) pt_ops.alloc_pte(__va)
635619
#define get_pgd_next_virt(__pa) pt_ops.get_pte_virt(__pa)
636620
#define create_pgd_next_mapping(__nextp, __va, __pa, __sz, __prot) \
637621
create_pte_mapping(__nextp, __va, __pa, __sz, __prot)
638622
#define fixmap_pgd_next ((uintptr_t)fixmap_pte)
639-
#define early_dtb_pgd_next ((uintptr_t)early_dtb_pmd)
640623
#define create_p4d_mapping(__pmdp, __va, __pa, __sz, __prot) do {} while(0)
641624
#define create_pud_mapping(__pmdp, __va, __pa, __sz, __prot) do {} while(0)
642625
#define create_pmd_mapping(__pmdp, __va, __pa, __sz, __prot) do {} while(0)
@@ -860,32 +843,28 @@ static void __init create_kernel_page_table(pgd_t *pgdir, bool early)
860843
* this means 2 PMD entries whereas for 32-bit kernel, this is only 1 PGDIR
861844
* entry.
862845
*/
863-
static void __init create_fdt_early_page_table(pgd_t *pgdir, uintptr_t dtb_pa)
846+
static void __init create_fdt_early_page_table(pgd_t *pgdir,
847+
uintptr_t fix_fdt_va,
848+
uintptr_t dtb_pa)
864849
{
865-
#ifndef CONFIG_BUILTIN_DTB
866850
uintptr_t pa = dtb_pa & ~(PMD_SIZE - 1);
867851

868-
create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA,
869-
IS_ENABLED(CONFIG_64BIT) ? early_dtb_pgd_next : pa,
870-
PGDIR_SIZE,
871-
IS_ENABLED(CONFIG_64BIT) ? PAGE_TABLE : PAGE_KERNEL);
872-
873-
if (pgtable_l5_enabled)
874-
create_p4d_mapping(early_dtb_p4d, DTB_EARLY_BASE_VA,
875-
(uintptr_t)early_dtb_pud, P4D_SIZE, PAGE_TABLE);
876-
877-
if (pgtable_l4_enabled)
878-
create_pud_mapping(early_dtb_pud, DTB_EARLY_BASE_VA,
879-
(uintptr_t)early_dtb_pmd, PUD_SIZE, PAGE_TABLE);
852+
#ifndef CONFIG_BUILTIN_DTB
853+
/* Make sure the fdt fixmap address is always aligned on PMD size */
854+
BUILD_BUG_ON(FIX_FDT % (PMD_SIZE / PAGE_SIZE));
880855

881-
if (IS_ENABLED(CONFIG_64BIT)) {
882-
create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA,
856+
/* In 32-bit only, the fdt lies in its own PGD */
857+
if (!IS_ENABLED(CONFIG_64BIT)) {
858+
create_pgd_mapping(early_pg_dir, fix_fdt_va,
859+
pa, MAX_FDT_SIZE, PAGE_KERNEL);
860+
} else {
861+
create_pmd_mapping(fixmap_pmd, fix_fdt_va,
883862
pa, PMD_SIZE, PAGE_KERNEL);
884-
create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA + PMD_SIZE,
863+
create_pmd_mapping(fixmap_pmd, fix_fdt_va + PMD_SIZE,
885864
pa + PMD_SIZE, PMD_SIZE, PAGE_KERNEL);
886865
}
887866

888-
dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PMD_SIZE - 1));
867+
dtb_early_va = (void *)fix_fdt_va + (dtb_pa & (PMD_SIZE - 1));
889868
#else
890869
/*
891870
* For 64-bit kernel, __va can't be used since it would return a linear
@@ -1055,7 +1034,8 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
10551034
create_kernel_page_table(early_pg_dir, true);
10561035

10571036
/* Setup early mapping for FDT early scan */
1058-
create_fdt_early_page_table(early_pg_dir, dtb_pa);
1037+
create_fdt_early_page_table(early_pg_dir,
1038+
__fix_to_virt(FIX_FDT), dtb_pa);
10591039

10601040
/*
10611041
* Bootime fixmap only can handle PMD_SIZE mapping. Thus, boot-ioremap
@@ -1097,6 +1077,16 @@ static void __init setup_vm_final(void)
10971077
u64 i;
10981078

10991079
/* Setup swapper PGD for fixmap */
1080+
#if !defined(CONFIG_64BIT)
1081+
/*
1082+
* In 32-bit, the device tree lies in a pgd entry, so it must be copied
1083+
* directly in swapper_pg_dir in addition to the pgd entry that points
1084+
* to fixmap_pte.
1085+
*/
1086+
unsigned long idx = pgd_index(__fix_to_virt(FIX_FDT));
1087+
1088+
set_pgd(&swapper_pg_dir[idx], early_pg_dir[idx]);
1089+
#endif
11001090
create_pgd_mapping(swapper_pg_dir, FIXADDR_START,
11011091
__pa_symbol(fixmap_pgd_next),
11021092
PGDIR_SIZE, PAGE_TABLE);

0 commit comments

Comments
 (0)