git: 2d6923790b16 - main - amd64 pmap: assert and explain why pmap_qremove() is safe WRT supermappings

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 25 Nov 2024 12:20:09 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=2d6923790b16785ac691cedb23234067672fe1cc

commit 2d6923790b16785ac691cedb23234067672fe1cc
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-11-23 21:02:25 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-11-25 12:16:50 +0000

    amd64 pmap: assert and explain why pmap_qremove() is safe WRT supermappings
    
    Based on alc@ comments from https://reviews.freebsd.org/D47678.
    
    Reviewed by:    alc
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D47717
---
 sys/amd64/amd64/pmap.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c
index 3b7220369b61..21b8555b5380 100644
--- a/sys/amd64/amd64/pmap.c
+++ b/sys/amd64/amd64/pmap.c
@@ -4082,7 +4082,19 @@ pmap_qremove(vm_offset_t sva, int count)
 
 	va = sva;
 	while (count-- > 0) {
+		/*
+		 * pmap_enter() calls within the kernel virtual
+		 * address space happen on virtual addresses from
+		 * subarenas that import superpage-sized and -aligned
+		 * address ranges.  So, the virtual address that we
+		 * allocate to use with pmap_qenter() can't be close
+		 * enough to one of those pmap_enter() calls for it to
+		 * be caught up in a promotion.
+		 */
 		KASSERT(va >= VM_MIN_KERNEL_ADDRESS, ("usermode va %lx", va));
+		KASSERT((*vtopde(va) & X86_PG_PS) == 0,
+		    ("pmap_qremove on promoted va %#lx", va));
+
 		pmap_kremove(va);
 		va += PAGE_SIZE;
 	}