git: 0fcf472fd583 - stable/13 - amd64: Add comments to pmap_pinit_type()

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 03 Nov 2021 17:54:04 UTC
The branch stable/13 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=0fcf472fd583c51d5d583305c10ba1430a378ba1

commit 0fcf472fd583c51d5d583305c10ba1430a378ba1
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2021-10-20 00:29:18 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2021-11-03 17:41:55 +0000

    amd64: Add comments to pmap_pinit_type()
    
    ... explaining why we don't pass the pmap pointer to
    pmap_alloc_pt_page().
    
    Reported by:    alc
    Reviewed by:    alc, kib
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit 34fac29e98313fb0bfba0503e2e19e352b452516)
---
 sys/amd64/amd64/pmap.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c
index 19219e4676cc..d7954b9444b5 100644
--- a/sys/amd64/amd64/pmap.c
+++ b/sys/amd64/amd64/pmap.c
@@ -4293,7 +4293,9 @@ pmap_pinit_type(pmap_t pmap, enum pmap_type pm_type, int flags)
 	int i;
 
 	/*
-	 * allocate the page directory page
+	 * Allocate the page directory page.  Pass NULL instead of a pointer to
+	 * the pmap here to avoid recording this page in the resident count, as
+	 * optimizations in pmap_remove() depend on this.
 	 */
 	pmltop_pg = pmap_alloc_pt_page(NULL, 0, VM_ALLOC_WIRED | VM_ALLOC_ZERO |
 	    VM_ALLOC_WAITOK);
@@ -4325,6 +4327,10 @@ pmap_pinit_type(pmap_t pmap, enum pmap_type pm_type, int flags)
 		else
 			pmap_pinit_pml4(pmltop_pg);
 		if ((curproc->p_md.md_flags & P_MD_KPTI) != 0) {
+			/*
+			 * As with pmltop_pg, pass NULL instead of a pointer to
+			 * the pmap to ensure that the PTI page isn't counted.
+			 */
 			pmltop_pgu = pmap_alloc_pt_page(NULL, 0,
 			    VM_ALLOC_WIRED | VM_ALLOC_WAITOK);
 			pmap->pm_pmltopu = (pml4_entry_t *)PHYS_TO_DMAP(