Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Jun 2013 05:36:52 +0000 (UTC)
From:      Neel Natu <neel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r252244 - in projects/bhyve_npt_pmap/sys/amd64: amd64 include
Message-ID:  <201306260536.r5Q5aquI001654@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: neel
Date: Wed Jun 26 05:36:51 2013
New Revision: 252244
URL: http://svnweb.freebsd.org/changeset/base/252244

Log:
  Add a function to initialize a pmap with the specified type. The existing
  pmap_pinit() now becomes a wrapper around this function.
  
  Install the shared kernel mappings only in regular x86 page tables. These
  mappings are meaningless in a nested page table which describes the guest
  physical address space. This was prompted by a discussion with Alax Cox.

Modified:
  projects/bhyve_npt_pmap/sys/amd64/amd64/pmap.c
  projects/bhyve_npt_pmap/sys/amd64/include/pmap.h

Modified: projects/bhyve_npt_pmap/sys/amd64/amd64/pmap.c
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/amd64/pmap.c	Wed Jun 26 05:03:47 2013	(r252243)
+++ projects/bhyve_npt_pmap/sys/amd64/amd64/pmap.c	Wed Jun 26 05:36:51 2013	(r252244)
@@ -1669,7 +1669,7 @@ pmap_pinit0(pmap_t pmap)
  * such as one in a vmspace structure.
  */
 int
-pmap_pinit(pmap_t pmap)
+pmap_pinit_type(pmap_t pmap, enum pmap_type pm_type)
 {
 	vm_page_t pml4pg;
 	int i;
@@ -1688,17 +1688,24 @@ pmap_pinit(pmap_t pmap)
 	if ((pml4pg->flags & PG_ZERO) == 0)
 		pagezero(pmap->pm_pml4);
 
-	/* Wire in kernel global address entries. */
-	pmap->pm_pml4[KPML4I] = KPDPphys | PG_RW | PG_V | PG_U;
-	for (i = 0; i < NDMPML4E; i++) {
-		pmap->pm_pml4[DMPML4I + i] = (DMPDPphys + (i << PAGE_SHIFT)) |
-		    PG_RW | PG_V | PG_U;
-	}
+	/*
+	 * Do not install the host kernel mappings in the nested page
+	 * tables. These mappings are meaningless in the guest physical
+	 * address space.
+	 */
+	if ((pmap->pm_type = pm_type) == PT_X86) {
+		/* Wire in kernel global address entries. */
+		pmap->pm_pml4[KPML4I] = KPDPphys | PG_RW | PG_V | PG_U;
+		for (i = 0; i < NDMPML4E; i++) {
+			pmap->pm_pml4[DMPML4I + i] =
+			  (DMPDPphys + (i << PAGE_SHIFT)) | PG_RW | PG_V | PG_U;
+		}
 
-	/* install self-referential address mapping entry(s) */
-	pmap->pm_pml4[PML4PML4I] = VM_PAGE_TO_PHYS(pml4pg) | PG_V | PG_RW | PG_A | PG_M;
+		/* install self-referential address mapping entry(s) */
+		pmap->pm_pml4[PML4PML4I] =
+			VM_PAGE_TO_PHYS(pml4pg) | PG_V | PG_RW | PG_A | PG_M;
+	}
 
-	pmap->pm_type = PT_X86;
 	pmap->pm_root.rt_root = 0;
 	CPU_ZERO(&pmap->pm_active);
 	TAILQ_INIT(&pmap->pm_pvchunk);
@@ -1707,6 +1714,13 @@ pmap_pinit(pmap_t pmap)
 	return (1);
 }
 
+int
+pmap_pinit(pmap_t pmap)
+{
+
+	return (pmap_pinit_type(pmap, PT_X86));
+}
+
 /*
  * This routine is called if the desired page table page does not exist.
  *

Modified: projects/bhyve_npt_pmap/sys/amd64/include/pmap.h
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/include/pmap.h	Wed Jun 26 05:03:47 2013	(r252243)
+++ projects/bhyve_npt_pmap/sys/amd64/include/pmap.h	Wed Jun 26 05:36:51 2013	(r252244)
@@ -272,6 +272,8 @@ extern struct pmap	kernel_pmap_store;
 #define	PMAP_MTX(pmap)		(&(pmap)->pm_mtx)
 #define	PMAP_TRYLOCK(pmap)	mtx_trylock(&(pmap)->pm_mtx)
 #define	PMAP_UNLOCK(pmap)	mtx_unlock(&(pmap)->pm_mtx)
+
+int pmap_pinit_type(pmap_t pmap, enum pmap_type pm_type);
 #endif
 
 /*



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