git: 7489f0bf84e4 - main - riscv/mp_machdep.c: Flush the TLB after releasing APs

From: Bojan Novković <bnovkov_at_FreeBSD.org>
Date: Fri, 10 Jul 2026 16:03:45 UTC
The branch main has been updated by bnovkov:

URL: https://cgit.FreeBSD.org/src/commit/?id=7489f0bf84e4c88ad6cfbf4c8cf91bd7bede56f6

commit 7489f0bf84e4c88ad6cfbf4c8cf91bd7bede56f6
Author:     Bojan Novković <bnovkov@FreeBSD.org>
AuthorDate: 2026-05-13 15:49:01 +0000
Commit:     Bojan Novković <bnovkov@FreeBSD.org>
CommitDate: 2026-07-10 15:52:52 +0000

    riscv/mp_machdep.c: Flush the TLB after releasing APs
    
    Spurious page faults caused by cached invalid entries may occur when
    starting APs and potentially panic the kernel if we're running in
    a non-sleepable context.
    
    Fix this avoidable panic by flushing the TLB after the AP is released.
    
    Differential Revision:  https://reviews.freebsd.org/D57003
    Reviewed by:    markj
---
 sys/riscv/riscv/mp_machdep.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/sys/riscv/riscv/mp_machdep.c b/sys/riscv/riscv/mp_machdep.c
index 235bee15ca29..9c81d9ee1043 100644
--- a/sys/riscv/riscv/mp_machdep.c
+++ b/sys/riscv/riscv/mp_machdep.c
@@ -172,6 +172,11 @@ init_secondary(uint64_t hart)
 	while (!atomic_load_int(&aps_ready))
 		__asm __volatile("wfi");
 
+	/*
+	 * Flush the TLB to avoid spurious kernel page faults
+	 * on implementations that cache invalid entries.
+	 */
+	sfence_vma();
 	/* Initialize curthread */
 	KASSERT(PCPU_GET(idlethread) != NULL, ("no idle thread"));
 	pcpup->pc_curthread = pcpup->pc_idlethread;