git: e704f88f3d92 - main - amd64: initialize APs kpmap_store in init_secondary()

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 04 May 2023 15:40:13 UTC
The branch main has been updated by kib:

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

commit e704f88f3d924202e60e37c82dd50a5022c89dd4
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-05-04 06:17:30 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-05-04 15:39:22 +0000

    amd64: initialize APs kpmap_store in init_secondary()
    
    The APs pcpu area is zeroed in init_secondary() by pcpu_init(), so the
    early initialization in pmap_bootstrap() is nop.
    
    Fixes:  42f722e721cd010ae5759a4b0d3b7b93c2b9cad2ESC
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    Differential revision:  https://reviews.freebsd.org/D39945
---
 sys/amd64/amd64/mp_machdep.c | 2 ++
 sys/amd64/amd64/pmap.c       | 8 ++------
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c
index 94589f736637..f6c3446e9981 100644
--- a/sys/amd64/amd64/mp_machdep.c
+++ b/sys/amd64/amd64/mp_machdep.c
@@ -215,6 +215,8 @@ init_secondary(void)
 	/* See comment in pmap_bootstrap(). */
 	pc->pc_pcid_next = PMAP_PCID_KERN + 2;
 	pc->pc_pcid_gen = 1;
+	pc->pc_kpmap_store.pm_pcid = PMAP_PCID_KERN;
+	pc->pc_kpmap_store.pm_gen = 1;
 
 	pc->pc_smp_tlb_gen = 1;
 
diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c
index a09920d62961..55086125fbb9 100644
--- a/sys/amd64/amd64/pmap.c
+++ b/sys/amd64/amd64/pmap.c
@@ -2036,13 +2036,9 @@ pmap_bootstrap(vm_paddr_t *firstaddr)
 	if (pmap_pcid_enabled) {
 		kernel_pmap->pm_pcidp = (void *)(uintptr_t)
 		    offsetof(struct pcpu, pc_kpmap_store);
-		for (i = 0; i < MAXCPU; i++) {
-			struct pmap_pcid *pcidp;
 
-			pcidp = zpcpu_get_cpu(kernel_pmap->pm_pcidp, i);
-			pcidp->pm_pcid = PMAP_PCID_KERN;
-			pcidp->pm_gen = 1;
-		}
+		PCPU_SET(kpmap_store.pm_pcid, PMAP_PCID_KERN);
+		PCPU_SET(kpmap_store.pm_gen, 1);
 
 		/*
 		 * PMAP_PCID_KERN + 1 is used for initialization of