git: 60a559d7dec5 - main - arm64/pmap: Ignore pmap_advise() for stage 2 pmaps

From: Hayzam Sherif <hayzam_at_FreeBSD.org>
Date: Fri, 20 Nov 2026 01:13:38 UTC
The branch main has been updated by hayzam:

URL: https://cgit.FreeBSD.org/src/commit/?id=60a559d7dec5344d2ef1f4ee225fbd0325feeb3c

commit 60a559d7dec5344d2ef1f4ee225fbd0325feeb3c
Author:     Hayzam Sherif <hayzam@FreeBSD.org>
AuthorDate: 2026-11-19 23:32:17 +0000
Commit:     Hayzam Sherif <hayzam@FreeBSD.org>
CommitDate: 2026-11-20 01:10:52 +0000

    arm64/pmap: Ignore pmap_advise() for stage 2 pmaps
    
    When vm_fault() handles a sequential fault that needs pager I/O, it
    calls vm_fault_dontneed(), which passes MADV_DONTNEED to pmap_advise()
    for the pages behind the fault.  For vmm(4) guest memory the pmap is a
    stage 2 pmap, so a guest that reads paged-out memory sequentially
    panics an INVARIANTS kernel on the stage 1 assertion in pmap_advise().
    
    MADV_DONTNEED and MADV_FREE are only hints, so ignore them for stage 2
    pmaps.
    
    Reviewed by:    markj
    Approved by:    markj (mentor)
    Sponsored by:   Alchemilla Ventures Private Limited
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D61622
---
 sys/arm64/arm64/pmap.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c
index 7340627e6721..e64d5a345f30 100644
--- a/sys/arm64/arm64/pmap.c
+++ b/sys/arm64/arm64/pmap.c
@@ -8205,11 +8205,18 @@ pmap_advise(pmap_t pmap, vm_offset_t sva, vm_offset_t eva, int advice)
 	pd_entry_t *l0, *l1, *l2, oldl2;
 	pt_entry_t *l3, *dl3, oldl3;
 
-	PMAP_ASSERT_STAGE1(pmap);
-
 	if (advice != MADV_DONTNEED && advice != MADV_FREE)
 		return;
 
+	/*
+	 * The code below changes stage 1 permission bits and invalidates
+	 * stage 1 TLB entries.  vm_fault() reaches here for a stage 2 pmap
+	 * when it drops pages behind a sequential fault.  MADV_DONTNEED and
+	 * MADV_FREE are advisory, so skip them entirely for stage 2 pmaps.
+	 */
+	if (pmap->pm_stage != PM_STAGE1)
+		return;
+
 	PMAP_LOCK(pmap);
 	for (; sva < eva; sva = va_next) {
 		l0 = pmap_l0(pmap, sva);