2020-11-19 00:41:53

by Atish Patra

[permalink] [raw]
Subject: [PATCH v5 3/5] riscv: Separate memory init from paging init

Currently, we perform some memory init functions in paging init. But,
that will be an issue for NUMA support where DT needs to be flattened
before numa initialization and memblock_present can only be called
after numa initialization.

Move memory initialization related functions to a separate function.

Signed-off-by: Atish Patra <[email protected]>
Reviewed-by: Greentime Hu <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
Reviewed-by: Palmer Dabbelt <[email protected]>
---
arch/riscv/include/asm/pgtable.h | 1 +
arch/riscv/kernel/setup.c | 1 +
arch/riscv/mm/init.c | 6 +++++-
3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 183f1f4b2ae6..a0f8a86236e8 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -471,6 +471,7 @@ extern void *dtb_early_va;
extern uintptr_t dtb_early_pa;
void setup_bootmem(void);
void paging_init(void);
+void misc_mem_init(void);

#define FIRST_USER_ADDRESS 0

diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index c424cc6dd833..eb1cbdc29ea7 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -88,6 +88,7 @@ void __init setup_arch(char **cmdline_p)
else
pr_err("No DTB found in kernel mappings\n");
#endif
+ misc_mem_init();

#ifdef CONFIG_SWIOTLB
swiotlb_init(1);
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 8e577f14f120..826e7de73f45 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -664,8 +664,12 @@ static void __init resource_init(void)
void __init paging_init(void)
{
setup_vm_final();
- sparse_init();
setup_zero_page();
+}
+
+void __init misc_mem_init(void)
+{
+ sparse_init();
zone_sizes_init();
resource_init();
}
--
2.25.1


2021-03-10 16:44:59

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v5 3/5] riscv: Separate memory init from paging init

Hi Atish,

On Thu, Nov 19, 2020 at 1:40 AM Atish Patra <[email protected]> wrote:
> Currently, we perform some memory init functions in paging init. But,
> that will be an issue for NUMA support where DT needs to be flattened
> before numa initialization and memblock_present can only be called
> after numa initialization.
>
> Move memory initialization related functions to a separate function.
>
> Signed-off-by: Atish Patra <[email protected]>
> Reviewed-by: Greentime Hu <[email protected]>
> Reviewed-by: Anup Patel <[email protected]>
> Reviewed-by: Palmer Dabbelt <[email protected]>

This is now commit cbd34f4bb37d62d8 in v5.12-rc1, breaking the boot on
Vexriscv:

[ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
[ 0.000000] printk: bootconsole [sbi0] enabled
[ 0.000000] printk: debug: ignoring loglevel setting.
[ 0.000000] Initial ramdisk at: 0x(ptrval) (8388608 bytes)
[ 0.000000] Unable to handle kernel paging request at virtual
address c8000008
[ 0.000000] Oops [#1]
[ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted
5.11.0-orangecrab-00023-g7c4fc8e3e982 #129
[ 0.000000] epc: c04d6624 ra : c04d6524 sp : c05ddf70
[ 0.000000] gp : c0678bc0 tp : c05e5b40 t0 : c8000000
[ 0.000000] t1 : 00030000 t2 : ffffffff s0 : c05ddfc0
[ 0.000000] s1 : c8000000 a0 : 00000000 a1 : c7ffffe0
[ 0.000000] a2 : 00000005 a3 : 00000001 a4 : 0000000c
[ 0.000000] a5 : 00000000 a6 : c04fe000 a7 : 0000000c
[ 0.000000] s2 : c04fe098 s3 : 000000a0 s4 : c7ffff60
[ 0.000000] s5 : c04fe0dc s6 : 80000200 s7 : c059f19c
[ 0.000000] s8 : 81000200 s9 : c059f1b8 s10: 80000200
[ 0.000000] s11: c059f19c t3 : 405dba80 t4 : c05e6f08
[ 0.000000] t5 : 81000200 t6 : 40501000
[ 0.000000] status: 00000100 badaddr: c8000008 cause: 0000000f
[ 0.000000] random: get_random_bytes called from
print_oops_end_marker+0x38/0x7c with crng_init=0
[ 0.000000] ---[ end trace 0000000000000000 ]---
[ 0.000000] Kernel panic - not syncing: Attempted to kill the idle task!

Note that I have "[PATCH v2 3/4] RISC-V: Fix L1_CACHE_BYTES for RV32"[1]
applied, to avoid another crash (7c4fc8e3e982 = v5.11 + [1] +
cherry-picked commits from the riscv-for-linus-5.12-mw0 pull request).

If I revert the L1_CACHE_BYTES change, the boot continues, but I'm back
to the old issue fixed by [1]:

[ 22.126687] Freeing initrd memory: 8192K
[ 22.321811] workingset: timestamp_bits=30 max_order=15 bucket_order=0
[ 29.001509] Block layer SCSI generic (bsg) driver version 0.4
loaded (major 253)
[ 29.021555] io scheduler mq-deadline registered
[ 29.033692] io scheduler kyber registered
[ 29.141294] Unable to handle kernel paging request at virtual
address 69726573
[ 29.158523] Oops [#1]
[ 29.162232] CPU: 0 PID: 1 Comm: swapper Not tainted
5.11.0-orangecrab-00023-g7c4fc8e3e982-dirty #132
[ 29.171970] epc: c000d3b0 ra : c000eb74 sp : c182dca0
[ 29.178786] gp : c067aee0 tp : c1830000 t0 : c18d75e0
[ 29.185935] t1 : 00030000 t2 : 00000000 s0 : c182dcb0
[ 29.193028] s1 : 00000000 a0 : c05eab14 a1 : c18d75c0
[ 29.200067] a2 : c7ffe384 a3 : 69726573 a4 : f000000b
[ 29.207095] a5 : f0000000 a6 : c7fffff8 a7 : 00000000
[ 29.214141] s2 : 01001f00 s3 : c05eb000 s4 : c067c000
[ 29.221171] s5 : c000ec0c s6 : 80000000 s7 : c05eaad4
[ 29.228200] s8 : c05eab58 s9 : c05a1000 s10: c18d75c0
[ 29.235238] s11: c05eab14 t3 : 20b9a6cc t4 : 00000001
[ 29.242277] t5 : 00000000 t6 : c188cd50
[ 29.247588] status: 00000120 badaddr: 69726573 cause: 0000000d
[ 29.274424] ---[ end trace 69dee1b9ca96f1d6 ]---
[ 29.282859] note: swapper[1] exited with preempt_count 1
[ 29.293156] Kernel panic - not syncing: Attempted to kill init!
exitcode=0x0000000b

[1] https://lore.kernel.org/linux-riscv/[email protected]/

Will have a deeper look later...

Thanks for any suggestions!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2021-03-12 15:52:36

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v5 3/5] riscv: Separate memory init from paging init

Hi Atish,

On Wed, Mar 10, 2021 at 5:41 PM Geert Uytterhoeven <[email protected]> wrote:
> On Thu, Nov 19, 2020 at 1:40 AM Atish Patra <[email protected]> wrote:
> > Currently, we perform some memory init functions in paging init. But,
> > that will be an issue for NUMA support where DT needs to be flattened
> > before numa initialization and memblock_present can only be called
> > after numa initialization.
> >
> > Move memory initialization related functions to a separate function.
> >
> > Signed-off-by: Atish Patra <[email protected]>
> > Reviewed-by: Greentime Hu <[email protected]>
> > Reviewed-by: Anup Patel <[email protected]>
> > Reviewed-by: Palmer Dabbelt <[email protected]>
>
> This is now commit cbd34f4bb37d62d8 in v5.12-rc1, breaking the boot on
> Vexriscv:
>
> [ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
> [ 0.000000] printk: bootconsole [sbi0] enabled
> [ 0.000000] printk: debug: ignoring loglevel setting.
> [ 0.000000] Initial ramdisk at: 0x(ptrval) (8388608 bytes)
> [ 0.000000] Unable to handle kernel paging request at virtual
> address c8000008

> Note that I have "[PATCH v2 3/4] RISC-V: Fix L1_CACHE_BYTES for RV32"[1]
> applied, to avoid another crash (7c4fc8e3e982 = v5.11 + [1] +
> cherry-picked commits from the riscv-for-linus-5.12-mw0 pull request).
>
> If I revert the L1_CACHE_BYTES change, the boot continues, but I'm back
> to the old issue fixed by [1]:
>
> [ 22.126687] Freeing initrd memory: 8192K
> [ 22.321811] workingset: timestamp_bits=30 max_order=15 bucket_order=0
> [ 29.001509] Block layer SCSI generic (bsg) driver version 0.4
> loaded (major 253)
> [ 29.021555] io scheduler mq-deadline registered
> [ 29.033692] io scheduler kyber registered
> [ 29.141294] Unable to handle kernel paging request at virtual
> address 69726573

> Will have a deeper look later...

I found the core issue, and sent a fix: "[PATCH] RISC-V: Fix
out-of-bounds accesses in init_resources()"
https://lore.kernel.org/linux-riscv/[email protected]/

It works now with either value of L1_CACHE_SHIFT, so patch "[PATCH v2
3/4] RISC-V: Fix L1_CACHE_BYTES for RV32" is no longer needed.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds