From b0568ddbecdf77c98c635a56f7137baec13754f5 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Mon, 20 Aug 2018 19:07:57 +0000 Subject: [PATCH] Always initialize PCPU kcr3 for vmspace0 pmap. If an exception or NMI occurs before CPU switched to a pmap different from vmspace0, PCPU kcr3 is left zero for pti config, which causes triple-fault in the handler. Sponsored by: The FreeBSD Foundation MFC after: 3 days --- sys/amd64/amd64/pmap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c index 18777d23f098..d012336220cd 100644 --- a/sys/amd64/amd64/pmap.c +++ b/sys/amd64/amd64/pmap.c @@ -2661,10 +2661,6 @@ pmap_pinit0(pmap_t pmap) CPU_FOREACH(i) { pmap->pm_pcids[i].pm_pcid = PMAP_PCID_KERN + 1; pmap->pm_pcids[i].pm_gen = 1; - if (!pti) { - __pcpu[i].pc_kcr3 = PMAP_NO_CR3; - __pcpu[i].pc_ucr3 = PMAP_NO_CR3; - } } pmap_activate_boot(pmap); } @@ -7571,6 +7567,7 @@ pmap_activate(struct thread *td) void pmap_activate_boot(pmap_t pmap) { + uint64_t kcr3; u_int cpuid; /* @@ -7586,6 +7583,11 @@ pmap_activate_boot(pmap_t pmap) CPU_SET(cpuid, &pmap->pm_active); #endif PCPU_SET(curpmap, pmap); + kcr3 = pmap->pm_cr3; + if (pmap_pcid_enabled) + kcr3 |= pmap->pm_pcids[cpuid].pm_pcid | CR3_PCID_SAVE; + PCPU_SET(kcr3, kcr3); + PCPU_SET(ucr3, PMAP_NO_CR3); } void