CVS commit: src/doc

2011-06-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Jun  2 22:15:22 UTC 2011

Modified Files:
src/doc: BRANCHES

Log Message:
Add note about cherry-xenmp branch


To generate a diff of this commit:
cvs rdiff -u -r1.307 -r1.308 src/doc/BRANCHES

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

Modified files:

Index: src/doc/BRANCHES
diff -u src/doc/BRANCHES:1.307 src/doc/BRANCHES:1.308
--- src/doc/BRANCHES:1.307	Fri May 20 08:12:46 2011
+++ src/doc/BRANCHES	Thu Jun  2 22:15:22 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: BRANCHES,v 1.307 2011/05/20 08:12:46 matt Exp $
+#	$NetBSD: BRANCHES,v 1.308 2011/06/02 22:15:22 cherry Exp $
 #
 # This file contains a list of branches that exist in the NetBSD CVS
 # tree and their current state.
@@ -285,6 +285,16 @@
 		cpuswitch.S which would otherwise make merging the
 		nathanw_sa branch difficult.
 
+Branch:		cherry-xenmp
+Description:	Port i386 and amd64 Xen kernels to run MP
+Status:		Active
+Start Date:	1st June 2011
+End Date:
+Base Tag:	cherry-xenmp-base
+Maintainer:	Cherry G. Mathew che...@netbsd.org
+Scope:		kernel
+Notes:
+
 Branch:		chris-arm-intr-rework
 Description:	Rework arm interrupt handling code
 Status:		Dormant



CVS commit: src/sys/sys

2011-06-21 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Tue Jun 21 07:20:57 UTC 2011

Modified Files:
src/sys/sys: userret.h

Log Message:
#include sys/proc.h before using struct proc.p_timerpend


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/sys/userret.h

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

Modified files:

Index: src/sys/sys/userret.h
diff -u src/sys/sys/userret.h:1.23 src/sys/sys/userret.h:1.24
--- src/sys/sys/userret.h:1.23	Fri Apr  8 10:36:58 2011
+++ src/sys/sys/userret.h	Tue Jun 21 07:20:56 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: userret.h,v 1.23 2011/04/08 10:36:58 yamt Exp $	*/
+/*	$NetBSD: userret.h,v 1.24 2011/06/21 07:20:56 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2003, 2006, 2008 The NetBSD Foundation, Inc.
@@ -66,6 +66,7 @@
 #define	_SYS_USERRET_H_
 
 #include sys/lockdebug.h
+#include sys/userret.h
 #include sys/intr.h
 
 /*



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

2011-06-26 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Jun 26 12:56:33 UTC 2011

Modified Files:
src/sys/arch/xen/include [cherry-xenmp]: intr.h
src/sys/arch/xen/xen [cherry-xenmp]: hypervisor.c

Log Message:
Unbreak uniprocessor build


To generate a diff of this commit:
cvs rdiff -u -r1.31.10.1 -r1.31.10.2 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.55.2.1 -r1.55.2.2 src/sys/arch/xen/xen/hypervisor.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/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.31.10.1 src/sys/arch/xen/include/intr.h:1.31.10.2
--- src/sys/arch/xen/include/intr.h:1.31.10.1	Fri Jun  3 13:27:40 2011
+++ src/sys/arch/xen/include/intr.h	Sun Jun 26 12:56:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.31.10.1 2011/06/03 13:27:40 cherry Exp $	*/
+/*	$NetBSD: intr.h,v 1.31.10.2 2011/06/26 12:56:32 cherry Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -185,9 +185,15 @@
 struct pic *intr_findpic(int);
 void intr_add_pcibus(struct pcibus_attach_args *);
 
+#ifdef MULTIPROCESSOR
 void xen_ipi_init(void);
 int xen_send_ipi(struct cpu_info *, uint32_t);
 void xen_broadcast_ipi(uint32_t);
+#else
+#define xen_ipi_init(_1) do {} while(0) /* nothing */
+#define xen_send_ipi(_i1, _i2) do {} while(0) /* nothing */
+#define xen_broadcast_ipi(_i1) do {} while(0) /* nothing */
+#endif /* MULTIPROCESSOR */
 
 #endif /* !_LOCORE */
 

Index: src/sys/arch/xen/xen/hypervisor.c
diff -u src/sys/arch/xen/xen/hypervisor.c:1.55.2.1 src/sys/arch/xen/xen/hypervisor.c:1.55.2.2
--- src/sys/arch/xen/xen/hypervisor.c:1.55.2.1	Fri Jun  3 13:27:42 2011
+++ src/sys/arch/xen/xen/hypervisor.c	Sun Jun 26 12:56:33 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.55.2.1 2011/06/03 13:27:42 cherry Exp $ */
+/* $NetBSD: hypervisor.c,v 1.55.2.2 2011/06/26 12:56:33 cherry Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hypervisor.c,v 1.55.2.1 2011/06/03 13:27:42 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: hypervisor.c,v 1.55.2.2 2011/06/26 12:56:33 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -128,7 +128,6 @@
 hypervisor_match, hypervisor_attach, NULL, NULL);
 
 static int hypervisor_print(void *, const char *);
-static int hypervisor_vcpu_print(void *, const char *);
 
 union hypervisor_attach_cookie {
 	const char *hac_device;		/* first elem of all */
@@ -183,6 +182,15 @@
 	return 0;
 }
 
+#ifdef MULTIPROCESSOR
+static int
+hypervisor_vcpu_print(void *aux, const char *parent)
+{
+	/* Unconfigured cpus are ignored quietly. */
+	return (QUIET);
+}
+#endif /* MULTIPROCESSOR */
+
 /*
  * Attach the hypervisor.
  */
@@ -190,7 +198,6 @@
 hypervisor_attach(device_t parent, device_t self, void *aux)
 {
 	int xen_version;
-	cpuid_t vcpuid;
 
 #if NPCI 0
 #ifdef PCI_BUS_FIXUP
@@ -226,6 +233,7 @@
 	 * allocated vcpus (See: cpu.c:vcpu_match()) by iterating
 	 * through the maximum supported by NetBSD MP.
 	 */
+	cpuid_t vcpuid;
 
 	for (vcpuid = 1; vcpuid  maxcpus; vcpuid++) {
 		memset(hac, 0, sizeof(hac));
@@ -331,13 +339,6 @@
 	return (UNCONF);
 }
 
-static int
-hypervisor_vcpu_print(void *aux, const char *parent)
-{
-	/* Unconfigured cpus are ignored quietly. */
-	return (QUIET);
-}
-
 #if defined(DOM0OPS)
 
 #define DIR_MODE	(S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)



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

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

Modified Files:
src/sys/arch/xen/conf [cherry-xenmp]: files.xen

Log Message:
Conditionally compile xen_ipi.c


To generate a diff of this commit:
cvs rdiff -u -r1.118.2.2 -r1.118.2.3 src/sys/arch/xen/conf/files.xen

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/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.118.2.2 src/sys/arch/xen/conf/files.xen:1.118.2.3
--- src/sys/arch/xen/conf/files.xen:1.118.2.2	Thu Jun 23 14:19:49 2011
+++ src/sys/arch/xen/conf/files.xen	Mon Jun 27 10:21:52 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.118.2.2 2011/06/23 14:19:49 cherry Exp $
+#	$NetBSD: files.xen,v 1.118.2.3 2011/06/27 10:21:52 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -127,7 +127,7 @@
 file	arch/xen/x86/consinit.c
 file	arch/x86/x86/identcpu.c
 file	arch/xen/x86/intr.c
-file	arch/xen/x86/xen_ipi.c
+file	arch/xen/x86/xen_ipi.c		multiprocessor
 file	arch/x86/x86/pmap.c
 file	arch/x86/x86/pmap_tlb.c
 file	arch/x86/x86/procfs_machdep.c	procfs



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 m...@adviseo.fr
@@ -69,7 +69,7 @@
 
 
 #include sys/cdefs.h
-__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

2011-07-16 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Jul 16 10:59:46 UTC 2011

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

Log Message:
Introduce a per-cpu shadow for pmap_kernel()'s L4 page


To generate a diff of this commit:
cvs rdiff -u -r1.34.2.2 -r1.34.2.3 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.121.2.2 -r1.121.2.3 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.56.2.2 -r1.56.2.3 src/sys/arch/xen/x86/cpu.c
cvs rdiff -u -r1.26.2.3 -r1.26.2.4 src/sys/arch/xen/x86/x86_xpmap.c
cvs rdiff -u -r1.2.2.1 -r1.2.2.2 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/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.34.2.2 src/sys/arch/x86/include/cpu.h:1.34.2.3
--- src/sys/arch/x86/include/cpu.h:1.34.2.2	Thu Jun 23 14:19:48 2011
+++ src/sys/arch/x86/include/cpu.h	Sat Jul 16 10:59:45 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.34.2.2 2011/06/23 14:19:48 cherry Exp $	*/
+/*	$NetBSD: cpu.h,v 1.34.2.3 2011/07/16 10:59:45 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -184,6 +184,8 @@
 
 #if defined(XEN)  defined(__x86_64__)
 	/* Currently active user PGD (can't use rcr3() with Xen) */
+	pd_entry_t *	ci_kpm_pdir;	/* per-cpu L4 PD (va) */
+	paddr_t		ci_kpm_pdirpa; /* per-cpu L4 PD (pa) */
 	paddr_t		ci_xen_current_user_pgd;
 #endif
 
@@ -232,6 +234,11 @@
 	int		ci_padout __aligned(64);
 };
 
+#ifdef __x86_64__
+#define ci_pdirpa(ci, index) \
+	((ci)-ci_kpm_pdirpa + (index) * sizeof(pd_entry_t))
+#endif /* __x86_64__ */
+
 /*
  * Macros to handle (some) trapframe registers for common x86 code.
  */

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.121.2.2 src/sys/arch/x86/x86/pmap.c:1.121.2.3
--- src/sys/arch/x86/x86/pmap.c:1.121.2.2	Thu Jun 23 14:19:48 2011
+++ src/sys/arch/x86/x86/pmap.c	Sat Jul 16 10:59:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.121.2.2 2011/06/23 14:19:48 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.121.2.3 2011/07/16 10:59:46 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.121.2.2 2011/06/23 14:19:48 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.121.2.3 2011/07/16 10:59:46 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -778,7 +778,7 @@
 		ci-ci_tlbstate = TLBSTATE_VALID;
 		atomic_or_32(pmap-pm_cpus, cpumask);
 		atomic_or_32(pmap-pm_kernel_cpus, cpumask);
-		lcr3(pmap_pdirpa(pmap, 0));
+		cpu_load_pmap(pmap);
 	}
 	pmap-pm_ncsw = l-l_ncsw;
 	*pmap2 = curpmap;
@@ -1515,6 +1515,15 @@
 			break;
 		pdes_pa = newp;
 	}
+
+	/* sync to per-cpu PD */
+	xpq_queue_lock();
+	xpq_queue_pte_update(
+		xpmap_ptom_masked(ci_pdirpa(cpu_info_primary,
+	pl_i(0, PTP_LEVELS))),
+  pmap_kernel()-pm_pdir[pl_i(0, PTP_LEVELS)]);
+	xpq_queue_unlock();
+	pmap_pte_flush();
 #else /* XEN */
 	pd_entry_t *pdes;
 
@@ -1575,15 +1584,18 @@
 void
 pmap_cpu_init_late(struct cpu_info *ci)
 {
+	/*
+	 * The BP has already its own PD page allocated during early
+	 * MD startup.
+	 */
+	if (ci == cpu_info_primary)
+		return;
+
 #ifdef PAE
 	int ret;
 	struct pglist pg;
 	struct vm_page *vmap;
 
-	/* The BP has already its own L3 page allocated in locore.S. */
-	if (ci == cpu_info_primary)
-		return;
-
 	/*
 	 * Allocate a page for the per-CPU L3 PD. cr3 being 32 bits, PA musts
 	 * resides below the 4GB boundary.
@@ -1607,7 +1619,35 @@
 		VM_PROT_READ | VM_PROT_WRITE, 0);
 
 	pmap_update(pmap_kernel());
+
+	xpq_queue_lock();
+	xpq_queue_pin_l3_table(xpmap_ptom_masked(ci-ci_pae_l3_pdirpa));
+	xpq_queue_unlock();
 #endif
+#if defined(XEN)  defined (__x86_64)
+	KASSERT(ci != NULL);
+
+	ci-ci_kpm_pdir = (pd_entry_t *)uvm_km_alloc(kernel_map,
+		 PAGE_SIZE, 0, UVM_KMF_WIRED | UVM_KMF_ZERO | UVM_KMF_NOWAIT);
+	if (ci-ci_kpm_pdir == NULL) {
+		panic(%s: failed to allocate L4 per-cpu PD for CPU %d\n,
+		  __func__, cpu_index(ci));
+	}
+	ci-ci_kpm_pdirpa = vtophys((vaddr_t) ci-ci_kpm_pdir);
+	KASSERT(ci-ci_kpm_pdirpa != 0);
+
+	cpu_load_pmap(pmap_kernel());
+
+	pmap_kenter_pa((vaddr_t)ci-ci_kpm_pdir, ci-ci_kpm_pdirpa,
+		VM_PROT_READ, 0);
+
+	pmap_update(pmap_kernel());
+
+	xpq_queue_lock();
+	xpq_queue_pin_l4_table(xpmap_ptom_masked(ci-ci_kpm_pdirpa));
+	xpq_queue_unlock();
+
+#endif /* defined(XEN)  defined (__x86_64__) */
 }
 
 /*
@@ -1825,8 +1865,24 @@
 		 * clear it before freeing
 		 */
 		if (pmap_pdirpa(pmap, 0) == curcpu()-ci_xen_current_user_pgd
-		 level == PTP_LEVELS - 1)
+		 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 
+			 */ 
+			CPU_INFO_ITERATOR cii;
+			

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

2011-07-23 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Jul 23 09:21:53 UTC 2011

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

Log Message:
Remove the bogus TLB ipi wrapper code. We don't use it in xen anyway.
This syncs back, with -current.


To generate a diff of this commit:
cvs rdiff -u -r1.18.6.1 -r1.18.6.2 src/sys/arch/x86/x86/ipi.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/ipi.c
diff -u src/sys/arch/x86/x86/ipi.c:1.18.6.1 src/sys/arch/x86/x86/ipi.c:1.18.6.2
--- src/sys/arch/x86/x86/ipi.c:1.18.6.1	Fri Jun  3 13:27:39 2011
+++ src/sys/arch/x86/x86/ipi.c	Sat Jul 23 09:21:52 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipi.c,v 1.18.6.1 2011/06/03 13:27:39 cherry Exp $	*/
+/*	$NetBSD: ipi.c,v 1.18.6.2 2011/07/23 09:21:52 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2008, 2009 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ipi.c,v 1.18.6.1 2011/06/03 13:27:39 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: ipi.c,v 1.18.6.2 2011/07/23 09:21:52 cherry Exp $);
 
 #include opt_mtrr.h
 
@@ -107,16 +107,6 @@
 x86_send_ipi(struct cpu_info *ci, int ipimask)
 {
 	int ret;
-	
-	KASSERT(ci != NULL);
-
-	if (ipimask  X86_IPI_TLB) { 	/* Wrapper for TLB event */
-		KASSERT(ipimask == X86_IPI_TLB);
-
-		ret = x86_ipi(LAPIC_TLB_MCAST_VECTOR,
-			  ci-ci_cpuid, LAPIC_DLMODE_FIXED);		
-		return ret;
-	}
 
 	atomic_or_32(ci-ci_ipis, ipimask);
 
@@ -142,15 +132,6 @@
 	int count = 0;
 	CPU_INFO_ITERATOR cii;
 
-	if (ipimask  X86_IPI_TLB) { 	/* Wrapper for TLB event */
-		KASSERT(ipimask == X86_IPI_TLB);
-
-		if (x86_ipi(LAPIC_TLB_BCAST_VECTOR, LAPIC_DEST_ALLEXCL,
-			LAPIC_DLMODE_FIXED)) {
-			panic(x86_ipi() failed on Broadcast via lapic.\n);
-		}
-	}
-
 	for (CPU_INFO_FOREACH(cii, ci)) {
 		if (ci == self)
 			continue;



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

2011-07-25 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jul 25 17:29:43 UTC 2011

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

Log Message:
Do not register the same callback more than once.


To generate a diff of this commit:
cvs rdiff -u -r1.54.6.1 -r1.54.6.2 src/sys/arch/xen/xen/clock.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/xen/clock.c
diff -u src/sys/arch/xen/xen/clock.c:1.54.6.1 src/sys/arch/xen/xen/clock.c:1.54.6.2
--- src/sys/arch/xen/xen/clock.c:1.54.6.1	Fri Jun  3 13:27:42 2011
+++ src/sys/arch/xen/xen/clock.c	Mon Jul 25 17:29:43 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.54.6.1 2011/06/03 13:27:42 cherry Exp $	*/
+/*	$NetBSD: clock.c,v 1.54.6.2 2011/07/25 17:29:43 cherry Exp $	*/
 
 /*
  *
@@ -29,7 +29,7 @@
 #include opt_xen.h
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.1 2011/06/03 13:27:42 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.2 2011/07/25 17:29:43 cherry Exp $);
 
 #include sys/param.h
 #include sys/cpu.h
@@ -452,7 +452,9 @@
 			 hardclock);
 
 #ifdef DOM0OPS
-	callout_init(xen_timepush_co, 0);
+	if (!tcdone) { /* Do this only once */
+		callout_init(xen_timepush_co, 0);
+	}
 #endif
 	evtch = bind_virq_to_evtch(VIRQ_TIMER);
 	aprint_verbose(Xen clock: using event channel %d\n, evtch);



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

2011-07-31 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Jul 31 20:49:12 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64 [cherry-xenmp]: db_interface.c
src/sys/arch/i386/i386 [cherry-xenmp]: db_interface.c gdt.c machdep.c
src/sys/arch/i386/include [cherry-xenmp]: intrdefs.h pmap.h
src/sys/arch/i386/isa [cherry-xenmp]: npx.c
src/sys/arch/x86/x86 [cherry-xenmp]: pmap.c pmap_tlb.c
src/sys/arch/xen/conf [cherry-xenmp]: std.xen
src/sys/arch/xen/x86 [cherry-xenmp]: cpu.c x86_xpmap.c xen_ipi.c
xenfunc.c

Log Message:
grow MP support for i386. boots to single user


To generate a diff of this commit:
cvs rdiff -u -r1.23.2.1 -r1.23.2.2 src/sys/arch/amd64/amd64/db_interface.c
cvs rdiff -u -r1.66 -r1.66.2.1 src/sys/arch/i386/i386/db_interface.c
cvs rdiff -u -r1.50 -r1.50.10.1 src/sys/arch/i386/i386/gdt.c
cvs rdiff -u -r1.702.2.1 -r1.702.2.2 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.3 -r1.3.140.1 src/sys/arch/i386/include/intrdefs.h
cvs rdiff -u -r1.109 -r1.109.2.1 src/sys/arch/i386/include/pmap.h
cvs rdiff -u -r1.139.6.1 -r1.139.6.2 src/sys/arch/i386/isa/npx.c
cvs rdiff -u -r1.121.2.3 -r1.121.2.4 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.3.2.2 -r1.3.2.3 src/sys/arch/x86/x86/pmap_tlb.c
cvs rdiff -u -r1.6 -r1.6.12.1 src/sys/arch/xen/conf/std.xen
cvs rdiff -u -r1.56.2.3 -r1.56.2.4 src/sys/arch/xen/x86/cpu.c
cvs rdiff -u -r1.26.2.4 -r1.26.2.5 src/sys/arch/xen/x86/x86_xpmap.c
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/arch/xen/x86/xen_ipi.c
cvs rdiff -u -r1.11.6.1 -r1.11.6.2 src/sys/arch/xen/x86/xenfunc.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/amd64/amd64/db_interface.c
diff -u src/sys/arch/amd64/amd64/db_interface.c:1.23.2.1 src/sys/arch/amd64/amd64/db_interface.c:1.23.2.2
--- src/sys/arch/amd64/amd64/db_interface.c:1.23.2.1	Fri Jun  3 13:27:37 2011
+++ src/sys/arch/amd64/amd64/db_interface.c	Sun Jul 31 20:49:10 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_interface.c,v 1.23.2.1 2011/06/03 13:27:37 cherry Exp $	*/
+/*	$NetBSD: db_interface.c,v 1.23.2.2 2011/07/31 20:49:10 cherry Exp $	*/
 
 /*
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: db_interface.c,v 1.23.2.1 2011/06/03 13:27:37 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: db_interface.c,v 1.23.2.2 2011/07/31 20:49:10 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -82,7 +82,9 @@
 #ifdef MULTIPROCESSOR
 extern void ddb_ipi(struct trapframe);
 static void ddb_suspend(struct trapframe *);
+#ifndef XEN
 int ddb_vec;
+#endif /* XEN */
 static bool ddb_mp_online;
 #endif
 

Index: src/sys/arch/i386/i386/db_interface.c
diff -u src/sys/arch/i386/i386/db_interface.c:1.66 src/sys/arch/i386/i386/db_interface.c:1.66.2.1
--- src/sys/arch/i386/i386/db_interface.c:1.66	Sun Apr  3 22:29:26 2011
+++ src/sys/arch/i386/i386/db_interface.c	Sun Jul 31 20:49:10 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_interface.c,v 1.66 2011/04/03 22:29:26 dyoung Exp $	*/
+/*	$NetBSD: db_interface.c,v 1.66.2.1 2011/07/31 20:49:10 cherry Exp $	*/
 
 /*
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: db_interface.c,v 1.66 2011/04/03 22:29:26 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: db_interface.c,v 1.66.2.1 2011/07/31 20:49:10 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -86,7 +86,9 @@
 extern void ddb_ipi(int, struct trapframe);
 extern void ddb_ipi_tss(struct i386tss *);
 static void ddb_suspend(struct trapframe *);
+#ifndef XEN
 int ddb_vec;
+#endif /* XEN */
 static bool ddb_mp_online;
 #endif
 
@@ -104,8 +106,12 @@
 {
 
 #ifdef MULTIPROCESSOR
+#ifndef XEN
 	ddb_vec = idt_vec_alloc(0xf0, 0xff);
 	idt_vec_set(ddb_vec, Xintrddbipi);
+#else
+	/* Initialised as part of xen_ipi_init() */
+#endif /* XEN */
 #endif
 }
 
@@ -119,8 +125,10 @@
 	int cpu_me = cpu_number();
 	int win;
 
+#ifndef XEN
 	if (ddb_vec == 0)
 		return 1;
+#endif /* XEN */
 
 	__cpu_simple_lock(db_lock);
 	if (ddb_cpu == NOCPU)
@@ -128,7 +136,11 @@
 	win = (ddb_cpu == cpu_me);
 	__cpu_simple_unlock(db_lock);
 	if (win) {
+#ifdef XEN
+		xen_broadcast_ipi(XEN_IPI_DDB);
+#else
 		x86_ipi(ddb_vec, LAPIC_DEST_ALLEXCL, LAPIC_DLMODE_FIXED);
+#endif /* XEN */
 	}
 	ddb_mp_online = x86_mp_online;
 	x86_mp_online = false;

Index: src/sys/arch/i386/i386/gdt.c
diff -u src/sys/arch/i386/i386/gdt.c:1.50 src/sys/arch/i386/i386/gdt.c:1.50.10.1
--- src/sys/arch/i386/i386/gdt.c:1.50	Sat Nov 21 03:11:00 2009
+++ src/sys/arch/i386/i386/gdt.c	Sun Jul 31 20:49:10 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gdt.c,v 1.50 2009/11/21 03:11:00 rmind Exp $	*/
+/*	$NetBSD: gdt.c,v 1.50.10.1 2011/07/31 20:49:10 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gdt.c,v 1.50 2009/11/21 03:11:00 rmind Exp $);
+__KERNEL_RCSID(0, 

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

2011-07-31 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Jul 31 20:55:22 UTC 2011

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

Log Message:
Oops. remove spurious #undef MULTIPROCESSOR


To generate a diff of this commit:
cvs rdiff -u -r1.3.2.3 -r1.3.2.4 src/sys/arch/x86/x86/pmap_tlb.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_tlb.c
diff -u src/sys/arch/x86/x86/pmap_tlb.c:1.3.2.3 src/sys/arch/x86/x86/pmap_tlb.c:1.3.2.4
--- src/sys/arch/x86/x86/pmap_tlb.c:1.3.2.3	Sun Jul 31 20:49:11 2011
+++ src/sys/arch/x86/x86/pmap_tlb.c	Sun Jul 31 20:55:22 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.3.2.3 2011/07/31 20:49:11 cherry Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.3.2.4 2011/07/31 20:55:22 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2008-2011 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pmap_tlb.c,v 1.3.2.3 2011/07/31 20:49:11 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap_tlb.c,v 1.3.2.4 2011/07/31 20:55:22 cherry Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -57,7 +57,7 @@
 #endif /* XEN */
 #include x86/i82489reg.h
 #include x86/i82489var.h
-#undef MULTIPROCESSOR
+
 /*
  * TLB shootdown structures.
  */



CVS commit: src/sys/arch

2010-07-06 Thread Cherry G. Mathew
/xenbus_probe.c
diff -u src/sys/arch/xen/xenbus/xenbus_probe.c:1.27 src/sys/arch/xen/xenbus/xenbus_probe.c:1.28
--- src/sys/arch/xen/xenbus/xenbus_probe.c:1.27	Fri Jan  9 22:26:25 2009
+++ src/sys/arch/xen/xenbus/xenbus_probe.c	Tue Jul  6 15:00:10 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_probe.c,v 1.27 2009/01/09 22:26:25 jym Exp $ */
+/* $NetBSD: xenbus_probe.c,v 1.28 2010/07/06 15:00:10 cherry Exp $ */
 /**
  * Talks to Xen Store to figure out what devices we have.
  *
@@ -29,7 +29,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: xenbus_probe.c,v 1.27 2009/01/09 22:26:25 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: xenbus_probe.c,v 1.28 2010/07/06 15:00:10 cherry Exp $);
 
 #if 0
 #define DPRINTK(fmt, args...) \
@@ -55,6 +55,10 @@
 #include xen/evtchn.h
 #include xen/shutdown_xenbus.h
 
+#ifdef XEN_BALLOON
+#include xen/balloon.h
+#endif
+
 #include xenbus_comms.h
 
 extern struct semaphore xenwatch_mutex;
@@ -514,6 +518,10 @@
 	register_xenbus_watch(be_watch);
 	shutdown_xenbus_setup();
 
+#ifdef XEN_BALLOON
+	balloon_xenbus_setup();
+#endif
+
 	/* Notify others that xenstore is up */
 	//notifier_call_chain(xenstore_chain, 0, NULL);
 }

Added files:

Index: src/sys/arch/xen/include/balloon.h
diff -u /dev/null src/sys/arch/xen/include/balloon.h:1.1
--- /dev/null	Tue Jul  6 15:00:10 2010
+++ src/sys/arch/xen/include/balloon.h	Tue Jul  6 15:00:09 2010
@@ -0,0 +1,37 @@
+/* $NetBSD: balloon.h,v 1.1 2010/07/06 15:00:09 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Cherry G. Mathew che...@zyx.in 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _XEN_BALLOON_H
+#define _XEN_BALLOON_H
+
+void balloon_xenbus_setup(void);
+
+#endif /* _XEN_BALLOON_H */

Index: src/sys/arch/xen/xen/balloon.c
diff -u /dev/null src/sys/arch/xen/xen/balloon.c:1.1
--- /dev/null	Tue Jul  6 15:00:10 2010
+++ src/sys/arch/xen/xen/balloon.c	Tue Jul  6 15:00:09 2010
@@ -0,0 +1,877 @@
+/* $NetBSD: balloon.c,v 1.1 2010/07/06 15:00:09 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Cherry G. Mathew che...@zyx.in and
+ * Jean-Yves Migeon j...@netbsd.org 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED

CVS commit: src/sys/arch/xen/xen

2010-07-08 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Jul  8 14:19:53 UTC 2010

Modified Files:
src/sys/arch/xen/xen: balloon.c

Log Message:
make read-only, and return sane values in balloon related sysctl(7)
nodes when  'options XEN_BALLOON' is disabled.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/xen/xen/balloon.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/xen/balloon.c
diff -u src/sys/arch/xen/xen/balloon.c:1.1 src/sys/arch/xen/xen/balloon.c:1.2
--- src/sys/arch/xen/xen/balloon.c:1.1	Tue Jul  6 15:00:09 2010
+++ src/sys/arch/xen/xen/balloon.c	Thu Jul  8 14:19:53 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: balloon.c,v 1.1 2010/07/06 15:00:09 cherry Exp $ */
+/* $NetBSD: balloon.c,v 1.2 2010/07/08 14:19:53 cherry Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: balloon.c,v 1.1 2010/07/06 15:00:09 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: balloon.c,v 1.2 2010/07/08 14:19:53 cherry Exp $);
 
 #include sys/inttypes.h
 #include sys/param.h
@@ -782,7 +782,17 @@
 		node_val = xenmem_get_currentreservation();
 		node.sysctl_data = node_val;
 		return sysctl_lookup(SYSCTLFN_CALL(node));
-
+#ifndef XEN_BALLOON /* Read only, if balloon is disabled */
+	} else if (strcmp(node.sysctl_name, target) == 0) {
+		if (newp != NULL || newlen != 0) {
+			return (EPERM);
+		}
+		node_val = xenmem_get_currentreservation();
+		node.sysctl_data = node_val;
+		error = sysctl_lookup(SYSCTLFN_CALL(node));
+		return error;
+	}
+#else
 	} else if (strcmp(node.sysctl_name, target) == 0) {
 		node_val = * (int64_t *) rnode-sysctl_data;
 		node.sysctl_data = node_val;
@@ -826,6 +836,7 @@
 
 		return 0;
 	}
+#endif /* XEN_BALLOON */
 
 	return EINVAL;
 }



CVS commit: src/sys/arch/xen/xen

2010-07-08 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Jul  8 14:51:14 UTC 2010

Modified Files:
src/sys/arch/xen/xen: balloon.c

Log Message:
Provide the sysctl(7) interface to the balloon driver only to dom0


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/xen/xen/balloon.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/xen/balloon.c
diff -u src/sys/arch/xen/xen/balloon.c:1.2 src/sys/arch/xen/xen/balloon.c:1.3
--- src/sys/arch/xen/xen/balloon.c:1.2	Thu Jul  8 14:19:53 2010
+++ src/sys/arch/xen/xen/balloon.c	Thu Jul  8 14:51:14 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: balloon.c,v 1.2 2010/07/08 14:19:53 cherry Exp $ */
+/* $NetBSD: balloon.c,v 1.3 2010/07/08 14:51:14 cherry Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: balloon.c,v 1.2 2010/07/08 14:19:53 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: balloon.c,v 1.3 2010/07/08 14:51:14 cherry Exp $);
 
 #include sys/inttypes.h
 #include sys/param.h
@@ -755,6 +755,7 @@
 
 }
 
+#if DOM0OPS
 
 /* 
  * sysctl(9) stuff 
@@ -886,3 +887,5 @@
 	sysctl_kern_xen_balloon, 0, sysctl_target, 0,
 	CTL_CREATE, CTL_EOL);
 }
+
+#endif /* DOM0OPS */



CVS commit: src/sys/arch/xen/xen

2010-07-10 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Jul 10 11:20:49 UTC 2010

Modified Files:
src/sys/arch/xen/xen: balloon.c

Log Message:
Provide and accept memory reservation information from the hypervisor
in KiloBytes. This is valid both for the xenbus interface, as well as
the dom0 only sysctl interface.

Thanks cegger@ for testing.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/xen/xen/balloon.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/xen/balloon.c
diff -u src/sys/arch/xen/xen/balloon.c:1.3 src/sys/arch/xen/xen/balloon.c:1.4
--- src/sys/arch/xen/xen/balloon.c:1.3	Thu Jul  8 14:51:14 2010
+++ src/sys/arch/xen/xen/balloon.c	Sat Jul 10 11:20:48 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: balloon.c,v 1.3 2010/07/08 14:51:14 cherry Exp $ */
+/* $NetBSD: balloon.c,v 1.4 2010/07/10 11:20:48 cherry Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: balloon.c,v 1.3 2010/07/08 14:51:14 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: balloon.c,v 1.4 2010/07/10 11:20:48 cherry Exp $);
 
 #include sys/inttypes.h
 #include sys/param.h
@@ -91,6 +91,11 @@
 #define XEN_RESERVATION_MIN (uvmexp.freemin + BALLOON_BALLAST) /* In pages */
 #define XEN_RESERVATION_MAX nkmempages /* In pages */
 
+/* KB - PAGEs */
+#define BALLOON_PAGES_TO_KB(_pg) (_pg * PAGE_SIZE / 1024)
+#define BALLOON_KB_TO_PAGES(_kb) (_kb * 1024 / PAGE_SIZE)
+#define BALLOON_PAGE_FLOOR(_kb) (_kb  PAGE_MASK)
+
 /* Forward declaration */
 static void xenbus_balloon_watcher(struct xenbus_watch *, const char **,
    unsigned int);
@@ -193,18 +198,16 @@
 		return 0;
 	}
 
-	/* Convert to npages */
+	/* Returned in KB */
 
