Skip to content

Commit 387181d

Browse files
avpatelpalmer-dabbelt
authored andcommitted
RISC-V: Always compile mm/init.c with cmodel=medany and notrace
The Linux RISC-V 32bit kernel is broken after we moved setup_vm() from kernel/setup.c to mm/init.c because Linux RISC-V 32bit kernel by default uses cmodel=medlow which results in a non-position-independent setup_vm(). This patch fixes Linux RISC-V 32bit kernel booting by: 1. Forcing cmodel=medany for mm/init.c 2. Moving remaing MM-related stuff va_pa_offset, pfn_base and empty_zero_page from kernel/setup.c to mm/init.c Further, the setup_vm() cannot handle GCC instrumentation for FTRACE so we disable it for mm/init.c by not using "-pg" compiler flag. Fixes: 6f1e9e9 ("RISC-V: Move setup_vm() to mm/init.c") Suggested-by: Christoph Hellwig <hch@lst.de> Suggested-by: Mike Rapoport <rppt@linux.ibm.com> Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Mike Rapoport <rppt@linux.ibm.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
1 parent dbee9c9 commit 387181d

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

arch/riscv/kernel/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
ifdef CONFIG_FTRACE
66
CFLAGS_REMOVE_ftrace.o = -pg
7-
CFLAGS_REMOVE_setup.o = -pg
87
endif
98

109
extra-y += head.o
@@ -29,8 +28,6 @@ obj-y += vdso.o
2928
obj-y += cacheinfo.o
3029
obj-y += vdso/
3130

32-
CFLAGS_setup.o := -mcmodel=medany
33-
3431
obj-$(CONFIG_FPU) += fpu.o
3532
obj-$(CONFIG_SMP) += smpboot.o
3633
obj-$(CONFIG_SMP) += smp.o

arch/riscv/kernel/setup.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ struct screen_info screen_info = {
4848
};
4949
#endif
5050

51-
unsigned long va_pa_offset;
52-
EXPORT_SYMBOL(va_pa_offset);
53-
unsigned long pfn_base;
54-
EXPORT_SYMBOL(pfn_base);
55-
56-
unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss;
57-
EXPORT_SYMBOL(empty_zero_page);
58-
5951
/* The lucky hart to first increment this variable will boot the other cores */
6052
atomic_t hart_lottery;
6153
unsigned long boot_cpu_hartid;

arch/riscv/mm/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2+
CFLAGS_init.o := -mcmodel=medany
3+
ifdef CONFIG_FTRACE
4+
CFLAGS_REMOVE_init.o = -pg
5+
endif
6+
17
obj-y += init.o
28
obj-y += fault.o
39
obj-y += extable.o

arch/riscv/mm/init.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include <asm/pgtable.h>
2626
#include <asm/io.h>
2727

28+
unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]
29+
__page_aligned_bss;
30+
EXPORT_SYMBOL(empty_zero_page);
31+
2832
static void __init zone_sizes_init(void)
2933
{
3034
unsigned long max_zone_pfns[MAX_NR_ZONES] = { 0, };
@@ -143,6 +147,11 @@ void __init setup_bootmem(void)
143147
}
144148
}
145149

150+
unsigned long va_pa_offset;
151+
EXPORT_SYMBOL(va_pa_offset);
152+
unsigned long pfn_base;
153+
EXPORT_SYMBOL(pfn_base);
154+
146155
pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
147156
pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
148157

@@ -172,6 +181,25 @@ void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
172181
}
173182
}
174183

184+
/*
185+
* setup_vm() is called from head.S with MMU-off.
186+
*
187+
* Following requirements should be honoured for setup_vm() to work
188+
* correctly:
189+
* 1) It should use PC-relative addressing for accessing kernel symbols.
190+
* To achieve this we always use GCC cmodel=medany.
191+
* 2) The compiler instrumentation for FTRACE will not work for setup_vm()
192+
* so disable compiler instrumentation when FTRACE is enabled.
193+
*
194+
* Currently, the above requirements are honoured by using custom CFLAGS
195+
* for init.o in mm/Makefile.
196+
*/
197+
198+
#ifndef __riscv_cmodel_medany
199+
#error "setup_vm() is called from head.S before relocate so it should "
200+
"not use absolute addressing."
201+
#endif
202+
175203
asmlinkage void __init setup_vm(void)
176204
{
177205
extern char _start;

0 commit comments

Comments
 (0)