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

2021-02-21 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Feb 21 20:11:59 UTC 2021

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

Log Message:
in xen_shm_map(), make sure to unmap any successfully mapped pages
before returning failure if there is partial failure

fix detection of partial failure - GNTTABOP_map_grant_ref can actually return
zero for partial failure, so we need to always check all the entries
to detect it

previously, DIAGNOSTIC kernel triggered panic() for partial failure,
and non-DIAGNOSTIC kernel did not detect it at all, leading to Dom0 page
fault later; since the mapping failure can be triggered by malicious
DomU via bad grant reference, it's important to expect the calls
to fail, and handle it gracefully without crashing Dom0

part of fixes for XSA-362


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/xen/x86/xen_shm_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/xen_shm_machdep.c
diff -u src/sys/arch/xen/x86/xen_shm_machdep.c:1.16 src/sys/arch/xen/x86/xen_shm_machdep.c:1.17
--- src/sys/arch/xen/x86/xen_shm_machdep.c:1.16	Sat Apr 25 15:26:17 2020
+++ src/sys/arch/xen/x86/xen_shm_machdep.c	Sun Feb 21 20:11:59 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: xen_shm_machdep.c,v 1.16 2020/04/25 15:26:17 bouyer Exp $  */
+/*  $NetBSD: xen_shm_machdep.c,v 1.17 2021/02/21 20:11:59 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.16 2020/04/25 15:26:17 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.17 2021/02/21 20:11:59 jdolecek Exp $");
 
 #include 
 #include 
@@ -45,16 +45,13 @@ __KERNEL_RCSID(0, "$NetBSD: xen_shm_mach
  * Helper routines for the backend drivers. This implements the necessary
  * functions to map a bunch of pages from foreign domains into our kernel VM
  * space, do I/O to it, and unmap it.
- *
- * At boot time, we grab some kernel VM space that we'll use to map the foreign
- * pages. We also maintain a virtual-to-machine mapping table to give back
- * the appropriate address to bus_dma if requested.
- *
- * If no more VM space is available, we return an error. The caller can then
- * register a callback which will be called when the required VM space is
- * available.
  */
 
+/*
+ * Map the memory referenced via grefp to supplied VA space.
+ * If there is a failure for particular gref, no memory is mapped
+ * and error is returned.
+ */
 int
 xen_shm_map(int nentries, int domid, grant_ref_t *grefp, vaddr_t va,
 grant_handle_t *handlep, int flags)
@@ -77,20 +74,69 @@ xen_shm_map(int nentries, int domid, gra
 	}
 
 	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, op, nentries);
-	if (__predict_false(ret)) {
-		printf("%s: HYPERVISOR_grant_table_op failed\n", __func__);
+	if (__predict_false(ret < 0)) {
+#ifdef DIAGNOSTIC
+		printf("%s: HYPERVISOR_grant_table_op failed %d\n", __func__,
+		ret);
+#endif
 		return EINVAL;
 	}
 
+	/*
+	 * If ret is positive, it means there was an error in processing,
+	 * and only first ret entries were actually handled. If it's zero,
+	 * it only means all entries were processed, but there could still
+	 * be failure.
+	 */
+	if (__predict_false(ret > 0 && ret < nentries)) {
+		nentries = ret;
+	}
+
 	for (i = 0; i < nentries; i++) {
+		if (__predict_false(op[i].status)) {
 #ifdef DIAGNOSTIC
-		if (__predict_false(op[i].status))
-			panic("%s: op[%d] status %d", __func__, i,
-			op[i].status);
+			printf("%s: op[%d] bad status %d gref %u\n", __func__,
+			i, op[i].status, grefp[i]);
 #endif
+			ret = 1;
+			continue;
+		}
 		handlep[i] = op[i].handle;
 	}
 
+	if (__predict_false(ret > 0)) {
+		int uncnt = 0;
+		gnttab_unmap_grant_ref_t unop[XENSHM_MAX_PAGES_PER_REQUEST];
+
+		/*
+		 * When returning error, make sure the successfully mapped
+		 * entries are unmapped before returning the error.
+		 * xen_shm_unmap() can't be used, it assumes
+		 * linear consecutive space.
+		 */
+		for (i = uncnt = 0; i < nentries; i++) {
+			if (op[i].status == 0) {
+unop[uncnt].host_addr = va + i * PAGE_SIZE;
+unop[uncnt].dev_bus_addr = 0;
+unop[uncnt].handle = handlep[i];
+uncnt++;
+			}
+		}
+		if (uncnt > 0) {
+			ret = HYPERVISOR_grant_table_op(
+			GNTTABOP_unmap_grant_ref, unop, uncnt);
+			if (ret != 0) {
+panic("%s: unmap on error recovery failed"
+" %d", __func__, ret);
+			}
+		}
+#ifdef DIAGNOSTIC
+		printf("%s: HYPERVISOR_grant_table_op bad entry\n",
+		__func__);
+#endif
+		return EINVAL;
+	}
+
 	return 0;
 }
 



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

2020-08-01 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Aug  1 12:39:40 UTC 2020

Modified Files:
src/sys/arch/xen/x86: pintr.c xen_intr.c

Log Message:
adjust includes to pull __HAVE_PCI_MSI_MSIX properly


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/xen/x86/pintr.c
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/xen/x86/xen_intr.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/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.19 src/sys/arch/xen/x86/pintr.c:1.20
--- src/sys/arch/xen/x86/pintr.c:1.19	Sun Jul 19 16:20:36 2020
+++ src/sys/arch/xen/x86/pintr.c	Sat Aug  1 12:39:40 2020
@@ -103,12 +103,13 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.19 2020/07/19 16:20:36 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.20 2020/08/01 12:39:40 jdolecek Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
 #include "isa.h"
 #include "pci.h"
+#include "opt_pci.h"
 
 #include 
 #include 
@@ -126,6 +127,8 @@ __KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.
 #include 
 #include 
 
+#include 
+
 #ifdef __HAVE_PCI_MSI_MSIX
 #include 
 #endif

