CVS commit: [netbsd-6-0] src/sys/arch/xen/xen

2012-10-31 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Wed Oct 31 16:15:28 UTC 2012

Modified Files:
src/sys/arch/xen/xen [netbsd-6-0]: xengnt.c

Log Message:
Pull up following revision(s) (requested by royger in ticket #640):
sys/arch/xen/xen/xengnt.c: revision 1.25
xen: don't use grants 0-8
Not all grants from the first frame can be used, grants from 0 to 8
(both included) are reserved for external tools. Using this grants
caused system crashes and fs corruption.
Closes PR port-xen/47057 and port-xen/47056
Reviewed by bouyer@


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.1 -r1.22.2.1.4.1 src/sys/arch/xen/xen/xengnt.c

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

Modified files:

Index: src/sys/arch/xen/xen/xengnt.c
diff -u src/sys/arch/xen/xen/xengnt.c:1.22.2.1 src/sys/arch/xen/xen/xengnt.c:1.22.2.1.4.1
--- src/sys/arch/xen/xen/xengnt.c:1.22.2.1	Thu Feb 23 21:19:55 2012
+++ src/sys/arch/xen/xen/xengnt.c	Wed Oct 31 16:15:28 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: xengnt.c,v 1.22.2.1 2012/02/23 21:19:55 riz Exp $  */
+/*  $NetBSD: xengnt.c,v 1.22.2.1.4.1 2012/10/31 16:15:28 riz Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.22.2.1 2012/02/23 21:19:55 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.22.2.1.4.1 2012/10/31 16:15:28 riz Exp $");
 
 #include 
 #include 
@@ -51,6 +51,9 @@ __KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1
 
 #define NR_GRANT_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_t))
 
+/* External tools reserve first few grant table entries. */
+#define NR_RESERVED_ENTRIES 8
+
 /* Current number of frames making up the grant table */
 int gnt_nr_grant_frames;
 /* Maximum number of frames that can make up the grant table */
@@ -161,7 +164,7 @@ xengnt_more_entries(void)
 	gnttab_setup_table_t setup;
 	u_long *pages;
 	int nframes_new = gnt_nr_grant_frames + 1;
-	int i;
+	int i, start_gnt;
 	KASSERT(mutex_owned(&grant_lock));
 
 	if (gnt_nr_grant_frames == gnt_max_grant_frames)
@@ -204,9 +207,14 @@ xengnt_more_entries(void)
 
 	/*
 	 * add the grant entries associated to the last grant table frame
-	 * and mark them as free
+	 * and mark them as free. Prevent using the first grants (from 0 to 8)
+	 * since they are used by the tools.
 	 */
-	for (i = gnt_nr_grant_frames * NR_GRANT_ENTRIES_PER_PAGE;
+	start_gnt = (gnt_nr_grant_frames * NR_GRANT_ENTRIES_PER_PAGE) <
+	(NR_RESERVED_ENTRIES + 1) ?
+	(NR_RESERVED_ENTRIES + 1) :
+	(gnt_nr_grant_frames * NR_GRANT_ENTRIES_PER_PAGE);
+	for (i = start_gnt;
 	i < nframes_new * NR_GRANT_ENTRIES_PER_PAGE;
 	i++) {
 		KASSERT(gnt_entries[last_gnt_entry] == XENGNT_NO_ENTRY);
@@ -240,7 +248,7 @@ xengnt_get_entry(void)
 	last_gnt_entry--;
 	entry = gnt_entries[last_gnt_entry];
 	gnt_entries[last_gnt_entry] = XENGNT_NO_ENTRY;
-	KASSERT(entry != XENGNT_NO_ENTRY);
+	KASSERT(entry != XENGNT_NO_ENTRY && entry > NR_RESERVED_ENTRIES);
 	KASSERT(last_gnt_entry >= 0);
 	KASSERT(last_gnt_entry <= gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE);
 	return entry;
@@ -253,6 +261,7 @@ static void
 xengnt_free_entry(grant_ref_t entry)
 {
 	mutex_enter(&grant_lock);
+	KASSERT(entry > NR_RESERVED_ENTRIES);
 	KASSERT(gnt_entries[last_gnt_entry] == XENGNT_NO_ENTRY);
 	KASSERT(last_gnt_entry >= 0);
 	KASSERT(last_gnt_entry <= gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE);



CVS commit: [netbsd-6-0] src/sys/arch/xen/xen

2015-11-15 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Nov 16 07:53:01 UTC 2015

Modified Files:
src/sys/arch/xen/xen [netbsd-6-0]: xbdback_xenbus.c

Log Message:
Pull up following revision(s) (requested by bouyer in ticket #1347):
sys/arch/xen/xen/xbdback_xenbus.c: revision 1.61
Fix typo which caused the kenrel thread to be created with a 0 priority.
This would cause the thread to be almost never scheduled when a userland
process could use all CPU.
Should fix the problem reported by Torbj?rn Granlund on port-xen@


To generate a diff of this commit:
cvs rdiff -u -r1.55.2.1.4.1 -r1.55.2.1.4.2 \
src/sys/arch/xen/xen/xbdback_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/xbdback_xenbus.c
diff -u src/sys/arch/xen/xen/xbdback_xenbus.c:1.55.2.1.4.1 src/sys/arch/xen/xen/xbdback_xenbus.c:1.55.2.1.4.2
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.55.2.1.4.1	Thu Nov  7 20:18:50 2013
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Mon Nov 16 07:53:01 2015
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.55.2.1.4.1 2013/11/07 20:18:50 snj Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.55.2.1.4.2 2015/11/16 07:53:01 msaitoh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.55.2.1.4.1 2013/11/07 20:18:50 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.55.2.1.4.2 2015/11/16 07:53:01 msaitoh Exp $");
 
 #include 
 #include 
@@ -648,7 +648,7 @@ xbdback_connect(struct xbdback_instance 
 	hypervisor_enable_event(xbdi->xbdi_evtchn);
 	hypervisor_notify_via_evtchn(xbdi->xbdi_evtchn);
 
-	if (kthread_create(IPL_NONE, KTHREAD_MPSAFE, NULL,
+	if (kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL,
 	xbdback_thread, xbdi, NULL, "%s", xbdi->xbdi_name) == 0)
 		return 0;
 



CVS commit: [netbsd-6-0] src/sys/arch/xen/xen

2015-05-26 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed May 27 05:57:14 UTC 2015

Modified Files:
src/sys/arch/xen/xen [netbsd-6-0]: xenevt.c

Log Message:
Pull up following revision(s) (requested by bouyer in ticket #1299):
sys/arch/xen/xen/xenevt.c: revision 1.42
Fix off by one error, pointed out by Wei Liu in port-xen/49919


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.39.10.1 src/sys/arch/xen/xen/xenevt.c

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

Modified files:

Index: src/sys/arch/xen/xen/xenevt.c
diff -u src/sys/arch/xen/xen/xenevt.c:1.39 src/sys/arch/xen/xen/xenevt.c:1.39.10.1
--- src/sys/arch/xen/xen/xenevt.c:1.39	Sat Dec  3 22:41:40 2011
+++ src/sys/arch/xen/xen/xenevt.c	Wed May 27 05:57:14 2015
@@ -1,4 +1,4 @@
-/*  $NetBSD: xenevt.c,v 1.39 2011/12/03 22:41:40 bouyer Exp $  */
+/*  $NetBSD: xenevt.c,v 1.39.10.1 2015/05/27 05:57:14 msaitoh Exp $  */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.39 2011/12/03 22:41:40 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.39.10.1 2015/05/27 05:57:14 msaitoh Exp $");
 
 #include "opt_xen.h"
 #include 
@@ -479,7 +479,7 @@ xenevt_fwrite(struct file *fp, off_t *of
 	if (uio->uio_resid == 0)
 		return (0);
 	nentries = uio->uio_resid / sizeof(uint16_t);
-	if (nentries > NR_EVENT_CHANNELS)
+	if (nentries >= NR_EVENT_CHANNELS)
 		return EMSGSIZE;
 	chans = kmem_alloc(nentries * sizeof(uint16_t), KM_SLEEP);
 	if (chans == NULL)
@@ -572,7 +572,7 @@ xenevt_fioctl(struct file *fp, u_long cm
 	{
 		struct ioctl_evtchn_unbind *unbind = addr;
 		
-		if (unbind->port > NR_EVENT_CHANNELS)
+		if (unbind->port >= NR_EVENT_CHANNELS)
 			return EINVAL;
 		mutex_enter(&devevent_lock);
 		if (devevent[unbind->port] != d) {
@@ -593,7 +593,7 @@ xenevt_fioctl(struct file *fp, u_long cm
 	{
 		struct ioctl_evtchn_notify *notify = addr;
 		
-		if (notify->port > NR_EVENT_CHANNELS)
+		if (notify->port >= NR_EVENT_CHANNELS)
 			return EINVAL;
 		mutex_enter(&devevent_lock);
 		if (devevent[notify->port] != d) {



CVS commit: [netbsd-6-0] src/sys/arch/xen/xen

2013-12-17 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Tue Dec 17 22:39:49 UTC 2013

Modified Files:
src/sys/arch/xen/xen [netbsd-6-0]: evtchn.c

Log Message:
Pull up following revision(s) (requested by bouyer in ticket #995):
sys/arch/xen/xen/evtchn.c: revision 1.70
Remove the "evtchn_do_event: handler %p didn't lower ipl %d %d\n" printf.
With help from Robert Elz we've finally figured out what's going on, and
it actually isn't a bug in the handler, but related to spin mutexes.
When a spin mutex is released, the IPL isn't lowered back if the
curcpu is holding other spin mutexes. This is because mutexes may not
be released in order (and, in this case, the CPU in interrupted while
it holds a spin mutex at IPL < IPL_SCHED).
Also remove the test and resetting the IPL, it will be reset anyway
inside the loop, or at the end of the loop.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.62.8.1 src/sys/arch/xen/xen/evtchn.c

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

Modified files:

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.62 src/sys/arch/xen/xen/evtchn.c:1.62.8.1
--- src/sys/arch/xen/xen/evtchn.c:1.62	Sun Feb 12 14:24:08 2012
+++ src/sys/arch/xen/xen/evtchn.c	Tue Dec 17 22:39:49 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.62 2012/02/12 14:24:08 jym Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.62.8.1 2013/12/17 22:39:49 riz Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.62 2012/02/12 14:24:08 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.62.8.1 2013/12/17 22:39:49 riz Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -347,13 +347,6 @@ splx:
 	ih_fun = (void *)ih->ih_fun;
 	ih_fun(ih->ih_arg, regs);
 	cli();
-	if (ci->ci_ilevel != i) {
-		printf("evtchn_do_event: "
-		"handler %p didn't lower "
-		"ipl %d %d\n",
-		ih_fun, ci->ci_ilevel, i);
-		ci->ci_ilevel = i;
-	}
 }
 hypervisor_enable_ipl(i);
 /* more pending IPLs may have been registered */



CVS commit: [netbsd-6-0] src/sys/arch/xen/xen

2013-11-07 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Thu Nov  7 20:18:50 UTC 2013

Modified Files:
src/sys/arch/xen/xen [netbsd-6-0]: xbdback_xenbus.c

Log Message:
Pull up following revision(s) (requested by bouyer in ticket #974):
sys/arch/xen/xen/xbdback_xenbus.c: revision 1.58
Add more XENPRINTF() to xbdback_connect()
in xbdback_backend_changed(), fix memory leak.
Do not free an uninitialized pointer in xbdback_connect(). Should fix
 hypervisor or dom0 reboot when using windows PV drivers, as reported
 by several users on port-xen.


To generate a diff of this commit:
cvs rdiff -u -r1.55.2.1 -r1.55.2.1.4.1 src/sys/arch/xen/xen/xbdback_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/xbdback_xenbus.c
diff -u src/sys/arch/xen/xen/xbdback_xenbus.c:1.55.2.1 src/sys/arch/xen/xen/xbdback_xenbus.c:1.55.2.1.4.1
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.55.2.1	Tue Jun  5 15:36:00 2012
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Thu Nov  7 20:18:50 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.55.2.1 2012/06/05 15:36:00 jdc Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.55.2.1.4.1 2013/11/07 20:18:50 snj Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.55.2.1 2012/06/05 15:36:00 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.55.2.1.4.1 2013/11/07 20:18:50 snj Exp $");
 
 #include 
 #include 
@@ -531,6 +531,7 @@ xbdback_connect(struct xbdback_instance 
 	const char *proto;
 	struct xenbus_device *xbusd = xbdi->xbdi_xbusd;
 
+	XENPRINTF(("xbdback %s: connect\n", xbusd->xbusd_path));
 	/* read comunication informations */
 	err = xenbus_read_ul(NULL, xbusd->xbusd_otherend,
 	"ring-ref", &ring_ref, 10);
@@ -539,6 +540,7 @@ xbdback_connect(struct xbdback_instance 
 		xbusd->xbusd_otherend);
 		return -1;
 	}
+	XENPRINTF(("xbdback %s: connect ring-ref %lu\n", xbusd->xbusd_path, ring_ref));
 	err = xenbus_read_ul(NULL, xbusd->xbusd_otherend,
 	"event-channel", &revtchn, 10);
 	if (err) {
@@ -546,12 +548,15 @@ xbdback_connect(struct xbdback_instance 
 		xbusd->xbusd_otherend);
 		return -1;
 	}
+	XENPRINTF(("xbdback %s: connect revtchn %lu\n", xbusd->xbusd_path, revtchn));
 	err = xenbus_read(NULL, xbusd->xbusd_otherend, "protocol",
 	&len, &xsproto);
 	if (err) {
 		xbdi->xbdi_proto = XBDIP_NATIVE;
 		proto = "unspecified";
+		XENPRINTF(("xbdback %s: connect no xsproto\n", xbusd->xbusd_path));
 	} else {
+		XENPRINTF(("xbdback %s: connect xsproto %s\n", xbusd->xbusd_path, xsproto));
 		if (strcmp(xsproto, XEN_IO_PROTO_ABI_NATIVE) == 0) {
 			xbdi->xbdi_proto = XBDIP_NATIVE;
 			proto = XEN_IO_PROTO_ABI_NATIVE;
@@ -567,8 +572,8 @@ xbdback_connect(struct xbdback_instance 
 			free(xsproto, M_DEVBUF);
 			return -1;
 		}
+		free(xsproto, M_DEVBUF);
 	}
-	free(xsproto, M_DEVBUF);
 
 	/* allocate VA space and map rings */
 	xbdi->xbdi_ring_va = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
@@ -578,6 +583,7 @@ xbdback_connect(struct xbdback_instance 
 		"can't get VA for ring", xbusd->xbusd_otherend);
 		return -1;
 	}
+	XENPRINTF(("xbdback %s: connect va 0x%" PRIxVADDR "\n", xbusd->xbusd_path, xbdi->xbdi_ring_va));
 
 	grop.host_addr = xbdi->xbdi_ring_va;
 	grop.flags = GNTMAP_host_map;
@@ -593,6 +599,7 @@ xbdback_connect(struct xbdback_instance 
 		goto err;
 	}
 	xbdi->xbdi_ring_handle = grop.handle;
+	XENPRINTF(("xbdback %s: connect grhandle %d\n", xbusd->xbusd_path, grop.handle));
 
 	switch(xbdi->xbdi_proto) {
 	case XBDIP_NATIVE:
@@ -627,6 +634,7 @@ xbdback_connect(struct xbdback_instance 
 		"can't bind event channel", xbusd->xbusd_otherend);
 		goto err2;
 	}
+	XENPRINTF(("xbdback %s: connect evchannel %d\n", xbusd->xbusd_path, xbdi->xbdi_evtchn));
 	xbdi->xbdi_evtchn = evop.u.bind_interdomain.local_port;
 
 	event_set_handler(xbdi->xbdi_evtchn, xbdback_evthandler,
@@ -766,6 +774,7 @@ xbdback_backend_changed(struct xenbus_wa
 		xbdi->xbdi_ro = false;
 	else
 		xbdi->xbdi_ro = true;
+	free(mode, M_DEVBUF);
 	major = major(xbdi->xbdi_dev);
 	devname = devsw_blk2name(major);
 	if (devname == NULL) {