Module Name:    src
Committed By:   cherry
Date:           Sun Jan 22 18:16:35 UTC 2012

Modified Files:
        src/sys/arch/x86/x86: pmap.c
        src/sys/arch/xen/x86: xen_pmap.c

Log Message:
Do not clobber pmap_kernel()'s pdir unnecessarily while syncing per-cpu pdirs


To generate a diff of this commit:
cvs rdiff -u -r1.153 -r1.154 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/xen/x86/xen_pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.153 src/sys/arch/x86/x86/pmap.c:1.154
--- src/sys/arch/x86/x86/pmap.c:1.153	Mon Jan  9 12:58:49 2012
+++ src/sys/arch/x86/x86/pmap.c	Sun Jan 22 18:16:35 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.153 2012/01/09 12:58:49 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.154 2012/01/22 18:16:35 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
@@ -171,7 +171,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.153 2012/01/09 12:58:49 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.154 2012/01/22 18:16:35 cherry Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -1883,7 +1883,6 @@ pmap_free_ptp(struct pmap *pmap, struct 
 		 * on any cpu, clear it before freeing
 		 */
 		if (level == PTP_LEVELS - 1) {
-			pmap_pte_set(&pmap_kernel()->pm_pdir[index], 0);
 			/*
 			 * Update the per-cpu PD on all cpus the current
 			 * pmap is active on 
@@ -1987,9 +1986,6 @@ pmap_get_ptp(struct pmap *pmap, vaddr_t 
 		 * if pmap is curmap and modifying top level (PGD)
 		 */
 		if(i == PTP_LEVELS && pmap != pmap_kernel()) {
-		        pmap_pte_set(&pmap_kernel()->pm_pdir[index],
-		                (pd_entry_t) (pmap_pa2pte(pa)
-		                        | PG_u | PG_RW | PG_V));
 			/*
 			 * Update the per-cpu PD on all cpus the current
 			 * pmap is active on 

Index: src/sys/arch/xen/x86/xen_pmap.c
diff -u src/sys/arch/xen/x86/xen_pmap.c:1.14 src/sys/arch/xen/x86/xen_pmap.c:1.15
--- src/sys/arch/xen/x86/xen_pmap.c:1.14	Thu Jan 19 22:04:05 2012
+++ src/sys/arch/xen/x86/xen_pmap.c	Sun Jan 22 18:16:34 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_pmap.c,v 1.14 2012/01/19 22:04:05 bouyer Exp $	*/
+/*	$NetBSD: xen_pmap.c,v 1.15 2012/01/22 18:16:34 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -102,7 +102,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.14 2012/01/19 22:04:05 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.15 2012/01/22 18:16:34 cherry Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -555,16 +555,19 @@ pmap_unmap_recursive_entries(void)
 
 extern struct cpu_info	* (*xpq_cpu)(void);
 static __inline void
-pmap_kpm_setpte(struct cpu_info *ci, int index)
+pmap_kpm_setpte(struct cpu_info *ci, struct pmap *pmap, int index)
 {
+	if (pmap == pmap_kernel()) {
+		KASSERT(index >= PDIR_SLOT_KERN);
+	}
 #ifdef PAE
-		xpq_queue_pte_update(
-			xpmap_ptetomach(&ci->ci_kpm_pdir[l2tol2(index)]),
-			pmap_kernel()->pm_pdir[index]);
+	xpq_queue_pte_update(
+		xpmap_ptetomach(&ci->ci_kpm_pdir[l2tol2(index)]),
+		pmap->pm_pdir[index]);
 #elif defined(__x86_64__)
-		xpq_queue_pte_update(
-			xpmap_ptetomach(&ci->ci_kpm_pdir[index]),
-			pmap_kernel()->pm_pdir[index]);
+	xpq_queue_pte_update(
+		xpmap_ptetomach(&ci->ci_kpm_pdir[index]),
+		pmap->pm_pdir[index]);
 #endif /* PAE */
 }
 
@@ -580,27 +583,20 @@ pmap_kpm_sync_xcall(void *arg1, void *ar
 	
 	struct cpu_info *ci = xpq_cpu();
 
-	if (pmap == pmap_kernel()) {
-		KASSERT(index >= PDIR_SLOT_KERN);
-		pmap_kpm_setpte(ci, index);
-		pmap_pte_flush();
-		return;
-	}
-
 #ifdef PAE
-	KASSERTMSG(false, "%s not allowed for PAE user pmaps", __func__);
-	return;
-#else /* __x86_64__ */
-	
-	if (ci->ci_pmap != pmap) {
-		/* pmap changed. Nothing to do. */
+	KASSERTMSG(pmap == pmap_kernel(), "%s not allowed for PAE user pmaps", __func__);
+#endif /* PAE */
+
+	if (__predict_true(pmap != pmap_kernel()) &&
+	    pmap != ci->ci_pmap) {
+		/* User pmap changed. Nothing to do. */
 		return;
 	}
-	
-	pmap_pte_set(&ci->ci_kpm_pdir[index],
-	    pmap->pm_pdir[index]);
+
+	/* Update per-cpu kpm */
+	pmap_kpm_setpte(ci, pmap, index);
 	pmap_pte_flush();
-#endif /* PAE || __x86_64__ */
+	return;
 }
 
 /*
@@ -626,7 +622,7 @@ xen_kpm_sync(struct pmap *pmap, int inde
 			}
 			if (pmap == pmap_kernel() ||
 			    ci->ci_cpumask & pmap->pm_cpus) {
-				pmap_kpm_setpte(ci, index);
+				pmap_kpm_setpte(ci, pmap, index);
 			}
 		}
 		pmap_pte_flush();

Reply via email to