Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Aug 2018 19:07:58 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r338112 - head/sys/amd64/amd64
Message-ID:  <201808201907.w7KJ7wOV064994@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Mon Aug 20 19:07:57 2018
New Revision: 338112
URL: https://svnweb.freebsd.org/changeset/base/338112

Log:
  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

Modified:
  head/sys/amd64/amd64/pmap.c

Modified: head/sys/amd64/amd64/pmap.c
==============================================================================
--- head/sys/amd64/amd64/pmap.c	Mon Aug 20 18:50:56 2018	(r338111)
+++ head/sys/amd64/amd64/pmap.c	Mon Aug 20 19:07:57 2018	(r338112)
@@ -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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808201907.w7KJ7wOV064994>