Module Name:    src
Committed By:   martin
Date:           Mon Apr 26 09:26:25 UTC 2010

Modified Files:
        src/sys/arch/sparc/sparc: pmap.c

Log Message:
Avoid using demap_lock early in pmap_bootstrap before it is initialized.


To generate a diff of this commit:
cvs rdiff -u -r1.339 -r1.340 src/sys/arch/sparc/sparc/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/sparc/sparc/pmap.c
diff -u src/sys/arch/sparc/sparc/pmap.c:1.339 src/sys/arch/sparc/sparc/pmap.c:1.340
--- src/sys/arch/sparc/sparc/pmap.c:1.339	Sun Dec 20 03:48:30 2009
+++ src/sys/arch/sparc/sparc/pmap.c	Mon Apr 26 09:26:25 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.339 2009/12/20 03:48:30 mrg Exp $ */
+/*	$NetBSD: pmap.c,v 1.340 2010/04/26 09:26:25 martin Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -56,7 +56,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.339 2009/12/20 03:48:30 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.340 2010/04/26 09:26:25 martin Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -316,6 +316,7 @@
 int	reginval;		/* [4/3mmu] the invalid region number */
 
 static kmutex_t demap_lock;
+static bool	lock_available = false;	/* demap_lock has been initialized */
 
 /*
  * (sun4/4c)
@@ -781,12 +782,14 @@
 {
 	int oldval, swapval;
 	volatile int *vpte = (volatile int *)pte;
+	bool can_lock = lock_available;
 
 	/*
 	 * Can only be one of these happening in the system
 	 * at any one time.
 	 */
-	mutex_spin_enter(&demap_lock);
+	if (__predict_true(can_lock))
+		mutex_spin_enter(&demap_lock);
 
 	/*
 	 * The idea is to loop swapping zero into the pte, flushing
@@ -805,7 +808,8 @@
 	swapval = (oldval & ~bic) | bis;
 	swap(vpte, swapval);
 
-	mutex_spin_exit(&demap_lock);
+	if (__predict_true(can_lock))
+		mutex_spin_exit(&demap_lock);
 
 	return (oldval);
 }
@@ -3028,6 +3032,7 @@
 	pmap_page_upload();
 	mutex_init(&demap_lock, MUTEX_DEFAULT, IPL_VM);
 	mutex_init(&ctx_lock, MUTEX_DEFAULT, IPL_SCHED);
+	lock_available = true;
 }
 
 #if defined(SUN4) || defined(SUN4C)
@@ -6746,6 +6751,7 @@
 	struct segmap *sp;
 	int pte;
 	int vr, vs, s, v = false;
+	bool can_lock = lock_available;
 
 	vr = VA_VREG(va);
 	vs = VA_VSEG(va);
@@ -6789,9 +6795,11 @@
 		 * the middle of the PTE update protocol. So, acquire the
 		 * demap lock and retry.
 		 */
-		mutex_spin_enter(&demap_lock);
+		if (__predict_true(can_lock))
+			mutex_spin_enter(&demap_lock);
 		pte = sp->sg_pte[VA_SUN4M_VPG(va)];
-		mutex_spin_exit(&demap_lock);
+		if (__predict_true(can_lock))
+			mutex_spin_exit(&demap_lock);
 		if ((pte & SRMMU_TETYPE) != SRMMU_TEPTE)
 			goto out;
 	}

Reply via email to