Index: src/sys/arch/xen/x86/xen_intr.c
diff -u src/sys/arch/xen/x86/xen_intr.c:1.27 src/sys/arch/xen/x86/xen_intr.c:1.28
--- src/sys/arch/xen/x86/xen_intr.c:1.27	Thu May  7 19:48:58 2020
+++ src/sys/arch/xen/x86/xen_intr.c	Sat Aug  1 12:39:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_intr.c,v 1.27 2020/05/07 19:48:58 bouyer Exp $	*/
+/*	$NetBSD: xen_intr.c,v 1.28 2020/08/01 12:39:40 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -30,9 +30,10 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.27 2020/05/07 19:48:58 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.28 2020/08/01 12:39:40 jdolecek Exp $");
 
 #include "opt_multiprocessor.h"
+#include "opt_pci.h"
 
 #include 
 #include 



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

2020-07-19 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Jul 19 16:20:36 UTC 2020

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

Log Message:
add #ifdef __HAVE_PCI_MSI_MSIX so this still compiles with NO_PCI_MSI_MSIX


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/xen/x86/pintr.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/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.18 src/sys/arch/xen/x86/pintr.c:1.19
--- src/sys/arch/xen/x86/pintr.c:1.18	Sun Jul 19 14:27:07 2020
+++ src/sys/arch/xen/x86/pintr.c	Sun Jul 19 16:20:36 2020
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.18 2020/07/19 14:27:07 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.19 2020/07/19 16:20:36 jdolecek Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -164,6 +164,7 @@ short irq2port[NR_EVENT_CHANNELS] = {0};
 
 #if defined(DOM0OPS) || NPCI > 0
 
+#ifdef __HAVE_PCI_MSI_MSIX
 static int
 xen_map_msi_pirq(struct pic *pic, int count, int *gsi)
 {
@@ -223,6 +224,7 @@ xen_pci_msi_probe(struct pic *pic, int c
 
 	return ret;
 }
+#endif /* __HAVE_PCI_MSI_MSIX */
 
 /*
  * This function doesn't "allocate" anything. It merely translates our



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

2020-07-08 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Jul  8 11:11:00 UTC 2020

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

Log Message:
initalize ci_kfpu_spl, to avoid triggering KASSERT() in fpu_kern_enter()

Follows revision 1.177 of sys/arch/x86/x86/cpu.c:
"""
Add a small API for in-kernel FPU operations.

fpu_kern_enter();
/* do FPU stuff */
fpu_kern_leave();
"""

With this DomU kernel boots with:
[   2.571] aes: Intel AES-NI


To generate a diff of this commit:
cvs rdiff -u -r1.137 -r1.138 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.137 src/sys/arch/xen/x86/cpu.c:1.138
--- src/sys/arch/xen/x86/cpu.c:1.137	Sat Jun 27 09:54:08 2020
+++ src/sys/arch/xen/x86/cpu.c	Wed Jul  8 11:11:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.137 2020/06/27 09:54:08 jdolecek Exp $	*/
+/*	$NetBSD: cpu.c,v 1.138 2020/07/08 11:11:00 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.137 2020/06/27 09:54:08 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.138 2020/07/08 11:11:00 jdolecek Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -232,6 +232,7 @@ cpu_attach(device_t parent, device_t sel
 	ci->ci_cpuid = caa->cpu_number;
 	ci->ci_vcpu = NULL;
 	ci->ci_index = nphycpu++;
+	ci->ci_kfpu_spl = -1;
 
 	if (!pmf_device_register(self, NULL, NULL))
 		aprint_error_dev(self, "couldn't establish power handler\n");
@@ -391,6 +392,7 @@ cpu_attach_common(device_t parent, devic
 	ci->ci_dev = self;
 	ci->ci_cpuid = cpunum;
 	ci->ci_vcpuid = cpunum;
+	ci->ci_kfpu_spl = -1;
 
 	KASSERT(HYPERVISOR_shared_info != NULL);
 	KASSERT(cpunum < XEN_LEGACY_MAX_VCPUS);



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

2020-06-27 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Jun 27 09:54:08 UTC 2020

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

Log Message:
avoid excessive stack usage in mp_cpu_start(), this is called after VM
init so kmem(9) can be used


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 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.136 src/sys/arch/xen/x86/cpu.c:1.137
--- src/sys/arch/xen/x86/cpu.c:1.136	Thu May 21 21:12:31 2020
+++ src/sys/arch/xen/x86/cpu.c	Sat Jun 27 09:54:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.136 2020/05/21 21:12:31 ad Exp $	*/
+/*	$NetBSD: cpu.c,v 1.137 2020/06/27 09:54:08 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.136 2020/05/21 21:12:31 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.137 2020/06/27 09:54:08 jdolecek Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -999,22 +999,24 @@ int
 mp_cpu_start(struct cpu_info *ci, vaddr_t target)
 {
 	int hyperror;
-	struct vcpu_guest_context vcpuctx;
+	struct vcpu_guest_context *vcpuctx;
 
 	KASSERT(ci != NULL);
 	KASSERT(ci != _info_primary);
 	KASSERT(ci->ci_flags & CPUF_AP);
 
+	vcpuctx = kmem_alloc(sizeof(*vcpuctx), KM_SLEEP);
+
 #ifdef __x86_64__
-	xen_init_amd64_vcpuctxt(ci, , (void (*)(struct cpu_info *))target);
+	xen_init_amd64_vcpuctxt(ci, vcpuctx, (void (*)(struct cpu_info *))target);
 #else
-	xen_init_i386_vcpuctxt(ci, , (void (*)(struct cpu_info *))target);
+	xen_init_i386_vcpuctxt(ci, vcpuctx, (void (*)(struct cpu_info *))target);
 #endif
 
 	/* Initialise the given vcpu to execute cpu_hatch(ci); */
-	if ((hyperror = HYPERVISOR_vcpu_op(VCPUOP_initialise, ci->ci_vcpuid, ))) {
+	if ((hyperror = HYPERVISOR_vcpu_op(VCPUOP_initialise, ci->ci_vcpuid, vcpuctx))) {
 		aprint_error(": context initialisation failed. errno = %d\n", hyperror);
-		return hyperror;
+		goto out;
 	}
 
 	/* Start it up */
@@ -1022,20 +1024,23 @@ mp_cpu_start(struct cpu_info *ci, vaddr_
 	/* First bring it down */
 	if ((hyperror = HYPERVISOR_vcpu_op(VCPUOP_down, ci->ci_vcpuid, NULL))) {
 		aprint_error(": VCPUOP_down hypervisor command failed. errno = %d\n", hyperror);
-		return hyperror;
+		goto out;
 	}
 
 	if ((hyperror = HYPERVISOR_vcpu_op(VCPUOP_up, ci->ci_vcpuid, NULL))) {
 		aprint_error(": VCPUOP_up hypervisor command failed. errno = %d\n", hyperror);
-		return hyperror;
+		goto out;
 	}
 
 	if (!vcpu_is_up(ci)) {
 		aprint_error(": did not come up\n");
-		return -1;
+		hyperror = -1;
+		goto out;
 	}
 
-	return 0;
+out:
+	kmem_free(vcpuctx, sizeof(*vcpuctx));
+	return hyperror;
 }
 
 void



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

2020-05-23 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat May 23 14:51:19 UTC 2020

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

Log Message:
switch back to PHYSDEVOP_alloc_irq_vector for non-MSI interrupts - on my
computer it works the same as PHYSDEVOP_map_pirq, but seems it doesn't
on other systems

fixes PR port-xen/55285 for Patrick Welche, but not yet for another system
by Frank Kardel


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/xen/x86/pintr.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/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.16 src/sys/arch/xen/x86/pintr.c:1.17
--- src/sys/arch/xen/x86/pintr.c:1.16	Fri May 15 07:42:58 2020
+++ src/sys/arch/xen/x86/pintr.c	Sat May 23 14:51:19 2020
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.16 2020/05/15 07:42:58 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.17 2020/05/23 14:51:19 jdolecek Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -173,7 +173,6 @@ short irq2port[NR_EVENT_CHANNELS] = {0};
 int
 xen_pic_to_gsi(struct pic *pic, int pin)
 {
-	struct physdev_map_pirq map_irq;
 	int ret;
 	int gsi;
 
@@ -199,21 +198,23 @@ xen_pic_to_gsi(struct pic *pic, int pin)
 			break;
 		}
 
-		memset(_irq, 0, sizeof(map_irq));
-		map_irq.domid = DOMID_SELF;
-		map_irq.type = MAP_PIRQ_TYPE_GSI;
-		map_irq.index = pin;
-		map_irq.pirq = gsi;
-		ret = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, _irq);
-		if (ret != 0)
-			panic("physdev_op(PHYSDEVOP_map_pirq) GSI fail %d",
-			ret);
+		struct physdev_irq irq_op;
+		memset(_op, 0, sizeof(irq_op));
+		irq_op.irq = gsi;
+		ret = HYPERVISOR_physdev_op(PHYSDEVOP_alloc_irq_vector,
+		_op);
+		if (ret < 0) {
+			panic("physdev_op(PHYSDEVOP_alloc_irq_vector) %d"
+			" fail %d", gsi, ret);
+		}
+		KASSERT(irq_op.vector == gsi);
 		break;
 	}
 	case PIC_MSI:
 	case PIC_MSIX:
 #ifdef __HAVE_PCI_MSI_MSIX
 	{
+		struct physdev_map_pirq map_irq;
 		const struct msipic_pci_info *i = msipic_get_pci_info(pic);
 
 		memset(_irq, 0, sizeof(map_irq));



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

2020-05-15 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri May 15 07:31:07 UTC 2020

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

Log Message:
only call PHYSDEVOP_map_pirq for a shared interrupt once, same as previous code

fixes boot problem reported privately by Frank Kardel and Patrick Welche


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/xen/x86/pintr.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/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.14 src/sys/arch/xen/x86/pintr.c:1.15
--- src/sys/arch/xen/x86/pintr.c:1.14	Mon May  4 15:55:56 2020
+++ src/sys/arch/xen/x86/pintr.c	Fri May 15 07:31:07 2020
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.14 2020/05/04 15:55:56 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.15 2020/05/15 07:31:07 jdolecek Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -194,6 +194,11 @@ xen_pic_to_gsi(struct pic *pic, int pin)
 	{
 		KASSERT(gsi < 255);
 
+		if (irq2port[gsi] != 0) {
+			/* Already mapped the shared interrupt */
+			break;
+		}
+
 		memset(_irq, 0, sizeof(map_irq));
 		map_irq.domid = DOMID_SELF;
 		map_irq.type = MAP_PIRQ_TYPE_GSI;
@@ -201,7 +206,8 @@ xen_pic_to_gsi(struct pic *pic, int pin)
 		map_irq.pirq = gsi;
 		ret = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, _irq);
 		if (ret != 0)
-			panic("physdev_op(PHYSDEVOP_map_pirq) fail");
+			panic("physdev_op(PHYSDEVOP_map_pirq) GSI fail %d",
+			ret);
 		break;
 	}
 	case PIC_MSI:
@@ -226,7 +232,8 @@ xen_pic_to_gsi(struct pic *pic, int pin)
 		}
 		ret = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, _irq);
 		if (ret != 0)
-			panic("physdev_op(PHYSDEVOP_map_pirq) fail");
+			panic("physdev_op(PHYSDEVOP_map_pirq) MSI fail %d",
+			ret);
 		KASSERT(map_irq.entry_nr == i->mp_veccnt);
 		gsi = map_irq.pirq;
 		break;



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

2020-05-06 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed May  6 19:50:26 UTC 2020

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

Log Message:
Make MP-safe: make sure the xpq_queue* are flushed before making the
pages visible to UVM.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/xen/x86/xen_bus_dma.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_bus_dma.c
diff -u src/sys/arch/xen/x86/xen_bus_dma.c:1.31 src/sys/arch/xen/x86/xen_bus_dma.c:1.32
--- src/sys/arch/xen/x86/xen_bus_dma.c:1.31	Sat Apr 25 15:26:17 2020
+++ src/sys/arch/xen/x86/xen_bus_dma.c	Wed May  6 19:50:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_bus_dma.c,v 1.31 2020/04/25 15:26:17 bouyer Exp $	*/
+/*	$NetBSD: xen_bus_dma.c,v 1.32 2020/05/06 19:50:26 bouyer Exp $	*/
 /*	NetBSD bus_dma.c,v 1.21 2005/04/16 07:53:35 yamt Exp */
 
 /*-
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_bus_dma.c,v 1.31 2020/04/25 15:26:17 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_bus_dma.c,v 1.32 2020/05/06 19:50:26 bouyer Exp $");
 
 #include 
 #include 
@@ -146,15 +146,18 @@ _xen_alloc_contig(bus_size_t size, bus_s
 		pa = VM_PAGE_TO_PHYS(pg);
 		xpmap_ptom_map(pa, ptoa(mfn+i));
 		xpq_queue_machphys_update(((paddr_t)(mfn+i)) << PAGE_SHIFT, pa);
-		/* while here, give extra pages back to UVM */
+	}
+	/* Flush updates through and flush the TLB */
+	xpq_queue_tlb_flush();
+	splx(s);
+	/* now that ptom/mtop are valid, give the extra pages back to UVM */
+	for (pg = mlistp->tqh_first, i = 0; pg != NULL; pg = pgnext, i++) {
+		pgnext = pg->pageq.queue.tqe_next;
 		if (i >= npagesreq) {
 			TAILQ_REMOVE(mlistp, pg, pageq.queue);
 			uvm_pagefree(pg);
 		}
 	}
-	/* Flush updates through and flush the TLB */
-	xpq_queue_tlb_flush();
-	splx(s);
 	return 0;
 
 failed:
@@ -190,11 +193,11 @@ failed:
 		pa = VM_PAGE_TO_PHYS(pg);
 		xpmap_ptom_map(pa, ptoa(mfn));
 		xpq_queue_machphys_update(((paddr_t)mfn) << PAGE_SHIFT, pa);
+		/* slow but we don't care */
+		xpq_queue_tlb_flush();
 		TAILQ_REMOVE(mlistp, pg, pageq.queue);
 		uvm_pagefree(pg);
 	}
-	/* Flush updates through and flush the TLB */
-	xpq_queue_tlb_flush();
 	splx(s);
 	return error;
 }



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

2020-05-06 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed May  6 19:47:05 UTC 2020

Modified Files:
src/sys/arch/xen/x86: x86_xpmap.c xenfunc.c

Log Message:
xpq_queue_* use per-cpu queue; splvm() is enough to protect them.
remove the XXX SMP comments.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/arch/xen/x86/x86_xpmap.c
cvs rdiff -u -r1.27 -r1.28 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/xen/x86/x86_xpmap.c
diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.87 src/sys/arch/xen/x86/x86_xpmap.c:1.88
--- src/sys/arch/xen/x86/x86_xpmap.c:1.87	Wed May  6 17:28:26 2020
+++ src/sys/arch/xen/x86/x86_xpmap.c	Wed May  6 19:47:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.87 2020/05/06 17:28:26 bouyer Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.88 2020/05/06 19:47:05 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.87 2020/05/06 17:28:26 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.88 2020/05/06 19:47:05 bouyer Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -182,7 +182,7 @@ xen_set_ldt(vaddr_t base, uint32_t entri
 		ptp = kvtopte(va);
 		pmap_pte_clearbits(ptp, PTE_W);
 	}
-	s = splvm(); /* XXXSMP */
+	s = splvm();
 	xpq_queue_set_ldt(base, entries);
 	splx(s);
 }
@@ -938,14 +938,14 @@ void
 xen_set_user_pgd(paddr_t page)
 {
 	struct mmuext_op op;
-	int s = splvm(); /* XXXSMP */
 
+	int s = splvm();
 	xpq_flush_queue();
+	splx(s);
 	op.cmd = MMUEXT_NEW_USER_BASEPTR;
 	op.arg1.mfn = xpmap_ptom_masked(page) >> PAGE_SHIFT;
 	if (HYPERVISOR_mmuext_op(, 1, NULL, DOMID_SELF) < 0)
 		panic("xen_set_user_pgd: failed to install new user page"
 			" directory %#" PRIxPADDR, page);
-	splx(s);
 }
 #endif /* __x86_64__ */

Index: src/sys/arch/xen/x86/xenfunc.c
diff -u src/sys/arch/xen/x86/xenfunc.c:1.27 src/sys/arch/xen/x86/xenfunc.c:1.28
--- src/sys/arch/xen/x86/xenfunc.c:1.27	Sat Apr 25 15:26:17 2020
+++ src/sys/arch/xen/x86/xenfunc.c	Wed May  6 19:47:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xenfunc.c,v 1.27 2020/04/25 15:26:17 bouyer Exp $	*/
+/*	$NetBSD: xenfunc.c,v 1.28 2020/05/06 19:47:05 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2004 Christian Limpach.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.27 2020/04/25 15:26:17 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.28 2020/05/06 19:47:05 bouyer Exp $");
 
 #include 
 
@@ -144,7 +144,7 @@ rcr0(void)
 void
 lcr3(register_t val)
 {
-	int s = splvm(); /* XXXSMP */
+	int s = splvm();
 	xpq_queue_pt_switch(xpmap_ptom_masked(val));
 	splx(s);
 }
@@ -153,7 +153,7 @@ lcr3(register_t val)
 void
 tlbflush(void)
 {
-	int s = splvm(); /* XXXSMP */
+	int s = splvm();
 	xpq_queue_tlb_flush();
 	splx(s);
 }



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

2020-05-06 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed May  6 17:28:26 UTC 2020

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

Log Message:
KASSERT() that the per-cpu queues are run at IPL_VM after boot.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 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.86 src/sys/arch/xen/x86/x86_xpmap.c:1.87
--- src/sys/arch/xen/x86/x86_xpmap.c:1.86	Sat May  2 16:44:36 2020
+++ src/sys/arch/xen/x86/x86_xpmap.c	Wed May  6 17:28:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.86 2020/05/02 16:44:36 bouyer Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.87 2020/05/06 17:28:26 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.86 2020/05/02 16:44:36 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.87 2020/05/06 17:28:26 bouyer Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -105,6 +105,7 @@ __KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -193,6 +194,8 @@ xpq_flush_queue(void)
 	int done = 0, ret;
 	size_t xpq_idx;
 
+	KASSERT(curcpu()->ci_ilevel >= IPL_VM || cold);
+
 	xpq_idx = curcpu()->ci_xpq_idx;
 	xpq_queue = xpq_queue_array[curcpu()->ci_cpuid];
 
@@ -219,7 +222,7 @@ retry:
 static inline void
 xpq_increment_idx(void)
 {
-
+	KASSERT(curcpu()->ci_ilevel >= IPL_VM || cold);
 	if (__predict_false(++curcpu()->ci_xpq_idx == XPQUEUE_SIZE))
 		xpq_flush_queue();
 }
@@ -315,12 +318,12 @@ xpq_queue_tlb_flush(void)
 void
 xpq_flush_cache(void)
 {
-	int s = splvm(); /* XXXSMP */
+	int s = splvm();
 
 	xpq_flush_queue();
 
 	asm("wbinvd":::"memory");
-	splx(s); /* XXX: removeme */
+	splx(s);
 }
 
 void



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

2020-05-03 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sun May  3 17:23:14 UTC 2020

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

Log Message:
Hanble dom0 console. This one doesn't need a ring to be mapped, and
can be used earlier.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/xen/x86/pvh_consinit.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/pvh_consinit.c
diff -u src/sys/arch/xen/x86/pvh_consinit.c:1.1 src/sys/arch/xen/x86/pvh_consinit.c:1.2
--- src/sys/arch/xen/x86/pvh_consinit.c:1.1	Sat May  2 16:44:36 2020
+++ src/sys/arch/xen/x86/pvh_consinit.c	Sun May  3 17:23:14 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: pvh_consinit.c,v 1.1 2020/05/02 16:44:36 bouyer Exp $ */
+/* $NetBSD: pvh_consinit.c,v 1.2 2020/05/03 17:23:14 bouyer Exp $ */
 
 /*
  * Copyright (c) 2020 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pvh_consinit.c,v 1.1 2020/05/02 16:44:36 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pvh_consinit.c,v 1.2 2020/05/03 17:23:14 bouyer Exp $");
 
 #include "xencons.h"
 #include 
@@ -59,7 +59,7 @@ xen_pvh_consinit(void)
 	 * boot stage.
 	 */
 	static int initted = 0;
-	if (initted == 0) {
+	if (initted == 0 && !xendomain_is_dom0()) {
 		/* pmap not up yet, fall back to printk() */
 		cn_tab = _xencons;
 		initted++;
@@ -68,6 +68,12 @@ xen_pvh_consinit(void)
 		return;
 	}
 	initted++;
+	if (xendomain_is_dom0()) {
+		xenconscn_attach(); /* no ring in this case */
+		initted++; /* don't init console twice */
+		return;
+	}
+		
 #if NXENCONS > 0
 	/* we can now map the xencons rings. */
 	struct xen_hvm_param xen_hvm_param;



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

2020-04-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue Apr 21 18:24:05 UTC 2020

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

Log Message:
Remove spurious reference to XEN_IPI_KICK - it represents the absence of
a specific IPI type.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 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.36 src/sys/arch/xen/x86/xen_ipi.c:1.37
--- src/sys/arch/xen/x86/xen_ipi.c:1.36	Mon Apr 13 22:54:12 2020
+++ src/sys/arch/xen/x86/xen_ipi.c	Tue Apr 21 18:24:05 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.36 2020/04/13 22:54:12 bouyer Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.37 2020/04/21 18:24:05 ad Exp $ */
 
 /*-
  * Copyright (c) 2011, 2019 The NetBSD Foundation, Inc.
@@ -33,10 +33,10 @@
 
 /* 
  * Based on: x86/ipi.c
- * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.36 2020/04/13 22:54:12 bouyer Exp $");
+ * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.37 2020/04/21 18:24:05 ad Exp $");
  */
 
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.36 2020/04/13 22:54:12 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.37 2020/04/21 18:24:05 ad Exp $");
 
 #include "opt_ddb.h"
 
@@ -156,7 +156,7 @@ valid_ipimask(uint32_t ipimask)
 {
 	uint32_t masks = XEN_IPI_GENERIC | XEN_IPI_HVCB | XEN_IPI_XCALL |
 		 XEN_IPI_DDB | XEN_IPI_SYNCH_FPU |
-		 XEN_IPI_HALT | XEN_IPI_KICK | XEN_IPI_AST;
+		 XEN_IPI_HALT | XEN_IPI_AST;
 
 	if (ipimask & ~masks) {
 		return false;



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

2020-04-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue Apr 21 18:22:29 UTC 2020

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

Log Message:
Follow convention and put entire predicate inside __predict_false()


To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 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.133 src/sys/arch/xen/x86/cpu.c:1.134
--- src/sys/arch/xen/x86/cpu.c:1.133	Mon Feb 24 12:20:29 2020
+++ src/sys/arch/xen/x86/cpu.c	Tue Apr 21 18:22:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.133 2020/02/24 12:20:29 rin Exp $	*/
+/*	$NetBSD: cpu.c,v 1.134 2020/04/21 18:22:29 ad Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.133 2020/02/24 12:20:29 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.134 2020/04/21 18:22:29 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -1094,7 +1094,7 @@ x86_cpu_idle_xen(void)
 	KASSERT(ci->ci_ilevel == IPL_NONE);
 
 	x86_disable_intr();
-	if (!__predict_false(ci->ci_want_resched)) {
+	if (__predict_false(!ci->ci_want_resched)) {
 		idle_block();
 	} else {
 		x86_enable_intr();



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

2020-04-07 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Apr  7 07:43:33 UTC 2020

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

Log Message:
remove  include, not used here


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/xen/x86/pintr.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/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.10 src/sys/arch/xen/x86/pintr.c:1.11
--- src/sys/arch/xen/x86/pintr.c:1.10	Wed Feb 13 06:15:51 2019
+++ src/sys/arch/xen/x86/pintr.c	Tue Apr  7 07:43:33 2020
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.10 2019/02/13 06:15:51 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.11 2020/04/07 07:43:33 jdolecek Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -115,7 +115,6 @@ __KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 



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

2020-01-13 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Jan 13 20:15:01 UTC 2020

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

Log Message:
Don't call cpu_switchto() before idle_loop(), it should not be needed any more.
While there, assume (and KASSERT) that curlwp == ci->ci_data.cpu_idlelwp,
this saves a lwp_getpcb() call.


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 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.131 src/sys/arch/xen/x86/cpu.c:1.132
--- src/sys/arch/xen/x86/cpu.c:1.131	Sat Nov 23 19:40:38 2019
+++ src/sys/arch/xen/x86/cpu.c	Mon Jan 13 20:15:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.131 2019/11/23 19:40:38 ad Exp $	*/
+/*	$NetBSD: cpu.c,v 1.132 2020/01/13 20:15:01 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.131 2019/11/23 19:40:38 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.132 2020/01/13 20:15:01 bouyer Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -716,9 +716,10 @@ cpu_hatch(void *v)
 
 	KASSERT((ci->ci_flags & CPUF_RUNNING) == 0);
 
+	KASSERT(ci->ci_curlwp == ci->ci_data.cpu_idlelwp);
+	KASSERT(curlwp == ci->ci_data.cpu_idlelwp);
 	pcb = lwp_getpcb(curlwp);
 	pcb->pcb_cr3 = pmap_pdirpa(pmap_kernel(), 0);
-	pcb = lwp_getpcb(ci->ci_data.cpu_idlelwp);
 
 	xen_ipi_init();
 
@@ -739,8 +740,7 @@ cpu_hatch(void *v)
 
 	aprint_debug_dev(ci->ci_dev, "running\n");
 
-	cpu_switchto(NULL, ci->ci_data.cpu_idlelwp, true);
-
+	KASSERT(ci->ci_curlwp == ci->ci_data.cpu_idlelwp);
 	idle_loop(NULL);
 	KASSERT(false);
 }



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

2020-01-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue Jan  7 13:48:01 UTC 2020

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

Log Message:
Correction to previous.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/xen/x86/xen_pmap.c

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

Modified files:

Index: src/sys/arch/xen/x86/xen_pmap.c
diff -u src/sys/arch/xen/x86/xen_pmap.c:1.36 src/sys/arch/xen/x86/xen_pmap.c:1.37
--- src/sys/arch/xen/x86/xen_pmap.c:1.36	Tue Jan  7 13:20:18 2020
+++ src/sys/arch/xen/x86/xen_pmap.c	Tue Jan  7 13:48:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_pmap.c,v 1.36 2020/01/07 13:20:18 ad Exp $	*/
+/*	$NetBSD: xen_pmap.c,v 1.37 2020/01/07 13:48:01 ad Exp $	*/
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -101,7 +101,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.36 2020/01/07 13:20:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.37 2020/01/07 13:48:01 ad Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -220,7 +220,9 @@ pmap_extract_ma(struct pmap *pmap, vaddr
 	pmap_map_ptes(pmap, , , );
 	if (!pmap_pdes_valid(va, pdes, , )) {
 		pmap_unmap_ptes(pmap, pmap2);
-		mutex_exit(>pm_lock);
+		if (pmap != pmap_kernel()) {
+			mutex_exit(>pm_lock);
+		}
 		return false;
 	}
 



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

2020-01-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue Jan  7 13:20:18 UTC 2020

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

Log Message:
pmap_extract_ma(): don't need to take pm_lock for pmap_kernel().


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/xen/x86/xen_pmap.c

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

Modified files:

Index: src/sys/arch/xen/x86/xen_pmap.c
diff -u src/sys/arch/xen/x86/xen_pmap.c:1.35 src/sys/arch/xen/x86/xen_pmap.c:1.36
--- src/sys/arch/xen/x86/xen_pmap.c:1.35	Sat Jan  4 22:49:20 2020
+++ src/sys/arch/xen/x86/xen_pmap.c	Tue Jan  7 13:20:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_pmap.c,v 1.35 2020/01/04 22:49:20 ad Exp $	*/
+/*	$NetBSD: xen_pmap.c,v 1.36 2020/01/07 13:20:18 ad Exp $	*/
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -101,7 +101,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.35 2020/01/04 22:49:20 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.36 2020/01/07 13:20:18 ad Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -214,7 +214,9 @@ pmap_extract_ma(struct pmap *pmap, vaddr
 	struct pmap *pmap2;
 	int lvl;
 
-	mutex_enter(>pm_lock);
+	if (pmap != pmap_kernel()) {
+		mutex_enter(>pm_lock);
+	}
 	pmap_map_ptes(pmap, , , );
 	if (!pmap_pdes_valid(va, pdes, , )) {
 		pmap_unmap_ptes(pmap, pmap2);
@@ -225,7 +227,9 @@ pmap_extract_ma(struct pmap *pmap, vaddr
 	KASSERT(lvl == 1);
 	pte = ptes[pl1_i(va)];
 	pmap_unmap_ptes(pmap, pmap2);
-	mutex_exit(>pm_lock);
+	if (pmap != pmap_kernel()) {
+		mutex_exit(>pm_lock);
+	}
 
 	if (__predict_true((pte & PTE_P) != 0)) {
 		if (pap != NULL)



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

2019-05-04 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat May  4 11:15:49 UTC 2019

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

Log Message:
More of maxv's "switch to proper types" - hopefully unbreak i386 build.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 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/xen/x86/xenfunc.c
diff -u src/sys/arch/xen/x86/xenfunc.c:1.25 src/sys/arch/xen/x86/xenfunc.c:1.26
--- src/sys/arch/xen/x86/xenfunc.c:1.25	Sat May  4 07:20:22 2019
+++ src/sys/arch/xen/x86/xenfunc.c	Sat May  4 11:15:49 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: xenfunc.c,v 1.25 2019/05/04 07:20:22 maxv Exp $	*/
+/*	$NetBSD: xenfunc.c,v 1.26 2019/05/04 11:15:49 kre Exp $	*/
 
 /*
  * Copyright (c) 2004 Christian Limpach.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.25 2019/05/04 07:20:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.26 2019/05/04 11:15:49 kre Exp $");
 
 #include 
 
@@ -138,7 +138,7 @@ rcr0(void)
 
 #ifndef __x86_64__
 void
-lcr3(vaddr_t val)
+lcr3(register_t val)
 {
 	int s = splvm(); /* XXXSMP */
 	xpq_queue_pt_switch(xpmap_ptom_masked(val));



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

2019-02-13 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Feb 13 09:57:46 UTC 2019

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

Log Message:
Conditionally compile a conditionally used variable.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/xen/x86/xen_mainbus.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_mainbus.c
diff -u src/sys/arch/xen/x86/xen_mainbus.c:1.4 src/sys/arch/xen/x86/xen_mainbus.c:1.5
--- src/sys/arch/xen/x86/xen_mainbus.c:1.4	Sat Dec 22 08:35:04 2018
+++ src/sys/arch/xen/x86/xen_mainbus.c	Wed Feb 13 09:57:46 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_mainbus.c,v 1.4 2018/12/22 08:35:04 maxv Exp $	*/
+/*	$NetBSD: xen_mainbus.c,v 1.5 2019/02/13 09:57:46 cherry Exp $	*/
 /*	NetBSD: mainbus.c,v 1.19 2017/05/23 08:54:39 nonaka Exp 	*/
 /*	NetBSD: mainbus.c,v 1.53 2003/10/27 14:11:47 junyoung Exp 	*/
 
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_mainbus.c,v 1.4 2018/12/22 08:35:04 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_mainbus.c,v 1.5 2019/02/13 09:57:46 cherry Exp $");
 
 #include 
 #include 
@@ -130,7 +130,9 @@ xen_mainbus_match(device_t parent, cfdat
 void
 xen_mainbus_attach(device_t parent, device_t self, void *aux)
 {
+#if NIPMI > 0 || NHYPERVISOR > 0
 	union xen_mainbus_attach_args mba;
+#endif
 
 #if NIPMI > 0
 	memset(_ipmi, 0, sizeof(mba.mba_ipmi));



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

2019-02-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Feb 13 06:15:51 UTC 2019

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

Log Message:
Catchup with struct intrstub; unification.

This should fix dom0 build breakage.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/xen/x86/pintr.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/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.9 src/sys/arch/xen/x86/pintr.c:1.10
--- src/sys/arch/xen/x86/pintr.c:1.9	Wed Oct 10 02:34:08 2018
+++ src/sys/arch/xen/x86/pintr.c	Wed Feb 13 06:15:51 2019
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.9 2018/10/10 02:34:08 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.10 2019/02/13 06:15:51 cherry Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -135,17 +135,19 @@ __KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.
 /* XXX: todo - compat with lapic.c and XEN for x2apic */
 bool x2apic_mode __read_mostly = false;
 /* for x86/i8259.c */
-struct intrstub legacy_stubs[NUM_LEGACY_IRQS] = {{0,0}};
+struct intrstub legacy_stubs[NUM_LEGACY_IRQS] = {{0,0,0}};
 /* for x86/ioapic.c */
-struct intrstub ioapic_edge_stubs[MAX_INTR_SOURCES] = {{0,0}};
-struct intrstub ioapic_level_stubs[MAX_INTR_SOURCES] = {{0,0}};
-struct intrstub x2apic_edge_stubs[MAX_INTR_SOURCES] = {{0,0}};
-struct intrstub x2apic_level_stubs[MAX_INTR_SOURCES] = {{0,0}};
+struct intrstub ioapic_edge_stubs[MAX_INTR_SOURCES] = {{0,0,0}};
+struct intrstub ioapic_level_stubs[MAX_INTR_SOURCES] = {{0,0,0}};
+struct intrstub x2apic_edge_stubs[MAX_INTR_SOURCES] = {{0,0,0}};
+struct intrstub x2apic_level_stubs[MAX_INTR_SOURCES] = {{0,0,0}};
 #include 
+#endif /* NIOAPIC */
+
 int irq2port[NR_EVENT_CHANNELS] = {0}; /* actually port + 1, so that 0 is invaid */
 static int irq2vect[256] = {0};
 static int vect2irq[256] = {0};
-#endif /* NIOAPIC */
+
 #if NACPICA > 0
 #include 
 #include 



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

2019-01-28 Thread Christoph Badura
Module Name:src
Committed By:   bad
Date:   Mon Jan 28 21:19:09 UTC 2019

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

Log Message:
Sprinkle DPRINTF #ifdef DEBUG_GEOM and set booted_method like 
arch/x86/x86/x86_autoconf.c

As discussed 1 week ago on port-xen.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/xen/x86/autoconf.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/autoconf.c
diff -u src/sys/arch/xen/x86/autoconf.c:1.21 src/sys/arch/xen/x86/autoconf.c:1.22
--- src/sys/arch/xen/x86/autoconf.c:1.21	Sat Dec 22 07:45:58 2018
+++ src/sys/arch/xen/x86/autoconf.c	Mon Jan 28 21:19:09 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.21 2018/12/22 07:45:58 cherry Exp $	*/
+/*	$NetBSD: autoconf.c,v 1.22 2019/01/28 21:19:09 bad Exp $	*/
 /*	NetBSD: autoconf.c,v 1.75 2003/12/30 12:33:22 pk Exp 	*/
 
 /*-
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.21 2018/12/22 07:45:58 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.22 2019/01/28 21:19:09 bad Exp $");
 
 #include "opt_xen.h"
 #include "opt_multiprocessor.h"
@@ -101,6 +101,12 @@ extern void platform_init(void);
 #include 
 #endif
 
+#ifdef DEBUG_GEOM
+#define DPRINTF(a) printf a
+#else
+#define DPRINTF(a)
+#endif
+
 /*
  * Determine i/o configuration for a machine.
  */
@@ -170,8 +176,10 @@ cpu_bootconf(void)
 	union xen_cmdline_parseinfo xcp;
 	static char bootspecbuf[sizeof(xcp.xcp_bootdev)];
 
-	if (booted_device)
+	if (booted_device) {
+		DPRINTF(("%s: preset booted_device: %s\n", __func__, device_xname(booted_device)));
 		return;
+	}
 
 	xen_parse_cmdline(XEN_PARSE_BOOTDEV, );
 
@@ -197,17 +205,22 @@ cpu_bootconf(void)
 			continue;
 
 		if (is_disk && strlen(xcp.xcp_bootdev) > strlen(devname)) {
+			/* XXX check device_cfdata as in x86_autoconf.c? */
 			booted_partition = toupper(
 xcp.xcp_bootdev[strlen(devname)]) - 'A';
+			DPRINTF(("%s: booted_partition: %d\n", __func__, booted_partition));
 		}
 
 		booted_device = dv;
+		booted_method = "bootinfo/bootdev";
 		break;
 	}
 	deviter_release();
 
-	if (booted_device)
+	if (booted_device) {
+		DPRINTF(("%s: booted_device: %s\n", __func__, device_xname(booted_device)));
 		return;
+	}
 
 	/*
 	 * not a boot device name, pass through to MI code
@@ -215,6 +228,8 @@ cpu_bootconf(void)
 	if (xcp.xcp_bootdev[0] != '\0') {
 		strlcpy(bootspecbuf, xcp.xcp_bootdev, sizeof(bootspecbuf));
 		bootspec = bootspecbuf;
+		booted_method = "bootinfo/bootspec";
+		DPRINTF(("%s: bootspec: %s\n", __func__, bootspec));
 		return;
 	}
 }
@@ -359,7 +374,6 @@ found:
 static int
 is_valid_disk(device_t dv)
 {
-
 	if (device_class(dv) != DV_DISK)
 		return (0);
 



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

2019-01-26 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 27 05:08:58 UTC 2019

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

Log Message:
fix duplicated chunk from merge


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 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.30 src/sys/arch/xen/x86/xen_ipi.c:1.31
--- src/sys/arch/xen/x86/xen_ipi.c:1.30	Sun Jan 27 02:08:39 2019
+++ src/sys/arch/xen/x86/xen_ipi.c	Sun Jan 27 05:08:58 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.30 2019/01/27 02:08:39 pgoyette Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.31 2019/01/27 05:08:58 dholland Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -33,12 +33,10 @@
 
 /* 
  * Based on: x86/ipi.c
- * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.30 2019/01/27 02:08:39 pgoyette Exp $");
+ * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.31 2019/01/27 05:08:58 dholland Exp $");
  */
 
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.30 2019/01/27 02:08:39 pgoyette Exp $");
-
-#include "opt_ddb.h"
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.31 2019/01/27 05:08:58 dholland Exp $");
 
 #include "opt_ddb.h"
 



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

2018-11-16 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov 17 05:26:46 UTC 2018

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

Log Message:
Use hypervisor provided interface to unmask specific ports.

Although at first glance this looks suboptimal, the unmask operation
fast path does not use hypervisor_unmask_event(). Instead, it directly
operates on the mask and pending bit arrays to provide what would
effectively be an "auto mask/eoi" semantic.

This change is thus not in the fast path, and has the advantage of
performance improvements since cross CPU state updates etc. is handled
within the hypervisor instead of domU IPIs.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 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.29 src/sys/arch/xen/x86/hypervisor_machdep.c:1.30
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.29	Fri Oct 26 05:33:21 2018
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Sat Nov 17 05:26:46 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.29 2018/10/26 05:33:21 cherry Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.30 2018/11/17 05:26:46 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.29 2018/10/26 05:33:21 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.30 2018/11/17 05:26:46 cherry Exp $");
 
 #include 
 #include 
@@ -322,47 +322,22 @@ hypervisor_send_event(struct cpu_info *c
 void
 hypervisor_unmask_event(unsigned int ev)
 {
-	volatile shared_info_t *s = HYPERVISOR_shared_info;
-	CPU_INFO_ITERATOR cii;
-	struct cpu_info *ci;
-	volatile struct vcpu_info *vci;
+
+	KASSERT(ev > 0 && ev < NR_EVENT_CHANNELS);
 
 #ifdef PORT_DEBUG
 	if (ev == PORT_DEBUG)
 		printf("hypervisor_unmask_event %d\n", ev);
 #endif
 
-	xen_atomic_clear_bit(>evtchn_mask[0], ev);
-	/*
-	 * The following is basically the equivalent of
-	 * 'hw_resend_irq'. Just like a real IO-APIC we 'lose the
-	 * interrupt edge' if the channel is masked.
-	 */
-	if (!xen_atomic_test_bit(>evtchn_pending[0], ev))
-		return;
+	/* Xen unmasks the evtchn_mask[0]:ev bit for us. */
+	evtchn_op_t op;
+	op.cmd = EVTCHNOP_unmask;
+	op.u.unmask.port = ev;
+	if (HYPERVISOR_event_channel_op() != 0)
+		panic("Failed to unmask event %d\n", ev);
 
-	for (CPU_INFO_FOREACH(cii, ci)) {
-		if (!xen_atomic_test_bit(>ci_evtmask[0], ev))
-			continue;
-		vci = ci->ci_vcpu;
-		if (__predict_true(ci == curcpu())) {
-			if (!xen_atomic_test_and_set_bit(>evtchn_pending_sel,
-ev>>LONG_SHIFT))
-xen_atomic_set_bit(>evtchn_upcall_pending, 0);
-		}
-		if (!vci->evtchn_upcall_mask) {
-			if (__predict_true(ci == curcpu())) {
-hypervisor_force_callback();
-			} else {
-if (__predict_false(
-xen_send_ipi(ci, XEN_IPI_HVCB))) {
-	panic("xen_send_ipi(cpu%d, "
-	"XEN_IPI_HVCB) failed\n",
-	(int) ci->ci_cpuid);
-}
-			}
-		}
-	}
+	return;
 }
 
 void



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

2018-10-17 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Oct 18 04:17:18 UTC 2018

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

Log Message:
Zero out page table memory for IDT before use.
To copy the IDT entry before registration, de-reference the indexed
value, not the first entry.
Add a MAX_XEN_IDT value for max entries we expect and KASSERT() for
this as a sanity check.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 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/xen/x86/xenfunc.c
diff -u src/sys/arch/xen/x86/xenfunc.c:1.21 src/sys/arch/xen/x86/xenfunc.c:1.22
--- src/sys/arch/xen/x86/xenfunc.c:1.21	Sun Sep 23 15:28:49 2018
+++ src/sys/arch/xen/x86/xenfunc.c	Thu Oct 18 04:17:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: xenfunc.c,v 1.21 2018/09/23 15:28:49 cherry Exp $	*/
+/*	$NetBSD: xenfunc.c,v 1.22 2018/10/18 04:17:18 cherry Exp $	*/
 
 /*
  * Copyright (c) 2004 Christian Limpach.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.21 2018/09/23 15:28:49 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.22 2018/10/18 04:17:18 cherry Exp $");
 
 #include 
 
@@ -41,6 +41,8 @@ __KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 
 #include 
 #include 
 
+#define MAX_XEN_IDT 128
+
 void xen_set_ldt(vaddr_t, uint32_t);
 
 void 
@@ -59,7 +61,8 @@ lidt(struct region_descriptor *rd)
 	 * will be available at the boot stage when this is called.
 	 */
 	static char xen_idt_page[PAGE_SIZE] __attribute__((__aligned__ (PAGE_SIZE)));
-
+	memset(xen_idt_page, 0, PAGE_SIZE);
+	
 	struct trap_info *xen_idt = (void * )xen_idt_page;
 	int xen_idt_idx = 0;
 	
@@ -73,9 +76,9 @@ lidt(struct region_descriptor *rd)
 	 * back in the requestor array.
 	 */
 	for (i = 0; i < nidt; i++) {
-		if (idd->address == 0) /* Skip gap */
+		if (idd[i].address == 0) /* Skip gap */
 			continue;
-
+		KASSERT(xen_idt_idx < MAX_XEN_IDT);
 		/* Copy over entry */
 		xen_idt[xen_idt_idx++] = idd[i];
 	}



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

2018-10-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Oct 10 02:16:34 UTC 2018

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

Log Message:
Since GSIs are invented by the mpbios/mpacpi interrupt routing probe code,
it's possible for shared GSIs to popup even outside the original
legacy_irq range.

Relax this latter, older assumption.

Thanks to Brad Spencer for extensive trialing on interesting hardware.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/xen/x86/pintr.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/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.7 src/sys/arch/xen/x86/pintr.c:1.8
--- src/sys/arch/xen/x86/pintr.c:1.7	Sun Oct  7 05:23:01 2018
+++ src/sys/arch/xen/x86/pintr.c	Wed Oct 10 02:16:34 2018
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.7 2018/10/07 05:23:01 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.8 2018/10/10 02:16:34 cherry Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -176,8 +176,7 @@ xen_vec_alloc(int gsi)
 			irq2vect[gsi] == op.u.irq_op.vector);
 		irq2vect[gsi] = op.u.irq_op.vector;
 		KASSERT(vect2irq[op.u.irq_op.vector] == 0 ||
-			(gsi > 0 && gsi < 16 &&
-			 vect2irq[op.u.irq_op.vector] == gsi));
+			 vect2irq[op.u.irq_op.vector] == gsi);
 		vect2irq[op.u.irq_op.vector] = gsi;
 	}
 



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

2018-10-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Oct  6 16:37:11 UTC 2018

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

Log Message:
Teach intr_establish_xname() for XEN to tolerate shared legacy_irq
registrations.

The current XEN code has not been able to tolerate shared legacy_irq
requests in xen_pirq_alloc(). This was never a problem because:

i) The only potential callpath with shared legacy_irq was
   isa_intr_establish_xname().
ii) The other callpath, namely pci_intr_establish_xname() passed
legacy_irq to intr_establish_xname(). However, this was ignored,
and a value of zero was passed to xen_pirq_alloc() which in
turn, allocated a new irq value, thus effectively demultiplexing
any shared legacy_irq value intended across randomly allocated
new irq values.
iii) Presumably on all platforms that XEN runs on, the isa callpath
 mentioned in i) never had shared irqs, and thus this was never
 a problem.

Except:
We now use a unified path for both isa_intr_establish_xname() and
pci_intr_establish_xname(). This means that now, intr_establish_xname()
which is a callee of both, needs to have a way to discern who the caller
was, and decide to pass on or discard the legacy_irq value, to preserve
the old semantics. However, this is impossible to do so, because the
callpath doesn't explicitly provide a mechanism for this discernment.

This is however not a problem, because from XEN's point of view, a
repeat registration of an irq is only a warning. legacy_irq is the only
case in which this repeat should occur, per the current implementation of
xen_pirq_alloc(). We thus tweak the KASSERT()s to tolerate a repeat value
in the legacy_irq, while maintaining the original intent of the KASSERT()
which was to ensure that existing unrelated irq registrations should never
be overwritten.

Once we re-organise XEN specific code and unify with the native
intr_establish_xname() path, we will not run into this problem, because
legacy_irq will be treated as the pin number of the i8259 pic
exactly as it is now treated in native.

In short, this commit should fix some of the panics being seen on
-current for certain configurations of hardware on which dom0 runs.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/xen/x86/pintr.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/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.3 src/sys/arch/xen/x86/pintr.c:1.4
--- src/sys/arch/xen/x86/pintr.c:1.3	Sat Feb 17 18:51:53 2018
+++ src/sys/arch/xen/x86/pintr.c	Sat Oct  6 16:37:11 2018
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.3 2018/02/17 18:51:53 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.4 2018/10/06 16:37:11 cherry Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -199,9 +199,13 @@ retry:
 	panic("PHYSDEVOP_ASSIGN_VECTOR irq %d", irq);
 goto retry;
 			}
-			KASSERT(irq2vect[irq] == 0);
+			KASSERT(irq2vect[irq] == 0 ||
+(irq > 0 && irq < 16 &&
+ irq2vect[irq] == op.u.irq_op.vector));
 			irq2vect[irq] = op.u.irq_op.vector;
-			KASSERT(vect2irq[op.u.irq_op.vector] == 0);
+			KASSERT(vect2irq[op.u.irq_op.vector] == 0 ||
+(irq > 0 && irq < 16 &&
+ vect2irq[op.u.irq_op.vector] == irq));
 			vect2irq[op.u.irq_op.vector] = irq;
 			pic->pic_addroute(pic, _info_primary, pin,
 			op.u.irq_op.vector, type);



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

2018-07-29 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Jul 29 08:02:25 UTC 2018

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

Log Message:
Reduce the confusion, rename a bunch of variables and reorg a little.
Tested on i386PAE-domU and amd64-dom0.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 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.80 src/sys/arch/xen/x86/x86_xpmap.c:1.81
--- src/sys/arch/xen/x86/x86_xpmap.c:1.80	Fri Jul 27 10:04:22 2018
+++ src/sys/arch/xen/x86/x86_xpmap.c	Sun Jul 29 08:02:24 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.80 2018/07/27 10:04:22 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.81 2018/07/29 08:02:24 maxv Exp $	*/
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.80 2018/07/27 10:04:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.81 2018/07/29 08:02:24 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -451,11 +451,10 @@ xpq_update_foreign(paddr_t ptr, pt_entry
 #define PDIRSZ	PTP_LEVELS
 #else
 /*
- * For PAE, we consider a single contiguous L2 "superpage" of 4 pages, all of
- * them mapped by the L3 page. We also need a shadow page for L3[3].
- * XXX so why 6?
+ * For PAE, we need an L3 page, a single contiguous L2 "superpage" of 4 pages
+ * (all of them mapped by the L3 page), and a shadow page for L3[3].
  */
-#define PDIRSZ	6
+#define PDIRSZ	(1 + 4 + 1)
 #endif
 
 /*
@@ -595,7 +594,7 @@ bootstrap_again:
 
 /*
  * Build a new table and switch to it.
- * old_count is # of old tables (including PGD, PDTPE and PDE).
+ * old_count is # of old tables (including L4, L3 and L2).
  * new_count is # of new tables (PTE only).
  * We assume the areas don't overlap.
  */
@@ -603,8 +602,7 @@ static void
 xen_bootstrap_tables(vaddr_t old_pgd, vaddr_t new_pgd, size_t old_count,
 size_t new_count, bool final)
 {
-	pd_entry_t *pdtpe, *pde, *pte;
-	pd_entry_t *bt_pgd;
+	pd_entry_t *L4cpu, *L4, *L3, *L2, *pte;
 	paddr_t addr;
 	vaddr_t page, avail, map_end;
 	int i;
@@ -659,68 +657,73 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	__PRINTK(("console %#lx ", xen_start_info.console_mfn));
 	__PRINTK(("xenstore %#" PRIx32 "\n", xen_start_info.store_mfn));
 
+	avail = new_pgd;
+
 	/*
-	 * Create bootstrap page tables. What we need:
-	 * - a PGD (level 4)
-	 * - a PDTPE (level 3)
-	 * - a PDE (level 2)
-	 * - some PTEs (level 1)
-	 */
-
-	bt_pgd = (pd_entry_t *)new_pgd;
-	memset(bt_pgd, 0, PAGE_SIZE);
-	avail = new_pgd + PAGE_SIZE;
-
-#ifdef __x86_64__
-	/* Per-cpu L4 */
-	pd_entry_t *bt_cpu_pgd = bt_pgd;
-	/* pmap_kernel() "shadow" L4 */
-	bt_pgd = (pd_entry_t *)avail;
-	memset(bt_pgd, 0, PAGE_SIZE);
+	 * Create our page tables.
+	 */
+
+#ifdef __x86_64__
+	/* per-cpu L4 */
+	L4cpu = (pd_entry_t *)avail;
+	memset(L4cpu, 0, PAGE_SIZE);
 	avail += PAGE_SIZE;
 
-	/* Install L3 */
-	pdtpe = (pd_entry_t *)avail;
-	memset(pdtpe, 0, PAGE_SIZE);
+	/* pmap_kernel L4 */
+	L4 = (pd_entry_t *)avail;
+	memset(L4, 0, PAGE_SIZE);
 	avail += PAGE_SIZE;
 
-	addr = ((u_long)pdtpe) - KERNBASE;
-	bt_pgd[pl4_pi(KERNTEXTOFF)] = bt_cpu_pgd[pl4_pi(KERNTEXTOFF)] =
-	xpmap_ptom_masked(addr) | PG_V | PG_RW;
-
-	/* Level 2 */
-	pde = (pd_entry_t *)avail;
-	memset(pde, 0, PAGE_SIZE);
+	/* L3 */
+	L3 = (pd_entry_t *)avail;
+	memset(L3, 0, PAGE_SIZE);
 	avail += PAGE_SIZE;
 
-	addr = ((u_long)pde) - KERNBASE;
-	pdtpe[pl3_pi(KERNTEXTOFF)] =
-	xpmap_ptom_masked(addr) | PG_V | PG_RW;
-#else
-	pdtpe = bt_pgd;
+	/* link L4->L3 */
+	addr = ((u_long)L3) - KERNBASE;
+	L4cpu[pl4_pi(KERNTEXTOFF)] = xpmap_ptom_masked(addr) | PG_V | PG_RW;
+	L4[pl4_pi(KERNTEXTOFF)] = xpmap_ptom_masked(addr) | PG_V | PG_RW;
+
+	/* L2 */
+	L2 = (pd_entry_t *)avail;
+	memset(L2, 0, PAGE_SIZE);
+	avail += PAGE_SIZE;
+
+	/* link L3->L2 */
+	addr = ((u_long)L2) - KERNBASE;
+	L3[pl3_pi(KERNTEXTOFF)] = xpmap_ptom_masked(addr) | PG_V | PG_RW;
+#else
+	/* no L4 on i386PAE */
+	__USE(L4cpu);
+	__USE(L4);
+
+	/* L3 */
+	L3 = (pd_entry_t *)avail;
+	memset(L3, 0, PAGE_SIZE);
+	avail += PAGE_SIZE;
 
 	/*
 	 * Our PAE-style level 2, 5 contiguous pages (4 L2 + 1 shadow).
 	 *  +-++-+
 	 * Physical layout: | 3 * USERLAND L2 | L2 KERN SHADOW | L2 KERN |
 	 *  +-++-+
-	 * However, we enter pdtpte[3] into L2 KERN, and not L2 KERN SHADOW.
-	 * This way, pde[L2_SLOT_KERN] always points to the shadow.
+	 * However, we enter L3[3] into L2 KERN, and not L2 KERN SHADOW.
+	 * This way, L2[L2_SLOT_KERN] always points to the shadow.
 	 */
-	pde = (pd_entry_t *)avail;
-	memset(pde, 0, PAGE_SIZE * 5);
+	L2 = (pd_entry_t *)avail;
+	memset(L2, 0, PAGE_SIZE * 5);
 	avail += PAGE_SIZE * 5;
 
 	/*
 	 * Link L2 pages 

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

2018-07-27 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jul 27 10:04:22 UTC 2018

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

Log Message:
Try to reduce the confusion, rename:

l2_4_count   -> PDIRSZ
count-> nL2
bootstrap_tables -> our_tables
init_tables  -> xen_tables

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 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.79 src/sys/arch/xen/x86/x86_xpmap.c:1.80
--- src/sys/arch/xen/x86/x86_xpmap.c:1.79	Thu Jul 26 17:20:09 2018
+++ src/sys/arch/xen/x86/x86_xpmap.c	Fri Jul 27 10:04:22 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.79 2018/07/26 17:20:09 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.80 2018/07/27 10:04:22 maxv Exp $	*/
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.79 2018/07/26 17:20:09 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.80 2018/07/27 10:04:22 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -448,13 +448,14 @@ xpq_update_foreign(paddr_t ptr, pt_entry
 #endif
 
 #ifdef __x86_64__
-static const int l2_4_count = PTP_LEVELS;
+#define PDIRSZ	PTP_LEVELS
 #else
 /*
  * For PAE, we consider a single contiguous L2 "superpage" of 4 pages, all of
  * them mapped by the L3 page. We also need a shadow page for L3[3].
+ * XXX so why 6?
  */
-static const int l2_4_count = 6;
+#define PDIRSZ	6
 #endif
 
 /*
@@ -478,8 +479,8 @@ static const int l2_4_count = 6;
 vaddr_t
 xen_locore(void)
 {
-	size_t count, oldcount, mapsize;
-	vaddr_t bootstrap_tables, init_tables;
+	size_t nL2, oldcount, mapsize;
+	vaddr_t our_tables, xen_tables;
 	u_int descs[4];
 
 	xen_init_features();
@@ -492,16 +493,16 @@ xen_locore(void)
 	xpmap_pg_nx = (descs[3] & CPUID_NOX) ? PG_NX : 0;
 
 	/* Space after Xen boostrap tables should be free */
-	init_tables = xen_start_info.pt_base;
-	bootstrap_tables = init_tables +
-	(xen_start_info.nr_pt_frames * PAGE_SIZE);
+	xen_tables = xen_start_info.pt_base;
+	our_tables = xen_tables + (xen_start_info.nr_pt_frames * PAGE_SIZE);
 
 	/*
 	 * Calculate how much space we need. First, everything mapped before
 	 * the Xen bootstrap tables.
 	 */
-	mapsize = init_tables - KERNTEXTOFF;
-	/* after the tables we'll have:
+	mapsize = xen_tables - KERNTEXTOFF;
+
+	/* After the tables we'll have:
 	 *  - UAREA
 	 *  - dummy user PGD (x86_64)
 	 *  - HYPERVISOR_shared_info
@@ -524,18 +525,18 @@ xen_locore(void)
 	 * At this point, mapsize doesn't include the table size.
 	 */
 #ifdef __x86_64__
-	count = TABLE_L2_ENTRIES;
+	nL2 = TABLE_L2_ENTRIES;
 #else
-	count = (mapsize + (NBPD_L2 - 1)) >> L2_SHIFT;
+	nL2 = (mapsize + (NBPD_L2 - 1)) >> L2_SHIFT;
 #endif
 
 	/*
 	 * Now compute how many L2 pages we need exactly. This is useful only
 	 * on i386, since the initial count for amd64 is already enough.
 	 */
-	while (KERNTEXTOFF + mapsize + (count + l2_4_count) * PAGE_SIZE >
-	KERNBASE + (count << L2_SHIFT)) {
-		count++;
+	while (KERNTEXTOFF + mapsize + (nL2 + PDIRSZ) * PAGE_SIZE >
+	KERNBASE + (nL2 << L2_SHIFT)) {
+		nL2++;
 	}
 
 #ifdef i386
@@ -545,15 +546,15 @@ xen_locore(void)
 	 * counted here. It's not a big issue to allocate one more L2 as
 	 * pmap_growkernel() will be called anyway.
 	 */
-	count++;
-	nkptp[1] = count;
+	nL2++;
+	nkptp[1] = nL2;
 #endif
 
 	/*
 	 * Install bootstrap pages. We may need more L2 pages than will
 	 * have the final table here, as it's installed after the final table.
 	 */
-	oldcount = count;
+	oldcount = nL2;
 
 bootstrap_again:
 
@@ -561,36 +562,35 @@ bootstrap_again:
 	 * Xen space we'll reclaim may not be enough for our new page tables,
 	 * move bootstrap tables if necessary.
 	 */
-	if (bootstrap_tables < init_tables + ((count + l2_4_count) * PAGE_SIZE))
-		bootstrap_tables = init_tables +
-		((count + l2_4_count) * PAGE_SIZE);
+	if (our_tables < xen_tables + ((nL2 + PDIRSZ) * PAGE_SIZE))
+		our_tables = xen_tables + ((nL2 + PDIRSZ) * PAGE_SIZE);
 
 	/*
 	 * Make sure the number of L2 pages we have is enough to map everything
 	 * from KERNBASE to the bootstrap tables themselves.
 	 */
-	if (bootstrap_tables + ((oldcount + l2_4_count) * PAGE_SIZE) >
+	if (our_tables + ((oldcount + PDIRSZ) * PAGE_SIZE) >
 	KERNBASE + (oldcount << L2_SHIFT)) {
 		oldcount++;
 		goto bootstrap_again;
 	}
 
 	/* Create temporary tables */
-	xen_bootstrap_tables(init_tables, bootstrap_tables,
+	xen_bootstrap_tables(xen_tables, our_tables,
 	xen_start_info.nr_pt_frames, oldcount, false);
 
 	/* Create final tables */
-	xen_bootstrap_tables(bootstrap_tables, init_tables,
-	oldcount + l2_4_count, count, true);
+	xen_bootstrap_tables(our_tables, xen_tables,
+	oldcount + PDIRSZ, nL2, 

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

2018-07-27 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jul 27 09:37:31 UTC 2018

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

Log Message:
Reduce the size of the blocks. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 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.124 src/sys/arch/xen/x86/cpu.c:1.125
--- src/sys/arch/xen/x86/cpu.c:1.124	Thu Jul 26 17:20:09 2018
+++ src/sys/arch/xen/x86/cpu.c	Fri Jul 27 09:37:31 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.124 2018/07/26 17:20:09 maxv Exp $	*/
+/*	$NetBSD: cpu.c,v 1.125 2018/07/27 09:37:31 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.124 2018/07/26 17:20:09 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.125 2018/07/27 09:37:31 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -1114,6 +1114,7 @@ cpu_load_pmap(struct pmap *pmap, struct 
 {
 	struct cpu_info *ci = curcpu();
 	cpuid_t cid = cpu_index(ci);
+	int i;
 
 	KASSERT(pmap != pmap_kernel());
 
@@ -1121,51 +1122,41 @@ cpu_load_pmap(struct pmap *pmap, struct 
 	/* make new pmap visible to xen_kpm_sync() */
 	kcpuset_atomic_set(pmap->pm_xen_ptp_cpus, cid);
 
-#ifdef i386
-	{
-		int i;
-		paddr_t l3_pd = xpmap_ptom_masked(ci->ci_pae_l3_pdirpa);
-		/* don't update the kernel L3 slot */
-		for (i = 0 ; i < PDP_SIZE - 1; i++) {
-			xpq_queue_pte_update(l3_pd + i * sizeof(pd_entry_t),
-			xpmap_ptom(pmap->pm_pdirpa[i]) | PG_V);
-		}
-		tlbflush();
-	}
-#endif
-
 #ifdef __x86_64__
-	{
-		int i;
-		pd_entry_t *new_pgd;
-		paddr_t l4_pd_ma;
+	pd_entry_t *new_pgd;
+	paddr_t l4_pd_ma;
 
-		l4_pd_ma = xpmap_ptom_masked(ci->ci_kpm_pdirpa);
+	l4_pd_ma = xpmap_ptom_masked(ci->ci_kpm_pdirpa);
 
-		/*
-		 * Map user space address in kernel space and load
-		 * user cr3
-		 */
-		new_pgd = pmap->pm_pdir;
-		KASSERT(pmap == ci->ci_pmap);
+	/*
+	 * Map user space address in kernel space and load
+	 * user cr3
+	 */
+	new_pgd = pmap->pm_pdir;
+	KASSERT(pmap == ci->ci_pmap);
 
-		/* Copy user pmap L4 PDEs (in user addr. range) to per-cpu L4 */
-		for (i = 0; i < PDIR_SLOT_PTE; i++) {
-			KASSERT(pmap != pmap_kernel() || new_pgd[i] == 0);
-			if (ci->ci_kpm_pdir[i] != new_pgd[i]) {
-xpq_queue_pte_update(
-l4_pd_ma + i * sizeof(pd_entry_t),
-new_pgd[i]);
-			}
+	/* Copy user pmap L4 PDEs (in user addr. range) to per-cpu L4 */
+	for (i = 0; i < PDIR_SLOT_PTE; i++) {
+		KASSERT(pmap != pmap_kernel() || new_pgd[i] == 0);
+		if (ci->ci_kpm_pdir[i] != new_pgd[i]) {
+			xpq_queue_pte_update(l4_pd_ma + i * sizeof(pd_entry_t),
+			new_pgd[i]);
 		}
+	}
 
-		xen_set_user_pgd(pmap_pdirpa(pmap, 0));
-		ci->ci_xen_current_user_pgd = pmap_pdirpa(pmap, 0);
-
-		tlbflush();
+	xen_set_user_pgd(pmap_pdirpa(pmap, 0));
+	ci->ci_xen_current_user_pgd = pmap_pdirpa(pmap, 0);
+#else
+	paddr_t l3_pd = xpmap_ptom_masked(ci->ci_pae_l3_pdirpa);
+	/* don't update the kernel L3 slot */
+	for (i = 0; i < PDP_SIZE - 1; i++) {
+		xpq_queue_pte_update(l3_pd + i * sizeof(pd_entry_t),
+		xpmap_ptom(pmap->pm_pdirpa[i]) | PG_V);
 	}
 #endif
 
+	tlbflush();
+
 	/* old pmap no longer visible to xen_kpm_sync() */
 	if (oldpmap != pmap_kernel()) {
 		kcpuset_atomic_clear(oldpmap->pm_xen_ptp_cpus, cid);
@@ -1195,6 +1186,8 @@ cpu_load_pmap(struct pmap *pmap, struct 
 void
 pmap_cpu_init_late(struct cpu_info *ci)
 {
+	int i;
+
 	/*
 	 * The BP has already its own PD page allocated during early
 	 * MD startup.
@@ -1202,7 +1195,6 @@ pmap_cpu_init_late(struct cpu_info *ci)
 
 #ifdef __x86_64__
 	/* Setup per-cpu normal_pdes */
-	int i;
 	extern pd_entry_t * const normal_pdes[];
 	for (i = 0;i < PTP_LEVELS - 1;i++) {
 		ci->ci_normal_pdes[i] = normal_pdes[i];
@@ -1219,8 +1211,7 @@ pmap_cpu_init_late(struct cpu_info *ci)
 	KASSERT(ci->ci_pae_l3_pdirpa != 0);
 
 	/* Initialise L2 entries 0 - 2: Point them to pmap_kernel() */
-	int i;
-	for (i = 0 ; i < PDP_SIZE - 1; 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/x86

2018-07-27 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jul 27 09:22:40 UTC 2018

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

Log Message:
style, localify global variables, etc, no real functional change


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/xen/x86/xen_shm_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/xen_shm_machdep.c
diff -u src/sys/arch/xen/x86/xen_shm_machdep.c:1.11 src/sys/arch/xen/x86/xen_shm_machdep.c:1.12
--- src/sys/arch/xen/x86/xen_shm_machdep.c:1.11	Sun Jun 24 20:28:57 2018
+++ src/sys/arch/xen/x86/xen_shm_machdep.c	Fri Jul 27 09:22:40 2018
@@ -1,4 +1,4 @@
-/*  $NetBSD: xen_shm_machdep.c,v 1.11 2018/06/24 20:28:57 jdolecek Exp $  */
+/*  $NetBSD: xen_shm_machdep.c,v 1.12 2018/07/27 09:22:40 maxv Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -22,12 +22,10 @@
  * 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 
-__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.11 2018/06/24 20:28:57 jdolecek Exp $");
-
+__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.12 2018/07/27 09:22:40 maxv Exp $");
 
 #include 
 #include 
@@ -44,42 +42,37 @@ __KERNEL_RCSID(0, "$NetBSD: xen_shm_mach
 #include 
 
 /*
- * Helper routines for the backend drivers. This implement the necessary
- * functions to map a bunch of pages from foreign domains in our kernel VM
+ * Helper routines for the backend drivers. This implements the necessary
+ * functions to map a bunch of pages from foreign domains into our kernel VM
  * space, do I/O to it, and unmap it.
  *
  * At boot time, we grab some kernel VM space that we'll use to map the foreign
- * pages. We also maintain a virtual to machine mapping table to give back
+ * pages. We also maintain a virtual-to-machine mapping table to give back
  * the appropriate address to bus_dma if requested.
+ *
  * If no more VM space is available, we return an error. The caller can then
  * register a callback which will be called when the required VM space is
  * available.
  */
 
-/* pointers to our VM space */
-static vaddr_t xen_shm_base_address;
-static u_long xen_shm_base_address_pg;
-static vaddr_t xen_shm_end_address;
-
 /* Grab enough VM space to map an entire vbd ring. */
 /* Xen3 linux guests seems to eat more pages, gives enough for 10 vbd rings */
 #define BLKIF_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
 #define XENSHM_NPAGES (BLKIF_RING_SIZE * (BLKIF_MAX_SEGMENTS_PER_REQUEST + 1) * 10)
 
-static vsize_t xen_shm_size = (XENSHM_NPAGES * PAGE_SIZE);
-
 /* vm space management */
-static vmem_t *xen_shm_arena;
+static vmem_t *xen_shm_arena __read_mostly;
 
 /* callbacks are registered in a FIFO list. */
-
 static SIMPLEQ_HEAD(xen_shm_callback_head, xen_shm_callback_entry)
 xen_shm_callbacks;
+
 struct xen_shm_callback_entry {
 	SIMPLEQ_ENTRY(xen_shm_callback_entry) xshmc_entries;
 	int (*xshmc_callback)(void *); /* our callback */
 	void *xshmc_arg; /* cookie passed to the callback */
 };
+
 /* a pool of struct xen_shm_callback_entry */
 static struct pool xen_shm_callback_pool;
 
@@ -91,6 +84,11 @@ static struct timeval xen_shm_errintvl =
 void
 xen_shm_init(void)
 {
+	vaddr_t xen_shm_base_address;
+	vaddr_t xen_shm_end_address;
+	u_long xen_shm_base_address_pg;
+	vsize_t xen_shm_size;
+
 	SIMPLEQ_INIT(_shm_callbacks);
 	pool_init(_shm_callback_pool, sizeof(struct xen_shm_callback_entry),
 	0, 0, 0, "xshmc", NULL, IPL_VM);
@@ -100,6 +98,8 @@ xen_shm_init(void)
 		panic("xen_shm_init can't prime pool");
 	}
 
+	xen_shm_size = (XENSHM_NPAGES * PAGE_SIZE);
+
 	xen_shm_base_address = uvm_km_alloc(kernel_map, xen_shm_size, 0,
 	UVM_KMF_VAONLY);
 	xen_shm_end_address = xen_shm_base_address + xen_shm_size;
@@ -107,8 +107,7 @@ xen_shm_init(void)
 	if (xen_shm_base_address == 0) {
 		panic("xen_shm_init no VM space");
 	}
-	xen_shm_arena = vmem_create("xen_shm",
-	xen_shm_base_address_pg,
+	xen_shm_arena = vmem_create("xen_shm", xen_shm_base_address_pg,
 	(xen_shm_end_address >> PAGE_SHIFT) - 1 - xen_shm_base_address_pg,
 	1, NULL, NULL, NULL, 1, VM_NOSLEEP, IPL_VM);
 	if (xen_shm_arena == NULL) {
@@ -120,45 +119,42 @@ int
 xen_shm_map(int nentries, int domid, grant_ref_t *grefp, vaddr_t *vap,
 grant_handle_t *handlep, int flags)
 {
-	int s, i;
-	vaddr_t new_va;
-	vmem_addr_t new_va_pg;
-	int err;
 	gnttab_map_grant_ref_t op[XENSHM_MAX_PAGES_PER_REQUEST];
+	vmem_addr_t new_va_pg;
+	vaddr_t new_va;
+	int ret, i, s;
 
 #ifdef DIAGNOSTIC
 	if (nentries > XENSHM_MAX_PAGES_PER_REQUEST) {
-		printf("xen_shm_map: %d entries\n", nentries);
-		panic("xen_shm_map");
+		panic("xen_shm_map: %d entries", nentries);
 	}
 #endif
+
 	/* XXXSMP */
 	s = splvm(); /* splvm is 

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

2018-07-26 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jul 26 15:06:14 UTC 2018

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

Log Message:
Remove dead code.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 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/xen/x86/xenfunc.c
diff -u src/sys/arch/xen/x86/xenfunc.c:1.18 src/sys/arch/xen/x86/xenfunc.c:1.19
--- src/sys/arch/xen/x86/xenfunc.c:1.18	Sun Jun 24 20:28:57 2018
+++ src/sys/arch/xen/x86/xenfunc.c	Thu Jul 26 15:06:14 2018
@@ -1,7 +1,6 @@
-/*	$NetBSD: xenfunc.c,v 1.18 2018/06/24 20:28:57 jdolecek Exp $	*/
+/*	$NetBSD: xenfunc.c,v 1.19 2018/07/26 15:06:14 maxv Exp $	*/
 
 /*
- *
  * Copyright (c) 2004 Christian Limpach.
  * All rights reserved.
  *
@@ -27,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.18 2018/06/24 20:28:57 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.19 2018/07/26 15:06:14 maxv Exp $");
 
 #include 
 
@@ -42,12 +41,6 @@ __KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 
 #include 
 #include 
 
-#ifdef XENDEBUG_LOW
-#define	__PRINTK(x) printk x
-#else
-#define	__PRINTK(x)
-#endif
-
 void xen_set_ldt(vaddr_t, uint32_t);
 
 void 
@@ -68,7 +61,6 @@ lldt(u_short sel)
 
 	if (ci->ci_curldt == sel)
 		return;
-	/* __PRINTK(("ldt %x\n", IDXSELN(sel))); */
 	if (sel == GSEL(GLDT_SEL, SEL_KPL))
 		xen_set_ldt((vaddr_t)ldtstore, NLDT);
 	else



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

2018-07-26 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jul 26 08:18:25 UTC 2018

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

Log Message:
Merge the blocks. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 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.76 src/sys/arch/xen/x86/x86_xpmap.c:1.77
--- src/sys/arch/xen/x86/x86_xpmap.c:1.76	Thu Jul 26 08:08:24 2018
+++ src/sys/arch/xen/x86/x86_xpmap.c	Thu Jul 26 08:18:25 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.76 2018/07/26 08:08:24 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.77 2018/07/26 08:18:25 maxv Exp $	*/
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.76 2018/07/26 08:08:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.77 2018/07/26 08:18:25 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -693,11 +693,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	addr = ((u_long)pdtpe) - KERNBASE;
 	bt_pgd[pl4_pi(KERNTEXTOFF)] = bt_cpu_pgd[pl4_pi(KERNTEXTOFF)] =
 	xpmap_ptom_masked(addr) | PG_V | PG_RW;
-#else
-	pdtpe = bt_pgd;
-#endif
 
-#ifdef __x86_64__
 	/* Level 2 */
 	pde = (pd_entry_t *)avail;
 	memset(pde, 0, PAGE_SIZE);
@@ -707,6 +703,8 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	pdtpe[pl3_pi(KERNTEXTOFF)] =
 	xpmap_ptom_masked(addr) | PG_V | PG_RW;
 #elif defined(PAE)
+	pdtpe = bt_pgd;
+
 	/*
 	 * Our PAE-style level 2, 5 contiguous pages (4 L2 + 1 shadow).
 	 *  +-++-+
@@ -730,6 +728,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	addr += PAGE_SIZE;
 	pdtpe[3] = xpmap_ptom_masked(addr) | PG_V;
 #else
+	pdtpe = bt_pgd;
 	pde = bt_pgd;
 #endif
 



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

2018-07-26 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jul 26 08:08:24 UTC 2018

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

Log Message:
Simplify the conditions; (PTP_LEVELS > 3) and (PTP_LEVELS > 2) are for
amd64, so use ifdef __x86_64__. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 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.75 src/sys/arch/xen/x86/x86_xpmap.c:1.76
--- src/sys/arch/xen/x86/x86_xpmap.c:1.75	Sun Jun 24 20:28:57 2018
+++ src/sys/arch/xen/x86/x86_xpmap.c	Thu Jul 26 08:08:24 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.75 2018/06/24 20:28:57 jdolecek Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.76 2018/07/26 08:08:24 maxv Exp $	*/
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.75 2018/06/24 20:28:57 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.76 2018/07/26 08:08:24 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -677,7 +677,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	memset(bt_pgd, 0, PAGE_SIZE);
 	avail = new_pgd + PAGE_SIZE;
 
-#if PTP_LEVELS > 3
+#ifdef __x86_64__
 	/* Per-cpu L4 */
 	pd_entry_t *bt_cpu_pgd = bt_pgd;
 	/* pmap_kernel() "shadow" L4 */
@@ -697,7 +697,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	pdtpe = bt_pgd;
 #endif
 
-#if PTP_LEVELS > 2
+#ifdef __x86_64__
 	/* Level 2 */
 	pde = (pd_entry_t *)avail;
 	memset(pde, 0, PAGE_SIZE);
@@ -849,8 +849,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 		addr = (u_long)pde - KERNBASE + 3 * PAGE_SIZE;
 		xpq_queue_pin_l2_table(xpmap_ptom_masked(addr));
 	}
-#else /* PAE */
-
+#else
 	/* Recursive entry in pmap_kernel(). */
 	bt_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_pgd - KERNBASE)
 	| PG_RO | PG_V | xpmap_pg_nx;
@@ -862,12 +861,12 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 
 	/* Mark tables RO */
 	xen_bt_set_readonly((vaddr_t)pde);
-#endif /* PAE */
+#endif
 
-#if PTP_LEVELS > 2 || defined(PAE)
+#if defined(__x86_64__) || defined(PAE)
 	xen_bt_set_readonly((vaddr_t)pdtpe);
 #endif
-#if PTP_LEVELS > 3
+#ifdef __x86_64__
 	xen_bt_set_readonly(new_pgd);
 #endif
 



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

2018-07-24 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Jul 24 12:26:14 UTC 2018

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

Log Message:
Fix what looks like a typo in xen_send_ipi():
ci != NULL || ci != curcpu()
is always true


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 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.25 src/sys/arch/xen/x86/xen_ipi.c:1.26
--- src/sys/arch/xen/x86/xen_ipi.c:1.25	Sun Jun 24 13:35:32 2018
+++ src/sys/arch/xen/x86/xen_ipi.c	Tue Jul 24 12:26:14 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.25 2018/06/24 13:35:32 jdolecek Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.26 2018/07/24 12:26:14 bouyer 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.25 2018/06/24 13:35:32 jdolecek Exp $");
+ * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.26 2018/07/24 12:26:14 bouyer Exp $");
  */
 
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.25 2018/06/24 13:35:32 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.26 2018/07/24 12:26:14 bouyer Exp $");
 
 #include "opt_ddb.h"
 
@@ -168,7 +168,7 @@ xen_send_ipi(struct cpu_info *ci, uint32
 {
 	evtchn_port_t evtchn;
 
-	KASSERT(ci != NULL || ci != curcpu());
+	KASSERT(ci != NULL && ci != curcpu());
 
 	if ((ci->ci_flags & CPUF_RUNNING) == 0) {
 		return ENOENT;



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

2018-07-24 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Jul 24 12:24:45 UTC 2018

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

Log Message:
Sync cpu_boot_secondary_processors() with x86/x86/cpu.c:
explicitely wait for all CPUs to be registered in kcpuset_running.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 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.122 src/sys/arch/xen/x86/cpu.c:1.123
--- src/sys/arch/xen/x86/cpu.c:1.122	Sat Jun 23 10:30:22 2018
+++ src/sys/arch/xen/x86/cpu.c	Tue Jul 24 12:24:45 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.122 2018/06/23 10:30:22 jdolecek Exp $	*/
+/*	$NetBSD: cpu.c,v 1.123 2018/07/24 12:24:45 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.122 2018/06/23 10:30:22 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.123 2018/07/24 12:24:45 bouyer Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -583,7 +583,11 @@ void
 cpu_boot_secondary_processors(void)
 {
 	struct cpu_info *ci;
+	kcpuset_t *cpus;
 	u_long i;
+
+	kcpuset_create(, true);
+	kcpuset_set(cpus, cpu_index(curcpu()));
 	for (i = 0; i < maxcpus; i++) {
 		ci = cpu_lookup(i);
 		if (ci == NULL)
@@ -595,7 +599,11 @@ cpu_boot_secondary_processors(void)
 		if (ci->ci_flags & (CPUF_BSP|CPUF_SP|CPUF_PRIMARY))
 			continue;
 		cpu_boot_secondary(ci);
+		kcpuset_set(cpus, cpu_index(ci));
 	}
+	while (!kcpuset_match(cpus, kcpuset_running))
+		;
+	kcpuset_destroy(cpus);
 
 	x86_mp_online = true;
 }



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

2018-06-23 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Jun 23 15:53:14 UTC 2018

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

Log Message:
make compile without DDB

PR port-xen/50282


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 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.23 src/sys/arch/xen/x86/xen_ipi.c:1.24
--- src/sys/arch/xen/x86/xen_ipi.c:1.23	Mon Nov  6 15:27:09 2017
+++ src/sys/arch/xen/x86/xen_ipi.c	Sat Jun 23 15:53:14 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.23 2017/11/06 15:27:09 cherry Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.24 2018/06/23 15:53:14 jdolecek Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -33,10 +33,12 @@
 
 /* 
  * Based on: x86/ipi.c
- * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.23 2017/11/06 15:27:09 cherry Exp $");
+ * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.24 2018/06/23 15:53:14 jdolecek Exp $");
  */
 
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.23 2017/11/06 15:27:09 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.24 2018/06/23 15:53:14 jdolecek Exp $");
+
+#include "opt_ddb.h"
 
 #include 
 
@@ -59,11 +61,13 @@ __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 
 #include 
 #include 
 
+#ifdef DDB
 extern void ddb_ipi(struct trapframe);
+static void xen_ipi_ddb(struct cpu_info *, struct intrframe *);
+#endif
 
 static void xen_ipi_halt(struct cpu_info *, struct intrframe *);
 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 xen_ipi_generic(struct cpu_info *, struct intrframe *);
@@ -72,7 +76,11 @@ static void (*ipifunc[XEN_NIPIS])(struct
 {	/* In order of priority (see: xen/include/intrdefs.h */
 	xen_ipi_halt,
 	xen_ipi_synch_fpu,
+#ifdef DDB
 	xen_ipi_ddb,
+#else
+	NULL,
+#endif
 	xen_ipi_xcall,
 	xen_ipi_hvcb,
 	xen_ipi_generic,
@@ -229,6 +237,7 @@ xen_ipi_synch_fpu(struct cpu_info *ci, s
 	fpusave_cpu(true);
 }
 
+#ifdef DDB
 static void
 xen_ipi_ddb(struct cpu_info *ci, struct intrframe *intrf)
 {
@@ -260,6 +269,7 @@ xen_ipi_ddb(struct cpu_info *ci, struct 
 	ddb_ipi(tf);
 #endif
 }
+#endif /* DDB */
 
 static void
 xen_ipi_xcall(struct cpu_info *ci, struct intrframe *intrf)



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

2018-01-13 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sat Jan 13 14:48:13 UTC 2018

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

Log Message:
Needs cpu_init_tss() for application processor too.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 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.116 src/sys/arch/xen/x86/cpu.c:1.117
--- src/sys/arch/xen/x86/cpu.c:1.116	Sat Nov 11 11:00:47 2017
+++ src/sys/arch/xen/x86/cpu.c	Sat Jan 13 14:48:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.116 2017/11/11 11:00:47 maxv Exp $	*/
+/*	$NetBSD: cpu.c,v 1.117 2018/01/13 14:48:13 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.116 2017/11/11 11:00:47 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.117 2018/01/13 14:48:13 bouyer Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -379,6 +379,7 @@ cpu_attach_common(device_t parent, devic
 		KM_SLEEP);
 		ci = (struct cpu_info *)roundup2(ptr, CACHE_LINE_SIZE);
 		memset(ci, 0, sizeof(*ci));
+		cpu_init_tss(ci);
 	} else {
 		aprint_naive(": %s Processor\n",
 		caa->cpu_role == CPU_ROLE_SP ? "Single" : "Boot");



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

2017-11-10 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Nov 11 06:16:52 UTC 2017

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

Log Message:
No externs in .c files!


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 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.113 src/sys/arch/xen/x86/cpu.c:1.114
--- src/sys/arch/xen/x86/cpu.c:1.113	Wed Nov  8 17:52:22 2017
+++ src/sys/arch/xen/x86/cpu.c	Sat Nov 11 06:16:52 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.113 2017/11/08 17:52:22 maxv Exp $	*/
+/*	$NetBSD: cpu.c,v 1.114 2017/11/11 06:16:52 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.113 2017/11/08 17:52:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.114 2017/11/11 06:16:52 riastradh Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -89,6 +89,7 @@ __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.11
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -525,7 +526,6 @@ cpu_attach_common(device_t parent, devic
 void
 cpu_init(struct cpu_info *ci)
 {
-	extern int x86_fpu_save;
 
 	/*
 	 * If we have FXSAVE/FXRESTOR, use them.



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

2017-07-06 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Jul  6 20:26:05 UTC 2017

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

Log Message:
gdt_prepframes() is called with a number of pages, don't convert to a number
of pages again. This didn't fail because we're called with only one page, and
the conversion from '1' to pages resulted in 1 again.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 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.110 src/sys/arch/xen/x86/cpu.c:1.111
--- src/sys/arch/xen/x86/cpu.c:1.110	Thu Mar 23 18:08:06 2017
+++ src/sys/arch/xen/x86/cpu.c	Thu Jul  6 20:26:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.110 2017/03/23 18:08:06 maxv Exp $	*/
+/*	$NetBSD: cpu.c,v 1.111 2017/07/06 20:26:05 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.110 2017/03/23 18:08:06 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.111 2017/07/06 20:26:05 bouyer Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -762,7 +762,7 @@ static void
 gdt_prepframes(paddr_t *frames, vaddr_t base, uint32_t entries)
 {
 	int i;
-	for (i = 0; i < roundup(entries, PAGE_SIZE) >> PAGE_SHIFT; i++) {
+	for (i = 0; i < entries; i++) {
 		frames[i] = ((paddr_t)xpmap_ptetomach(
 		(pt_entry_t *)(base + (i << PAGE_SHIFT >> PAGE_SHIFT;
 



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

2017-03-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Mar 18 13:35:57 UTC 2017

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

Log Message:
Style, and remove debug code that does not work anyway.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 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.72 src/sys/arch/xen/x86/x86_xpmap.c:1.73
--- src/sys/arch/xen/x86/x86_xpmap.c:1.72	Wed Mar  8 18:00:49 2017
+++ src/sys/arch/xen/x86/x86_xpmap.c	Sat Mar 18 13:35:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.72 2017/03/08 18:00:49 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.73 2017/03/18 13:35:57 maxv Exp $	*/
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.72 2017/03/08 18:00:49 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.73 2017/03/18 13:35:57 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -119,11 +119,8 @@ __KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,
 
 #ifdef XENDEBUG
 #define	XENPRINTF(x) printf x
-#define	XENPRINTK2(x) /* printk x */
-static char XBUF[256];
 #else
 #define	XENPRINTF(x)
-#define	XENPRINTK2(x)
 #endif
 
 /* Xen requires the start_info struct to be page aligned */
@@ -139,10 +136,6 @@ pt_entry_t xpmap_pg_nx __read_mostly;
 static mmu_update_t xpq_queue_array[MAXCPUS][XPQUEUE_SIZE];
 static int xpq_idx_array[MAXCPUS];
 
-#ifdef XENDEBUG
-void xpq_debug_dump(void);
-#endif
-
 void xen_failsafe_handler(void);
 
 extern volatile struct xencons_interface *xencons_interface; /* XXX */
@@ -203,46 +196,26 @@ void
 xpq_flush_queue(void)
 {
 	mmu_update_t *xpq_queue;
-	int i, ok = 0, ret, xpq_idx;
+	int done = 0, ret, xpq_idx;
 
 	xpq_idx = xpq_idx_array[curcpu()->ci_cpuid];
 	xpq_queue = xpq_queue_array[curcpu()->ci_cpuid];
 
 retry:
-	ret = HYPERVISOR_mmu_update(xpq_queue, xpq_idx, , DOMID_SELF);
-
-	if (xpq_idx != 0 && ret < 0) {
-		struct cpu_info *ci;
-		CPU_INFO_ITERATOR cii;
+	ret = HYPERVISOR_mmu_update(xpq_queue, xpq_idx, , DOMID_SELF);
 
+	if (ret < 0 && xpq_idx != 0) {
 		printf("xpq_flush_queue: %d entries (%d successful) on "
 		"cpu%d (%ld)\n",
-		xpq_idx, ok, curcpu()->ci_index, curcpu()->ci_cpuid);
+		xpq_idx, done, curcpu()->ci_index, curcpu()->ci_cpuid);
 
-		if (ok != 0) {
-			xpq_queue += ok;
-			xpq_idx -= ok;
-			ok = 0;
+		if (done != 0) {
+			xpq_queue += done;
+			xpq_idx -= done;
+			done = 0;
 			goto retry;
 		}
 
-		for (CPU_INFO_FOREACH(cii, ci)) {
-			xpq_queue = xpq_queue_array[ci->ci_cpuid];
-			xpq_idx = xpq_idx_array[ci->ci_cpuid];
-			printf("cpu%d (%ld):\n", ci->ci_index, ci->ci_cpuid);
-			for (i = 0; i < xpq_idx; i++) {
-printf("  0x%016" PRIx64 ": 0x%016" PRIx64 "\n",
-   xpq_queue[i].ptr, xpq_queue[i].val);
-			}
-#ifdef __x86_64__
-			for (i = 0; i < PDIR_SLOT_PTE; i++) {
-if (ci->ci_kpm_pdir[i] == 0)
-	continue;
-printf(" kpm_pdir[%d]: 0x%" PRIx64 "\n",
-i, ci->ci_kpm_pdir[i]);
-			}
-#endif
-		}
 		panic("HYPERVISOR_mmu_update failed, ret: %d\n", ret);
 	}
 	xpq_idx_array[curcpu()->ci_cpuid] = 0;
@@ -288,7 +261,7 @@ xpq_queue_pt_switch(paddr_t pa)
 	op.cmd = MMUEXT_NEW_BASEPTR;
 	op.arg1.mfn = pa >> PAGE_SHIFT;
 	if (HYPERVISOR_mmuext_op(, 1, NULL, DOMID_SELF) < 0)
-		panic("xpq_queue_pt_switch");
+		panic(__func__);
 }
 
 void
@@ -298,10 +271,10 @@ xpq_queue_pin_table(paddr_t pa, int lvl)
 
 	xpq_flush_queue();
 
-	op.arg1.mfn = pa >> PAGE_SHIFT;
 	op.cmd = lvl;
+	op.arg1.mfn = pa >> PAGE_SHIFT;
 	if (HYPERVISOR_mmuext_op(, 1, NULL, DOMID_SELF) < 0)
-		panic("xpq_queue_pin_table");
+		panic(__func__);
 }
 
 void
@@ -311,10 +284,10 @@ xpq_queue_unpin_table(paddr_t pa)
 
 	xpq_flush_queue();
 
-	op.arg1.mfn = pa >> PAGE_SHIFT;
 	op.cmd = MMUEXT_UNPIN_TABLE;
+	op.arg1.mfn = pa >> PAGE_SHIFT;
 	if (HYPERVISOR_mmuext_op(, 1, NULL, DOMID_SELF) < 0)
-		panic("xpq_queue_unpin_table");
+		panic(__func__);
 }
 
 void
@@ -329,7 +302,7 @@ xpq_queue_set_ldt(vaddr_t va, uint32_t e
 	op.arg1.linear_addr = va;
 	op.arg2.nr_ents = entries;
 	if (HYPERVISOR_mmuext_op(, 1, NULL, DOMID_SELF) < 0)
-		panic("xpq_queue_set_ldt");
+		panic(__func__);
 }
 
 void
@@ -341,7 +314,7 @@ xpq_queue_tlb_flush(void)
 
 	op.cmd = MMUEXT_TLB_FLUSH_LOCAL;
 	if (HYPERVISOR_mmuext_op(, 1, NULL, DOMID_SELF) < 0)
-		panic("xpq_queue_tlb_flush");
+		panic(__func__);
 }
 
 void
@@ -365,7 +338,7 @@ xpq_queue_invlpg(vaddr_t va)
 	op.cmd = MMUEXT_INVLPG_LOCAL;
 	op.arg1.linear_addr = (va & ~PAGE_MASK);
 	if (HYPERVISOR_mmuext_op(, 1, NULL, DOMID_SELF) < 0)
-		panic("xpq_queue_invlpg");
+		panic(__func__);
 }
 
 void
@@ -383,7 +356,7 @@ xen_mcast_invlpg(vaddr_t va, kcpuset_t *
 	op.arg2.vcpumask = _xm;
 
 	if (HYPERVISOR_mmuext_op(, 1, NULL, DOMID_SELF) < 0)
-		panic("xpq_queue_invlpg_all");
+		panic(__func__);
 }
 
 void

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

2017-01-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Jan 22 19:42:48 UTC 2017

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

Log Message:
Import xpmap_pg_nx, and put it in the per-cpu recursive slot on amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 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.105 src/sys/arch/xen/x86/cpu.c:1.106
--- src/sys/arch/xen/x86/cpu.c:1.105	Fri Nov 25 12:20:03 2016
+++ src/sys/arch/xen/x86/cpu.c	Sun Jan 22 19:42:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.105 2016/11/25 12:20:03 maxv Exp $	*/
+/*	$NetBSD: cpu.c,v 1.106 2017/01/22 19:42:48 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.105 2016/11/25 12:20:03 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.106 2017/01/22 19:42:48 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -1218,20 +1218,19 @@ pmap_cpu_init_late(struct cpu_info *ci)
 	KASSERT(ci->ci_kpm_pdirpa != 0);
 
 #if defined(__x86_64__)
-	/*
-	 * Copy over the pmap_kernel() shadow L4 entries 
-	 */
+	extern pt_entry_t xpmap_pg_nx;
 
+	/* Copy over the pmap_kernel() shadow L4 entries */
 	memcpy(ci->ci_kpm_pdir, pmap_kernel()->pm_pdir, PAGE_SIZE);
 
 	/* Recursive kernel mapping */
 	ci->ci_kpm_pdir[PDIR_SLOT_PTE] = xpmap_ptom_masked(ci->ci_kpm_pdirpa)
-	| PG_k | PG_V;
+	| PG_k | PG_V | xpmap_pg_nx;
 #elif defined(PAE)
-	/* Copy over the pmap_kernel() shadow L2 entries that map the kernel */
+	/* Copy over the pmap_kernel() shadow L2 entries */
 	memcpy(ci->ci_kpm_pdir, pmap_kernel()->pm_pdir + PDIR_SLOT_KERN,
 	nkptp[PTP_LEVELS - 1] * sizeof(pd_entry_t));
-#endif /* __x86_64__ else PAE */
+#endif
 
 	/* Xen wants a RO pdir. */
 	pmap_protect(pmap_kernel(), (vaddr_t)ci->ci_kpm_pdir,



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

2017-01-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Jan 22 19:24:52 UTC 2017

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

Log Message:
Export xpmap_pg_nx, and put it in the page table pages. It does not change
anything, since Xen removes the X bit on these; but it is better for
consistency.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 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.69 src/sys/arch/xen/x86/x86_xpmap.c:1.70
--- src/sys/arch/xen/x86/x86_xpmap.c:1.69	Fri Jan  6 08:32:26 2017
+++ src/sys/arch/xen/x86/x86_xpmap.c	Sun Jan 22 19:24:51 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.69 2017/01/06 08:32:26 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.70 2017/01/22 19:24:51 maxv Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.69 2017/01/06 08:32:26 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.70 2017/01/22 19:24:51 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -105,6 +105,8 @@ unsigned long *xpmap_phys_to_machine_map
 kmutex_t pte_lock;
 vaddr_t xen_dummy_page;
 
+pt_entry_t xpmap_pg_nx;
+
 void xen_failsafe_handler(void);
 
 #define HYPERVISOR_mmu_update_self(req, count, success_count) \
@@ -609,6 +611,7 @@ xen_locore(void)
 {
 	size_t count, oldcount, mapsize;
 	vaddr_t bootstrap_tables, init_tables;
+	u_int descs[4];
 
 	xen_init_features();
 
@@ -617,6 +620,10 @@ xen_locore(void)
 	xpmap_phys_to_machine_mapping =
 	(unsigned long *)xen_start_info.mfn_list;
 
+	/* Set the NX/XD bit, if available. descs[3] = %edx. */
+	x86_cpuid(0x8001, descs);
+	xpmap_pg_nx = (descs[3] & CPUID_NOX) ? PG_NX : 0;
+
 	/* Space after Xen boostrap tables should be free */
 	init_tables = xen_start_info.pt_base;
 	bootstrap_tables = init_tables +
@@ -738,14 +745,6 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	extern char __data_start;
 	extern char __kernel_end;
 	extern char *early_zerop; /* from pmap.c */
-	pt_entry_t pg_nx;
-	u_int descs[4];
-
-	/*
-	 * Set the NX/XD bit, if available. descs[3] = %edx.
-	 */
-	x86_cpuid(0x8001, descs);
-	pg_nx = (descs[3] & CPUID_NOX) ? PG_NX : 0;
 
 	/*
 	 * Layout of RW area after the kernel image:
@@ -895,7 +894,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 			page < (vaddr_t)atdevbase + IOM_SIZE) {
 pte[pl1_pi(page)] =
 IOM_BEGIN + (page - (vaddr_t)atdevbase);
-pte[pl1_pi(page)] |= pg_nx;
+pte[pl1_pi(page)] |= xpmap_pg_nx;
 			}
 #endif
 
@@ -906,15 +905,15 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 			} else if (page >= (vaddr_t)&__rodata_start &&
 			page < (vaddr_t)&__data_start) {
 /* Map the kernel rodata R. */
-pte[pl1_pi(page)] |= PG_RO | pg_nx;
+pte[pl1_pi(page)] |= PG_RO | xpmap_pg_nx;
 			} else if (page >= old_pgd &&
 			page < old_pgd + (old_count * PAGE_SIZE)) {
 /* Map the old page tables R. */
-pte[pl1_pi(page)] |= PG_RO | pg_nx;
+pte[pl1_pi(page)] |= PG_RO | xpmap_pg_nx;
 			} else if (page >= new_pgd &&
 			page < new_pgd + ((new_count + l2_4_count) * PAGE_SIZE)) {
 /* Map the new page tables R. */
-pte[pl1_pi(page)] |= PG_RO | pg_nx;
+pte[pl1_pi(page)] |= PG_RO | xpmap_pg_nx;
 #ifdef i386
 			} else if (page == (vaddr_t)tmpgdt) {
 /*
@@ -928,10 +927,10 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 			} else if (page >= (vaddr_t)&__data_start &&
 			page < (vaddr_t)&__kernel_end) {
 /* Map the kernel data+bss RW. */
-pte[pl1_pi(page)] |= PG_RW | pg_nx;
+pte[pl1_pi(page)] |= PG_RW | xpmap_pg_nx;
 			} else {
 /* Map the page RW. */
-pte[pl1_pi(page)] |= PG_RW | pg_nx;
+pte[pl1_pi(page)] |= PG_RW | xpmap_pg_nx;
 			}
 
 			page += PAGE_SIZE;
@@ -962,7 +961,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	addr = (u_long)pde - KERNBASE;
 	for (i = 0; i < 3; i++, addr += PAGE_SIZE) {
 		pde[PDIR_SLOT_PTE + i] = xpmap_ptom_masked(addr) | PG_k | PG_V |
-		pg_nx;
+		xpmap_pg_nx;
 	}
 
 	/* Mark tables RO, and pin L2 KERN SHADOW. */
@@ -978,11 +977,11 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 
 	/* Recursive entry in pmap_kernel(). */
 	bt_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_pgd - KERNBASE)
-	| PG_k | PG_RO | PG_V | pg_nx;
+	| PG_k | PG_RO | PG_V | xpmap_pg_nx;
 #ifdef __x86_64__
 	/* Recursive entry in higher-level per-cpu PD. */
 	bt_cpu_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_cpu_pgd - KERNBASE)
-	| PG_k | PG_RO | PG_V | pg_nx;
+	| PG_k | PG_RO | PG_V | xpmap_pg_nx;
 #endif
 
 	/* Mark tables RO */
@@ -1061,23 +1060,16 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	xpq_flush_queue();
 }
 
-
 /*
- * Bootstrap helper functions
+ * Mark a page read-only, assuming vaddr = paddr + KERNBASE.
  */
-
-/*
- * Mark a page readonly
- * XXX: 

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

2017-01-06 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan  6 08:32:26 UTC 2017

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

Log Message:
Remove a few #if 0s, and explain what we are doing on PAE: the last two PAs
are entered in reversed order.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 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.68 src/sys/arch/xen/x86/x86_xpmap.c:1.69
--- src/sys/arch/xen/x86/x86_xpmap.c:1.68	Fri Dec 16 19:52:22 2016
+++ src/sys/arch/xen/x86/x86_xpmap.c	Fri Jan  6 08:32:26 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.68 2016/12/16 19:52:22 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.69 2017/01/06 08:32:26 maxv Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.68 2016/12/16 19:52:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.69 2017/01/06 08:32:26 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -664,7 +664,7 @@ xen_locore(void)
 		count++;
 	}
 
-#ifndef __x86_64__
+#ifdef i386
 	/*
 	 * One more L2 page: we'll allocate several pages after kva_start
 	 * in pmap_bootstrap() before pmap_growkernel(), which have not been
@@ -832,21 +832,24 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	pdtpe[pl3_pi(KERNTEXTOFF)] =
 	xpmap_ptom_masked(addr) | PG_k | PG_V | PG_RW;
 #elif defined(PAE)
-	/* Our PAE-style level 2: 5 contigous pages (4 L2 + 1 shadow) */
+	/*
+	 * Our PAE-style level 2, 5 contiguous pages (4 L2 + 1 shadow).
+	 *  +-++-+
+	 * Physical layout: | 3 * USERLAND L2 | L2 KERN SHADOW | L2 KERN |
+	 *  +-++-+
+	 * However, we enter pdtpte[3] into L2 KERN, and not L2 KERN SHADOW.
+	 * This way, pde[L2_SLOT_KERN] always points to the shadow.
+	 */
 	pde = (pd_entry_t *)avail;
 	memset(pde, 0, PAGE_SIZE * 5);
 	avail += PAGE_SIZE * 5;
-	addr = ((u_long)pde) - KERNBASE;
 
 	/*
-	 * Enter L2 pages in L3. The real L2 kernel PD will be the last one
-	 * (so that pde[L2_SLOT_KERN] always points to the shadow).
+	 * Link L2 pages in L3, with a special case for L2 KERN. Xen doesn't
+	 * want RW permissions in L3 entries, it'll add them itself.
 	 */
+	addr = ((u_long)pde) - KERNBASE;
 	for (i = 0; i < 3; i++, addr += PAGE_SIZE) {
-		/*
-		 * Xen doesn't want RW mappings in L3 entries, it'll add it
-		 * itself.
-		 */
 		pdtpe[i] = xpmap_ptom_masked(addr) | PG_k | PG_V;
 	}
 	addr += PAGE_SIZE;
@@ -944,15 +947,11 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 
 	/* Install recursive page tables mapping */
 #ifdef PAE
-	/*
-	 * We need a shadow page for the kernel's L2 page.
-	 * The real L2 kernel PD will be the last one (so that
-	 * pde[L2_SLOT_KERN] always points to the shadow).
-	 */
+	/* Copy L2 KERN into L2 KERN SHADOW, and reference the latter in cpu0. */
 	memcpy([L2_SLOT_KERN + NPDPG], [L2_SLOT_KERN], PAGE_SIZE);
 	cpu_info_primary.ci_kpm_pdir = [L2_SLOT_KERN + NPDPG];
 	cpu_info_primary.ci_kpm_pdirpa =
-	(vaddr_t) cpu_info_primary.ci_kpm_pdir - KERNBASE;
+	(vaddr_t)cpu_info_primary.ci_kpm_pdir - KERNBASE;
 
 	/*
 	 * We don't enter a recursive entry from the L3 PD. Instead, we enter
@@ -965,28 +964,16 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 		pde[PDIR_SLOT_PTE + i] = xpmap_ptom_masked(addr) | PG_k | PG_V |
 		pg_nx;
 	}
-#if 0
-	addr += PAGE_SIZE; /* point to shadow L2 */
-	pde[PDIR_SLOT_PTE + 3] = xpmap_ptom_masked(addr) | PG_k | PG_V;
-#endif
-	/* Mark tables RO, and pin the kernel's shadow as L2 */
+
+	/* Mark tables RO, and pin L2 KERN SHADOW. */
 	addr = (u_long)pde - KERNBASE;
 	for (i = 0; i < 5; i++, addr += PAGE_SIZE) {
 		xen_bt_set_readonly(((vaddr_t)pde) + PAGE_SIZE * i);
-#if 0
-		if (i == 2 || i == 3)
-			continue;
-		xpq_queue_pin_l2_table(xpmap_ptom_masked(addr));
-#endif
 	}
 	if (final) {
 		addr = (u_long)pde - KERNBASE + 3 * PAGE_SIZE;
 		xpq_queue_pin_l2_table(xpmap_ptom_masked(addr));
 	}
-#if 0
-	addr = (u_long)pde - KERNBASE + 2 * PAGE_SIZE;
-	xpq_queue_pin_l2_table(xpmap_ptom_masked(addr));
-#endif
 #else /* PAE */
 
 	/* Recursive entry in pmap_kernel(). */
@@ -1000,7 +987,8 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 
 	/* Mark tables RO */
 	xen_bt_set_readonly((vaddr_t)pde);
-#endif
+#endif /* PAE */
+
 #if PTP_LEVELS > 2 || defined(PAE)
 	xen_bt_set_readonly((vaddr_t)pdtpe);
 #endif



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

2016-12-26 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Dec 26 08:53:11 UTC 2016

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

Log Message:
In the MP case,
do not attempt to pmap_tlb_shootdown() after a pmap_kenter_ma() during
boot. pmap_tlb_shootdown() assumes post boot. Instead invalidate the
entry on the local CPU only.

XXX: to DTRT, probably this assumption needs re-examination.
XXX: The tradeoff is a (predicted) single word size comparison
 penalty, so perhaps a decision needs performance stats.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/xen/x86/xen_pmap.c

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

Modified files:

Index: src/sys/arch/xen/x86/xen_pmap.c
diff -u src/sys/arch/xen/x86/xen_pmap.c:1.24 src/sys/arch/xen/x86/xen_pmap.c:1.25
--- src/sys/arch/xen/x86/xen_pmap.c:1.24	Tue Dec 13 10:54:27 2016
+++ src/sys/arch/xen/x86/xen_pmap.c	Mon Dec 26 08:53:11 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_pmap.c,v 1.24 2016/12/13 10:54:27 kamil Exp $	*/
+/*	$NetBSD: xen_pmap.c,v 1.25 2016/12/26 08:53:11 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -102,7 +102,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.24 2016/12/13 10:54:27 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.25 2016/12/26 08:53:11 cherry Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -188,9 +188,13 @@ pmap_kenter_ma(vaddr_t va, paddr_t ma, v
 
 	if (pmap_valid_entry(opte)) {
 #if defined(MULTIPROCESSOR)
-		kpreempt_disable();
-		pmap_tlb_shootdown(pmap_kernel(), va, opte, TLBSHOOT_KENTER);
-		kpreempt_enable();
+		if (__predict_false(x86_mp_online == false)) {
+			pmap_update_pg(va);
+		} else {
+			kpreempt_disable();
+			pmap_tlb_shootdown(pmap_kernel(), va, opte, TLBSHOOT_KENTER);
+			kpreempt_enable();
+		}
 #else
 		/* Don't bother deferring in the single CPU case. */
 		pmap_update_pg(va);



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

2016-11-25 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Nov 25 12:20:03 UTC 2016

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

Log Message:
KNF a little


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 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.104 src/sys/arch/xen/x86/cpu.c:1.105
--- src/sys/arch/xen/x86/cpu.c:1.104	Thu Jul  7 06:55:40 2016
+++ src/sys/arch/xen/x86/cpu.c	Fri Nov 25 12:20:03 2016
@@ -1,5 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.104 2016/07/07 06:55:40 msaitoh Exp $	*/
-/* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
+/*	$NetBSD: cpu.c,v 1.105 2016/11/25 12:20:03 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -66,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.104 2016/07/07 06:55:40 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.105 2016/11/25 12:20:03 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -294,8 +293,7 @@ vcpu_match(device_t parent, cfdata_t mat
 
 	if (strcmp(vcaa->vcaa_name, match->cf_name) == 0) {
 		error = HYPERVISOR_vcpu_op(VCPUOP_get_runstate_info,
-	   vcaa->vcaa_caa.cpu_number,
-	   );
+		vcaa->vcaa_caa.cpu_number, );
 		switch (error) {
 		case 0:
 			return 1;
@@ -341,7 +339,7 @@ cpu_vm_init(struct cpu_info *ci)
 		cai = >ci_cinfo[i];
 
 		tcolors = atop(cai->cai_totalsize);
-		switch(cai->cai_associativity) {
+		switch (cai->cai_associativity) {
 		case 0xff:
 			tcolors = 1; /* fully associative */
 			break;
@@ -465,14 +463,12 @@ cpu_attach_common(device_t parent, devic
 		atomic_or_32(>ci_flags, CPUF_SP);
 		cpu_identify(ci);
 		x86_cpu_idle_init();
-
 		break;
 
 	case CPU_ROLE_BP:
 		atomic_or_32(>ci_flags, CPUF_BSP);
 		cpu_identify(ci);
 		x86_cpu_idle_init();
-
 		break;
 
 	case CPU_ROLE_AP:
@@ -521,9 +517,9 @@ cpu_attach_common(device_t parent, devic
 		l,
 #ifdef i386
 		(void *)pcb->pcb_esp
-#else /* i386 */
+#else
 		(void *)pcb->pcb_rsp
-#endif /* i386 */
+#endif
 		);
 		
 	}
@@ -695,7 +691,7 @@ cpu_hatch(void *v)
 	xen_ipi_init();
 
 	xen_initclocks();
-	
+
 #ifdef __x86_64__
 	fpuinit(ci);
 #endif
@@ -764,10 +760,8 @@ gdt_prepframes(paddr_t *frames, vaddr_t 
 {
 	int i;
 	for (i = 0; i < roundup(entries, PAGE_SIZE) >> PAGE_SHIFT; i++) {
-
-		frames[i] = ((paddr_t) xpmap_ptetomach(
-(pt_entry_t *) (base + (i << PAGE_SHIFT
-			>> PAGE_SHIFT;
+		frames[i] = ((paddr_t)xpmap_ptetomach(
+		(pt_entry_t *)(base + (i << PAGE_SHIFT >> PAGE_SHIFT;
 
 		/* Mark Read-only */
 		pmap_pte_clearbits(kvtopte(base + (i << PAGE_SHIFT)),
@@ -779,9 +773,8 @@ gdt_prepframes(paddr_t *frames, vaddr_t 
 extern char *ldtstore;
 
 static void
-xen_init_amd64_vcpuctxt(struct cpu_info *ci,
-			struct vcpu_guest_context *initctx, 
-			void targetrip(struct cpu_info *))
+xen_init_amd64_vcpuctxt(struct cpu_info *ci, struct vcpu_guest_context *initctx,
+void targetrip(struct cpu_info *))
 {
 	/* page frames to point at GDT */
 	extern int gdt_size;
@@ -798,12 +791,12 @@ xen_init_amd64_vcpuctxt(struct cpu_info 
 	KASSERT(initctx != NULL);
 	KASSERT(targetrip != NULL);
 
-	memset(initctx, 0, sizeof *initctx);
+	memset(initctx, 0, sizeof(*initctx));
 
 	gdt_ents = roundup(gdt_size, PAGE_SIZE) >> PAGE_SHIFT;
 	KASSERT(gdt_ents <= 16);
 
-	gdt_prepframes(frames, (vaddr_t) ci->ci_gdt, gdt_ents);
+	gdt_prepframes(frames, (vaddr_t)ci->ci_gdt, gdt_ents);
 
 	/* Initialise the vcpu context: We use idle_loop()'s pcb context. */
 
@@ -842,11 +835,11 @@ xen_init_amd64_vcpuctxt(struct cpu_info 
 	initctx->user_regs.ds = GSEL(GDATA_SEL, SEL_KPL);
 
 	/* GDT */
-	memcpy(initctx->gdt_frames, frames, sizeof frames);
+	memcpy(initctx->gdt_frames, frames, sizeof(frames));
 	initctx->gdt_ents = gdt_ents;
 
 	/* LDT */
-	initctx->ldt_base = (unsigned long) ldtstore;
+	initctx->ldt_base = (unsigned long)ldtstore;
 	initctx->ldt_ents = LDT_SIZE >> 3;
 
 	/* Kernel context state */
@@ -854,19 +847,18 @@ 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] = (vaddr_t) targetrip;
-	/* 
+	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()
 	 */
 	initctx->ctrlreg[3] = xen_pfn_to_cr3(x86_btop(xpmap_ptom(ci->ci_kpm_pdirpa)));
 	initctx->ctrlreg[4] = CR4_PAE | CR4_OSFXSR | CR4_OSXMMEXCPT;
 
-
 	/* Xen callbacks */
-	initctx->event_callback_eip = (unsigned long) hypervisor_callback;
-	initctx->failsafe_callback_eip = (unsigned long) failsafe_callback;
-	initctx->syscall_callback_eip = (unsigned long) Xsyscall;
+	initctx->event_callback_eip = (unsigned long)hypervisor_callback;
+	initctx->failsafe_callback_eip = (unsigned 

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

2016-11-15 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Nov 15 17:01:12 UTC 2016

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

Log Message:
Mmh, apparently I didn't properly test my previous change since it does not
compile anymore


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 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.66 src/sys/arch/xen/x86/x86_xpmap.c:1.67
--- src/sys/arch/xen/x86/x86_xpmap.c:1.66	Tue Nov 15 15:37:20 2016
+++ src/sys/arch/xen/x86/x86_xpmap.c	Tue Nov 15 17:01:12 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.66 2016/11/15 15:37:20 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.67 2016/11/15 17:01:12 maxv Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.66 2016/11/15 15:37:20 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.67 2016/11/15 17:01:12 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -799,7 +799,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	avail += PAGE_SIZE;
 
 	addr = ((u_long)pdtpe) - KERNBASE;
-	bt_pgd[L4_SLOT_KERNBASE] = bt_cpu_pgd[L4_SLOT_KERNBASE] =
+	bt_pgd[pl4_pi(KERNTEXTOFF)] = bt_cpu_pgd[pl4_pi(KERNTEXTOFF)] =
 	xpmap_ptom_masked(addr) | PG_k | PG_V | PG_RW;
 #else
 	pdtpe = bt_pgd;
@@ -812,7 +812,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	avail += PAGE_SIZE;
 
 	addr = ((u_long)pde) - KERNBASE;
-	pdtpe[L3_SLOT_KERNBASE] =
+	pdtpe[pl3_pi(KERNTEXTOFF)] =
 	xpmap_ptom_masked(addr) | PG_k | PG_V | PG_RW;
 #elif defined(PAE)
 	/* Our PAE-style level 2: 5 contigous pages (4 L2 + 1 shadow) */



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

2016-11-15 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Nov 15 15:37:20 UTC 2016

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

Log Message:
Keep simplifying that stuff. Also, replace plX_pi(KERNTEXTOFF) by
LX_SLOT_KERNBASE: the base address is KERNBASE, and we just start mapping
from KERNTEXTOFF. For symmetry with the normal amd64, does not change
anything.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 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.65 src/sys/arch/xen/x86/x86_xpmap.c:1.66
--- src/sys/arch/xen/x86/x86_xpmap.c:1.65	Fri Nov 11 11:34:51 2016
+++ src/sys/arch/xen/x86/x86_xpmap.c	Tue Nov 15 15:37:20 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.65 2016/11/11 11:34:51 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.66 2016/11/15 15:37:20 maxv Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -38,7 +38,6 @@
  * 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.
- *
  */
 
 /*
@@ -66,9 +65,8 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.65 2016/11/11 11:34:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.66 2016/11/15 15:37:20 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -90,20 +88,15 @@ __KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,
 
 #undef	XENDEBUG
 /* #define XENDEBUG_SYNC */
-/* #define XENDEBUG_LOW */
 
 #ifdef XENDEBUG
 #define	XENPRINTF(x) printf x
-#define	XENPRINTK(x) printk x
 #define	XENPRINTK2(x) /* printk x */
 static char XBUF[256];
 #else
 #define	XENPRINTF(x)
-#define	XENPRINTK(x)
 #define	XENPRINTK2(x)
 #endif
-#define	PRINTF(x) printf x
-#define	PRINTK(x) printk x
 
 volatile shared_info_t *HYPERVISOR_shared_info;
 /* Xen requires the start_info struct to be page aligned */
@@ -120,7 +113,7 @@ extern volatile struct xencons_interface
 extern struct xenstore_domain_interface *xenstore_interface; /* XXX */
 
 static void xen_bt_set_readonly(vaddr_t);
-static void xen_bootstrap_tables(vaddr_t, vaddr_t, size_t, size_t, int);
+static void xen_bootstrap_tables(vaddr_t, vaddr_t, size_t, size_t, bool);
 
 vaddr_t xen_locore(void);
 
@@ -180,7 +173,8 @@ static int xpq_idx_array[MAXCPUS];
 
 #ifdef i386
 extern union descriptor tmpgdt[];
-#endif /* i386 */
+#endif
+
 void
 xpq_flush_queue(void)
 {
@@ -581,7 +575,7 @@ xpq_debug_dump(void)
 
 #ifdef PAE
 /*
- * For PAE, we consider a single contigous L2 "superpage" of 4 pages, all of
+ * For PAE, we consider a single contiguous L2 "superpage" of 4 pages, all of
  * them mapped by the L3 page. We also need a shadow page for L3[3].
  */
 static const int l2_4_count = 6;
@@ -643,15 +637,15 @@ xen_locore(void)
 #ifdef __x86_64__
 	count = TABLE_L2_ENTRIES;
 #else
-	count = (mapsize + (NBPD_L2 -1)) >> L2_SHIFT;
+	count = (mapsize + (NBPD_L2 - 1)) >> L2_SHIFT;
 #endif
 
 	/*
 	 * Now compute how many L2 pages we need exactly. This is useful only
 	 * on i386, since the initial count for amd64 is already enough.
 	 */
-	while (mapsize + (count + l2_4_count) * PAGE_SIZE + KERNTEXTOFF >
-	(count << L2_SHIFT) + KERNBASE) {
+	while (KERNTEXTOFF + mapsize + (count + l2_4_count) * PAGE_SIZE >
+	KERNBASE + (count << L2_SHIFT)) {
 		count++;
 	}
 
@@ -682,20 +676,23 @@ bootstrap_again:
 		bootstrap_tables = init_tables +
 		((count + l2_4_count) * PAGE_SIZE);
 
-	/* Make sure we have enough to map the bootstrap tables. */
+	/*
+	 * Make sure the number of L2 pages we have is enough to map everything
+	 * from KERNBASE to the bootstrap tables themselves.
+	 */
 	if (bootstrap_tables + ((oldcount + l2_4_count) * PAGE_SIZE) > 
-	(oldcount << L2_SHIFT) + KERNBASE) {
+	KERNBASE + (oldcount << L2_SHIFT)) {
 		oldcount++;
 		goto bootstrap_again;
 	}
 
 	/* Create temporary tables */
 	xen_bootstrap_tables(init_tables, bootstrap_tables,
-	xen_start_info.nr_pt_frames, oldcount, 0);
+	xen_start_info.nr_pt_frames, oldcount, false);
 
 	/* Create final tables */
 	xen_bootstrap_tables(bootstrap_tables, init_tables,
-	oldcount + l2_4_count, count, 1);
+	oldcount + l2_4_count, count, true);
 
 	/* Zero out free space after tables */
 	memset((void *)(init_tables + ((count + l2_4_count) * PAGE_SIZE)), 0,
@@ -715,7 +712,7 @@ bootstrap_again:
  */
 static void
 xen_bootstrap_tables(vaddr_t old_pgd, vaddr_t new_pgd, size_t old_count,
-size_t new_count, int final)
+size_t new_count, bool final)
 {
 	pd_entry_t *pdtpe, *pde, *pte;
 	pd_entry_t *bt_pgd;
@@ -736,7 +733,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	pg_nx = (descs[3] & CPUID_NOX) ? PG_NX : 0;
 
 	/*
-	 * Size of RW area after the 

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

2016-11-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Nov 11 11:12:42 UTC 2016

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

Log Message:
Start simplifying the Xen locore: rename and reorder several things, remove
awful debug messages, use unsigned counters, fix typos and KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 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.63 src/sys/arch/xen/x86/x86_xpmap.c:1.64
--- src/sys/arch/xen/x86/x86_xpmap.c:1.63	Tue Nov  1 12:16:10 2016
+++ src/sys/arch/xen/x86/x86_xpmap.c	Fri Nov 11 11:12:42 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.63 2016/11/01 12:16:10 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.64 2016/11/11 11:12:42 maxv Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -42,7 +42,6 @@
  */
 
 /*
- *
  * Copyright (c) 2004 Christian Limpach.
  * All rights reserved.
  *
@@ -69,7 +68,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.63 2016/11/01 12:16:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.64 2016/11/11 11:12:42 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -91,13 +90,12 @@ __KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,
 
 #undef	XENDEBUG
 /* #define XENDEBUG_SYNC */
-/* #define	XENDEBUG_LOW */
+/* #define XENDEBUG_LOW */
 
 #ifdef XENDEBUG
 #define	XENPRINTF(x) printf x
 #define	XENPRINTK(x) printk x
 #define	XENPRINTK2(x) /* printk x */
-
 static char XBUF[256];
 #else
 #define	XENPRINTF(x)
@@ -118,6 +116,14 @@ void xen_failsafe_handler(void);
 #define HYPERVISOR_mmu_update_self(req, count, success_count) \
 	HYPERVISOR_mmu_update((req), (count), (success_count), DOMID_SELF)
 
+extern volatile struct xencons_interface *xencons_interface; /* XXX */
+extern struct xenstore_domain_interface *xenstore_interface; /* XXX */
+
+static void xen_bt_set_readonly(vaddr_t);
+static void xen_bootstrap_tables(vaddr_t, vaddr_t, size_t, size_t, int);
+
+vaddr_t xen_pmap_bootstrap(void);
+
 /*
  * kcpuset internally uses an array of uint32_t while xen uses an array of
  * u_long. As we're little-endian we can cast one to the other.
@@ -127,8 +133,8 @@ typedef union {
 	uint32_t xcpum_km[2];
 #else
 	uint32_t xcpum_km[1];
-#endif	
-	u_long   xcpum_xm;
+#endif
+	u_long xcpum_xm;
 } xcpumask_t;
 
 void
@@ -138,7 +144,6 @@ xen_failsafe_handler(void)
 	panic("xen_failsafe_handler called!\n");
 }
 
-
 void
 xen_set_ldt(vaddr_t base, uint32_t entries)
 {
@@ -568,37 +573,16 @@ xpq_debug_dump(void)
 #endif
 
 
-extern volatile struct xencons_interface *xencons_interface; /* XXX */
-extern struct xenstore_domain_interface *xenstore_interface; /* XXX */
-
-static void xen_bt_set_readonly(vaddr_t);
-static void xen_bootstrap_tables(vaddr_t, vaddr_t, int, int, int);
-
-/* How many PDEs ? */
 #if L2_SLOT_KERNBASE > 0
 #define TABLE_L2_ENTRIES (2 * (NKL2_KIMG_ENTRIES + 1))
 #else
 #define TABLE_L2_ENTRIES (NKL2_KIMG_ENTRIES + 1)
 #endif
 
-/* 
- * Construct and switch to new pagetables
- * first_avail is the first vaddr we can use after
- * we get rid of Xen pagetables
- */
-
-vaddr_t xen_pmap_bootstrap(void);
-
-/*
- * Function to get rid of Xen bootstrap tables
- */
-
-/* How many PDP do we need: */
 #ifdef PAE
 /*
- * For PAE, we consider a single contigous L2 "superpage" of 4 pages,
- * all of them mapped by the L3 page. We also need a shadow page
- * for L3[3].
+ * For PAE, we consider a single contigous L2 "superpage" of 4 pages, all of
+ * them mapped by the L3 page. We also need a shadow page for L3[3].
  */
 static const int l2_4_count = 6;
 #elif defined(__x86_64__)
@@ -607,11 +591,14 @@ static const int l2_4_count = PTP_LEVELS
 static const int l2_4_count = PTP_LEVELS - 1;
 #endif
 
+/*
+ * Xen locore: get rid of the Xen bootstrap tables. Build and switch to new page
+ * tables.
+ */
 vaddr_t
 xen_pmap_bootstrap(void)
 {
-	int count, oldcount;
-	long mapsize;
+	size_t count, oldcount, mapsize;
 	vaddr_t bootstrap_tables, init_tables;
 
 	xen_init_features();
@@ -620,16 +607,15 @@ xen_pmap_bootstrap(void)
 
 	xpmap_phys_to_machine_mapping =
 	(unsigned long *)xen_start_info.mfn_list;
-	init_tables = xen_start_info.pt_base;
-	__PRINTK(("xen_arch_pmap_bootstrap init_tables=0x%lx\n", init_tables));
 
 	/* Space after Xen boostrap tables should be free */
-	bootstrap_tables = xen_start_info.pt_base +
-		(xen_start_info.nr_pt_frames * PAGE_SIZE);
+	init_tables = xen_start_info.pt_base;
+	bootstrap_tables = init_tables +
+	(xen_start_info.nr_pt_frames * PAGE_SIZE);
 
 	/*
-	 * Calculate how many space we need
-	 * first everything mapped before the Xen bootstrap tables
+	 * Calculate how much space we need. First, everything mapped before
+	 * the Xen bootstrap tables.
 	 */
 	mapsize = init_tables - KERNTEXTOFF;
 	/* after the tables we'll have:
@@ -645,30 +631,33 @@ 

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

2016-11-01 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Nov  1 12:16:10 UTC 2016

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

Log Message:
Map the PTE space as non-executable on PAE. The same is already done on
amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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.62 src/sys/arch/xen/x86/x86_xpmap.c:1.63
--- src/sys/arch/xen/x86/x86_xpmap.c:1.62	Tue Nov  1 12:00:21 2016
+++ src/sys/arch/xen/x86/x86_xpmap.c	Tue Nov  1 12:16:10 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.62 2016/11/01 12:00:21 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.63 2016/11/01 12:16:10 maxv Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -69,7 +69,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.62 2016/11/01 12:00:21 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.63 2016/11/01 12:16:10 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -994,7 +994,8 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	 */
 	addr = (u_long)pde - KERNBASE;
 	for (i = 0; i < 3; i++, addr += PAGE_SIZE) {
-		pde[PDIR_SLOT_PTE + i] = xpmap_ptom_masked(addr) | PG_k | PG_V;
+		pde[PDIR_SLOT_PTE + i] = xpmap_ptom_masked(addr) | PG_k | PG_V |
+		pg_nx;
 		__PRINTK(("pde[%d] va %#" PRIxVADDR " pa %#" PRIxPADDR
 		" entry %#" PRIxPADDR "\n",
 		(int)(PDIR_SLOT_PTE + i), pde + PAGE_SIZE * i,



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

2016-11-01 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Nov  1 12:00:21 UTC 2016

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

Log Message:
Map the remaining pages as non-executable. Only text should have X.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 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.61 src/sys/arch/xen/x86/x86_xpmap.c:1.62
--- src/sys/arch/xen/x86/x86_xpmap.c:1.61	Thu Aug 25 17:03:57 2016
+++ src/sys/arch/xen/x86/x86_xpmap.c	Tue Nov  1 12:00:21 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.61 2016/08/25 17:03:57 bouyer Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.62 2016/11/01 12:00:21 maxv Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -69,7 +69,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.61 2016/08/25 17:03:57 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.62 2016/11/01 12:00:21 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -950,8 +950,8 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 /* Map the kernel data+bss RW. */
 pte[pl1_pi(page)] |= PG_RW | pg_nx;
 			} else {
-/* map page RW */
-pte[pl1_pi(page)] |= PG_RW;
+/* Map the page RW. */
+pte[pl1_pi(page)] |= PG_RW | pg_nx;
 			}
 
 			if ((page  >= old_pgd && page < old_pgd + (old_count * PAGE_SIZE))



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

2016-08-25 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Aug 25 17:03:57 UTC 2016

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

Log Message:
Revert to 1.59 (adding back the W^X kernel mapings), and move the data+bss
mapping late so that mappings that should be RO (such as page tables) won't
be made RW by accident.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 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.60 src/sys/arch/xen/x86/x86_xpmap.c:1.61
--- src/sys/arch/xen/x86/x86_xpmap.c:1.60	Tue Aug 23 11:03:52 2016
+++ src/sys/arch/xen/x86/x86_xpmap.c	Thu Aug 25 17:03:57 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.60 2016/08/23 11:03:52 bouyer Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.61 2016/08/25 17:03:57 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -69,7 +69,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.60 2016/08/23 11:03:52 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.61 2016/08/25 17:03:57 bouyer Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -730,15 +730,24 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	pd_entry_t *pdtpe, *pde, *pte;
 	pd_entry_t *bt_pgd;
 	paddr_t addr;
-	vaddr_t page, avail, text_end, map_end;
+	vaddr_t page, avail, map_end;
 	int i;
+	extern char __rodata_start;
 	extern char __data_start;
+	extern char __kernel_end;
 	extern char *early_zerop; /* from pmap.c */
+	pt_entry_t pg_nx;
+	u_int descs[4];
 
 	__PRINTK(("xen_bootstrap_tables(%#" PRIxVADDR ", %#" PRIxVADDR ","
 	" %d, %d)\n",
 	old_pgd, new_pgd, old_count, new_count));
-	text_end = ((vaddr_t)&__data_start) & ~PAGE_MASK;
+
+	/*
+	 * Set the NX/XD bit, if available. descs[3] = %edx.
+	 */
+	x86_cpuid(0x8001, descs);
+	pg_nx = (descs[3] & CPUID_NOX) ? PG_NX : 0;
 
 	/*
 	 * size of R/W area after kernel text:
@@ -776,8 +785,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	}
 #endif /* DOM0OPS */
 
-	__PRINTK(("xen_bootstrap_tables text_end 0x%lx map_end 0x%lx\n",
-	text_end, map_end));
+	__PRINTK(("xen_bootstrap_tables map_end 0x%lx\n", map_end));
 	__PRINTK(("console %#lx ", xen_start_info.console_mfn));
 	__PRINTK(("xenstore %#" PRIx32 "\n", xen_start_info.store_mfn));
 
@@ -905,20 +913,26 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 			page < (vaddr_t)atdevbase + IOM_SIZE) {
 pte[pl1_pi(page)] =
 IOM_BEGIN + (page - (vaddr_t)atdevbase);
+pte[pl1_pi(page)] |= pg_nx;
 			}
 #endif
+
 			pte[pl1_pi(page)] |= PG_k | PG_V;
-			if (page < text_end) {
-/* map kernel text RO */
+			if (page < (vaddr_t)&__rodata_start) {
+/* Map the kernel text RX. */
 pte[pl1_pi(page)] |= PG_RO;
+			} else if (page >= (vaddr_t)&__rodata_start &&
+			page < (vaddr_t)&__data_start) {
+/* Map the kernel rodata R. */
+pte[pl1_pi(page)] |= PG_RO | pg_nx;
 			} else if (page >= old_pgd &&
 			page < old_pgd + (old_count * PAGE_SIZE)) {
-/* map old page tables RO */
-pte[pl1_pi(page)] |= PG_RO;
+/* Map the old page tables R. */
+pte[pl1_pi(page)] |= PG_RO | pg_nx;
 			} else if (page >= new_pgd &&
 			page < new_pgd + ((new_count + l2_4_count) * PAGE_SIZE)) {
-/* map new page tables RO */
-pte[pl1_pi(page)] |= PG_RO;
+/* Map the new page tables R. */
+pte[pl1_pi(page)] |= PG_RO | pg_nx;
 #ifdef i386
 			} else if (page == (vaddr_t)tmpgdt) {
 /*
@@ -931,6 +945,10 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 page += PAGE_SIZE;
 continue;
 #endif /* i386 */
+			} else if (page >= (vaddr_t)&__data_start &&
+			page < (vaddr_t)&__kernel_end) {
+/* Map the kernel data+bss RW. */
+pte[pl1_pi(page)] |= PG_RW | pg_nx;
 			} else {
 /* map page RW */
 pte[pl1_pi(page)] |= PG_RW;
@@ -1011,15 +1029,19 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	xpq_queue_pin_l2_table(xpmap_ptom_masked(addr));
 #endif
 #else /* PAE */
-	/* recursive entry in higher-level per-cpu PD and pmap_kernel() */
-	bt_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_pgd - KERNBASE) | PG_k | PG_V;
+
+	/* Recursive entry in pmap_kernel(). */
+	bt_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_pgd - KERNBASE)
+	| PG_k | PG_RO | PG_V | pg_nx;
 #ifdef __x86_64__
-	   bt_cpu_pgd[PDIR_SLOT_PTE] =
-		   xpmap_ptom_masked((paddr_t)bt_cpu_pgd - KERNBASE) | PG_k | PG_V;
-#endif /* __x86_64__ */
+	/* Recursive entry in higher-level per-cpu PD. */
+	bt_cpu_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_cpu_pgd - KERNBASE)
+	| PG_k | PG_RO | PG_V | pg_nx;
+#endif
 	__PRINTK(("bt_pgd[PDIR_SLOT_PTE] va %#" PRIxVADDR " pa %#" PRIxPADDR
 	" entry %#" PRIxPADDR "\n", new_pgd, (paddr_t)new_pgd - KERNBASE,
 	bt_pgd[PDIR_SLOT_PTE]));
+
 	/* Mark tables RO */
 	xen_bt_set_readonly((vaddr_t) pde);
 #endif
@@ -1029,6 +1051,7 @@ 

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

2016-08-23 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Aug 23 11:03:52 UTC 2016

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

Log Message:
Stopgap measure: revert to rev 1.56. starting with 1.57 an i386PAE Xen
kernel doesn't boot:
(XEN) mm.c:2394:d139v0 Bad type (saw 5401 != exp 7000) 
for mfn 1136f5 (pfn 621)
(XEN) mm.c:887:d139v0 Could not get page type PGT_writable_page
(XEN) mm.c:939:d139v0 Error getting mfn 1136f5 (pfn 621) from L1 entry 
0001136f5003 for l1e_owner=139, pg_owner=139
(XEN) mm.c:1254:d139v0 Failure in alloc_l1_table: entry 33
(XEN) mm.c:2141:d139v0 Error while validating mfn 112f57 (pfn dbf) for type 
1000: caf=8003 taf=1001
(XEN) mm.c:947:d139v0 Attempt to create linear p.t. with write perms
(XEN) mm.c:1330:d139v0 Failure in alloc_l2_table: entry 3
(XEN) mm.c:2141:d139v0 Error while validating mfn 112f5b (pfn dbb) for type 
2200: caf=8003 taf=2201
(XEN) mm.c:1412:d139v0 Failure in alloc_l3_table: entry 3
(XEN) mm.c:2141:d139v0 Error while validating mfn 112f60 (pfn db6) for type 
3000: caf=8003 taf=3001
(XEN) mm.c:3044:d139v0 Error while pinning mfn 112f60
(XEN) traps.c:459:d139v0 Unhandled bkpt fault/trap [#3] on VCPU 0 [ec=]
(XEN) domain_crash_sync called from entry.S: fault at 82d080231894 
compat_create_bounce_frame+0xda/0xf2


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 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.59 src/sys/arch/xen/x86/x86_xpmap.c:1.60
--- src/sys/arch/xen/x86/x86_xpmap.c:1.59	Thu Aug 11 15:35:10 2016
+++ src/sys/arch/xen/x86/x86_xpmap.c	Tue Aug 23 11:03:52 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.59 2016/08/11 15:35:10 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.60 2016/08/23 11:03:52 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -69,7 +69,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.59 2016/08/11 15:35:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.60 2016/08/23 11:03:52 bouyer Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -730,24 +730,15 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	pd_entry_t *pdtpe, *pde, *pte;
 	pd_entry_t *bt_pgd;
 	paddr_t addr;
-	vaddr_t page, avail, map_end;
+	vaddr_t page, avail, text_end, map_end;
 	int i;
-	extern char __rodata_start;
 	extern char __data_start;
-	extern char __kernel_end;
 	extern char *early_zerop; /* from pmap.c */
-	pt_entry_t pg_nx;
-	u_int descs[4];
 
 	__PRINTK(("xen_bootstrap_tables(%#" PRIxVADDR ", %#" PRIxVADDR ","
 	" %d, %d)\n",
 	old_pgd, new_pgd, old_count, new_count));
-
-	/*
-	 * Set the NX/XD bit, if available. descs[3] = %edx.
-	 */
-	x86_cpuid(0x8001, descs);
-	pg_nx = (descs[3] & CPUID_NOX) ? PG_NX : 0;
+	text_end = ((vaddr_t)&__data_start) & ~PAGE_MASK;
 
 	/*
 	 * size of R/W area after kernel text:
@@ -785,7 +776,8 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	}
 #endif /* DOM0OPS */
 
-	__PRINTK(("xen_bootstrap_tables map_end 0x%lx\n", map_end));
+	__PRINTK(("xen_bootstrap_tables text_end 0x%lx map_end 0x%lx\n",
+	text_end, map_end));
 	__PRINTK(("console %#lx ", xen_start_info.console_mfn));
 	__PRINTK(("xenstore %#" PRIx32 "\n", xen_start_info.store_mfn));
 
@@ -913,30 +905,20 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 			page < (vaddr_t)atdevbase + IOM_SIZE) {
 pte[pl1_pi(page)] =
 IOM_BEGIN + (page - (vaddr_t)atdevbase);
-pte[pl1_pi(page)] |= pg_nx;
 			}
 #endif
-
 			pte[pl1_pi(page)] |= PG_k | PG_V;
-			if (page < (vaddr_t)&__rodata_start) {
-/* Map the kernel text RX. */
+			if (page < text_end) {
+/* map kernel text RO */
 pte[pl1_pi(page)] |= PG_RO;
-			} else if (page >= (vaddr_t)&__rodata_start &&
-			page < (vaddr_t)&__data_start) {
-/* Map the kernel rodata R. */
-pte[pl1_pi(page)] |= PG_RO | pg_nx;
-			} else if (page >= (vaddr_t)&__data_start &&
-			page < (vaddr_t)&__kernel_end) {
-/* Map the kernel data+bss RW. */
-pte[pl1_pi(page)] |= PG_RW | pg_nx;
 			} else if (page >= old_pgd &&
 			page < old_pgd + (old_count * PAGE_SIZE)) {
-/* Map the old page tables R. */
-pte[pl1_pi(page)] |= PG_RO | pg_nx;
+/* map old page tables RO */
+pte[pl1_pi(page)] |= PG_RO;
 			} else if (page >= new_pgd &&
 			page < new_pgd + ((new_count + l2_4_count) * PAGE_SIZE)) {
-/* Map the new page tables R. */
-pte[pl1_pi(page)] |= PG_RO | pg_nx;
+/* map new page tables RO */
+pte[pl1_pi(page)] |= PG_RO;
 #ifdef i386
 			} else if (page == (vaddr_t)tmpgdt) {
 /*
@@ -1029,19 +1011,15 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	xpq_queue_pin_l2_table(xpmap_ptom_masked(addr));
 #endif
 #else /* PAE */
-
-	/* 

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

2016-08-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Aug 11 15:35:10 UTC 2016

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

Log Message:
Make the I/O area non-executable on Xen.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 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.58 src/sys/arch/xen/x86/x86_xpmap.c:1.59
--- src/sys/arch/xen/x86/x86_xpmap.c:1.58	Wed Aug  3 11:51:18 2016
+++ src/sys/arch/xen/x86/x86_xpmap.c	Thu Aug 11 15:35:10 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.58 2016/08/03 11:51:18 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.59 2016/08/11 15:35:10 maxv Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -69,7 +69,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.58 2016/08/03 11:51:18 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.59 2016/08/11 15:35:10 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -913,6 +913,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 			page < (vaddr_t)atdevbase + IOM_SIZE) {
 pte[pl1_pi(page)] =
 IOM_BEGIN + (page - (vaddr_t)atdevbase);
+pte[pl1_pi(page)] |= pg_nx;
 			}
 #endif
 



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

2016-08-03 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Aug  3 11:51:18 UTC 2016

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

Log Message:
Map the recursive slot and page table pages as non-executable on Xen. Same
as normal x86.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 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.57 src/sys/arch/xen/x86/x86_xpmap.c:1.58
--- src/sys/arch/xen/x86/x86_xpmap.c:1.57	Tue Aug  2 14:21:53 2016
+++ src/sys/arch/xen/x86/x86_xpmap.c	Wed Aug  3 11:51:18 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.57 2016/08/02 14:21:53 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.58 2016/08/03 11:51:18 maxv Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -69,7 +69,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.57 2016/08/02 14:21:53 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.58 2016/08/03 11:51:18 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -918,7 +918,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 
 			pte[pl1_pi(page)] |= PG_k | PG_V;
 			if (page < (vaddr_t)&__rodata_start) {
-/* Map kernel text RX. */
+/* Map the kernel text RX. */
 pte[pl1_pi(page)] |= PG_RO;
 			} else if (page >= (vaddr_t)&__rodata_start &&
 			page < (vaddr_t)&__data_start) {
@@ -930,12 +930,12 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 pte[pl1_pi(page)] |= PG_RW | pg_nx;
 			} else if (page >= old_pgd &&
 			page < old_pgd + (old_count * PAGE_SIZE)) {
-/* map old page tables RO */
-pte[pl1_pi(page)] |= PG_RO;
+/* Map the old page tables R. */
+pte[pl1_pi(page)] |= PG_RO | pg_nx;
 			} else if (page >= new_pgd &&
 			page < new_pgd + ((new_count + l2_4_count) * PAGE_SIZE)) {
-/* map new page tables RO */
-pte[pl1_pi(page)] |= PG_RO;
+/* Map the new page tables R. */
+pte[pl1_pi(page)] |= PG_RO | pg_nx;
 #ifdef i386
 			} else if (page == (vaddr_t)tmpgdt) {
 /*
@@ -1028,15 +1028,19 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	xpq_queue_pin_l2_table(xpmap_ptom_masked(addr));
 #endif
 #else /* PAE */
-	/* recursive entry in higher-level per-cpu PD and pmap_kernel() */
-	bt_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_pgd - KERNBASE) | PG_k | PG_V;
+
+	/* Recursive entry in pmap_kernel(). */
+	bt_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_pgd - KERNBASE)
+	| PG_k | PG_RO | PG_V | pg_nx;
 #ifdef __x86_64__
-	   bt_cpu_pgd[PDIR_SLOT_PTE] =
-		   xpmap_ptom_masked((paddr_t)bt_cpu_pgd - KERNBASE) | PG_k | PG_V;
-#endif /* __x86_64__ */
+	/* Recursive entry in higher-level per-cpu PD. */
+	bt_cpu_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_cpu_pgd - KERNBASE)
+	| PG_k | PG_RO | PG_V | pg_nx;
+#endif
 	__PRINTK(("bt_pgd[PDIR_SLOT_PTE] va %#" PRIxVADDR " pa %#" PRIxPADDR
 	" entry %#" PRIxPADDR "\n", new_pgd, (paddr_t)new_pgd - KERNBASE,
 	bt_pgd[PDIR_SLOT_PTE]));
+
 	/* Mark tables RO */
 	xen_bt_set_readonly((vaddr_t) pde);
 #endif
@@ -1046,6 +1050,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 #if PTP_LEVELS > 3
 	xen_bt_set_readonly(new_pgd);
 #endif
+
 	/* Pin the PGD */
 	__PRINTK(("pin PGD: %"PRIxVADDR"\n", new_pgd - KERNBASE));
 #ifdef __x86_64__



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

2016-08-02 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Aug  2 14:21:53 UTC 2016

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

Log Message:
Map the kernel text, rodata and data+bss independently on Xen, with
respectively RX, R and RW.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 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.56 src/sys/arch/xen/x86/x86_xpmap.c:1.57
--- src/sys/arch/xen/x86/x86_xpmap.c:1.56	Tue Aug  2 13:29:35 2016
+++ src/sys/arch/xen/x86/x86_xpmap.c	Tue Aug  2 14:21:53 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.56 2016/08/02 13:29:35 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.57 2016/08/02 14:21:53 maxv Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -69,7 +69,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.56 2016/08/02 13:29:35 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.57 2016/08/02 14:21:53 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -730,15 +730,24 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	pd_entry_t *pdtpe, *pde, *pte;
 	pd_entry_t *bt_pgd;
 	paddr_t addr;
-	vaddr_t page, avail, text_end, map_end;
+	vaddr_t page, avail, map_end;
 	int i;
+	extern char __rodata_start;
 	extern char __data_start;
+	extern char __kernel_end;
 	extern char *early_zerop; /* from pmap.c */
+	pt_entry_t pg_nx;
+	u_int descs[4];
 
 	__PRINTK(("xen_bootstrap_tables(%#" PRIxVADDR ", %#" PRIxVADDR ","
 	" %d, %d)\n",
 	old_pgd, new_pgd, old_count, new_count));
-	text_end = ((vaddr_t)&__data_start) & ~PAGE_MASK;
+
+	/*
+	 * Set the NX/XD bit, if available. descs[3] = %edx.
+	 */
+	x86_cpuid(0x8001, descs);
+	pg_nx = (descs[3] & CPUID_NOX) ? PG_NX : 0;
 
 	/*
 	 * size of R/W area after kernel text:
@@ -776,8 +785,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 	}
 #endif /* DOM0OPS */
 
-	__PRINTK(("xen_bootstrap_tables text_end 0x%lx map_end 0x%lx\n",
-	text_end, map_end));
+	__PRINTK(("xen_bootstrap_tables map_end 0x%lx\n", map_end));
 	__PRINTK(("console %#lx ", xen_start_info.console_mfn));
 	__PRINTK(("xenstore %#" PRIx32 "\n", xen_start_info.store_mfn));
 
@@ -907,10 +915,19 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 IOM_BEGIN + (page - (vaddr_t)atdevbase);
 			}
 #endif
+
 			pte[pl1_pi(page)] |= PG_k | PG_V;
-			if (page < text_end) {
-/* map kernel text RO */
+			if (page < (vaddr_t)&__rodata_start) {
+/* Map kernel text RX. */
 pte[pl1_pi(page)] |= PG_RO;
+			} else if (page >= (vaddr_t)&__rodata_start &&
+			page < (vaddr_t)&__data_start) {
+/* Map the kernel rodata R. */
+pte[pl1_pi(page)] |= PG_RO | pg_nx;
+			} else if (page >= (vaddr_t)&__data_start &&
+			page < (vaddr_t)&__kernel_end) {
+/* Map the kernel data+bss RW. */
+pte[pl1_pi(page)] |= PG_RW | pg_nx;
 			} else if (page >= old_pgd &&
 			page < old_pgd + (old_count * PAGE_SIZE)) {
 /* map old page tables RO */



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

2016-08-02 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Aug  2 13:29:35 UTC 2016

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

Log Message:
Use PG_RO instead of a magic zero.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 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.55 src/sys/arch/xen/x86/x86_xpmap.c:1.56
--- src/sys/arch/xen/x86/x86_xpmap.c:1.55	Tue Aug  2 13:25:56 2016
+++ src/sys/arch/xen/x86/x86_xpmap.c	Tue Aug  2 13:29:35 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.55 2016/08/02 13:25:56 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.56 2016/08/02 13:29:35 maxv Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -69,7 +69,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.55 2016/08/02 13:25:56 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.56 2016/08/02 13:29:35 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -910,15 +910,15 @@ xen_bootstrap_tables(vaddr_t old_pgd, va
 			pte[pl1_pi(page)] |= PG_k | PG_V;
 			if (page < text_end) {
 /* map kernel text RO */
-pte[pl1_pi(page)] |= 0;
+pte[pl1_pi(page)] |= PG_RO;
 			} else if (page >= old_pgd &&
 			page < old_pgd + (old_count * PAGE_SIZE)) {
 /* map old page tables RO */
-pte[pl1_pi(page)] |= 0;
+pte[pl1_pi(page)] |= PG_RO;
 			} else if (page >= new_pgd &&
 			page < new_pgd + ((new_count + l2_4_count) * PAGE_SIZE)) {
 /* map new page tables RO */
-pte[pl1_pi(page)] |= 0;
+pte[pl1_pi(page)] |= PG_RO;
 #ifdef i386
 			} else if (page == (vaddr_t)tmpgdt) {
 /*



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

2016-08-02 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Aug  2 13:25:56 UTC 2016

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

Log Message:
KNF, and use PAGE_SIZE instead of NBPG.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 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.54 src/sys/arch/xen/x86/x86_xpmap.c:1.55
--- src/sys/arch/xen/x86/x86_xpmap.c:1.54	Sun May 29 17:06:17 2016
+++ src/sys/arch/xen/x86/x86_xpmap.c	Tue Aug  2 13:25:56 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.54 2016/05/29 17:06:17 bouyer Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.55 2016/08/02 13:25:56 maxv Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert 
@@ -69,7 +69,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.54 2016/05/29 17:06:17 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.55 2016/08/02 13:25:56 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -571,8 +571,8 @@ xpq_debug_dump(void)
 extern volatile struct xencons_interface *xencons_interface; /* XXX */
 extern struct xenstore_domain_interface *xenstore_interface; /* XXX */
 
-static void xen_bt_set_readonly (vaddr_t);
-static void xen_bootstrap_tables (vaddr_t, vaddr_t, int, int, int);
+static void xen_bt_set_readonly(vaddr_t);
+static void xen_bootstrap_tables(vaddr_t, vaddr_t, int, int, int);
 
 /* How many PDEs ? */
 #if L2_SLOT_KERNBASE > 0
@@ -587,7 +587,7 @@ static void xen_bootstrap_tables (vaddr_
  * we get rid of Xen pagetables
  */
 
-vaddr_t xen_pmap_bootstrap (void);
+vaddr_t xen_pmap_bootstrap(void);
 
 /*
  * Function to get rid of Xen bootstrap tables
@@ -616,7 +616,7 @@ xen_pmap_bootstrap(void)
 
 	xen_init_features();
 
-	memset(xpq_idx_array, 0, sizeof xpq_idx_array);
+	memset(xpq_idx_array, 0, sizeof(xpq_idx_array));
 
 	xpmap_phys_to_machine_mapping =
 	(unsigned long *)xen_start_info.mfn_list;
@@ -639,12 +639,12 @@ xen_pmap_bootstrap(void)
 	 *  - early_zerop
 	 *  - ISA I/O mem (if needed)
 	 */
-	mapsize += UPAGES * NBPG;
+	mapsize += UPAGES * PAGE_SIZE;
 #ifdef __x86_64__
-	mapsize += NBPG;
+	mapsize += PAGE_SIZE;
 #endif
-	mapsize += NBPG;
-	mapsize += NBPG;
+	mapsize += PAGE_SIZE;
+	mapsize += PAGE_SIZE;
 
 #ifdef DOM0OPS
 	if (xendomain_is_dom0()) {
@@ -652,7 +652,7 @@ xen_pmap_bootstrap(void)
 		mapsize += IOM_SIZE;
 	}
 #endif
-	/* at this point mapsize doens't include the table size */
+	/* at this point mapsize doesn't include the table size */
 
 #ifdef __x86_64__
 	count = TABLE_L2_ENTRIES;
@@ -709,7 +709,7 @@ bootstrap_again:
 
 	/* zero out free space after tables */
 	memset((void *)(init_tables + ((count + l2_4_count) * PAGE_SIZE)), 0,
-	(UPAGES + 1) * NBPG);
+	(UPAGES + 1) * PAGE_SIZE);
 
 	/* Finally, flush TLB. */
 	xpq_queue_tlb_flush();
@@ -718,14 +718,14 @@ bootstrap_again:
 }
 
 /*
- * Build a new table and switch to it
- * old_count is # of old tables (including PGD, PDTPE and PDE)
- * new_count is # of new tables (PTE only)
- * we assume areas don't overlap
+ * Build a new table and switch to it.
+ * old_count is # of old tables (including PGD, PDTPE and PDE).
+ * new_count is # of new tables (PTE only).
+ * We assume the areas don't overlap.
  */
 static void
-xen_bootstrap_tables (vaddr_t old_pgd, vaddr_t new_pgd,
-	int old_count, int new_count, int final)
+xen_bootstrap_tables(vaddr_t old_pgd, vaddr_t new_pgd,
+int old_count, int new_count, int final)
 {
 	pd_entry_t *pdtpe, *pde, *pte;
 	pd_entry_t *bt_pgd;
@@ -739,26 +739,28 @@ xen_bootstrap_tables (vaddr_t old_pgd, v
 	" %d, %d)\n",
 	old_pgd, new_pgd, old_count, new_count));
 	text_end = ((vaddr_t)&__data_start) & ~PAGE_MASK;
+
 	/*
 	 * size of R/W area after kernel text:
-	 *  xencons_interface (if present)
-	 *  xenstore_interface (if present)
-	 *  table pages (new_count + l2_4_count entries)
+	 * xencons_interface (if present)
+	 * xenstore_interface (if present)
+	 * table pages (new_count + l2_4_count entries)
 	 * extra mappings (only when final is true):
-	 *  UAREA
-	 *  dummy user PGD (x86_64 only)/gdt page (i386 only)
-	 *  HYPERVISOR_shared_info
-	 *  early_zerop
-	 *  ISA I/O mem (if needed)
+	 * UAREA
+	 * dummy user PGD (x86_64 only)/gdt page (i386 only)
+	 * HYPERVISOR_shared_info
+	 * early_zerop
+	 * ISA I/O mem (if needed)
 	 */
-	map_end = new_pgd + ((new_count + l2_4_count) * NBPG);
+	map_end = new_pgd + ((new_count + l2_4_count) * PAGE_SIZE);
 	if (final) {
-		map_end += (UPAGES + 1) * NBPG;
+		map_end += (UPAGES + 1) * PAGE_SIZE;
 		HYPERVISOR_shared_info = (shared_info_t *)map_end;
-		map_end += NBPG;
+		map_end += PAGE_SIZE;
 		early_zerop = (char *)map_end;
-		map_end += NBPG;
+		map_end += PAGE_SIZE;
 	}
+
 	/*
 	 * we always set atdevbase, as it's used by init386 to find the first
 	 * 

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

2015-12-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec 13 16:11:14 UTC 2015

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

Log Message:
need definition


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 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.102 src/sys/arch/xen/x86/cpu.c:1.103
--- src/sys/arch/xen/x86/cpu.c:1.102	Sun Dec 13 10:22:31 2015
+++ src/sys/arch/xen/x86/cpu.c	Sun Dec 13 11:11:14 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.102 2015/12/13 15:22:31 christos Exp $	*/
+/*	$NetBSD: cpu.c,v 1.103 2015/12/13 16:11:14 christos Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.102 2015/12/13 15:22:31 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.103 2015/12/13 16:11:14 christos Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -172,7 +172,7 @@ struct cpu_info phycpu_info_primary __al
 struct cpu_info *cpu_info_list = _info_primary;
 struct cpu_info *phycpu_info_list = _info_primary;
 
-extern uint32_t cpu_feature[]; /* X86 CPUID feature bits
+uint32_t cpu_feature[7]; /* X86 CPUID feature bits
 			  *	[0] basic features %edx
 			  *	[1] basic features %ecx
 			  *	[2] extended features %edx



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

2015-12-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec 13 15:22:31 UTC 2015

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

Log Message:
fix the build.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 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.101 src/sys/arch/xen/x86/cpu.c:1.102
--- src/sys/arch/xen/x86/cpu.c:1.101	Mon Dec  8 10:22:47 2014
+++ src/sys/arch/xen/x86/cpu.c	Sun Dec 13 10:22:31 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.101 2014/12/08 15:22:47 msaitoh Exp $	*/
+/*	$NetBSD: cpu.c,v 1.102 2015/12/13 15:22:31 christos Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.101 2014/12/08 15:22:47 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.102 2015/12/13 15:22:31 christos Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -172,12 +172,14 @@ struct cpu_info phycpu_info_primary __al
 struct cpu_info *cpu_info_list = _info_primary;
 struct cpu_info *phycpu_info_list = _info_primary;
 
-uint32_t cpu_feature[5]; /* X86 CPUID feature bits
+extern uint32_t cpu_feature[]; /* X86 CPUID feature bits
 			  *	[0] basic features %edx
 			  *	[1] basic features %ecx
 			  *	[2] extended features %edx
 			  *	[3] extended features %ecx
 			  *	[4] VIA padlock features
+			  *	[5] structured extended features cpuid.7:%ebx
+			  *	[6] structured extended features cpuid.7:%ecx
 			  */
 
 bool x86_mp_online;



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

2015-02-07 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Feb  7 20:01:48 UTC 2015

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

Log Message:
valid_ipimask is only used under DIAGNOSTIC, so only define it then.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 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.18 src/sys/arch/xen/x86/xen_ipi.c:1.19
--- src/sys/arch/xen/x86/xen_ipi.c:1.18	Mon May 19 22:47:54 2014
+++ src/sys/arch/xen/x86/xen_ipi.c	Sat Feb  7 20:01:48 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.18 2014/05/19 22:47:54 rmind Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.19 2015/02/07 20:01:48 joerg 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.18 2014/05/19 22:47:54 rmind Exp $); 
+ * __KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.19 2015/02/07 20:01:48 joerg Exp $); 
  */
 
-__KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.18 2014/05/19 22:47:54 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.19 2015/02/07 20:01:48 joerg Exp $);
 
 #include sys/types.h
 
@@ -131,6 +131,7 @@ xen_ipi_init(void)
 	hypervisor_enable_event(evtchn);
 }
 
+#ifdef DIAGNOSTIC
 static inline bool /* helper */
 valid_ipimask(uint32_t ipimask)
 {
@@ -145,6 +146,7 @@ valid_ipimask(uint32_t ipimask)
 	}
 
 }
+#endif
 
 int
 xen_send_ipi(struct cpu_info *ci, uint32_t ipimask)



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

2014-04-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Apr  3 15:53:05 UTC 2014

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

Log Message:
Change findroot() to cpu_bootconf() since this is what it does. Remove bogus
comment.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/xen/x86/autoconf.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/autoconf.c
diff -u src/sys/arch/xen/x86/autoconf.c:1.16 src/sys/arch/xen/x86/autoconf.c:1.17
--- src/sys/arch/xen/x86/autoconf.c:1.16	Wed Oct  3 14:58:33 2012
+++ src/sys/arch/xen/x86/autoconf.c	Thu Apr  3 11:53:05 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.16 2012/10/03 18:58:33 dsl Exp $	*/
+/*	$NetBSD: autoconf.c,v 1.17 2014/04/03 15:53:05 christos Exp $	*/
 /*	NetBSD: autoconf.c,v 1.75 2003/12/30 12:33:22 pk Exp 	*/
 
 /*-
@@ -45,7 +45,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: autoconf.c,v 1.16 2012/10/03 18:58:33 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: autoconf.c,v 1.17 2014/04/03 15:53:05 christos Exp $);
 
 #include opt_xen.h
 #include opt_compat_oldboot.h
@@ -86,7 +86,6 @@ __KERNEL_RCSID(0, $NetBSD: autoconf.c,v
 #include machine/pcb.h
 #include machine/bootinfo.h
 
-static void findroot(void);
 static int is_valid_disk(device_t);
 
 struct disklist *x86_alldisks;
@@ -143,7 +142,7 @@ cpu_configure(void)
 void
 cpu_rootconf(void)
 {
-	findroot();
+	cpu_bootconf();
 
 	printf(boot device: %s\n,
 	booted_device ? device_xname(booted_device) : unknown);
@@ -153,11 +152,9 @@ cpu_rootconf(void)
 
 /*
  * Attempt to find the device from which we were booted.
- * If we can do so, and not instructed not to do so,
- * change rootdev to correspond to the load device.
  */
 void
-findroot(void)
+cpu_bootconf(void)
 {
 	device_t dv;
 	deviter_t di;



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

2014-03-03 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Mon Mar  3 22:09:32 UTC 2014

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

Log Message:
Use the global pci_mode to avoid 'set but not used' warnings from gcc 4.8.3.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/xen/x86/mainbus.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/mainbus.c
diff -u src/sys/arch/xen/x86/mainbus.c:1.17 src/sys/arch/xen/x86/mainbus.c:1.18
--- src/sys/arch/xen/x86/mainbus.c:1.17	Fri Jan 31 10:37:01 2014
+++ src/sys/arch/xen/x86/mainbus.c	Mon Mar  3 22:09:32 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: mainbus.c,v 1.17 2014/01/31 10:37:01 bouyer Exp $	*/
+/*	$NetBSD: mainbus.c,v 1.18 2014/03/03 22:09:32 dsl Exp $	*/
 /*	NetBSD: mainbus.c,v 1.53 2003/10/27 14:11:47 junyoung Exp 	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: mainbus.c,v 1.17 2014/01/31 10:37:01 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: mainbus.c,v 1.18 2014/03/03 22:09:32 dsl Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -133,9 +133,6 @@ mainbus_match(device_t parent, cfdata_t 
 void
 mainbus_attach(device_t parent, device_t self, void *aux)
 {
-#if defined(DOM0OPS)  NPCI  0
-	int mode;
-#endif
 	union mainbus_attach_args mba;
 #if defined(DOM0OPS)
 	int numcpus = 0;
@@ -157,9 +154,9 @@ mainbus_attach(device_t parent, device_t
 #endif
 #if NPCI  0
 		/* ACPI needs to be able to access PCI configuration space. */
-		mode = pci_mode_detect();
+		pci_mode_detect();
 #ifdef PCI_BUS_FIXUP
-		if (mode != 0) {
+		if (pci_mode != 0) {
 			pci_maxbus = pci_bus_fixup(NULL, 0);
 			aprint_debug_dev(self, PCI bus max, after 
 			pci_bus_fixup: %i\n, pci_maxbus);



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

2014-01-31 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Jan 31 10:37:01 UTC 2014

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

Log Message:
Move back call to pci_mode_detect() outside of #ifdef PCI_BUS_FIXUP.
Even if mode is not used, the call to pci_mode_detect() is mandatory to
initialize the PCI subsystem.
Fix panic booting -current DOM0 reported by Patrick Welche on port-xen.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/xen/x86/mainbus.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/mainbus.c
diff -u src/sys/arch/xen/x86/mainbus.c:1.16 src/sys/arch/xen/x86/mainbus.c:1.17
--- src/sys/arch/xen/x86/mainbus.c:1.16	Wed Nov  6 06:23:15 2013
+++ src/sys/arch/xen/x86/mainbus.c	Fri Jan 31 10:37:01 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: mainbus.c,v 1.16 2013/11/06 06:23:15 mrg Exp $	*/
+/*	$NetBSD: mainbus.c,v 1.17 2014/01/31 10:37:01 bouyer Exp $	*/
 /*	NetBSD: mainbus.c,v 1.53 2003/10/27 14:11:47 junyoung Exp 	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: mainbus.c,v 1.16 2013/11/06 06:23:15 mrg Exp $);
+__KERNEL_RCSID(0, $NetBSD: mainbus.c,v 1.17 2014/01/31 10:37:01 bouyer Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -133,7 +133,7 @@ mainbus_match(device_t parent, cfdata_t 
 void
 mainbus_attach(device_t parent, device_t self, void *aux)
 {
-#if defined(DOM0OPS)  NPCI  0  defined(PCI_BUS_FIXUP)
+#if defined(DOM0OPS)  NPCI  0
 	int mode;
 #endif
 	union mainbus_attach_args mba;
@@ -157,8 +157,8 @@ mainbus_attach(device_t parent, device_t
 #endif
 #if NPCI  0
 		/* ACPI needs to be able to access PCI configuration space. */
-#ifdef PCI_BUS_FIXUP
 		mode = pci_mode_detect();
+#ifdef PCI_BUS_FIXUP
 		if (mode != 0) {
 			pci_maxbus = pci_bus_fixup(NULL, 0);
 			aprint_debug_dev(self, PCI bus max, after 



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

2013-11-09 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Sun Nov 10 01:19:13 UTC 2013

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

Log Message:
Change xpq_flush_cache to just do WBINVD letting the hypervisor trap and
handle it as MMUEXT_FLUSH_CACHE is a privileged hypervisor operation.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 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.51 src/sys/arch/xen/x86/x86_xpmap.c:1.52
--- src/sys/arch/xen/x86/x86_xpmap.c:1.51	Fri Nov  8 02:23:52 2013
+++ src/sys/arch/xen/x86/x86_xpmap.c	Sun Nov 10 01:19:13 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.51 2013/11/08 02:23:52 christos Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.52 2013/11/10 01:19:13 jnemeth 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.51 2013/11/08 02:23:52 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.52 2013/11/10 01:19:13 jnemeth Exp $);
 
 #include opt_xen.h
 #include opt_ddb.h
@@ -348,16 +348,12 @@ xpq_queue_tlb_flush(void)
 void
 xpq_flush_cache(void)
 {
-	struct mmuext_op op;
-	int s = splvm(), err;
+	int s = splvm();
 
 	xpq_flush_queue();
 
 	XENPRINTK2((xpq_queue_flush_cache\n));
-	op.cmd = MMUEXT_FLUSH_CACHE;
-	if ((err = HYPERVISOR_mmuext_op(op, 1, NULL, DOMID_SELF))  0) {
-		panic(xpq_flush_cache, err %d, err);
-	}
+	asm(wbinvd:::memory);
 	splx(s); /* XXX: removeme */
 }
 



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

2013-11-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Nov  8 02:23:52 UTC 2013

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

Log Message:
fix unused variable warnings


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 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.50 src/sys/arch/xen/x86/x86_xpmap.c:1.51
--- src/sys/arch/xen/x86/x86_xpmap.c:1.50	Wed Nov  6 01:23:15 2013
+++ src/sys/arch/xen/x86/x86_xpmap.c	Thu Nov  7 21:23:52 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.50 2013/11/06 06:23:15 mrg Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.51 2013/11/08 02:23:52 christos 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.50 2013/11/06 06:23:15 mrg Exp $);
+__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.51 2013/11/08 02:23:52 christos Exp $);
 
 #include opt_xen.h
 #include opt_ddb.h
@@ -1044,6 +1044,7 @@ xen_bootstrap_tables (vaddr_t old_pgd, v
 		cpu_info_primary.ci_kpm_pdirpa = ((paddr_t) bt_cpu_pgd - KERNBASE);
 	}
 #endif
+	__USE(pdtpe);
 
 	/* Now we can safely reclaim space taken by old tables */
 	



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

2013-09-14 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Sep 14 13:07:55 UTC 2013

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

Log Message:
GC max_cpus.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 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.11 src/sys/arch/xen/x86/xen_ipi.c:1.12
--- src/sys/arch/xen/x86/xen_ipi.c:1.11	Thu Dec 27 06:42:14 2012
+++ src/sys/arch/xen/x86/xen_ipi.c	Sat Sep 14 13:07:55 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.11 2012/12/27 06:42:14 cherry Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.12 2013/09/14 13:07:55 joerg 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.11 2012/12/27 06:42:14 cherry Exp $); 
+ * __KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.12 2013/09/14 13:07:55 joerg Exp $); 
  */
 
-__KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.11 2012/12/27 06:42:14 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.12 2013/09/14 13:07:55 joerg Exp $);
 
 #include sys/types.h
 
@@ -132,12 +132,6 @@ xen_ipi_init(void)
 	hypervisor_enable_event(evtchn);
 }
 
-/* prefer this to global variable */
-static inline u_int max_cpus(void)
-{
-	return maxcpus;
-}
-
 static inline bool /* helper */
 valid_ipimask(uint32_t ipimask)
 {



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

2012-08-21 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Aug 21 09:06:03 UTC 2012

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

Log Message:
Redo previous the correct way: Xen expects a u_long * for vcpumask,
so use 2 uint32_t on LP64.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 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.47 src/sys/arch/xen/x86/x86_xpmap.c:1.48
--- src/sys/arch/xen/x86/x86_xpmap.c:1.47	Tue Aug 21 01:17:46 2012
+++ src/sys/arch/xen/x86/x86_xpmap.c	Tue Aug 21 09:06:02 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.47 2012/08/21 01:17:46 rmind Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.48 2012/08/21 09:06:02 bouyer 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.47 2012/08/21 01:17:46 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.48 2012/08/21 09:06:02 bouyer Exp $);
 
 #include opt_xen.h
 #include opt_ddb.h
@@ -118,6 +118,19 @@ void xen_failsafe_handler(void);
 #define HYPERVISOR_mmu_update_self(req, count, success_count) \
 	HYPERVISOR_mmu_update((req), (count), (success_count), DOMID_SELF)
 
+/*
+ * kcpuset internally uses an array of uint32_t while xen uses an array of
+ * u_long. As we're little-endian we can cast one to the other.
+ */
+typedef union {
+#ifdef _LP64
+	uint32_t xcpum_km[2];
+#else
+	uint32_t xcpum_km[1];
+#endif	
+	u_long   xcpum_xm;
+} xcpumask_t;
+
 void
 xen_failsafe_handler(void)
 {
@@ -364,17 +377,17 @@ xpq_queue_invlpg(vaddr_t va)
 void
 xen_mcast_invlpg(vaddr_t va, kcpuset_t *kc)
 {
-	uint32_t xcpumask = 0;
+	xcpumask_t xcpumask;
 	mmuext_op_t op;
 
-	kcpuset_copybits(kc, xcpumask, sizeof(xcpumask));
+	kcpuset_copybits(kc, xcpumask.xcpum_km[0], sizeof(xcpumask));
 
 	/* Flush pending page updates */
 	xpq_flush_queue();
 
 	op.cmd = MMUEXT_INVLPG_MULTI;
 	op.arg1.linear_addr = va;
-	op.arg2.vcpumask = xcpumask;
+	op.arg2.vcpumask = xcpumask.xcpum_xm;
 
 	if (HYPERVISOR_mmuext_op(op, 1, NULL, DOMID_SELF)  0) {
 		panic(xpq_queue_invlpg_all);
@@ -405,16 +418,16 @@ xen_bcast_invlpg(vaddr_t va)
 void
 xen_mcast_tlbflush(kcpuset_t *kc)
 {
-	uint32_t xcpumask = 0;
+	xcpumask_t xcpumask;
 	mmuext_op_t op;
 
-	kcpuset_copybits(kc, xcpumask, sizeof(xcpumask));
+	kcpuset_copybits(kc, xcpumask.xcpum_km[0], sizeof(xcpumask));
 
 	/* Flush pending page updates */
 	xpq_flush_queue();
 
 	op.cmd = MMUEXT_TLB_FLUSH_MULTI;
-	op.arg2.vcpumask = xcpumask;
+	op.arg2.vcpumask = xcpumask.xcpum_xm;
 
 	if (HYPERVISOR_mmuext_op(op, 1, NULL, DOMID_SELF)  0) {
 		panic(xpq_queue_invlpg_all);



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

2012-08-20 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Tue Aug 21 01:17:46 UTC 2012

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

Log Message:
Fix Xen build.  Make xcpumask uint32_t, fits 32 CPUs (can increase).


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 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.46 src/sys/arch/xen/x86/x86_xpmap.c:1.47
--- src/sys/arch/xen/x86/x86_xpmap.c:1.46	Sat Jun 30 22:50:37 2012
+++ src/sys/arch/xen/x86/x86_xpmap.c	Tue Aug 21 01:17:46 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.46 2012/06/30 22:50:37 jym Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.47 2012/08/21 01:17:46 rmind 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.46 2012/06/30 22:50:37 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.47 2012/08/21 01:17:46 rmind Exp $);
 
 #include opt_xen.h
 #include opt_ddb.h
@@ -364,7 +364,7 @@ xpq_queue_invlpg(vaddr_t va)
 void
 xen_mcast_invlpg(vaddr_t va, kcpuset_t *kc)
 {
-	u_long xcpumask = 0;
+	uint32_t xcpumask = 0;
 	mmuext_op_t op;
 
 	kcpuset_copybits(kc, xcpumask, sizeof(xcpumask));
@@ -405,7 +405,7 @@ xen_bcast_invlpg(vaddr_t va)
 void
 xen_mcast_tlbflush(kcpuset_t *kc)
 {
-	u_long xcpumask = 0;
+	uint32_t xcpumask = 0;
 	mmuext_op_t op;
 
 	kcpuset_copybits(kc, xcpumask, sizeof(xcpumask));



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

2012-06-24 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Sun Jun 24 13:56:10 UTC 2012

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

Log Message:
Update comment: we stopped using xcall to sync PTP between CPUs.
pmap_kpm_sync_xcall = xen_kpm_sync


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 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.92 src/sys/arch/xen/x86/cpu.c:1.93
--- src/sys/arch/xen/x86/cpu.c:1.92	Wed Jun  6 22:22:41 2012
+++ src/sys/arch/xen/x86/cpu.c	Sun Jun 24 13:56:10 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.92 2012/06/06 22:22:41 rmind Exp $	*/
+/*	$NetBSD: cpu.c,v 1.93 2012/06/24 13:56:10 jym 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.92 2012/06/06 22:22:41 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.93 2012/06/24 13:56:10 jym Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1113,7 +1113,7 @@ cpu_load_pmap(struct pmap *pmap, struct 
 	cpuid_t cid = cpu_index(ci);
 
 	mutex_enter(ci-ci_kpm_mtx);
-	/* make new pmap visible to pmap_kpm_sync_xcall() */
+	/* make new pmap visible to xen_kpm_sync() */
 	kcpuset_atomic_set(pmap-pm_xen_ptp_cpus, cid);
 #endif
 #ifdef i386
@@ -1166,7 +1166,7 @@ cpu_load_pmap(struct pmap *pmap, struct 
 
 #endif /* __x86_64__ */
 #if defined(__x86_64__) || defined(PAE)
-	/* old pmap no longer visible to pmap_kpm_sync_xcall() */
+	/* old pmap no longer visible to xen_kpm_sync() */
 	if (oldpmap != pmap_kernel()) {
 		kcpuset_atomic_clear(oldpmap-pm_xen_ptp_cpus, cid);
 	}



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

2012-03-11 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Sun Mar 11 16:16:44 UTC 2012

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

Log Message:
Typo fix.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 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.89 src/sys/arch/xen/x86/cpu.c:1.90
--- src/sys/arch/xen/x86/cpu.c:1.89	Sat Feb 25 18:57:50 2012
+++ src/sys/arch/xen/x86/cpu.c	Sun Mar 11 16:16:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.89 2012/02/25 18:57:50 bouyer Exp $	*/
+/*	$NetBSD: cpu.c,v 1.90 2012/03/11 16:16:44 jym 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.89 2012/02/25 18:57:50 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.90 2012/03/11 16:16:44 jym Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1196,7 +1196,7 @@ cpu_load_pmap(struct pmap *pmap, struct 
   * considered to be a canonical SHADOW PDIR with the following
   * properties: 
   * - Its recursive mapping points to itself
-  * - per-cpu recurseive mappings point to themselves on __x86_64__
+  * - per-cpu recursive mappings point to themselves on __x86_64__
   * - per-cpu L4 pages' kernel entries are expected to be in sync with
   *   the shadow
   */



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

2012-03-11 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Sun Mar 11 17:14:30 UTC 2012

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

Log Message:
Split the map/unmap code from the sync/flush code: move xpq_flush_queue()
calls after pmap_{,un}map_recursive_entries() so that pmap's handlers
handle the flush themselves.

Now pmap_{,un}map_recursive_entries() do what their names imply, nothing more.

Fix pmap_xen_suspend()'s comment: APDPs are now gone.

pmap's handlers are called deep during kernel save/restore. We already
are at IPL_VM + kpreemption disabled. No need to wrap the xpq_flush_queue()
with splvm/splx.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/xen/x86/xen_pmap.c

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

Modified files:

Index: src/sys/arch/xen/x86/xen_pmap.c
diff -u src/sys/arch/xen/x86/xen_pmap.c:1.19 src/sys/arch/xen/x86/xen_pmap.c:1.20
--- src/sys/arch/xen/x86/xen_pmap.c:1.19	Fri Mar  2 16:38:14 2012
+++ src/sys/arch/xen/x86/xen_pmap.c	Sun Mar 11 17:14:30 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_pmap.c,v 1.19 2012/03/02 16:38:14 bouyer Exp $	*/
+/*	$NetBSD: xen_pmap.c,v 1.20 2012/03/11 17:14:30 jym Exp $	*/
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -102,7 +102,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: xen_pmap.c,v 1.19 2012/03/02 16:38:14 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_pmap.c,v 1.20 2012/03/11 17:14:30 jym Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -236,22 +236,16 @@ pmap_extract_ma(struct pmap *pmap, vaddr
 }
 
 /*
- * Flush all APDP entries found in pmaps
- * Required during Xen save/restore operations, as Xen does not
- * handle alternative recursive mappings properly
+ * Xen pmap's handlers for save/restore
  */
 void
 pmap_xen_suspend(void)
 {
-	int s;
-
-	s = splvm();
-	xpq_flush_queue();
-	splx(s);
-
 #ifdef PAE
 	pmap_unmap_recursive_entries();
 #endif
+
+	xpq_flush_queue();
 }
 
 void
@@ -260,6 +254,8 @@ pmap_xen_resume(void)
 #ifdef PAE
 	pmap_map_recursive_entries();
 #endif
+
+	xpq_flush_queue();
 }
 
 #ifdef PAE
@@ -294,10 +290,13 @@ pmap_map_recursive_entries(void)
 		xpmap_ptom(pmap_pdirpa(pmap_kernel(), PDIR_SLOT_PTE + i)),
 		xpmap_ptom(pmap_kernel()-pm_pdirpa[i]) | PG_V);
 	}
-
-	xpq_flush_queue();
 }
 
+/*
+ * Unmap recursive entries found in pmaps. Required during Xen
+ * save/restore operations, as Xen does not handle recursive mappings
+ * properly.
+ */
 void
 pmap_unmap_recursive_entries(void)
 {
@@ -322,13 +321,11 @@ pmap_unmap_recursive_entries(void)
 	mutex_exit(pmaps_lock);
 
 	/* do it for pmap_kernel() too! */
-	for (i = 0; i  PDP_SIZE; i++)
+	for (i = 0; i  PDP_SIZE; i++) {
 		xpq_queue_pte_update(
 		xpmap_ptom(pmap_pdirpa(pmap_kernel(), PDIR_SLOT_PTE + i)),
 		0);
-
-	xpq_flush_queue();
-
+	}
 }
 #endif /* PAE */
 



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

2012-03-02 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Mar  2 16:37:38 UTC 2012

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

Log Message:
MMUEXT_INVLPG_MULTI and MMUEXT_TLB_FLUSH_MULTI use a long as cpu mask,
not uint32_t, so  pass a pointer of the right type.
While there, cleanup includes and delete local, redundant define of PG_k.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 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.41 src/sys/arch/xen/x86/x86_xpmap.c:1.42
--- src/sys/arch/xen/x86/x86_xpmap.c:1.41	Fri Feb 24 08:06:08 2012
+++ src/sys/arch/xen/x86/x86_xpmap.c	Fri Mar  2 16:37:38 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.41 2012/02/24 08:06:08 cherry Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.42 2012/03/02 16:37:38 bouyer 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.41 2012/02/24 08:06:08 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.42 2012/03/02 16:37:38 bouyer Exp $);
 
 #include opt_xen.h
 #include opt_ddb.h
@@ -78,10 +78,11 @@ __KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,
 #include sys/param.h
 #include sys/systm.h
 #include sys/mutex.h
+#include sys/cpu.h
 
 #include uvm/uvm.h
 
-#include machine/pmap.h
+#include x86/pmap.h
 #include machine/gdt.h
 #include xen/xenfunc.h
 
@@ -106,13 +107,6 @@ static char XBUF[256];
 #define	PRINTF(x) printf x
 #define	PRINTK(x) printk x
 
-/* on x86_64 kernel runs in ring 3 */
-#ifdef __x86_64__
-#define PG_k PG_u
-#else
-#define PG_k 0
-#endif
-
 volatile shared_info_t *HYPERVISOR_shared_info;
 /* Xen requires the start_info struct to be page aligned */
 union start_info_union start_info_union __aligned(PAGE_SIZE);
@@ -371,13 +365,14 @@ void
 xen_mcast_invlpg(vaddr_t va, uint32_t cpumask)
 {
 	mmuext_op_t op;
+	u_long xcpumask = cpumask;
 
 	/* Flush pending page updates */
 	xpq_flush_queue();
 
 	op.cmd = MMUEXT_INVLPG_MULTI;
 	op.arg1.linear_addr = va;
-	op.arg2.vcpumask = cpumask;
+	op.arg2.vcpumask = xcpumask;
 
 	if (HYPERVISOR_mmuext_op(op, 1, NULL, DOMID_SELF)  0) {
 		panic(xpq_queue_invlpg_all);
@@ -409,12 +404,13 @@ void
 xen_mcast_tlbflush(uint32_t cpumask)
 {
 	mmuext_op_t op;
+	u_long xcpumask = cpumask;
 
 	/* Flush pending page updates */
 	xpq_flush_queue();
 
 	op.cmd = MMUEXT_TLB_FLUSH_MULTI;
-	op.arg2.vcpumask = cpumask;
+	op.arg2.vcpumask = xcpumask;
 
 	if (HYPERVISOR_mmuext_op(op, 1, NULL, DOMID_SELF)  0) {
 		panic(xpq_queue_invlpg_all);



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

2012-03-02 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Mar  2 16:38:14 UTC 2012

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

Log Message:
Add some more KASSERT()


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/xen/x86/xen_pmap.c

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

Modified files:

Index: src/sys/arch/xen/x86/xen_pmap.c
diff -u src/sys/arch/xen/x86/xen_pmap.c:1.18 src/sys/arch/xen/x86/xen_pmap.c:1.19
--- src/sys/arch/xen/x86/xen_pmap.c:1.18	Fri Feb 24 08:06:08 2012
+++ src/sys/arch/xen/x86/xen_pmap.c	Fri Mar  2 16:38:14 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_pmap.c,v 1.18 2012/02/24 08:06:08 cherry Exp $	*/
+/*	$NetBSD: xen_pmap.c,v 1.19 2012/03/02 16:38:14 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -102,7 +102,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: xen_pmap.c,v 1.18 2012/02/24 08:06:08 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_pmap.c,v 1.19 2012/03/02 16:38:14 bouyer Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -337,6 +337,8 @@ pmap_unmap_recursive_entries(void)
 static __inline void
 pmap_kpm_setpte(struct cpu_info *ci, struct pmap *pmap, int index)
 {
+	KASSERT(mutex_owned(pmap-pm_lock));
+	KASSERT(mutex_owned(ci-ci_kpm_mtx));
 	if (pmap == pmap_kernel()) {
 		KASSERT(index = PDIR_SLOT_KERN);
 	}
@@ -363,6 +365,7 @@ xen_kpm_sync(struct pmap *pmap, int inde
 	struct cpu_info *ci;
 	
 	KASSERT(pmap != NULL);
+	KASSERT(kpreempt_disabled());
 
 	pmap_pte_flush();
 



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

2012-02-25 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sat Feb 25 18:57:51 UTC 2012

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

Log Message:
The code assumes that ci_index is also the Xen's cpunum, and that
cpunum is less than XEN_LEGACY_MAX_VCPUS. KASSERT both.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 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.88 src/sys/arch/xen/x86/cpu.c:1.89
--- src/sys/arch/xen/x86/cpu.c:1.88	Fri Feb 24 11:43:06 2012
+++ src/sys/arch/xen/x86/cpu.c	Sat Feb 25 18:57:50 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.88 2012/02/24 11:43:06 bouyer Exp $	*/
+/*	$NetBSD: cpu.c,v 1.89 2012/02/25 18:57:50 bouyer 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.88 2012/02/24 11:43:06 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.89 2012/02/25 18:57:50 bouyer Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -409,6 +409,7 @@ cpu_attach_common(device_t parent, devic
 	ci-ci_cpuid = cpunum;
 
 	KASSERT(HYPERVISOR_shared_info != NULL);
+	KASSERT(cpunum  XEN_LEGACY_MAX_VCPUS);
 	ci-ci_vcpu = HYPERVISOR_shared_info-vcpu_info[cpunum];
 
 	KASSERT(ci-ci_func == 0);
@@ -434,6 +435,7 @@ cpu_attach_common(device_t parent, devic
 		KASSERT(ci-ci_data.cpu_idlelwp != NULL);
 	}
 
+	KASSERT(ci-ci_cpuid == ci-ci_index);
 	ci-ci_cpumask = (1  cpu_index(ci));
 	pmap_reference(pmap_kernel());
 	ci-ci_pmap = pmap_kernel();



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

2012-02-24 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Feb 24 11:31:23 UTC 2012

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

Log Message:
Get rid of phycpus_attached bitmask; it's maintained but not used and
will limit the number of physical CPUs to 32 without good reasons.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 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.86 src/sys/arch/xen/x86/cpu.c:1.87
--- src/sys/arch/xen/x86/cpu.c:1.86	Fri Feb 24 08:06:07 2012
+++ src/sys/arch/xen/x86/cpu.c	Fri Feb 24 11:31:23 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.86 2012/02/24 08:06:07 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.87 2012/02/24 11:31:23 bouyer 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.86 2012/02/24 08:06:07 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.87 2012/02/24 11:31:23 bouyer Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -184,9 +184,6 @@ struct cpu_info *phycpu_info_list = phy
 uint32_t cpus_attached = 1;
 uint32_t cpus_running = 1;
 
-uint32_t phycpus_attached = 0;
-uint32_t phycpus_running = 0;
-
 uint32_t cpu_feature[5]; /* X86 CPUID feature bits
 			  *	[0] basic features %edx
 			  *	[1] basic features %ecx
@@ -222,11 +219,6 @@ cpu_attach(device_t parent, device_t sel
 
 	sc-sc_dev = self;
 
-	if (phycpus_attached == ~0) {
-		aprint_error(: increase MAXCPUS\n);
-		return;
-	}
-
 	/*
 	 * If we're an Application Processor, allocate a cpu_info
 	 * If we're the first attached CPU use the primary cpu_info,
@@ -260,8 +252,6 @@ cpu_attach(device_t parent, device_t sel
 	ci-ci_index = nphycpu++;
 	ci-ci_cpumask = (1  cpu_index(ci));
 
-	atomic_or_32(phycpus_attached, ci-ci_cpumask);
-
 	if (!pmf_device_register(self, NULL, NULL))
 		aprint_error_dev(self, couldn't establish power handler\n);
 



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

2012-02-24 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Feb 24 11:43:06 UTC 2012

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

Log Message:
Don't maintain ci_cpumask for physical CPUs, it's not used.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 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.87 src/sys/arch/xen/x86/cpu.c:1.88
--- src/sys/arch/xen/x86/cpu.c:1.87	Fri Feb 24 11:31:23 2012
+++ src/sys/arch/xen/x86/cpu.c	Fri Feb 24 11:43:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.87 2012/02/24 11:31:23 bouyer Exp $	*/
+/*	$NetBSD: cpu.c,v 1.88 2012/02/24 11:43:06 bouyer 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.87 2012/02/24 11:31:23 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.88 2012/02/24 11:43:06 bouyer Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -250,7 +250,6 @@ cpu_attach(device_t parent, device_t sel
 	ci-ci_cpuid = caa-cpu_number;
 	ci-ci_vcpu = NULL;
 	ci-ci_index = nphycpu++;
-	ci-ci_cpumask = (1  cpu_index(ci));
 
 	if (!pmf_device_register(self, NULL, NULL))
 		aprint_error_dev(self, couldn't establish power handler\n);



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

2012-02-22 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Feb 22 18:29:32 UTC 2012

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

Log Message:
use pmap_protect() instead of pmap_kenter_pa() to remap R/O an exiting
page. This gets rid of the last mapping already present warnings.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 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.82 src/sys/arch/xen/x86/cpu.c:1.83
--- src/sys/arch/xen/x86/cpu.c:1.82	Tue Feb 21 19:10:13 2012
+++ src/sys/arch/xen/x86/cpu.c	Wed Feb 22 18:29:31 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.82 2012/02/21 19:10:13 bouyer Exp $	*/
+/*	$NetBSD: cpu.c,v 1.83 2012/02/22 18:29:31 bouyer 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.82 2012/02/21 19:10:13 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.83 2012/02/22 18:29:31 bouyer Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1324,9 +1324,9 @@ pmap_cpu_init_late(struct cpu_info *ci)
 #endif /* __x86_64__ else PAE */
 
 	/* Xen wants R/O */
-	pmap_kenter_pa((vaddr_t)ci-ci_kpm_pdir, ci-ci_kpm_pdirpa,
-	VM_PROT_READ, 0);
-
+	pmap_protect(pmap_kernel(), (vaddr_t)ci-ci_kpm_pdir,
+	(vaddr_t)ci-ci_kpm_pdir + PAGE_SIZE, VM_PROT_READ);
+	pmap_update(pmap_kernel());
 #if defined(PAE)
 	/* Initialise L3 entry 3. This mapping is shared across all
 	 * pmaps and is static, ie; loading a new pmap will not update
@@ -1336,8 +1336,9 @@ 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) */
-	pmap_kenter_pa((vaddr_t)ci-ci_pae_l3_pdir, ci-ci_pae_l3_pdirpa,
-		VM_PROT_READ, 0);
+	pmap_protect(pmap_kernel(), (vaddr_t)ci-ci_pae_l3_pdir,
+	(vaddr_t)ci-ci_pae_l3_pdir + PAGE_SIZE, VM_PROT_READ);
+	pmap_update(pmap_kernel());
 
 	xpq_queue_pin_l3_table(xpmap_ptom_masked(ci-ci_pae_l3_pdirpa));
 



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/xen/x86

2012-02-13 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Mon Feb 13 23:54:58 UTC 2012

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

Log Message:
PAT flags are not under control of Xen domains currently, so there is no
point in enabling them.

Avoids:
- a warning logged by hypervisor when a domain attempts to modify the PAT
MSR.
- an error during domain resuming, where a PAT flag has been set on a page
while the hypervisor does not allow it.

ok releng@.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 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.79 src/sys/arch/xen/x86/cpu.c:1.80
--- src/sys/arch/xen/x86/cpu.c:1.79	Sat Jan 28 12:15:19 2012
+++ src/sys/arch/xen/x86/cpu.c	Mon Feb 13 23:54:58 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.79 2012/01/28 12:15:19 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.80 2012/02/13 23:54:58 jym 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.79 2012/01/28 12:15:19 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.80 2012/02/13 23:54:58 jym Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -532,7 +532,6 @@ cpu_attach_common(device_t parent, devic
 		panic(unknown processor type??\n);
 	}
 
-	pat_init(ci);
 	atomic_or_32(cpus_attached, ci-ci_cpumask);
 
 #ifdef MPVERBOSE



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/xen/x86

2012-01-19 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Jan 19 22:04:05 UTC 2012

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

Log Message:
add a missing splvm()/splx() to protect the xpq queue.


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

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

Modified files:

Index: src/sys/arch/xen/x86/xen_pmap.c
diff -u src/sys/arch/xen/x86/xen_pmap.c:1.13 src/sys/arch/xen/x86/xen_pmap.c:1.14
--- src/sys/arch/xen/x86/xen_pmap.c:1.13	Mon Jan  9 12:58:49 2012
+++ src/sys/arch/xen/x86/xen_pmap.c	Thu Jan 19 22:04:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_pmap.c,v 1.13 2012/01/09 12:58:49 cherry Exp $	*/
+/*	$NetBSD: xen_pmap.c,v 1.14 2012/01/19 22:04:05 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -102,7 +102,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: xen_pmap.c,v 1.13 2012/01/09 12:58:49 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_pmap.c,v 1.14 2012/01/19 22:04:05 bouyer Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -619,6 +619,7 @@ xen_kpm_sync(struct pmap *pmap, int inde
 	if (__predict_false(xpq_cpu != x86_curcpu)) { /* Too early to xcall */
 		CPU_INFO_ITERATOR cii;
 		struct cpu_info *ci;
+		int s = splvm();
 		for (CPU_INFO_FOREACH(cii, ci)) {
 			if (ci == NULL) {
 continue;
@@ -629,6 +630,7 @@ xen_kpm_sync(struct pmap *pmap, int inde
 			}
 		}
 		pmap_pte_flush();
+		splx(s);
 		return;
 	}
 



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/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/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

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-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-10-20 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Thu Oct 20 13:21:11 UTC 2011

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

Log Message:
Remove code that is commented out and out-of-sync with x86. If Xen needs to
use cpu_resume(), cpu_suspend(), or cpu_shutdown() in the future, it is
better to expose these from x86 rather than duplicate code.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 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.67 src/sys/arch/xen/x86/cpu.c:1.68
--- src/sys/arch/xen/x86/cpu.c:1.67	Thu Oct  6 06:56:30 2011
+++ src/sys/arch/xen/x86/cpu.c	Thu Oct 20 13:21:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.67 2011/10/06 06:56:30 mrg Exp $	*/
+/*	$NetBSD: cpu.c,v 1.68 2011/10/20 13:21:11 jruoho 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.67 2011/10/06 06:56:30 mrg Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.68 2011/10/20 13:21:11 jruoho Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -535,11 +535,6 @@ cpu_attach_common(device_t parent, devic
 	pat_init(ci);
 	atomic_or_32(cpus_attached, ci-ci_cpumask);
 
-#if 0
-	if (!pmf_device_register(self, cpu_suspend, cpu_resume))
-		aprint_error_dev(self, couldn't establish power handler\n);
-#endif
-
 #ifdef MPVERBOSE
 	if (mp_verbose) {
 		struct lwp *l = ci-ci_data.cpu_idlelwp;
@@ -1132,72 +1127,6 @@ cpu_offline_md(void)
 splx(s);
 }
 
-#if 0
-/* XXX joerg restructure and restart CPUs individually */
-static bool
-cpu_suspend(device_t dv, const pmf_qual_t *qual)
-{
-	struct cpu_softc *sc = device_private(dv);
-	struct cpu_info *ci = sc-sc_info;
-	int err;
-
-	if ((ci-ci_flags  CPUF_PRESENT) == 0)
-		return true;
-
-	cpufreq_suspend(ci);
-
-	if ((ci-ci_flags  CPUF_PRIMARY) != 0)
-		return true;
-
-	if (ci-ci_data.cpu_idlelwp == NULL)
-		return true;
-
-	sc-sc_wasonline = !(ci-ci_schedstate.spc_flags  SPCF_OFFLINE);
-
-	if (sc-sc_wasonline) {
-		mutex_enter(cpu_lock);
-		err = cpu_setstate(ci, false);
-		mutex_exit(cpu_lock);
-
-		if (err != 0)
-			return false;
-	}
-
-	return true;
-}
-
-static bool
-cpu_resume(device_t dv, const pmf_qual_t *qual)
-{
-	struct cpu_softc *sc = device_private(dv);
-	struct cpu_info *ci = sc-sc_info;
-	int err = 0;
-
-	if ((ci-ci_flags  CPUF_PRESENT) == 0)
-		return true;
-
-	if ((ci-ci_flags  CPUF_PRIMARY) != 0)
-		goto out;
-
-	if (ci-ci_data.cpu_idlelwp == NULL)
-		goto out;
-
-	if (sc-sc_wasonline) {
-		mutex_enter(cpu_lock);
-		err = cpu_setstate(ci, true);
-		mutex_exit(cpu_lock);
-	}
-
-out:
-	if (err != 0)
-		return false;
-
-	cpufreq_resume(ci);
-
-	return true;
-}
-#endif
-
 void
 cpu_get_tsc_freq(struct cpu_info *ci)
 {



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

2011-08-21 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Sun Aug 21 10:00:13 UTC 2011

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

Log Message:
Merge err printf with the panic(9) message.

Also fix the if () {...} statement with braces, to avoid calling panic()
every time. Hi cherry!


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 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.32 src/sys/arch/xen/x86/x86_xpmap.c:1.33
--- src/sys/arch/xen/x86/x86_xpmap.c:1.32	Sat Aug 13 20:24:19 2011
+++ src/sys/arch/xen/x86/x86_xpmap.c	Sun Aug 21 10:00:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.32 2011/08/13 20:24:19 cherry Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.33 2011/08/21 10:00:13 jym 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.32 2011/08/13 20:24:19 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.33 2011/08/21 10:00:13 jym Exp $);
 
 #include opt_xen.h
 #include opt_ddb.h
@@ -343,9 +343,9 @@
 
 	XENPRINTK2((xpq_queue_flush_cache\n));
 	op.cmd = MMUEXT_FLUSH_CACHE;
-	if ((err = HYPERVISOR_mmuext_op(op, 1, NULL, DOMID_SELF))  0)
-		printf(errno == %d\n, err);
-		panic(xpq_flush_cache);
+	if ((err = HYPERVISOR_mmuext_op(op, 1, NULL, DOMID_SELF))  0) {
+		panic(xpq_flush_cache, err %d, err);
+	}
 	xpq_queue_unlock();
 	splx(s); /* XXX: removeme */
 }



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

2011-08-15 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Aug 15 20:14:52 UTC 2011

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

Log Message:
Do not panic() on xen_send_ipi() sent to a cpu not yet running.
x86 MP boot depends on this strange behaviour.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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.62 src/sys/arch/xen/x86/cpu.c:1.63
--- src/sys/arch/xen/x86/cpu.c:1.62	Sat Aug 13 12:37:30 2011
+++ src/sys/arch/xen/x86/cpu.c	Mon Aug 15 20:14:52 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.62 2011/08/13 12:37:30 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.63 2011/08/15 20:14:52 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.62 2011/08/13 12:37:30 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.63 2011/08/15 20:14:52 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1292,8 +1292,5 @@
 void
 cpu_kick(struct cpu_info *ci)
 {
-	if (xen_send_ipi(ci, XEN_IPI_KICK) != 0) {
-		panic(xen_send_ipi(%s, XEN_IPI_KICK) failed\n,
-		cpu_name(ci));
-	}
+	xen_send_ipi(ci, XEN_IPI_KICK);
 }



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

2011-08-15 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Aug 15 20:17:12 UTC 2011

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

Log Message:
invert buggy ci_flag test


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 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.3 src/sys/arch/xen/x86/xen_ipi.c:1.4
--- src/sys/arch/xen/x86/xen_ipi.c:1.3	Wed Aug 10 20:38:45 2011
+++ src/sys/arch/xen/x86/xen_ipi.c	Mon Aug 15 20:17:12 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.3 2011/08/10 20:38:45 cherry Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.4 2011/08/15 20:17:12 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.3 2011/08/10 20:38:45 cherry Exp $); 
+ * __KERNEL_RCSID(0, $NetBSD: xen_ipi.c,v 1.4 2011/08/15 20:17:12 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.4 2011/08/15 20:17:12 cherry Exp $);
 
 #include sys/types.h
 
@@ -158,7 +158,7 @@
 
 	KASSERT(ci != NULL || ci != curcpu());
 
-	if ((ci-ci_flags  CPUF_RUNNING) != 0) {
+	if ((ci-ci_flags  CPUF_RUNNING) == 0) {
 		return ENOENT;
 	}
 



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

2011-08-15 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Aug 16 02:59:16 UTC 2011

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

Log Message:
Fix broken build.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 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.63 src/sys/arch/xen/x86/cpu.c:1.64
--- src/sys/arch/xen/x86/cpu.c:1.63	Mon Aug 15 20:14:52 2011
+++ src/sys/arch/xen/x86/cpu.c	Tue Aug 16 02:59:16 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.63 2011/08/15 20:14:52 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.64 2011/08/16 02:59:16 dholland 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.63 2011/08/15 20:14:52 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.64 2011/08/16 02:59:16 dholland Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1292,5 +1292,5 @@
 void
 cpu_kick(struct cpu_info *ci)
 {
-	xen_send_ipi(ci, XEN_IPI_KICK);
+	(void)xen_send_ipi(ci, XEN_IPI_KICK);
 }



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

2011-08-13 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Aug 13 16:22:15 UTC 2011

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

Log Message:
Remove spurious header.
Thanks rmind@


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/xen/x86/intr.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/intr.c
diff -u src/sys/arch/xen/x86/intr.c:1.28 src/sys/arch/xen/x86/intr.c:1.29
--- src/sys/arch/xen/x86/intr.c:1.28	Thu Aug 11 17:59:00 2011
+++ src/sys/arch/xen/x86/intr.c	Sat Aug 13 16:22:15 2011
@@ -103,7 +103,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: intr.c,v 1.28 2011/08/11 17:59:00 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: intr.c,v 1.29 2011/08/13 16:22:15 cherry Exp $);
 
 #include opt_multiprocessor.h
 #include opt_xen.h
@@ -119,7 +119,6 @@
 #include sys/proc.h
 #include sys/errno.h
 #include sys/cpu.h
-#include sys/simplelock.h
 
 #include uvm/uvm_extern.h
 



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

2011-08-13 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Aug 13 20:24:19 UTC 2011

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

Log Message:
Call the right function
(fix for an egregious error)


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 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.31 src/sys/arch/xen/x86/x86_xpmap.c:1.32
--- src/sys/arch/xen/x86/x86_xpmap.c:1.31	Sat Aug 13 12:09:38 2011
+++ src/sys/arch/xen/x86/x86_xpmap.c	Sat Aug 13 20:24:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.31 2011/08/13 12:09:38 cherry Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.32 2011/08/13 20:24:19 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.31 2011/08/13 12:09:38 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.32 2011/08/13 20:24:19 cherry Exp $);
 
 #include opt_xen.h
 #include opt_ddb.h
@@ -185,7 +185,7 @@
 bool
 xpq_queue_locked(void)
 {
-	return xpq_queue_locked();
+	return simple_lock_held(xpq_lock);
 }
 #endif /* MULTIPROCESSOR */
 



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/x86

2011-07-31 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Sun Jul 31 18:00:54 UTC 2011

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

Log Message:
Fix typo in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/xen/x86/xen_shm_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/xen_shm_machdep.c
diff -u src/sys/arch/xen/x86/xen_shm_machdep.c:1.8 src/sys/arch/xen/x86/xen_shm_machdep.c:1.9
--- src/sys/arch/xen/x86/xen_shm_machdep.c:1.8	Sun Mar 28 20:46:18 2010
+++ src/sys/arch/xen/x86/xen_shm_machdep.c	Sun Jul 31 18:00:54 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: xen_shm_machdep.c,v 1.8 2010/03/28 20:46:18 snj Exp $  */
+/*  $NetBSD: xen_shm_machdep.c,v 1.9 2011/07/31 18:00:54 jym Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: xen_shm_machdep.c,v 1.8 2010/03/28 20:46:18 snj Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_shm_machdep.c,v 1.9 2011/07/31 18:00:54 jym Exp $);
 
 
 #include sys/types.h
@@ -48,7 +48,7 @@
  * functions to map a bunch of pages from foreign domains in our kernel VM
  * space, do I/O to it, and unmap it.
  *
- * At boot time, we grap some kernel VM space that we'll use to map the foreign
+ * At boot time, we grab some kernel VM space that we'll use to map the foreign
  * pages. We also maintain a virtual to machine mapping table to give back
  * the appropriate address to bus_dma if requested.
  * If no more VM space is available, we return an error. The caller can then



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

2011-07-16 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Sat Jul 16 14:46:18 UTC 2011

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

Log Message:
Initialise cpus_running to 1 on Xen, as it was done on x86.

Problem analysed by hannken@.  Fixes PR/45062.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 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.59 src/sys/arch/xen/x86/cpu.c:1.60
--- src/sys/arch/xen/x86/cpu.c:1.59	Wed Jun 15 20:50:02 2011
+++ src/sys/arch/xen/x86/cpu.c	Sat Jul 16 14:46:18 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.59 2011/06/15 20:50:02 rmind Exp $	*/
+/*	$NetBSD: cpu.c,v 1.60 2011/07/16 14:46:18 rmind 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.59 2011/06/15 20:50:02 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.60 2011/07/16 14:46:18 rmind Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -174,7 +174,7 @@
 static void	cpu_set_tss_gates(struct cpu_info *ci);
 
 uint32_t cpus_attached = 1;
-uint32_t cpus_running = 0;
+uint32_t cpus_running = 1;
 
 uint32_t phycpus_attached = 0;
 uint32_t phycpus_running = 0;



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

2011-07-01 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Fri Jul  1 18:37:09 UTC 2011

Modified Files:
src/sys/arch/xen/x86: consinit.c mainbus.c xen_bus_dma.c

Log Message:
#include sys/bus.h instead of machine/bus.h.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/xen/x86/consinit.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/xen/x86/mainbus.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/xen/x86/xen_bus_dma.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/consinit.c
diff -u src/sys/arch/xen/x86/consinit.c:1.14 src/sys/arch/xen/x86/consinit.c:1.15
--- src/sys/arch/xen/x86/consinit.c:1.14	Wed Apr 28 19:17:04 2010
+++ src/sys/arch/xen/x86/consinit.c	Fri Jul  1 18:37:08 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: consinit.c,v 1.14 2010/04/28 19:17:04 dyoung Exp $	*/
+/*	$NetBSD: consinit.c,v 1.15 2011/07/01 18:37:08 dyoung Exp $	*/
 /*	NetBSD: consinit.c,v 1.4 2004/03/13 17:31:34 bjh21 Exp 	*/
 
 /*
@@ -28,14 +28,14 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: consinit.c,v 1.14 2010/04/28 19:17:04 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: consinit.c,v 1.15 2011/07/01 18:37:08 dyoung Exp $);
 
 #include opt_kgdb.h
 
 #include sys/param.h
 #include sys/systm.h
 #include sys/device.h
-#include machine/bus.h
+#include sys/bus.h
 #include machine/bootinfo.h
 
 #include xencons.h

Index: src/sys/arch/xen/x86/mainbus.c
diff -u src/sys/arch/xen/x86/mainbus.c:1.13 src/sys/arch/xen/x86/mainbus.c:1.14
--- src/sys/arch/xen/x86/mainbus.c:1.13	Fri Nov 12 02:07:27 2010
+++ src/sys/arch/xen/x86/mainbus.c	Fri Jul  1 18:37:08 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: mainbus.c,v 1.13 2010/11/12 02:07:27 dholland Exp $	*/
+/*	$NetBSD: mainbus.c,v 1.14 2011/07/01 18:37:08 dyoung Exp $	*/
 /*	NetBSD: mainbus.c,v 1.53 2003/10/27 14:11:47 junyoung Exp 	*/
 
 /*
@@ -32,13 +32,13 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: mainbus.c,v 1.13 2010/11/12 02:07:27 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: mainbus.c,v 1.14 2011/07/01 18:37:08 dyoung Exp $);
 
 #include sys/param.h
 #include sys/systm.h
 #include sys/device.h
 
-#include machine/bus.h
+#include sys/bus.h
 
 #include hypervisor.h
 #include pci.h

Index: src/sys/arch/xen/x86/xen_bus_dma.c
diff -u src/sys/arch/xen/x86/xen_bus_dma.c:1.22 src/sys/arch/xen/x86/xen_bus_dma.c:1.23
--- src/sys/arch/xen/x86/xen_bus_dma.c:1.22	Fri Nov 12 10:51:14 2010
+++ src/sys/arch/xen/x86/xen_bus_dma.c	Fri Jul  1 18:37:08 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_bus_dma.c,v 1.22 2010/11/12 10:51:14 njoly Exp $	*/
+/*	$NetBSD: xen_bus_dma.c,v 1.23 2011/07/01 18:37:08 dyoung Exp $	*/
 /*	NetBSD bus_dma.c,v 1.21 2005/04/16 07:53:35 yamt Exp */
 
 /*-
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: xen_bus_dma.c,v 1.22 2010/11/12 10:51:14 njoly Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_bus_dma.c,v 1.23 2011/07/01 18:37:08 dyoung Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -40,7 +40,7 @@
 #include sys/mbuf.h
 #include sys/proc.h
 
-#include machine/bus.h
+#include sys/bus.h
 #include machine/bus_private.h
 
 #include uvm/uvm.h



  1   2   >