riscv: mm: Disable GCOV instrumentation in set_satp_mode()
PATCH 1/1 riscv: mm: Disable GCOV instrumentation in set_satp_mode()
From: Xionggui Chen <[email protected]>
When CONFIG_GCOV_PROFILE_ALL is enabled, GCC instruments set_satp_mode() with GCOV counter updates.
The function temporarily enables an identity mapping to probe supported SATP modes. GCOV instrumentation may access counters outside this temporary mapping while SATP is enabled, causing a Store/AMO page fault during early boot.
On QEMU virt with Linux 7.4.0-rc1, the fault occurs immediately after writing satp. The faulting instruction is an amoadd.d updating a GCOV counter in set_satp_mode().
Mark set_satp_mode() with __no_profile to prevent GCOV counter accesses during SATP probing, while preserving GCOV coverage for the other functions in init.c.
Without this change, QEMU fails during early boot. With this change, the kernel reaches root filesystem mounting.
The fix was also verified on RISC-V hardware with Linux 7.2.0.
--- arch/riscv/mm/init.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/riscv/mm/init.c +4 -1
@@ -833,8 +833,11 @@ static bool __init is_vaddr_valid(unsigned long va)* The maximum SATP mode is limited by both the command line and the "mmu-type" * property in the device tree, since some platforms may hang if an unsupported * SATP mode is attempted. +* +* GCOV instrumentation must be disabled because the temporary identity +* mapping does not cover GCOV counters while probing SATP modes. */ -static __init void set_satp_mode (uintptr_t dtb_pa) +static __init __no_profile void set_satp_mode(uintptr_t dtb_pa) {u64 identity_satp, hw_satp;uintptr_t set_satp_mode_pmd = ((unsigned long )set_satp_mode) &PMD_MASK ;
Signature · 1 line
2.53.0