CVS commit: [cherry-xenmp] src/sys/arch/xen/x86

2011-06-27 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jun 27 10:23:21 UTC 2011

Modified Files:
src/sys/arch/xen/x86 [cherry-xenmp]: x86_xpmap.c

Log Message:
Add xpq locking around xpq-QUEUE_TLB_FLUSH()


To generate a diff of this commit:
cvs rdiff -u -r1.26.2.2 -r1.26.2.3 src/sys/arch/xen/x86/x86_xpmap.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/xen/x86/x86_xpmap.c
diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.2 src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.3
--- src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.2	Thu Jun 23 14:19:50 2011
+++ src/sys/arch/xen/x86/x86_xpmap.c	Mon Jun 27 10:23:21 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.26.2.2 2011/06/23 14:19:50 cherry Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.26.2.3 2011/06/27 10:23:21 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -69,7 +69,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.26.2.2 2011/06/23 14:19:50 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.26.2.3 2011/06/27 10:23:21 cherry Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -658,7 +658,9 @@
 	(UPAGES + 1) * NBPG);
 
 	/* Finally, flush TLB. */
+	xpq_queue_lock();
 	xpq_queue_tlb_flush();
+	xpq_queue_unlock();
 
 	return (init_tables + ((count + l2_4_count) * PAGE_SIZE));
 }



CVS commit: [cherry-xenmp] src/sys/arch/xen/x86

2011-09-18 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Sep 18 16:48:23 UTC 2011

Modified Files:
src/sys/arch/xen/x86 [cherry-xenmp]: x86_xpmap.c

Log Message:
Make the xpq locking per-cpu


To generate a diff of this commit:
cvs rdiff -u -r1.26.2.9 -r1.26.2.10 src/sys/arch/xen/x86/x86_xpmap.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/xen/x86/x86_xpmap.c
diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.9 src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.10
--- src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.9	Fri Sep  9 11:53:43 2011
+++ src/sys/arch/xen/x86/x86_xpmap.c	Sun Sep 18 16:48:23 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.26.2.9 2011/09/09 11:53:43 cherry Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.26.2.10 2011/09/18 16:48:23 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -69,7 +69,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.26.2.9 2011/09/09 11:53:43 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.26.2.10 2011/09/18 16:48:23 cherry Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -168,26 +168,26 @@
 static int xpq_idx_array[MAXCPUS];
 
 #ifdef MULTIPROCESSOR
-static struct simplelock xpq_lock = SIMPLELOCK_INITIALIZER;
+static struct simplelock xpq_lock[MAXCPUS];
 
 extern struct cpu_info * (*xpq_cpu)(void);
 
 void
 xpq_queue_lock(void)
 {
-	simple_lock(&xpq_lock);
+	simple_lock(&xpq_lock[xpq_cpu()->ci_cpuid]);
 }
 
 void
 xpq_queue_unlock(void)
 {
-	simple_unlock(&xpq_lock);
+	simple_unlock(&xpq_lock[xpq_cpu()->ci_cpuid]);
 }
 
 bool
 xpq_queue_locked(void)
 {
-	return simple_lock_held(&xpq_lock);
+	return simple_lock_held(&xpq_lock[xpq_cpu()->ci_cpuid]);
 }
 #endif /* MULTIPROCESSOR */
 
@@ -589,12 +589,15 @@
 vaddr_t
 xen_pmap_bootstrap(void)
 {
-	int count, oldcount;
+	int count, oldcount, i;
 	long mapsize;
 	vaddr_t bootstrap_tables, init_tables;
 
 	memset(xpq_idx_array, 0, sizeof xpq_idx_array);
-	
+	for (i = 0; i < MAXCPUS;i++) {
+		simple_lock_init(&xpq_lock[i]);
+	}
+
 	xpmap_phys_to_machine_mapping =
 	(unsigned long *)xen_start_info.mfn_list;
 	init_tables = xen_start_info.pt_base;



CVS commit: [cherry-xenmp] src/sys/arch/xen/x86

2011-08-22 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Aug 22 16:48:03 UTC 2011

Modified Files:
src/sys/arch/xen/x86 [cherry-xenmp]: hypervisor_machdep.c

Log Message:
Do not trust the hypervisor to route events to the right cpu. Enforce this in 
stipending()


To generate a diff of this commit:
cvs rdiff -u -r1.14.2.3 -r1.14.2.4 src/sys/arch/xen/x86/hypervisor_machdep.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/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.3 src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.4
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.3	Wed Aug 17 09:40:39 2011
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Mon Aug 22 16:48:03 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.14.2.3 2011/08/17 09:40:39 cherry Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.14.2.4 2011/08/22 16:48:03 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.14.2.3 2011/08/17 09:40:39 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.14.2.4 2011/08/22 16:48:03 cherry Exp $");
 
 #include 
 #include 
@@ -140,8 +140,8 @@
 	int *ret = args;
 
 	if (evtsource[port]) {
-		hypervisor_set_ipending(ci, evtsource[port]->ev_imask,
-		l1i, l2i);
+		hypervisor_set_ipending(evtsource[port]->ev_cpu,
+		evtsource[port]->ev_imask, l1i, l2i);
 		evtsource[port]->ev_evcnt.ev_count++;
 		if (*ret == 0 && ci->ci_ilevel <
 		evtsource[port]->ev_maxlevel)



CVS commit: [cherry-xenmp] src/sys/arch/xen/x86

2011-08-22 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Aug 22 17:39:19 UTC 2011

Modified Files:
src/sys/arch/xen/x86 [cherry-xenmp]: xen_pmap.c

Log Message:
Remove spurious locks


To generate a diff of this commit:
cvs rdiff -u -r1.2.2.3 -r1.2.2.4 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/xen/x86/xen_pmap.c
diff -u src/sys/arch/xen/x86/xen_pmap.c:1.2.2.3 src/sys/arch/xen/x86/xen_pmap.c:1.2.2.4
--- src/sys/arch/xen/x86/xen_pmap.c:1.2.2.3	Sat Aug 20 19:22:47 2011
+++ src/sys/arch/xen/x86/xen_pmap.c	Mon Aug 22 17:39:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_pmap.c,v 1.2.2.3 2011/08/20 19:22:47 cherry Exp $	*/
+/*	$NetBSD: xen_pmap.c,v 1.2.2.4 2011/08/22 17:39:19 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -102,7 +102,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.2.2.3 2011/08/20 19:22:47 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.2.2.4 2011/08/22 17:39:19 cherry Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -212,7 +212,6 @@
 
 	/* the kernel's pmap is always accessible */
 	if (pmap == pmap_kernel()) {
-		mutex_enter(pmap->pm_lock);
 		*pmap2 = NULL;
 		*ptepp = PTE_BASE;
 		*pdeppp = normal_pdes;
@@ -327,7 +326,6 @@
 {
 
 	if (pmap == pmap_kernel()) {
-		mutex_exit(pmap->pm_lock);
 		return;
 	}
 	KASSERT(kpreempt_disabled());



CVS commit: [cherry-xenmp] src/sys/arch/xen/x86

2011-08-26 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Aug 26 13:33:34 UTC 2011

Modified Files:
src/sys/arch/xen/x86 [cherry-xenmp]: cpu.c

Log Message:
Name the L4 per-cpu pointer appropriately.
User cr3 should point to the per-cpu L4, not the user pmap pdir


To generate a diff of this commit:
cvs rdiff -u -r1.56.2.7 -r1.56.2.8 src/sys/arch/xen/x86/cpu.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/xen/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.56.2.7 src/sys/arch/xen/x86/cpu.c:1.56.2.8
--- src/sys/arch/xen/x86/cpu.c:1.56.2.7	Sat Aug 20 19:22:47 2011
+++ src/sys/arch/xen/x86/cpu.c	Fri Aug 26 13:33:34 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.56.2.7 2011/08/20 19:22:47 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.56.2.8 2011/08/26 13:33:34 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.56.2.7 2011/08/20 19:22:47 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.56.2.8 2011/08/26 13:33:34 cherry Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -1253,10 +1253,10 @@
 	int i, s;
 	pd_entry_t *new_pgd;
 	struct cpu_info *ci;
-	paddr_t l3_shadow_pa;
+	paddr_t l4_pd_ma;
 
 	ci = curcpu();
-	l3_shadow_pa = xpmap_ptom_masked(ci->ci_kpm_pdirpa);
+	l4_pd_ma = xpmap_ptom_masked(ci->ci_kpm_pdirpa);
 
 	/*
 	 * Map user space address in kernel space and load
@@ -1269,15 +1269,15 @@
 
 	/* Copy user pmap L4 PDEs (in user addr. range) to per-cpu L4 */
 	for (i = 0; i < PDIR_SLOT_PTE; i++) {
-		xpq_queue_pte_update(l3_shadow_pa + i * sizeof(pd_entry_t), new_pgd[i]);
+		xpq_queue_pte_update(l4_pd_ma + i * sizeof(pd_entry_t), new_pgd[i]);
 	}
 
 	if (__predict_true(pmap != pmap_kernel())) {
-		xen_set_user_pgd(pmap_pdirpa(pmap, 0));
+		xen_set_user_pgd(ci->ci_kpm_pdirpa);
 		ci->ci_xen_current_user_pgd = pmap_pdirpa(pmap, 0);
 	}
 	else {
-		xpq_queue_pt_switch(l3_shadow_pa);
+		xpq_queue_pt_switch(l4_pd_ma);
 		ci->ci_xen_current_user_pgd = 0;
 	}
 	xpq_queue_unlock();



CVS commit: [cherry-xenmp] src/sys/arch/xen/x86

2011-09-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Sep  9 11:53:43 UTC 2011

Modified Files:
src/sys/arch/xen/x86 [cherry-xenmp]: cpu.c x86_xpmap.c

Log Message:
fix amd64 boot.


To generate a diff of this commit:
cvs rdiff -u -r1.56.2.10 -r1.56.2.11 src/sys/arch/xen/x86/cpu.c
cvs rdiff -u -r1.26.2.8 -r1.26.2.9 src/sys/arch/xen/x86/x86_xpmap.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/xen/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.56.2.10 src/sys/arch/xen/x86/cpu.c:1.56.2.11
--- src/sys/arch/xen/x86/cpu.c:1.56.2.10	Thu Sep  1 08:04:46 2011
+++ src/sys/arch/xen/x86/cpu.c	Fri Sep  9 11:53:43 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.56.2.10 2011/09/01 08:04:46 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.56.2.11 2011/09/09 11:53:43 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.56.2.10 2011/09/01 08:04:46 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.56.2.11 2011/09/09 11:53:43 cherry Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -712,6 +712,7 @@
  * work. 
  */
 extern void x86_64_tls_switch(struct lwp *);
+
 void
 cpu_hatch(void *v)
 {
@@ -918,7 +919,8 @@
 	 * Use pmap_kernel() L4 PD directly, until we setup the
 	 * per-cpu L4 PD in pmap_cpu_init_late()
 	 */
-	initctx->ctrlreg[3] = xpmap_ptom(pcb->pcb_cr3);
+
+	initctx->ctrlreg[3] = xen_pfn_to_cr3(x86_btop(xpmap_ptom(ci->ci_kpm_pdirpa)));
 	initctx->ctrlreg[4] = CR4_PAE | CR4_OSFXSR | CR4_OSXMMEXCPT;
 
 
@@ -1281,7 +1283,7 @@
 	}
 
 	if (__predict_true(pmap != pmap_kernel())) {
-		xen_set_user_pgd(ci->ci_kpm_pdirpa);
+		xen_set_user_pgd(pmap_pdirpa(pmap, 0));
 		ci->ci_xen_current_user_pgd = pmap_pdirpa(pmap, 0);
 	}
 	else {
@@ -1299,6 +1301,27 @@
 
 /*
  * pmap_cpu_init_late: perform late per-CPU initialization.
+ * Short note about percpu PDIR pages:
+ * Both the PAE and __x86_64__ architectures have per-cpu PDIR
+ * tables. This is to get around Xen's pagetable setup constraints for
+ * PAE (multiple L3[3]s cannot point to the same L2 - Xen
+ * will refuse to pin a table setup this way.) and for multiple cpus
+ * to map in different user pmaps on __x86_64__ (see: cpu_load_pmap())
+ *
+ * What this means for us is that the PDIR of the pmap_kernel() is
+ * considered to be a canonical "SHADOW" PDIR with the following
+ * properties: 
+ * - Its recursive mapping points to itself
+ * - per-cpu recurseive mappings point to themselves
+ * - per-cpu L4 pages' kernel entries are expected to be in sync with
+ *   the shadow
+ * - APDP_PDE_SHADOW accesses the shadow pdir
+ * - APDP_PDE accesses the per-cpu pdir
+ * - alternate mappings are considered per-cpu - however, x86 pmap
+ *   currently partially consults the shadow - this works because the
+ *   shadow PDE is updated together with the per-cpu entry (see:
+ *   xen_pmap.c: pmap_map_ptes(), and the pmap is locked while the
+ * alternate ptes are mapped in.
  */
 
 void
@@ -1315,7 +1338,7 @@
 
 	KASSERT(ci != NULL);
 
-#ifdef PAE
+#if defined(PAE)
 	ci->ci_pae_l3_pdir = (paddr_t *)uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
 	UVM_KMF_WIRED | UVM_KMF_ZERO | UVM_KMF_NOWAIT);
 
@@ -1344,26 +1367,32 @@
 	}
 	ci->ci_kpm_pdirpa = vtophys((vaddr_t) ci->ci_kpm_pdir);
 	KASSERT(ci->ci_kpm_pdirpa != 0);
+
+#if defined(__x86_64__)
 	/*
-	 * Copy over kernel pmd entries from boot
-	 * cpu. XXX:locking/races
+	 * Copy over the pmap_kernel() shadow L4 entries 
 	 */
 
-	memcpy(ci->ci_kpm_pdir,
-	&pmap_kernel()->pm_pdir[PDIR_SLOT_KERN],
-	nkptp[PTP_LEVELS - 1] * sizeof(pd_entry_t));
+	memcpy(ci->ci_kpm_pdir, pmap_kernel()->pm_pdir, PAGE_SIZE);
+
+	/* Recursive kernel mapping */
+	ci->ci_kpm_pdir[PDIR_SLOT_PTE] = xpmap_ptom_masked(ci->ci_kpm_pdirpa) | PG_k | PG_V;
+#elif defined(PAE)
+	/* Copy over the pmap_kernel() shadow L2 entries that map the kernel */
+	memcpy(ci->ci_kpm_pdir, pmap_kernel()->pm_pdir + PDIR_SLOT_KERN, nkptp[PTP_LEVELS - 1] * sizeof(pd_entry_t));
+#endif /* __x86_64__ else PAE */
 
 	/* Xen wants R/O */
 	pmap_kenter_pa((vaddr_t)ci->ci_kpm_pdir, ci->ci_kpm_pdirpa,
 	VM_PROT_READ, 0);
 
-#ifdef PAE
+#if defined(PAE)
 	/* Initialise L3 entry 3. This mapping is shared across all
 	 * pmaps and is static, ie; loading a new pmap will not update
 	 * this entry.
 	 */
 	
-	ci->ci_pae_l3_pdir[3] = xpmap_ptom_masked(ci->ci_kpm_pdirpa) | PG_V;
+	ci->ci_pae_l3_pdir[3] = xpmap_ptom_masked(ci->ci_kpm_pdirpa) | PG_k | PG_V;
 
 	/* Mark L3 R/O (Xen wants this) */
 	pmap_kenter_pa((vaddr_t)ci->ci_pae_l3_pdir, ci->ci_pae_l3_pdirpa,

Index: src/sys/arch/xen/x86/x86_xpmap.c
diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.8 src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.9
--- src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.8	Tue Aug 30 12:53:46 2011
+++ src/sys/arch/xen/x86/x86_xpmap.c	Fri Sep  9 11:53:43 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.26.2