From 7d9f375e4a7631b4cdd4bc9243a832aaf2b80869 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Fri, 12 Jul 2024 17:38:53 +0200 Subject: [PATCH] Remove newline in OpenSBI trap debug line --- JOURNAL.md | 107 +++++++++++++++++++++++++++++++++++++- opensbi-timer-debug.patch | 4 +- 2 files changed, 108 insertions(+), 3 deletions(-) diff --git a/JOURNAL.md b/JOURNAL.md index 560d526..99a6e6f 100644 --- a/JOURNAL.md +++ b/JOURNAL.md @@ -1851,7 +1851,7 @@ may cause more problems down the line. No ethernet found. No ethernet found. -However, now I cannot boot the kernel, as it is overwritting the FDT: +However, now I cannot boot the kernel, as it is overwriting the FDT: => printenv fdtcontroladdr fdtcontroladdr=82200000 @@ -2097,6 +2097,8 @@ affecting. Disabling the clint doesn't seem to cause any effect. In fact, the kernel is still able to get a clock as shown in the kernel messages. +### OBSERVATION: The kernel hangs after the unaligned check begins + I enabled the ftrace for initcall and I can see that is getting stuck in the unaligned check: @@ -2220,3 +2222,106 @@ Memory regions: 0x8400_0000 to 0x84.._.... M: (R,W) S/U: () Linux kernel +Okay, so we enter the unaligned access check: + + ![ 2.947680] initcall_start: func=check_unaligned_access_all_cpus+0x0/0x1d4 + $ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + ... + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned load$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + !OpenSBI: misaligned store$ + +But we never arrive to anywhere else. + +Here are the current options that match ALIGN: + + hut% grep ALIGN /nix/store/c9jr35xnh2ffzjvkq8nvzj9i2siz1n4s-linux-config-riscv64-unknown-linux-gnu-6.9.7 + CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW=y + CONFIG_RISCV_MISALIGNED=y + CONFIG_RISCV_PROBE_UNALIGNED_ACCESS=y + # CONFIG_RISCV_EMULATED_UNALIGNED_ACCESS is not set + # CONFIG_RISCV_SLOW_UNALIGNED_ACCESS is not set + # CONFIG_RISCV_EFFICIENT_UNALIGNED_ACCESS is not set + CONFIG_HAVE_64BIT_ALIGNED_ACCESS=y + CONFIG_FUNCTION_ALIGNMENT=0 + CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC=y + CONFIG_CMA_ALIGNMENT=8 + # CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_64B is not set + +We may want to set these two: + + # CONFIG_RISCV_EMULATED_UNALIGNED_ACCESS is not set + # CONFIG_RISCV_SLOW_UNALIGNED_ACCESS is not set + +And disable + + CONFIG_RISCV_PROBE_UNALIGNED_ACCESS=y + +So we don't perform the probing. However, this may bite later, so probably is a +better idea to debug it now. I could bound where it is failing as it doesn't +seem to be outside the speed check function. + + +Those 8 pairs of load and store calls seem to match this assembly function in +arch/riscv/kernel/copy-unaligned.S: + + /* void __riscv_copy_bytes_unaligned(void *, const void *, size_t) */ + /* Performs a memcpy without aligning buffers, using only byte accesses. */ + /* Note: The size is truncated to a multiple of 8 */ + SYM_FUNC_START(__riscv_copy_bytes_unaligned) + andi a4, a2, ~(8-1) + beqz a4, 2f + add a3, a1, a4 + 1: + lb a4, 0(a1) + lb a5, 1(a1) + lb a6, 2(a1) + lb a7, 3(a1) + lb t0, 4(a1) + lb t1, 5(a1) + lb t2, 6(a1) + lb t3, 7(a1) + sb a4, 0(a0) + sb a5, 1(a0) + sb a6, 2(a0) + sb a7, 3(a0) + sb t0, 4(a0) + sb t1, 5(a0) + sb t2, 6(a0) + sb t3, 7(a0) + addi a0, a0, 8 + addi a1, a1, 8 + bltu a1, a3, 1b + + 2: + ret + SYM_FUNC_END(__riscv_copy_bytes_unaligned) diff --git a/opensbi-timer-debug.patch b/opensbi-timer-debug.patch index 735f55e..33471af 100644 --- a/opensbi-timer-debug.patch +++ b/opensbi-timer-debug.patch @@ -34,7 +34,7 @@ index 7b618de..65e42b0 100644 void sbi_timer_exit(struct sbi_scratch *scratch) diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c -index b4f3a17..b60315f 100644 +index b4f3a17..742eea6 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -283,6 +283,7 @@ static int sbi_trap_aia_irq(void) @@ -77,7 +77,7 @@ index b4f3a17..b60315f 100644 if (rc) sbi_trap_error(msg, rc, tcntx); + else -+ sbi_printf("$\n"); ++ sbi_printf("$"); if (((regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT) != PRV_M) sbi_sse_process_pending_events(regs);