-	return new_target * 1024 / PAGE_SIZE;
+	return new_target;
 }
 
 static void
 xenbus_balloon_write_target(unsigned long long new_target)
 {
 
-	/* Convert to KB */
-	new_target = new_target * PAGE_SIZE / 1024;
-
+	/* new_target is in KB */
 	if (0 != xenbus_printf(NULL, memory, target, %llu, new_target)) {
 		printf(error, couldn't write xenbus target node\n);
 	}
@@ -247,9 +250,9 @@
 balloon_feedback_target(size_t newtarget)
 {
 	/* Notify XenStore. */
-	xenbus_balloon_write_target(newtarget);
+	xenbus_balloon_write_target(BALLOON_PAGES_TO_KB(newtarget));
 	/* Update sysctl value XXX: Locking ? */
-	sysctl_target = newtarget;
+	sysctl_target = BALLOON_PAGES_TO_KB(newtarget);
 
 	/* Finally update our private copy */
 	balloon_set_target(newtarget);
@@ -651,15 +654,18 @@
 xenbus_balloon_watcher(struct xenbus_watch *watch, const char **vec,
 		   unsigned int len)
 {
-	size_t new_target;
+	size_t new_target; /* In KB */
 
 	if (0 == (new_target = (size_t) xenbus_balloon_read_target())) {
 		/* Don't update target value */
 		return;
 	}
+
+	new_target = BALLOON_PAGE_FLOOR(new_target);
+
 #if BALLOONDEBUG 
-	if (new_target  balloon_conf.xen_res_min ||
-	new_target  balloon_conf.xen_res_max) {
+	if (new_target  BALLOON_KB_TO_PAGES(balloon_conf.xen_res_min) ||
+	new_target  BALLOON_KB_TO_PAGES(balloon_conf.xen_res_max)) {
 		printf(Requested target is unacceptable.\n);
 		return;
 	}
@@ -669,7 +675,7 @@
 	 * balloon_set_target() calls
 	 * xenbus_balloon_write_target(). Not sure if this is racy 
 	 */
-	balloon_set_target(new_target);
+	balloon_set_target(BALLOON_KB_TO_PAGES(new_target));
 
 #if BALLOONDEBUG
 	printf(Setting target to %zu\n, new_target);
@@ -727,7 +733,8 @@
 	 * Initialise the sysctl_xxx copies of target and current
 	 * as above, because sysctl inits before balloon_xenbus_setup()
 	 */
-	sysctl_target = sysctl_current = currentpages;
+	sysctl_current = currentpages;
+	sysctl_target = BALLOON_PAGES_TO_KB(currentpages);
 
 	/* Setup xenbus node watch callback */
 	if (register_xenbus_watch(xenbus_balloon_watch)) {
@@ -780,7 +787,7 @@
 	node = *rnode;
 
 	if (strcmp(node.sysctl_name, current) == 0) {
-		node_val = xenmem_get_currentreservation();
+		node_val = BALLOON_PAGES_TO_KB(xenmem_get_currentreservation());
 		node.sysctl_data = node_val;
 		return sysctl_lookup(SYSCTLFN_CALL(node));
 #ifndef XEN_BALLOON /* Read only, if balloon is disabled */
@@ -788,7 +795,7 @@
 		if (newp != NULL || newlen != 0) {
 			return (EPERM);
 		}
-		node_val = xenmem_get_currentreservation();
+		node_val = BALLOON_PAGES_TO_KB(xenmem_get_currentreservation());
 		node.sysctl_data = node_val;
 		error = sysctl_lookup(SYSCTLFN_CALL(node));
 		return error;
@@ -796,6 +803,7 @@
 #else
 	} else if (strcmp(node.sysctl_name, target) == 0) {
 		node_val = * (int64_t *) rnode-sysctl_data;
+		node_val = BALLOON_PAGE_FLOOR(node_val);
 		node.sysctl_data = node_val;
 		error = sysctl_lookup(SYSCTLFN_CALL(node));
 		if (error != 0) {
@@ -803,8 +811,8 @@
 		}
 
 		/* Sanity check new size */
-		if (node_val  XEN_RESERVATION_MIN || 
-   		node_val  XEN_RESERVATION_MAX ) {
+		if (node_val  

CVS commit: src/sys/arch/amd64/amd64

2011-03-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Mar  7 02:24:57 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: fpu.c

Log Message:
Use macros clts/stts instead of directly manipulating CR0 flags.
Expose fpuinit to XEN build. (remove #ifdef XEN)


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/amd64/amd64/fpu.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/amd64/amd64/fpu.c
diff -u src/sys/arch/amd64/amd64/fpu.c:1.33 src/sys/arch/amd64/amd64/fpu.c:1.34
--- src/sys/arch/amd64/amd64/fpu.c:1.33	Mon Dec 20 00:25:24 2010
+++ src/sys/arch/amd64/amd64/fpu.c	Mon Mar  7 02:24:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.33 2010/12/20 00:25:24 matt Exp $	*/
+/*	$NetBSD: fpu.c,v 1.34 2011/03/07 02:24:57 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -100,7 +100,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: fpu.c,v 1.33 2010/12/20 00:25:24 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: fpu.c,v 1.34 2011/03/07 02:24:57 cherry Exp $);
 
 #include opt_multiprocessor.h
 
@@ -155,18 +155,16 @@
 void fpudna(struct cpu_info *);
 static int x86fpflags_to_ksiginfo(uint32_t);
 
-#ifndef XEN
 /*
  * Init the FPU.
  */
 void
 fpuinit(struct cpu_info *ci)
 {
-	lcr0(rcr0()  ~(CR0_EM|CR0_TS));
+	clts();
 	fninit();
-	lcr0(rcr0() | (CR0_TS));
+	stts();
 }
-#endif
 
 /*
  * Record the FPU state and reinitialize it all except for the control word.



CVS commit: src/sys/arch/i386/i386

2012-01-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Jan 12 19:37:46 UTC 2012

Modified Files:
src/sys/arch/i386/i386: machdep.c

Log Message:
re-order call to x86_bus_space_init() until after %fs is initialised via 
initgdt().

x86_bus_space_init() uses mutex(9) since it uses extent(9), which requires %fs 
to be setup before use.


To generate a diff of this commit:
cvs rdiff -u -r1.715 -r1.716 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.715 src/sys/arch/i386/i386/machdep.c:1.716
--- src/sys/arch/i386/i386/machdep.c:1.715	Fri Dec 30 17:57:49 2011
+++ src/sys/arch/i386/i386/machdep.c	Thu Jan 12 19:37:45 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.715 2011/12/30 17:57:49 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.716 2012/01/12 19:37:45 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.715 2011/12/30 17:57:49 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.716 2012/01/12 19:37:45 cherry Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -1354,9 +1354,6 @@ init386(paddr_t first_avail)
 	cpu_info_primary.ci_pae_l3_pdir = (pd_entry_t *)(rcr3() + KERNBASE);
 #endif /* PAE  !XEN */
 
-#if NISA  0 || NPCI  0
-	x86_bus_space_init();
-#endif
 #ifdef XEN
 	xen_parse_cmdline(XEN_PARSE_BOOTFLAGS, NULL);
 #endif
@@ -1412,6 +1409,11 @@ init386(paddr_t first_avail)
 	 */
 	initgdt(NULL);
 #endif /* XEN */
+
+#if NISA  0 || NPCI  0
+	x86_bus_space_init();
+#endif /* NISA  0 || NPCI  0 */
+	
 	consinit();	/* XXX SHOULD NOT BE DONE HERE */
 
 #ifdef DEBUG_MEMLOAD



CVS commit: src/sys/arch

2012-01-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Jan 12 19:49:37 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: machdep.c
src/sys/arch/i386/i386: machdep.c
src/sys/arch/xen/x86: x86_xpmap.c

Log Message:
relocate pte_lock initialisation to the earliest points after %fs is first 
usable in the XEN bootpath


To generate a diff of this commit:
cvs rdiff -u -r1.173 -r1.174 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.716 -r1.717 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.37 -r1.38 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/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.173 src/sys/arch/amd64/amd64/machdep.c:1.174
--- src/sys/arch/amd64/amd64/machdep.c:1.173	Mon Dec 12 19:03:08 2011
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Jan 12 19:49:37 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.173 2011/12/12 19:03:08 mrg Exp $	*/
+/*	$NetBSD: machdep.c,v 1.174 2012/01/12 19:49:37 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.173 2011/12/12 19:03:08 mrg Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.174 2012/01/12 19:49:37 cherry Exp $);
 
 /* #define XENDEBUG_LOW  */
 
@@ -1640,6 +1640,7 @@ init_x86_64(paddr_t first_avail)
 	use_pae = 1; /* PAE always enabled in long mode */
 
 #ifdef XEN
+	mutex_init(pte_lock, MUTEX_DEFAULT, IPL_VM);
 	pcb-pcb_cr3 = xen_start_info.pt_base - KERNBASE;
 	__PRINTK((pcb_cr3 0x%lx\n, xen_start_info.pt_base - KERNBASE));
 #endif

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.716 src/sys/arch/i386/i386/machdep.c:1.717
--- src/sys/arch/i386/i386/machdep.c:1.716	Thu Jan 12 19:37:45 2012
+++ src/sys/arch/i386/i386/machdep.c	Thu Jan 12 19:49:37 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.716 2012/01/12 19:37:45 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.717 2012/01/12 19:49:37 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.716 2012/01/12 19:37:45 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.717 2012/01/12 19:49:37 cherry Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -1408,6 +1408,8 @@ init386(paddr_t first_avail)
 	 * before the above variables are set.
 	 */
 	initgdt(NULL);
+
+	mutex_init(pte_lock, MUTEX_DEFAULT, IPL_VM);
 #endif /* XEN */
 
 #if NISA  0 || NPCI  0

Index: src/sys/arch/xen/x86/x86_xpmap.c
diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.37 src/sys/arch/xen/x86/x86_xpmap.c:1.38
--- src/sys/arch/xen/x86/x86_xpmap.c:1.37	Mon Jan  9 13:04:13 2012
+++ src/sys/arch/xen/x86/x86_xpmap.c	Thu Jan 12 19:49:37 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.37 2012/01/09 13:04:13 cherry Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.38 2012/01/12 19:49:37 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert m...@adviseo.fr
@@ -69,7 +69,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.37 2012/01/09 13:04:13 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.38 2012/01/12 19:49:37 cherry Exp $);
 
 #include opt_xen.h
 #include opt_ddb.h
@@ -77,7 +77,7 @@ __KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,
 
 #include sys/param.h
 #include sys/systm.h
-#include sys/simplelock.h
+#include sys/mutex.h
 
 #include uvm/uvm.h
 
@@ -653,8 +653,6 @@ bootstrap_again:
 	/* Finally, flush TLB. */
 	xpq_queue_tlb_flush();
 
-	mutex_init(pte_lock, MUTEX_DEFAULT, IPL_VM);
-	
 	return (init_tables + ((count + l2_4_count) * PAGE_SIZE));
 }
 



CVS commit: src/doc

2012-01-13 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Jan 13 08:54:00 UTC 2012

Modified Files:
src/doc: BRANCHES

Log Message:
Officially terminate the cherry-xenmp branch.


To generate a diff of this commit:
cvs rdiff -u -r1.318 -r1.319 src/doc/BRANCHES

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

Modified files:

Index: src/doc/BRANCHES
diff -u src/doc/BRANCHES:1.318 src/doc/BRANCHES:1.319
--- src/doc/BRANCHES:1.318	Wed Jan  4 16:36:49 2012
+++ src/doc/BRANCHES	Fri Jan 13 08:54:00 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: BRANCHES,v 1.318 2012/01/04 16:36:49 yamt Exp $
+#	$NetBSD: BRANCHES,v 1.319 2012/01/13 08:54:00 cherry Exp $
 #
 # This file contains a list of branches that exist in the NetBSD CVS
 # tree and their current state.
@@ -287,13 +287,13 @@ Notes:		This code was on a branch becaus
 
 Branch:		cherry-xenmp
 Description:	Port i386 and amd64 Xen kernels to run MP
-Status:		Active
+Status:		Terminated
 Start Date:	1st June 2011
-End Date:
+End Date:	13th January 2012
 Base Tag:	cherry-xenmp-base
 Maintainer:	Cherry G. Mathew che...@netbsd.org
 Scope:		kernel
-Notes:
+Notes:		None
 
 Branch:		chris-arm-intr-rework
 Description:	Rework arm interrupt handling code



CVS commit: src/sys/arch/amd64/include

2012-01-15 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Jan 15 16:48:31 UTC 2012

Modified Files:
src/sys/arch/amd64/include: pmap.h

Log Message:
for xen on amd64 PDP_BASE points to the per-cpu ci-ci_kpm_pdir copy of 
*pmap_kernel()*'s L4 pdir, which is an alias for ci-ci_kpm_pdir. This is 
unlike PAE, where PDP_BASE points to the per-pmap pm_pdir consisting of 4 
pages, the last of which is the shadow. This shadow is not used directly in 
an active pmap, since it duplicates the kernel space and, for PAE, xen 
dissallows multiple cpus pointing to the same L3[3] page. Therefore, we use a 
per-cpu copy of the pmap_kernel() pdir's L3[3] page, ci-ci_pae_l3_pdir[3], 
while L3[0-2] point to the original pmap's pm_pdir[0 - 2]. Thus the shadow 
pdir only exists on i386 PAE. Note that on PAE, the recursive PDIR_SLOT_PTE is 
not per-cpu, and therefore cannot be made to point to per-cpu pdirs via 
(L4_BASE + PDIR_SLOT_PTE), unlike xen x86_64 where this is exactly the case.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/amd64/include/pmap.h

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/amd64/include/pmap.h
diff -u src/sys/arch/amd64/include/pmap.h:1.29 src/sys/arch/amd64/include/pmap.h:1.30
--- src/sys/arch/amd64/include/pmap.h:1.29	Mon Jan  9 13:04:13 2012
+++ src/sys/arch/amd64/include/pmap.h	Sun Jan 15 16:48:31 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.29 2012/01/09 13:04:13 cherry Exp $	*/
+/*	$NetBSD: pmap.h,v 1.30 2012/01/15 16:48:31 cherry Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -193,7 +193,6 @@
 
 #define PDP_PDE		(L4_BASE + PDIR_SLOT_PTE)
 #define APDP_PDE	(curcpu()-ci_kpm_pdir[PDIR_SLOT_APTE])
-#define APDP_PDE_SHADOW	(L4_BASE + PDIR_SLOT_APTE)
 
 #define PDP_BASE	L4_BASE
 #define APDP_BASE	AL4_BASE



CVS commit: src/sys/arch

2012-01-22 Thread Cherry G. Mathew
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();



CVS commit: src/sys/arch/x86/x86

2012-01-28 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Jan 28 08:57:09 UTC 2012

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

Log Message:
Fix pae xen build.


To generate a diff of this commit:
cvs rdiff -u -r1.156 -r1.157 src/sys/arch/x86/x86/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.156 src/sys/arch/x86/x86/pmap.c:1.157
--- src/sys/arch/x86/x86/pmap.c:1.156	Sat Jan 28 07:19:17 2012
+++ src/sys/arch/x86/x86/pmap.c	Sat Jan 28 08:57:09 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.156 2012/01/28 07:19:17 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.157 2012/01/28 08:57:09 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.156 2012/01/28 07:19:17 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.157 2012/01/28 08:57:09 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -795,13 +795,13 @@ pmap_map_ptes(struct pmap *pmap, struct 
 	pmap-pm_ncsw = l-l_ncsw;
 	*pmap2 = curpmap;
 	*ptepp = PTE_BASE;
-#ifdef XEN
+#if defined(XEN)  defined(__x86_64__)
 	KASSERT(ci-ci_normal_pdes[PTP_LEVELS - 2] == L4_BASE);
 	ci-ci_normal_pdes[PTP_LEVELS - 2] = pmap-pm_pdir;
 	*pdeppp = ci-ci_normal_pdes;
-#else /* XEN */
+#else /* XEN  __x86_64__ */
 	*pdeppp = normal_pdes;
-#endif /* XEN */
+#endif /* XEN  __x86_64__ */
 }
 
 /*



CVS commit: src/sys/arch/xen/x86

2012-01-28 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Jan 28 12:15:19 UTC 2012

Modified Files:
src/sys/arch/xen/x86: cpu.c

Log Message:
Update comments to remove references to alternate pte space.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 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.78 src/sys/arch/xen/x86/cpu.c:1.79
--- src/sys/arch/xen/x86/cpu.c:1.78	Sat Jan 28 07:19:17 2012
+++ src/sys/arch/xen/x86/cpu.c	Sat Jan 28 12:15:19 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.78 2012/01/28 07:19:17 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.79 2012/01/28 12:15:19 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.78 2012/01/28 07:19:17 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.79 2012/01/28 12:15:19 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1244,16 +1244,9 @@ cpu_load_pmap(struct pmap *pmap)
   * 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 recurseive mappings point to themselves on __x86_64__
   * - 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



CVS commit: src/sys/arch/x86/x86

2012-01-29 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Jan 29 11:37:08 UTC 2012

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

Log Message:
Remove apte related shootdowns.


To generate a diff of this commit:
cvs rdiff -u -r1.157 -r1.158 src/sys/arch/x86/x86/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.157 src/sys/arch/x86/x86/pmap.c:1.158
--- src/sys/arch/x86/x86/pmap.c:1.157	Sat Jan 28 08:57:09 2012
+++ src/sys/arch/x86/x86/pmap.c	Sun Jan 29 11:37:08 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.157 2012/01/28 08:57:09 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.158 2012/01/29 11:37:08 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.157 2012/01/28 08:57:09 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.158 2012/01/29 11:37:08 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -1869,12 +1869,6 @@ pmap_free_ptp(struct pmap *pmap, struct 
 	int level;
 	vaddr_t invaladdr;
 	pd_entry_t opde;
-#ifdef XEN
-	struct pmap *curpmap = vm_map_pmap(curlwp-l_proc-p_vmspace-vm_map);
-#ifdef MULTIPROCESSOR
-	vaddr_t invaladdr2;
-#endif
-#endif
 
 	KASSERT(pmap != pmap_kernel());
 	KASSERT(mutex_owned(pmap-pm_lock));
@@ -1901,16 +1895,8 @@ pmap_free_ptp(struct pmap *pmap, struct 
 #  endif /*__x86_64__ */
 		invaladdr = level == 1 ? (vaddr_t)ptes :
 		(vaddr_t)pdes[level - 2];
-		pmap_tlb_shootdown(curpmap, invaladdr + index * PAGE_SIZE,
+		pmap_tlb_shootdown(pmap, invaladdr + index * PAGE_SIZE,
 		opde, TLBSHOOT_FREE_PTP1);
-#  if defined(MULTIPROCESSOR)
-		invaladdr2 = level == 1 ? (vaddr_t)PTE_BASE :
-		(vaddr_t)normal_pdes[level - 2];
-		if (pmap != curpmap || invaladdr != invaladdr2) {
-			pmap_tlb_shootdown(pmap, invaladdr2 + index * PAGE_SIZE,
-			opde, TLBSHOOT_FREE_PTP2);
-		}
-#  endif /* MULTIPROCESSOR */
 #else	/* XEN */
 		invaladdr = level == 1 ? (vaddr_t)ptes :
 		(vaddr_t)pdes[level - 2];



CVS commit: src/sys/arch/x86/x86

2012-01-29 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Jan 29 11:37:44 UTC 2012

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

Log Message:
remove obsolete comment


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/sys/arch/x86/x86/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.158 src/sys/arch/x86/x86/pmap.c:1.159
--- src/sys/arch/x86/x86/pmap.c:1.158	Sun Jan 29 11:37:08 2012
+++ src/sys/arch/x86/x86/pmap.c	Sun Jan 29 11:37:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.158 2012/01/29 11:37:08 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.159 2012/01/29 11:37:44 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.158 2012/01/29 11:37:08 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.159 2012/01/29 11:37:44 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -2348,10 +2348,6 @@ pmap_destroy(struct pmap *pmap)
 		KASSERT(TAILQ_EMPTY(pmap-pm_obj[i].memq));
 	}
 
-	/*
-	 * MULTIPROCESSOR -- no need to flush out of other processors'
-	 * APTE space because we do that in pmap_unmap_ptes().
-	 */
 	pool_cache_put(pmap_pdp_cache, pmap-pm_pdir);
 
 #ifdef USER_LDT



CVS commit: src/sys/arch/x86/x86

2012-01-30 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jan 30 10:33:05 UTC 2012

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

Log Message:
On xen, prevent cached PDP objects from being reused by pool_cache(9),
since they are pinned on the hypervisor and thus R/O for the domU.

Separately, after every per-cpu pmap pdir entry reset, make sure that
the corresponding L3 PTP pointers are flushed from all cpus with the
pmap loaded. Enforce this immediately via pmap_tlb_shootnow();


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/sys/arch/x86/x86/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.160 src/sys/arch/x86/x86/pmap.c:1.161
--- src/sys/arch/x86/x86/pmap.c:1.160	Sun Jan 29 11:45:37 2012
+++ src/sys/arch/x86/x86/pmap.c	Mon Jan 30 10:33:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.160 2012/01/29 11:45:37 drochner Exp $	*/
+/*	$NetBSD: pmap.c,v 1.161 2012/01/30 10:33:05 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.160 2012/01/29 11:45:37 drochner Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.161 2012/01/30 10:33:05 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -1614,7 +1614,7 @@ pmap_prealloc_lowmem_ptps(void)
 void
 pmap_init(void)
 {
-	int i;
+	int i, flags;
 
 	for (i = 0; i  PV_HASH_SIZE; i++) {
 		SLIST_INIT(pv_hash_heads[i].hh_list);
@@ -1629,12 +1629,22 @@ pmap_init(void)
 
 	pool_cache_bootstrap(pmap_cache, sizeof(struct pmap), 0, 0, 0,
 	pmappl, NULL, IPL_NONE, NULL, NULL, NULL);
+
+#ifdef XEN
+	/* 
+	 * pool_cache(9) should not touch cached objects, since they
+	 * are pinned on xen and R/O for the domU
+	 */
+	flags = PR_NOTOUCH;
+#else /* XEN */
+	flags = 0;
+#endif /* XEN */
 #ifdef PAE
-	pool_cache_bootstrap(pmap_pdp_cache, PAGE_SIZE * PDP_SIZE, 0, 0, 0,
+	pool_cache_bootstrap(pmap_pdp_cache, PAGE_SIZE * PDP_SIZE, 0, 0, flags,
 	pdppl, pmap_pdp_allocator, IPL_NONE,
 	pmap_pdp_ctor, pmap_pdp_dtor, NULL);
 #else /* PAE */
-	pool_cache_bootstrap(pmap_pdp_cache, PAGE_SIZE, 0, 0, 0,
+	pool_cache_bootstrap(pmap_pdp_cache, PAGE_SIZE, 0, 0, flags,
 	pdppl, NULL, IPL_NONE, pmap_pdp_ctor, pmap_pdp_dtor, NULL);
 #endif /* PAE */
 	pool_cache_bootstrap(pmap_pv_cache, sizeof(struct pv_entry), 0, 0,
@@ -1897,6 +1907,7 @@ pmap_free_ptp(struct pmap *pmap, struct 
 		(vaddr_t)pdes[level - 2];
 		pmap_tlb_shootdown(pmap, invaladdr + index * PAGE_SIZE,
 		opde, TLBSHOOT_FREE_PTP1);
+		pmap_tlb_shootnow();
 #else	/* XEN */
 		invaladdr = level == 1 ? (vaddr_t)ptes :
 		(vaddr_t)pdes[level - 2];



CVS commit: src/sys/arch

2012-01-30 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jan 30 10:55:25 UTC 2012

Modified Files:
src/sys/arch/amd64/conf: XEN3_DOMU
src/sys/arch/i386/conf: XEN3_DOMU

Log Message:
switch on NetBSD/Xen MULTIPROCESSOR support for domUs as default, for wider 
testing


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/amd64/conf/XEN3_DOMU
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/i386/conf/XEN3_DOMU

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/amd64/conf/XEN3_DOMU
diff -u src/sys/arch/amd64/conf/XEN3_DOMU:1.35 src/sys/arch/amd64/conf/XEN3_DOMU:1.36
--- src/sys/arch/amd64/conf/XEN3_DOMU:1.35	Mon Dec 19 19:09:16 2011
+++ src/sys/arch/amd64/conf/XEN3_DOMU	Mon Jan 30 10:55:25 2012
@@ -1,8 +1,8 @@
-# $NetBSD: XEN3_DOMU,v 1.35 2011/12/19 19:09:16 cherry Exp $
+# $NetBSD: XEN3_DOMU,v 1.36 2012/01/30 10:55:25 cherry Exp $
 
 include 	arch/amd64/conf/std.xen
 
-#options		MULTIPROCESSOR	# Experimental
+options		MULTIPROCESSOR
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 

Index: src/sys/arch/i386/conf/XEN3_DOMU
diff -u src/sys/arch/i386/conf/XEN3_DOMU:1.40 src/sys/arch/i386/conf/XEN3_DOMU:1.41
--- src/sys/arch/i386/conf/XEN3_DOMU:1.40	Mon Dec 19 19:09:16 2011
+++ src/sys/arch/i386/conf/XEN3_DOMU	Mon Jan 30 10:55:25 2012
@@ -1,8 +1,8 @@
-# $NetBSD: XEN3_DOMU,v 1.40 2011/12/19 19:09:16 cherry Exp $
+# $NetBSD: XEN3_DOMU,v 1.41 2012/01/30 10:55:25 cherry Exp $
 
 include 	arch/xen/conf/std.xen
 
-#options		MULTIPROCESSOR	# Experimental
+options		MULTIPROCESSOR
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 



CVS commit: src/sys/arch/x86/x86

2012-01-30 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jan 30 17:56:27 UTC 2012

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

Log Message:
Remove obsolete comment


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/arch/x86/x86/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.161 src/sys/arch/x86/x86/pmap.c:1.162
--- src/sys/arch/x86/x86/pmap.c:1.161	Mon Jan 30 10:33:05 2012
+++ src/sys/arch/x86/x86/pmap.c	Mon Jan 30 17:56:27 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.161 2012/01/30 10:33:05 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.162 2012/01/30 17:56:27 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.161 2012/01/30 10:33:05 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.162 2012/01/30 17:56:27 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -1986,10 +1986,6 @@ pmap_get_ptp(struct pmap *pmap, vaddr_t 
 		pmap_pte_set(pva[index], (pd_entry_t)
 		(pmap_pa2pte(pa) | PG_u | PG_RW | PG_V));
 #if defined(XEN)  defined(__x86_64__)
-		/*
-		 * In Xen we must enter the mapping in kernel map too
-		 * if pmap is curmap and modifying top level (PGD)
-		 */
 		if(i == PTP_LEVELS  pmap != pmap_kernel()) {
 			/*
 			 * Update the per-cpu PD on all cpus the current



CVS commit: src/sys/arch/x86/x86

2012-02-01 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Feb  1 18:55:33 UTC 2012

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

Log Message:
amd64/Xen doesn't require special treatment for pmap_is_curpmap(),
since cpu_load_pmap() ensures that the linear map is in place for the
kernel. This emulates normal shared kernel mappings, except for the
recursive mapping of the PDP_BASE, which will point to the per-cpu
pdir, which will be a copy of the pmap_kernel()-pm_pdir; instead of
the user pmap-pm_pdir.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/arch/x86/x86/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.162 src/sys/arch/x86/x86/pmap.c:1.163
--- src/sys/arch/x86/x86/pmap.c:1.162	Mon Jan 30 17:56:27 2012
+++ src/sys/arch/x86/x86/pmap.c	Wed Feb  1 18:55:32 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.162 2012/01/30 17:56:27 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.163 2012/02/01 18:55:32 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.162 2012/01/30 17:56:27 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.163 2012/02/01 18:55:32 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -675,17 +675,8 @@ pv_pte_next(struct pmap_page *pp, struct
 bool
 pmap_is_curpmap(struct pmap *pmap)
 {
-#if defined(XEN)  defined(__x86_64__)
-	/*
-	 * Only kernel pmap is physically loaded.
-	 * User PGD may be active, but TLB will be flushed
-	 * with HYPERVISOR_iret anyway, so let's say no
-	 */
-	return(pmap == pmap_kernel());
-#else /* XEN  __x86_64__*/
 	return((pmap == pmap_kernel()) ||
 	   (pmap == curcpu()-ci_pmap));
-#endif
 }
 
 /*



CVS commit: src/sys/arch

2012-02-19 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Feb 19 10:39:06 UTC 2012

Modified Files:
src/sys/arch/amd64/include: pmap.h
src/sys/arch/i386/include: pmap.h vmparam.h

Log Message:
Removing remaining references to the alternate PTE space. Modify documentation 
appropriately


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/amd64/include/pmap.h
cvs rdiff -u -r1.114 -r1.115 src/sys/arch/i386/include/pmap.h
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/i386/include/vmparam.h

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/amd64/include/pmap.h
diff -u src/sys/arch/amd64/include/pmap.h:1.31 src/sys/arch/amd64/include/pmap.h:1.32
--- src/sys/arch/amd64/include/pmap.h:1.31	Thu Jan 19 22:00:56 2012
+++ src/sys/arch/amd64/include/pmap.h	Sun Feb 19 10:39:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.31 2012/01/19 22:00:56 bouyer Exp $	*/
+/*	$NetBSD: pmap.h,v 1.32 2012/02/19 10:39:06 cherry Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -84,19 +84,14 @@
 #endif /* XEN */
 
 /*
- * The x86_64 pmap module closely resembles the i386 one. It uses
- * the same recursive entry scheme, and the same alternate area
- * trick for accessing non-current pmaps. See the i386 pmap.h
+ * The x86_64 pmap module closely resembles the i386 one and it 
+ * uses the same recursive entry scheme. See the i386 pmap.h
  * for a description. The obvious difference is that 3 extra
  * levels of page table need to be dealt with. The level 1 page
  * table pages are at:
  *
  * l1: 0x7f80 - 0x7fff (39 bits, needs PML4 entry)
  *
- * The alternate space is at:
- *
- * l1: 0xff80 - 0x (39 bits, needs PML4 entry)
- *
  * The rest is kept as physical pages in 3 UVM objects, and is
  * temporarily mapped for virtual access when needed.
  *
@@ -104,7 +99,7 @@
  *
  *  +-+ 0x
  *  | |
- *  |alt.L1 table (PTE pages) |
+ *  | Unused  |
  *  | |
  *  +-+ 0xff80
  *  ~ ~
@@ -161,41 +156,30 @@
 #define L4_SLOT_KERN		320
 #endif
 #define L4_SLOT_KERNBASE	511
-#define L4_SLOT_APTE		510
 
 #define PDIR_SLOT_KERN	L4_SLOT_KERN
 #define PDIR_SLOT_PTE	L4_SLOT_PTE
-#define PDIR_SLOT_APTE	L4_SLOT_APTE
 
 /*
  * the following defines give the virtual addresses of various MMU
  * data structures:
- * PTE_BASE and APTE_BASE: the base VA of the linear PTE mappings
- * PTD_BASE and APTD_BASE: the base VA of the recursive mapping of the PTD
- * PDP_PDE and APDP_PDE: the VA of the PDE that points back to the PDP/APDP
+ * PTE_BASE: the base VA of the linear PTE mappings
+ * PTD_BASE: the base VA of the recursive mapping of the PTD
+ * PDP_PDE: the VA of the PDE that points back to the PDP
  *
  */
 
 #define PTE_BASE  ((pt_entry_t *) (L4_SLOT_PTE * NBPD_L4))
 #define KERN_BASE  ((pt_entry_t *) (L4_SLOT_KERN * NBPD_L4))
-#define APTE_BASE ((pt_entry_t *) (VA_SIGN_NEG((L4_SLOT_APTE * NBPD_L4
 
 #define L1_BASE		PTE_BASE
-#define AL1_BASE	APTE_BASE
-
 #define L2_BASE ((pd_entry_t *)((char *)L1_BASE + L4_SLOT_PTE * NBPD_L3))
 #define L3_BASE ((pd_entry_t *)((char *)L2_BASE + L4_SLOT_PTE * NBPD_L2))
 #define L4_BASE ((pd_entry_t *)((char *)L3_BASE + L4_SLOT_PTE * NBPD_L1))
 
-#define AL2_BASE ((pd_entry_t *)((char *)AL1_BASE + L4_SLOT_PTE * NBPD_L3))
-#define AL3_BASE ((pd_entry_t *)((char *)AL2_BASE + L4_SLOT_PTE * NBPD_L2))
-#define AL4_BASE ((pd_entry_t *)((char *)AL3_BASE + L4_SLOT_PTE * NBPD_L1))
-
 #define PDP_PDE		(L4_BASE + PDIR_SLOT_PTE)
-#define APDP_PDE	(curcpu()-ci_kpm_pdir[PDIR_SLOT_APTE])
 
 #define PDP_BASE	L4_BASE
-#define APDP_BASE	AL4_BASE
 
 #define NKL4_MAX_ENTRIES	(unsigned long)1
 #define NKL3_MAX_ENTRIES	(unsigned long)(NKL4_MAX_ENTRIES * 512)
@@ -227,7 +211,6 @@
   NKL3_MAX_ENTRIES, NKL4_MAX_ENTRIES }
 #define NBPD_INITIALIZER	{ NBPD_L1, NBPD_L2, NBPD_L3, NBPD_L4 }
 #define PDES_INITIALIZER	{ L2_BASE, L3_BASE, L4_BASE }
-#define APDES_INITIALIZER	{ AL2_BASE, AL3_BASE, AL4_BASE }
 
 #define PTP_LEVELS	4
 

Index: src/sys/arch/i386/include/pmap.h
diff -u src/sys/arch/i386/include/pmap.h:1.114 src/sys/arch/i386/include/pmap.h:1.115
--- src/sys/arch/i386/include/pmap.h:1.114	Thu Jan 19 22:00:57 2012
+++ src/sys/arch/i386/include/pmap.h	Sun Feb 19 10:39:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.114 2012/01/19 22:00:57 bouyer Exp $	*/
+/*	$NetBSD: pmap.h,v 1.115 2012/02/19 10:39:06 cherry Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -100,8 +100,7 @@
  *			0xc000	linear mapping of PTPs)
  * 768-1023	0xc000-		kernel address space (constant
  *			0xffc0	across all pmap's/processes)
- * 1023		0xffc0-		alternate recursive PDP 

CVS commit: src/sys/arch/xen/x86

2012-02-22 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Feb 23 04:10:51 UTC 2012

Modified Files:
src/sys/arch/xen/x86: cpu.c

Log Message:
cpu_load_pmap() should not be used to load pmap_kernel(), since in the
x86 model, its mappings are shared across pmaps. KASSERT() for this
and remove unused codepaths.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 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.83 src/sys/arch/xen/x86/cpu.c:1.84
--- src/sys/arch/xen/x86/cpu.c:1.83	Wed Feb 22 18:29:31 2012
+++ src/sys/arch/xen/x86/cpu.c	Thu Feb 23 04:10:51 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.83 2012/02/22 18:29:31 bouyer Exp $	*/
+/*	$NetBSD: cpu.c,v 1.84 2012/02/23 04:10:51 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.83 2012/02/22 18:29:31 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.84 2012/02/23 04:10:51 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1176,6 +1176,8 @@ x86_cpu_idle_xen(void)
 void
 cpu_load_pmap(struct pmap *pmap, struct pmap *oldpmap)
 {
+	KASSERT(pmap != pmap_kernel());
+	
 #if defined(__x86_64__) || defined(PAE)
 	struct cpu_info *ci = curcpu();
 	uint32_t cpumask = ci-ci_cpumask;
@@ -1226,14 +1228,8 @@ cpu_load_pmap(struct pmap *pmap, struct 
 			}
 		}
 
-		if (__predict_true(pmap != pmap_kernel())) {
-			xen_set_user_pgd(pmap_pdirpa(pmap, 0));
-			ci-ci_xen_current_user_pgd = pmap_pdirpa(pmap, 0);
-		}
-		else {
-			xpq_queue_pt_switch(l4_pd_ma);
-			ci-ci_xen_current_user_pgd = 0;
-		}
+		xen_set_user_pgd(pmap_pdirpa(pmap, 0));
+		ci-ci_xen_current_user_pgd = pmap_pdirpa(pmap, 0);
 
 		tlbflush();
 	}



CVS commit: src/sys/arch/xen/x86

2012-02-22 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Feb 23 07:30:30 UTC 2012

Modified Files:
src/sys/arch/xen/x86: cpu.c

Log Message:
Cleanup.

 - Remove cruft from native x86 origin.
 - Remove access to privileged MSRs.
 - Cleanup stale comments.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 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.84 src/sys/arch/xen/x86/cpu.c:1.85
--- src/sys/arch/xen/x86/cpu.c:1.84	Thu Feb 23 04:10:51 2012
+++ src/sys/arch/xen/x86/cpu.c	Thu Feb 23 07:30:30 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.84 2012/02/23 04:10:51 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.85 2012/02/23 07:30:30 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.84 2012/02/23 04:10:51 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.85 2012/02/23 07:30:30 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -464,7 +464,6 @@ cpu_attach_common(device_t parent, devic
 
 		/* Every processor needs to init it's own ipi h/w (similar to lapic) */
 		xen_ipi_init();
-		/* XXX: clock_init() */
 
 		/* Make sure DELAY() is initialized. */
 		DELAY(1);
@@ -477,9 +476,6 @@ cpu_attach_common(device_t parent, devic
 	case CPU_ROLE_SP:
 		atomic_or_32(ci-ci_flags, CPUF_SP);
 		cpu_identify(ci);
-#if 0
-		x86_errata();
-#endif
 		x86_cpu_idle_init();
 
 		break;
@@ -487,9 +483,6 @@ cpu_attach_common(device_t parent, devic
 	case CPU_ROLE_BP:
 		atomic_or_32(ci-ci_flags, CPUF_BSP);
 		cpu_identify(ci);
-#if 0
-		x86_errata();
-#endif
 		x86_cpu_idle_init();
 
 		break;
@@ -561,23 +554,6 @@ cpu_init(struct cpu_info *ci)
 {
 
 	/*
-	 * On a P6 or above, enable global TLB caching if the
-	 * hardware supports it.
-	 */
-	if (cpu_feature[0]  CPUID_PGE)
-		lcr4(rcr4() | CR4_PGE);	/* enable global TLB caching */
-
-#ifdef XXXMTRR
-	/*
-	 * On a P6 or above, initialize MTRR's if the hardware supports them.
-	 */
-	if (cpu_feature[0]  CPUID_MTRR) {
-		if ((ci-ci_flags  CPUF_AP) == 0)
-			i686_mtrr_init_first();
-		mtrr_init_cpu(ci);
-	}
-#endif
-	/*
 	 * If we have FXSAVE/FXRESTOR, use them.
 	 */
 	if (cpu_feature[0]  CPUID_FXSR) {
@@ -600,8 +576,6 @@ cpu_init(struct cpu_info *ci)
 
 	atomic_or_32(cpus_running, ci-ci_cpumask);
 	atomic_or_32(ci-ci_flags, CPUF_RUNNING);
-
-	/* XXX: register vcpu_register_runstate_memory_area, and figure out how to make sure this VCPU is running ? */
 }
 
 
@@ -739,15 +713,13 @@ cpu_hatch(void *v)
 	KASSERT((ci-ci_flags  CPUF_RUNNING) == 0);
 
 	pcb = lwp_getpcb(curlwp);
-	pcb-pcb_cr3 = pmap_pdirpa(pmap_kernel(), 0); /* XXX: consider using pmap_load() ? */
+	pcb-pcb_cr3 = pmap_pdirpa(pmap_kernel(), 0);
 	pcb = lwp_getpcb(ci-ci_data.cpu_idlelwp);
 
 	xen_ipi_init();
 
 	xen_initclocks();
 	
-	/* XXX: lapic_initclocks(); */
-
 #ifdef __x86_64__
 	fpuinit(ci);
 #endif
@@ -760,9 +732,6 @@ cpu_hatch(void *v)
 	s = splhigh();
 	x86_enable_intr();
 	splx(s);
-#if 0
-	x86_errata();
-#endif
 
 	aprint_debug_dev(ci-ci_dev, running\n);
 
@@ -831,7 +800,7 @@ gdt_prepframes(paddr_t *frames, vaddr_t 
 }
 
 #ifdef __x86_64__
-extern char *ldtstore; /* XXX: Xen MP todo */
+extern char *ldtstore;
 
 static void
 xen_init_amd64_vcpuctxt(struct cpu_info *ci,
@@ -855,13 +824,11 @@ xen_init_amd64_vcpuctxt(struct cpu_info 
 
 	memset(initctx, 0, sizeof *initctx);
 
-	gdt_ents = roundup(gdt_size, PAGE_SIZE)  PAGE_SHIFT; /* XXX: re-investigate roundup(gdt_size... ) for gdt_ents. */
+	gdt_ents = roundup(gdt_size, PAGE_SIZE)  PAGE_SHIFT; 
 	KASSERT(gdt_ents = 16);
 
 	gdt_prepframes(frames, (vaddr_t) ci-ci_gdt, gdt_ents);
 
-	/* XXX: The stuff in here is amd64 specific. move to mptramp.[Sc] ? */
-
 	/* Initialise the vcpu context: We use idle_loop()'s pcb context. */
 
 	l = ci-ci_data.cpu_idlelwp;
@@ -911,7 +878,7 @@ xen_init_amd64_vcpuctxt(struct cpu_info 
 	initctx-kernel_sp = pcb-pcb_rsp0;
 	initctx-ctrlreg[0] = pcb-pcb_cr0;
 	initctx-ctrlreg[1] = 0; /* resuming from kernel - no User cr3. */
-	initctx-ctrlreg[2] = pcb-pcb_cr2; /* XXX: */
+	initctx-ctrlreg[2] = (vaddr_t) targetrip;
 	/* 
 	 * Use pmap_kernel() L4 PD directly, until we setup the
 	 * per-cpu L4 PD in pmap_cpu_init_late()
@@ -953,7 +920,7 @@ xen_init_i386_vcpuctxt(struct cpu_info *
 
 	memset(initctx, 0, sizeof *initctx);
 
-	gdt_ents = roundup(gdt_size, PAGE_SIZE)  PAGE_SHIFT; /* XXX: re-investigate roundup(gdt_size... ) for gdt_ents. */
+	gdt_ents = roundup(gdt_size, PAGE_SIZE)  PAGE_SHIFT;
 	KASSERT(gdt_ents = 16);
 
 	gdt_prepframes(frames, (vaddr_t) ci-ci_gdt, gdt_ents);
@@ -1015,7 +982,7 @@ xen_init_i386_vcpuctxt(struct cpu_info *
 	initctx-kernel_sp = pcb-pcb_esp0;
 	initctx-ctrlreg[0] = pcb-pcb_cr0;
 	initctx-ctrlreg[1] = 0; /* resuming from kernel - no User cr3. */
-	initctx-ctrlreg[2] = 

CVS commit: src/sys/arch

2012-02-24 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Feb 24 08:06:08 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: locore.S
src/sys/arch/i386/i386: gdt.c locore.S machdep.c
src/sys/arch/xen/x86: cpu.c x86_xpmap.c xen_pmap.c

Log Message:
(xen) - remove the (*xpq_cpu)() shim.We hasten the %fs/%gs setup process during 
boot.Although this is hacky, it lets us use the non-xen specificpmap_pte_xxx() 
functions in pmap code (and others).


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/i386/i386/gdt.c
cvs rdiff -u -r1.95 -r1.96 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.720 -r1.721 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.85 -r1.86 src/sys/arch/xen/x86/cpu.c
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/xen/x86/x86_xpmap.c
cvs rdiff -u -r1.17 -r1.18 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/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.66 src/sys/arch/amd64/amd64/locore.S:1.67
--- src/sys/arch/amd64/amd64/locore.S:1.66	Sun Dec  4 16:24:13 2011
+++ src/sys/arch/amd64/amd64/locore.S	Fri Feb 24 08:06:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.66 2011/12/04 16:24:13 chs Exp $	*/
+/*	$NetBSD: locore.S,v 1.67 2012/02/24 08:06:07 cherry Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -778,6 +778,11 @@ start:
 	cpuid
 	movl	%eax,_C_LABEL(cpuid_level)
 
+	movq	$cpu_info_primary, %rdi
+	movq	%rdi, CPU_INFO_SELF(%rdi) /* ci-ci_self = ci */
+	movq	$1, %rsi
+	call	cpu_init_msrs	/* cpu_init_msrs(ci, true); */
+
 	call	xen_pmap_bootstrap
 
 	/*

Index: src/sys/arch/i386/i386/gdt.c
diff -u src/sys/arch/i386/i386/gdt.c:1.52 src/sys/arch/i386/i386/gdt.c:1.53
--- src/sys/arch/i386/i386/gdt.c:1.52	Sun Nov  6 11:40:46 2011
+++ src/sys/arch/i386/i386/gdt.c	Fri Feb 24 08:06:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: gdt.c,v 1.52 2011/11/06 11:40:46 cherry Exp $	*/
+/*	$NetBSD: gdt.c,v 1.53 2012/02/24 08:06:07 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gdt.c,v 1.52 2011/11/06 11:40:46 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: gdt.c,v 1.53 2012/02/24 08:06:07 cherry Exp $);
 
 #include opt_multiprocessor.h
 #include opt_xen.h
@@ -214,9 +214,10 @@ gdt_init_cpu(struct cpu_info *ci)
 		* properly yet, ie; curcpu() won't work at this
 		* point and spl() will break.
 		*/
-		   xpq_queue_pte_update(xpmap_ptetomach(ptp),
-	*ptp  ~PG_RW);
-		   xpq_flush_queue();
+			if (HYPERVISOR_update_va_mapping((vaddr_t)va,
+*ptp  ~PG_RW, UVMF_INVLPG)  0) {
+panic(%s page RO update failed.\n, __func__);
+			}
 		}
 	}
 

Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.95 src/sys/arch/i386/i386/locore.S:1.96
--- src/sys/arch/i386/i386/locore.S:1.95	Fri Mar 18 15:18:16 2011
+++ src/sys/arch/i386/i386/locore.S	Fri Feb 24 08:06:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.95 2011/03/18 15:18:16 joerg Exp $	*/
+/*	$NetBSD: locore.S,v 1.96 2012/02/24 08:06:07 cherry Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -129,7 +129,7 @@
  */
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: locore.S,v 1.95 2011/03/18 15:18:16 joerg Exp $);
+__KERNEL_RCSID(0, $NetBSD: locore.S,v 1.96 2012/02/24 08:06:07 cherry Exp $);
 
 #include opt_compat_oldboot.h
 #include opt_ddb.h
@@ -238,7 +238,12 @@ _C_LABEL(tablesize):	.long	0
 
 	.space 512
 tmpstk:
-
+#ifdef XEN
+	.align 		PAGE_SIZE, 0x0	# Align on page boundary
+_C_LABEL(tmpgdt):
+	.space 		PAGE_SIZE	# Xen expects a page
+#endif /* XEN */
+	.globl tmpgdt
 #ifndef XEN
 #define	_RELOC(x)	((x) - KERNBASE)
 #else
@@ -787,6 +792,15 @@ start:
 	cpuid
 	movl	%eax,RELOC(cpuid_level)
 
+	/*
+	 * Use a temp page. We'll re- add it to uvm(9) once we're
+	 * done using it.
+	 */
+	movl	$RELOC(tmpgdt), %eax
+	pushl	%eax		# start of temporary gdt
+	call	_C_LABEL(initgdt)
+	addl	$4,%esp
+
 	call	xen_pmap_bootstrap
 
 	/*

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.720 src/sys/arch/i386/i386/machdep.c:1.721
--- src/sys/arch/i386/i386/machdep.c:1.720	Thu Feb 23 14:45:55 2012
+++ src/sys/arch/i386/i386/machdep.c	Fri Feb 24 08:06:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.720 2012/02/23 14:45:55 chs Exp $	*/
+/*	$NetBSD: machdep.c,v 1.721 2012/02/24 08:06:07 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.720 2012/02/23 14:45:55 chs Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.721 2012/02/24 08:06:07 cherry Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -525,9 +525,6 @@ i386_proc0_tss_ldt_init(void)
 }
 
 #ifdef XEN
-/* Shim for curcpu() until %fs is ready */
-extern struct cpu_info	* 

CVS commit: src/sys/arch/x86/x86

2012-02-24 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Feb 24 08:11:14 UTC 2012

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

Log Message:
kernel page attribute change should be reflected on all cpus, since
the page is going to be released after the _dtor() hook is called.


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/sys/arch/x86/x86/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.170 src/sys/arch/x86/x86/pmap.c:1.171
--- src/sys/arch/x86/x86/pmap.c:1.170	Thu Feb 23 18:59:21 2012
+++ src/sys/arch/x86/x86/pmap.c	Fri Feb 24 08:11:14 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.170 2012/02/23 18:59:21 bouyer Exp $	*/
+/*	$NetBSD: pmap.c,v 1.171 2012/02/24 08:11:14 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.170 2012/02/23 18:59:21 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.171 2012/02/24 08:11:14 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -2172,7 +2172,7 @@ pmap_pdp_dtor(void *arg, void *v)
 		/* Set page RW again */
 		pte = kvtopte(object);
 		xpq_queue_pte_update(xpmap_ptetomach(pte), *pte | PG_RW);
-		xpq_queue_invlpg((vaddr_t)object);
+		xpq_bcast_invlpg((vaddr_t)object);
 	}
 	splx(s);
 #endif  /* XEN */



CVS commit: src/sys/arch/x86/x86

2012-02-24 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Feb 24 08:17:20 UTC 2012

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

Log Message:
Revert previous


To generate a diff of this commit:
cvs rdiff -u -r1.171 -r1.172 src/sys/arch/x86/x86/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.171 src/sys/arch/x86/x86/pmap.c:1.172
--- src/sys/arch/x86/x86/pmap.c:1.171	Fri Feb 24 08:11:14 2012
+++ src/sys/arch/x86/x86/pmap.c	Fri Feb 24 08:17:20 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.171 2012/02/24 08:11:14 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.172 2012/02/24 08:17:20 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.171 2012/02/24 08:11:14 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.172 2012/02/24 08:17:20 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -2172,7 +2172,7 @@ pmap_pdp_dtor(void *arg, void *v)
 		/* Set page RW again */
 		pte = kvtopte(object);
 		xpq_queue_pte_update(xpmap_ptetomach(pte), *pte | PG_RW);
-		xpq_bcast_invlpg((vaddr_t)object);
+		xpq_queue_invlpg((vaddr_t)object);
 	}
 	splx(s);
 #endif  /* XEN */



CVS commit: src/sys/arch/x86/x86

2012-02-24 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Feb 24 08:44:44 UTC 2012

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

Log Message:
kernel page attribute change should be reflected on all cpus, since
the page is going to be released after the _dtor() hook is called.


To generate a diff of this commit:
cvs rdiff -u -r1.172 -r1.173 src/sys/arch/x86/x86/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.172 src/sys/arch/x86/x86/pmap.c:1.173
--- src/sys/arch/x86/x86/pmap.c:1.172	Fri Feb 24 08:17:20 2012
+++ src/sys/arch/x86/x86/pmap.c	Fri Feb 24 08:44:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.172 2012/02/24 08:17:20 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.173 2012/02/24 08:44:44 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.172 2012/02/24 08:17:20 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.173 2012/02/24 08:44:44 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -2172,7 +2172,7 @@ pmap_pdp_dtor(void *arg, void *v)
 		/* Set page RW again */
 		pte = kvtopte(object);
 		xpq_queue_pte_update(xpmap_ptetomach(pte), *pte | PG_RW);
-		xpq_queue_invlpg((vaddr_t)object);
+		xen_bcast_invlpg((vaddr_t)object);
 	}
 	splx(s);
 #endif  /* XEN */



CVS commit: src/sys/arch/x86/x86

2012-02-25 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Feb 25 12:33:54 UTC 2012

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

Log Message:
Use pmap_pte_xxx() functions instead of xen specific pte update
functions.

No functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.173 -r1.174 src/sys/arch/x86/x86/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.173 src/sys/arch/x86/x86/pmap.c:1.174
--- src/sys/arch/x86/x86/pmap.c:1.173	Fri Feb 24 08:44:44 2012
+++ src/sys/arch/x86/x86/pmap.c	Sat Feb 25 12:33:53 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.173 2012/02/24 08:44:44 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.174 2012/02/25 12:33:53 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.173 2012/02/24 08:44:44 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.174 2012/02/25 12:33:53 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -1548,43 +1548,10 @@ pmap_prealloc_lowmem_ptps(void)
 {
 	int level;
 	paddr_t newp;
-#ifdef XEN
-	paddr_t pdes_pa;
-
-	pdes_pa = pmap_pdirpa(pmap_kernel(), 0);
-	level = PTP_LEVELS;
-	for (;;) {
-		newp = avail_start;
-		avail_start += PAGE_SIZE;
-		HYPERVISOR_update_va_mapping ((vaddr_t)early_zerop,
-		xpmap_ptom_masked(newp) | PG_u | PG_V | PG_RW, UVMF_INVLPG);
-		memset(early_zerop, 0, PAGE_SIZE);
-		/* Mark R/O before installing */
-		HYPERVISOR_update_va_mapping ((vaddr_t)early_zerop,
-		xpmap_ptom_masked(newp) | PG_u | PG_V, UVMF_INVLPG);
-		if (newp  (NKL2_KIMG_ENTRIES * NBPD_L2))
-			HYPERVISOR_update_va_mapping (newp + KERNBASE,
-			xpmap_ptom_masked(newp) | PG_u | PG_V, UVMF_INVLPG);
-		/* Update the pmap_kernel() L4 shadow */
-		xpq_queue_pte_update (
-		xpmap_ptom_masked(pdes_pa)
-		+ (pl_i(0, level) * sizeof (pd_entry_t)),
-		xpmap_ptom_masked(newp) | PG_RW | PG_u | PG_V);
-		/* sync to per-cpu PD */
-		xpq_queue_pte_update(
-			xpmap_ptom_masked(cpu_info_primary.ci_kpm_pdirpa +
-			pl_i(0, PTP_LEVELS) *
-			sizeof(pd_entry_t)),
-			pmap_kernel()-pm_pdir[pl_i(0, PTP_LEVELS)]);
-		pmap_pte_flush();
-		level--;
-		if (level = 1)
-			break;
-		pdes_pa = newp;
-	}
-#else /* XEN */
 	pd_entry_t *pdes;
 
+	const pd_entry_t pteflags = PG_k | PG_V | PG_RW;
+
 	pdes = pmap_kernel()-pm_pdir;
 	level = PTP_LEVELS;
 	for (;;) {
@@ -1593,18 +1560,47 @@ pmap_prealloc_lowmem_ptps(void)
 #ifdef __HAVE_DIRECT_MAP
 		memset((void *)PMAP_DIRECT_MAP(newp), 0, PAGE_SIZE);
 #else
-		pmap_pte_set(early_zero_pte, (newp  PG_FRAME) | PG_V | PG_RW);
+		pmap_pte_set(early_zero_pte, pmap_pa2pte(newp) | pteflags);
 		pmap_pte_flush();
 		pmap_update_pg((vaddr_t)early_zerop);
 		memset(early_zerop, 0, PAGE_SIZE);
 #endif
-		pdes[pl_i(0, level)] = (newp  PG_FRAME) | PG_V | PG_RW;
+
+#ifdef XEN
+		/* Mark R/O before installing */
+		HYPERVISOR_update_va_mapping ((vaddr_t)early_zerop,
+		xpmap_ptom_masked(newp) | PG_u | PG_V, UVMF_INVLPG);
+		if (newp  (NKL2_KIMG_ENTRIES * NBPD_L2))
+			HYPERVISOR_update_va_mapping (newp + KERNBASE,
+			xpmap_ptom_masked(newp) | PG_u | PG_V, UVMF_INVLPG);
+
+
+		if (level == PTP_LEVELS) { /* Top level pde is per-cpu */
+			pd_entry_t *kpm_pdir;
+			/* Reach it via recursive mapping */
+			kpm_pdir = normal_pdes[PTP_LEVELS - 2];
+
+			/* Set it as usual. We can't defer this
+			 * outside the loop since recursive
+			 * pte entries won't be accessible during
+			 * further iterations at lower levels
+			 * otherwise.
+			 */
+			pmap_pte_set(kpm_pdir[pl_i(0, PTP_LEVELS)],
+			pmap_pa2pte(newp) | pteflags);
+		}
+
+#endif /* XEN */			
+		pmap_pte_set(pdes[pl_i(0, level)],
+		pmap_pa2pte(newp) | pteflags);
+			
+		pmap_pte_flush();
+		
 		level--;
 		if (level = 1)
 			break;
 		pdes = normal_pdes[level - 2];
 	}
-#endif /* XEN */
 }
 #endif /* defined(__x86_64__) */
 
@@ -2171,7 +2167,7 @@ pmap_pdp_dtor(void *arg, void *v)
 	for (i = 0; i  PDP_SIZE; i++, object += PAGE_SIZE) {
 		/* Set page RW again */
 		pte = kvtopte(object);
-		xpq_queue_pte_update(xpmap_ptetomach(pte), *pte | PG_RW);
+		pmap_pte_set(pte, *pte | PG_RW);
 		xen_bcast_invlpg((vaddr_t)object);
 	}
 	splx(s);
@@ -4191,7 +4187,7 @@ pmap_alloc_level(pd_entry_t * const *pde
 			pmap_get_physpage(va, level - 1, pa);
 			pte = pmap_pa2pte(pa) | PG_k | PG_V | PG_RW;
 #ifdef XEN
-			xpq_queue_pte_update(xpmap_ptetomach(pdep[i]), pte);
+			pmap_pte_set(pdep[i], pte);
 #if defined(PAE) || defined(__x86_64__)
 			if (level == PTP_LEVELS  i = PDIR_SLOT_KERN) {
 if (__predict_true(
@@ -4211,8 +4207,7 @@ pmap_alloc_level(pd_entry_t * const *pde
 	pd_entry_t *cpu_pdep =
 		cpu_info_primary.ci_kpm_pdir[i];
 #endif
-	xpq_queue_pte_update(
-	xpmap_ptetomach(cpu_pdep), pte);
+	pmap_pte_set(cpu_pdep, pte);
 }
 	

CVS commit: src/sys/arch/x86/x86

2012-02-25 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Feb 25 19:32:27 UTC 2012

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

Log Message:
(xen) Flush the xpq before broadcasting page invalidate.


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/sys/arch/x86/x86/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.174 src/sys/arch/x86/x86/pmap.c:1.175
--- src/sys/arch/x86/x86/pmap.c:1.174	Sat Feb 25 12:33:53 2012
+++ src/sys/arch/x86/x86/pmap.c	Sat Feb 25 19:32:27 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.174 2012/02/25 12:33:53 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.175 2012/02/25 19:32:27 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.174 2012/02/25 12:33:53 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.175 2012/02/25 19:32:27 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -2168,6 +2168,7 @@ pmap_pdp_dtor(void *arg, void *v)
 		/* Set page RW again */
 		pte = kvtopte(object);
 		pmap_pte_set(pte, *pte | PG_RW);
+		pmap_pte_flush();
 		xen_bcast_invlpg((vaddr_t)object);
 	}
 	splx(s);



CVS commit: src/sys/arch/x86/x86

2012-02-25 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Feb 25 20:03:58 UTC 2012

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

Log Message:
Revert previous since it does a redundant xpq queue flush.
xen_bcast_invlpg() flushes the queue for us.


To generate a diff of this commit:
cvs rdiff -u -r1.175 -r1.176 src/sys/arch/x86/x86/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.175 src/sys/arch/x86/x86/pmap.c:1.176
--- src/sys/arch/x86/x86/pmap.c:1.175	Sat Feb 25 19:32:27 2012
+++ src/sys/arch/x86/x86/pmap.c	Sat Feb 25 20:03:58 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.175 2012/02/25 19:32:27 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.176 2012/02/25 20:03:58 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.175 2012/02/25 19:32:27 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.176 2012/02/25 20:03:58 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -2168,7 +2168,6 @@ pmap_pdp_dtor(void *arg, void *v)
 		/* Set page RW again */
 		pte = kvtopte(object);
 		pmap_pte_set(pte, *pte | PG_RW);
-		pmap_pte_flush();
 		xen_bcast_invlpg((vaddr_t)object);
 	}
 	splx(s);



CVS commit: src/sys/arch

2011-11-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Nov  6 11:40:47 UTC 2011

Modified Files:
src/sys/arch/amd64/include: pmap.h
src/sys/arch/i386/i386: gdt.c machdep.c
src/sys/arch/i386/include: pmap.h
src/sys/arch/x86/include: intrdefs.h pmap.h
src/sys/arch/xen/include: hypervisor.h xenpmap.h
src/sys/arch/xen/x86: cpu.c x86_xpmap.c xen_pmap.c xenfunc.c

Log Message:
[merging from cherry-xenmp] Make the xen MMU op queue locking api private. 
Implement per-cpu queues.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/amd64/include/pmap.h
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/i386/i386/gdt.c
cvs rdiff -u -r1.709 -r1.710 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.110 -r1.111 src/sys/arch/i386/include/pmap.h
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x86/include/intrdefs.h
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/x86/include/pmap.h
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/xen/include/xenpmap.h
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/xen/x86/cpu.c
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/xen/x86/x86_xpmap.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/xen/x86/xen_pmap.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/xen/x86/xenfunc.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/amd64/include/pmap.h
diff -u src/sys/arch/amd64/include/pmap.h:1.26 src/sys/arch/amd64/include/pmap.h:1.27
--- src/sys/arch/amd64/include/pmap.h:1.26	Sat Aug 27 16:23:44 2011
+++ src/sys/arch/amd64/include/pmap.h	Sun Nov  6 11:40:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.26 2011/08/27 16:23:44 christos Exp $	*/
+/*	$NetBSD: pmap.h,v 1.27 2011/11/06 11:40:46 cherry Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -277,9 +277,7 @@ static __inline void
 pmap_pte_set(pt_entry_t *pte, pt_entry_t npte)
 {
 	int s = splvm();
-	xpq_queue_lock();
 	xpq_queue_pte_update(xpmap_ptetomach(pte), npte);
-	xpq_queue_unlock();
 	splx(s);
 }
 
@@ -288,14 +286,12 @@ pmap_pte_cas(volatile pt_entry_t *ptep, 
 {
 	int s = splvm();
 
-	xpq_queue_lock();
 	pt_entry_t opte = *ptep;
 
 	if (opte == o) {
 		xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(ptep)), n);
 		xpq_flush_queue();
 	}
-	xpq_queue_unlock();
 	splx(s);
 	return opte;
 }
@@ -304,11 +300,9 @@ static __inline pt_entry_t
 pmap_pte_testset(volatile pt_entry_t *pte, pt_entry_t npte)
 {
 	int s = splvm();
-	xpq_queue_lock();
 	pt_entry_t opte = *pte;
 	xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)), npte);
 	xpq_flush_queue();
-	xpq_queue_unlock();
 	splx(s);
 	return opte;
 }
@@ -317,10 +311,8 @@ static __inline void
 pmap_pte_setbits(volatile pt_entry_t *pte, pt_entry_t bits)
 {
 	int s = splvm();
-	xpq_queue_lock();
 	xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)), (*pte) | bits);
 	xpq_flush_queue();
-	xpq_queue_unlock();
 	splx(s);
 }
 
@@ -328,11 +320,9 @@ static __inline void
 pmap_pte_clearbits(volatile pt_entry_t *pte, pt_entry_t bits)
 {	
 	int s = splvm();
-	xpq_queue_lock();
 	xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)),
 	(*pte)  ~bits);
 	xpq_flush_queue();
-	xpq_queue_unlock();
 	splx(s);
 }
 
@@ -340,9 +330,7 @@ static __inline void
 pmap_pte_flush(void)
 {
 	int s = splvm();
-	xpq_queue_lock();
 	xpq_flush_queue();
-	xpq_queue_unlock();
 	splx(s);
 }
 #endif

Index: src/sys/arch/i386/i386/gdt.c
diff -u src/sys/arch/i386/i386/gdt.c:1.51 src/sys/arch/i386/i386/gdt.c:1.52
--- src/sys/arch/i386/i386/gdt.c:1.51	Thu Aug 11 11:01:30 2011
+++ src/sys/arch/i386/i386/gdt.c	Sun Nov  6 11:40:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gdt.c,v 1.51 2011/08/11 11:01:30 cherry Exp $	*/
+/*	$NetBSD: gdt.c,v 1.52 2011/11/06 11:40:46 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gdt.c,v 1.51 2011/08/11 11:01:30 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: gdt.c,v 1.52 2011/11/06 11:40:46 cherry Exp $);
 
 #include opt_multiprocessor.h
 #include opt_xen.h
@@ -214,11 +214,9 @@ gdt_init_cpu(struct cpu_info *ci)
 		* properly yet, ie; curcpu() won't work at this
 		* point and spl() will break.
 		*/
-		   xpq_queue_lock();
 		   xpq_queue_pte_update(xpmap_ptetomach(ptp),
 	*ptp  ~PG_RW);
 		   xpq_flush_queue();
-		   xpq_queue_unlock();
 		}
 	}
 

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.709 src/sys/arch/i386/i386/machdep.c:1.710
--- src/sys/arch/i386/i386/machdep.c:1.709	Sat Aug 13 12:09:38 2011
+++ src/sys/arch/i386/i386/machdep.c	Sun Nov  6 11:40:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.709 2011/08/13 12:09:38 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.710 2011/11/06 11:40:46 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h

CVS commit: src/sys/arch

2011-11-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Nov  6 15:18:19 UTC 2011

Modified Files:
src/sys/arch/amd64/include: pmap.h
src/sys/arch/i386/include: pmap.h
src/sys/arch/x86/include: cpu.h
src/sys/arch/x86/x86: pmap.c
src/sys/arch/xen/x86: cpu.c x86_xpmap.c

Log Message:
[merging from cherry-xenmp] make pmap_kernel() shadow PMD per-cpu and MP aware.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/amd64/include/pmap.h
cvs rdiff -u -r1.111 -r1.112 src/sys/arch/i386/include/pmap.h
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.137 -r1.138 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/xen/x86/cpu.c
cvs rdiff -u -r1.35 -r1.36 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/amd64/include/pmap.h
diff -u src/sys/arch/amd64/include/pmap.h:1.27 src/sys/arch/amd64/include/pmap.h:1.28
--- src/sys/arch/amd64/include/pmap.h:1.27	Sun Nov  6 11:40:46 2011
+++ src/sys/arch/amd64/include/pmap.h	Sun Nov  6 15:18:18 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.27 2011/11/06 11:40:46 cherry Exp $	*/
+/*	$NetBSD: pmap.h,v 1.28 2011/11/06 15:18:18 cherry Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -192,7 +192,8 @@
 #define AL4_BASE ((pd_entry_t *)((char *)AL3_BASE + L4_SLOT_PTE * NBPD_L1))
 
 #define PDP_PDE		(L4_BASE + PDIR_SLOT_PTE)
-#define APDP_PDE	(L4_BASE + PDIR_SLOT_APTE)
+#define APDP_PDE	(curcpu()-ci_kpm_pdir[PDIR_SLOT_APTE])
+#define APDP_PDE_SHADOW	(L4_BASE + PDIR_SLOT_APTE)
 
 #define PDP_BASE	L4_BASE
 #define APDP_BASE	AL4_BASE

Index: src/sys/arch/i386/include/pmap.h
diff -u src/sys/arch/i386/include/pmap.h:1.111 src/sys/arch/i386/include/pmap.h:1.112
--- src/sys/arch/i386/include/pmap.h:1.111	Sun Nov  6 11:40:46 2011
+++ src/sys/arch/i386/include/pmap.h	Sun Nov  6 15:18:18 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.111 2011/11/06 11:40:46 cherry Exp $	*/
+/*	$NetBSD: pmap.h,v 1.112 2011/11/06 15:18:18 cherry Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -277,7 +277,7 @@
  * mapping, because it points to the shadow PD. Use the kernel PD instead,
  * which is static
  */
-#define APDP_PDE	(pmap_kl2pd[l2tol2(PDIR_SLOT_APTE)])
+#define APDP_PDE	(curcpu()-ci_kpm_pdir[l2tol2(PDIR_SLOT_APTE)])
 #define APDP_PDE_SHADOW	(L2_BASE + PDIR_SLOT_APTE)
 #else /* PAE  XEN */
 #define APDP_PDE	(L2_BASE + PDIR_SLOT_APTE)
@@ -428,13 +428,6 @@ pmap_pte_flush(void)
 
 #endif
 
-#ifdef PAE
-/* Address of the static kernel's L2 page */
-pd_entry_t *pmap_kl2pd;
-paddr_t pmap_kl2paddr;
-#endif
-
-
 struct trapframe;
 
 int	pmap_exec_fixup(struct vm_map *, struct trapframe *, struct pcb *);

Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.40 src/sys/arch/x86/include/cpu.h:1.41
--- src/sys/arch/x86/include/cpu.h:1.40	Tue Nov  1 21:21:32 2011
+++ src/sys/arch/x86/include/cpu.h	Sun Nov  6 15:18:18 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.40 2011/11/01 21:21:32 joerg Exp $	*/
+/*	$NetBSD: cpu.h,v 1.41 2011/11/06 15:18:18 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -176,16 +176,19 @@ struct cpu_info {
 #endif
 
 #ifdef PAE
-	uint32_t	ci_pae_l3_pdirpa; /* PA of L3 PD */
+	paddr_t	ci_pae_l3_pdirpa; /* PA of L3 PD */
 	pd_entry_t *	ci_pae_l3_pdir; /* VA pointer to L3 PD */
 #endif
 
-#if defined(XEN)  defined(__x86_64__)
+#if defined(XEN)  (defined(PAE) || defined(__x86_64__))
 	/* Currently active user PGD (can't use rcr3() with Xen) */
-	pd_entry_t *	ci_kpm_pdir;	/* per-cpu L4 PD (va) */
-	paddr_t		ci_kpm_pdirpa; /* per-cpu L4 PD (pa) */
+	pd_entry_t *	ci_kpm_pdir;	/* per-cpu PMD (va) */
+	paddr_t		ci_kpm_pdirpa; /* per-cpu PMD (pa) */
+#if defined(__x86_64__)
 	paddr_t		ci_xen_current_user_pgd;
-#endif
+#endif /* __x86_64__ */
+#endif /* XEN et.al */
+
 
 	char *ci_doubleflt_stack;
 	char *ci_ddbipi_stack;
@@ -233,11 +236,6 @@ struct cpu_info {
 	int		ci_padout __aligned(64);
 };
 
-#ifdef __x86_64__
-#define ci_pdirpa(ci, index) \
-	((ci)-ci_kpm_pdirpa + (index) * sizeof(pd_entry_t))
-#endif /* __x86_64__ */
-
 /*
  * Macros to handle (some) trapframe registers for common x86 code.
  */

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.137 src/sys/arch/x86/x86/pmap.c:1.138
--- src/sys/arch/x86/x86/pmap.c:1.137	Tue Oct 18 23:43:06 2011
+++ src/sys/arch/x86/x86/pmap.c	Sun Nov  6 15:18:18 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.137 2011/10/18 23:43:06 jym Exp $	*/
+/*	$NetBSD: pmap.c,v 1.138 2011/11/06 15:18:18 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.137 2011/10/18 23:43:06 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.138 2011/11/06 15:18:18 cherry Exp 

CVS commit: src/sys/arch/i386/i386

2011-11-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Nov  6 15:35:29 UTC 2011

Modified Files:
src/sys/arch/i386/i386: machdep.c

Log Message:
DTRT when initialising pmap_pa_end.


To generate a diff of this commit:
cvs rdiff -u -r1.710 -r1.711 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.710 src/sys/arch/i386/i386/machdep.c:1.711
--- src/sys/arch/i386/i386/machdep.c:1.710	Sun Nov  6 11:40:46 2011
+++ src/sys/arch/i386/i386/machdep.c	Sun Nov  6 15:35:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.710 2011/11/06 11:40:46 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.711 2011/11/06 15:35:29 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.710 2011/11/06 11:40:46 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.711 2011/11/06 15:35:29 cherry Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -1440,7 +1440,7 @@ init386(paddr_t first_avail)
 	avail_start = first_avail;
 	avail_end = ctob(xen_start_info.nr_pages) + XPMAP_OFFSET;
 	pmap_pa_start = (KERNTEXTOFF - KERNBASE);
-	pmap_pa_end = avail_end;
+	pmap_pa_end = pmap_pa_start + ctob(xen_start_info.nr_pages);
 	mem_clusters[0].start = avail_start;
 	mem_clusters[0].size = avail_end - avail_start;
 	mem_cluster_cnt++;



CVS commit: src/sys/arch/amd64/amd64

2011-11-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Nov  6 15:51:09 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
DTRT with macros and use xen's info page when initialising pmap_pa_start and 
pmap_pa_end.


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/sys/arch/amd64/amd64/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/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.168 src/sys/arch/amd64/amd64/machdep.c:1.169
--- src/sys/arch/amd64/amd64/machdep.c:1.168	Mon Oct 31 12:42:36 2011
+++ src/sys/arch/amd64/amd64/machdep.c	Sun Nov  6 15:51:09 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.168 2011/10/31 12:42:36 yamt Exp $	*/
+/*	$NetBSD: machdep.c,v 1.169 2011/11/06 15:51:09 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.168 2011/10/31 12:42:36 yamt Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.169 2011/11/06 15:51:09 cherry Exp $);
 
 /* #define XENDEBUG_LOW  */
 
@@ -1684,8 +1684,8 @@ init_x86_64(paddr_t first_avail)
 	/* Determine physical address space */
 	avail_start = first_avail;
 	avail_end = ctob(xen_start_info.nr_pages);
-	pmap_pa_start = (KERNTEXTOFF - KERNBASE);
-	pmap_pa_end = avail_end;
+	pmap_pa_start = XPMAP_OFFSET;
+	pmap_pa_end = pmap_pa_start + ctob(xen_start_info.nr_pages);
 	__PRINTK((pmap_pa_start 0x%lx avail_start 0x%lx avail_end 0x%lx\n,
 	pmap_pa_start, avail_start, avail_end));
 #endif	/* !XEN */



CVS commit: src/sys/arch/amd64/amd64

2011-11-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Nov  6 15:53:04 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Use the right format strings with printf


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/amd64/amd64/trap.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/amd64/amd64/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.67 src/sys/arch/amd64/amd64/trap.c:1.68
--- src/sys/arch/amd64/amd64/trap.c:1.67	Wed Oct  5 20:39:24 2011
+++ src/sys/arch/amd64/amd64/trap.c	Sun Nov  6 15:53:04 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.67 2011/10/05 20:39:24 njoly Exp $	*/
+/*	$NetBSD: trap.c,v 1.68 2011/11/06 15:53:04 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.67 2011/10/05 20:39:24 njoly Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.68 2011/11/06 15:53:04 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_kgdb.h
@@ -275,7 +275,7 @@ trap(struct trapframe *frame)
 		else
 			printf(unknown trap %ld, (u_long)frame-tf_trapno);
 		printf( in %s mode\n, (type  T_USER) ? user : supervisor);
-		printf(trap type %d code %lx rip %lx cs %lx rflags %lx cr2
+		printf(trap type %d code %lx rip %lx cs %lx rflags %lx cr2 
 		%lx cpl %x rsp %lx\n,
 		type, frame-tf_err, (u_long)frame-tf_rip, frame-tf_cs,
 		frame-tf_rflags, rcr2(), curcpu()-ci_ilevel, frame-tf_rsp);
@@ -733,7 +733,7 @@ frame_dump(struct trapframe *tf)
 	(void *)tf-tf_r13, (void *)tf-tf_r14, (void *)tf-tf_r15);
 	printf(rbp %p  rbx %p  rax %p\n,
 	(void *)tf-tf_rbp, (void *)tf-tf_rbx, (void *)tf-tf_rax);
-	printf(cs %p  ds %p  es %p  fs %p  gs %p  ss %p\n,
+	printf(cs %lx  ds %lx  es %lx  fs %lx  gs %lx  ss %lx\n,
 		tf-tf_cs  0x, tf-tf_ds  0x, tf-tf_es  0x,
 		tf-tf_fs  0x, tf-tf_gs  0x, tf-tf_ss  0x);
 	



CVS commit: src/sys/arch/xen

2011-11-07 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Nov  7 15:51:31 UTC 2011

Modified Files:
src/sys/arch/xen/include: intrdefs.h
src/sys/arch/xen/x86: xen_ipi.c

Log Message:
Add an ipi callback to force hypervisor callback. this is useful to re-route 
interrupts to a given vcpu


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/xen/include/intrdefs.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/xen/x86/xen_ipi.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/include/intrdefs.h
diff -u src/sys/arch/xen/include/intrdefs.h:1.10 src/sys/arch/xen/include/intrdefs.h:1.11
--- src/sys/arch/xen/include/intrdefs.h:1.10	Wed Aug 10 06:29:23 2011
+++ src/sys/arch/xen/include/intrdefs.h	Mon Nov  7 15:51:31 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: intrdefs.h,v 1.10 2011/08/10 06:29:23 cherry Exp $ */
+/* $NetBSD: intrdefs.h,v 1.11 2011/11/07 15:51:31 cherry Exp $ */
 
 /* This file co-exists, and is included via machine/intrdefs.h */
 
@@ -11,7 +11,8 @@
 #define XEN_IPI_SYNCH_FPU	0x0002
 #define XEN_IPI_DDB		0x0004
 #define XEN_IPI_XCALL		0x0008
+#define XEN_IPI_HVCB		0x0010
 
-#define XEN_NIPIS 4 /* IPI_KICK doesn't have a handler */
+#define XEN_NIPIS 5 /* IPI_KICK doesn't have a handler */
 
 #endif /* _XEN_INTRDEFS_H_ */

Index: src/sys/arch/xen/x86/xen_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.5 src/sys/arch/xen/x86/xen_ipi.c:1.6
--- src/sys/arch/xen/x86/xen_ipi.c:1.5	Tue Sep 27 01:02:37 2011
+++ src/sys/arch/xen/x86/xen_ipi.c	Mon Nov  7 15:51:31 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.5 2011/09/27 01:02:37 jym Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.6 2011/11/07 15:51:31 cherry Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -33,10 +33,10 @@
 
 /* 
  * Based on: x86/ipi.c
- * __KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.5 2011/09/27 01:02:37 jym Exp $); 
+ * __KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.6 2011/11/07 15:51:31 cherry Exp $); 
  */
 
-__KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.5 2011/09/27 01:02:37 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.6 2011/11/07 15:51:31 cherry Exp $);
 
 #include sys/types.h
 
@@ -72,13 +72,15 @@ static void xen_ipi_halt(struct cpu_info
 static void xen_ipi_synch_fpu(struct cpu_info *, struct intrframe *);
 static void xen_ipi_ddb(struct cpu_info *, struct intrframe *);
 static void xen_ipi_xcall(struct cpu_info *, struct intrframe *);
+static void xen_ipi_hvcb(struct cpu_info *, struct intrframe *);
 
 static void (*ipifunc[XEN_NIPIS])(struct cpu_info *, struct intrframe *) =
 {	/* In order of priority (see: xen/include/intrdefs.h */
 	xen_ipi_halt,
 	xen_ipi_synch_fpu,
 	xen_ipi_ddb,
-	xen_ipi_xcall
+	xen_ipi_xcall,
+	xen_ipi_hvcb
 };
 
 static void
@@ -139,9 +141,9 @@ static inline u_int max_cpus(void)
 static inline bool /* helper */
 valid_ipimask(uint32_t ipimask)
 {
-	uint32_t masks =  XEN_IPI_XCALL | XEN_IPI_DDB | 
-		XEN_IPI_SYNCH_FPU | XEN_IPI_HALT | 
-		XEN_IPI_KICK;
+	uint32_t masks =  XEN_IPI_HVCB | XEN_IPI_XCALL |
+		 XEN_IPI_DDB | XEN_IPI_SYNCH_FPU |
+		 XEN_IPI_HALT | XEN_IPI_KICK;
 
 	if (ipimask  ~masks) {
 		return false;
@@ -296,3 +298,16 @@ xc_send_ipi(struct cpu_info *ci)
 		xen_broadcast_ipi(XEN_IPI_XCALL);
 	}
 }
+
+static void
+xen_ipi_hvcb(struct cpu_info *ci, struct intrframe *intrf)
+{
+	KASSERT(ci != NULL);
+	KASSERT(intrf != NULL);
+
+	volatile struct vcpu_info *vci = ci-ci_vcpu;
+
+	KASSERT(ci == curcpu());
+	KASSERT(!vci-evtchn_upcall_mask);
+	hypervisor_force_callback();
+}



CVS commit: src/sys/arch

2011-11-08 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Tue Nov  8 17:16:52 UTC 2011

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

Log Message:
Expose the PG_k #define pt/pd bit to both xen and baremetal x86. This is 
required, since kernel pages are mapped with user permissions in XEN/amd64 
since the VM kernel runs in ring3. Since XEN/i386(including PAE) runs in ring1, 
supervisor mode is appropriate for these ports. We need to share this since the 
pmap implementation is still shared. Once the xen implementation is 
sufficiently independant of the x86 one, this can be made private to 
xen/include/xenpmap.h


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/x86/include/pmap.h
cvs rdiff -u -r1.140 -r1.141 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/xen/include/xenpmap.h
cvs rdiff -u -r1.7 -r1.8 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/include/pmap.h
diff -u src/sys/arch/x86/include/pmap.h:1.44 src/sys/arch/x86/include/pmap.h:1.45
--- src/sys/arch/x86/include/pmap.h:1.44	Sun Nov  6 11:40:47 2011
+++ src/sys/arch/x86/include/pmap.h	Tue Nov  8 17:16:52 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.44 2011/11/06 11:40:47 cherry Exp $	*/
+/*	$NetBSD: pmap.h,v 1.45 2011/11/08 17:16:52 cherry Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -173,6 +173,16 @@ struct pmap {
 	((pmap)-pm_pdirpa[0] + (index) * sizeof(pd_entry_t))
 #endif
 
+/* 
+ * flag to be used for kernel mappings: PG_u on Xen/amd64, 
+ * 0 otherwise.
+ */
+#if defined(XEN)  defined(__x86_64__)
+#define PG_k PG_u
+#else
+#define PG_k 0
+#endif
+
 /*
  * MD flags that we use for pmap_enter and pmap_kenter_pa:
  */

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.140 src/sys/arch/x86/x86/pmap.c:1.141
--- src/sys/arch/x86/x86/pmap.c:1.140	Tue Nov  8 12:44:29 2011
+++ src/sys/arch/x86/x86/pmap.c	Tue Nov  8 17:16:52 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.140 2011/11/08 12:44:29 njoly Exp $	*/
+/*	$NetBSD: pmap.c,v 1.141 2011/11/08 17:16:52 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.140 2011/11/08 12:44:29 njoly Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.141 2011/11/08 17:16:52 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -211,11 +211,6 @@ __KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.1
 #include xen/hypervisor.h
 #endif
 
-/* If this is not needed anymore it should be GC'ed */
-#ifndef PG_k
-#define	PG_k	0
-#endif
-
 /*
  * general info:
  *

Index: src/sys/arch/xen/include/xenpmap.h
diff -u src/sys/arch/xen/include/xenpmap.h:1.30 src/sys/arch/xen/include/xenpmap.h:1.31
--- src/sys/arch/xen/include/xenpmap.h:1.30	Sun Nov  6 11:40:47 2011
+++ src/sys/arch/xen/include/xenpmap.h	Tue Nov  8 17:16:52 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xenpmap.h,v 1.30 2011/11/06 11:40:47 cherry Exp $	*/
+/*	$NetBSD: xenpmap.h,v 1.31 2011/11/08 17:16:52 cherry Exp $	*/
 
 /*
  *
@@ -34,13 +34,6 @@
 #include opt_xen.h
 #endif
 
-/* flag to be used for kernel mappings: PG_u on Xen/amd64, 0 otherwise */
-#if defined(XEN)  defined(__x86_64__)
-#define PG_k PG_u
-#else
-#define PG_k 0
-#endif
-
 #define	INVALID_P2M_ENTRY	(~0UL)
 
 void xpq_queue_machphys_update(paddr_t, paddr_t);

Index: src/sys/arch/xen/x86/xen_pmap.c
diff -u src/sys/arch/xen/x86/xen_pmap.c:1.7 src/sys/arch/xen/x86/xen_pmap.c:1.8
--- src/sys/arch/xen/x86/xen_pmap.c:1.7	Sun Nov  6 11:40:47 2011
+++ src/sys/arch/xen/x86/xen_pmap.c	Tue Nov  8 17:16:52 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_pmap.c,v 1.7 2011/11/06 11:40:47 cherry Exp $	*/
+/*	$NetBSD: xen_pmap.c,v 1.8 2011/11/08 17:16:52 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -102,7 +102,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: xen_pmap.c,v 1.7 2011/11/06 11:40:47 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_pmap.c,v 1.8 2011/11/08 17:16:52 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -142,13 +142,6 @@ __KERNEL_RCSID(0, $NetBSD: xen_pmap.c,v
 #include xen/hypervisor.h
 #endif
 
-/* flag to be used for kernel mappings: PG_u on Xen/amd64, 0 otherwise */
-#if defined(XEN)  defined(__x86_64__)
-#define PG_k PG_u
-#else
-#define PG_k 0
-#endif
-
 #define COUNT(x)	/* nothing */
 
 static pd_entry_t * const alternate_pdes[] = APDES_INITIALIZER;



CVS commit: src/sys/arch/xen/xen

2011-11-17 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Nov 18 06:01:50 UTC 2011

Modified Files:
src/sys/arch/xen/xen: clock.c

Log Message:
[merging from cherry-xenmp]
 - Make clock MP aware.
 - Bring in fixes that bouyer@ brought in via:
   cvs rdiff -u -r1.54.6.4 -r1.54.6.5 src/sys/arch/xen/xen/clock.c

Thanks to riz@ for testing on dom0


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/xen/xen/clock.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/xen/clock.c
diff -u src/sys/arch/xen/xen/clock.c:1.56 src/sys/arch/xen/xen/clock.c:1.57
--- src/sys/arch/xen/xen/clock.c:1.56	Tue Sep 20 00:12:24 2011
+++ src/sys/arch/xen/xen/clock.c	Fri Nov 18 06:01:50 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.56 2011/09/20 00:12:24 jym Exp $	*/
+/*	$NetBSD: clock.c,v 1.57 2011/11/18 06:01:50 cherry Exp $	*/
 
 /*
  *
@@ -29,7 +29,7 @@
 #include opt_xen.h
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.56 2011/09/20 00:12:24 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.57 2011/11/18 06:01:50 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -43,6 +43,7 @@ __KERNEL_RCSID(0, $NetBSD: clock.c,v 1.
 #include xen/xen.h
 #include xen/hypervisor.h
 #include xen/evtchn.h
+#include xen/xen3-public/vcpu.h
 #include machine/cpu_counter.h
 
 #include dev/clock_subr.h
@@ -66,22 +67,32 @@ static struct timecounter xen_timecounte
 };
 
 /* These are periodically updated in shared_info, and then copied here. */
-static volatile uint64_t shadow_tsc_stamp;
-static volatile uint64_t shadow_system_time;
-static volatile unsigned long shadow_time_version; /* XXXSMP */
-static volatile uint32_t shadow_freq_mul;
-static volatile int8_t shadow_freq_shift;
-static volatile struct timespec shadow_ts;
+struct shadow {
+	uint64_t tsc_stamp;
+	uint64_t system_time;
+	unsigned long time_version; /* XXXSMP */
+	uint32_t freq_mul;
+	int8_t freq_shift;
+	struct timespec ts;
+};
+
+/* Protects volatile variables ci_shadow  xen_clock_bias */
+static kmutex_t tmutex;
 
-/* The time when the last hardclock(9) call should have taken place. */
-static volatile uint64_t processed_system_time;
+/* Per CPU shadow time values */
+static volatile struct shadow ci_shadow[MAXCPUS];
+
+/* The time when the last hardclock(9) call should have taken place,
+ * per cpu.
+ */
+static volatile uint64_t vcpu_system_time[MAXCPUS];
 
 /*
  * The clock (as returned by xen_get_timecount) may need to be held
  * back to maintain the illusion that hardclock(9) was called when it
  * was supposed to be, not when Xen got around to scheduling us.
  */
-static volatile uint64_t xen_clock_bias = 0;
+static volatile uint64_t xen_clock_bias[MAXCPUS];
 
 #ifdef DOM0OPS
 /* If we're dom0, send our time to Xen every minute or so. */
@@ -96,25 +107,30 @@ static callout_t xen_timepush_co;
  * area.  Must be called at splhigh (per timecounter requirements).
  */
 static void
-get_time_values_from_xen(void)
+get_time_values_from_xen(struct cpu_info *ci)
 {
-	volatile struct vcpu_time_info *t = curcpu()-ci_vcpu-time;
+
+	volatile struct shadow *shadow = ci_shadow[ci-ci_cpuid];
+
+	volatile struct vcpu_time_info *t = ci-ci_vcpu-time;
 	uint32_t tversion;
 
+	KASSERT(mutex_owned(tmutex));
+
 	do {
-		shadow_time_version = t-version;
+		shadow-time_version = t-version;
 		xen_rmb();
-		shadow_tsc_stamp = t-tsc_timestamp;
-		shadow_system_time = t-system_time;
-		shadow_freq_mul = t-tsc_to_system_mul;
-		shadow_freq_shift = t-tsc_shift;
+		shadow-tsc_stamp = t-tsc_timestamp;
+		shadow-system_time = t-system_time;
+		shadow-freq_mul = t-tsc_to_system_mul;
+		shadow-freq_shift = t-tsc_shift;
 		xen_rmb();
-	} while ((t-version  1) || (shadow_time_version != t-version));
+	} while ((t-version  1) || (shadow-time_version != t-version));
 	do {
 		tversion = HYPERVISOR_shared_info-wc_version;
 		xen_rmb();
-		shadow_ts.tv_sec = HYPERVISOR_shared_info-wc_sec;
-		shadow_ts.tv_nsec = HYPERVISOR_shared_info-wc_nsec;
+		shadow-ts.tv_sec = HYPERVISOR_shared_info-wc_sec;
+		shadow-ts.tv_nsec = HYPERVISOR_shared_info-wc_nsec;
 		xen_rmb();
 	} while ((HYPERVISOR_shared_info-wc_version  1) ||
 	(tversion != HYPERVISOR_shared_info-wc_version));
@@ -124,12 +140,17 @@ get_time_values_from_xen(void)
  * Are the values we have up to date?
  */
 static inline int
-time_values_up_to_date(void)
+time_values_up_to_date(struct cpu_info *ci)
 {
 	int rv;
 
+	volatile struct shadow *shadow = ci_shadow[ci-ci_cpuid];
+
+	KASSERT(ci != NULL);
+	KASSERT(mutex_owned(tmutex));
+
 	xen_rmb();
-	rv = shadow_time_version == curcpu()-ci_vcpu-time.version;
+	rv = shadow-time_version == ci-ci_vcpu-time.version;
 	xen_rmb();
 
 	return rv;
@@ -164,52 +185,40 @@ scale_delta(uint64_t delta, uint32_t mul
  * Must be called at splhigh (per timecounter requirements).
  */
 static uint64_t
-get_tsc_offset_ns(void)
+get_tsc_offset_ns(struct cpu_info *ci)

CVS commit: src/sys/arch

2011-11-19 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov 19 17:13:39 UTC 2011

Modified Files:
src/sys/arch/x86/include: cpu.h
src/sys/arch/xen/include: hypervisor.h
src/sys/arch/xen/x86: hypervisor_machdep.c
src/sys/arch/xen/xen: evtchn.c

Log Message:
[merging from cherry-xenmp] bring in bouyer@'s changes via:
http://mail-index.netbsd.org/source-changes/2011/10/22/msg028271.html
From the Log:
Log Message:
Various interrupt fixes, mainly:
keep a per-cpu mask of enabled events, and use it to get pending events.
A cpu-specific event (all of them at this time) should not be ever masked
by another CPU, because it may prevent the target CPU from seeing it
(the clock events all fires at once for example).


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/xen/xen/evtchn.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/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.42 src/sys/arch/x86/include/cpu.h:1.43
--- src/sys/arch/x86/include/cpu.h:1.42	Thu Nov 10 00:12:05 2011
+++ src/sys/arch/x86/include/cpu.h	Sat Nov 19 17:13:39 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.42 2011/11/10 00:12:05 jym Exp $	*/
+/*	$NetBSD: cpu.h,v 1.43 2011/11/19 17:13:39 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -126,6 +126,7 @@ struct cpu_info {
 
 #ifdef XEN
 	struct iplsource  *ci_isources[NIPL];
+	u_long ci_evtmask[NR_EVENT_CHANNELS]; /* events allowed on this CPU */
 #else
 	struct intrsource *ci_isources[MAX_INTR_SOURCES];
 #endif

Index: src/sys/arch/xen/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.34 src/sys/arch/xen/include/hypervisor.h:1.35
--- src/sys/arch/xen/include/hypervisor.h:1.34	Sun Nov  6 11:40:47 2011
+++ src/sys/arch/xen/include/hypervisor.h	Sat Nov 19 17:13:39 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.34 2011/11/06 11:40:47 cherry Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.35 2011/11/19 17:13:39 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -134,6 +134,7 @@ void do_hypervisor_callback(struct intrf
 void hypervisor_enable_event(unsigned int);
 
 /* hypervisor_machdep.c */
+void hypervisor_send_event(struct cpu_info *, unsigned int);
 void hypervisor_unmask_event(unsigned int);
 void hypervisor_mask_event(unsigned int);
 void hypervisor_clear_event(unsigned int);

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.16 src/sys/arch/xen/x86/hypervisor_machdep.c:1.17
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.16	Tue Sep 20 00:12:24 2011
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Sat Nov 19 17:13:39 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.16 2011/09/20 00:12:24 jym Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.17 2011/11/19 17:13:39 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.16 2011/09/20 00:12:24 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.17 2011/11/19 17:13:39 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -109,6 +109,7 @@ evt_iterate_bits(struct cpu_info *ci, vo
 		l1 = ~(1UL  l1i);
 
 		l2 = pendingl2[l1i]  (mask != NULL ? ~mask[l1i] : -1UL);
+		l2 = ci-ci_evtmask[l1i];
 
 		if (mask != NULL) xen_atomic_setbits_l(mask[l1i], l2);
 		xen_atomic_clearbits_l(pendingl2[l1i], l2);
@@ -140,8 +141,8 @@ evt_set_pending(struct cpu_info *ci, uns
 	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)
@@ -281,6 +282,36 @@ do_hypervisor_callback(struct intrframe 
 }
 
 void
+hypervisor_send_event(struct cpu_info *ci, unsigned int ev)
+{
+	KASSERT(ci != NULL);
+
+	volatile shared_info_t *s = HYPERVISOR_shared_info;
+	volatile struct vcpu_info *vci = ci-ci_vcpu;
+
+#ifdef PORT_DEBUG
+	if (ev == PORT_DEBUG)
+		printf(hypervisor_send_event %d\n, ev);
+#endif
+
+	xen_atomic_set_bit(s-evtchn_pending[0], ev);
+	xen_atomic_set_bit(vci-evtchn_pending_sel,
+			   ev  LONG_SHIFT);
+
+	xen_atomic_set_bit(vci-evtchn_upcall_pending, 0);
+
+	xen_atomic_clear_bit(s-evtchn_mask[0], ev);
+
+	if (__predict_true(ci == curcpu())) {
+		hypervisor_force_callback();
+	} else {
+		if (xen_send_ipi(ci, XEN_IPI_HVCB)) {
+			panic(xen_send_ipi(cpu%d, XEN_IPI_HVCB) failed\n, (int) ci-ci_cpuid);
+		}
+	}
+}
+
+void
 hypervisor_unmask_event(unsigned int ev)
 {
 	volatile shared_info_t *s = HYPERVISOR_shared_info;
@@ -375,6 +406,13 @@ 

CVS commit: src/sys/arch/x86/x86

2011-12-03 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Dec  4 04:28:41 UTC 2011

Modified Files:
src/sys/arch/x86/x86: pmap_tlb.c

Log Message:
Split out the cross-CPU tlb flushing code between XEN and non-XEN.
x86 tlb flushing is asynchronous and uses x86_ipi()
XEN tlb flushing uses synchronous hypercalls.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x86/x86/pmap_tlb.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_tlb.c
diff -u src/sys/arch/x86/x86/pmap_tlb.c:1.3 src/sys/arch/x86/x86/pmap_tlb.c:1.4
--- src/sys/arch/x86/x86/pmap_tlb.c:1.3	Wed Jun 15 20:50:02 2011
+++ src/sys/arch/x86/x86/pmap_tlb.c	Sun Dec  4 04:28:41 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.3 2011/06/15 20:50:02 rmind Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.4 2011/12/04 04:28:41 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2008-2011 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pmap_tlb.c,v 1.3 2011/06/15 20:50:02 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap_tlb.c,v 1.4 2011/12/04 04:28:41 cherry Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -52,7 +52,9 @@ __KERNEL_RCSID(0, $NetBSD: pmap_tlb.c,v
 #include uvm/uvm.h
 
 #include machine/cpuvar.h
-#include x86/pmap.h
+#ifdef XEN
+#include xen/xenpmap.h
+#endif /* XEN */
 #include x86/i82489reg.h
 #include x86/i82489var.h
 
@@ -261,6 +263,64 @@ pmap_tlb_shootdown(struct pmap *pm, vadd
 	splx(s);
 }
 
+#ifdef MULTIPROCESSOR
+#ifdef XEN
+static inline
+void pmap_tlb_processpacket(pmap_tlb_packet_t *tp)
+{
+	struct cpu_info *self = curcpu();
+	if (tp-tp_count == (uint16_t)-1) {
+		xen_mcast_tlbflush(tp-tp_cpumask 
+   cpus_running 
+   ~self-ci_cpumask);
+	} else {
+		/* Invalidating a single page or a range of pages. */
+		int i;
+		for (i = tp-tp_count - 1; i = 0; i--) {
+			xen_mcast_invlpg(tp-tp_va[i],
+	 tp-tp_cpumask  
+	 cpus_running 
+	 ~self-ci_cpumask);
+		}
+	}
+
+	/* Ack the request */
+	atomic_and_32(pmap_tlb_mailbox.tm_pending, ~tp-tp_cpumask);
+}
+#else /* XEN */
+static inline 
+void pmap_tlb_processpacket(pmap_tlb_packet_t *tp)
+{
+	int err = 0;
+	CPU_INFO_ITERATOR cii;
+	struct cpu_info *lci;
+
+	if (tp-tp_cpumask == cpus_running) {
+		err = x86_ipi(LAPIC_TLB_VECTOR, LAPIC_DEST_ALLEXCL,
+		LAPIC_DLMODE_FIXED);
+	} else {
+		struct cpu_info *self = curcpu();
+		for (CPU_INFO_FOREACH(cii, lci)) {
+			if (__predict_false(lci == self)) {
+continue;
+			}
+			if ((lci-ci_cpumask  pmap_tlb_mailbox.tm_pending) == 0) {
+continue;
+			}
+			KASSERT(lci-ci_flags  CPUF_RUNNING);
+
+			err |= x86_ipi(LAPIC_TLB_VECTOR,
+   lci-ci_cpuid, LAPIC_DLMODE_FIXED);
+		}
+	}
+
+	if (__predict_false(err != 0)) {
+		panic(pmap_tlb_shootdown: IPI failed);
+	}
+}
+#endif /* XEN */
+#endif /* MULTIPROCESSOR */
+
 /*
  * pmap_tlb_shootnow: process pending TLB shootdowns queued on current CPU.
  *
@@ -297,9 +357,7 @@ pmap_tlb_shootnow(void)
 
 #ifdef MULTIPROCESSOR
 	if (remote != 0) {
-		CPU_INFO_ITERATOR cii;
-		struct cpu_info *lci;
-		int count, err;
+		int count;
 		/*
 		 * Gain ownership of the shootdown mailbox.  We must stay
 		 * at IPL_VM once we own it or could deadlock against an
@@ -330,29 +388,19 @@ pmap_tlb_shootnow(void)
 		/*
 		 * Initiate shootdowns on remote CPUs.
 		 */
-		if (tp-tp_cpumask == cpus_running) {
-			err = x86_ipi(LAPIC_TLB_VECTOR, LAPIC_DEST_ALLEXCL,
-			LAPIC_DLMODE_FIXED);
-		} else {
-			err = 0;
-			for (CPU_INFO_FOREACH(cii, lci)) {
-if ((lci-ci_cpumask  remote) == 0) {
-	continue;
-}
-if ((lci-ci_flags  CPUF_RUNNING) == 0) {
-	remote = ~lci-ci_cpumask;
-	atomic_and_32(tm-tm_pending, remote);
-	continue;
-}
-err |= x86_ipi(LAPIC_TLB_VECTOR,
-lci-ci_cpuid, LAPIC_DLMODE_FIXED);
-			}
-		}
-		if (__predict_false(err != 0)) {
-			panic(pmap_tlb_shootdown: IPI failed);
-		}
+		/* Trim mailbox wait to only for CPUF_RUNNING cpus */
+		atomic_and_32(tm-tm_pending, cpus_running);
+
+		pmap_tlb_processpacket(tp);
+#ifdef XEN
+		/* 
+		 * remote CPUs have been synchronously flushed
+		 */
+		remote = 0; 
+#endif /* XEN */
 	}
-#endif
+#endif /* MULTIPROCESSOR */
+
 	/*
 	 * Shootdowns on remote CPUs are now in flight.  In the meantime,
 	 * perform local shootdowns and do not forget to update emap gen.



CVS commit: src/sys/arch/xen/xen

2011-12-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Dec  4 15:15:41 UTC 2011

Modified Files:
src/sys/arch/xen/xen: if_xennet_xenbus.c

Log Message:
[merging from cherry-xenmp]
Make MP aware: use mutex(9) instead of spl(9)


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/xen/xen/if_xennet_xenbus.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/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.54 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.55
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.54	Sat Nov 19 22:51:21 2011
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Sun Dec  4 15:15:41 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.54 2011/11/19 22:51:21 tls Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.55 2011/12/04 15:15:41 cherry Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -85,7 +85,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_xennet_xenbus.c,v 1.54 2011/11/19 22:51:21 tls Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_xennet_xenbus.c,v 1.55 2011/12/04 15:15:41 cherry Exp $);
 
 #include opt_xen.h
 #include opt_nfs_boot.h
@@ -188,6 +188,8 @@ struct xennet_xenbus_softc {
 	grant_ref_t sc_tx_ring_gntref;
 	grant_ref_t sc_rx_ring_gntref;
 
+	kmutex_t sc_tx_lock; /* protects free TX list, below */
+	kmutex_t sc_rx_lock; /* protects free RX list, below */
 	struct xennet_txreq sc_txreqs[NET_TX_RING_SIZE];
 	struct xennet_rxreq sc_rxreqs[NET_RX_RING_SIZE];
 	SLIST_HEAD(,xennet_txreq) sc_txreq_head; /* list of free TX requests */
@@ -305,12 +307,14 @@ xennet_xenbus_attach(device_t parent, de
 	sc-sc_xbusd-xbusd_otherend_changed = xennet_backend_changed;
 
 	/* initialize free RX and RX request lists */
+	mutex_init(sc-sc_tx_lock, MUTEX_DEFAULT, IPL_NET);
 	SLIST_INIT(sc-sc_txreq_head);
 	for (i = 0; i  NET_TX_RING_SIZE; i++) {
 		sc-sc_txreqs[i].txreq_id = i;
 		SLIST_INSERT_HEAD(sc-sc_txreq_head, sc-sc_txreqs[i],
 		txreq_next);
 	}
+	mutex_init(sc-sc_rx_lock, MUTEX_DEFAULT, IPL_NET);
 	SLIST_INIT(sc-sc_rxreq_head);
 	s = splvm();
 	for (i = 0; i  NET_RX_RING_SIZE; i++) {
@@ -680,12 +684,12 @@ xennet_alloc_rx_buffer(struct xennet_xen
 	RING_IDX i;
 	struct xennet_rxreq *req;
 	struct xen_memory_reservation reservation;
-	int s1, s2, otherend_id;
+	int s, otherend_id;
 	paddr_t pfn;
 
 	otherend_id = sc-sc_xbusd-xbusd_otherend_id;
 
-	s1 = splnet();
+	mutex_enter(sc-sc_rx_lock);
 	for (i = 0; sc-sc_free_rxreql != 0; i++) {
 		req  = SLIST_FIRST(sc-sc_rxreq_head);
 		KASSERT(req != NULL);
@@ -734,7 +738,7 @@ xennet_alloc_rx_buffer(struct xennet_xen
 
 out_loop:
 	if (i == 0) {
-		splx(s1);
+		mutex_exit(sc-sc_rx_lock);
 		return;
 	}
 
@@ -747,9 +751,9 @@ out_loop:
 		 * outstanding in the page update queue -- make sure we flush
 		 * those first!
 		 */
-		s2 = splvm();
+		s = splvm();
 		xpq_flush_queue();
-		splx(s2);
+		splx(s);
 		/* now decrease reservation */
 		xenguest_handle(reservation.extent_start) = xennet_pages;
 		reservation.nr_extents = i;
@@ -769,7 +773,7 @@ out_loop:
 	sc-sc_rx_ring.req_prod_pvt = req_prod + i;
 	RING_PUSH_REQUESTS(sc-sc_rx_ring);
 
-	splx(s1);
+	mutex_exit(sc-sc_rx_lock);
 	return;
 }
 
@@ -805,9 +809,11 @@ xennet_free_rx_buffer(struct xennet_xenb
 			 * this req is still granted. Get back the page or
 			 * allocate a new one, and remap it.
 			 */
+			mutex_enter(sc-sc_rx_lock);
 			SLIST_INSERT_HEAD(sc-sc_rxreq_head, rxreq,
 			rxreq_next);
 			sc-sc_free_rxreql++;
+			mutex_exit(sc-sc_rx_lock);
 
 			switch (sc-sc_rx_feature) {
 			case FEATURE_RX_COPY:
@@ -875,12 +881,14 @@ xennet_rx_mbuf_free(struct mbuf *m, void
 	struct xennet_rxreq *req = arg;
 	struct xennet_xenbus_softc *sc = req-rxreq_sc;
 
-	int s = splnet();
+	mutex_enter(sc-sc_rx_lock);
 
 	/* puts back the RX request in the list of free RX requests */
 	SLIST_INSERT_HEAD(sc-sc_rxreq_head, req, rxreq_next);
 	sc-sc_free_rxreql++;
 
+	mutex_exit(sc-sc_rx_lock);
+
 	/*
 	 * ring needs more requests to be pushed in, allocate some
 	 * RX buffers to catch-up with backend's consumption
@@ -893,7 +901,6 @@ xennet_rx_mbuf_free(struct mbuf *m, void
 
 	if (m)
 		pool_cache_put(mb_cache, m);
-	splx(s);
 }
 
 /*
@@ -933,7 +940,9 @@ again:
 		xengnt_revoke_access(req-txreq_gntref);
 
 		m_freem(req-txreq_m);
+		mutex_enter(sc-sc_tx_lock);
 		SLIST_INSERT_HEAD(sc-sc_txreq_head, req, txreq_next);
+		mutex_exit(sc-sc_tx_lock);
 	}
 	sc-sc_tx_ring.rsp_cons = resp_prod;
 	/* set new event and check for race with rsp_cons update */
@@ -1168,13 +1177,11 @@ xennet_softstart(void *arg)
 	struct xennet_txreq *req;
 	int notify;
 	int do_notify = 0;
-	int s;
-
-	s = splnet();
 
+	mutex_enter(sc-sc_tx_lock);
 	if (__predict_false(
 	(ifp-if_flags  (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)) {
-		splx(s);
+		mutex_exit(sc-sc_tx_lock);
 		return;
 	}
 
@@ -1329,7 +1336,7 @@ xennet_softstart(void *arg)
 		

CVS commit: src/sys/arch/xen/xen

2011-12-07 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Dec  7 12:31:51 UTC 2011

Modified Files:
src/sys/arch/xen/xen: evtchn.c

Log Message:
Move to kmem_zalloc() instead of malloc().


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/xen/xen/evtchn.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/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.56 src/sys/arch/xen/xen/evtchn.c:1.57
--- src/sys/arch/xen/xen/evtchn.c:1.56	Sat Nov 19 17:13:39 2011
+++ src/sys/arch/xen/xen/evtchn.c	Wed Dec  7 12:31:51 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.56 2011/11/19 17:13:39 cherry Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.57 2011/12/07 12:31:51 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: evtchn.c,v 1.56 2011/11/19 17:13:39 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: evtchn.c,v 1.57 2011/12/07 12:31:51 cherry Exp $);
 
 #include opt_xen.h
 #include isa.h
@@ -66,7 +66,7 @@ __KERNEL_RCSID(0, $NetBSD: evtchn.c,v 1
 #include sys/systm.h
 #include sys/device.h
 #include sys/proc.h
-#include sys/malloc.h
+#include sys/kmem.h
 #include sys/reboot.h
 #include sys/mutex.h
 
@@ -561,7 +561,7 @@ pirq_establish(int pirq, int evtch, int 
 	}
 
 	if (event_set_handler(evtch, pirq_interrupt, ih, level, evname) != 0) {
-		free(ih, M_DEVBUF);
+		kmem_free(ih, sizeof (struct iplsource));
 		return NULL;
 	}
 
@@ -659,8 +659,7 @@ event_set_handler(int evtch, int (*func)
 	printf(event_set_handler evtch %d handler %p level %d\n, evtch,
 	   handler, level);
 #endif
-	ih = malloc(sizeof (struct intrhand), M_DEVBUF,
-	M_WAITOK|M_ZERO);
+	ih = kmem_zalloc(sizeof (struct intrhand), KM_NOSLEEP);
 	if (ih == NULL)
 		panic(can't allocate fixed interrupt source);
 
@@ -685,8 +684,8 @@ event_set_handler(int evtch, int (*func)
 
 	/* register handler for event channel */
 	if (evtsource[evtch] == NULL) {
-		evts = malloc(sizeof (struct evtsource),
-		M_DEVBUF, M_WAITOK|M_ZERO);
+		evts = kmem_zalloc(sizeof (struct evtsource),
+		KM_NOSLEEP);
 		if (evts == NULL)
 			panic(can't allocate fixed interrupt source);
 
@@ -742,8 +741,8 @@ event_set_iplhandler(struct cpu_info *ci
 
 	KASSERT(ci == ih-ih_cpu);
 	if (ci-ci_isources[level] == NULL) {
-		ipls = malloc(sizeof (struct iplsource),
-		M_DEVBUF, M_WAITOK|M_ZERO);
+		ipls = kmem_zalloc(sizeof (struct iplsource),
+		KM_NOSLEEP);
 		if (ipls == NULL)
 			panic(can't allocate fixed interrupt source);
 		ipls-ipl_recurse = xenev_stubs[level].ist_recurse;
@@ -795,11 +794,11 @@ event_remove_handler(int evtch, int (*fu
 	if (ih == NULL)
 		panic(event_remove_handler);
 	*ihp = ih-ih_ipl_next;
-	free(ih, M_DEVBUF);
+	kmem_free(ih, sizeof (struct iplsource));
 	if (evts-ev_handlers == NULL) {
 		xen_atomic_clear_bit(ci-ci_evtmask[0], evtch);
 		evcnt_detach(evts-ev_evcnt);
-		free(evts, M_DEVBUF);
+		kmem_free(evts, sizeof (struct evtsource));
 		evtsource[evtch] = NULL;
 	} else {
 		intr_calculatemasks(evts, evtch, ci);



CVS commit: src/sys/arch/xen/xen

2011-12-07 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Dec  8 03:34:48 UTC 2011

Modified Files:
src/sys/arch/xen/xen: evtchn.c

Log Message:
kmem_free() the appropriate size.

Thanks cegger@


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/xen/xen/evtchn.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/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.60 src/sys/arch/xen/xen/evtchn.c:1.61
--- src/sys/arch/xen/xen/evtchn.c:1.60	Wed Dec  7 16:26:23 2011
+++ src/sys/arch/xen/xen/evtchn.c	Thu Dec  8 03:34:44 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.60 2011/12/07 16:26:23 cegger Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.61 2011/12/08 03:34:44 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: evtchn.c,v 1.60 2011/12/07 16:26:23 cegger Exp $);
+__KERNEL_RCSID(0, $NetBSD: evtchn.c,v 1.61 2011/12/08 03:34:44 cherry Exp $);
 
 #include opt_xen.h
 #include isa.h
@@ -795,7 +795,7 @@ event_remove_handler(int evtch, int (*fu
 	if (ih == NULL)
 		panic(event_remove_handler);
 	*ihp = ih-ih_ipl_next;
-	kmem_free(ih, sizeof (struct iplsource));
+	kmem_free(ih, sizeof (struct intrhand));
 	if (evts-ev_handlers == NULL) {
 		xen_atomic_clear_bit(ci-ci_evtmask[0], evtch);
 		evcnt_detach(evts-ev_evcnt);



CVS commit: src/sys/arch/xen/xen

2011-12-08 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Dec  9 03:58:12 UTC 2011

Modified Files:
src/sys/arch/xen/xen: xengnt.c

Log Message:
Use mutex(9) instead of spl(9). Add further locks around grant table access.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/xen/xen/xengnt.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/xen/xengnt.c
diff -u src/sys/arch/xen/xen/xengnt.c:1.20 src/sys/arch/xen/xen/xengnt.c:1.21
--- src/sys/arch/xen/xen/xengnt.c:1.20	Tue Sep 20 00:12:24 2011
+++ src/sys/arch/xen/xen/xengnt.c	Fri Dec  9 03:58:12 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: xengnt.c,v 1.20 2011/09/20 00:12:24 jym Exp $  */
+/*  $NetBSD: xengnt.c,v 1.21 2011/12/09 03:58:12 cherry Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: xengnt.c,v 1.20 2011/09/20 00:12:24 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: xengnt.c,v 1.21 2011/12/09 03:58:12 cherry Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -35,6 +35,7 @@ __KERNEL_RCSID(0, $NetBSD: xengnt.c,v 1
 #include sys/queue.h
 #include sys/extent.h
 #include sys/kernel.h
+#include sys/mutex.h
 #include uvm/uvm.h
 
 #include xen/hypervisor.h
@@ -64,6 +65,7 @@ int last_gnt_entry;
 
 /* VM address of the grant table */
 grant_entry_t *grant_table;
+kmutex_t grant_lock;
 
 static grant_ref_t xengnt_get_entry(void);
 static void xengnt_free_entry(grant_ref_t);
@@ -99,6 +101,8 @@ xengnt_init(void)
 	for (i = 0; i = nr_grant_entries; i++)
 		gnt_entries[i] = XENGNT_NO_ENTRY;
 
+	mutex_init(grant_lock, MUTEX_DEFAULT, IPL_VM);
+
 	xengnt_resume();
 
 }
@@ -217,13 +221,13 @@ static grant_ref_t
 xengnt_get_entry(void)
 {
 	grant_ref_t entry;
-	int s = splvm();
+	mutex_enter(grant_lock);
 	static struct timeval xengnt_nonmemtime;
 	static const struct timeval xengnt_nonmemintvl = {5,0};
 
 	if (last_gnt_entry == 0) {
 		if (xengnt_more_entries()) {
-			splx(s);
+			mutex_exit(grant_lock);
 			if (ratecheck(xengnt_nonmemtime, xengnt_nonmemintvl))
 printf(xengnt_get_entry: out of grant 
 table entries\n);
@@ -234,7 +238,7 @@ xengnt_get_entry(void)
 	last_gnt_entry--;
 	entry = gnt_entries[last_gnt_entry];
 	gnt_entries[last_gnt_entry] = XENGNT_NO_ENTRY;
-	splx(s);
+	mutex_exit(grant_lock);
 	KASSERT(entry != XENGNT_NO_ENTRY);
 	KASSERT(last_gnt_entry = 0);
 	KASSERT(last_gnt_entry = gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE);
@@ -247,13 +251,13 @@ xengnt_get_entry(void)
 static void
 xengnt_free_entry(grant_ref_t entry)
 {
-	int s = splvm();
+	mutex_enter(grant_lock);
 	KASSERT(gnt_entries[last_gnt_entry] == XENGNT_NO_ENTRY);
 	KASSERT(last_gnt_entry = 0);
 	KASSERT(last_gnt_entry = gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE);
 	gnt_entries[last_gnt_entry] = entry;
 	last_gnt_entry++;
-	splx(s);
+	mutex_exit(grant_lock);
 }
 
 int
@@ -263,6 +267,7 @@ xengnt_grant_access(domid_t dom, paddr_t
 	if (__predict_false(*entryp == XENGNT_NO_ENTRY))
 		return ENOMEM;
 
+	mutex_enter(grant_lock);
 	grant_table[*entryp].frame = ma  PAGE_SHIFT;
 	grant_table[*entryp].domid = dom;
 	/*
@@ -272,6 +277,7 @@ xengnt_grant_access(domid_t dom, paddr_t
 	xen_rmb();
 	grant_table[*entryp].flags =
 	GTF_permit_access | (ro ? GTF_readonly : 0);
+	mutex_exit(grant_lock);
 	return 0;
 }
 
@@ -298,6 +304,7 @@ xengnt_grant_transfer(domid_t dom, grant
 	if (__predict_false(*entryp == XENGNT_NO_ENTRY))
 		return ENOMEM;
 
+	mutex_enter(grant_lock);
 	grant_table[*entryp].frame = 0;
 	grant_table[*entryp].domid = dom;
 	/*
@@ -306,6 +313,7 @@ xengnt_grant_transfer(domid_t dom, grant
 	 */
 	xen_rmb();
 	grant_table[*entryp].flags = GTF_accept_transfer;
+	mutex_exit(grant_lock);
 	return 0;
 }
 



CVS commit: src/sys/arch/xen/xen

2011-12-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Dec  9 11:47:49 UTC 2011

Modified Files:
src/sys/arch/xen/xen: hypervisor.c

Log Message:
Move events/interrupt subsystem initialisation to before when ipis are used


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/xen/xen/hypervisor.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/xen/hypervisor.c
diff -u src/sys/arch/xen/xen/hypervisor.c:1.59 src/sys/arch/xen/xen/hypervisor.c:1.60
--- src/sys/arch/xen/xen/hypervisor.c:1.59	Wed Dec  7 15:47:43 2011
+++ src/sys/arch/xen/xen/hypervisor.c	Fri Dec  9 11:47:49 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.59 2011/12/07 15:47:43 cegger Exp $ */
+/* $NetBSD: hypervisor.c,v 1.60 2011/12/09 11:47:49 cherry Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hypervisor.c,v 1.59 2011/12/07 15:47:43 cegger Exp $);
+__KERNEL_RCSID(0, $NetBSD: hypervisor.c,v 1.60 2011/12/09 11:47:49 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -217,6 +217,7 @@ hypervisor_attach(device_t parent, devic
 	   xen_version  0x);
 
 	xengnt_init();
+	events_init();
 
 	memset(hac, 0, sizeof(hac));
 	hac.hac_vcaa.vcaa_name = vcpu;
@@ -248,7 +249,6 @@ hypervisor_attach(device_t parent, devic
 	}
 
 #endif /* MULTIPROCESSOR */
-	events_init();
 
 #if NXENBUS  0
 	memset(hac, 0, sizeof(hac));



CVS commit: src/sys/arch

2011-12-19 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Dec 19 19:09:16 UTC 2011

Modified Files:
src/sys/arch/amd64/conf: XEN3_DOMU
src/sys/arch/i386/conf: XEN3_DOMU

Log Message:
Add knob to turn MULTIPROCESSOR build on for XEN


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/amd64/conf/XEN3_DOMU
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/i386/conf/XEN3_DOMU

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/amd64/conf/XEN3_DOMU
diff -u src/sys/arch/amd64/conf/XEN3_DOMU:1.34 src/sys/arch/amd64/conf/XEN3_DOMU:1.35
--- src/sys/arch/amd64/conf/XEN3_DOMU:1.34	Sun Dec 18 05:49:23 2011
+++ src/sys/arch/amd64/conf/XEN3_DOMU	Mon Dec 19 19:09:16 2011
@@ -1,7 +1,9 @@
-# $NetBSD: XEN3_DOMU,v 1.34 2011/12/18 05:49:23 dholland Exp $
+# $NetBSD: XEN3_DOMU,v 1.35 2011/12/19 19:09:16 cherry Exp $
 
 include 	arch/amd64/conf/std.xen
 
+#options		MULTIPROCESSOR	# Experimental
+
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
 #options 	UVMHIST

Index: src/sys/arch/i386/conf/XEN3_DOMU
diff -u src/sys/arch/i386/conf/XEN3_DOMU:1.39 src/sys/arch/i386/conf/XEN3_DOMU:1.40
--- src/sys/arch/i386/conf/XEN3_DOMU:1.39	Sun Dec 18 05:49:28 2011
+++ src/sys/arch/i386/conf/XEN3_DOMU	Mon Dec 19 19:09:16 2011
@@ -1,7 +1,9 @@
-# $NetBSD: XEN3_DOMU,v 1.39 2011/12/18 05:49:28 dholland Exp $
+# $NetBSD: XEN3_DOMU,v 1.40 2011/12/19 19:09:16 cherry Exp $
 
 include 	arch/xen/conf/std.xen
 
+#options		MULTIPROCESSOR	# Experimental
+
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
 #options 	UVMHIST



CVS commit: src/sys/arch/xen/x86

2011-12-26 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Dec 26 18:27:11 UTC 2011

Modified Files:
src/sys/arch/xen/x86: hypervisor_machdep.c

Log Message:
Do not fiddle with the event masks of non-local vcpus when unmasking events 
across vcpus


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 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.18 src/sys/arch/xen/x86/hypervisor_machdep.c:1.19
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.18	Sat Dec  3 22:41:40 2011
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Mon Dec 26 18:27:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.18 2011/12/03 22:41:40 bouyer Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.19 2011/12/26 18:27:11 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.18 2011/12/03 22:41:40 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.19 2011/12/26 18:27:11 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -338,9 +338,11 @@ hypervisor_unmask_event(unsigned int ev)
 		if (!xen_atomic_test_bit(ci-ci_evtmask[0], ev))
 			continue;
 		vci = ci-ci_vcpu;
-		if (!xen_atomic_test_and_set_bit(vci-evtchn_pending_sel,
-		evLONG_SHIFT))
-			xen_atomic_set_bit(vci-evtchn_upcall_pending, 0);
+		if (__predict_true(ci == curcpu())) {
+			if (!xen_atomic_test_and_set_bit(vci-evtchn_pending_sel,
+evLONG_SHIFT))
+xen_atomic_set_bit(vci-evtchn_upcall_pending, 0);
+		}
 		if (!vci-evtchn_upcall_mask) {
 			if (__predict_true(ci == curcpu())) {
 hypervisor_force_callback();



CVS commit: src/sys/arch/xen/x86

2011-12-26 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Tue Dec 27 07:45:41 UTC 2011

Modified Files:
src/sys/arch/xen/x86: hypervisor_machdep.c

Log Message:
Do not touch pending flags across vcpus


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 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.19 src/sys/arch/xen/x86/hypervisor_machdep.c:1.20
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.19	Mon Dec 26 18:27:11 2011
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Tue Dec 27 07:45:41 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.19 2011/12/26 18:27:11 cherry Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.20 2011/12/27 07:45:41 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.19 2011/12/26 18:27:11 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.20 2011/12/27 07:45:41 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -295,10 +295,12 @@ hypervisor_send_event(struct cpu_info *c
 #endif
 
 	xen_atomic_set_bit(s-evtchn_pending[0], ev);
-	xen_atomic_set_bit(vci-evtchn_pending_sel,
-			   ev  LONG_SHIFT);
 
-	xen_atomic_set_bit(vci-evtchn_upcall_pending, 0);
+	if (__predict_true(ci == curcpu())) {
+		xen_atomic_set_bit(vci-evtchn_pending_sel,
+		ev  LONG_SHIFT);
+		xen_atomic_set_bit(vci-evtchn_upcall_pending, 0);
+	}
 
 	xen_atomic_clear_bit(s-evtchn_mask[0], ev);
 



CVS commit: src/sys/arch/xen/x86

2011-12-28 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Dec 28 18:59:21 UTC 2011

Modified Files:
src/sys/arch/xen/x86: xen_ipi.c

Log Message:
Remove temporary variable definition that is unused in non DIAGNOSTIC builds.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/xen/x86/xen_ipi.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_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.7 src/sys/arch/xen/x86/xen_ipi.c:1.8
--- src/sys/arch/xen/x86/xen_ipi.c:1.7	Wed Dec  7 15:47:43 2011
+++ src/sys/arch/xen/x86/xen_ipi.c	Wed Dec 28 18:59:21 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.7 2011/12/07 15:47:43 cegger Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.8 2011/12/28 18:59:21 cherry Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -33,10 +33,10 @@
 
 /* 
  * Based on: x86/ipi.c
- * __KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.7 2011/12/07 15:47:43 cegger Exp $); 
+ * __KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.8 2011/12/28 18:59:21 cherry Exp $); 
  */
 
-__KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.7 2011/12/07 15:47:43 cegger Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.8 2011/12/28 18:59:21 cherry Exp $);
 
 #include sys/types.h
 
@@ -304,10 +304,8 @@ xen_ipi_hvcb(struct cpu_info *ci, struct
 {
 	KASSERT(ci != NULL);
 	KASSERT(intrf != NULL);
-
-	volatile struct vcpu_info *vci = ci-ci_vcpu;
-
 	KASSERT(ci == curcpu());
-	KASSERT(!vci-evtchn_upcall_mask);
+	KASSERT(!ci-ci_vcpu-evtchn_upcall_mask);
+
 	hypervisor_force_callback();
 }



CVS commit: src/sys/arch/xen/x86

2011-12-30 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Dec 30 12:16:19 UTC 2011

Modified Files:
src/sys/arch/xen/x86: xen_ipi.c

Log Message:
Remove spurious (debug) printf()


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/xen/x86/xen_ipi.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_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.8 src/sys/arch/xen/x86/xen_ipi.c:1.9
--- src/sys/arch/xen/x86/xen_ipi.c:1.8	Wed Dec 28 18:59:21 2011
+++ src/sys/arch/xen/x86/xen_ipi.c	Fri Dec 30 12:16:19 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.8 2011/12/28 18:59:21 cherry Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.9 2011/12/30 12:16:19 cherry Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -33,10 +33,10 @@
 
 /* 
  * Based on: x86/ipi.c
- * __KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.8 2011/12/28 18:59:21 cherry Exp $); 
+ * __KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.9 2011/12/30 12:16:19 cherry Exp $); 
  */
 
-__KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.8 2011/12/28 18:59:21 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.9 2011/12/30 12:16:19 cherry Exp $);
 
 #include sys/types.h
 
@@ -289,7 +289,6 @@ xc_send_ipi(struct cpu_info *ci)
 
 	KASSERT(kpreempt_disabled());
 	KASSERT(curcpu() != ci);
-	printf(xc_send_ipi called \n);
 	if (ci) {
 		if (0 != xen_send_ipi(ci, XEN_IPI_XCALL)) {
 			panic(xen_send_ipi(XEN_IPI_XCALL) failed\n);



CVS commit: src/sys/arch

2011-12-30 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Dec 30 16:55:21 UTC 2011

Modified Files:
src/sys/arch/x86/x86: pmap.c
src/sys/arch/xen/include: xenpmap.h
src/sys/arch/xen/x86: cpu.c xen_pmap.c

Log Message:
per-cpu shadow directory pages should be updated locally via cross-calls. Do 
this.


To generate a diff of this commit:
cvs rdiff -u -r1.147 -r1.148 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/xen/include/xenpmap.h
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/xen/x86/cpu.c
cvs rdiff -u -r1.11 -r1.12 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.147 src/sys/arch/x86/x86/pmap.c:1.148
--- src/sys/arch/x86/x86/pmap.c:1.147	Fri Dec  9 17:32:51 2011
+++ src/sys/arch/x86/x86/pmap.c	Fri Dec 30 16:55:21 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.147 2011/12/09 17:32:51 chs Exp $	*/
+/*	$NetBSD: pmap.c,v 1.148 2011/12/30 16:55:21 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.147 2011/12/09 17:32:51 chs Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.148 2011/12/30 16:55:21 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -1915,16 +1915,7 @@ pmap_free_ptp(struct pmap *pmap, struct 
 			 * Update the per-cpu PD on all cpus the current
 			 * pmap is active on 
 			 */ 
-			CPU_INFO_ITERATOR cii;
-			struct cpu_info *ci;
-			for (CPU_INFO_FOREACH(cii, ci)) {
-if (ci == NULL) {
-	continue;
-}
-if (ci-ci_cpumask  pmap-pm_cpus) {
-	pmap_pte_set(ci-ci_kpm_pdir[index], 0);
-}
-			}
+			xen_kpm_sync(pmap, index);
 		}
 #  endif /*__x86_64__ */
 		invaladdr = level == 1 ? (vaddr_t)ptes :
@@ -2029,17 +2020,7 @@ pmap_get_ptp(struct pmap *pmap, vaddr_t 
 			 * Update the per-cpu PD on all cpus the current
 			 * pmap is active on 
 			 */ 
-			CPU_INFO_ITERATOR cii;
-			struct cpu_info *ci;
-			for (CPU_INFO_FOREACH(cii, ci)) {
-if (ci == NULL) {
-	continue;
-}
-if (ci-ci_cpumask  pmap-pm_cpus) {
-	pmap_pte_set(ci-ci_kpm_pdir[index],
-		 (pd_entry_t) (pmap_pa2pte(pa) | PG_u | PG_RW | PG_V));
-}
-			}
+			xen_kpm_sync(pmap, index);
 		}
 #endif /* XEN  __x86_64__ */
 		pmap_pte_flush();
@@ -4247,33 +4228,14 @@ pmap_alloc_level(pd_entry_t * const *pde
 			pmap_get_physpage(va, level - 1, pa);
 			pte = pmap_pa2pte(pa) | PG_k | PG_V | PG_RW;
 #ifdef XEN
-			switch (level) {
-			case PTP_LEVELS: 
+			xpq_queue_pte_update(xpmap_ptetomach(pdep[i]), pte);
+			if (level == PTP_LEVELS) {
 #if defined(PAE) || defined(__x86_64__)
 if (i = PDIR_SLOT_KERN) {
 	/* update per-cpu PMDs on all cpus */
-	CPU_INFO_ITERATOR cii;
-	struct cpu_info *ci;
-	for (CPU_INFO_FOREACH(cii, ci)) {
-		if (ci == NULL) {
-			continue;
-		}
-#ifdef PAE
-		xpq_queue_pte_update(
-			xpmap_ptetomach(ci-ci_kpm_pdir[l2tol2(i)]), pte);
-#elif defined(__x86_64__)
-		xpq_queue_pte_update(
-			xpmap_ptetomach(ci-ci_kpm_pdir[i]), pte);
-#endif /* PAE */
-	}
+	xen_kpm_sync(pmap_kernel(), i);
 }
 #endif /* PAE || __x86_64__ */
-/* FALLTHROUGH */
-
-			default: /* All other levels */
-xpq_queue_pte_update(
-	xpmap_ptetomach(pdep[i]), 
-	pte);
 			}
 #else /* XEN */
 			pdep[i] = pte;

Index: src/sys/arch/xen/include/xenpmap.h
diff -u src/sys/arch/xen/include/xenpmap.h:1.32 src/sys/arch/xen/include/xenpmap.h:1.33
--- src/sys/arch/xen/include/xenpmap.h:1.32	Wed Nov 23 00:56:56 2011
+++ src/sys/arch/xen/include/xenpmap.h	Fri Dec 30 16:55:21 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xenpmap.h,v 1.32 2011/11/23 00:56:56 jym Exp $	*/
+/*	$NetBSD: xenpmap.h,v 1.33 2011/12/30 16:55:21 cherry Exp $	*/
 
 /*
  *
@@ -61,6 +61,10 @@ void	pmap_map_recursive_entries(void);
 void	pmap_unmap_recursive_entries(void);
 #endif /* PAE */
 
+#if defined(PAE) || defined(__x86_64__)
+void xen_kpm_sync(struct pmap *, int);
+#endif /* PAE || __x86_64__ */
+
 #define xpq_queue_pin_l1_table(pa)	\
 	xpq_queue_pin_table(pa, MMUEXT_PIN_L1_TABLE)
 #define xpq_queue_pin_l2_table(pa)	\

Index: src/sys/arch/xen/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.71 src/sys/arch/xen/x86/cpu.c:1.72
--- src/sys/arch/xen/x86/cpu.c:1.71	Wed Dec  7 15:47:43 2011
+++ src/sys/arch/xen/x86/cpu.c	Fri Dec 30 16:55:21 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.71 2011/12/07 15:47:43 cegger Exp $	*/
+/*	$NetBSD: cpu.c,v 1.72 2011/12/30 16:55:21 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.71 2011/12/07 15:47:43 cegger Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.72 2011/12/30 16:55:21 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1102,6 +1102,7 @@ static struct 

CVS commit: src/sys/arch

2011-12-30 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Dec 30 17:57:49 UTC 2011

Modified Files:
src/sys/arch/i386/i386: machdep.c
src/sys/arch/i386/include: cpu.h
src/sys/arch/x86/include: cpu.h
src/sys/arch/x86/x86: pmap.c

Log Message:
Move the per-cpu l3 page allocation code to a separate MD function. Avoids code 
duplication for xen PAE


To generate a diff of this commit:
cvs rdiff -u -r1.714 -r1.715 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.177 -r1.178 src/sys/arch/i386/include/cpu.h
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.148 -r1.149 src/sys/arch/x86/x86/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.714 src/sys/arch/i386/i386/machdep.c:1.715
--- src/sys/arch/i386/i386/machdep.c:1.714	Tue Nov 29 11:12:26 2011
+++ src/sys/arch/i386/i386/machdep.c	Fri Dec 30 17:57:49 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.714 2011/11/29 11:12:26 martin Exp $	*/
+/*	$NetBSD: machdep.c,v 1.715 2011/12/30 17:57:49 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.714 2011/11/29 11:12:26 martin Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.715 2011/12/30 17:57:49 cherry Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -1917,3 +1917,38 @@ mm_md_open(dev_t dev, int flag, int mode
 	}
 	return 0;
 }
+
+#ifdef PAE
+void
+cpu_alloc_l3_page(struct cpu_info *ci)
+{
+	int ret;
+	struct pglist pg;
+	struct vm_page *vmap;
+
+	KASSERT(ci != NULL);
+	/*
+	 * Allocate a page for the per-CPU L3 PD. cr3 being 32 bits, PA musts
+	 * resides below the 4GB boundary.
+	 */
+	ret = uvm_pglistalloc(PAGE_SIZE, 0, 0x1ULL, 32, 0, pg, 1, 0);
+	vmap = TAILQ_FIRST(pg);
+
+	if (ret != 0 || vmap == NULL)
+		panic(%s: failed to allocate L3 pglist for CPU %d (ret %d)\n,
+			__func__, cpu_index(ci), ret);
+
+	ci-ci_pae_l3_pdirpa = vmap-phys_addr;
+
+	ci-ci_pae_l3_pdir = (paddr_t *)uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
+		UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
+	if (ci-ci_pae_l3_pdir == NULL)
+		panic(%s: failed to allocate L3 PD for CPU %d\n,
+			__func__, cpu_index(ci));
+
+	pmap_kenter_pa((vaddr_t)ci-ci_pae_l3_pdir, ci-ci_pae_l3_pdirpa,
+		VM_PROT_READ | VM_PROT_WRITE, 0);
+
+	pmap_update(pmap_kernel());
+}
+#endif /* PAE */

Index: src/sys/arch/i386/include/cpu.h
diff -u src/sys/arch/i386/include/cpu.h:1.177 src/sys/arch/i386/include/cpu.h:1.178
--- src/sys/arch/i386/include/cpu.h:1.177	Tue Jul 26 12:56:39 2011
+++ src/sys/arch/i386/include/cpu.h	Fri Dec 30 17:57:49 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.177 2011/07/26 12:56:39 yamt Exp $	*/
+/*	$NetBSD: cpu.h,v 1.178 2011/12/30 17:57:49 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -86,6 +86,10 @@ cpu_set_curpri(int pri)
 #define	CLKF_INTR(frame)	(curcpu()-ci_idepth  0)
 #define	LWP_PC(l)		((l)-l_md.md_regs-tf_eip)
 
+#ifdef PAE
+void cpu_alloc_l3_page(struct cpu_info *);
+#endif /* PAE */
+
 #endif	/* _KERNEL */
 
 #endif /* !_I386_CPU_H_ */

Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.44 src/sys/arch/x86/include/cpu.h:1.45
--- src/sys/arch/x86/include/cpu.h:1.44	Wed Dec  7 15:47:42 2011
+++ src/sys/arch/x86/include/cpu.h	Fri Dec 30 17:57:49 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.44 2011/12/07 15:47:42 cegger Exp $	*/
+/*	$NetBSD: cpu.h,v 1.45 2011/12/30 17:57:49 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -177,7 +177,7 @@ struct cpu_info {
 #endif
 
 #ifdef PAE
-	paddr_t	ci_pae_l3_pdirpa; /* PA of L3 PD */
+	uint32_t	ci_pae_l3_pdirpa; /* PA of L3 PD */
 	pd_entry_t *	ci_pae_l3_pdir; /* VA pointer to L3 PD */
 #endif
 

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.148 src/sys/arch/x86/x86/pmap.c:1.149
--- src/sys/arch/x86/x86/pmap.c:1.148	Fri Dec 30 16:55:21 2011
+++ src/sys/arch/x86/x86/pmap.c	Fri Dec 30 17:57:49 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.148 2011/12/30 16:55:21 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.149 2011/12/30 17:57:49 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.148 2011/12/30 16:55:21 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.149 2011/12/30 17:57:49 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -1663,33 +1663,7 @@ pmap_cpu_init_late(struct cpu_info *ci)
 		return;
 
 #ifdef PAE
-	int ret;
-	struct pglist pg;
-	struct vm_page *vmap;
-
-	/*
-	 * Allocate a page for the per-CPU L3 PD. cr3 being 32 bits, PA musts
-	 * resides below the 4GB boundary.
-	 */
-	ret = uvm_pglistalloc(PAGE_SIZE, 0, 0x1ULL, 32, 0, pg, 1, 0);
-	vmap = 

CVS commit: src/sys/arch/xen/x86

2011-12-30 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Dec 30 18:01:20 UTC 2011

Modified Files:
src/sys/arch/xen/x86: cpu.c

Log Message:
Force pae l3 page allocation for new vcpus to be  4G, so they fit in 32bits


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 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.72 src/sys/arch/xen/x86/cpu.c:1.73
--- src/sys/arch/xen/x86/cpu.c:1.72	Fri Dec 30 16:55:21 2011
+++ src/sys/arch/xen/x86/cpu.c	Fri Dec 30 18:01:20 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.72 2011/12/30 16:55:21 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.73 2011/12/30 18:01:20 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.72 2011/12/30 16:55:21 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.73 2011/12/30 18:01:20 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1271,23 +1271,15 @@ pmap_cpu_init_late(struct cpu_info *ci)
 	KASSERT(ci != NULL);
 
 #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);
-
-	if (ci-ci_pae_l3_pdir == NULL) {
-		panic(%s: failed to allocate L3 per-cpu PD for CPU %d\n,
-		  __func__, cpu_index(ci));
-	}
-	ci-ci_pae_l3_pdirpa = vtophys((vaddr_t) ci-ci_pae_l3_pdir);
+	cpu_alloc_l3_page(ci);
 	KASSERT(ci-ci_pae_l3_pdirpa != 0);
 
 	/* Initialise L2 entries 0 - 2: Point them to pmap_kernel() */
-	ci-ci_pae_l3_pdir[0] =
-	xpmap_ptom_masked(pmap_kernel()-pm_pdirpa[0]) | PG_V;
-	ci-ci_pae_l3_pdir[1] =
-	xpmap_ptom_masked(pmap_kernel()-pm_pdirpa[1]) | PG_V;
-	ci-ci_pae_l3_pdir[2] =
-	xpmap_ptom_masked(pmap_kernel()-pm_pdirpa[2]) | PG_V;
+	int i;
+	for (i = 0; i  PTP_LEVELS - 1; i++ ) {
+		ci-ci_pae_l3_pdir[i] =
+		xpmap_ptom_masked(pmap_kernel()-pm_pdirpa[i]) | PG_V;
+	}
 #endif /* PAE */
 
 	ci-ci_kpm_pdir = (pd_entry_t *)uvm_km_alloc(kernel_map, PAGE_SIZE, 0,



CVS commit: src/sys/arch/xen/x86

2011-12-30 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Dec 30 19:18:35 UTC 2011

Modified Files:
src/sys/arch/xen/x86: cpu.c

Log Message:
Never cut-paste code from email!
Use the right count (0 - 2) of l3 unshared userland entries for per-cpu 
initialisation.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 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.73 src/sys/arch/xen/x86/cpu.c:1.74
--- src/sys/arch/xen/x86/cpu.c:1.73	Fri Dec 30 18:01:20 2011
+++ src/sys/arch/xen/x86/cpu.c	Fri Dec 30 19:18:35 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.73 2011/12/30 18:01:20 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.74 2011/12/30 19:18:35 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.73 2011/12/30 18:01:20 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.74 2011/12/30 19:18:35 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1276,7 +1276,7 @@ pmap_cpu_init_late(struct cpu_info *ci)
 
 	/* Initialise L2 entries 0 - 2: Point them to pmap_kernel() */
 	int i;
-	for (i = 0; i  PTP_LEVELS - 1; i++ ) {
+	for (i = 0; i  3; i++ ) {
 		ci-ci_pae_l3_pdir[i] =
 		xpmap_ptom_masked(pmap_kernel()-pm_pdirpa[i]) | PG_V;
 	}



CVS commit: src/sys/arch/xen/x86

2012-01-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Jan  4 10:30:24 UTC 2012

Modified Files:
src/sys/arch/xen/x86: cpu.c

Log Message:
Use macro PDP_SIZE instead of numeric constant, for unshared PAE L3 entries.
Thanks jym@


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 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.74 src/sys/arch/xen/x86/cpu.c:1.75
--- src/sys/arch/xen/x86/cpu.c:1.74	Fri Dec 30 19:18:35 2011
+++ src/sys/arch/xen/x86/cpu.c	Wed Jan  4 10:30:23 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.74 2011/12/30 19:18:35 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.75 2012/01/04 10:30:23 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.74 2011/12/30 19:18:35 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.75 2012/01/04 10:30:23 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1276,7 +1276,7 @@ pmap_cpu_init_late(struct cpu_info *ci)
 
 	/* Initialise L2 entries 0 - 2: Point them to pmap_kernel() */
 	int i;
-	for (i = 0; i  3; i++ ) {
+	for (i = 0 ; i  PDP_SIZE - 1; i++) {
 		ci-ci_pae_l3_pdir[i] =
 		xpmap_ptom_masked(pmap_kernel()-pm_pdirpa[i]) | PG_V;
 	}



CVS commit: src/sys/arch/xen/xen

2012-01-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Jan  4 10:48:24 UTC 2012

Modified Files:
src/sys/arch/xen/xen: if_xennet_xenbus.c

Log Message:
Tighten up locking in the network driver.
This probably needs more attention since xennet_rx_mbuf_free() hooks
into the network layer.
The locking can also be made finer grained. Performance testing could
add some insights.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/xen/xen/if_xennet_xenbus.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/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.56 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.57
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.56	Wed Dec  7 15:47:43 2011
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Wed Jan  4 10:48:24 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.56 2011/12/07 15:47:43 cegger Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.57 2012/01/04 10:48:24 cherry Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -85,7 +85,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_xennet_xenbus.c,v 1.56 2011/12/07 15:47:43 cegger Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_xennet_xenbus.c,v 1.57 2012/01/04 10:48:24 cherry Exp $);
 
 #include opt_xen.h
 #include opt_nfs_boot.h
@@ -790,6 +790,7 @@ xennet_free_rx_buffer(struct xennet_xenb
 	multicall_entry_t mcl[2];
 
 	int s = splbio();
+	mutex_enter(sc-sc_rx_lock);
 	
 	DPRINTF((%s: xennet_free_rx_buffer\n, device_xname(sc-sc_dev)));
 	/* get back memory from RX ring */
@@ -802,18 +803,18 @@ xennet_free_rx_buffer(struct xennet_xenb
 		 */
 		while ((volatile grant_ref_t)rxreq-rxreq_gntref ==
 		GRANT_STACK_REF)
+			mutex_exit(sc-sc_rx_lock);
 			tsleep(xennet_xenbus_detach, PRIBIO, xnet_free, hz/2);
+			mutex_enter(sc-sc_rx_lock);
 
 		if (rxreq-rxreq_gntref != GRANT_INVALID_REF) {
 			/*
 			 * this req is still granted. Get back the page or
 			 * allocate a new one, and remap it.
 			 */
-			mutex_enter(sc-sc_rx_lock);
 			SLIST_INSERT_HEAD(sc-sc_rxreq_head, rxreq,
 			rxreq_next);
 			sc-sc_free_rxreql++;
-			mutex_exit(sc-sc_rx_lock);
 
 			switch (sc-sc_rx_feature) {
 			case FEATURE_RX_COPY:
@@ -868,6 +869,7 @@ xennet_free_rx_buffer(struct xennet_xenb
 		}
 
 	}
+	mutex_exit(sc-sc_rx_lock);
 	splx(s);
 	DPRINTF((%s: xennet_free_rx_buffer done\n, device_xname(sc-sc_dev)));
 }
@@ -880,27 +882,31 @@ xennet_rx_mbuf_free(struct mbuf *m, void
 {
 	struct xennet_rxreq *req = arg;
 	struct xennet_xenbus_softc *sc = req-rxreq_sc;
-
+	
 	mutex_enter(sc-sc_rx_lock);
 
 	/* puts back the RX request in the list of free RX requests */
 	SLIST_INSERT_HEAD(sc-sc_rxreq_head, req, rxreq_next);
 	sc-sc_free_rxreql++;
 
-	mutex_exit(sc-sc_rx_lock);
-
 	/*
 	 * ring needs more requests to be pushed in, allocate some
 	 * RX buffers to catch-up with backend's consumption
 	 */
 	req-rxreq_gntref = GRANT_INVALID_REF;
+	
 	if (sc-sc_free_rxreql = SC_NLIVEREQ(sc) 
 	__predict_true(sc-sc_backend_status == BEST_CONNECTED)) {
+		mutex_exit(sc-sc_rx_lock);
 		xennet_alloc_rx_buffer(sc);
 	}
-
+	else {
+		mutex_exit(sc-sc_rx_lock);
+	}
+	
 	if (m)
 		pool_cache_put(mb_cache, m);
+
 }
 
 /*
@@ -921,6 +927,7 @@ xennet_tx_complete(struct xennet_xenbus_
 again:
 	resp_prod = sc-sc_tx_ring.sring-rsp_prod;
 	xen_rmb();
+	mutex_enter(sc-sc_tx_lock);
 	for (i = sc-sc_tx_ring.rsp_cons; i != resp_prod; i++) {
 		req = sc-sc_txreqs[RING_GET_RESPONSE(sc-sc_tx_ring, i)-id];
 		KASSERT(req-txreq_id ==
@@ -938,12 +945,11 @@ again:
 		else
 			ifp-if_opackets++;
 		xengnt_revoke_access(req-txreq_gntref);
-
 		m_freem(req-txreq_m);
-		mutex_enter(sc-sc_tx_lock);
 		SLIST_INSERT_HEAD(sc-sc_txreq_head, req, txreq_next);
-		mutex_exit(sc-sc_tx_lock);
 	}
+	mutex_exit(sc-sc_tx_lock);
+
 	sc-sc_tx_ring.rsp_cons = resp_prod;
 	/* set new event and check for race with rsp_cons update */
 	sc-sc_tx_ring.sring-rsp_event = 
@@ -995,6 +1001,14 @@ again:
 
 	resp_prod = sc-sc_rx_ring.sring-rsp_prod;
 	xen_rmb(); /* ensure we see replies up to resp_prod */
+
+	/*
+	 * The locking in this loop needs to be done carefully, as
+	 * m_free() will take the sc_rx_lock() via
+	 * xennet_rx_mbuf_free()
+	 */
+	mutex_enter(sc-sc_rx_lock);
+	
 	for (i = sc-sc_rx_ring.rsp_cons; i != resp_prod; i++) {
 		netif_rx_response_t *rx = RING_GET_RESPONSE(sc-sc_rx_ring, i);
 		req = sc-sc_rxreqs[rx-id];
@@ -1035,7 +1049,7 @@ again:
 
 		pa = req-rxreq_pa;
 		va = req-rxreq_va;
-
+		
 		if (sc-sc_rx_feature == FEATURE_RX_FLIP) {
 			/* remap the page */
 			mmu[0].ptr = (ma  PAGE_SHIFT) | MMU_MACHPHYS_UPDATE;
@@ -1064,8 +1078,10 @@ again:
 DPRINTFN(XEDB_EVENT,
 (xennet_handler bad dest\n));
 /* packet not for us */
+mutex_exit(sc-sc_rx_lock);
 xennet_rx_mbuf_free(NULL, (void *)va, PAGE_SIZE,
 req);
+mutex_enter(sc-sc_rx_lock);
 continue;
 			}
 		}
@@ -1073,7 

CVS commit: src/sys/arch

2012-01-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Jan  6 15:15:28 UTC 2012

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

Log Message:
Address those pesky DIAGNOSTIC messages. \n
Take a performance hit at fork() for not DTRT. \n
Note: Only applicable for kernels built with options DIAGNOSTIC \n


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.75 -r1.76 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/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.149 src/sys/arch/x86/x86/pmap.c:1.150
--- src/sys/arch/x86/x86/pmap.c:1.149	Fri Dec 30 17:57:49 2011
+++ src/sys/arch/x86/x86/pmap.c	Fri Jan  6 15:15:27 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.149 2011/12/30 17:57:49 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.150 2012/01/06 15:15:27 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.149 2011/12/30 17:57:49 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.150 2012/01/06 15:15:27 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -2120,6 +2120,9 @@ pmap_pdp_ctor(void *arg, void *v, int fl
 	for (i = 0; i  PDP_SIZE; i++, object += PAGE_SIZE) {
 		(void) pmap_extract(pmap_kernel(), object, pdirpa);
 		/* FIXME: This should use pmap_protect() .. */
+#ifdef DIAGNOSTIC
+		pmap_kremove(object, PAGE_SIZE);
+#endif /* DIAGNOSTIC */
 		pmap_kenter_pa(object, pdirpa, VM_PROT_READ, 0);
 		pmap_update(pmap_kernel());
 		/*

Index: src/sys/arch/xen/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.75 src/sys/arch/xen/x86/cpu.c:1.76
--- src/sys/arch/xen/x86/cpu.c:1.75	Wed Jan  4 10:30:23 2012
+++ src/sys/arch/xen/x86/cpu.c	Fri Jan  6 15:15:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.75 2012/01/04 10:30:23 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.76 2012/01/06 15:15:28 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.75 2012/01/04 10:30:23 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.76 2012/01/06 15:15:28 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1307,6 +1307,10 @@ pmap_cpu_init_late(struct cpu_info *ci)
 #endif /* __x86_64__ else PAE */
 
 	/* Xen wants R/O */
+	/* FIXME: This should use pmap_protect() .. */
+#ifdef DIAGNOSTIC
+	pmap_kremove((vaddr_t)ci-ci_kpm_pdir, PAGE_SIZE);
+#endif /* DIAGNOSTIC */
 	pmap_kenter_pa((vaddr_t)ci-ci_kpm_pdir, ci-ci_kpm_pdirpa,
 	VM_PROT_READ, 0);
 
@@ -1319,6 +1323,10 @@ pmap_cpu_init_late(struct cpu_info *ci)
 	ci-ci_pae_l3_pdir[3] = xpmap_ptom_masked(ci-ci_kpm_pdirpa) | PG_k | PG_V;
 
 	/* Mark L3 R/O (Xen wants this) */
+#ifdef DIAGNOSTIC
+	/* FIXME: This should use pmap_protect() .. */
+	pmap_kremove((vaddr_t)ci-ci_pae_l3_pdir, PAGE_SIZE);
+#endif /* DIAGNOSTIC */
 	pmap_kenter_pa((vaddr_t)ci-ci_pae_l3_pdir, ci-ci_pae_l3_pdirpa,
 		VM_PROT_READ, 0);
 



CVS commit: src/sys/arch

2012-01-08 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jan  9 04:39:14 UTC 2012

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

Log Message:
revert previous commit. DIAGNOSTIC should only do strict checks, not muffle 
current ones


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.76 -r1.77 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/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.150 src/sys/arch/x86/x86/pmap.c:1.151
--- src/sys/arch/x86/x86/pmap.c:1.150	Fri Jan  6 15:15:27 2012
+++ src/sys/arch/x86/x86/pmap.c	Mon Jan  9 04:39:14 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.150 2012/01/06 15:15:27 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.151 2012/01/09 04:39:14 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.150 2012/01/06 15:15:27 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.151 2012/01/09 04:39:14 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -2120,9 +2120,6 @@ pmap_pdp_ctor(void *arg, void *v, int fl
 	for (i = 0; i  PDP_SIZE; i++, object += PAGE_SIZE) {
 		(void) pmap_extract(pmap_kernel(), object, pdirpa);
 		/* FIXME: This should use pmap_protect() .. */
-#ifdef DIAGNOSTIC
-		pmap_kremove(object, PAGE_SIZE);
-#endif /* DIAGNOSTIC */
 		pmap_kenter_pa(object, pdirpa, VM_PROT_READ, 0);
 		pmap_update(pmap_kernel());
 		/*

Index: src/sys/arch/xen/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.76 src/sys/arch/xen/x86/cpu.c:1.77
--- src/sys/arch/xen/x86/cpu.c:1.76	Fri Jan  6 15:15:28 2012
+++ src/sys/arch/xen/x86/cpu.c	Mon Jan  9 04:39:14 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.76 2012/01/06 15:15:28 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.77 2012/01/09 04:39:14 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.76 2012/01/06 15:15:28 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.77 2012/01/09 04:39:14 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1307,10 +1307,6 @@ pmap_cpu_init_late(struct cpu_info *ci)
 #endif /* __x86_64__ else PAE */
 
 	/* Xen wants R/O */
-	/* FIXME: This should use pmap_protect() .. */
-#ifdef DIAGNOSTIC
-	pmap_kremove((vaddr_t)ci-ci_kpm_pdir, PAGE_SIZE);
-#endif /* DIAGNOSTIC */
 	pmap_kenter_pa((vaddr_t)ci-ci_kpm_pdir, ci-ci_kpm_pdirpa,
 	VM_PROT_READ, 0);
 
@@ -1323,10 +1319,6 @@ pmap_cpu_init_late(struct cpu_info *ci)
 	ci-ci_pae_l3_pdir[3] = xpmap_ptom_masked(ci-ci_kpm_pdirpa) | PG_k | PG_V;
 
 	/* Mark L3 R/O (Xen wants this) */
-#ifdef DIAGNOSTIC
-	/* FIXME: This should use pmap_protect() .. */
-	pmap_kremove((vaddr_t)ci-ci_pae_l3_pdir, PAGE_SIZE);
-#endif /* DIAGNOSTIC */
 	pmap_kenter_pa((vaddr_t)ci-ci_pae_l3_pdir, ci-ci_pae_l3_pdirpa,
 		VM_PROT_READ, 0);
 



CVS commit: src/sys/arch/x86/x86

2012-01-08 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jan  9 04:55:35 UTC 2012

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

Log Message:
While freeing ptps, remove stale L3 frame entries on all CPUS the pmap is 
loaded on, not just the current one.


To generate a diff of this commit:
cvs rdiff -u -r1.151 -r1.152 src/sys/arch/x86/x86/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.151 src/sys/arch/x86/x86/pmap.c:1.152
--- src/sys/arch/x86/x86/pmap.c:1.151	Mon Jan  9 04:39:14 2012
+++ src/sys/arch/x86/x86/pmap.c	Mon Jan  9 04:55:35 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.151 2012/01/09 04:39:14 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.152 2012/01/09 04:55: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.151 2012/01/09 04:39:14 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.152 2012/01/09 04:55:35 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -1880,16 +1880,22 @@ pmap_free_ptp(struct pmap *pmap, struct 
 #  if defined(__x86_64__)
 		/*
 		 * If ptp is a L3 currently mapped in kernel space,
-		 * clear it before freeing
+		 * on any cpu, clear it before freeing
 		 */
-		if (pmap_pdirpa(pmap, 0) == curcpu()-ci_xen_current_user_pgd
-		 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 
-			 */ 
-			xen_kpm_sync(pmap, index);
+		struct cpu_info *ci;
+		CPU_INFO_ITERATOR cii;
+
+		for (CPU_INFO_FOREACH(cii, ci)) {
+			if (pmap_pdirpa(pmap, 0) == ci-ci_xen_current_user_pgd
+			 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 
+ */ 
+xen_kpm_sync(pmap, index);
+break;
+			}
 		}
 #  endif /*__x86_64__ */
 		invaladdr = level == 1 ? (vaddr_t)ptes :



CVS commit: src/sys/arch

2012-01-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jan  9 12:58:49 UTC 2012

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

Log Message:
Harden cross-cpu L3 sync - avoid optimisations that may race.
Update ci-ci_kpm_pdir from user pmap, not global pmap_kernel() entry which may 
get clobbered by other CPUs.
XXX: Look into why we use pmap_kernel() userspace entries at all.


To generate a diff of this commit:
cvs rdiff -u -r1.152 -r1.153 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.12 -r1.13 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.152 src/sys/arch/x86/x86/pmap.c:1.153
--- src/sys/arch/x86/x86/pmap.c:1.152	Mon Jan  9 04:55:35 2012
+++ src/sys/arch/x86/x86/pmap.c	Mon Jan  9 12:58:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.152 2012/01/09 04:55:35 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.153 2012/01/09 12:58:49 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.152 2012/01/09 04:55:35 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.153 2012/01/09 12:58:49 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -1882,20 +1882,14 @@ pmap_free_ptp(struct pmap *pmap, struct 
 		 * If ptp is a L3 currently mapped in kernel space,
 		 * on any cpu, clear it before freeing
 		 */
-		struct cpu_info *ci;
-		CPU_INFO_ITERATOR cii;
+		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 
+			 */ 
+			xen_kpm_sync(pmap, index);
 
-		for (CPU_INFO_FOREACH(cii, ci)) {
-			if (pmap_pdirpa(pmap, 0) == ci-ci_xen_current_user_pgd
-			 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 
- */ 
-xen_kpm_sync(pmap, index);
-break;
-			}
 		}
 #  endif /*__x86_64__ */
 		invaladdr = level == 1 ? (vaddr_t)ptes :

Index: src/sys/arch/xen/x86/xen_pmap.c
diff -u src/sys/arch/xen/x86/xen_pmap.c:1.12 src/sys/arch/xen/x86/xen_pmap.c:1.13
--- src/sys/arch/xen/x86/xen_pmap.c:1.12	Fri Dec 30 16:55:21 2011
+++ src/sys/arch/xen/x86/xen_pmap.c	Mon Jan  9 12:58:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_pmap.c,v 1.12 2011/12/30 16:55:21 cherry Exp $	*/
+/*	$NetBSD: xen_pmap.c,v 1.13 2012/01/09 12:58:49 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -102,7 +102,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: xen_pmap.c,v 1.12 2011/12/30 16:55:21 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_pmap.c,v 1.13 2012/01/09 12:58:49 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -576,6 +576,8 @@ pmap_kpm_sync_xcall(void *arg1, void *ar
 
 	struct pmap *pmap = arg1;
 	int index = *(int *)arg2;
+	KASSERT(pmap == pmap_kernel() || index  PDIR_SLOT_PTE);
+	
 	struct cpu_info *ci = xpq_cpu();
 
 	if (pmap == pmap_kernel()) {
@@ -596,7 +598,7 @@ pmap_kpm_sync_xcall(void *arg1, void *ar
 	}
 	
 	pmap_pte_set(ci-ci_kpm_pdir[index],
-	pmap_kernel()-pm_pdir[index]);
+	pmap-pm_pdir[index]);
 	pmap_pte_flush();
 #endif /* PAE || __x86_64__ */
 }
@@ -650,6 +652,7 @@ xen_kpm_sync(struct pmap *pmap, int inde
 #else /* MULTIPROCESSOR */
 #define CPU_IS_CURCPU(ci) __predict_true((ci) == curcpu())
 #endif /* MULTIPROCESSOR */
+#if 0 /* XXX: Race with remote pmap_load() */
 if (ci-ci_want_pmapload 
 !CPU_IS_CURCPU(ci)) {
 	/*
@@ -659,7 +662,7 @@ xen_kpm_sync(struct pmap *pmap, int inde
 	 */
 	continue;
 }
-
+#endif /* 0 */
 where = xc_unicast(XC_HIGHPRI, pmap_kpm_sync_xcall,
 pmap, index, ci);
 xc_wait(where);



CVS commit: src/sys/arch

2012-01-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jan  9 13:04:13 UTC 2012

Modified Files:
src/sys/arch/amd64/include: pmap.h
src/sys/arch/i386/include: pmap.h
src/sys/arch/xen/x86: x86_xpmap.c

Log Message:
Make cross-cpu pte access MP safe.
XXX: review cases of use of pmap_set_pte() vs direct use of 
xpq_queue_pte_update()


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/amd64/include/pmap.h
cvs rdiff -u -r1.112 -r1.113 src/sys/arch/i386/include/pmap.h
cvs rdiff -u -r1.36 -r1.37 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/amd64/include/pmap.h
diff -u src/sys/arch/amd64/include/pmap.h:1.28 src/sys/arch/amd64/include/pmap.h:1.29
--- src/sys/arch/amd64/include/pmap.h:1.28	Sun Nov  6 15:18:18 2011
+++ src/sys/arch/amd64/include/pmap.h	Mon Jan  9 13:04:13 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.28 2011/11/06 15:18:18 cherry Exp $	*/
+/*	$NetBSD: pmap.h,v 1.29 2012/01/09 13:04:13 cherry Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -263,6 +263,8 @@
 atomic_and_ulong((volatile unsigned long *)p, ~(b))
 #define pmap_pte_flush()		/* nothing */
 #else
+extern kmutex_t pte_lock;
+
 static __inline pt_entry_t
 pmap_pa2pte(paddr_t pa)
 {
@@ -277,54 +279,57 @@ pmap_pte2pa(pt_entry_t pte)
 static __inline void
 pmap_pte_set(pt_entry_t *pte, pt_entry_t npte)
 {
-	int s = splvm();
+	mutex_enter(pte_lock);
 	xpq_queue_pte_update(xpmap_ptetomach(pte), npte);
-	splx(s);
+	mutex_exit(pte_lock);
 }
 
 static __inline pt_entry_t
 pmap_pte_cas(volatile pt_entry_t *ptep, pt_entry_t o, pt_entry_t n)
 {
-	int s = splvm();
-
-	pt_entry_t opte = *ptep;
+	pt_entry_t opte;
 
+	mutex_enter(pte_lock);
+	opte = *ptep;
 	if (opte == o) {
 		xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(ptep)), n);
 		xpq_flush_queue();
 	}
-	splx(s);
+
+	mutex_exit(pte_lock);
 	return opte;
 }
 
 static __inline pt_entry_t
 pmap_pte_testset(volatile pt_entry_t *pte, pt_entry_t npte)
 {
-	int s = splvm();
-	pt_entry_t opte = *pte;
+	pt_entry_t opte;
+
+	mutex_enter(pte_lock);
+	opte = *pte;
 	xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)), npte);
 	xpq_flush_queue();
-	splx(s);
+	mutex_exit(pte_lock);
 	return opte;
 }
 
 static __inline void
 pmap_pte_setbits(volatile pt_entry_t *pte, pt_entry_t bits)
 {
-	int s = splvm();
+	mutex_enter(pte_lock);
 	xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)), (*pte) | bits);
 	xpq_flush_queue();
-	splx(s);
+	mutex_exit(pte_lock);
 }
 
 static __inline void
 pmap_pte_clearbits(volatile pt_entry_t *pte, pt_entry_t bits)
 {	
-	int s = splvm();
+	mutex_enter(pte_lock);
 	xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)),
 	(*pte)  ~bits);
 	xpq_flush_queue();
-	splx(s);
+	mutex_exit(pte_lock);
 }
 
 static __inline void

Index: src/sys/arch/i386/include/pmap.h
diff -u src/sys/arch/i386/include/pmap.h:1.112 src/sys/arch/i386/include/pmap.h:1.113
--- src/sys/arch/i386/include/pmap.h:1.112	Sun Nov  6 15:18:18 2011
+++ src/sys/arch/i386/include/pmap.h	Mon Jan  9 13:04:13 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.112 2011/11/06 15:18:18 cherry Exp $	*/
+/*	$NetBSD: pmap.h,v 1.113 2012/01/09 13:04:13 cherry Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -354,6 +354,8 @@
 #endif /* PAE */
 
 #else /* XEN */
+extern kmutex_t pte_lock;
+
 static __inline pt_entry_t
 pmap_pa2pte(paddr_t pa)
 {
@@ -368,54 +370,57 @@ pmap_pte2pa(pt_entry_t pte)
 static __inline void
 pmap_pte_set(pt_entry_t *pte, pt_entry_t npte)
 {
-	int s = splvm();
+	mutex_enter(pte_lock);
 	xpq_queue_pte_update(xpmap_ptetomach(pte), npte);
-	splx(s);
+	mutex_exit(pte_lock);
 }
 
 static __inline pt_entry_t
 pmap_pte_cas(volatile pt_entry_t *ptep, pt_entry_t o, pt_entry_t n)
 {
-	int s = splvm();
-	pt_entry_t opte = *ptep;
+	pt_entry_t opte;
 
+	mutex_enter(pte_lock);
+	opte = *ptep;
 	if (opte == o) {
 		xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(ptep)), n);
 		xpq_flush_queue();
 	}
-	splx(s);
+	mutex_exit(pte_lock);
 	return opte;
 }
 
 static __inline pt_entry_t
 pmap_pte_testset(volatile pt_entry_t *pte, pt_entry_t npte)
 {
-	int s = splvm();
-	pt_entry_t opte = *pte;
+	pt_entry_t opte;
+
+	mutex_enter(pte_lock);
+	opte = *pte;
 	xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)),
 	npte);
 	xpq_flush_queue();
-	splx(s);
+	mutex_exit(pte_lock);
 	return opte;
 }
 
 static __inline void
 pmap_pte_setbits(volatile pt_entry_t *pte, pt_entry_t bits)
 {
-	int s = splvm();
+	mutex_enter(pte_lock);
 	xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)), (*pte) | bits);
 	xpq_flush_queue();
-	splx(s);
+	mutex_exit(pte_lock);
 }
 
 static __inline void
 pmap_pte_clearbits(volatile pt_entry_t *pte, pt_entry_t bits)
 {	
-	int s = splvm();
+	mutex_enter(pte_lock);
 	xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)),
 	

CVS commit: src/sys/arch/xen/xen

2012-01-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jan  9 13:33:38 UTC 2012

Modified Files:
src/sys/arch/xen/xen: clock.c

Log Message:
Remove obsolete comment.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/xen/xen/clock.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/xen/clock.c
diff -u src/sys/arch/xen/xen/clock.c:1.58 src/sys/arch/xen/xen/clock.c:1.59
--- src/sys/arch/xen/xen/clock.c:1.58	Wed Dec  7 15:47:43 2011
+++ src/sys/arch/xen/xen/clock.c	Mon Jan  9 13:33:38 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.58 2011/12/07 15:47:43 cegger Exp $	*/
+/*	$NetBSD: clock.c,v 1.59 2012/01/09 13:33:38 cherry Exp $	*/
 
 /*
  *
@@ -29,7 +29,7 @@
 #include opt_xen.h
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.58 2011/12/07 15:47:43 cegger Exp $);
+__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.59 2012/01/09 13:33:38 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -395,7 +395,6 @@ sysctl_xen_timepush(SYSCTLFN_ARGS)
 #endif
 
 /* ARGSUSED */
-/* SMP note: Timecounter uses vcpu0's clock */
 u_int
 xen_get_timecount(struct timecounter *tc)
 {



CVS commit: src/sys/arch/xen/xen

2012-01-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jan  9 13:35:42 UTC 2012

Modified Files:
src/sys/arch/xen/xen: clock.c

Log Message:
Remove redundant use of curcpu().


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/xen/xen/clock.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/xen/clock.c
diff -u src/sys/arch/xen/xen/clock.c:1.59 src/sys/arch/xen/xen/clock.c:1.60
--- src/sys/arch/xen/xen/clock.c:1.59	Mon Jan  9 13:33:38 2012
+++ src/sys/arch/xen/xen/clock.c	Mon Jan  9 13:35:42 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.59 2012/01/09 13:33:38 cherry Exp $	*/
+/*	$NetBSD: clock.c,v 1.60 2012/01/09 13:35:42 cherry Exp $	*/
 
 /*
  *
@@ -29,7 +29,7 @@
 #include opt_xen.h
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.59 2012/01/09 13:33:38 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.60 2012/01/09 13:35:42 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -237,7 +237,7 @@ xen_wall_time(struct timespec *wt)
 		 * Under Xen3, shadow-ts is the wall time less system time
 		 * get_vcpu_time() will update shadow
 		 */
-		nsec = get_vcpu_time(curcpu());
+		nsec = get_vcpu_time(ci);
 		*wt = shadow-ts;
 		nsec += wt-tv_nsec;
 	} while (!time_values_up_to_date(ci));



CVS commit: src/sys/arch/i386/i386

2012-09-01 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Sep  1 23:19:47 UTC 2012

Modified Files:
src/sys/arch/i386/i386: locore.S

Log Message:
Restrict export of the tmpgdt symbol to XEN kernels

Spotted by uwe@


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/arch/i386/i386/locore.S

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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.101 src/sys/arch/i386/i386/locore.S:1.102
--- src/sys/arch/i386/i386/locore.S:1.101	Wed Jun 27 00:37:08 2012
+++ src/sys/arch/i386/i386/locore.S	Sat Sep  1 23:19:46 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.101 2012/06/27 00:37:08 jym Exp $	*/
+/*	$NetBSD: locore.S,v 1.102 2012/09/01 23:19:46 cherry Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -129,7 +129,7 @@
  */
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: locore.S,v 1.101 2012/06/27 00:37:08 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: locore.S,v 1.102 2012/09/01 23:19:46 cherry Exp $);
 
 #include opt_compat_oldboot.h
 #include opt_ddb.h
@@ -233,10 +233,10 @@ _C_LABEL(tablesize):	.long	0
 tmpstk:
 #ifdef XEN
 	.align 		PAGE_SIZE, 0x0	# Align on page boundary
+	.globl tmpgdt
 _C_LABEL(tmpgdt):
 	.space 		PAGE_SIZE	# Xen expects a page
 #endif /* XEN */
-	.globl tmpgdt
 #ifndef XEN
 #define	_RELOC(x)	((x) - KERNBASE)
 #else



CVS commit: src/sys/arch/amd64/amd64

2012-09-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Sep  3 05:01:45 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Revert to unmanaged x86 memory mapped isa and pci space.
This is a revert of commit r1.169:
http://mail-index.netbsd.org/source-changes/2011/11/06/msg028702.html

This should allow X to run on NetBSD/xen amd64 dom0, and fixes PR #46634


To generate a diff of this commit:
cvs rdiff -u -r1.189 -r1.190 src/sys/arch/amd64/amd64/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/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.189 src/sys/arch/amd64/amd64/machdep.c:1.190
--- src/sys/arch/amd64/amd64/machdep.c:1.189	Sun Jul 15 15:17:56 2012
+++ src/sys/arch/amd64/amd64/machdep.c	Mon Sep  3 05:01:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.189 2012/07/15 15:17:56 dsl Exp $	*/
+/*	$NetBSD: machdep.c,v 1.190 2012/09/03 05:01:44 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.189 2012/07/15 15:17:56 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.190 2012/09/03 05:01:44 cherry Exp $);
 
 /* #define XENDEBUG_LOW  */
 
@@ -1723,8 +1723,8 @@ init_x86_64(paddr_t first_avail)
 	/* Determine physical address space */
 	avail_start = first_avail;
 	avail_end = ctob(xen_start_info.nr_pages);
-	pmap_pa_start = 0;
-	pmap_pa_end = pmap_pa_start + ctob(xen_start_info.nr_pages);
+	pmap_pa_start = (KERNTEXTOFF - KERNBASE);
+	pmap_pa_end = avail_end;
 	__PRINTK((pmap_pa_start 0x%lx avail_start 0x%lx avail_end 0x%lx\n,
 	pmap_pa_start, avail_start, avail_end));
 #endif	/* !XEN */



CVS commit: src/sys/dev/usb

2009-12-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Dec 12 14:01:54 UTC 2009

Modified Files:
src/sys/dev/usb: usbdevs

Log Message:
Add product IDs for Qualcomm RWT FCT-CDMA 2000 1xRTT Modem, ZTE Storage and 
CDMA 1xEVDO Modem
From $FreeBSD: head/sys/dev/usb/usbdevs 199331 2009-11-16 20:35:16Z thompsa $


To generate a diff of this commit:
cvs rdiff -u -r1.537 -r1.538 src/sys/dev/usb/usbdevs

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

Modified files:

Index: src/sys/dev/usb/usbdevs
diff -u src/sys/dev/usb/usbdevs:1.537 src/sys/dev/usb/usbdevs:1.538
--- src/sys/dev/usb/usbdevs:1.537	Sun Nov 15 17:33:28 2009
+++ src/sys/dev/usb/usbdevs	Sat Dec 12 14:01:54 2009
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.537 2009/11/15 17:33:28 tsutsui Exp $
+$NetBSD: usbdevs,v 1.538 2009/12/12 14:01:54 cherry Exp $
 
 /*
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -1940,8 +1940,11 @@
 /* Qualcomm products */
 product QUALCOMM CDMA_MSM	0x6000	CDMA Technologies MSM phone
 product QUALCOMM MSM_HSDPA	0x6613	HSDPA MSM
+product QUALCOMM2 RWT_FCT   0x3100  RWT FCT-CDMA 2000 1xRTT modem
 product QUALCOMM2 CDMA_MSM	0x3196	CDMA Technologies MSM modem
 product QUALCOMMINC CDMA_MSM	0x0001	CDMA Technologies MSM modem
+product QUALCOMMINC ZTE_STOR	0x2000  USB ZTE Storage
+product QUALCOMMINC AC8700	0xfffe	CDMA 1xEVDO USB modem
 
 /* Qualcomm Kyocera products */
 product QUALCOMM_K CDMA_MSM_K	0x17da	Qualcomm Kyocera CDMA Technologies MSM



CVS commit: src/sys/dev/usb

2009-12-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Dec 12 14:03:48 UTC 2009

Modified Files:
src/sys/dev/usb: usbdevs.h usbdevs_data.h

Log Message:
regen from usbdevs 1.538
 Add product IDs for Qualcomm RWT FCT-CDMA 2000 1xRTT Modem, ZTE Storage and 
 CDMA 1xEVDO Modem
 From $FreeBSD: head/sys/dev/usb/usbdevs 199331 2009-11-16 20:35:16Z thompsa $


To generate a diff of this commit:
cvs rdiff -u -r1.531 -r1.532 src/sys/dev/usb/usbdevs.h
cvs rdiff -u -r1.532 -r1.533 src/sys/dev/usb/usbdevs_data.h

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

Modified files:

Index: src/sys/dev/usb/usbdevs.h
diff -u src/sys/dev/usb/usbdevs.h:1.531 src/sys/dev/usb/usbdevs.h:1.532
--- src/sys/dev/usb/usbdevs.h:1.531	Sun Nov 15 17:34:32 2009
+++ src/sys/dev/usb/usbdevs.h	Sat Dec 12 14:03:48 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdevs.h,v 1.531 2009/11/15 17:34:32 tsutsui Exp $	*/
+/*	$NetBSD: usbdevs.h,v 1.532 2009/12/12 14:03:48 cherry Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
@@ -1947,8 +1947,11 @@
 /* Qualcomm products */
 #define	USB_PRODUCT_QUALCOMM_CDMA_MSM	0x6000		/* CDMA Technologies MSM phone */
 #define	USB_PRODUCT_QUALCOMM_MSM_HSDPA	0x6613		/* HSDPA MSM */
+#define	USB_PRODUCT_QUALCOMM2_RWT_FCT	0x3100		/* RWT FCT-CDMA 2000 1xRTT modem */
 #define	USB_PRODUCT_QUALCOMM2_CDMA_MSM	0x3196		/* CDMA Technologies MSM modem */
 #define	USB_PRODUCT_QUALCOMMINC_CDMA_MSM	0x0001		/* CDMA Technologies MSM modem */
+#define	USB_PRODUCT_QUALCOMMINC_ZTE_STOR	0x2000		/* USB ZTE Storage */
+#define	USB_PRODUCT_QUALCOMMINC_AC8700	0xfffe		/* CDMA 1xEVDO USB modem */
 
 /* Qualcomm Kyocera products */
 #define	USB_PRODUCT_QUALCOMM_K_CDMA_MSM_K	0x17da		/* Qualcomm Kyocera CDMA Technologies MSM */

Index: src/sys/dev/usb/usbdevs_data.h
diff -u src/sys/dev/usb/usbdevs_data.h:1.532 src/sys/dev/usb/usbdevs_data.h:1.533
--- src/sys/dev/usb/usbdevs_data.h:1.532	Sun Nov 15 17:34:32 2009
+++ src/sys/dev/usb/usbdevs_data.h	Sat Dec 12 14:03:48 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdevs_data.h,v 1.532 2009/11/15 17:34:32 tsutsui Exp $	*/
+/*	$NetBSD: usbdevs_data.h,v 1.533 2009/12/12 14:03:48 cherry Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
@@ -5659,6 +5659,10 @@
 	HSDPA MSM,
 	},
 	{
+	USB_VENDOR_QUALCOMM2, USB_PRODUCT_QUALCOMM2_RWT_FCT,
+	RWT FCT-CDMA 2000 1xRTT modem,
+	},
+	{
 	USB_VENDOR_QUALCOMM2, USB_PRODUCT_QUALCOMM2_CDMA_MSM,
 	CDMA Technologies MSM modem,
 	},
@@ -5667,6 +5671,14 @@
 	CDMA Technologies MSM modem,
 	},
 	{
+	USB_VENDOR_QUALCOMMINC, USB_PRODUCT_QUALCOMMINC_ZTE_STOR,
+	USB ZTE Storage,
+	},
+	{
+	USB_VENDOR_QUALCOMMINC, USB_PRODUCT_QUALCOMMINC_AC8700,
+	CDMA 1xEVDO USB modem,
+	},
+	{
 	USB_VENDOR_QUALCOMM_K, USB_PRODUCT_QUALCOMM_K_CDMA_MSM_K,
 	Qualcomm Kyocera CDMA Technologies MSM,
 	},
@@ -7019,4 +7031,4 @@
 	Prestige,
 	},
 };
-const int usb_nproducts = 1281;
+const int usb_nproducts = 1284;



CVS commit: src/sys/dev/usb

2009-12-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Dec 12 14:18:28 UTC 2009

Modified Files:
src/sys/dev/usb: ugensa.c

Log Message:
Add ID for Qualcomminc AC8700 as found in ZTE, Incorporated ZTE CDMA Tech, rev 
1.10/0.00,  Works with BSNL (http://www.bsnl.co.in) EVDO service


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/usb/ugensa.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/dev/usb/ugensa.c
diff -u src/sys/dev/usb/ugensa.c:1.24 src/sys/dev/usb/ugensa.c:1.25
--- src/sys/dev/usb/ugensa.c:1.24	Thu Nov 12 19:51:44 2009
+++ src/sys/dev/usb/ugensa.c	Sat Dec 12 14:18:27 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugensa.c,v 1.24 2009/11/12 19:51:44 dyoung Exp $	*/
+/*	$NetBSD: ugensa.c,v 1.25 2009/12/12 14:18:27 cherry Exp $	*/
 
 /*
  * Copyright (c) 2004, 2005 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ugensa.c,v 1.24 2009/11/12 19:51:44 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: ugensa.c,v 1.25 2009/12/12 14:18:27 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -96,6 +96,7 @@
 	{{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_FLEXPACKGPS }, 0 },
 	{{ USB_VENDOR_QUALCOMM_K, USB_PRODUCT_QUALCOMM_K_CDMA_MSM_K }, 0 },
 	{{ USB_VENDOR_DELL, USB_PRODUCT_DELL_HSDPA }, 0 },
+	{{ USB_VENDOR_QUALCOMMINC, USB_PRODUCT_QUALCOMMINC_AC8700 }, 0 },
 
 	/*
 	 * The following devices are untested, but they are purported to



CVS commit: src/sys/dev/usb

2009-12-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Dec 12 14:30:59 UTC 2009

Modified Files:
src/sys/dev/usb: usbdevs.h usbdevs_data.h

Log Message:
regen properly for usbdevs, 1.538, _after_ commit


To generate a diff of this commit:
cvs rdiff -u -r1.532 -r1.533 src/sys/dev/usb/usbdevs.h
cvs rdiff -u -r1.533 -r1.534 src/sys/dev/usb/usbdevs_data.h

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

Modified files:

Index: src/sys/dev/usb/usbdevs.h
diff -u src/sys/dev/usb/usbdevs.h:1.532 src/sys/dev/usb/usbdevs.h:1.533
--- src/sys/dev/usb/usbdevs.h:1.532	Sat Dec 12 14:03:48 2009
+++ src/sys/dev/usb/usbdevs.h	Sat Dec 12 14:30:59 2009
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs.h,v 1.532 2009/12/12 14:03:48 cherry Exp $	*/
+/*	$NetBSD: usbdevs.h,v 1.533 2009/12/12 14:30:59 cherry Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.537 2009/11/15 17:33:28 tsutsui Exp
+ *	NetBSD: usbdevs,v 1.538 2009/12/12 14:01:54 cherry Exp
  */
 
 /*

Index: src/sys/dev/usb/usbdevs_data.h
diff -u src/sys/dev/usb/usbdevs_data.h:1.533 src/sys/dev/usb/usbdevs_data.h:1.534
--- src/sys/dev/usb/usbdevs_data.h:1.533	Sat Dec 12 14:03:48 2009
+++ src/sys/dev/usb/usbdevs_data.h	Sat Dec 12 14:30:59 2009
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs_data.h,v 1.533 2009/12/12 14:03:48 cherry Exp $	*/
+/*	$NetBSD: usbdevs_data.h,v 1.534 2009/12/12 14:30:59 cherry Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.537 2009/11/15 17:33:28 tsutsui Exp
+ *	NetBSD: usbdevs,v 1.538 2009/12/12 14:01:54 cherry Exp
  */
 
 /*



CVS commit: src/share/man/man4

2009-12-14 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Dec 14 09:06:37 UTC 2009

Modified Files:
src/share/man/man4: ugensa.4

Log Message:
Add reference to Qualcom Inc AC8700 / ZTE 1x EVDO interface. Thanks 
sayspra...@gmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/share/man/man4/ugensa.4

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

Modified files:

Index: src/share/man/man4/ugensa.4
diff -u src/share/man/man4/ugensa.4:1.8 src/share/man/man4/ugensa.4:1.9
--- src/share/man/man4/ugensa.4:1.8	Wed Apr 30 13:10:54 2008
+++ src/share/man/man4/ugensa.4	Mon Dec 14 09:06:37 2009
@@ -1,4 +1,4 @@
-.\ $NetBSD: ugensa.4,v 1.8 2008/04/30 13:10:54 martin Exp $
+.\ $NetBSD: ugensa.4,v 1.9 2009/12/14 09:06:37 cherry Exp $
 .\
 .\ Copyright (c) 2001 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -47,6 +47,7 @@
 .It Airprime PC5220
 .It Novatel FlexPak GPS receiver
 .It Qualcom CDMA MSM (found in Kyocera KPC650 EVDO interface)
+.It Qualcom Inc. CDMA AC8700 (found in the ZTE 1x EVDO interface)
 .It Sierra AirCard 580
 .It Sierra AirCard 595
 .It Sierra AirCard 875 [not tested]



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

2011-08-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Aug  4 09:07:47 UTC 2011

Modified Files:
src/sys/arch/xen/include [cherry-xenmp]: evtchn.h hypervisor.h intr.h
src/sys/arch/xen/x86 [cherry-xenmp]: hypervisor_machdep.c
src/sys/arch/xen/xen [cherry-xenmp]: evtchn.c xenevt.c

Log Message:
first cut at per-cpu event handling


To generate a diff of this commit:
cvs rdiff -u -r1.18.10.1 -r1.18.10.2 src/sys/arch/xen/include/evtchn.h
cvs rdiff -u -r1.31 -r1.31.10.1 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.31.10.2 -r1.31.10.3 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.14.2.1 -r1.14.2.2 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.47.6.1 -r1.47.6.2 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.37 -r1.37.2.1 src/sys/arch/xen/xen/xenevt.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/include/evtchn.h
diff -u src/sys/arch/xen/include/evtchn.h:1.18.10.1 src/sys/arch/xen/include/evtchn.h:1.18.10.2
--- src/sys/arch/xen/include/evtchn.h:1.18.10.1	Fri Jun  3 13:27:40 2011
+++ src/sys/arch/xen/include/evtchn.h	Thu Aug  4 09:07:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.h,v 1.18.10.1 2011/06/03 13:27:40 cherry Exp $	*/
+/*	$NetBSD: evtchn.h,v 1.18.10.2 2011/08/04 09:07:46 cherry Exp $	*/
 
 /*
  *
@@ -42,7 +42,9 @@
 int event_remove_handler(int, int (*func)(void *), void *);
 
 struct intrhand;
-void event_set_iplhandler(struct intrhand *, int);
+void event_set_iplhandler(struct cpu_info *ci,
+			  struct intrhand *, 
+			  int);
 
 extern int debug_port;
 extern int xen_debug_handler(void *);

Index: src/sys/arch/xen/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.31 src/sys/arch/xen/include/hypervisor.h:1.31.10.1
--- src/sys/arch/xen/include/hypervisor.h:1.31	Mon Oct 19 18:41:10 2009
+++ src/sys/arch/xen/include/hypervisor.h	Thu Aug  4 09:07:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.31 2009/10/19 18:41:10 bouyer Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.31.10.1 2011/08/04 09:07:46 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -91,6 +91,7 @@
 #include xen/xen3-public/io/netif.h
 #include xen/xen3-public/io/blkif.h
 
+#include machine/cpu.h
 #include machine/hypercalls.h
 
 #undef u8
@@ -136,7 +137,8 @@
 void hypervisor_mask_event(unsigned int);
 void hypervisor_clear_event(unsigned int);
 void hypervisor_enable_ipl(unsigned int);
-void hypervisor_set_ipending(uint32_t, int, int);
+void hypervisor_set_ipending(struct cpu_info *, 
+			 uint32_t, int, int);
 void hypervisor_machdep_attach(void);
 
 /* 

Index: src/sys/arch/xen/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.31.10.2 src/sys/arch/xen/include/intr.h:1.31.10.3
--- src/sys/arch/xen/include/intr.h:1.31.10.2	Sun Jun 26 12:56:32 2011
+++ src/sys/arch/xen/include/intr.h	Thu Aug  4 09:07:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.31.10.2 2011/06/26 12:56:32 cherry Exp $	*/
+/*	$NetBSD: intr.h,v 1.31.10.3 2011/08/04 09:07:46 cherry Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -58,13 +58,8 @@
 	struct intrhand *ev_handlers;	/* handler chain */
 	struct evcnt ev_evcnt;		/* interrupt counter */
 	char ev_evname[32];		/* event counter name */
+	struct cpu_info *ev_cpu;	/* cpu on which this event is bound */
 	struct simplelock ev_lock;	/* protects this structure */
-
-	/* 
-	 * XXX: The lock is quite coursegrained ( for the entire
-	 * handler list ), but contention is expected to be low. See
-	 * how this performs and revisit.
-	 */
 };
 
 /*

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.1 src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.2
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.1	Fri Jun  3 13:27:41 2011
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Thu Aug  4 09:07:47 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.14.2.1 2011/06/03 13:27:41 cherry Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.14.2.2 2011/08/04 09:07:47 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.14.2.1 2011/06/03 13:27:41 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.14.2.2 2011/08/04 09:07:47 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -86,13 +86,101 @@
 // #define PORT_DEBUG 4
 // #define EARLY_DEBUG_EVENT
 
+static inline unsigned int
+evt_bitstr_to_port(unsigned long l1, unsigned long l2)
+{
+	unsigned int l1i, l2i, port;
+
+	l1i = xen_ffs(l1) - 1;
+	l2i = xen_ffs(l2) - 1;
+
+	port = (l1i  LONG_SHIFT) + l2i;
+	return port;
+}
+
+/* callback function type */
+typedef void (*iterate_func_t)(struct cpu_info *,
+			   unsigned int,
+			   unsigned int,
+			   unsigned int,
+			   void *);
+
+
+static inline void
+evt_iterate_pending(struct cpu_info *ci,
+		volatile unsigned long *pendingl1,
+		volatile 

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

2011-08-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Aug  4 13:04:20 UTC 2011

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

Log Message:
Send an ipi at IPL_HIGH to remote cpu, in order to get it to run spllower()


To generate a diff of this commit:
cvs rdiff -u -r1.47.6.2 -r1.47.6.3 src/sys/arch/xen/xen/evtchn.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/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.47.6.2 src/sys/arch/xen/xen/evtchn.c:1.47.6.3
--- src/sys/arch/xen/xen/evtchn.c:1.47.6.2	Thu Aug  4 09:07:47 2011
+++ src/sys/arch/xen/xen/evtchn.c	Thu Aug  4 13:04:20 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.47.6.2 2011/08/04 09:07:47 cherry Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.47.6.3 2011/08/04 13:04:20 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: evtchn.c,v 1.47.6.2 2011/08/04 09:07:47 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: evtchn.c,v 1.47.6.3 2011/08/04 13:04:20 cherry Exp $);
 
 #include opt_xen.h
 #include isa.h
@@ -245,7 +245,16 @@
 	evtsource[evtch]-ev_imask,
 	evtch  LONG_SHIFT,
 	evtch  LONG_MASK);
-		/* leave masked */
+
+		if (evtsource[evtch]-ev_cpu != ci) { 
+			/* facilitate spllower() on remote cpu */
+			struct cpu_info *rci = evtsource[evtch]-ev_cpu;
+			if (xen_send_ipi(rci, XEN_IPI_KICK)) {
+panic(xen_send_ipi(%s, XEN_IPI_KICK) failed\n, cpu_name(rci));
+			}
+		}
+
+		/* leave masked */ 
 		return 0;
 	}
 	ci-ci_ilevel = evtsource[evtch]-ev_maxlevel;



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

2011-08-05 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Aug  5 17:26:27 UTC 2011

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

Log Message:
pmap_enter() test needs an address that work for both i386 and amd64


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/arch/xen/xen/xentests.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/xen/xentests.c
diff -u src/sys/arch/xen/xen/xentests.c:1.1.2.1 src/sys/arch/xen/xen/xentests.c:1.1.2.2
--- src/sys/arch/xen/xen/xentests.c:1.1.2.1	Fri Jun  3 13:27:42 2011
+++ src/sys/arch/xen/xen/xentests.c	Fri Aug  5 17:26:27 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: xentests.c,v 1.1.2.1 2011/06/03 13:27:42 cherry Exp $ */
+/* $NetBSD: xentests.c,v 1.1.2.2 2011/08/05 17:26:27 cherry Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: xentests.c,v 1.1.2.1 2011/06/03 13:27:42 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: xentests.c,v 1.1.2.2 2011/08/05 17:26:27 cherry Exp $);
 
 #include sys/types.h
 
@@ -997,6 +997,7 @@
 	return result;
 }
 
+#define USEFULLUSERLANDADDRESS 0x1
 
 /* pmap enter and extract */
 
@@ -1006,7 +1007,7 @@
 	KASSERT(arg != NULL);
 	struct test_args *ta = arg;
 
-	vaddr_t va = 0xfeedface  ~PAGE_MASK; /* PAGE_SIZE aligned */
+	vaddr_t va = USEFULLUSERLANDADDRESS  ~PAGE_MASK; /* PAGE_SIZE aligned */
 	paddr_t pa;
 	struct vm_page *pg;
 



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

2011-08-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Aug  6 14:05:35 UTC 2011

Modified Files:
src/sys/arch/i386/i386 [cherry-xenmp]: gdt.c

Log Message:
gdtgrow() must extend the gdt size on all cpus, not just the primary


To generate a diff of this commit:
cvs rdiff -u -r1.50.10.1 -r1.50.10.2 src/sys/arch/i386/i386/gdt.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/i386/i386/gdt.c
diff -u src/sys/arch/i386/i386/gdt.c:1.50.10.1 src/sys/arch/i386/i386/gdt.c:1.50.10.2
--- src/sys/arch/i386/i386/gdt.c:1.50.10.1	Sun Jul 31 20:49:10 2011
+++ src/sys/arch/i386/i386/gdt.c	Sat Aug  6 14:05:35 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gdt.c,v 1.50.10.1 2011/07/31 20:49:10 cherry Exp $	*/
+/*	$NetBSD: gdt.c,v 1.50.10.2 2011/08/06 14:05:35 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gdt.c,v 1.50.10.1 2011/07/31 20:49:10 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: gdt.c,v 1.50.10.2 2011/08/06 14:05:35 cherry Exp $);
 
 #include opt_multiprocessor.h
 #include opt_xen.h
@@ -266,15 +266,17 @@
 			gdt_size[which] = MINGDTSIZ;
 			new_len = gdt_size[which] * sizeof(gdt[0]);
 		}
-		for(va = (vaddr_t)(cpu_info_primary.ci_gdt) + old_len + max_len;
-		va  (vaddr_t)(cpu_info_primary.ci_gdt) + new_len + max_len;
-		va += PAGE_SIZE) {
-			while ((pg = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO))
-			== NULL) {
-uvm_wait(gdt_grow);
+		for (CPU_INFO_FOREACH(cii, ci)) {
+			for(va = (vaddr_t)(ci-ci_gdt) + old_len + max_len;
+			va  (vaddr_t)(ci-ci_gdt) + new_len + max_len;
+			va += PAGE_SIZE) {
+while ((pg = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO))
+   == NULL) {
+	uvm_wait(gdt_grow);
+}
+pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pg),
+	   VM_PROT_READ | VM_PROT_WRITE, 0);
 			}
-			pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pg),
-			VM_PROT_READ | VM_PROT_WRITE, 0);
 		}
 		return;
 	}



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

2011-08-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Aug  6 21:06:34 UTC 2011

Modified Files:
src/sys/arch/i386/i386 [cherry-xenmp]: machdep.c

Log Message:
Update cpu local GDT entries for TLS registers %gs and %fs


To generate a diff of this commit:
cvs rdiff -u -r1.702.2.2 -r1.702.2.3 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.702.2.2 src/sys/arch/i386/i386/machdep.c:1.702.2.3
--- src/sys/arch/i386/i386/machdep.c:1.702.2.2	Sun Jul 31 20:49:10 2011
+++ src/sys/arch/i386/i386/machdep.c	Sat Aug  6 21:06:34 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.702.2.2 2011/07/31 20:49:10 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.702.2.3 2011/08/06 21:06:34 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.702.2.2 2011/07/31 20:49:10 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.702.2.3 2011/08/06 21:06:34 cherry Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -560,6 +560,12 @@
 
 	HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), pcb-pcb_esp0);
 
+	/* Update TLS segment pointers */
+	update_descriptor(ci-ci_gdt[GUFS_SEL],
+			  (union descriptor *) pcb-pcb_fsd);
+	update_descriptor(ci-ci_gdt[GUGS_SEL], 
+			  (union descriptor *) pcb-pcb_gsd);
+
 	physop.cmd = PHYSDEVOP_SET_IOPL;
 	physop.u.set_iopl.iopl = pcb-pcb_iopl;
 	HYPERVISOR_physdev_op(physop);



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

2011-08-07 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Aug  7 19:48:08 UTC 2011

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

Log Message:
Fix XEN3PAE_DOMx build


To generate a diff of this commit:
cvs rdiff -u -r1.702.2.3 -r1.702.2.4 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.56.2.4 -r1.56.2.5 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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.702.2.3 src/sys/arch/i386/i386/machdep.c:1.702.2.4
--- src/sys/arch/i386/i386/machdep.c:1.702.2.3	Sat Aug  6 21:06:34 2011
+++ src/sys/arch/i386/i386/machdep.c	Sun Aug  7 19:48:07 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.702.2.3 2011/08/06 21:06:34 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.702.2.4 2011/08/07 19:48:07 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.702.2.3 2011/08/06 21:06:34 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.702.2.4 2011/08/07 19:48:07 cherry Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -1195,7 +1195,7 @@
 		pt_entry_t pg_nx = (cpu_feature[2]  CPUID_NOX ? PG_NX : 0);
 
 		pte = kvtopte((vaddr_t)gdt);
-		npte = pmap_pa2pte((paddr_t)gdt - KERNBASE);
+		npte = pmap_pa2pte((vaddr_t)gdt - KERNBASE);
 		npte |= PG_RO | pg_nx | PG_V;
 
 		xpq_queue_lock();

Index: src/sys/arch/xen/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.56.2.4 src/sys/arch/xen/x86/cpu.c:1.56.2.5
--- src/sys/arch/xen/x86/cpu.c:1.56.2.4	Sun Jul 31 20:49:11 2011
+++ src/sys/arch/xen/x86/cpu.c	Sun Aug  7 19:48:08 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.56.2.4 2011/07/31 20:49:11 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.56.2.5 2011/08/07 19:48:08 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.56.2.4 2011/07/31 20:49:11 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.56.2.5 2011/08/07 19:48:08 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -140,7 +140,7 @@
 	bool sc_wasonline;
 };
 
-int mp_cpu_start(struct cpu_info *, paddr_t);
+int mp_cpu_start(struct cpu_info *, vaddr_t);
 void mp_cpu_start_cleanup(struct cpu_info *);
 const struct cpu_functions mp_cpu_funcs = { mp_cpu_start, NULL,
   mp_cpu_start_cleanup };



CVS commit: src/sys/arch/xen/include

2011-08-10 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Aug 10 06:29:23 UTC 2011

Added Files:
src/sys/arch/xen/include: intrdefs.h

Log Message:
Add Xen specific ipi bitmasks


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.10 src/sys/arch/xen/include/intrdefs.h

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

Added files:

Index: src/sys/arch/xen/include/intrdefs.h
diff -u /dev/null src/sys/arch/xen/include/intrdefs.h:1.10
--- /dev/null	Wed Aug 10 06:29:23 2011
+++ src/sys/arch/xen/include/intrdefs.h	Wed Aug 10 06:29:23 2011
@@ -0,0 +1,17 @@
+/* $NetBSD: intrdefs.h,v 1.10 2011/08/10 06:29:23 cherry Exp $ */
+
+/* This file co-exists, and is included via machine/intrdefs.h */
+
+#ifndef _XEN_INTRDEFS_H_
+#define _XEN_INTRDEFS_H_
+
+/* Xen IPI types */
+#define XEN_IPI_KICK		0x
+#define XEN_IPI_HALT		0x0001
+#define XEN_IPI_SYNCH_FPU	0x0002
+#define XEN_IPI_DDB		0x0004
+#define XEN_IPI_XCALL		0x0008
+
+#define XEN_NIPIS 4 /* IPI_KICK doesn't have a handler */
+
+#endif /* _XEN_INTRDEFS_H_ */



CVS commit: src/sys/arch

2011-08-10 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Aug 10 06:30:59 UTC 2011

Modified Files:
src/sys/arch/amd64/include: intrdefs.h
src/sys/arch/i386/include: intrdefs.h

Log Message:
Include Xen specific definitions.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/amd64/include/intrdefs.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/i386/include/intrdefs.h

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/amd64/include/intrdefs.h
diff -u src/sys/arch/amd64/include/intrdefs.h:1.1 src/sys/arch/amd64/include/intrdefs.h:1.2
--- src/sys/arch/amd64/include/intrdefs.h:1.1	Sat Apr 26 18:39:43 2003
+++ src/sys/arch/amd64/include/intrdefs.h	Wed Aug 10 06:30:59 2011
@@ -1,3 +1,6 @@
-/*	$NetBSD: intrdefs.h,v 1.1 2003/04/26 18:39:43 fvdl Exp $	*/
+/*	$NetBSD: intrdefs.h,v 1.2 2011/08/10 06:30:59 cherry Exp $	*/
 
 #include x86/intrdefs.h
+#ifdef XEN
+#include xen/intrdefs.h
+#endif /* XEN */

Index: src/sys/arch/i386/include/intrdefs.h
diff -u src/sys/arch/i386/include/intrdefs.h:1.3 src/sys/arch/i386/include/intrdefs.h:1.4
--- src/sys/arch/i386/include/intrdefs.h:1.3	Wed Feb 26 21:29:01 2003
+++ src/sys/arch/i386/include/intrdefs.h	Wed Aug 10 06:30:59 2011
@@ -1,3 +1,6 @@
-/*	$NetBSD: intrdefs.h,v 1.3 2003/02/26 21:29:01 fvdl Exp $	*/
+/*	$NetBSD: intrdefs.h,v 1.4 2011/08/10 06:30:59 cherry Exp $	*/
 
 #include x86/intrdefs.h
+#ifdef XEN
+#include xen/intrdefs.h
+#endif /* XEN */



CVS commit: src/sys/arch/amd64/include

2011-08-10 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Aug 10 06:33:13 UTC 2011

Modified Files:
src/sys/arch/amd64/include: frameasm.h

Log Message:
Correct offset calculation for ci


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/amd64/include/frameasm.h

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/amd64/include/frameasm.h
diff -u src/sys/arch/amd64/include/frameasm.h:1.15 src/sys/arch/amd64/include/frameasm.h:1.16
--- src/sys/arch/amd64/include/frameasm.h:1.15	Wed Jan 12 23:12:11 2011
+++ src/sys/arch/amd64/include/frameasm.h	Wed Aug 10 06:33:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: frameasm.h,v 1.15 2011/01/12 23:12:11 joerg Exp $	*/
+/*	$NetBSD: frameasm.h,v 1.16 2011/08/10 06:33:13 cherry Exp $	*/
 
 #ifndef _AMD64_MACHINE_FRAMEASM_H
 #define _AMD64_MACHINE_FRAMEASM_H
@@ -132,15 +132,13 @@
 
 #ifdef XEN
 #define CLI(temp_reg) \
- 	movl CPUVAR(CPUID),%e ## temp_reg ;			\
- 	shlq $6,%r ## temp_reg ;\
- 	addq CPUVAR(VCPU),%r ## temp_reg ;			\
- 	movb $1,EVTCHN_UPCALL_MASK(%r ## temp_reg)
+ 	movq CPUVAR(VCPU),%r ## temp_reg ;			\
+	movb $1,EVTCHN_UPCALL_MASK(%r ## temp_reg);
+
 #define STI(temp_reg) \
- 	movl CPUVAR(CPUID),%e ## temp_reg ;			\
- 	shlq $6,%r ## temp_reg ;\
- 	addq CPUVAR(VCPU),%r ## temp_reg ;			\
- 	movb $0,EVTCHN_UPCALL_MASK(%r ## temp_reg)
+ 	movq CPUVAR(VCPU),%r ## temp_reg ;			\
+	movb $0,EVTCHN_UPCALL_MASK(%r ## temp_reg);
+
 #else /* XEN */
 #define CLI(temp_reg) cli
 #define STI(temp_reg) sti



CVS commit: src/sys/arch/i386/i386

2011-08-10 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Aug 10 06:38:02 UTC 2011

Modified Files:
src/sys/arch/i386/i386: machdep.c

Log Message:
tweak the xen specific startup path to not use %fs before it is setup. Minor 
refactoring. Use Xen specific ipi calls.


To generate a diff of this commit:
cvs rdiff -u -r1.706 -r1.707 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.706 src/sys/arch/i386/i386/machdep.c:1.707
--- src/sys/arch/i386/i386/machdep.c:1.706	Fri Jul  1 18:14:15 2011
+++ src/sys/arch/i386/i386/machdep.c	Wed Aug 10 06:38:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.706 2011/07/01 18:14:15 dyoung Exp $	*/
+/*	$NetBSD: machdep.c,v 1.707 2011/08/10 06:38:02 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.706 2011/07/01 18:14:15 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.707 2011/08/10 06:38:02 cherry Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -560,6 +560,12 @@
 
 	HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), pcb-pcb_esp0);
 
+	/* Update TLS segment pointers */
+	update_descriptor(ci-ci_gdt[GUFS_SEL],
+			  (union descriptor *) pcb-pcb_fsd);
+	update_descriptor(ci-ci_gdt[GUGS_SEL], 
+			  (union descriptor *) pcb-pcb_gsd);
+
 	physop.cmd = PHYSDEVOP_SET_IOPL;
 	physop.u.set_iopl.iopl = pcb-pcb_iopl;
 	HYPERVISOR_physdev_op(physop);
@@ -949,8 +955,12 @@
 	}
 
 #ifdef MULTIPROCESSOR
+#ifdef XEN
+	xen_broadcast_ipi(XEN_IPI_HALT);
+#else /* XEN */
 	x86_broadcast_ipi(X86_IPI_HALT);
-#endif
+#endif /* XEN */
+#endif /* MULTIPROCESSOR */
 
 	if (howto  RB_HALT) {
 #if NACPICA  0
@@ -1123,14 +1133,18 @@
 int xen_idt_idx;
 #endif
 
-#ifndef XEN
 void cpu_init_idt(void)
 {
+#ifndef XEN
 	struct region_descriptor region;
 	setregion(region, pentium_idt, NIDT * sizeof(idt[0]) - 1);
 	lidt(region);
-}
+#else /* XEN */
+	XENPRINTF((HYPERVISOR_set_trap_table %p\n, xen_idt));
+	if (HYPERVISOR_set_trap_table(xen_idt))
+		panic(HYPERVISOR_set_trap_table %p failed\n, xen_idt);
 #endif /* !XEN */
+}
 
 void
 initgdt(union descriptor *tgdt)
@@ -1166,7 +1180,28 @@
 	lgdt(region);
 #else /* !XEN */
 	frames[0] = xpmap_ptom((uint32_t)gdt - KERNBASE)  PAGE_SHIFT;
-	pmap_kenter_pa((vaddr_t)gdt, (uint32_t)gdt - KERNBASE, VM_PROT_READ, 0);
+	{	/*
+		 * Enter the gdt page RO into the kernel map. We can't
+		 * use pmap_kenter_pa() here, because %fs is not
+		 * usable until the gdt is loaded, and %fs is used as
+		 * the base pointer for curcpu() and curlwp(), both of
+		 * which are in the callpath of pmap_kenter_pa().
+		 * So we mash up our own - this is MD code anyway.
+		 *
+		 * XXX: review this once we have finegrained locking
+		 * for xpq.
+		 */
+		pt_entry_t *pte, npte;
+		pt_entry_t pg_nx = (cpu_feature[2]  CPUID_NOX ? PG_NX : 0);
+
+		pte = kvtopte((vaddr_t)gdt);
+		npte = pmap_pa2pte((vaddr_t)gdt - KERNBASE);
+		npte |= PG_RO | pg_nx | PG_V;
+
+		xpq_queue_pte_update(xpmap_ptetomach(pte), npte);
+		xpq_flush_queue();
+	}
+
 	XENPRINTK((loading gdt %lx, %d entries\n, frames[0]  PAGE_SHIFT,
 	NGDT));
 	if (HYPERVISOR_set_gdt(frames, NGDT /* XXX is it right ? */))
@@ -1579,10 +1614,7 @@
 	xen_idt[xen_idt_idx].address = (uint32_t)IDTVEC(svr4_fasttrap);
 	xen_idt_idx++;
 	lldt(GSEL(GLDT_SEL, SEL_KPL));
-
-	XENPRINTF((HYPERVISOR_set_trap_table %p\n, xen_idt));
-	if (HYPERVISOR_set_trap_table(xen_idt))
-		panic(HYPERVISOR_set_trap_table %p failed\n, xen_idt);
+	cpu_init_idt();
 #endif /* XEN */
 
 	init386_ksyms();



CVS commit: src/sys/arch/xen

2011-08-10 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Aug 10 09:50:37 UTC 2011

Modified Files:
src/sys/arch/xen/include: xenpmap.h
src/sys/arch/xen/x86: x86_xpmap.c

Log Message:
Introduce locking primitives for Xen pte operations, and xen helper calls for 
MP related MMU ops


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/xen/include/xenpmap.h
cvs rdiff -u -r1.28 -r1.29 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/include/xenpmap.h
diff -u src/sys/arch/xen/include/xenpmap.h:1.27 src/sys/arch/xen/include/xenpmap.h:1.28
--- src/sys/arch/xen/include/xenpmap.h:1.27	Fri Apr 29 22:45:41 2011
+++ src/sys/arch/xen/include/xenpmap.h	Wed Aug 10 09:50:37 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xenpmap.h,v 1.27 2011/04/29 22:45:41 jym Exp $	*/
+/*	$NetBSD: xenpmap.h,v 1.28 2011/08/10 09:50:37 cherry Exp $	*/
 
 /*
  *
@@ -36,6 +36,8 @@
 
 #define	INVALID_P2M_ENTRY	(~0UL)
 
+void xpq_queue_lock(void);
+void xpq_queue_unlock(void);
 void xpq_queue_machphys_update(paddr_t, paddr_t);
 void xpq_queue_invlpg(vaddr_t);
 void xpq_queue_pte_update(paddr_t, pt_entry_t);
@@ -46,6 +48,13 @@
 void xpq_queue_pin_table(paddr_t, int);
 void xpq_queue_unpin_table(paddr_t);
 int  xpq_update_foreign(paddr_t, pt_entry_t, int);
+void xen_vcpu_mcast_invlpg(vaddr_t, vaddr_t, uint32_t);
+void xen_vcpu_bcast_invlpg(vaddr_t, vaddr_t);
+void xen_mcast_tlbflush(uint32_t);
+void xen_bcast_tlbflush(void);
+void xen_mcast_invlpg(vaddr_t, uint32_t);
+void xen_bcast_invlpg(vaddr_t);
+
 
 #define xpq_queue_pin_l1_table(pa)	\
 	xpq_queue_pin_table(pa, MMUEXT_PIN_L1_TABLE)

Index: src/sys/arch/xen/x86/x86_xpmap.c
diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.28 src/sys/arch/xen/x86/x86_xpmap.c:1.29
--- src/sys/arch/xen/x86/x86_xpmap.c:1.28	Wed Jun 15 20:50:02 2011
+++ src/sys/arch/xen/x86/x86_xpmap.c	Wed Aug 10 09:50:37 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.28 2011/06/15 20:50:02 rmind Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.29 2011/08/10 09:50:37 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert m...@adviseo.fr
@@ -69,7 +69,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.28 2011/06/15 20:50:02 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.29 2011/08/10 09:50:37 cherry Exp $);
 
 #include opt_xen.h
 #include opt_ddb.h
@@ -77,6 +77,7 @@
 
 #include sys/param.h
 #include sys/systm.h
+#include sys/simplelock.h
 
 #include uvm/uvm.h
 
@@ -152,7 +153,9 @@
 		pmap_pte_clearbits(ptp, PG_RW);
 	}
 	s = splvm();
+	xpq_queue_lock();
 	xpq_queue_set_ldt(base, entries);
+	xpq_queue_unlock();
 	splx(s);
 }
 
@@ -163,12 +166,27 @@
 #define XPQUEUE_SIZE 2048
 static mmu_update_t xpq_queue[XPQUEUE_SIZE];
 static int xpq_idx = 0;
+static struct simplelock xpq_lock = SIMPLELOCK_INITIALIZER;
 
 void
+xpq_queue_lock(void)
+{
+	simple_lock(xpq_lock);
+}
+
+void
+xpq_queue_unlock(void)
+{
+	simple_unlock(xpq_lock);
+}
+
+/* Must be called with xpq_lock held */
+void
 xpq_flush_queue(void)
 {
 	int i, ok, ret;
 
+	KASSERT(simple_lock_held(xpq_lock));
 	XENPRINTK2((flush queue %p entries %d\n, xpq_queue, xpq_idx));
 	for (i = 0; i  xpq_idx; i++)
 		XENPRINTK2((%d: 0x%08 PRIx64  0x%08 PRIx64 \n, i,
@@ -187,10 +205,12 @@
 	xpq_idx = 0;
 }
 
+/* Must be called with xpq_lock held */
 static inline void
 xpq_increment_idx(void)
 {
 
+	KASSERT(simple_lock_held(xpq_lock));
 	xpq_idx++;
 	if (__predict_false(xpq_idx == XPQUEUE_SIZE))
 		xpq_flush_queue();
@@ -201,6 +221,7 @@
 {
 	XENPRINTK2((xpq_queue_machphys_update ma=0x% PRIx64  pa=0x% PRIx64
 	\n, (int64_t)ma, (int64_t)pa));
+	KASSERT(simple_lock_held(xpq_lock));
 	xpq_queue[xpq_idx].ptr = ma | MMU_MACHPHYS_UPDATE;
 	xpq_queue[xpq_idx].val = (pa - XPMAP_OFFSET)  PAGE_SHIFT;
 	xpq_increment_idx();
@@ -214,6 +235,7 @@
 {
 
 	KASSERT((ptr  3) == 0);
+	KASSERT(simple_lock_held(xpq_lock));
 	xpq_queue[xpq_idx].ptr = (paddr_t)ptr | MMU_NORMAL_PT_UPDATE;
 	xpq_queue[xpq_idx].val = val;
 	xpq_increment_idx();
@@ -226,6 +248,7 @@
 xpq_queue_pt_switch(paddr_t pa)
 {
 	struct mmuext_op op;
+	KASSERT(simple_lock_held(xpq_lock));
 	xpq_flush_queue();
 
 	XENPRINTK2((xpq_queue_pt_switch: 0x% PRIx64  0x% PRIx64 \n,
@@ -240,6 +263,8 @@
 xpq_queue_pin_table(paddr_t pa, int lvl)
 {
 	struct mmuext_op op;
+
+	KASSERT(simple_lock_held(xpq_lock));
 	xpq_flush_queue();
 
 	XENPRINTK2((xpq_queue_pin_l%d_table: %# PRIxPADDR \n,
@@ -256,6 +281,8 @@
 xpq_queue_unpin_table(paddr_t pa)
 {
 	struct mmuext_op op;
+
+	KASSERT(simple_lock_held(xpq_lock));
 	xpq_flush_queue();
 
 	XENPRINTK2((xpq_queue_unpin_table: %# PRIxPADDR \n, pa));
@@ -269,6 +296,8 @@
 xpq_queue_set_ldt(vaddr_t va, uint32_t entries)
 {
 	struct mmuext_op op;
+
+	KASSERT(simple_lock_held(xpq_lock));
 	xpq_flush_queue();
 
 	XENPRINTK2((xpq_queue_set_ldt\n));
@@ -284,6 +313,8 @@
 xpq_queue_tlb_flush(void)
 {
 	struct mmuext_op op;
+
+	

CVS commit: src/sys/arch

2011-08-10 Thread Cherry G. Mathew
 /* XEN */
 		x86_send_ipi(ci, 0);
+#endif /* XEN */
 	}
 }
 
@@ -239,7 +246,11 @@
 	KASSERT(kpreempt_disabled());
 	aston(l, X86_AST_GENERIC);
 	if (l-l_cpu != curcpu())
+#ifdef XEN
+		xen_send_ipi(l-l_cpu, XEN_IPI_KICK);
+#else /* XEN */
 		x86_send_ipi(l-l_cpu, 0);
+#endif /* XEN */
 }
 
 void
@@ -363,7 +374,7 @@
 	else
 		x86_cpu_idle_set(x86_cpu_idle_mwait, mwait, false);
 #else
-	x86_cpu_idle_set(x86_cpu_idle_xen, xen, false);
+	x86_cpu_idle_set(x86_cpu_idle_xen, xen, true);
 #endif
 }
 

Index: src/sys/arch/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.121 src/sys/arch/xen/conf/files.xen:1.122
--- src/sys/arch/xen/conf/files.xen:1.121	Mon Jun 13 00:53:15 2011
+++ src/sys/arch/xen/conf/files.xen	Wed Aug 10 11:39:45 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.121 2011/06/13 00:53:15 pgoyette Exp $
+#	$NetBSD: files.xen,v 1.122 2011/08/10 11:39:45 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -56,7 +56,6 @@
 file	arch/i386/i386/trap.c
 file	arch/i386/i386/lock_stubs.S
 
-file	arch/i386/i386/mptramp.S		multiprocessor
 
 file	arch/i386/i386/pmc.c			perfctrs
 
@@ -82,7 +81,6 @@
 file	arch/amd64/amd64/trap.c
 file	arch/amd64/amd64/fpu.c
 file	arch/amd64/amd64/lock_stubs.S
-file	arch/amd64/amd64/mptramp.S		multiprocessor
 endif
 
 file	kern/subr_disk_mbr.c		disk
@@ -129,7 +127,7 @@
 file	arch/xen/x86/consinit.c
 file	arch/x86/x86/identcpu.c
 file	arch/xen/x86/intr.c
-file	arch/x86/x86/ipi.c
+file	arch/xen/x86/xen_ipi.c		multiprocessor
 file	arch/x86/x86/pmap.c
 file	arch/x86/x86/pmap_tlb.c
 file	arch/x86/x86/procfs_machdep.c	procfs

Index: src/sys/arch/xen/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.31 src/sys/arch/xen/include/intr.h:1.32
--- src/sys/arch/xen/include/intr.h:1.31	Wed Jul 29 12:02:06 2009
+++ src/sys/arch/xen/include/intr.h	Wed Aug 10 11:39:45 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.31 2009/07/29 12:02:06 cegger Exp $	*/
+/*	$NetBSD: intr.h,v 1.32 2011/08/10 11:39:45 cherry Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -175,9 +175,15 @@
 struct pic *intr_findpic(int);
 void intr_add_pcibus(struct pcibus_attach_args *);
 
-int x86_send_ipi(struct cpu_info *, int);
-void x86_broadcast_ipi(int);
-void x86_multicast_ipi(int, int);
+#ifdef MULTIPROCESSOR
+void xen_ipi_init(void);
+int xen_send_ipi(struct cpu_info *, uint32_t);
+void xen_broadcast_ipi(uint32_t);
+#else
+#define xen_ipi_init(_1) do {} while(0) /* nothing */
+#define xen_send_ipi(_i1, _i2) do {} while(0) /* nothing */
+#define xen_broadcast_ipi(_i1) do {} while(0) /* nothing */
+#endif /* MULTIPROCESSOR */
 
 #endif /* !_LOCORE */
 

Added files:

Index: src/sys/arch/xen/x86/xen_ipi.c
diff -u /dev/null src/sys/arch/xen/x86/xen_ipi.c:1.2
--- /dev/null	Wed Aug 10 11:39:46 2011
+++ src/sys/arch/xen/x86/xen_ipi.c	Wed Aug 10 11:39:46 2011
@@ -0,0 +1,311 @@
+/* $NetBSD: xen_ipi.c,v 1.2 2011/08/10 11:39:46 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Cherry G. Mathew che...@zyx.in
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h			/* RCS ID macro */
+
+/* 
+ * Based on: x86/ipi.c
+ * __KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.2 2011/08/10 11:39:46 cherry Exp $); 
+ */
+
+__KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.2 2011/08/10 11:39:46 cherry Exp $);
+
+#include sys/types.h
+
+#include sys/atomic.h
+#include sys/mutex.h
+#include sys/cpu.h
+#include sys/device.h
+#include sys/xcall.h
+#include sys/errno.h
+#include sys/systm.h
+
+#include machine/cpu.h
+#ifdef __x86_64__

CVS commit: src/sys/arch/xen/x86

2011-08-10 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Aug 10 20:38:45 UTC 2011

Modified Files:
src/sys/arch/xen/x86: xen_ipi.c

Log Message:
KNF police (rmind@ :-)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/xen/x86/xen_ipi.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_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.2 src/sys/arch/xen/x86/xen_ipi.c:1.3
--- src/sys/arch/xen/x86/xen_ipi.c:1.2	Wed Aug 10 11:39:46 2011
+++ src/sys/arch/xen/x86/xen_ipi.c	Wed Aug 10 20:38:45 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.2 2011/08/10 11:39:46 cherry Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.3 2011/08/10 20:38:45 cherry Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -33,10 +33,10 @@
 
 /* 
  * Based on: x86/ipi.c
- * __KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.2 2011/08/10 11:39:46 cherry Exp $); 
+ * __KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.3 2011/08/10 20:38:45 cherry Exp $); 
  */
 
-__KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.2 2011/08/10 11:39:46 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.3 2011/08/10 20:38:45 cherry Exp $);
 
 #include sys/types.h
 
@@ -96,14 +96,11 @@
 		ci-ci_ipi_events[bit].ev_count++;
 		if (ipifunc[bit] != NULL) {
 			(*ipifunc[bit])(ci, regs);
-		}
-		else {
+		} else {
 			panic(ipifunc[%d] unsupported!\n, bit);
 			/* NOTREACHED */
 		}
 	}
-
-	return;
 }
 
 /* Must be called once for every cpu that expects to send/recv ipis */
@@ -119,7 +116,8 @@
 	vcpu = ci-ci_cpuid;
 	KASSERT(vcpu  MAX_VIRT_CPUS);
 
-	evtchn = ci-ci_ipi_evtchn = bind_vcpu_to_evtch(vcpu);
+	evtchn = bind_vcpu_to_evtch(vcpu);
+	ci-ci_ipi_evtchn = evtchn;
 
 	KASSERT(evtchn != -1  evtchn  NR_EVENT_CHANNELS);
 
@@ -130,7 +128,6 @@
 	}
 
 	hypervisor_enable_event(evtchn);
-	return;
 }
 
 /* prefer this to global variable */
@@ -148,8 +145,7 @@
 
 	if (ipimask  ~masks) {
 		return false;
-	}
-	else {
+	} else {
 		return true;
 	}
 
@@ -162,15 +158,14 @@
 
 	KASSERT(ci != NULL || ci != curcpu());
 
-	if (!(ci-ci_flags  CPUF_RUNNING)) {
+	if ((ci-ci_flags  CPUF_RUNNING) != 0) {
 		return ENOENT;
 	}
 
 	evtchn = ci-ci_ipi_evtchn;
-	if (false == valid_ipimask(ipimask)) {
-		panic(xen_send_ipi() called with invalid ipimask\n);
-		/* NOTREACHED */
-	}
+
+	KASSERTMSG(valid_ipimask(ipimask) == true, 
+		(xen_send_ipi() called with invalid ipimask\n));
 
 	atomic_or_32(ci-ci_ipis, ipimask);
 	hypervisor_notify_via_evtchn(evtchn);
@@ -184,10 +179,8 @@
 	struct cpu_info *ci, *self = curcpu();
 	CPU_INFO_ITERATOR cii;
 
-	if (false == valid_ipimask(ipimask)) {
-		panic(xen_broadcast_ipi() called with invalid ipimask\n);
-		/* NOTREACHED */
-	}
+	KASSERTMSG(valid_ipimask(ipimask) == true, 
+		(xen_broadcast_ipi() called with invalid ipimask\n));
 
 	/* 
 	 * XXX-cherry: there's an implicit broadcast sending order
@@ -211,9 +204,6 @@
 			}
 		}
 	}
-
-	return;
-	/* NOTREACHED */
 }
 
 /* MD wrapper for the xcall(9) callback. */
@@ -228,7 +218,6 @@
 		panic(vcpu% PRIuCPUID shutdown failed.\n, ci-ci_cpuid);
 	}
 
-	return;
 }
 
 static void
@@ -242,7 +231,6 @@
 #else
 	npxsave_cpu(true);
 #endif /* __x86_64__ */
-	return;
 }
 
 static void
@@ -291,7 +279,6 @@
 	KASSERT(intrf != NULL);
 
 	xc_ipi_handler();
-	return;
 }
 
 void
@@ -304,7 +291,7 @@
 	if (ci) {
 		if (0 != xen_send_ipi(ci, XEN_IPI_XCALL)) {
 			panic(xen_send_ipi(XEN_IPI_XCALL) failed\n);
-		};
+		}
 	} else {
 		xen_broadcast_ipi(XEN_IPI_XCALL);
 	}



CVS commit: src/sys/arch/xen

2011-08-10 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Aug 10 21:46:02 UTC 2011

Modified Files:
src/sys/arch/xen/include: hypervisor.h
src/sys/arch/xen/x86: hypervisor_machdep.c
src/sys/arch/xen/xen: evtchn.c

Log Message:
refactor the bitstring/mask operations to be behind an API. Make pending 
interrupt marking cpu aware.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/xen/xen/evtchn.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/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.31 src/sys/arch/xen/include/hypervisor.h:1.32
--- src/sys/arch/xen/include/hypervisor.h:1.31	Mon Oct 19 18:41:10 2009
+++ src/sys/arch/xen/include/hypervisor.h	Wed Aug 10 21:46:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.31 2009/10/19 18:41:10 bouyer Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.32 2011/08/10 21:46:02 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -91,6 +91,7 @@
 #include xen/xen3-public/io/netif.h
 #include xen/xen3-public/io/blkif.h
 
+#include machine/cpu.h
 #include machine/hypercalls.h
 
 #undef u8
@@ -136,7 +137,8 @@
 void hypervisor_mask_event(unsigned int);
 void hypervisor_clear_event(unsigned int);
 void hypervisor_enable_ipl(unsigned int);
-void hypervisor_set_ipending(uint32_t, int, int);
+void hypervisor_set_ipending(struct cpu_info *, 
+			 uint32_t, int, int);
 void hypervisor_machdep_attach(void);
 
 /* 

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.14 src/sys/arch/xen/x86/hypervisor_machdep.c:1.15
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.14	Wed Mar 30 21:53:58 2011
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Wed Aug 10 21:46:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.14 2011/03/30 21:53:58 jym Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.15 2011/08/10 21:46:02 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.14 2011/03/30 21:53:58 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.15 2011/08/10 21:46:02 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -86,13 +86,79 @@
 // #define PORT_DEBUG 4
 // #define EARLY_DEBUG_EVENT
 
+/* callback function type */
+typedef void (*iterate_func_t)(struct cpu_info *, unsigned int,
+			   unsigned int, unsigned int, void *);
+
+static inline void
+evt_iterate_bits(struct cpu_info *ci, volatile unsigned long *pendingl1,
+		 volatile unsigned long *pendingl2, 
+		 volatile unsigned long *mask,
+		 iterate_func_t iterate_pending, void *iterate_args)
+{
+
+	KASSERT(pendingl1 != NULL);
+	KASSERT(pendingl2 != NULL);
+	
+	unsigned long l1, l2;
+	unsigned int l1i, l2i, port;
+
+	l1 = xen_atomic_xchg(pendingl1, 0);
+	while ((l1i = xen_ffs(l1)) != 0) {
+		l1i--;
+		l1 = ~(1UL  l1i);
+
+		l2 = pendingl2[l1i]  (mask != NULL ? ~mask[l1i] : -1UL);
+
+		if (mask != NULL) xen_atomic_setbits_l(mask[l1i], l2);
+		xen_atomic_clearbits_l(pendingl2[l1i], l2);
+
+		while ((l2i = xen_ffs(l2)) != 0) {
+			l2i--;
+			l2 = ~(1UL  l2i);
+
+			port = (l1i  LONG_SHIFT) + l2i;
+
+			iterate_pending(ci, port, l1i, l2i, iterate_args);
+		}
+	}
+}
+
+/*
+ * Set per-cpu pending information for outstanding events that
+ * cannot be processed now.
+ */
+   
+static inline void
+evt_set_pending(struct cpu_info *ci, unsigned int port, unsigned int l1i,
+		unsigned int l2i, void *args)
+{
+
+	KASSERT(args != NULL);
+	KASSERT(ci != NULL);
+
+	int *ret = args;
+
+	if (evtsource[port]) {
+		hypervisor_set_ipending(ci, evtsource[port]-ev_imask,
+		l1i, l2i);
+		evtsource[port]-ev_evcnt.ev_count++;
+		if (*ret == 0  ci-ci_ilevel 
+		evtsource[port]-ev_maxlevel)
+			*ret = 1;
+	}
+#ifdef DOM0OPS
+	else  {
+		/* set pending event */
+		xenevt_setipending(l1i, l2i);
+	}
+#endif
+}
+
 int stipending(void);
 int
 stipending(void)
 {
-	unsigned long l1;
-	unsigned long l2;
-	unsigned int l1i, l2i, port;
 	volatile shared_info_t *s = HYPERVISOR_shared_info;
 	struct cpu_info *ci;
 	volatile struct vcpu_info *vci;
@@ -120,45 +186,16 @@
 	 * we're only called after STIC, so we know that we'll have to
 	 * STI at the end
 	 */
+
 	while (vci-evtchn_upcall_pending) {
 		cli();
+
 		vci-evtchn_upcall_pending = 0;
-		/* NB. No need for a barrier here -- XCHG is a barrier
-		 * on x86. */
-		l1 = xen_atomic_xchg(vci-evtchn_pending_sel, 0);
-		while ((l1i = xen_ffs(l1)) != 0) {
-			l1i--;
-			l1 = ~(1UL  l1i);
-
-			l2 = s-evtchn_pending[l1i]  ~s-evtchn_mask[l1i];
-			/*
-			 * mask and clear event. More efficient than calling
-			 * hypervisor_mask/clear_event for each event.
-			 */
-			xen_atomic_setbits_l(s-evtchn_mask[l1i], l2);
-			

CVS commit: src/sys/arch/i386/i386

2011-08-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Aug 11 11:01:31 UTC 2011

Modified Files:
src/sys/arch/i386/i386: gdt.c

Log Message:
per-cpu gdt support for xen


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/i386/i386/gdt.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/i386/i386/gdt.c
diff -u src/sys/arch/i386/i386/gdt.c:1.50 src/sys/arch/i386/i386/gdt.c:1.51
--- src/sys/arch/i386/i386/gdt.c:1.50	Sat Nov 21 03:11:00 2009
+++ src/sys/arch/i386/i386/gdt.c	Thu Aug 11 11:01:30 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gdt.c,v 1.50 2009/11/21 03:11:00 rmind Exp $	*/
+/*	$NetBSD: gdt.c,v 1.51 2011/08/11 11:01:30 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gdt.c,v 1.50 2009/11/21 03:11:00 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: gdt.c,v 1.51 2011/08/11 11:01:30 cherry Exp $);
 
 #include opt_multiprocessor.h
 #include opt_xen.h
@@ -207,17 +207,28 @@
 		KASSERT(va = VM_MIN_KERNEL_ADDRESS);
 		ptp = kvtopte(va);
 		frames[f] = *ptp  PAGE_SHIFT;
-		pmap_pte_clearbits(ptp, PG_RW);
+		{ 
+		   /* 
+		* pmap_pte_clearbits(ptp, PG_RW);
+		* but without spl(), since %fs is not setup
+		* properly yet, ie; curcpu() won't work at this
+		* point and spl() will break.
+		*/
+		   xpq_queue_lock();
+		   xpq_queue_pte_update(xpmap_ptetomach(ptp),
+	*ptp  ~PG_RW);
+		   xpq_flush_queue();
+		   xpq_queue_unlock();
+		}
 	}
-	/* printk(loading gdt %x, %d entries, %d pages, */
-	/* frames[0]  PAGE_SHIFT, gdt_size[0], len  PAGE_SHIFT); */
+
 	if (HYPERVISOR_set_gdt(frames, gdt_size[0]))
 		panic(HYPERVISOR_set_gdt failed!\n);
 	lgdt_finish();
 #endif
 }
 
-#ifdef MULTIPROCESSOR
+#if defined(MULTIPROCESSOR)  !defined(XEN)
 
 void
 gdt_reload_cpu(struct cpu_info *ci)
@@ -255,15 +266,17 @@
 			gdt_size[which] = MINGDTSIZ;
 			new_len = gdt_size[which] * sizeof(gdt[0]);
 		}
-		for(va = (vaddr_t)(cpu_info_primary.ci_gdt) + old_len + max_len;
-		va  (vaddr_t)(cpu_info_primary.ci_gdt) + new_len + max_len;
-		va += PAGE_SIZE) {
-			while ((pg = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO))
-			== NULL) {
-uvm_wait(gdt_grow);
+		for (CPU_INFO_FOREACH(cii, ci)) {
+			for(va = (vaddr_t)(ci-ci_gdt) + old_len + max_len;
+			va  (vaddr_t)(ci-ci_gdt) + new_len + max_len;
+			va += PAGE_SIZE) {
+while ((pg = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO))
+   == NULL) {
+	uvm_wait(gdt_grow);
+}
+pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pg),
+	   VM_PROT_READ | VM_PROT_WRITE, 0);
 			}
-			pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pg),
-			VM_PROT_READ | VM_PROT_WRITE, 0);
 		}
 		return;
 	}



CVS commit: src/sys/arch/xen

2011-08-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Aug 11 17:59:00 UTC 2011

Modified Files:
src/sys/arch/xen/include: evtchn.h intr.h
src/sys/arch/xen/x86: intr.c
src/sys/arch/xen/xen: evtchn.c xenevt.c

Log Message:
Make event/interrupt handling MP aware


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/xen/include/evtchn.h
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/xen/x86/intr.c
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/xen/xen/xenevt.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/include/evtchn.h
diff -u src/sys/arch/xen/include/evtchn.h:1.18 src/sys/arch/xen/include/evtchn.h:1.19
--- src/sys/arch/xen/include/evtchn.h:1.18	Fri Oct 23 02:32:33 2009
+++ src/sys/arch/xen/include/evtchn.h	Thu Aug 11 17:58:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.h,v 1.18 2009/10/23 02:32:33 snj Exp $	*/
+/*	$NetBSD: evtchn.h,v 1.19 2011/08/11 17:58:59 cherry Exp $	*/
 
 /*
  *
@@ -41,8 +41,9 @@
 int event_set_handler(int, int (*func)(void *), void *, int, const char *);
 int event_remove_handler(int, int (*func)(void *), void *);
 
+struct cpu_info;
 struct intrhand;
-void event_set_iplhandler(struct intrhand *, int);
+void event_set_iplhandler(struct cpu_info *, struct intrhand *, int);
 
 extern int debug_port;
 extern int xen_debug_handler(void *);
@@ -52,6 +53,8 @@
 int unbind_pirq_from_evtch(int);
 int unbind_virq_from_evtch(int);
 
+evtchn_port_t bind_vcpu_to_evtch(cpuid_t);
+
 struct pintrhand {
 	int pirq;
 	int evtch;

Index: src/sys/arch/xen/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.32 src/sys/arch/xen/include/intr.h:1.33
--- src/sys/arch/xen/include/intr.h:1.32	Wed Aug 10 11:39:45 2011
+++ src/sys/arch/xen/include/intr.h	Thu Aug 11 17:58:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.32 2011/08/10 11:39:45 cherry Exp $	*/
+/*	$NetBSD: intr.h,v 1.33 2011/08/11 17:58:59 cherry Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -54,6 +54,7 @@
 	uint32_t ev_imask;		/* interrupt mask */
 	struct intrhand *ev_handlers;	/* handler chain */
 	struct evcnt ev_evcnt;		/* interrupt counter */
+	struct cpu_info *ev_cpu;/* cpu on which this event is bound */
 	char ev_evname[32];		/* event counter name */
 };
 
@@ -161,7 +162,6 @@
 
 void intr_default_setup(void);
 int x86_nmi(void);
-void intr_calculatemasks(struct evtsource *);
 
 void *intr_establish(int, struct pic *, int, int, int, int (*)(void *), void *, bool);
 void intr_disestablish(struct intrhand *);
@@ -180,9 +180,9 @@
 int xen_send_ipi(struct cpu_info *, uint32_t);
 void xen_broadcast_ipi(uint32_t);
 #else
-#define xen_ipi_init(_1) do {} while(0) /* nothing */
-#define xen_send_ipi(_i1, _i2) do {} while(0) /* nothing */
-#define xen_broadcast_ipi(_i1) do {} while(0) /* nothing */
+#define xen_ipi_init(_1) ((void) 0) /* nothing */
+#define xen_send_ipi(_i1, _i2) (0) /* nothing */
+#define xen_broadcast_ipi(_i1) ((void) 0) /* nothing */
 #endif /* MULTIPROCESSOR */
 
 #endif /* !_LOCORE */

Index: src/sys/arch/xen/x86/intr.c
diff -u src/sys/arch/xen/x86/intr.c:1.27 src/sys/arch/xen/x86/intr.c:1.28
--- src/sys/arch/xen/x86/intr.c:1.27	Fri Mar 19 23:27:12 2010
+++ src/sys/arch/xen/x86/intr.c	Thu Aug 11 17:59:00 2011
@@ -103,7 +103,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: intr.c,v 1.27 2010/03/19 23:27:12 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: intr.c,v 1.28 2011/08/11 17:59:00 cherry Exp $);
 
 #include opt_multiprocessor.h
 #include opt_xen.h
@@ -119,6 +119,7 @@
 #include sys/proc.h
 #include sys/errno.h
 #include sys/cpu.h
+#include sys/simplelock.h
 
 #include uvm/uvm_extern.h
 
@@ -153,24 +154,6 @@
 #endif
 
 /*
- * Recalculate the interrupt from scratch for an event source.
- */
-void
-intr_calculatemasks(struct evtsource *evts)
-{
-	struct intrhand *ih;
-
-	evts-ev_maxlevel = IPL_NONE;
-	evts-ev_imask = 0;
-	for (ih = evts-ev_handlers; ih != NULL; ih = ih-ih_evt_next) {
-		if (ih-ih_level  evts-ev_maxlevel)
-			evts-ev_maxlevel = ih-ih_level;
-		evts-ev_imask |= (1  ih-ih_level);
-	}
-
-}
-
-/*
  * Fake interrupt handler structures for the benefit of symmetry with
  * other interrupt sources.
  */

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.49 src/sys/arch/xen/xen/evtchn.c:1.50
--- src/sys/arch/xen/xen/evtchn.c:1.49	Wed Aug 10 21:46:02 2011
+++ src/sys/arch/xen/xen/evtchn.c	Thu Aug 11 17:59:00 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.49 2011/08/10 21:46:02 cherry Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.50 2011/08/11 17:59:00 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,20 +54,21 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: evtchn.c,v 1.49 2011/08/10 21:46:02 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: evtchn.c,v 1.50 2011/08/11 17:59:00 

CVS commit: src/sys/arch

2011-08-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Aug 11 18:05:11 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: fpu.c
src/sys/arch/i386/isa: npx.c

Log Message:
More appropriate use of xen_send_ipi().


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/amd64/amd64/fpu.c
cvs rdiff -u -r1.141 -r1.142 src/sys/arch/i386/isa/npx.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/amd64/amd64/fpu.c
diff -u src/sys/arch/amd64/amd64/fpu.c:1.36 src/sys/arch/amd64/amd64/fpu.c:1.37
--- src/sys/arch/amd64/amd64/fpu.c:1.36	Wed Aug 10 11:39:44 2011
+++ src/sys/arch/amd64/amd64/fpu.c	Thu Aug 11 18:05:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.36 2011/08/10 11:39:44 cherry Exp $	*/
+/*	$NetBSD: fpu.c,v 1.37 2011/08/11 18:05:11 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -100,7 +100,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: fpu.c,v 1.36 2011/08/10 11:39:44 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: fpu.c,v 1.37 2011/08/11 18:05:11 cherry Exp $);
 
 #include opt_multiprocessor.h
 
@@ -407,7 +407,10 @@
 		}
 		splx(s);
 #ifdef XEN
-		xen_send_ipi(oci, XEN_IPI_SYNCH_FPU);
+		if (xen_send_ipi(oci, XEN_IPI_SYNCH_FPU) != 0) {
+			panic(xen_send_ipi(%s, XEN_IPI_SYNCH_FPU) failed.,
+			cpu_name(oci));
+		}
 #else /* XEN */
 		x86_send_ipi(oci, X86_IPI_SYNCH_FPU);
 #endif

Index: src/sys/arch/i386/isa/npx.c
diff -u src/sys/arch/i386/isa/npx.c:1.141 src/sys/arch/i386/isa/npx.c:1.142
--- src/sys/arch/i386/isa/npx.c:1.141	Wed Aug 10 11:39:45 2011
+++ src/sys/arch/i386/isa/npx.c	Thu Aug 11 18:05:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: npx.c,v 1.141 2011/08/10 11:39:45 cherry Exp $	*/
+/*	$NetBSD: npx.c,v 1.142 2011/08/11 18:05:11 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: npx.c,v 1.141 2011/08/10 11:39:45 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: npx.c,v 1.142 2011/08/11 18:05:11 cherry Exp $);
 
 #if 0
 #define IPRINTF(x)	printf x
@@ -720,7 +720,10 @@
 		}
 		splx(s);
 #ifdef XEN
-		xen_send_ipi(oci, XEN_IPI_SYNCH_FPU);
+		if (xen_send_ipi(oci, XEN_IPI_SYNCH_FPU) != 0) {
+			panic(xen_send_ipi(%s, XEN_IPI_SYNCH_FPU) failed.,
+			cpu_name(oci));
+		}
 #else /* XEN */
 		x86_send_ipi(oci, X86_IPI_SYNCH_FPU);
 #endif



CVS commit: src/sys/arch

2011-08-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Aug 11 18:11:17 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: machdep.c
src/sys/arch/i386/i386: machdep.c
src/sys/arch/x86/include: cpu.h
src/sys/arch/x86/x86: cpu.c x86_machdep.c
src/sys/arch/xen/x86: cpu.c

Log Message:
Hide the MD details of specific IPIs behind semantically pleasing functions. 
This cleans up a couple of #ifdef XEN/#endif pairs


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.707 -r1.708 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.90 -r1.91 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/x86/x86/x86_machdep.c
cvs rdiff -u -r1.60 -r1.61 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/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.163 src/sys/arch/amd64/amd64/machdep.c:1.164
--- src/sys/arch/amd64/amd64/machdep.c:1.163	Wed Aug 10 11:39:45 2011
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Aug 11 18:11:17 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.163 2011/08/10 11:39:45 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.164 2011/08/11 18:11:17 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008
@@ -107,7 +107,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.163 2011/08/10 11:39:45 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.164 2011/08/11 18:11:17 cherry Exp $);
 
 /* #define XENDEBUG_LOW  */
 
@@ -719,11 +719,7 @@
 #endif /* XEN */
 	}
 
-#ifdef XEN
-	xen_broadcast_ipi(XEN_IPI_HALT);
-#else /* XEN */
-	x86_broadcast_ipi(X86_IPI_HALT);
-#endif
+	cpu_broadcast_halt();
 
 	if (howto  RB_HALT) {
 #if NACPICA  0

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.707 src/sys/arch/i386/i386/machdep.c:1.708
--- src/sys/arch/i386/i386/machdep.c:1.707	Wed Aug 10 06:38:02 2011
+++ src/sys/arch/i386/i386/machdep.c	Thu Aug 11 18:11:17 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.707 2011/08/10 06:38:02 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.708 2011/08/11 18:11:17 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.707 2011/08/10 06:38:02 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.708 2011/08/11 18:11:17 cherry Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -955,11 +955,7 @@
 	}
 
 #ifdef MULTIPROCESSOR
-#ifdef XEN
-	xen_broadcast_ipi(XEN_IPI_HALT);
-#else /* XEN */
-	x86_broadcast_ipi(X86_IPI_HALT);
-#endif /* XEN */
+	cpu_broadcast_halt();
 #endif /* MULTIPROCESSOR */
 
 	if (howto  RB_HALT) {

Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.36 src/sys/arch/x86/include/cpu.h:1.37
--- src/sys/arch/x86/include/cpu.h:1.36	Wed Aug 10 06:40:35 2011
+++ src/sys/arch/x86/include/cpu.h	Thu Aug 11 18:11:17 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.36 2011/08/10 06:40:35 cherry Exp $	*/
+/*	$NetBSD: cpu.h,v 1.37 2011/08/11 18:11:17 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -314,6 +314,8 @@
 void cpu_init_idle_lwps(void);
 void cpu_init_msrs(struct cpu_info *, bool);
 void cpu_load_pmap(struct pmap *);
+void cpu_broadcast_halt(void);
+void cpu_kick(struct cpu_info *);
 
 extern uint32_t cpus_attached;
 

Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.90 src/sys/arch/x86/x86/cpu.c:1.91
--- src/sys/arch/x86/x86/cpu.c:1.90	Fri Jul 29 21:21:43 2011
+++ src/sys/arch/x86/x86/cpu.c	Thu Aug 11 18:11:17 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.90 2011/07/29 21:21:43 dyoung Exp $	*/
+/*	$NetBSD: cpu.c,v 1.91 2011/08/11 18:11:17 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.90 2011/07/29 21:21:43 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.91 2011/08/11 18:11:17 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_mpbios.h		/* for MPDEBUG */
@@ -1210,3 +1210,23 @@
 	lcr3(pmap_pdirpa(pmap, 0));
 #endif /* PAE */
 }
+
+/*
+ * Notify all other cpus to halt.
+ */
+
+void
+cpu_broadcast_halt(struct cpu_info *ci)
+{
+	x86_broadcast_ipi(X86_IPI_HALT);
+}
+
+/*
+ * Send a dummy ipi to a cpu to force it to run splraise()/spllower()
+ */
+
+void
+cpu_kick(struct cpu_info *ci)
+{
+	x86_send_ipi(ci, 0);
+}

Index: src/sys/arch/x86/x86/x86_machdep.c
diff -u src/sys/arch/x86/x86/x86_machdep.c:1.54 src/sys/arch/x86/x86/x86_machdep.c:1.55
--- src/sys/arch/x86/x86/x86_machdep.c:1.54	Wed Aug 10 11:39:45 2011
+++ src/sys/arch/x86/x86/x86_machdep.c	Thu Aug 11 18:11:17 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_machdep.c,v 1.54 2011/08/10 

CVS commit: src/sys/arch

2011-08-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Aug 11 18:36:14 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: fpu.c
src/sys/arch/i386/isa: npx.c

Log Message:
unbreak the build. #include sys/cpu.h


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/amd64/amd64/fpu.c
cvs rdiff -u -r1.142 -r1.143 src/sys/arch/i386/isa/npx.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/amd64/amd64/fpu.c
diff -u src/sys/arch/amd64/amd64/fpu.c:1.37 src/sys/arch/amd64/amd64/fpu.c:1.38
--- src/sys/arch/amd64/amd64/fpu.c:1.37	Thu Aug 11 18:05:11 2011
+++ src/sys/arch/amd64/amd64/fpu.c	Thu Aug 11 18:36:14 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.37 2011/08/11 18:05:11 cherry Exp $	*/
+/*	$NetBSD: fpu.c,v 1.38 2011/08/11 18:36:14 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -100,13 +100,14 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: fpu.c,v 1.37 2011/08/11 18:05:11 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: fpu.c,v 1.38 2011/08/11 18:36:14 cherry Exp $);
 
 #include opt_multiprocessor.h
 
 #include sys/param.h
 #include sys/systm.h
 #include sys/conf.h
+#include sys/cpu.h
 #include sys/file.h
 #include sys/proc.h
 #include sys/ioctl.h

Index: src/sys/arch/i386/isa/npx.c
diff -u src/sys/arch/i386/isa/npx.c:1.142 src/sys/arch/i386/isa/npx.c:1.143
--- src/sys/arch/i386/isa/npx.c:1.142	Thu Aug 11 18:05:11 2011
+++ src/sys/arch/i386/isa/npx.c	Thu Aug 11 18:36:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: npx.c,v 1.142 2011/08/11 18:05:11 cherry Exp $	*/
+/*	$NetBSD: npx.c,v 1.143 2011/08/11 18:36:13 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: npx.c,v 1.142 2011/08/11 18:05:11 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: npx.c,v 1.143 2011/08/11 18:36:13 cherry Exp $);
 
 #if 0
 #define IPRINTF(x)	printf x
@@ -110,6 +110,7 @@
 #include sys/param.h
 #include sys/systm.h
 #include sys/conf.h
+#include sys/cpu.h
 #include sys/file.h
 #include sys/proc.h
 #include sys/ioctl.h



CVS commit: src/sys/arch

2011-08-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Aug 11 19:52:53 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: db_interface.c
src/sys/arch/i386/i386: db_interface.c

Log Message:
make ddb minimally MP aware


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/amd64/amd64/db_interface.c
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/i386/i386/db_interface.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/amd64/amd64/db_interface.c
diff -u src/sys/arch/amd64/amd64/db_interface.c:1.23 src/sys/arch/amd64/amd64/db_interface.c:1.24
--- src/sys/arch/amd64/amd64/db_interface.c:1.23	Sun Apr  3 22:29:25 2011
+++ src/sys/arch/amd64/amd64/db_interface.c	Thu Aug 11 19:52:52 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_interface.c,v 1.23 2011/04/03 22:29:25 dyoung Exp $	*/
+/*	$NetBSD: db_interface.c,v 1.24 2011/08/11 19:52:52 cherry Exp $	*/
 
 /*
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: db_interface.c,v 1.23 2011/04/03 22:29:25 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: db_interface.c,v 1.24 2011/08/11 19:52:52 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -82,7 +82,9 @@
 #ifdef MULTIPROCESSOR
 extern void ddb_ipi(struct trapframe);
 static void ddb_suspend(struct trapframe *);
+#ifndef XEN
 int ddb_vec;
+#endif /* XEN */
 static bool ddb_mp_online;
 #endif
 
@@ -98,9 +100,13 @@
 {
 
 #ifdef MULTIPROCESSOR
+#ifndef XEN
 	ddb_vec = idt_vec_alloc(0xf0, 0xff);
 	setgate((struct gate_descriptor *)idt[ddb_vec], Xintrddb, 1,
 	SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
+#else
+	/* Initialised as part of xen_ipi_init() */
+#endif /* XEN */
 #endif
 }
 
@@ -114,8 +120,10 @@
 	int cpu_me = cpu_number();
 	int win;
 
+#ifndef XEN
 	if (ddb_vec == 0)
 		return 1;
+#endif /* XEN */
 
 	__cpu_simple_lock(db_lock);
 	if (ddb_cpu == NOCPU)
@@ -123,7 +131,12 @@
 	win = (ddb_cpu == cpu_me);
 	__cpu_simple_unlock(db_lock);
 	if (win) {
+#ifdef XEN
+		xen_broadcast_ipi(XEN_IPI_DDB);
+#else
 		x86_ipi(ddb_vec, LAPIC_DEST_ALLEXCL, LAPIC_DLMODE_FIXED);
+#endif /* XEN */
+
 	}
 	ddb_mp_online = x86_mp_online;
 	x86_mp_online = false;

Index: src/sys/arch/i386/i386/db_interface.c
diff -u src/sys/arch/i386/i386/db_interface.c:1.66 src/sys/arch/i386/i386/db_interface.c:1.67
--- src/sys/arch/i386/i386/db_interface.c:1.66	Sun Apr  3 22:29:26 2011
+++ src/sys/arch/i386/i386/db_interface.c	Thu Aug 11 19:52:52 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_interface.c,v 1.66 2011/04/03 22:29:26 dyoung Exp $	*/
+/*	$NetBSD: db_interface.c,v 1.67 2011/08/11 19:52:52 cherry Exp $	*/
 
 /*
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: db_interface.c,v 1.66 2011/04/03 22:29:26 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: db_interface.c,v 1.67 2011/08/11 19:52:52 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -86,7 +86,9 @@
 extern void ddb_ipi(int, struct trapframe);
 extern void ddb_ipi_tss(struct i386tss *);
 static void ddb_suspend(struct trapframe *);
+#ifndef XEN
 int ddb_vec;
+#endif /* XEN */
 static bool ddb_mp_online;
 #endif
 
@@ -104,8 +106,12 @@
 {
 
 #ifdef MULTIPROCESSOR
+#ifndef XEN
 	ddb_vec = idt_vec_alloc(0xf0, 0xff);
 	idt_vec_set(ddb_vec, Xintrddbipi);
+#else
+	/* Initialised as part of xen_ipi_init() */
+#endif /* XEN */
 #endif
 }
 
@@ -119,8 +125,10 @@
 	int cpu_me = cpu_number();
 	int win;
 
+#ifndef XEN
 	if (ddb_vec == 0)
 		return 1;
+#endif /* XEN */
 
 	__cpu_simple_lock(db_lock);
 	if (ddb_cpu == NOCPU)
@@ -128,7 +136,11 @@
 	win = (ddb_cpu == cpu_me);
 	__cpu_simple_unlock(db_lock);
 	if (win) {
+#ifdef XEN
+		xen_broadcast_ipi(XEN_IPI_DDB);
+#else
 		x86_ipi(ddb_vec, LAPIC_DEST_ALLEXCL, LAPIC_DLMODE_FIXED);
+#endif /* XEN */
 	}
 	ddb_mp_online = x86_mp_online;
 	x86_mp_online = false;



CVS commit: src/sys/arch/x86/x86

2011-08-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Aug 11 20:33:20 UTC 2011

Modified Files:
src/sys/arch/x86/x86: cpu.c

Log Message:
Unbreak the build. (conflicting types in function declaration and definition)

Thanks riz@


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/arch/x86/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/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.91 src/sys/arch/x86/x86/cpu.c:1.92
--- src/sys/arch/x86/x86/cpu.c:1.91	Thu Aug 11 18:11:17 2011
+++ src/sys/arch/x86/x86/cpu.c	Thu Aug 11 20:33:20 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.91 2011/08/11 18:11:17 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.92 2011/08/11 20:33:20 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.91 2011/08/11 18:11:17 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.92 2011/08/11 20:33:20 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_mpbios.h		/* for MPDEBUG */
@@ -1216,7 +1216,7 @@
  */
 
 void
-cpu_broadcast_halt(struct cpu_info *ci)
+cpu_broadcast_halt(void)
 {
 	x86_broadcast_ipi(X86_IPI_HALT);
 }



CVS commit: src/sys/arch/xen

2011-08-13 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Aug 13 11:41:57 UTC 2011

Modified Files:
src/sys/arch/xen/include: xenpmap.h
src/sys/arch/xen/x86: x86_xpmap.c

Log Message:
remove unnecessary locking overhead for UP


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/xen/include/xenpmap.h
cvs rdiff -u -r1.29 -r1.30 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/include/xenpmap.h
diff -u src/sys/arch/xen/include/xenpmap.h:1.28 src/sys/arch/xen/include/xenpmap.h:1.29
--- src/sys/arch/xen/include/xenpmap.h:1.28	Wed Aug 10 09:50:37 2011
+++ src/sys/arch/xen/include/xenpmap.h	Sat Aug 13 11:41:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xenpmap.h,v 1.28 2011/08/10 09:50:37 cherry Exp $	*/
+/*	$NetBSD: xenpmap.h,v 1.29 2011/08/13 11:41:57 cherry Exp $	*/
 
 /*
  *
@@ -36,8 +36,16 @@
 
 #define	INVALID_P2M_ENTRY	(~0UL)
 
+#ifdef MULTIPROCESSOR
 void xpq_queue_lock(void);
 void xpq_queue_unlock(void);
+bool xpq_queue_locked(void);
+#else /* MULTIPROCESSOR */
+#define xpq_queue_lock() do {} while(0) /* nothing */
+#define xpq_queue_unlock() do {} while(0) /* nothing */
+#define xpq_queue_locked() (true) /* Always true for UP */
+#endif /* MULTIPROCESSOR */
+
 void xpq_queue_machphys_update(paddr_t, paddr_t);
 void xpq_queue_invlpg(vaddr_t);
 void xpq_queue_pte_update(paddr_t, pt_entry_t);

Index: src/sys/arch/xen/x86/x86_xpmap.c
diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.29 src/sys/arch/xen/x86/x86_xpmap.c:1.30
--- src/sys/arch/xen/x86/x86_xpmap.c:1.29	Wed Aug 10 09:50:37 2011
+++ src/sys/arch/xen/x86/x86_xpmap.c	Sat Aug 13 11:41:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.29 2011/08/10 09:50:37 cherry Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.30 2011/08/13 11:41:57 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert m...@adviseo.fr
@@ -69,7 +69,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.29 2011/08/10 09:50:37 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.30 2011/08/13 11:41:57 cherry Exp $);
 
 #include opt_xen.h
 #include opt_ddb.h
@@ -166,6 +166,8 @@
 #define XPQUEUE_SIZE 2048
 static mmu_update_t xpq_queue[XPQUEUE_SIZE];
 static int xpq_idx = 0;
+
+#ifdef MULTIPROCESSOR
 static struct simplelock xpq_lock = SIMPLELOCK_INITIALIZER;
 
 void
@@ -180,13 +182,20 @@
 	simple_unlock(xpq_lock);
 }
 
+bool
+xpq_queue_locked(void)
+{
+	return xpq_queue_locked();
+}
+#endif /* MULTIPROCESSOR */
+
 /* Must be called with xpq_lock held */
 void
 xpq_flush_queue(void)
 {
 	int i, ok, ret;
 
-	KASSERT(simple_lock_held(xpq_lock));
+	KASSERT(xpq_queue_locked());
 	XENPRINTK2((flush queue %p entries %d\n, xpq_queue, xpq_idx));
 	for (i = 0; i  xpq_idx; i++)
 		XENPRINTK2((%d: 0x%08 PRIx64  0x%08 PRIx64 \n, i,
@@ -210,7 +219,7 @@
 xpq_increment_idx(void)
 {
 
-	KASSERT(simple_lock_held(xpq_lock));
+	KASSERT(xpq_queue_locked());
 	xpq_idx++;
 	if (__predict_false(xpq_idx == XPQUEUE_SIZE))
 		xpq_flush_queue();
@@ -221,7 +230,7 @@
 {
 	XENPRINTK2((xpq_queue_machphys_update ma=0x% PRIx64  pa=0x% PRIx64
 	\n, (int64_t)ma, (int64_t)pa));
-	KASSERT(simple_lock_held(xpq_lock));
+	KASSERT(xpq_queue_locked());
 	xpq_queue[xpq_idx].ptr = ma | MMU_MACHPHYS_UPDATE;
 	xpq_queue[xpq_idx].val = (pa - XPMAP_OFFSET)  PAGE_SHIFT;
 	xpq_increment_idx();
@@ -235,7 +244,7 @@
 {
 
 	KASSERT((ptr  3) == 0);
-	KASSERT(simple_lock_held(xpq_lock));
+	KASSERT(xpq_queue_locked());
 	xpq_queue[xpq_idx].ptr = (paddr_t)ptr | MMU_NORMAL_PT_UPDATE;
 	xpq_queue[xpq_idx].val = val;
 	xpq_increment_idx();
@@ -248,7 +257,7 @@
 xpq_queue_pt_switch(paddr_t pa)
 {
 	struct mmuext_op op;
-	KASSERT(simple_lock_held(xpq_lock));
+	KASSERT(xpq_queue_locked());
 	xpq_flush_queue();
 
 	XENPRINTK2((xpq_queue_pt_switch: 0x% PRIx64  0x% PRIx64 \n,
@@ -264,7 +273,7 @@
 {
 	struct mmuext_op op;
 
-	KASSERT(simple_lock_held(xpq_lock));
+	KASSERT(xpq_queue_locked());
 	xpq_flush_queue();
 
 	XENPRINTK2((xpq_queue_pin_l%d_table: %# PRIxPADDR \n,
@@ -282,7 +291,7 @@
 {
 	struct mmuext_op op;
 
-	KASSERT(simple_lock_held(xpq_lock));
+	KASSERT(xpq_queue_locked());
 	xpq_flush_queue();
 
 	XENPRINTK2((xpq_queue_unpin_table: %# PRIxPADDR \n, pa));
@@ -297,7 +306,7 @@
 {
 	struct mmuext_op op;
 
-	KASSERT(simple_lock_held(xpq_lock));
+	KASSERT(xpq_queue_locked());
 	xpq_flush_queue();
 
 	XENPRINTK2((xpq_queue_set_ldt\n));
@@ -314,7 +323,7 @@
 {
 	struct mmuext_op op;
 
-	KASSERT(simple_lock_held(xpq_lock));
+	KASSERT(xpq_queue_locked());
 	xpq_flush_queue();
 
 	XENPRINTK2((xpq_queue_tlb_flush\n));
@@ -345,7 +354,7 @@
 xpq_queue_invlpg(vaddr_t va)
 {
 	struct mmuext_op op;
-	KASSERT(simple_lock_held(xpq_lock));
+	KASSERT(xpq_queue_locked());
 	xpq_flush_queue();
 
 	XENPRINTK2((xpq_queue_invlpg %# PRIxVADDR \n, va));
@@ -360,7 +369,7 @@
 {
 	mmuext_op_t op;
 
-	KASSERT(simple_lock_held(xpq_lock));
+	KASSERT(xpq_queue_locked());
 
 	/* Flush 

  1   2   3   >