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

2021-07-28 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Jul 28 22:17:49 UTC 2021

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

Log Message:
fix off-by-one check in another KASSERT() for bcount

still related to PR port-xen/56328


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 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.98 src/sys/arch/xen/xen/xbdback_xenbus.c:1.99
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.98	Wed Jul 28 21:38:50 2021
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Wed Jul 28 22:17:49 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.98 2021/07/28 21:38:50 jdolecek Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.99 2021/07/28 22:17:49 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.98 2021/07/28 21:38:50 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.99 2021/07/28 22:17:49 jdolecek Exp $");
 
 #include 
 #include 
@@ -1311,7 +1311,7 @@ xbdback_co_io_gotio(struct xbdback_insta
 
 	KASSERT(bcount <= MAXPHYS);
 	KASSERT(xbd_io->xio_start_offset < PAGE_SIZE);
-	KASSERT(bcount + xbd_io->xio_start_offset < VBD_VA_SIZE);
+	KASSERT(bcount + xbd_io->xio_start_offset <= VBD_VA_SIZE);
 
 	/* Fill-in the buf */
 	if (xbdi->xbdi_xen_req.operation == BLKIF_OP_WRITE) {



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

2021-07-28 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Jul 28 21:38:50 UTC 2021

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

Log Message:
fix intentional, but eventually faulty off-by-one for the maximum number
of segments for I/O - this was supposed to allow MAXPHYS-size I/O even
with page offset, but actually ended up letting through I/O up to
MAXPHYS+PAGE_SIZE

the KASSERT(bcount < MAXPHYS) is kept as-is, since at that place the number
of segments should already be validated, so it's kernel bug if the size
is still too big there

fixes PR port-xen/56328 by Greg Oster


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 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.97 src/sys/arch/xen/xen/xbdback_xenbus.c:1.98
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.97	Sun Feb 21 20:02:25 2021
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Wed Jul 28 21:38:50 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.97 2021/02/21 20:02:25 jdolecek Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.98 2021/07/28 21:38:50 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.97 2021/02/21 20:02:25 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.98 2021/07/28 21:38:50 jdolecek Exp $");
 
 #include 
 #include 
@@ -71,8 +71,7 @@ __KERNEL_RCSID(0, "$NetBSD: xbdback_xenb
 #define VBD_BSIZE 512
 #define VBD_MAXSECT ((PAGE_SIZE / VBD_BSIZE) - 1)
 
-/* Need to alloc one extra page to account for possible mapping offset */
-#define VBD_VA_SIZE	(MAXPHYS + PAGE_SIZE)
+#define VBD_VA_SIZE			MAXPHYS
 #define VBD_MAX_INDIRECT_SEGMENTS	VBD_VA_SIZE >> PAGE_SHIFT
 
 CTASSERT(XENSHM_MAX_PAGES_PER_REQUEST >= VBD_MAX_INDIRECT_SEGMENTS);



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

2021-06-16 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Jun 16 10:49:50 UTC 2021

Modified Files:
src/sys/arch/xen/xenbus: xenbus_probe.c

Log Message:
Grab KERNEL_LOCK before calling config_found()


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/xen/xenbus/xenbus_probe.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/xenbus/xenbus_probe.c
diff -u src/sys/arch/xen/xenbus/xenbus_probe.c:1.56 src/sys/arch/xen/xenbus/xenbus_probe.c:1.57
--- src/sys/arch/xen/xenbus/xenbus_probe.c:1.56	Sat Apr 24 23:36:52 2021
+++ src/sys/arch/xen/xenbus/xenbus_probe.c	Wed Jun 16 10:49:50 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_probe.c,v 1.56 2021/04/24 23:36:52 thorpej Exp $ */
+/* $NetBSD: xenbus_probe.c,v 1.57 2021/06/16 10:49:50 bouyer Exp $ */
 /**
  * Talks to Xen Store to figure out what devices we have.
  *
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.56 2021/04/24 23:36:52 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.57 2021/06/16 10:49:50 bouyer Exp $");
 
 #if 0
 #define DPRINTK(fmt, args...) \
@@ -469,8 +469,11 @@ xenbus_probe_device_type(const char *pat
 kmem_free(xbusd, xbusd->xbusd_sz);
 break;
 			}
+
+			KERNEL_LOCK(1, curlwp);
 			xbusd->xbusd_u.f.f_dev = config_found(xenbus_dev,
 			, xenbus_print, CFARG_EOL);
+			KERNEL_UNLOCK_ONE(curlwp);
 			if (xbusd->xbusd_u.f.f_dev == NULL) {
 kmem_free(xbusd, xbusd->xbusd_sz);
 continue;
@@ -652,8 +655,10 @@ xenbus_probe(void *unused)
 	register_xenbus_watch(_watch);
 
 	/* attach balloon. */
+	KERNEL_LOCK(1, curlwp);
 	config_found(xenbus_dev, _xa, xenbus_print,
 	CFARG_EOL);
+	KERNEL_UNLOCK_ONE(curlwp);
 
 	shutdown_xenbus_setup();
 



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

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

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

Log Message:
reset xio_xv before calling xbdback_io_error() so it won't try to unmap
the non-initialized handles when xen_shm_map() fails

remove the ratechecked error printf for shm error - xbdback_io_error() prints
the error too

part of fixes for XSA-362


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 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.96 src/sys/arch/xen/xen/xbdback_xenbus.c:1.97
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.96	Thu May  7 19:49:29 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Sun Feb 21 20:02:25 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.96 2020/05/07 19:49:29 bouyer Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.97 2021/02/21 20:02:25 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.96 2020/05/07 19:49:29 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.97 2021/02/21 20:02:25 jdolecek Exp $");
 
 #include 
 #include 
@@ -1570,13 +1570,11 @@ xbdback_map_shm(struct xbdback_io *xbd_i
 #endif
 		return xbd_io;
 	default:
-		if (ratecheck(>xbdi_lasterr_time, _err_intvl)) {
-			printf("xbdback_map_shm: xen_shm error %d ", error);
-		}
-		/* this will also free xbd_io via xbdback_iodone() */
-		xbdback_io_error(xbd_io, error);
+		/* reset xio_xv so error handling won't try to unmap it */
 		SLIST_INSERT_HEAD(>xbdi_va_free, xbd_io->xio_xv, xv_next);
 		xbd_io->xio_xv = NULL;
+		/* this will also free xbd_io via xbdback_iodone() */
+		xbdback_io_error(xbd_io, error);
 		/* do not retry */
 		xbdi->xbdi_cont = xbdback_co_main_incr;
 		return xbdi;



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

2020-11-30 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Nov 30 17:05:02 UTC 2020

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

Log Message:
Switch some debug/informational printf to device_printf(). Usefull
for multiprocessor environnement.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/xen/xen/xen_clock.c

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

Modified files:

Index: src/sys/arch/xen/xen/xen_clock.c
diff -u src/sys/arch/xen/xen/xen_clock.c:1.7 src/sys/arch/xen/xen/xen_clock.c:1.8
--- src/sys/arch/xen/xen/xen_clock.c:1.7	Fri May 22 17:44:05 2020
+++ src/sys/arch/xen/xen/xen_clock.c	Mon Nov 30 17:05:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_clock.c,v 1.7 2020/05/22 17:44:05 riastradh Exp $	*/
+/*	$NetBSD: xen_clock.c,v 1.8 2020/11/30 17:05:02 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2017, 2018 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.7 2020/05/22 17:44:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.8 2020/11/30 17:05:02 bouyer Exp $");
 
 #include 
 #include 
@@ -278,7 +278,7 @@ xen_vcputime_systime_ns(void)
 		 * run behind Xen's idea of it, and pretend it hadn't.
 		 */
 #if XEN_CLOCK_DEBUG		/* XXX dtrace hook */
-		printf("xen cpu tsc %"PRIu64
+		device_printf(ci->ci_dev, "xen cpu tsc %"PRIu64
 		" ran backwards from timestamp %"PRIu64
 		" by %"PRIu64"\n",
 		tsc, tsc_timestamp, tsc_timestamp - tsc);
@@ -302,7 +302,7 @@ xen_vcputime_systime_ns(void)
 	 */
 	if (__predict_false((int64_t)delta_ns < 0)) {
 #if XEN_CLOCK_DEBUG		/* XXX dtrace hook */
-		printf("xen tsc delta in ns went negative: %"PRId64"\n",
+		device_printf(ci->ci_dev, "xen tsc delta in ns went negative: %"PRId64"\n",
 		delta_ns);
 #endif
 		ci->ci_xen_tsc_delta_negative_evcnt.ev_count++;
@@ -693,7 +693,7 @@ again:
 	now = xen_vcputime_systime_ns();
 	if (now < last) {
 #if XEN_CLOCK_DEBUG		/* XXX dtrace hook */
-		printf("xen systime ran backwards in hardclock %"PRIu64"ns\n",
+		device_printf(ci->ci_dev, "xen systime ran backwards in hardclock %"PRIu64"ns\n",
 		last - now);
 #endif
 		ci->ci_xen_systime_backwards_hardclock_evcnt.ev_count++;



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

2020-11-15 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sun Nov 15 14:01:06 UTC 2020

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

Log Message:
Don't restrict debug event to XENPV, it's also usefull for PVH/PVHVM


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 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.95 src/sys/arch/xen/xen/evtchn.c:1.96
--- src/sys/arch/xen/xen/evtchn.c:1.95	Wed May 13 13:19:38 2020
+++ src/sys/arch/xen/xen/evtchn.c	Sun Nov 15 14:01:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.95 2020/05/13 13:19:38 jdolecek Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.96 2020/11/15 14:01:06 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.95 2020/05/13 13:19:38 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.96 2020/11/15 14:01:06 bouyer Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -261,7 +261,6 @@ events_init(void)
 bool
 events_resume(void)
 {
-#ifdef XENPV
 	debug_port = bind_virq_to_evtch(VIRQ_DEBUG);
 
 	KASSERT(debug_port != -1);
@@ -276,7 +275,6 @@ events_resume(void)
 	evtsource[debug_port] = (void *)-1;
 	xen_atomic_set_bit(()->ci_evtmask[0], debug_port);
 	hypervisor_unmask_event(debug_port);
-#endif /* XENPV */
 	x86_enable_intr();		/* at long last... */
 
 	return true;



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

2020-09-15 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Sep 15 10:58:02 UTC 2020

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

Log Message:
Fix side effect of previous commit: skip xencons attachement only for
PVHVM guests. Should fix issue with console on PV dom0 reported by
kardel@ in private mail


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/xen/xen/hypervisor.c

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

Modified files:

Index: src/sys/arch/xen/xen/hypervisor.c
diff -u src/sys/arch/xen/xen/hypervisor.c:1.88 src/sys/arch/xen/xen/hypervisor.c:1.89
--- src/sys/arch/xen/xen/hypervisor.c:1.88	Wed Sep  9 16:46:06 2020
+++ src/sys/arch/xen/xen/hypervisor.c	Tue Sep 15 10:58:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.88 2020/09/09 16:46:06 bouyer Exp $ */
+/* $NetBSD: hypervisor.c,v 1.89 2020/09/15 10:58:02 bouyer Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.88 2020/09/09 16:46:06 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.89 2020/09/15 10:58:02 bouyer Exp $");
 
 #include 
 #include 
@@ -676,7 +676,7 @@ hypervisor_attach(device_t parent, devic
 	config_found_ia(self, "xendevbus", _xenbus, hypervisor_print);
 #endif
 #if NXENCONS > 0
-	if (xencons_interface != 0) {
+	if (xencons_interface != 0 || vm_guest != VM_GUEST_XENPVHVM) {
 		memset(, 0, sizeof(hac));
 		hac.hac_xencons.xa_device = "xencons";
 		config_found_ia(self, "xendevbus", _xencons, hypervisor_print);



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

2020-09-09 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Sep  9 16:46:06 UTC 2020

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

Log Message:
Workarounds for amazon's Xen 4.2 version, still present on some instances:
- It doens't provides an xencons, so allow HVM_PARAM_CONSOLE_PFN to fail
- the xen clock is not fully functionnal, so don't try to use it if
  HVM_PARAM_CONSOLE_PFN failed.
- it doesn't have XEN_HVM_CPUID_VCPU_ID_PRESENT so fall back to ci_acpiid
  as ci_vcpuid in this case.

It also doesn't support the per-CPU event callback; so fix the fallback
to global vector (don't try to register more per-cpu vector)
Should fix port-amd64/55543


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/arch/xen/xen/hypervisor.c

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

Modified files:

Index: src/sys/arch/xen/xen/hypervisor.c
diff -u src/sys/arch/xen/xen/hypervisor.c:1.87 src/sys/arch/xen/xen/hypervisor.c:1.88
--- src/sys/arch/xen/xen/hypervisor.c:1.87	Tue Jul 14 00:45:53 2020
+++ src/sys/arch/xen/xen/hypervisor.c	Wed Sep  9 16:46:06 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.87 2020/07/14 00:45:53 yamaguchi Exp $ */
+/* $NetBSD: hypervisor.c,v 1.88 2020/09/09 16:46:06 bouyer Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.87 2020/07/14 00:45:53 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.88 2020/09/09 16:46:06 bouyer Exp $");
 
 #include 
 #include 
@@ -413,31 +413,41 @@ xen_hvm_init(void)
 	xen_hvm_param.index = HVM_PARAM_CONSOLE_PFN;
 	
 	if ( HYPERVISOR_hvm_op(HVMOP_get_param, _hvm_param) < 0) {
-		aprint_error(
+		aprint_debug(
 		"Xen HVM: Unable to obtain xencons page address\n");
-		return 0;
-	}
-
-	/* Re-use PV field */
-	xen_start_info.console.domU.mfn = xen_hvm_param.value;
-
-	pmap_kenter_pa((vaddr_t) xencons_interface, ptoa(xen_start_info.console.domU.mfn),
-	VM_PROT_READ|VM_PROT_WRITE, 0);
+		xen_start_info.console.domU.mfn = 0;
+		xen_start_info.console.domU.evtchn = -1;
+		xencons_interface = 0;
+	} else {
+		/* Re-use PV field */
+		xen_start_info.console.domU.mfn = xen_hvm_param.value;
 
-	xen_hvm_param.domid = DOMID_SELF;
-	xen_hvm_param.index = HVM_PARAM_CONSOLE_EVTCHN;
+		pmap_kenter_pa((vaddr_t) xencons_interface,
+		ptoa(xen_start_info.console.domU.mfn),
+		VM_PROT_READ|VM_PROT_WRITE, 0);
+
+		xen_hvm_param.domid = DOMID_SELF;
+		xen_hvm_param.index = HVM_PARAM_CONSOLE_EVTCHN;
+
+		if ( HYPERVISOR_hvm_op(HVMOP_get_param, _hvm_param) < 0) {
+			aprint_error(
+			   "Xen HVM: Unable to obtain xencons event channel\n");
+			return 0;
+		}
 
-	if ( HYPERVISOR_hvm_op(HVMOP_get_param, _hvm_param) < 0) {
-		aprint_error(
-		"Xen HVM: Unable to obtain xencons event channel\n");
-		return 0;
+		xen_start_info.console.domU.evtchn = xen_hvm_param.value;
 	}
 
-	xen_start_info.console.domU.evtchn = xen_hvm_param.value;
-
-
-	delay_func = x86_delay = xen_delay;
-	x86_initclock_func = xen_initclocks;
+	/*
+	 * PR port-amd64/55543
+	 * workround for amazon's Xen 4.2: it looks like the Xen clock is not
+	 * fully funtionnal here. This version also doesn't support
+	 * HVM_PARAM_CONSOLE_PFN. 
+	 */
+	if (xencons_interface != 0) {
+		delay_func = x86_delay = xen_delay;
+		x86_initclock_func = xen_initclocks;
+	}
 
 	vm_guest = VM_GUEST_XENPVHVM; /* Be more specific */
 	return 1;
@@ -458,13 +468,14 @@ xen_hvm_init_cpu(struct cpu_info *ci)
 
 	descs[0] = 0;
 	x86_cpuid(XEN_CPUID_LEAF(4), descs);
-	if (!(descs[0] & XEN_HVM_CPUID_VCPU_ID_PRESENT)) {
-		aprint_error_dev(ci->ci_dev, "Xen HVM: can't get VCPU id\n");
-		vm_guest = VM_GUEST_XENHVM;
-		return 0;
+	if (descs[0] & XEN_HVM_CPUID_VCPU_ID_PRESENT) {
+		ci->ci_vcpuid = descs[1];
+	} else {
+		aprint_debug_dev(ci->ci_dev,
+		"Xen HVM: can't get VCPU id, falling back to ci_acpiid\n");
+		ci->ci_vcpuid = ci->ci_acpiid;
 	}
 
-	ci->ci_vcpuid = descs[1];
 	ci->ci_vcpu = _shared_info->vcpu_info[ci->ci_vcpuid];
 
 	/* Register event callback handler. */
@@ -491,6 +502,7 @@ xen_hvm_init_cpu(struct cpu_info *ci)
 panic("event upcall vector");
 			aprint_error_dev(ci->ci_dev,
 			"falling back to global vector\n");
+			xenhvm_use_percpu_callback = 0;
 		} else {
 			/*
 			 * From FreeBSD:
@@ -664,9 +676,11 @@ hypervisor_attach(device_t parent, devic
 	config_found_ia(self, "xendevbus", _xenbus, hypervisor_print);
 #endif
 #if NXENCONS > 0
-	memset(, 0, sizeof(hac));
-	hac.hac_xencons.xa_device = "xencons";
-	config_found_ia(self, "xendevbus", _xencons, hypervisor_print);
+	if (xencons_interface != 0) {
+		memset(, 0, sizeof(hac));
+		hac.hac_xencons.xa_device = "xencons";
+		config_found_ia(self, "xendevbus", _xencons, hypervisor_print);
+	}
 #endif
 #if defined(XENPV) && defined(DOM0OPS)
 #if NPCI > 0



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

2020-08-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug 26 15:54:11 UTC 2020

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

Log Message:
Nix trailing whitespace and mixed space/tab indentation.


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/arch/xen/xen/if_xennet_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.127 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.128
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.127	Wed Jun 24 14:33:08 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Wed Aug 26 15:54:10 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.127 2020/06/24 14:33:08 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.128 2020/08/26 15:54:10 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.127 2020/06/24 14:33:08 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.128 2020/08/26 15:54:10 riastradh Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -177,7 +177,7 @@ struct xennet_xenbus_softc {
 
 	unsigned int sc_evtchn;
 	struct intrhand *sc_ih;
-	
+
 	grant_ref_t sc_tx_ring_gntref;
 	grant_ref_t sc_rx_ring_gntref;
 
@@ -320,7 +320,7 @@ xennet_xenbus_attach(device_t parent, de
 	SLIST_INIT(>sc_txreq_head);
 	for (i = 0; i < NET_TX_RING_SIZE; i++) {
 		struct xennet_txreq *txreq = >sc_txreqs[i];
-	
+
 		txreq->txreq_id = i;
 		if (bus_dmamap_create(sc->sc_xbusd->xbusd_dmat, maxsz, nsegs,
 		PAGE_SIZE, PAGE_SIZE, BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW,
@@ -387,7 +387,7 @@ xennet_xenbus_attach(device_t parent, de
 		| IFCAP_CSUM_TCPv4_Rx | IFCAP_CSUM_TCPv4_Tx
 		| IFCAP_CSUM_UDPv6_Rx
 		| IFCAP_CSUM_TCPv6_Rx;
-#define XN_M_CSUM_SUPPORTED 		\
+#define XN_M_CSUM_SUPPORTED		\
 	(M_CSUM_TCPv4 | M_CSUM_UDPv4 | M_CSUM_TCPv6 | M_CSUM_UDPv6)
 
 	if (sc->sc_features & FEATURE_IPV6CSUM) {
@@ -781,7 +781,7 @@ xennet_alloc_rx_buffer(struct xennet_xen
 			printf("%s: rx no mbuf\n", ifp->if_xname);
 			break;
 		}
- 
+
 		va = (vaddr_t)pool_cache_get_paddr(
 		if_xennetrxbuf_cache, PR_NOWAIT, );
 		if (__predict_false(va == 0)) {
@@ -790,11 +790,11 @@ xennet_alloc_rx_buffer(struct xennet_xen
 			break;
 		}
 
- 		MEXTADD(m, va, PAGE_SIZE,
- 		M_DEVBUF, xennet_rx_mbuf_free, NULL);
+		MEXTADD(m, va, PAGE_SIZE,
+		M_DEVBUF, xennet_rx_mbuf_free, NULL);
 		m->m_len = m->m_pkthdr.len = PAGE_SIZE;
- 		m->m_ext.ext_paddr = pa;
- 		m->m_flags |= M_EXT_RW; /* we own the buffer */
+		m->m_ext.ext_paddr = pa;
+		m->m_flags |= M_EXT_RW; /* we own the buffer */
 
 		/* Set M_EXT_CLUSTER so that load_mbuf uses m_ext.ext_paddr */
 		m->m_flags |= M_EXT_CLUSTER;
@@ -1232,10 +1232,10 @@ xennet_start(struct ifnet *ifp)
 
 #ifdef XENNET_DEBUG_DUMP
 		xennet_hex_dump(mtod(m, u_char *), m->m_pkthdr.len, "s",
-			   	req->txreq_id);
+		req->txreq_id);
 #endif
 
-		if (!xennet_submit_tx_request(sc, m, req, _prod)) {	
+		if (!xennet_submit_tx_request(sc, m, req, _prod)) {
 			/* Grant failed, postpone */
 			sc->sc_cnt_tx_drop.ev_count++;
 			bus_dmamap_unload(sc->sc_xbusd->xbusd_dmat,



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

2020-07-13 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Jul 13 21:21:57 UTC 2020

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

Log Message:
change xbd_unmap_align() to get the bp via argument rathen than
req_bp, to avoid using req_bp after it's been set to NULL by the
time xbd_unmap_align() is called in xbd_handler(); this fixes
regression caused by previous fix

also make sure xbd_unmap_align() works correctly even when using the
linked request pair for I/O (ie. for Dom0 not supporting indirect
segments), regardless of the order the paired requests finish


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/sys/arch/xen/xen/xbd_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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.128 src/sys/arch/xen/xen/xbd_xenbus.c:1.129
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.128	Mon Jun 29 21:45:50 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Mon Jul 13 21:21:56 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.128 2020/06/29 21:45:50 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.129 2020/07/13 21:21:56 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.128 2020/06/29 21:45:50 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.129 2020/07/13 21:21:56 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -157,7 +157,7 @@ struct xbd_xenbus_softc {
 	SLIST_HEAD(,xbd_indirect) sc_indirect_head;
 
 	vmem_addr_t sc_unalign_buffer;
-	struct xbd_req *sc_unalign_used;
+	void *sc_unalign_used;
 
 	int sc_backend_status; /* our status with backend */
 #define BLKIF_STATE_DISCONNECTED 0
@@ -206,7 +206,8 @@ static void xbd_diskstart_submit(struct 
 static void xbd_diskstart_submit_indirect(struct xbd_xenbus_softc *,
 	struct xbd_req *, struct buf *bp);
 static int  xbd_map_align(struct xbd_xenbus_softc *, struct xbd_req *);
-static void xbd_unmap_align(struct xbd_xenbus_softc *, struct xbd_req *, bool);
+static void xbd_unmap_align(struct xbd_xenbus_softc *, struct xbd_req *,
+	struct buf *);
 
 static void xbdminphys(struct buf *);
 
@@ -887,7 +888,7 @@ again:
 		bus_dmamap_unload(sc->sc_xbusd->xbusd_dmat, xbdreq->req_dmamap);
 
 		if (__predict_false(bp->b_data != xbdreq->req_data))
-			xbd_unmap_align(sc, xbdreq, true);
+			xbd_unmap_align(sc, xbdreq, bp);
 		xbdreq->req_data = NULL;
 
 		dk_done(>sc_dksc, bp);
@@ -1187,7 +1188,7 @@ xbd_diskstart(device_t self, struct buf 
 		printf("%s: %s: bus_dmamap_load failed\n",
 		device_xname(sc->sc_dksc.sc_dev), __func__);
 		if (__predict_false(bp->b_data != xbdreq->req_data))
-			xbd_unmap_align(sc, xbdreq, false);
+			xbd_unmap_align(sc, xbdreq, NULL);
 		error = EINVAL;
 		goto out;
 	}
@@ -1213,7 +1214,7 @@ xbd_diskstart(device_t self, struct buf 
 			bus_dmamap_unload(sc->sc_xbusd->xbusd_dmat,
 			xbdreq->req_dmamap);
 			if (__predict_false(bp->b_data != xbdreq->req_data))
-xbd_unmap_align(sc, xbdreq, false);
+xbd_unmap_align(sc, xbdreq, NULL);
 			error = EAGAIN;
 			goto out;
 		}
@@ -1243,7 +1244,7 @@ xbd_diskstart(device_t self, struct buf 
 		xbdreq->req_parent_done = false;
 		xbdreq2->req_parent = xbdreq;
 		xbdreq2->req_bp = bp;
-		xbdreq2->req_data = NULL;
+		xbdreq2->req_data = xbdreq->req_data;
 		xbd_diskstart_submit(sc, xbdreq2->req_id,
 		bp, XBD_MAX_CHUNK, xbdreq->req_dmamap,
 		xbdreq->req_gntref);
@@ -1379,7 +1380,7 @@ xbd_map_align(struct xbd_xenbus_softc *s
 		sc->sc_cnt_unalign_busy.ev_count++;
 		return EAGAIN;
 	}
-	sc->sc_unalign_used = req;
+	sc->sc_unalign_used = req->req_bp;
 
 	KASSERT(req->req_bp->b_bcount <= MAXPHYS);
 	req->req_data = (void *)sc->sc_unalign_buffer;
@@ -1390,11 +1391,11 @@ xbd_map_align(struct xbd_xenbus_softc *s
 }
 
 static void
-xbd_unmap_align(struct xbd_xenbus_softc *sc, struct xbd_req *req, bool sync)
+xbd_unmap_align(struct xbd_xenbus_softc *sc, struct xbd_req *req,
+struct buf *bp)
 {
-	KASSERT(sc->sc_unalign_used == req);
-	if (sync && req->req_bp->b_flags & B_READ)
-		memcpy(req->req_bp->b_data, req->req_data,
-		req->req_bp->b_bcount);
+	KASSERT(!bp || sc->sc_unalign_used == bp);
+	if (bp && bp->b_flags & B_READ)
+		memcpy(bp->b_data, req->req_data, bp->b_bcount);
 	sc->sc_unalign_used = NULL;
 }



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

2020-06-29 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Jun 29 21:45:50 UTC 2020

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

Log Message:
when using two linked requests for I/O (i.e. when backend doesn't support
INDIRECT segments), make sure to clear req_bp for both of them

fixes a misfired assertion in BLKIF_OP_FLUSH_DISKCACHE - PR port-xen/55431


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/arch/xen/xen/xbd_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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.127 src/sys/arch/xen/xen/xbd_xenbus.c:1.128
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.127	Wed May 13 16:17:46 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Mon Jun 29 21:45:50 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.127 2020/05/13 16:17:46 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.128 2020/06/29 21:45:50 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.127 2020/05/13 16:17:46 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.128 2020/06/29 21:45:50 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -832,6 +832,7 @@ again:
 		}
 
 		bp = xbdreq->req_bp;
+		xbdreq->req_bp = NULL;
 		KASSERT(bp != NULL && bp->b_data != NULL);
 		DPRINTF(("%s(%p): b_bcount = %ld\n", __func__,
 		bp, (long)bp->b_bcount));
@@ -887,7 +888,7 @@ again:
 
 		if (__predict_false(bp->b_data != xbdreq->req_data))
 			xbd_unmap_align(sc, xbdreq, true);
-		xbdreq->req_bp = xbdreq->req_data = NULL;
+		xbdreq->req_data = NULL;
 
 		dk_done(>sc_dksc, bp);
 



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

2020-06-24 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Jun 24 14:33:08 UTC 2020

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

Log Message:
fix tyop in KASSERT() condition which made it an assignment rather than a check

the field indeed is supposed to be set to GRANT_INVALID_REF at this moment,
the grant must be already revoked by this time

pointed out by Taylor R Campbell


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/sys/arch/xen/xen/if_xennet_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.126 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.127
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.126	Thu May 14 13:25:40 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Wed Jun 24 14:33:08 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.126 2020/05/14 13:25:40 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.127 2020/06/24 14:33:08 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.126 2020/05/14 13:25:40 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.127 2020/06/24 14:33:08 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -774,7 +774,7 @@ xennet_alloc_rx_buffer(struct xennet_xen
 		KASSERT(req != NULL);
 		KASSERT(req == >sc_rxreqs[req->rxreq_id]);
 		KASSERT(req->rxreq_m == NULL);
-		KASSERT(req->rxreq_gntref = GRANT_INVALID_REF);
+		KASSERT(req->rxreq_gntref == GRANT_INVALID_REF);
 
 		MGETHDR(m, M_DONTWAIT, MT_DATA);
 		if (__predict_false(m == NULL)) {



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

2020-06-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Jun  4 08:24:44 UTC 2020

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

Log Message:
 G.C. No functional change. OK'd by bouyer@.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/xen/xen/xen_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/xen/xen_machdep.c
diff -u src/sys/arch/xen/xen/xen_machdep.c:1.25 src/sys/arch/xen/xen/xen_machdep.c:1.26
--- src/sys/arch/xen/xen/xen_machdep.c:1.25	Tue May 19 21:57:25 2020
+++ src/sys/arch/xen/xen/xen_machdep.c	Thu Jun  4 08:24:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_machdep.c,v 1.25 2020/05/19 21:57:25 ad Exp $	*/
+/*	$NetBSD: xen_machdep.c,v 1.26 2020/06/04 08:24:44 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.25 2020/05/19 21:57:25 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.26 2020/06/04 08:24:44 msaitoh Exp $");
 
 #include "opt_xen.h"
 
@@ -87,8 +87,6 @@ __KERNEL_RCSID(0, "$NetBSD: xen_machdep.
 #endif
 
 
-u_int	tsc_get_timecount(struct timecounter *);
-
 bool xen_suspend_allow;
 
 void
@@ -220,7 +218,6 @@ xen_parse_cmdline(int what, union xen_cm
 }
 
 #ifdef XENPV
-extern uint64_t tsc_freq;	/* XXX */
 
 static int sysctl_xen_suspend(SYSCTLFN_ARGS);
 static void xen_suspend_domain(void);



CVS commit: src/sys/arch/xen

2020-05-26 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue May 26 10:11:56 UTC 2020

Modified Files:
src/sys/arch/xen/include: xenio.h
src/sys/arch/xen/xen: privcmd.c

Log Message:
Implement new ioctl, needed by Xen 4.13:
IOCTL_PRIVCMD_MMAPBATCH_V2
IOCTL_PRIVCMD_MMAP_RESOURCE
IOCTL_GNTDEV_MMAP_GRANT_REF
IOCTL_GNTDEV_ALLOC_GRANT_REF


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/xen/include/xenio.h
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/xen/xen/privcmd.c

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

Modified files:

Index: src/sys/arch/xen/include/xenio.h
diff -u src/sys/arch/xen/include/xenio.h:1.11 src/sys/arch/xen/include/xenio.h:1.12
--- src/sys/arch/xen/include/xenio.h:1.11	Thu Jul  7 06:55:40 2016
+++ src/sys/arch/xen/include/xenio.h	Tue May 26 10:11:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xenio.h,v 1.11 2016/07/07 06:55:40 msaitoh Exp $	*/
+/*	$NetBSD: xenio.h,v 1.12 2020/05/26 10:11:56 bouyer Exp $	*/
 
 /**
  * privcmd.h
@@ -114,9 +114,92 @@ typedef struct oprivcmd_hypercall
  */
 #define IOCTL_PRIVCMD_INITDOMAIN_EVTCHN \
 _IOR('P', 5, int)
+
 #define IOCTL_PRIVCMD_MMAPBATCH_V2  \
 _IOW('P', 6, privcmd_mmapbatch_v2_t)
 
+/*
+ * @cmd: IOCTL_PRIVCMD_MMAP_RESOURCE
+ * @arg _mmap_resource_t
+ * Return: 
+ * map the specified resource at the provided virtual address
+ */ 
+
+typedef struct privcmd_mmap_resource {
+domid_t dom;
+	uint32_t type;
+	uint32_t id;
+	uint32_t idx; 
+	uint64_t num; 
+	uint64_t addr;
+} privcmd_mmap_resource_t;
+
+#define IOCTL_PRIVCMD_MMAP_RESOURCE  \
+_IOW('P', 7, privcmd_mmap_resource_t)
+
+/*
+ * @cmd: IOCTL_GNTDEV_MMAP_GRANT_REF
+ * @arg _gntdev_mmap_grant_ref
+ * Return: 
+ * map the grant references at the virtual address provided by caller
+ * The grant ref already exists (e.g. comes from a remote domain)
+ */ 
+struct ioctl_gntdev_grant_ref {
+	/* The domain ID of the grant to be mapped. */
+	uint32_t domid;
+	/* The grant reference of the grant to be mapped. */
+	uint32_t ref;
+};
+
+struct ioctl_gntdev_grant_notify {
+	ssize_t offset;
+	uint32_t action;
+	uint32_t event_channel_port;
+};
+#define UNMAP_NOTIFY_CLEAR_BYTE 0x1
+#define UNMAP_NOTIFY_SEND_EVENT 0x2
+
+struct ioctl_gntdev_mmap_grant_ref {
+	/* The number of grants to be mapped. */
+	uint32_t count;
+	uint32_t pad;
+	/* The virtual address where they should be mapped */
+	void *va;
+	/* notify action */
+	struct ioctl_gntdev_grant_notify notify;
+	/* Array of grant references, of size @count. */
+	struct ioctl_gntdev_grant_ref *refs;
+};
+
+#define IOCTL_GNTDEV_MMAP_GRANT_REF \
+_IOW('P', 8, struct ioctl_gntdev_mmap_grant_ref)
+
+/*
+ * @cmd: IOCTL_GNTDEV_ALLOC_GRANT_REF
+ * @arg _gntdev_alloc_grant_ref
+ * Return: 
+ * Allocate local memory and grant it to a remote domain.
+ * local memory is mmaped at the virtual address provided by caller
+ */ 
+
+struct ioctl_gntdev_alloc_grant_ref {
+	/* IN parameters */ 
+	uint16_t domid;
+	uint16_t flags;
+	uint32_t count;
+	void *va;
+	/* notify action */
+	struct ioctl_gntdev_grant_notify notify;
+	/* Variable OUT parameter */  
+	uint32_t *gref_ids; 
+};
+
+#define IOCTL_GNTDEV_ALLOC_GRANT_REF \
+_IOW('P', 9, struct ioctl_gntdev_alloc_grant_ref)
+
+#define GNTDEV_ALLOC_FLAG_WRITABLE 0x01
+
+
 /* Interface to /dev/xenevt */
 /* EVTCHN_RESET: Clear and reinit the event buffer. Clear error condition. */
 #define EVTCHN_RESET  _IO('E', 1)

Index: src/sys/arch/xen/xen/privcmd.c
diff -u src/sys/arch/xen/xen/privcmd.c:1.57 src/sys/arch/xen/xen/privcmd.c:1.58
--- src/sys/arch/xen/xen/privcmd.c:1.57	Tue May  5 17:02:01 2020
+++ src/sys/arch/xen/xen/privcmd.c	Tue May 26 10:11:56 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: privcmd.c,v 1.57 2020/05/05 17:02:01 bouyer Exp $ */
+/* $NetBSD: privcmd.c,v 1.58 2020/05/26 10:11:56 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2004 Christian Limpach.
@@ -27,7 +27,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.57 2020/05/05 17:02:01 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.58 2020/05/26 10:11:56 bouyer Exp $");
 
 #include 
 #include 
@@ -47,29 +47,68 @@ __KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 
 #include 
 #include 
 #include 
+#include 
 
 #define	PRIVCMD_MODE	(S_IRUSR)
 
 /* Magic value is used to mark invalid pages.
  * This must be a value within the page-offset.
  * Page-aligned values including 0x0 are used by the guest.
- */ 
+ */
 #define INVALID_PAGE	0xfff
 
+typedef enum _privcmd_type {
+	PTYPE_PRIVCMD,
+	PTYPE_GNTDEV_REF,
+	PTYPE_GNTDEV_ALLOC
+} privcmd_type;
+
+struct privcmd_object_privcmd {
+paddr_t *maddr; /* array of machine address to map */
+int domid;
+boolno_translate;
+};
+
+struct privcmd_object_gntref {
+struct ioctl_gntdev_grant_notify notify;
+	struct gnttab_map_grant_ref ops[1]; /* variable length */
+};
+
+struct 

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

2020-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri May 22 17:44:05 UTC 2020

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

Log Message:
Set frame = NULL in XENPV whether DIAGNOSTIC or not.

For Xen PV, the interrupt logic stores the relevant information in
the CPU's struct cpu_info, and CLKF_USERMODE and CLKF_PC don't use
the frame argument at all.  (For Xen PVH, we behave like normal x86
and use the frame as passed.)

DIAGNOSTIC shouldn't change the data flows that affect non-DIAGNOSTIC
logic, so let's just unconditionally set frame = NULL for XENPV.  If
this makes a difference, that's a bug -- and it's a bug that should
not be concealed by enabling DIAGNOSTIC.

ok bouyer


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/xen/xen/xen_clock.c

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

Modified files:

Index: src/sys/arch/xen/xen/xen_clock.c
diff -u src/sys/arch/xen/xen/xen_clock.c:1.6 src/sys/arch/xen/xen/xen_clock.c:1.7
--- src/sys/arch/xen/xen/xen_clock.c:1.6	Thu May 21 21:12:31 2020
+++ src/sys/arch/xen/xen/xen_clock.c	Fri May 22 17:44:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_clock.c,v 1.6 2020/05/21 21:12:31 ad Exp $	*/
+/*	$NetBSD: xen_clock.c,v 1.7 2020/05/22 17:44:05 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2017, 2018 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.6 2020/05/21 21:12:31 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.7 2020/05/22 17:44:05 riastradh Exp $");
 
 #include 
 #include 
@@ -681,7 +681,7 @@ xen_timer_handler(void *cookie, struct c
 	KASSERT(cpu_intr_p());
 	KASSERT(cookie == ci);
 
-#if defined(DIAGNOSTIC) && defined(XENPV)
+#if defined(XENPV)
 	frame = NULL; /* We use values cached in curcpu()  */
 #endif
 again:



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

2020-05-19 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 19 21:57:25 UTC 2020

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

Log Message:
Remove duplicate def of tsc_get_timecount().


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/xen/xen/xen_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/xen/xen_machdep.c
diff -u src/sys/arch/xen/xen/xen_machdep.c:1.24 src/sys/arch/xen/xen/xen_machdep.c:1.25
--- src/sys/arch/xen/xen/xen_machdep.c:1.24	Sat May  2 16:44:36 2020
+++ src/sys/arch/xen/xen/xen_machdep.c	Tue May 19 21:57:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_machdep.c,v 1.24 2020/05/02 16:44:36 bouyer Exp $	*/
+/*	$NetBSD: xen_machdep.c,v 1.25 2020/05/19 21:57:25 ad Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.24 2020/05/02 16:44:36 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.25 2020/05/19 21:57:25 ad Exp $");
 
 #include "opt_xen.h"
 
@@ -227,13 +227,6 @@ static void xen_suspend_domain(void);
 static void xen_prepare_suspend(void);
 static void xen_prepare_resume(void);
 
-u_int
-tsc_get_timecount(struct timecounter *tc)
-{
-
-	panic("xen: tsc_get_timecount");
-}
-
 /*
  * this function sets up the machdep.xen.suspend sysctl(7) that
  * controls domain suspend/save.



CVS commit: src/sys/arch/xen

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

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

Log Message:
use short for irq2port[] to save memory (4KB), it only needs to store
numbers <= NR_EVENT_CHANNELS (2048)


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.15 -r1.16 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/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.56 src/sys/arch/xen/include/intr.h:1.57
--- src/sys/arch/xen/include/intr.h:1.56	Thu May 14 19:36:02 2020
+++ src/sys/arch/xen/include/intr.h	Fri May 15 07:42:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.56 2020/05/14 19:36:02 jdolecek Exp $	*/
+/*	$NetBSD: intr.h,v 1.57 2020/05/15 07:42:58 jdolecek Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -64,7 +64,7 @@ struct evtsource {
 };
 
 extern struct intrstub xenev_stubs[];
-extern int irq2port[NR_EVENT_CHANNELS]; /* actually port + 1, so that 0 is invaid */
+extern short irq2port[NR_EVENT_CHANNELS]; /* actually port + 1, so that 0 is invaid */
 
 #ifdef MULTIPROCESSOR
 int xen_intr_biglock_wrapper(void *);

Index: src/sys/arch/xen/x86/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.15 src/sys/arch/xen/x86/pintr.c:1.16
--- src/sys/arch/xen/x86/pintr.c:1.15	Fri May 15 07:31:07 2020
+++ src/sys/arch/xen/x86/pintr.c	Fri May 15 07:42:58 2020
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.15 2020/05/15 07:31:07 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.16 2020/05/15 07:42:58 jdolecek Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -148,7 +148,7 @@ struct intrstub x2apic_level_stubs[MAX_I
 #endif /* NIOAPIC */
 
 // XXX NR_EVENT_CHANNELS is 2048, use some sparse structure?
-int irq2port[NR_EVENT_CHANNELS] = {0}; /* actually port + 1, so that 0 is invaid */
+short irq2port[NR_EVENT_CHANNELS] = {0}; /* actually port + 1, so that 0 is invaid */
 
 #if NACPICA > 0
 #include 



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

2020-05-14 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu May 14 19:36:03 UTC 2020

Modified Files:
src/sys/arch/xen/include: intr.h

Log Message:
xen_vec_alloc() is no more


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/xen/include/intr.h

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

Modified files:

Index: src/sys/arch/xen/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.55 src/sys/arch/xen/include/intr.h:1.56
--- src/sys/arch/xen/include/intr.h:1.55	Sat Apr 25 15:26:17 2020
+++ src/sys/arch/xen/include/intr.h	Thu May 14 19:36:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.55 2020/04/25 15:26:17 bouyer Exp $	*/
+/*	$NetBSD: intr.h,v 1.56 2020/05/14 19:36:02 jdolecek Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -71,7 +71,6 @@ int xen_intr_biglock_wrapper(void *);
 #endif
 
 #if defined(DOM0OPS) || NPCI > 0
-int xen_vec_alloc(int);
 int xen_pic_to_gsi(struct pic *, int);
 #endif /* defined(DOM0OPS) || NPCI > 0 */
 



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

2020-05-14 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu May 14 13:25:40 UTC 2020

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

Log Message:
fix resume for xennet, now the network continues working after resume

we can't read feature-rx-copy in resume, at that time the new backend
device is not filled yet; convert it just to feature flag read on interface
attach, can assume any backend would support rx-copy anyway

fix compile with XENNET_DEBUG

part of PR port-xen/55207


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/sys/arch/xen/xen/if_xennet_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.125 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.126
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.125	Thu May 14 09:47:25 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Thu May 14 13:25:40 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.125 2020/05/14 09:47:25 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.126 2020/05/14 13:25:40 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.125 2020/05/14 09:47:25 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.126 2020/05/14 13:25:40 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -198,7 +198,8 @@ struct xennet_xenbus_softc {
 	int sc_features;
 #define FEATURE_IPV6CSUM	0x01	/* IPv6 checksum offload */
 #define FEATURE_SG		0x02	/* scatter-gatter */
-#define FEATURE_BITS		"\20\1IPV6-CSUM\2SG"
+#define FEATURE_RX_COPY		0x04	/* RX-copy */
+#define FEATURE_BITS		"\20\1IPV6-CSUM\2SG\3RX-COPY"
 	krndsource_t sc_rnd_source;
 	struct evcnt sc_cnt_tx_defrag;
 	struct evcnt sc_cnt_tx_queue_full;
@@ -280,6 +281,10 @@ xennet_xenbus_attach(device_t parent, de
 
 	/* read feature support flags */
 	err = xenbus_read_ul(NULL, sc->sc_xbusd->xbusd_otherend,
+	"feature-rx-copy", , 10);
+	if (!err && uval == 1)
+		sc->sc_features |= FEATURE_RX_COPY;
+	err = xenbus_read_ul(NULL, sc->sc_xbusd->xbusd_otherend,
 	"feature-ipv6-csum-offload", , 10);
 	if (!err && uval == 1)
 		sc->sc_features |= FEATURE_IPV6CSUM;
@@ -601,19 +606,9 @@ static bool
 xennet_talk_to_backend(struct xennet_xenbus_softc *sc)
 {
 	int error;
-	unsigned long rx_copy;
 	struct xenbus_transaction *xbt;
 	const char *errmsg;
 
-	error = xenbus_read_ul(NULL, sc->sc_xbusd->xbusd_otherend,
-	"feature-rx-copy", _copy, 10);
-	if (error || !rx_copy) {
-		xenbus_dev_fatal(sc->sc_xbusd, error,
-		"feature-rx-copy not supported");
-		return false;
-	}
-	aprint_normal_dev(sc->sc_dev, "using RX copy mode\n");
-
 again:
 	xbt = xenbus_transaction_start();
 	if (xbt == NULL)
@@ -637,7 +632,7 @@ again:
 		goto abort_transaction;
 	}
 	error = xenbus_printf(xbt, sc->sc_xbusd->xbusd_path,
-	"request-rx-copy", "%lu", rx_copy);
+	"request-rx-copy", "%u", 1);
 	if (error) {
 		errmsg = "writing request-rx-copy";
 		goto abort_transaction;
@@ -1232,9 +1227,8 @@ xennet_start(struct ifnet *ifp)
 		}
 
 		DPRINTFN(XEDB_MBUF, ("xennet_start id %d, "
-		"mbuf %p, buf %p/%p, size %d\n",
-		req->txreq_id, m, mtod(m, void *), (void *)ma,
-		m->m_pkthdr.len));
+		"mbuf %p, buf %p, size %d\n",
+		req->txreq_id, m, mtod(m, void *), m->m_pkthdr.len));
 
 #ifdef XENNET_DEBUG_DUMP
 		xennet_hex_dump(mtod(m, u_char *), m->m_pkthdr.len, "s",



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

2020-05-14 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu May 14 13:18:55 UTC 2020

Modified Files:
src/sys/arch/xen/xenbus: xenbus_probe.c

Log Message:
fix compile when DPRINK() is defined


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/xen/xenbus/xenbus_probe.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/xenbus/xenbus_probe.c
diff -u src/sys/arch/xen/xenbus/xenbus_probe.c:1.53 src/sys/arch/xen/xenbus/xenbus_probe.c:1.54
--- src/sys/arch/xen/xenbus/xenbus_probe.c:1.53	Wed May 13 13:19:38 2020
+++ src/sys/arch/xen/xenbus/xenbus_probe.c	Thu May 14 13:18:55 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_probe.c,v 1.53 2020/05/13 13:19:38 jdolecek Exp $ */
+/* $NetBSD: xenbus_probe.c,v 1.54 2020/05/14 13:18:55 jdolecek Exp $ */
 /**
  * Talks to Xen Store to figure out what devices we have.
  *
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.53 2020/05/13 13:19:38 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.54 2020/05/14 13:18:55 jdolecek Exp $");
 
 #if 0
 #define DPRINTK(fmt, args...) \
@@ -195,7 +195,7 @@ read_otherend_details(struct xenbus_devi
 		return err;
 	}
 	DPRINTK("read_otherend_details: read %s/%s returned %s\n",
-	xendev->xbusd_path, path_node, val);
+	xendev->xbusd_path, path_node, xendev->xbusd_otherend);
 
 	if (strlen(xendev->xbusd_otherend) == 0 ||
 	!xenbus_exists(NULL, xendev->xbusd_otherend, "")) {
@@ -322,7 +322,7 @@ xenbus_probe_device_type(const char *pat
 
 	DPRINTK("probe %s type %s", path, type);
 	err = xenbus_directory(NULL, path, "", _dir_n, );
-	DPRINTK("directory err %d dir_n %d", err, dir_n);
+	DPRINTK("directory err %d dir_n %d", err, orig_dir_n);
 	if (err)
 		return err;
 	dir_n = orig_dir_n;



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

2020-05-14 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu May 14 09:47:25 UTC 2020

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

Log Message:
rearrange so that suspend & resume doesn't cause panics, and interface
is more likely to work - particularly, don't try to xengnt_revoke_access()
after resume, move xen_intr_disestablish() call to resume, also
unmask the event channel on resume

XXX right now xennet device detaches immediately after resume, which is not
desirable and needs to be fixed

part of PR port-xen/55207


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/sys/arch/xen/xen/if_xennet_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.124 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.125
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.124	Tue May  5 09:52:13 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Thu May 14 09:47:25 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.124 2020/05/05 09:52:13 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.125 2020/05/14 09:47:25 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.124 2020/05/05 09:52:13 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.125 2020/05/14 09:47:25 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -218,7 +218,7 @@ static int  xennet_xenbus_detach(device_
 static void xennet_backend_changed(void *, XenbusState);
 
 static void xennet_alloc_rx_buffer(struct xennet_xenbus_softc *);
-static void xennet_free_rx_buffer(struct xennet_xenbus_softc *);
+static void xennet_free_rx_buffer(struct xennet_xenbus_softc *, bool);
 static void xennet_tx_complete(struct xennet_xenbus_softc *);
 static void xennet_rx_mbuf_free(struct mbuf *, void *, size_t, void *);
 static int  xennet_handler(void *);
@@ -233,7 +233,7 @@ static void xennet_start(struct ifnet *)
 static int  xennet_ioctl(struct ifnet *, u_long, void *);
 
 static bool xennet_xenbus_suspend(device_t dev, const pmf_qual_t *);
-static bool xennet_xenbus_resume (device_t dev, const pmf_qual_t *);
+static bool xennet_xenbus_resume(device_t dev, const pmf_qual_t *);
 
 CFATTACH_DECL3_NEW(xennet, sizeof(struct xennet_xenbus_softc),
xennet_xenbus_match, xennet_xenbus_attach, xennet_xenbus_detach, NULL,
@@ -412,15 +412,6 @@ xennet_xenbus_attach(device_t parent, de
 	sc->sc_tx_ring.sring = tx_ring;
 	sc->sc_rx_ring.sring = rx_ring;
 
-	/* resume shared structures and tell backend that we are ready */
-	if (xennet_xenbus_resume(self, PMF_Q_NONE) == false) {
-		uvm_km_free(kernel_map, (vaddr_t)tx_ring, PAGE_SIZE,
-		UVM_KMF_WIRED);
-		uvm_km_free(kernel_map, (vaddr_t)rx_ring, PAGE_SIZE,
-		UVM_KMF_WIRED);
-		return;
-	}
-
 	rnd_attach_source(>sc_rnd_source, device_xname(sc->sc_dev),
 	RND_TYPE_NET, RND_FLAG_DEFAULT);
 
@@ -444,6 +435,15 @@ xennet_xenbus_attach(device_t parent, de
 		aprint_error_dev(self, "couldn't establish power handler\n");
 	else
 		pmf_class_network_register(self, ifp);
+
+	/* resume shared structures and tell backend that we are ready */
+	if (xennet_xenbus_resume(self, PMF_Q_NONE) == false) {
+		uvm_km_free(kernel_map, (vaddr_t)tx_ring, PAGE_SIZE,
+		UVM_KMF_WIRED);
+		uvm_km_free(kernel_map, (vaddr_t)rx_ring, PAGE_SIZE,
+		UVM_KMF_WIRED);
+		return;
+	}
 }
 
 static int
@@ -451,7 +451,6 @@ xennet_xenbus_detach(device_t self, int 
 {
 	struct xennet_xenbus_softc *sc = device_private(self);
 	struct ifnet *ifp = >sc_ethercom.ec_if;
-	RING_IDX i;
 
 	if ((flags & (DETACH_SHUTDOWN | DETACH_FORCE)) == DETACH_SHUTDOWN) {
 		/* Trigger state transition with backend */
@@ -480,14 +479,7 @@ xennet_xenbus_detach(device_t self, int 
 	mutex_exit(>sc_tx_lock);
 
 	mutex_enter(>sc_rx_lock);
-	xennet_free_rx_buffer(sc);
-	for (i = 0; i < NET_RX_RING_SIZE; i++) {
-		struct xennet_rxreq *rxreq = >sc_rxreqs[i];
-		if (rxreq->rxreq_m != NULL) {
-			m_freem(rxreq->rxreq_m);
-			rxreq->rxreq_m = NULL;
-		}
-	}
+	xennet_free_rx_buffer(sc, true);
 	mutex_exit(>sc_rx_lock);
 
 	ether_ifdetach(ifp);
@@ -537,19 +529,16 @@ xennet_xenbus_resume(device_t dev, const
 	netif_rx_sring_t *rx_ring;
 	paddr_t ma;
 
-	/* invalidate the RX and TX rings */
-	if (sc->sc_backend_status == BEST_SUSPENDED) {
-		/*
-		 * Device was suspended, so ensure that access associated to
-		 * the previous RX and TX rings are revoked.
-		 */
-		xengnt_revoke_access(sc->sc_tx_ring_gntref);
-		xengnt_revoke_access(sc->sc_rx_ring_gntref);
-	}
-
+	/* All grants were removed during suspend */
 	sc->sc_tx_ring_gntref = GRANT_INVALID_REF;
 	sc->sc_rx_ring_gntref = GRANT_INVALID_REF;
 
+	mutex_enter(>sc_rx_lock);
+	/* Free but don't revoke, the grant is gone */
+	xennet_free_rx_buffer(sc, false);
+	

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

2020-05-13 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed May 13 22:13:49 UTC 2020

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

Log Message:
fix how shutdown is acknowledged - do it just by writing empty value
into the key; this is necessary for suspend, for it removal fails with
EACCESS

now 'xl save' proceeds almost instantly without timing out, and no longer
complains about the domain not acknowleding suspend

part of port-xen/55207


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/xen/xen/shutdown_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/shutdown_xenbus.c
diff -u src/sys/arch/xen/xen/shutdown_xenbus.c:1.8 src/sys/arch/xen/xen/shutdown_xenbus.c:1.9
--- src/sys/arch/xen/xen/shutdown_xenbus.c:1.8	Tue Apr  7 11:47:06 2020
+++ src/sys/arch/xen/xen/shutdown_xenbus.c	Wed May 13 22:13:49 2020
@@ -1,4 +1,4 @@
-/*	$Id: shutdown_xenbus.c,v 1.8 2020/04/07 11:47:06 jdolecek Exp $	*/
+/*	$Id: shutdown_xenbus.c,v 1.9 2020/05/13 22:13:49 jdolecek Exp $	*/
 
 /*-
  * Copyright (c)2006 YAMAMOTO Takashi,
@@ -56,7 +56,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: shutdown_xenbus.c,v 1.8 2020/04/07 11:47:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: shutdown_xenbus.c,v 1.9 2020/05/13 22:13:49 jdolecek Exp $");
 
 #include 
 
@@ -97,8 +97,9 @@ again:
 	}
 	error = xenbus_read(xbt, SHUTDOWN_PATH, SHUTDOWN_NAME,
 	reqstr, sizeof(reqstr));
-	if (error) {
-		if (error != ENOENT) {
+	/* Ignore if read error or empty value */
+	if (error || reqstr[0] == '\0') {
+		if (error && error != ENOENT) {
 			printf("%s: xenbus_read %d\n", __func__, error);
 		}
 		error = xenbus_transaction_end(xbt, 1);
@@ -109,7 +110,8 @@ again:
 		return;
 	}
 
-	error = xenbus_rm(xbt, SHUTDOWN_PATH, SHUTDOWN_NAME);
+	/* Acknowledge the command */
+	error = xenbus_write(xbt, SHUTDOWN_PATH, SHUTDOWN_NAME, "");
 	if (error) {
 		printf("%s: xenbus_rm %d\n", __func__, error);
 	}



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

2020-05-13 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed May 13 16:17:46 UTC 2020

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

Log Message:
move the xen_intr_disestablish() to resume - having it in suspend
seems to cause panic in later phases of suspend

don't try to revoke grants in resume, they are all gone

add some diagnostic code in suspend to make sure the request lists are ready
for resume

part of PR port-xen/55207


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/sys/arch/xen/xen/xbd_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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.126 src/sys/arch/xen/xen/xbd_xenbus.c:1.127
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.126	Tue May 12 09:54:02 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Wed May 13 16:17:46 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.126 2020/05/12 09:54:02 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.127 2020/05/13 16:17:46 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.126 2020/05/12 09:54:02 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.127 2020/05/13 16:17:46 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -492,12 +492,22 @@ xbd_xenbus_suspend(device_t dev, const p
 	hypervisor_mask_event(sc->sc_evtchn);
 	sc->sc_backend_status = BLKIF_STATE_SUSPENDED;
 
-	mutex_exit(>sc_lock);
+#ifdef DIAGNOSTIC
+	/* Check that all requests are finished and device ready for resume */
+	int reqcnt = 0;
+	struct xbd_req *req;
+	SLIST_FOREACH(req, >sc_xbdreq_head, req_next)
+		reqcnt++;
+	KASSERT(reqcnt == __arraycount(sc->sc_reqs));
+
+	int incnt = 0;
+	struct xbd_indirect *in;
+	SLIST_FOREACH(in, >sc_indirect_head, in_next)
+		incnt++;
+	KASSERT(incnt == __arraycount(sc->sc_indirect));
+#endif
 
-	if (sc->sc_ih != NULL) {
-		xen_intr_disestablish(sc->sc_ih);
-		sc->sc_ih = NULL;
-	}
+	mutex_exit(>sc_lock);
 
 	xenbus_device_suspend(sc->sc_xbusd);
 	aprint_verbose_dev(dev, "removed event channel %d\n", sc->sc_evtchn);
@@ -517,13 +527,7 @@ xbd_xenbus_resume(device_t dev, const pm
 
 	sc = device_private(dev);
 
-	if (sc->sc_backend_status == BLKIF_STATE_SUSPENDED) {
-		/*
-		 * Device was suspended, so ensure that access associated to
-		 * the block I/O ring is revoked.
-		 */
-		xengnt_revoke_access(sc->sc_ring_gntref);
-	}
+	/* All grants were removed during suspend */
 	sc->sc_ring_gntref = GRANT_INVALID_REF;
 
 	/* Initialize ring */
@@ -561,6 +565,10 @@ xbd_xenbus_resume(device_t dev, const pm
 	if (error)
 		goto abort_resume;
 
+	if (sc->sc_ih != NULL) {
+		xen_intr_disestablish(sc->sc_ih);
+		sc->sc_ih = NULL;
+	}
 	aprint_verbose_dev(dev, "using event channel %d\n",
 	sc->sc_evtchn);
 	sc->sc_ih = xen_intr_establish_xname(-1, _pic, sc->sc_evtchn,



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

2020-05-13 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed May 13 16:13:14 UTC 2020

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

Log Message:
need to set the version on resume same as during initialization

part of PR port-xen/55207


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 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.37 src/sys/arch/xen/xen/xengnt.c:1.38
--- src/sys/arch/xen/xen/xengnt.c:1.37	Sat Apr 25 15:26:18 2020
+++ src/sys/arch/xen/xen/xengnt.c	Wed May 13 16:13:14 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xengnt.c,v 1.37 2020/04/25 15:26:18 bouyer Exp $  */
+/*  $NetBSD: xengnt.c,v 1.38 2020/05/13 16:13:14 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.37 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.38 2020/05/13 16:13:14 jdolecek Exp $");
 
 #include 
 #include 
@@ -102,13 +102,6 @@ xengnt_init(void)
 	 */
 	gnt_nr_grant_frames = gnt_max_grant_frames;
 
-
-	struct gnttab_set_version gntversion;
-	gntversion.version = 2;
-	rc = HYPERVISOR_grant_table_op(GNTTABOP_set_version, , 1);
-	if (rc < 0 || gntversion.version != 2)
-		panic("GNTTABOP_set_version 2 failed %d", rc);
-
 	nr_grant_entries =
 	gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE;
 
@@ -132,7 +125,6 @@ xengnt_init(void)
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_VM);
 
 	xengnt_resume();
-
 }
 
 /*
@@ -141,8 +133,15 @@ xengnt_init(void)
 bool
 xengnt_resume(void)
 {
+	int rc;
 	int previous_nr_grant_frames = gnt_nr_grant_frames;
 
+	struct gnttab_set_version gntversion;
+	gntversion.version = 2;
+	rc = HYPERVISOR_grant_table_op(GNTTABOP_set_version, , 1);
+	if (rc < 0 || gntversion.version != 2)
+		panic("GNTTABOP_set_version 2 failed %d", rc);
+
 	last_gnt_entry = 0;
 	gnt_nr_grant_frames = 0;
 



CVS commit: src/sys/arch/xen

2020-05-13 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed May 13 13:19:38 UTC 2020

Modified Files:
src/sys/arch/xen/xen: evtchn.c
src/sys/arch/xen/xenbus: xenbus_comms.c xenbus_comms.h xenbus_probe.c

Log Message:
don't reinitialize mutexes/cv on resume

part of PR port-xen/55207


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/xen/xenbus/xenbus_comms.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/xen/xenbus/xenbus_comms.h
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/xen/xenbus/xenbus_probe.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.94 src/sys/arch/xen/xen/evtchn.c:1.95
--- src/sys/arch/xen/xen/evtchn.c:1.94	Thu May  7 19:48:57 2020
+++ src/sys/arch/xen/xen/evtchn.c	Wed May 13 13:19:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.94 2020/05/07 19:48:57 bouyer Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.95 2020/05/13 13:19:38 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.94 2020/05/07 19:48:57 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.95 2020/05/13 13:19:38 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -254,6 +254,13 @@ void
 events_init(void)
 {
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_NONE);
+
+	(void)events_resume();
+}
+
+bool
+events_resume(void)
+{
 #ifdef XENPV
 	debug_port = bind_virq_to_evtch(VIRQ_DEBUG);
 
@@ -271,6 +278,8 @@ events_init(void)
 	hypervisor_unmask_event(debug_port);
 #endif /* XENPV */
 	x86_enable_intr();		/* at long last... */
+
+	return true;
 }
 
 bool
@@ -294,15 +303,6 @@ events_suspend(void)
 	return true;
 }
 
-bool
-events_resume (void)
-{
-	events_init();
-
-	return true;
-}
-
-
 unsigned int
 evtchn_do_event(int evtch, struct intrframe *regs)
 {

Index: src/sys/arch/xen/xenbus/xenbus_comms.c
diff -u src/sys/arch/xen/xenbus/xenbus_comms.c:1.23 src/sys/arch/xen/xenbus/xenbus_comms.c:1.24
--- src/sys/arch/xen/xenbus/xenbus_comms.c:1.23	Wed May  6 16:50:13 2020
+++ src/sys/arch/xen/xenbus/xenbus_comms.c	Wed May 13 13:19:38 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_comms.c,v 1.23 2020/05/06 16:50:13 bouyer Exp $ */
+/* $NetBSD: xenbus_comms.c,v 1.24 2020/05/13 13:19:38 jdolecek Exp $ */
 /**
  * xenbus_comms.c
  *
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.23 2020/05/06 16:50:13 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.24 2020/05/13 13:19:38 jdolecek Exp $");
 
 #include 
 #include  
@@ -219,11 +219,17 @@ xb_read(void *data, unsigned len)
 int
 xb_init_comms(device_t dev)
 {
-	int evtchn;
-
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_TTY);
 	cv_init(_cv, "xsio");
 
+	return xb_resume_comms(dev);
+}
+
+int
+xb_resume_comms(device_t dev)
+{
+	int evtchn;
+
 	evtchn = xen_start_info.store_evtchn;
 
 	ih = xen_intr_establish_xname(-1, _pic, evtchn, IST_LEVEL, IPL_TTY,

Index: src/sys/arch/xen/xenbus/xenbus_comms.h
diff -u src/sys/arch/xen/xenbus/xenbus_comms.h:1.7 src/sys/arch/xen/xenbus/xenbus_comms.h:1.8
--- src/sys/arch/xen/xenbus/xenbus_comms.h:1.7	Wed May  6 16:50:13 2020
+++ src/sys/arch/xen/xenbus/xenbus_comms.h	Wed May 13 13:19:38 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_comms.h,v 1.7 2020/05/06 16:50:13 bouyer Exp $ */
+/* $NetBSD: xenbus_comms.h,v 1.8 2020/05/13 13:19:38 jdolecek Exp $ */
 /*
  * Private include for xenbus communications.
  * 
@@ -30,10 +30,10 @@
 #define _XENBUS_COMMS_H
 
 void xenbus_kernfs_init(void);
-int xs_init(device_t dev);
-int xb_init_comms(device_t dev);
-void xb_suspend_comms(device_t dev);
-void xb_resume_comms(device_t dev);
+int xs_init(device_t);
+int xb_init_comms(device_t);
+void xb_suspend_comms(device_t);
+int xb_resume_comms(device_t);
 
 void xb_xenstored_make_ready(void);
 

Index: src/sys/arch/xen/xenbus/xenbus_probe.c
diff -u src/sys/arch/xen/xenbus/xenbus_probe.c:1.52 src/sys/arch/xen/xenbus/xenbus_probe.c:1.53
--- src/sys/arch/xen/xenbus/xenbus_probe.c:1.52	Wed May  6 16:50:13 2020
+++ src/sys/arch/xen/xenbus/xenbus_probe.c	Wed May 13 13:19:38 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_probe.c,v 1.52 2020/05/06 16:50:13 bouyer Exp $ */
+/* $NetBSD: xenbus_probe.c,v 1.53 2020/05/13 13:19:38 jdolecek Exp $ */
 /**
  * Talks to Xen Store to figure out what devices we have.
  *
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.52 2020/05/06 16:50:13 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.53 2020/05/13 13:19:38 jdolecek Exp $");
 
 #if 0
 #define DPRINTK(fmt, args...) \
@@ -131,7 +131,7 @@ xenbus_suspend(device_t dev, const pmf_q
 static bool
 xenbus_resume(device_t dev, const pmf_qual_t *qual)
 {
-	

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

2020-05-12 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue May 12 09:54:02 UTC 2020

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

Log Message:
move xen_intr_disestablish() call in xbd_xenbus_suspend() so it's executed
without holding the xbd mutex, to avoid LOCKDEBUG assertion on suspend

while here only disestablish the intr if it was established

part of PR port-xen/55207


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/sys/arch/xen/xen/xbd_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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.125 src/sys/arch/xen/xen/xbd_xenbus.c:1.126
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.125	Thu May  7 19:25:57 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Tue May 12 09:54:02 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.125 2020/05/07 19:25:57 maxv Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.126 2020/05/12 09:54:02 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.125 2020/05/07 19:25:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.126 2020/05/12 09:54:02 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -436,7 +436,10 @@ xbd_xenbus_detach(device_t dev, int flag
 	}
 
 	hypervisor_mask_event(sc->sc_evtchn);
-	xen_intr_disestablish(sc->sc_ih);
+	if (sc->sc_ih != NULL) {
+		xen_intr_disestablish(sc->sc_ih);
+		sc->sc_ih = NULL;
+	}
 
 	mutex_enter(>sc_lock);
 	while (xengnt_status(sc->sc_ring_gntref))
@@ -488,10 +491,14 @@ xbd_xenbus_suspend(device_t dev, const p
 
 	hypervisor_mask_event(sc->sc_evtchn);
 	sc->sc_backend_status = BLKIF_STATE_SUSPENDED;
-	xen_intr_disestablish(sc->sc_ih);
 
 	mutex_exit(>sc_lock);
 
+	if (sc->sc_ih != NULL) {
+		xen_intr_disestablish(sc->sc_ih);
+		sc->sc_ih = NULL;
+	}
+
 	xenbus_device_suspend(sc->sc_xbusd);
 	aprint_verbose_dev(dev, "removed event channel %d\n", sc->sc_evtchn);
 



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

2020-05-09 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sat May  9 08:01:38 UTC 2020

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

Log Message:
Also set x86_delay to xen_delay, unbreaks PVH


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/sys/arch/xen/xen/hypervisor.c

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

Modified files:

Index: src/sys/arch/xen/xen/hypervisor.c
diff -u src/sys/arch/xen/xen/hypervisor.c:1.83 src/sys/arch/xen/xen/hypervisor.c:1.84
--- src/sys/arch/xen/xen/hypervisor.c:1.83	Fri May  8 17:28:33 2020
+++ src/sys/arch/xen/xen/hypervisor.c	Sat May  9 08:01:38 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.83 2020/05/08 17:28:33 bouyer Exp $ */
+/* $NetBSD: hypervisor.c,v 1.84 2020/05/09 08:01:38 bouyer Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.83 2020/05/08 17:28:33 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.84 2020/05/09 08:01:38 bouyer Exp $");
 
 #include 
 #include 
@@ -258,7 +258,7 @@ init_xen_early(void)
 		printk(
 		"Xen HVM: Unable to register HYPERVISOR_shared_info %d\n", err);
 	}
-	delay_func = xen_delay;
+	delay_func = x86_delay = xen_delay;
 	x86_initclock_func = xen_initclocks;
 	x86_cpu_initclock_func = xen_cpu_initclocks;
 	if (hvm_start_info->cmdline_paddr != 0) {
@@ -434,7 +434,7 @@ xen_hvm_init(void)
 	xen_start_info.console.domU.evtchn = xen_hvm_param.value;
 
 
-	delay_func = xen_delay;
+	delay_func = x86_delay = xen_delay;
 	x86_initclock_func = xen_initclocks;
 	x86_cpu_initclock_func = xen_cpu_initclocks;
 



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

2020-05-08 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri May  8 17:28:33 UTC 2020

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

Log Message:
strlcpy() the command line only if it's present.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/arch/xen/xen/hypervisor.c

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

Modified files:

Index: src/sys/arch/xen/xen/hypervisor.c
diff -u src/sys/arch/xen/xen/hypervisor.c:1.82 src/sys/arch/xen/xen/hypervisor.c:1.83
--- src/sys/arch/xen/xen/hypervisor.c:1.82	Thu May  7 15:44:35 2020
+++ src/sys/arch/xen/xen/hypervisor.c	Fri May  8 17:28:33 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.82 2020/05/07 15:44:35 bouyer Exp $ */
+/* $NetBSD: hypervisor.c,v 1.83 2020/05/08 17:28:33 bouyer Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.82 2020/05/07 15:44:35 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.83 2020/05/08 17:28:33 bouyer Exp $");
 
 #include 
 #include 
@@ -261,10 +261,14 @@ init_xen_early(void)
 	delay_func = xen_delay;
 	x86_initclock_func = xen_initclocks;
 	x86_cpu_initclock_func = xen_cpu_initclocks;
-	cmd_line =
-	(void *)((uintptr_t)hvm_start_info->cmdline_paddr + KERNBASE);
-	strlcpy(xen_start_info.cmd_line, cmd_line,
-	sizeof(xen_start_info.cmd_line));
+	if (hvm_start_info->cmdline_paddr != 0) {
+		cmd_line =
+		(void *)((uintptr_t)hvm_start_info->cmdline_paddr + KERNBASE);
+		strlcpy(xen_start_info.cmd_line, cmd_line,
+		sizeof(xen_start_info.cmd_line));
+	} else {
+		xen_start_info.cmd_line[0] = '\0';
+	}
 	xen_start_info.flags = hvm_start_info->flags;
 }
 



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

2020-05-07 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu May  7 19:52:50 UTC 2020

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

Log Message:
Go back using cpu_info_primary, all events are bound to vCPU 0 by default.
Register the event handler on cpu_info_primary.
While there. update the event counter on interrupts.
Finally this should be MP-safe.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 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.59 src/sys/arch/xen/xen/xenevt.c:1.60
--- src/sys/arch/xen/xen/xenevt.c:1.59	Wed May  6 20:40:33 2020
+++ src/sys/arch/xen/xen/xenevt.c	Thu May  7 19:52:50 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xenevt.c,v 1.59 2020/05/06 20:40:33 bouyer Exp $  */
+/*  $NetBSD: xenevt.c,v 1.60 2020/05/07 19:52:50 bouyer Exp $  */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.59 2020/05/06 20:40:33 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.60 2020/05/07 19:52:50 bouyer Exp $");
 
 #include "opt_xen.h"
 #include 
@@ -129,6 +129,7 @@ struct xenevt_d {
 };
 
 static struct intrhand *xenevt_ih;
+static evtchn_port_t xenevt_ev;
 
 /* event -> user device mapping */
 static struct xenevt_d *devevent[NR_EVENT_CHANNELS];
@@ -175,15 +176,17 @@ xenevtattach(int n)
 
 	/*
 	 * Allocate a loopback event port.
-	 * This helps us massage xenevt_processevt() into the
-	 * callchain at the appropriate level using only
-	 * intr_establish_xname().
+	 * It won't be used by itself, but will help registering IPL
+	 * handlers.
 	 */
-	evtchn_port_t evtchn = xenevt_alloc_event();
+	xenevt_ev = xenevt_alloc_event();
 
-	/* The real objective here is to wiggle into the ih callchain for IPL level */
-	xenevt_ih = intr_establish_xname(-1, _pic, evtchn, 
-	IST_LEVEL, level, xenevt_processevt, NULL, true, "xenevt");
+	/*
+	 * The real objective here is to wiggle into the ih callchain for
+	 * IPL level on vCPU 0. (events are bound to vCPU 0 by default).
+	 */
+	xenevt_ih = event_set_handler(xenevt_ev, xenevt_processevt, NULL,
+	level, NULL, "xenevt", true, _info_primary);
 
 	KASSERT(xenevt_ih != NULL);
 }
@@ -192,9 +195,12 @@ xenevtattach(int n)
 void
 xenevt_setipending(int l1, int l2)
 {
+	KASSERT(curcpu() == xenevt_ih->ih_cpu);
+	KASSERT(xenevt_ih->ih_cpu->ci_ilevel >= IPL_HIGH);
 	atomic_or_ulong(_ev1, 1UL << l1);
 	atomic_or_ulong(_ev2[l1], 1UL << l2);
 	atomic_or_32(_ih->ih_cpu->ci_ipending, 1 << SIR_XENIPL_HIGH);
+	evtsource[xenevt_ev]->ev_evcnt.ev_count++;
 }
 
 /* process pending events */



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

2020-05-07 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu May  7 19:49:30 UTC 2020

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

Log Message:
This should be mpsafe, register the event handler as such.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 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.95 src/sys/arch/xen/xen/xbdback_xenbus.c:1.96
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.95	Wed May  6 20:09:26 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Thu May  7 19:49:29 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.95 2020/05/06 20:09:26 bouyer Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.96 2020/05/07 19:49:29 bouyer Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.95 2020/05/06 20:09:26 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.96 2020/05/07 19:49:29 bouyer Exp $");
 
 #include 
 #include 
@@ -597,7 +597,7 @@ xbdback_connect(struct xbdback_instance 
 	xbdi->xbdi_evtchn = evop.u.bind_interdomain.local_port;
 
 	xbdi->xbdi_ih = intr_establish_xname(-1, _pic, xbdi->xbdi_evtchn,
-	IST_LEVEL, IPL_BIO, xbdback_evthandler, xbdi, false,
+	IST_LEVEL, IPL_BIO, xbdback_evthandler, xbdi, true,
 	xbdi->xbdi_name);
 	KASSERT(xbdi->xbdi_ih != NULL);
 	aprint_verbose("xbd backend domain %d handle %#x (%d) "



CVS commit: src/sys/arch/xen

2020-05-07 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu May  7 19:48:58 UTC 2020

Modified Files:
src/sys/arch/xen/include: evtchn.h
src/sys/arch/xen/x86: xen_intr.c xen_ipi.c
src/sys/arch/xen/xen: evtchn.c xen_clock.c

Log Message:
Change event_set_handler() to take the target CPU parameter. If ci is NULL,
  event_set_handler() will choose the CPU and bind the event.
  If ci is not NULL the caller is responsible for binding the event.
Use a IPI xcall to register the handlers if needed.
pull in a hack from x86 to force pirq handlers to be mpsafe if registered at
a level != IPL_VM. This is for the com at isa interrupt handler, which
registers at IPL_HIGH and has to way to tell it's mpsafe (taking
KERNEL_LOCK at IPL_HIGH causes deadlocks on MP systems).


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/xen/include/evtchn.h
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/xen/x86/xen_intr.c
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/xen/x86/xen_ipi.c
cvs rdiff -u -r1.93 -r1.94 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/xen/xen/xen_clock.c

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

Modified files:

Index: src/sys/arch/xen/include/evtchn.h
diff -u src/sys/arch/xen/include/evtchn.h:1.31 src/sys/arch/xen/include/evtchn.h:1.32
--- src/sys/arch/xen/include/evtchn.h:1.31	Mon May  4 15:55:56 2020
+++ src/sys/arch/xen/include/evtchn.h	Thu May  7 19:48:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.h,v 1.31 2020/05/04 15:55:56 jdolecek Exp $	*/
+/*	$NetBSD: evtchn.h,v 1.32 2020/05/07 19:48:58 bouyer Exp $	*/
 
 /*
  *
@@ -40,12 +40,11 @@ unsigned int evtchn_do_event(int, struct
 void call_evtchn_do_event(int, struct intrframe *);
 void call_xenevt_event(int);
 struct intrhand *event_set_handler(int, int (*func)(void *), void *,
-int, const char *, const char *, bool, bool);
+int, const char *, const char *, bool, struct cpu_info *);
 int event_remove_handler(int, int (*func)(void *), void *);
 
 struct cpu_info;
 struct intrhand;
-void event_set_iplhandler(struct cpu_info *, struct intrhand *, int);
 
 extern int debug_port;
 extern int xen_debug_handler(void *);

Index: src/sys/arch/xen/x86/xen_intr.c
diff -u src/sys/arch/xen/x86/xen_intr.c:1.26 src/sys/arch/xen/x86/xen_intr.c:1.27
--- src/sys/arch/xen/x86/xen_intr.c:1.26	Tue May  5 17:02:01 2020
+++ src/sys/arch/xen/x86/xen_intr.c	Thu May  7 19:48:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_intr.c,v 1.26 2020/05/05 17:02:01 bouyer Exp $	*/
+/*	$NetBSD: xen_intr.c,v 1.27 2020/05/07 19:48:58 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.26 2020/05/05 17:02:01 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.27 2020/05/07 19:48:58 bouyer Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -143,7 +143,7 @@ xen_intr_establish_xname(int legacy_irq,
 		sizeof(intrstr_buf));
 
 		rih = event_set_handler(pin, handler, arg, level,
-		intrstr, xname, known_mpsafe, true);
+		intrstr, xname, known_mpsafe, NULL);
 
 		if (rih == NULL) {
 			printf("%s: can't establish interrupt\n", __func__);
@@ -157,6 +157,8 @@ xen_intr_establish_xname(int legacy_irq,
 	struct pintrhand *pih;
 	int gsi;
 	int evtchn;
+	/* the hack below is from x86's intr_establish_xname() */
+	bool mpsafe = (known_mpsafe || level != IPL_VM);
 
 	KASSERTMSG(legacy_irq == -1 || (0 <= legacy_irq && legacy_irq < NUM_XEN_IRQS),
 	"bad legacy IRQ value: %d", legacy_irq);
@@ -190,7 +192,7 @@ xen_intr_establish_xname(int legacy_irq,
 	}
 
 	pih = pirq_establish(gsi, evtchn, handler, arg, level,
-			 intrstr, xname, known_mpsafe);
+			 intrstr, xname, mpsafe);
 	pih->pic = pic;
 	return pih;
 #endif /* NPCI > 0 || NISA > 0 */

Index: src/sys/arch/xen/x86/xen_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.38 src/sys/arch/xen/x86/xen_ipi.c:1.39
--- src/sys/arch/xen/x86/xen_ipi.c:1.38	Sat Apr 25 15:26:17 2020
+++ src/sys/arch/xen/x86/xen_ipi.c	Thu May  7 19:48:58 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.38 2020/04/25 15:26:17 bouyer Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.39 2020/05/07 19:48:58 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2011, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  * Based on: x86/ipi.c
  */
 
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.38 2020/04/25 15:26:17 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.39 2020/05/07 19:48:58 bouyer Exp $");
 
 #include "opt_ddb.h"
 
@@ -143,7 +143,7 @@ xen_ipi_init(void)
 	device_xname(ci->ci_dev));
 
 	if (event_set_handler(evtchn, xen_ipi_handler, ci, IPL_HIGH, NULL,
-	intr_xname, true, false) == NULL) {
+	intr_xname, true, ci) == NULL) {
 		panic("%s: unable to register ipi handler\n", __func__);
 		/* NOTREACHED */
 	}

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.93 src/sys/arch/xen/xen/evtchn.c:1.94
--- 

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

2020-05-07 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu May  7 19:25:57 UTC 2020

Modified Files:
src/sys/arch/xen/xen: xbd_xenbus.c xencons.c

Log Message:
Localify.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/sys/arch/xen/xen/xbd_xenbus.c
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/xen/xen/xencons.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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.124 src/sys/arch/xen/xen/xbd_xenbus.c:1.125
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.124	Sun May  3 17:54:28 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Thu May  7 19:25:57 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.124 2020/05/03 17:54:28 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.125 2020/05/07 19:25:57 maxv Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.124 2020/05/03 17:54:28 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.125 2020/05/07 19:25:57 maxv Exp $");
 
 #include "opt_xen.h"
 
@@ -214,14 +214,14 @@ CFATTACH_DECL3_NEW(xbd, sizeof(struct xb
 xbd_xenbus_match, xbd_xenbus_attach, xbd_xenbus_detach, NULL, NULL, NULL,
 DVF_DETACH_SHUTDOWN);
 
-dev_type_open(xbdopen);
-dev_type_close(xbdclose);
-dev_type_read(xbdread);
-dev_type_write(xbdwrite);
-dev_type_ioctl(xbdioctl);
-dev_type_strategy(xbdstrategy);
-dev_type_dump(xbddump);
-dev_type_size(xbdsize);
+static dev_type_open(xbdopen);
+static dev_type_close(xbdclose);
+static dev_type_read(xbdread);
+static dev_type_write(xbdwrite);
+static dev_type_ioctl(xbdioctl);
+static dev_type_strategy(xbdstrategy);
+static dev_type_dump(xbddump);
+static dev_type_size(xbdsize);
 
 const struct bdevsw xbd_bdevsw = {
 	.d_open = xbdopen,
@@ -924,7 +924,7 @@ xbd_iosize(device_t dev, int *maxxfer)
 		*maxxfer = XBD_MAX_XFER;
 }
 
-int
+static int
 xbdopen(dev_t dev, int flags, int fmt, struct lwp *l)
 {
 	struct	xbd_xenbus_softc *sc;
@@ -939,7 +939,7 @@ xbdopen(dev_t dev, int flags, int fmt, s
 	return dk_open(>sc_dksc, dev, flags, fmt, l);
 }
 
-int
+static int
 xbdclose(dev_t dev, int flags, int fmt, struct lwp *l)
 {
 	struct xbd_xenbus_softc *sc;
@@ -950,7 +950,7 @@ xbdclose(dev_t dev, int flags, int fmt, 
 	return dk_close(>sc_dksc, dev, flags, fmt, l);
 }
 
-void
+static void
 xbdstrategy(struct buf *bp)
 {
 	struct xbd_xenbus_softc *sc;
@@ -976,7 +976,7 @@ xbdstrategy(struct buf *bp)
 	return;
 }
 
-int
+static int
 xbdsize(dev_t dev)
 {
 	struct	xbd_xenbus_softc *sc;
@@ -989,7 +989,7 @@ xbdsize(dev_t dev)
 	return dk_size(>sc_dksc, dev);
 }
 
-int
+static int
 xbdread(dev_t dev, struct uio *uio, int flags)
 {
 	struct xbd_xenbus_softc *sc = 
@@ -1001,7 +1001,7 @@ xbdread(dev_t dev, struct uio *uio, int 
 	return physio(xbdstrategy, NULL, dev, B_READ, xbdminphys, uio);
 }
 
-int
+static int
 xbdwrite(dev_t dev, struct uio *uio, int flags)
 {
 	struct xbd_xenbus_softc *sc =
@@ -1015,7 +1015,7 @@ xbdwrite(dev_t dev, struct uio *uio, int
 	return physio(xbdstrategy, NULL, dev, B_WRITE, xbdminphys, uio);
 }
 
-int
+static int
 xbdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
 {
 	struct xbd_xenbus_softc *sc =
@@ -1087,7 +1087,7 @@ xbdioctl(dev_t dev, u_long cmd, void *da
 	return error;
 }
 
-int
+static int
 xbddump(dev_t dev, daddr_t blkno, void *va, size_t size)
 {
 	struct xbd_xenbus_softc *sc;

Index: src/sys/arch/xen/xen/xencons.c
diff -u src/sys/arch/xen/xen/xencons.c:1.49 src/sys/arch/xen/xen/xencons.c:1.50
--- src/sys/arch/xen/xen/xencons.c:1.49	Sat Apr 25 15:26:18 2020
+++ src/sys/arch/xen/xen/xencons.c	Thu May  7 19:25:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xencons.c,v 1.49 2020/04/25 15:26:18 bouyer Exp $	*/
+/*	$NetBSD: xencons.c,v 1.50 2020/05/07 19:25:57 maxv Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xencons.c,v 1.49 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xencons.c,v 1.50 2020/05/07 19:25:57 maxv Exp $");
 
 #include "opt_xen.h"
 
@@ -96,11 +96,10 @@ static struct intrhand *ih;
 #define	XENCONS_UNIT(x)	(minor(x))
 #define XENCONS_BURST 128
 
-int xencons_match(device_t, cfdata_t, void *);
-void xencons_attach(device_t, device_t, void *);
-int xencons_intr(void *);
-void xencons_tty_input(struct xencons_softc *, char*, int);
-
+static int xencons_match(device_t, cfdata_t, void *);
+static void xencons_attach(device_t, device_t, void *);
+static int xencons_intr(void *);
+static void xencons_tty_input(struct xencons_softc *, char*, int);
 
 struct xencons_softc {
 	device_t sc_dev;
@@ -114,14 +113,14 @@ CFATTACH_DECL_NEW(xencons, sizeof(struct
 
 extern struct cfdriver xencons_cd;
 
-dev_type_open(xencons_open);
-dev_type_close(xencons_close);
-dev_type_read(xencons_read);
-dev_type_write(xencons_write);
-dev_type_ioctl(xencons_ioctl);

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

2020-05-07 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu May  7 15:44:35 UTC 2020

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

Log Message:
Cast physical address to uintptr_t, fix PAE build.
Pointed out by John D. Baker


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sys/arch/xen/xen/hypervisor.c

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

Modified files:

Index: src/sys/arch/xen/xen/hypervisor.c
diff -u src/sys/arch/xen/xen/hypervisor.c:1.81 src/sys/arch/xen/xen/hypervisor.c:1.82
--- src/sys/arch/xen/xen/hypervisor.c:1.81	Tue May  5 17:02:01 2020
+++ src/sys/arch/xen/xen/hypervisor.c	Thu May  7 15:44:35 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.81 2020/05/05 17:02:01 bouyer Exp $ */
+/* $NetBSD: hypervisor.c,v 1.82 2020/05/07 15:44:35 bouyer Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.81 2020/05/05 17:02:01 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.82 2020/05/07 15:44:35 bouyer Exp $");
 
 #include 
 #include 
@@ -244,7 +244,7 @@ init_xen_early(void)
 	xen_init_hypercall_page();
 	hvm_start_info = (void *)((uintptr_t)hvm_start_paddr + KERNBASE);
 
-	HYPERVISOR_shared_info = (void *)(HYPERVISOR_shared_info_pa + KERNBASE);
+	HYPERVISOR_shared_info = (void *)((uintptr_t)HYPERVISOR_shared_info_pa + KERNBASE);
 	struct xen_add_to_physmap xmap = {
 		.domid = DOMID_SELF,
 		.space = XENMAPSPACE_shared_info,



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

2020-05-06 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed May  6 20:40:33 UTC 2020

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

Log Message:
The event channel is not necesserely bound to the primary CPU.
Use the CPU returned in the interrupt handler instead.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 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.58 src/sys/arch/xen/xen/xenevt.c:1.59
--- src/sys/arch/xen/xen/xenevt.c:1.58	Tue May  5 17:02:01 2020
+++ src/sys/arch/xen/xen/xenevt.c	Wed May  6 20:40:33 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xenevt.c,v 1.58 2020/05/05 17:02:01 bouyer Exp $  */
+/*  $NetBSD: xenevt.c,v 1.59 2020/05/06 20:40:33 bouyer Exp $  */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.58 2020/05/05 17:02:01 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.59 2020/05/06 20:40:33 bouyer Exp $");
 
 #include "opt_xen.h"
 #include 
@@ -128,6 +128,8 @@ struct xenevt_d {
 	struct cpu_info *ci; /* prefered CPU for events for this device */
 };
 
+static struct intrhand *xenevt_ih;
+
 /* event -> user device mapping */
 static struct xenevt_d *devevent[NR_EVENT_CHANNELS];
 
@@ -160,7 +162,6 @@ static evtchn_port_t xenevt_alloc_event(
 void
 xenevtattach(int n)
 {
-	struct intrhand *ih __diagused;
 	int level = IPL_HIGH;
 
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_HIGH);
@@ -181,10 +182,10 @@ xenevtattach(int n)
 	evtchn_port_t evtchn = xenevt_alloc_event();
 
 	/* The real objective here is to wiggle into the ih callchain for IPL level */
-	ih = intr_establish_xname(-1, _pic, evtchn,  IST_LEVEL, level,
-	xenevt_processevt, NULL, true, "xenevt");
+	xenevt_ih = intr_establish_xname(-1, _pic, evtchn, 
+	IST_LEVEL, level, xenevt_processevt, NULL, true, "xenevt");
 
-	KASSERT(ih != NULL);
+	KASSERT(xenevt_ih != NULL);
 }
 
 /* register pending event - always called with interrupt disabled */
@@ -193,7 +194,7 @@ xenevt_setipending(int l1, int l2)
 {
 	atomic_or_ulong(_ev1, 1UL << l1);
 	atomic_or_ulong(_ev2[l1], 1UL << l2);
-	atomic_or_32(_info_primary.ci_ipending, 1 << SIR_XENIPL_HIGH);
+	atomic_or_32(_ih->ih_cpu->ci_ipending, 1 << SIR_XENIPL_HIGH);
 }
 
 /* process pending events */
@@ -307,7 +308,7 @@ xenevtopen(dev_t dev, int flags, int mod
 			return error;
 
 		d = kmem_zalloc(sizeof(*d), KM_SLEEP);
-		d->ci = _info_primary;
+		d->ci = xenevt_ih->ih_cpu;
 		mutex_init(>lock, MUTEX_DEFAULT, IPL_HIGH);
 		cv_init(>cv, "xenevt");
 		selinit(>sel);



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

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

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

Log Message:
Drop xbdi_lock() before calling intr_disestablish(), it needs to take
cpu_lock.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 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.94 src/sys/arch/xen/xen/xbdback_xenbus.c:1.95
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.94	Wed May  6 19:49:00 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Wed May  6 20:09:26 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.94 2020/05/06 19:49:00 bouyer Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.95 2020/05/06 20:09:26 bouyer Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.94 2020/05/06 19:49:00 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.95 2020/05/06 20:09:26 bouyer Exp $");
 
 #include 
 #include 
@@ -643,7 +643,6 @@ xbdback_disconnect(struct xbdback_instan
 		return;
 	}
 	hypervisor_mask_event(xbdi->xbdi_evtchn);
-	intr_disestablish(xbdi->xbdi_ih);
 
 	/* signal thread that we want to disconnect, then wait for it */
 	xbdi->xbdi_status = DISCONNECTING;
@@ -653,6 +652,7 @@ xbdback_disconnect(struct xbdback_instan
 		cv_wait(>xbdi_cv, >xbdi_lock);
 
 	mutex_exit(>xbdi_lock);
+	intr_disestablish(xbdi->xbdi_ih);
 
 	xenbus_switch_state(xbdi->xbdi_xbusd, NULL, XenbusStateClosing);
 }



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

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

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

Log Message:
Attempts to make MP-safe:
xpmap_ptom_unmap() doens't need to be called at splvm; we own the pa.
Use atomic ops to change pmap_pa_end
Make sure the ptom/mtop are up to date before giving the pages back to the
pool.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/xen/xen/balloon.c

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

Modified files:

Index: src/sys/arch/xen/xen/balloon.c
diff -u src/sys/arch/xen/xen/balloon.c:1.22 src/sys/arch/xen/xen/balloon.c:1.23
--- src/sys/arch/xen/xen/balloon.c:1.22	Wed May  6 17:27:39 2020
+++ src/sys/arch/xen/xen/balloon.c	Wed May  6 19:52:19 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: balloon.c,v 1.22 2020/05/06 17:27:39 bouyer Exp $ */
+/* $NetBSD: balloon.c,v 1.23 2020/05/06 19:52:19 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: balloon.c,v 1.22 2020/05/06 17:27:39 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: balloon.c,v 1.23 2020/05/06 19:52:19 bouyer Exp $");
 
 #include 
 #include 
@@ -366,7 +366,7 @@ bpge_dtor(void *arg, void *obj)
 static size_t
 balloon_inflate(struct balloon_xenbus_softc *sc, size_t tpages)
 {
-	int rpages, s, ret;
+	int rpages, ret;
 	paddr_t pa;
 	struct balloon_page_entry *bpg_entry;
 	xen_pfn_t *mfn_list = sc->sc_mfn_list;
@@ -395,10 +395,8 @@ balloon_inflate(struct balloon_xenbus_so
 
 		mfn_list[rpages] = xpmap_ptom(pa) >> PAGE_SHIFT;
 
-		s = splvm(); /* XXXSMP */
 		/* Invalidate pg */
 		xpmap_ptom_unmap(pa);
-		splx(s);
 
 		SLIST_INSERT_HEAD(_sc->balloon_page_entries, 
   bpg_entry, entry);
@@ -494,19 +492,29 @@ balloon_deflate(struct balloon_xenbus_so
 			pa = pmap_pa_end;
 
 			/* P2M update */
-			s = splvm(); /* XXXSMP */
-			pmap_pa_end += PAGE_SIZE; /* XXX: TLB flush ?*/
+#if defined(_LP64) || defined(PAE)
+			atomic_add_64(_pa_end, PAGE_SIZE);
+#else
+			atomic_add_32(_pa_end, PAGE_SIZE);
+#endif
+			s = splvm();
 			xpmap_ptom_map(pa, ptoa(mfn_list[rpages]));
 			xpq_queue_machphys_update(ptoa(mfn_list[rpages]), pa);
+			xpq_flush_queue();
 			splx(s);
 
 			if (uvm_physseg_plug(atop(pa), 1, NULL) == false) {
 /* Undo P2M */
-s = splvm(); /* XXXSMP */
+s = splvm();
 xpmap_ptom_unmap(pa);
 xpq_queue_machphys_update(ptoa(mfn_list[rpages]), 0);
-pmap_pa_end -= PAGE_SIZE; /* XXX: TLB flush ?*/
+xpq_flush_queue();
 splx(s);
+#if defined(_LP64) || defined(PAE)
+atomic_add_64(_pa_end, -PAGE_SIZE);
+#else
+atomic_add_32(_pa_end, -PAGE_SIZE);
+#endif
 break;
 			}
 			continue;
@@ -529,18 +537,15 @@ balloon_deflate(struct balloon_xenbus_so
 		/* Update P->M */
 		pa = VM_PAGE_TO_PHYS(bpg_entry->pg);
 
-		s = splvm(); /* XXXSMP */
-
+		s = splvm();
 		xpmap_ptom_map(pa, ptoa(mfn_list[rpages]));
 		xpq_queue_machphys_update(ptoa(mfn_list[rpages]), pa);
-
+		xpq_flush_queue();
 		splx(s);
 
 		pool_cache_put(sc->bpge_pool, bpg_entry);
 	}
 
-	xpq_flush_queue();
-
 #if BALLOONDEBUG
 	device_printf(sc->sc_dev, "deflate %zu => deflated by %d\n",
 	tpages, rpages);



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

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

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

Log Message:
We can't take v_interlock with a spin lock held. Release xbdi_lock
before scheduling the I/O, and take again once queued.
It looks safe to drop the lock here.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 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.93 src/sys/arch/xen/xen/xbdback_xenbus.c:1.94
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.93	Tue May  5 17:02:01 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Wed May  6 19:49:00 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.93 2020/05/05 17:02:01 bouyer Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.94 2020/05/06 19:49:00 bouyer Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.93 2020/05/05 17:02:01 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.94 2020/05/06 19:49:00 bouyer Exp $");
 
 #include 
 #include 
@@ -1387,6 +1387,8 @@ xbdback_co_do_io(struct xbdback_instance
 	}
 	case BLKIF_OP_READ:
 	case BLKIF_OP_WRITE:
+		KASSERT(mutex_owned(>xbdi_lock));
+		mutex_exit(>xbdi_lock);
 		xbd_io->xio_buf.b_data = (void *)
 		(xbd_io->xio_vaddr + xbd_io->xio_start_offset);
 
@@ -1397,6 +1399,7 @@ xbdback_co_do_io(struct xbdback_instance
 		}
 		/* will call xbdback_iodone() asynchronously when done */
 		bdev_strategy(_io->xio_buf);
+		mutex_enter(>xbdi_lock);
 		xbdi->xbdi_cont = xbdback_co_main_incr;
 		return xbdi;
 	default:



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

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

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

Log Message:
No need to run hypercalls at IPL_VM.
XXX still not MP-safe


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/xen/xen/balloon.c

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

Modified files:

Index: src/sys/arch/xen/xen/balloon.c
diff -u src/sys/arch/xen/xen/balloon.c:1.21 src/sys/arch/xen/xen/balloon.c:1.22
--- src/sys/arch/xen/xen/balloon.c:1.21	Sat Apr 25 15:26:18 2020
+++ src/sys/arch/xen/xen/balloon.c	Wed May  6 17:27:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: balloon.c,v 1.21 2020/04/25 15:26:18 bouyer Exp $ */
+/* $NetBSD: balloon.c,v 1.22 2020/05/06 17:27:39 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: balloon.c,v 1.21 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: balloon.c,v 1.22 2020/05/06 17:27:39 bouyer Exp $");
 
 #include 
 #include 
@@ -272,15 +272,11 @@ error:
 static size_t
 xenmem_get_maxreservation(void)
 {
-	int s;
 	unsigned int ret;
 
-	s = splvm(); /* XXXSMP */
 	ret = HYPERVISOR_memory_op(XENMEM_maximum_reservation, 
 	& (domid_t) { DOMID_SELF });
 
-	splx(s);
-
 	if (ret == 0) {
 		/* well, a maximum reservation of 0 is really bogus */
 		panic("%s failed, maximum reservation returned 0", __func__);
@@ -293,12 +289,10 @@ xenmem_get_maxreservation(void)
 static size_t
 xenmem_get_currentreservation(void)
 {
-	int s, ret;
+	int ret;
 
-	s = splvm(); /* XXXSMP */
 	ret = HYPERVISOR_memory_op(XENMEM_current_reservation,
    & (domid_t) { DOMID_SELF });
-	splx(s);
 
 	if (ret < 0) {
 		panic("%s failed: %d", __func__, ret);
@@ -415,11 +409,8 @@ balloon_inflate(struct balloon_xenbus_so
 	set_xen_guest_handle(reservation.extent_start, mfn_list);
 	reservation.nr_extents = rpages;
 
-	s = splvm(); /* XXXSMP */
 	ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
    );
-	splx(s);
-
 	if (ret != rpages) {
 		/*
 		 * we are in bad shape: the operation failed for certain
@@ -481,9 +472,7 @@ balloon_deflate(struct balloon_xenbus_so
 	set_xen_guest_handle(reservation.extent_start, mfn_list);
 	reservation.nr_extents = tpages;
 
-	s = splvm(); /* XXXSMP */
 	ret = HYPERVISOR_memory_op(XENMEM_increase_reservation, );
-	splx(s);
 
 	if (ret < 0) {
 		panic("%s: increase reservation failed, ret %d",



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

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

Modified Files:
src/sys/arch/xen/xenbus: xenbus_comms.c xenbus_comms.h xenbus_probe.c
xenbus_xs.c

Log Message:
Convert remaining splfoo/splx and tsleep/wakeup to mutex and condvar.
Mark kernel threads and interrupt handlers MPSAFE.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/xen/xenbus/xenbus_comms.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/xen/xenbus/xenbus_comms.h
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/xen/xenbus/xenbus_probe.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/xen/xenbus/xenbus_xs.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/xenbus/xenbus_comms.c
diff -u src/sys/arch/xen/xenbus/xenbus_comms.c:1.22 src/sys/arch/xen/xenbus/xenbus_comms.c:1.23
--- src/sys/arch/xen/xenbus/xenbus_comms.c:1.22	Sat Apr 25 15:26:18 2020
+++ src/sys/arch/xen/xenbus/xenbus_comms.c	Wed May  6 16:50:13 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_comms.c,v 1.22 2020/04/25 15:26:18 bouyer Exp $ */
+/* $NetBSD: xenbus_comms.c,v 1.23 2020/05/06 16:50:13 bouyer Exp $ */
 /**
  * xenbus_comms.c
  *
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.22 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.23 2020/05/06 16:50:13 bouyer Exp $");
 
 #include 
 #include  
@@ -37,6 +37,7 @@ __KERNEL_RCSID(0, "$NetBSD: xenbus_comms
 #include 
 #include 
 #include 
+#include 
 
 #include 	/* for xendomain_is_dom0() */
 #include 	/* for xendomain_is_dom0() */
@@ -54,6 +55,8 @@ __KERNEL_RCSID(0, "$NetBSD: xenbus_comms
 
 static struct intrhand *ih;
 struct xenstore_domain_interface *xenstore_interface;
+static kmutex_t xenstore_lock;
+static kcondvar_t xenstore_cv;
 
 extern int xenstored_ready;
 // static DECLARE_WORK(probe_work, xenbus_probe, NULL);
@@ -76,11 +79,12 @@ static int
 wake_waiting(void *arg)
 {
 	if (__predict_false(xenstored_ready == 0 && xendomain_is_dom0())) {
-		xenstored_ready = 1;
-		wakeup(_ready);
+		xb_xenstored_make_ready();
 	} 
 
-	wakeup(_interface);
+	mutex_enter(_lock);
+	cv_broadcast(_cv);
+	mutex_exit(_lock);
 	return 1;
 }
 
@@ -118,16 +122,15 @@ xb_write(const void *data, unsigned len)
 	struct xenstore_domain_interface *intf = xenstore_domain_interface();
 	XENSTORE_RING_IDX cons, prod;
 
-	int s = spltty();
-
+	mutex_enter(_lock);
 	while (len != 0) {
 		void *dst;
 		unsigned int avail;
 
 		while ((intf->req_prod - intf->req_cons) == XENSTORE_RING_SIZE) {
-			XENPRINTF(("xb_write tsleep\n"));
-			tsleep(_interface, PRIBIO, "wrst", 0);
-			XENPRINTF(("xb_write tsleep done\n"));
+			XENPRINTF(("xb_write cv_wait\n"));
+			cv_wait(_cv, _lock);
+			XENPRINTF(("xb_write cv_wait done\n"));
 		}
 
 		/* Read indexes, then verify. */
@@ -135,7 +138,7 @@ xb_write(const void *data, unsigned len)
 		prod = intf->req_prod;
 		xen_rmb();
 		if (!check_indexes(cons, prod)) {
-			splx(s);
+			mutex_exit(_lock);
 			return EIO;
 		}
 
@@ -156,8 +159,7 @@ xb_write(const void *data, unsigned len)
 
 		hypervisor_notify_via_evtchn(xen_start_info.store_evtchn);
 	}
-
-	splx(s);
+	mutex_exit(_lock);
 	return 0;
 }
 
@@ -167,14 +169,14 @@ xb_read(void *data, unsigned len)
 	struct xenstore_domain_interface *intf = xenstore_domain_interface();
 	XENSTORE_RING_IDX cons, prod;
 
-	int s = spltty();
+	mutex_enter(_lock);
 
 	while (len != 0) {
 		unsigned int avail;
 		const char *src;
 
 		while (intf->rsp_cons == intf->rsp_prod)
-			tsleep(_interface, PRIBIO, "rdst", 0);
+			cv_wait(_cv, _lock);
 
 		/* Read indexes, then verify. */
 		cons = intf->rsp_cons;
@@ -182,7 +184,7 @@ xb_read(void *data, unsigned len)
 		xen_rmb();
 		if (!check_indexes(cons, prod)) {
 			XENPRINTF(("xb_read EIO\n"));
-			splx(s);
+			mutex_exit(_lock);
 			return EIO;
 		}
 
@@ -209,8 +211,7 @@ xb_read(void *data, unsigned len)
 
 		hypervisor_notify_via_evtchn(xen_start_info.store_evtchn);
 	}
-
-	splx(s);
+	mutex_exit(_lock);
 	return 0;
 }
 
@@ -220,10 +221,13 @@ xb_init_comms(device_t dev)
 {
 	int evtchn;
 
+	mutex_init(_lock, MUTEX_DEFAULT, IPL_TTY);
+	cv_init(_cv, "xsio");
+
 	evtchn = xen_start_info.store_evtchn;
 
 	ih = xen_intr_establish_xname(-1, _pic, evtchn, IST_LEVEL, IPL_TTY,
-	wake_waiting, NULL, false, device_xname(dev));
+	wake_waiting, NULL, true, device_xname(dev));
 
 	hypervisor_unmask_event(evtchn);
 	aprint_verbose_dev(dev, "using event channel %d\n", evtchn);

Index: src/sys/arch/xen/xenbus/xenbus_comms.h
diff -u src/sys/arch/xen/xenbus/xenbus_comms.h:1.6 src/sys/arch/xen/xenbus/xenbus_comms.h:1.7
--- src/sys/arch/xen/xenbus/xenbus_comms.h:1.6	Tue Sep 20 00:12:25 2011
+++ src/sys/arch/xen/xenbus/xenbus_comms.h	Wed May  6 16:50:13 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_comms.h,v 1.6 2011/09/20 00:12:25 jym Exp $ */
+/* $NetBSD: 

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

2020-05-06 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed May  6 13:43:48 UTC 2020

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

Log Message:
remove the per-channel spin lock and instead make sure that events
add/remove will only be done on the CPU the handler is bound to, with
interrupts disabled.
Should be similar to the native x86 interrupts add/remove.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 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.92 src/sys/arch/xen/xen/evtchn.c:1.93
--- src/sys/arch/xen/xen/evtchn.c:1.92	Mon May  4 15:55:56 2020
+++ src/sys/arch/xen/xen/evtchn.c	Wed May  6 13:43:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.92 2020/05/04 15:55:56 jdolecek Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.93 2020/05/06 13:43:48 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.92 2020/05/04 15:55:56 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.93 2020/05/06 13:43:48 bouyer Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -70,6 +70,7 @@ __KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -91,9 +92,6 @@ static kmutex_t evtchn_lock;
 /* event handlers */
 struct evtsource *evtsource[NR_EVENT_CHANNELS];
 
-/* channel locks */
-static kmutex_t evtlock[NR_EVENT_CHANNELS];
-
 /* Reference counts for bindings to event channels XXX: redo for SMP */
 static uint8_t evtch_bindcount[NR_EVENT_CHANNELS];
 
@@ -362,7 +360,6 @@ evtchn_do_event(int evtch, struct intrfr
 	KASSERT(ci->ci_ilevel >= IPL_VM);
 	KASSERT(cpu_intr_p());
 	x86_enable_intr();
-	mutex_spin_enter([evtch]);
 	ih = evtsource[evtch]->ev_handlers;
 	while (ih != NULL) {
 		KASSERT(ih->ih_cpu == ci);
@@ -383,7 +380,6 @@ evtchn_do_event(int evtch, struct intrfr
 			hypervisor_set_ipending(iplmask,
 			evtch >> LONG_SHIFT, evtch & LONG_MASK);
 			/* leave masked */
-			mutex_spin_exit([evtch]);
 			goto splx;
 		}
 		iplmask &= ~(1 << XEN_IPL2SIR(ih->ih_level));
@@ -392,7 +388,6 @@ evtchn_do_event(int evtch, struct intrfr
 		ih_fun(ih->ih_arg, regs);
 		ih = ih->ih_evt_next;
 	}
-	mutex_spin_exit([evtch]);
 	x86_disable_intr();
 	hypervisor_unmask_event(evtch);
 
@@ -773,13 +768,10 @@ intr_calculatemasks(struct evtsource *ev
 	struct intrhand *ih;
 	int cpu_receive = 0;
 
-#ifdef MULTIPROCESSOR
-	KASSERT(!mutex_owned([evtch]));
-#endif
-	mutex_spin_enter([evtch]);
 	evts->ev_maxlevel = IPL_NONE;
 	evts->ev_imask = 0;
 	for (ih = evts->ev_handlers; ih != NULL; ih = ih->ih_evt_next) {
+		KASSERT(ih->ih_cpu == curcpu());
 		if (ih->ih_level > evts->ev_maxlevel)
 			evts->ev_maxlevel = ih->ih_level;
 		evts->ev_imask |= (1 << XEN_IPL2SIR(ih->ih_level));
@@ -790,7 +782,6 @@ intr_calculatemasks(struct evtsource *ev
 		xen_atomic_set_bit(()->ci_evtmask[0], evtch);
 	else
 		xen_atomic_clear_bit(()->ci_evtmask[0], evtch);
-	mutex_spin_exit([evtch]);
 }
 
 struct intrhand *
@@ -800,7 +791,6 @@ event_set_handler(int evtch, int (*func)
 	struct cpu_info *ci = curcpu(); /* XXX: pass in ci ? */
 	struct evtsource *evts;
 	struct intrhand *ih, **ihp;
-	int s;
 	char intrstr_buf[INTRIDBUF];
 
 #ifdef IRQ_DEBUG
@@ -836,11 +826,7 @@ event_set_handler(int evtch, int (*func)
 	}
 #endif /* MULTIPROCESSOR */
 
-	s = splhigh();
-
-	/* register per-cpu handler for spllower() */
-	event_set_iplhandler(ci, ih, level);
-
+	mutex_enter(_lock);
 	/* register handler for event channel */
 	if (evtsource[evtch] == NULL) {
 		evtchn_op_t op;
@@ -860,7 +846,6 @@ event_set_handler(int evtch, int (*func)
 		 * is more explicitly implemented.
 		 */
 		evts->ev_cpu = ci;
-		mutex_init([evtch], MUTEX_DEFAULT, IPL_HIGH);
 		evtsource[evtch] = evts;
 		strlcpy(evts->ev_intrname, intrname, sizeof(evts->ev_intrname));
 
@@ -876,10 +861,14 @@ event_set_handler(int evtch, int (*func)
 ci->ci_vcpuid);
 			}
 		}
+#ifndef XENPV
+		evts->ev_isl = intr_allocate_io_intrsource(intrname);
+		evts->ev_isl->is_pic = _pic;
+		evts->ev_isl->is_handlers = evts->ev_handlers;
+#endif
 	} else {
 		evts = evtsource[evtch];
 		/* sort by IPL order, higher first */
-		mutex_spin_enter([evtch]);
 		for (ihp = >ev_handlers; ; ihp = &((*ihp)->ih_evt_next)) {
 			if ((*ihp)->ih_level < ih->ih_level) {
 /* insert before *ihp */
@@ -892,33 +881,23 @@ event_set_handler(int evtch, int (*func)
 break;
 			}
 		}
-		mutex_spin_exit([evtch]);
 #ifndef XENPV
-		mutex_enter(_lock);
 		evts->ev_isl->is_handlers = evts->ev_handlers;
-		mutex_exit(_lock);
 #endif
 	}
-
+	const u_long psl = x86_read_psl();
+	x86_disable_intr();
+	/* register per-cpu handler for spllower() */
+	event_set_iplhandler(ci, ih, level);
+	intr_calculatemasks(evts, evtch, ci);
+	x86_write_psl(psl);
 
 	// append device name
 	if (evts->ev_xname[0] != '\0')

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

2020-05-05 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue May  5 09:52:13 UTC 2020

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

Log Message:
due to the locking wild west for if_ioctl can't assert IFNET_LOCKED()
in xennet_ioctl(), so just do splnet() like other drivers do, and hope for best

fixes failed KASSERT() e.g. when starting rpcbind(), which ends
up calling this via sys_setsockopt()->sosetopt()->...->in6_addmulti()->
if_mcast_op(), this path doesn't currently take IFNET_LOCK()


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/sys/arch/xen/xen/if_xennet_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.123 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.124
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.123	Mon May  4 10:03:45 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Tue May  5 09:52:13 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.123 2020/05/04 10:03:45 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.124 2020/05/05 09:52:13 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,10 +81,11 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.123 2020/05/04 10:03:45 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.124 2020/05/05 09:52:13 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
+#include "opt_net_mpsafe.h"
 
 #include 
 #include 
@@ -1267,7 +1268,13 @@ xennet_ioctl(struct ifnet *ifp, u_long c
 #endif
 	int error = 0;
 
+#ifdef NET_MPSAFE
+#ifdef notyet
+	/* XXX IFNET_LOCK() is not taken in some cases e.g. multicast ioctls */
 	KASSERT(IFNET_LOCKED(ifp));
+#endif
+#endif
+	int s = splnet();
 
 	DPRINTFN(XEDB_FOLLOW, ("%s: xennet_ioctl()\n",
 	device_xname(sc->sc_dev)));
@@ -1278,6 +1285,8 @@ xennet_ioctl(struct ifnet *ifp, u_long c
 	DPRINTFN(XEDB_FOLLOW, ("%s: xennet_ioctl() returning %d\n",
 	device_xname(sc->sc_dev), error));
 
+	splx(s);
+
 	return error;
 }
 



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

2020-05-04 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon May  4 10:03:45 UTC 2020

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

Log Message:
fix delet-o


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/arch/xen/xen/if_xennet_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.122 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.123
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.122	Mon May  4 08:22:45 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Mon May  4 10:03:45 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.122 2020/05/04 08:22:45 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.123 2020/05/04 10:03:45 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.122 2020/05/04 08:22:45 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.123 2020/05/04 10:03:45 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -382,7 +382,7 @@ xennet_xenbus_attach(device_t parent, de
 		| IFCAP_CSUM_UDPv6_Rx
 		| IFCAP_CSUM_TCPv6_Rx;
 #define XN_M_CSUM_SUPPORTED 		\
-	(M_CSUM_TCPv4 | M_CSUM_UDPv4 | | M_CSUM_TCPv6 | M_CSUM_UDPv6)
+	(M_CSUM_TCPv4 | M_CSUM_UDPv4 | M_CSUM_TCPv6 | M_CSUM_UDPv6)
 
 	if (sc->sc_features & FEATURE_IPV6CSUM) {
 		/*



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

2020-05-04 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon May  4 08:22:45 UTC 2020

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

Log Message:
remove IPv4 csum offloading for xennet(4) - it's not complete, and even
if it was, it doesn't work with Linux Dom0 as it expects the IPv4 csum present


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/sys/arch/xen/xen/if_xennet_xenbus.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/xen/xen/xennet_checksum.c
cvs rdiff -u -r1.103 -r1.104 src/sys/arch/xen/xen/xennetback_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.121 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.122
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.121	Fri May  1 19:53:17 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Mon May  4 08:22:45 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.121 2020/05/01 19:53:17 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.122 2020/05/04 08:22:45 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.121 2020/05/01 19:53:17 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.122 2020/05/04 08:22:45 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -377,15 +377,13 @@ xennet_xenbus_attach(device_t parent, de
 	ifp->if_extflags = IFEF_MPSAFE;
 	ifp->if_snd.ifq_maxlen = uimax(ifqmaxlen, NET_TX_RING_SIZE * 2);
 	ifp->if_capabilities =
-		IFCAP_CSUM_IPv4_Rx | IFCAP_CSUM_IPv4_Tx
-		| IFCAP_CSUM_UDPv4_Rx | IFCAP_CSUM_UDPv4_Tx
+		IFCAP_CSUM_UDPv4_Rx | IFCAP_CSUM_UDPv4_Tx
 		| IFCAP_CSUM_TCPv4_Rx | IFCAP_CSUM_TCPv4_Tx
 		| IFCAP_CSUM_UDPv6_Rx
 		| IFCAP_CSUM_TCPv6_Rx;
-#define XN_M_CSUM_SUPPORTED (	\
-		M_CSUM_TCPv4 | M_CSUM_UDPv4 | M_CSUM_IPv4	\
-		| M_CSUM_TCPv6 | M_CSUM_UDPv6			\
-	)
+#define XN_M_CSUM_SUPPORTED 		\
+	(M_CSUM_TCPv4 | M_CSUM_UDPv4 | | M_CSUM_TCPv6 | M_CSUM_UDPv6)
+
 	if (sc->sc_features & FEATURE_IPV6CSUM) {
 		/*
 		 * If backend supports IPv6 csum offloading, we can skip

Index: src/sys/arch/xen/xen/xennet_checksum.c
diff -u src/sys/arch/xen/xen/xennet_checksum.c:1.13 src/sys/arch/xen/xen/xennet_checksum.c:1.14
--- src/sys/arch/xen/xen/xennet_checksum.c:1.13	Sun May  3 16:10:26 2020
+++ src/sys/arch/xen/xen/xennet_checksum.c	Mon May  4 08:22:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xennet_checksum.c,v 1.13 2020/05/03 16:10:26 jdolecek Exp $	*/
+/*	$NetBSD: xennet_checksum.c,v 1.14 2020/05/04 08:22:45 jdolecek Exp $	*/
 
 /*-
  * Copyright (c)2006 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennet_checksum.c,v 1.13 2020/05/03 16:10:26 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennet_checksum.c,v 1.14 2020/05/04 08:22:45 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -147,7 +147,7 @@ xennet_checksum_fill(struct ifnet *ifp, 
 	switch (nxt) {
 	case IPPROTO_UDP:
 		if (iph)
-			m->m_pkthdr.csum_flags = M_CSUM_UDPv4 | M_CSUM_IPv4;
+			m->m_pkthdr.csum_flags = M_CSUM_UDPv4;
 #ifdef INET6
 		else
 			m->m_pkthdr.csum_flags = M_CSUM_UDPv6;
@@ -157,7 +157,7 @@ xennet_checksum_fill(struct ifnet *ifp, 
 		break;
 	case IPPROTO_TCP:
 		if (iph)
-			m->m_pkthdr.csum_flags = M_CSUM_TCPv4 | M_CSUM_IPv4;
+			m->m_pkthdr.csum_flags = M_CSUM_TCPv4;
 #ifdef INET6
 		else
 			m->m_pkthdr.csum_flags = M_CSUM_TCPv6;
@@ -167,10 +167,6 @@ xennet_checksum_fill(struct ifnet *ifp, 
 		break;
 	case IPPROTO_ICMP:
 	case IPPROTO_IGMP:
-		if (iph)
-			m->m_pkthdr.csum_flags = M_CSUM_IPv4;
-		m->m_pkthdr.csum_data = iphlen << 16;
-		break;
 	case IPPROTO_HOPOPTS:
 	case IPPROTO_ICMPV6:
 	case IPPROTO_FRAGMENT:
@@ -196,17 +192,9 @@ xennet_checksum_fill(struct ifnet *ifp, 
 	 */
 	sw_csum = m->m_pkthdr.csum_flags & ~ifp->if_csum_flags_rx;
 
-	/*
-	 * Always initialize the sum to 0!  Some HW assisted
-	 * checksumming requires this. in_undefer_cksum()
-	 * also needs it to be zero.
-	 */
-	if (iph != NULL && (m->m_pkthdr.csum_flags & M_CSUM_IPv4))
-		iph->ip_sum = 0;
-
-	if (sw_csum & (M_CSUM_IPv4|M_CSUM_UDPv4|M_CSUM_TCPv4)) {
+	if (sw_csum & (M_CSUM_UDPv4|M_CSUM_TCPv4)) {
 		in_undefer_cksum(m, ehlen,
-		sw_csum & (M_CSUM_IPv4|M_CSUM_UDPv4|M_CSUM_TCPv4));
+		sw_csum & (M_CSUM_UDPv4|M_CSUM_TCPv4));
 	}
 
 #ifdef INET6

Index: src/sys/arch/xen/xen/xennetback_xenbus.c
diff -u src/sys/arch/xen/xen/xennetback_xenbus.c:1.103 src/sys/arch/xen/xen/xennetback_xenbus.c:1.104
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.103	Sun May  3 17:56:19 2020
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Mon May  4 08:22:45 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.103 2020/05/03 17:56:19 jdolecek Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.104 2020/05/04 08:22:45 

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

2020-05-03 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun May  3 17:56:19 UTC 2020

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

Log Message:
add support for scatter-gather also for frontend Rx path (backend -> frontend)

enable ETHERCAP_JUMBO_MTU and feature-sg


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/arch/xen/xen/xennetback_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/xennetback_xenbus.c
diff -u src/sys/arch/xen/xen/xennetback_xenbus.c:1.102 src/sys/arch/xen/xen/xennetback_xenbus.c:1.103
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.102	Sat May  2 11:28:02 2020
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Sun May  3 17:56:19 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.102 2020/05/02 11:28:02 jdolecek Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.103 2020/05/03 17:56:19 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.102 2020/05/02 11:28:02 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.103 2020/05/03 17:56:19 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -60,8 +60,6 @@ __KERNEL_RCSID(0, "$NetBSD: xennetback_x
 
 #include 
 
-/* #define notyet 1 */
-
 /*
  * Backend network device driver for Xen.
  */
@@ -263,11 +261,7 @@ xennetback_xenbus_create(struct xenbus_d
 	/* create pseudo-interface */
 	aprint_verbose_ifnet(ifp, "Ethernet address %s\n",
 	ether_sprintf(xneti->xni_enaddr));
-	xneti->xni_ec.ec_capabilities |= ETHERCAP_VLAN_MTU
-#ifdef notyet
-		| ETHERCAP_JUMBO_MTU
-#endif
-	;
+	xneti->xni_ec.ec_capabilities |= ETHERCAP_VLAN_MTU | ETHERCAP_JUMBO_MTU;
 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
 	ifp->if_snd.ifq_maxlen =
 	uimax(ifqmaxlen, NET_TX_RING_SIZE * 2);
@@ -327,7 +321,6 @@ xennetback_xenbus_create(struct xenbus_d
 			xbusd->xbusd_path, err);
 			goto abort_xbt;
 		}
-#if notyet
 		err = xenbus_printf(xbt, xbusd->xbusd_path,
 		"feature-sg", "%d", 1);
 		if (err) {
@@ -336,7 +329,6 @@ xennetback_xenbus_create(struct xenbus_d
 			xbusd->xbusd_path, err);
 			goto abort_xbt;
 		}
-#endif
 	} while ((err = xenbus_transaction_end(xbt, 0)) == EAGAIN);
 	if (err) {
 		aprint_error_ifnet(ifp,
@@ -678,21 +670,22 @@ xennetback_tx_check_packet(const netif_t
 }
 
 static int
-xennetback_copy(struct ifnet *ifp, gnttab_copy_t *gop, int copycnt)
+xennetback_copy(struct ifnet *ifp, gnttab_copy_t *gop, int copycnt,
+const char *dir)
 {
 	/*
 	 * Copy the data and ack it. Delaying it until the mbuf is
 	 * freed will stall transmit.
 	 */
 	if (HYPERVISOR_grant_table_op(GNTTABOP_copy, gop, copycnt) != 0) {
-		printf("%s: GNTTABOP_copy Tx failed", ifp->if_xname);
+		printf("%s: GNTTABOP_copy %s failed", ifp->if_xname, dir);
 		return EINVAL;
 	}
 
 	for (int i = 0; i < copycnt; i++) {
 		if (gop->status != GNTST_okay) {
-			printf("%s GNTTABOP_copy[%d] Tx %d\n",
-			ifp->if_xname, i, gop->status);
+			printf("%s GNTTABOP_copy[%d] %s %d\n",
+			ifp->if_xname, i, dir, gop->status);
 			return EINVAL;
 		}
 	}
@@ -758,7 +751,7 @@ xennetback_tx_copy_process(struct ifnet 
 			KASSERT(copycnt <= NB_XMIT_PAGES_BATCH);
 			if (copycnt == NB_XMIT_PAGES_BATCH) {
 if (xennetback_copy(ifp, xneti->xni_gop_copy,
-copycnt) != 0)
+copycnt, "Tx") != 0)
 	goto abort;
 copycnt = 0;
 			}
@@ -791,7 +784,7 @@ xennetback_tx_copy_process(struct ifnet 
 		KASSERT(goff == xst->xs_tx_size);
 	}
 	if (copycnt > 0) {
-		if (xennetback_copy(ifp, xneti->xni_gop_copy, copycnt) != 0)
+		if (xennetback_copy(ifp, xneti->xni_gop_copy, copycnt, "Tx"))
 			goto abort;
 		copycnt = 0;
 	}
@@ -1058,19 +1051,151 @@ xennetback_ifstart(struct ifnet *ifp)
 }
 
 static void
+xennetback_rx_copy_process(struct ifnet *ifp, struct xnetback_instance *xneti,
+	int queued, int copycnt)
+{
+	int notify;
+	struct xnetback_xstate *xst;
+
+	if (xennetback_copy(ifp, xneti->xni_gop_copy, copycnt, "Rx") != 0) {
+		/* message already displayed */
+		goto free_mbufs;
+	}
+
+	/* update pointer */
+	xen_rmb();
+	xneti->xni_rxring.req_cons += queued;
+	xneti->xni_rxring.rsp_prod_pvt += queued;
+	RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(>xni_rxring, notify);
+
+	/* send event */
+	if (notify) {
+		xen_rmb();
+		XENPRINTF(("%s receive event\n",
+		xneti->xni_if.if_xname));
+		hypervisor_notify_via_evtchn(xneti->xni_evtchn);
+	}
+
+free_mbufs:
+	/* now that data was copied we can free the mbufs */
+	for (int j = 0; j < queued; j++) {
+		xst = >xni_xstate[j];
+		if (xst->xs_loaded) {
+			bus_dmamap_unload(xneti->xni_xbusd->xbusd_dmat,
+			xst->xs_dmamap);
+			xst->xs_loaded = false;
+		}
+		if (xst->xs_m != NULL) {
+			m_freem(xst->xs_m);
+			xst->xs_m = NULL;
+		}
+	}
+}
+
+static void
+xennetback_rx_copy_queue(struct xnetback_instance *xneti,
+

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

2020-05-03 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun May  3 17:54:28 UTC 2020

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

Log Message:
reduce buffer size for format_number() so that xbd(4) would show the size
in KB/GB/TB instead of bytes again; the '9' matches what xbd(4) used before,
and also e.g. wd(4)


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/sys/arch/xen/xen/xbd_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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.123 src/sys/arch/xen/xen/xbd_xenbus.c:1.124
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.123	Sat Apr 25 15:26:18 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Sun May  3 17:54:28 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.123 2020/04/25 15:26:18 bouyer Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.124 2020/05/03 17:54:28 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.123 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.124 2020/05/03 17:54:28 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -676,7 +676,8 @@ xbd_backend_changed(void *arg, XenbusSta
 		sc->sc_backend_status = BLKIF_STATE_CONNECTED;
 		hypervisor_unmask_event(sc->sc_evtchn);
 
-		format_bytes(buf, sizeof(buf), sc->sc_sectors * sc->sc_secsize);
+		format_bytes(buf, uimin(9, sizeof(buf)),
+		sc->sc_sectors * sc->sc_secsize);
 		aprint_normal_dev(sc->sc_dksc.sc_dev,
 "%s, %d bytes/sect x %" PRIu64 " sectors\n",
 buf, (int)dg->dg_secsize, sc->sc_xbdsize);



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

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

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

Log Message:
For PVH and HVM, copy hvm_start_info.flags to xen_start_info.flags


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/xen/xen/hypervisor.c

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

Modified files:

Index: src/sys/arch/xen/xen/hypervisor.c
diff -u src/sys/arch/xen/xen/hypervisor.c:1.79 src/sys/arch/xen/xen/hypervisor.c:1.80
--- src/sys/arch/xen/xen/hypervisor.c:1.79	Sat May  2 16:44:36 2020
+++ src/sys/arch/xen/xen/hypervisor.c	Sun May  3 17:24:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.79 2020/05/02 16:44:36 bouyer Exp $ */
+/* $NetBSD: hypervisor.c,v 1.80 2020/05/03 17:24:11 bouyer Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.79 2020/05/02 16:44:36 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.80 2020/05/03 17:24:11 bouyer Exp $");
 
 #include 
 #include 
@@ -265,6 +265,7 @@ init_xen_early(void)
 	(void *)((uintptr_t)hvm_start_info->cmdline_paddr + KERNBASE);
 	strlcpy(xen_start_info.cmd_line, cmd_line,
 	sizeof(xen_start_info.cmd_line));
+	xen_start_info.flags = hvm_start_info->flags;
 }
 
 



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

2020-05-03 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun May  3 16:10:26 UTC 2020

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

Log Message:
return EOPNOTSUPP for unknown IP protocol (same as unknown ethernet type),
so that EINVAL is returned only when the packet is too short


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/xen/xen/xennet_checksum.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/xennet_checksum.c
diff -u src/sys/arch/xen/xen/xennet_checksum.c:1.12 src/sys/arch/xen/xen/xennet_checksum.c:1.13
--- src/sys/arch/xen/xen/xennet_checksum.c:1.12	Fri May  1 19:53:17 2020
+++ src/sys/arch/xen/xen/xennet_checksum.c	Sun May  3 16:10:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xennet_checksum.c,v 1.12 2020/05/01 19:53:17 jdolecek Exp $	*/
+/*	$NetBSD: xennet_checksum.c,v 1.13 2020/05/03 16:10:26 jdolecek Exp $	*/
 
 /*-
  * Copyright (c)2006 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennet_checksum.c,v 1.12 2020/05/01 19:53:17 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennet_checksum.c,v 1.13 2020/05/03 16:10:26 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -186,7 +186,7 @@ xennet_checksum_fill(struct ifnet *ifp, 
 			printf("%s: unknown proto %d passed no checksum\n",
 			ifp->if_xname, nxt);
 #endif /* XENNET_DEBUG */
-		error = EINVAL;
+		error = EOPNOTSUPP;
 		goto out;
 	}
 	}



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

2020-05-02 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sat May  2 16:46:06 UTC 2020

Modified Files:
src/sys/arch/xen/conf: files.xen

Log Message:
This is called pvh_consinit not hvm_consinit


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

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

Modified files:

Index: src/sys/arch/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.183 src/sys/arch/xen/conf/files.xen:1.184
--- src/sys/arch/xen/conf/files.xen:1.183	Sat May  2 16:44:36 2020
+++ src/sys/arch/xen/conf/files.xen	Sat May  2 16:46:06 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.183 2020/05/02 16:44:36 bouyer Exp $
+#	$NetBSD: files.xen,v 1.184 2020/05/02 16:46:06 bouyer Exp $
 
 defflag	opt_xen.h			XEN XENPVH XENPVHVM PAE
 
@@ -11,7 +11,7 @@ file	arch/xen/x86/xen_mainbus.c		xen
 file	arch/xen/xen/xen_clock.c		xen
 file	arch/xen/x86/xen_bus_dma.c		xen
 
-file	arch/xen/x86/hvm_consinit.c		xenpvhvm
+file	arch/xen/x86/pvh_consinit.c		xenpvhvm
 
 define hypervisorbus {}
 define xendevbus {}



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

2020-05-02 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat May  2 11:28:02 UTC 2020

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

Log Message:
fix gref offset when setting up copy of multi-fragment packet so data
for second and further fragments gets copied into correct place


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/arch/xen/xen/xennetback_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/xennetback_xenbus.c
diff -u src/sys/arch/xen/xen/xennetback_xenbus.c:1.101 src/sys/arch/xen/xen/xennetback_xenbus.c:1.102
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.101	Fri May  1 19:59:47 2020
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Sat May  2 11:28:02 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.101 2020/05/01 19:59:47 jdolecek Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.102 2020/05/02 11:28:02 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.101 2020/05/01 19:59:47 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.102 2020/05/02 11:28:02 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -749,6 +749,7 @@ xennetback_tx_copy_process(struct ifnet 
 		}
 
 		gsize = xst->xs_tx_size;
+		goff = 0;
 		for (; seg < dm->dm_nsegs && gsize > 0; seg++) {
 			bus_dma_segment_t *ds = >dm_segs[seg];
 			ma = ds->ds_addr;
@@ -787,6 +788,7 @@ xennetback_tx_copy_process(struct ifnet 
 			segoff = 0;
 		}
 		KASSERT(gsize == 0);
+		KASSERT(goff == xst->xs_tx_size);
 	}
 	if (copycnt > 0) {
 		if (xennetback_copy(ifp, xneti->xni_gop_copy, copycnt) != 0)
@@ -931,6 +933,7 @@ mbuf_fail:
  * Flush queue if too full to fit this
  * new packet whole.
  */
+KASSERT(m0 == NULL);
 xennetback_tx_copy_process(ifp, xneti, queued);
 queued = 0;
 			}



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

2020-05-01 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri May  1 19:59:47 UTC 2020

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

Log Message:
destroy dma maps in xennetback_xenbus_destroy() to avoid memory leak
when xvif(4) is destroyed


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/arch/xen/xen/xennetback_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/xennetback_xenbus.c
diff -u src/sys/arch/xen/xen/xennetback_xenbus.c:1.100 src/sys/arch/xen/xen/xennetback_xenbus.c:1.101
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.100	Fri May  1 19:53:17 2020
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Fri May  1 19:59:47 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.100 2020/05/01 19:53:17 jdolecek Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.101 2020/05/01 19:59:47 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.100 2020/05/01 19:53:17 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.101 2020/05/01 19:59:47 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -386,6 +386,15 @@ xennetback_xenbus_destroy(void *arg)
 	evcnt_detach(>xni_cnt_rx_cksum_blank);
 	evcnt_detach(>xni_cnt_rx_cksum_undefer);
 
+	/* Destroy DMA maps */
+	for (int i = 0; i < __arraycount(xneti->xni_xstate); i++) {
+		if (xneti->xni_xstate[i].xs_dmamap != NULL) {
+			bus_dmamap_destroy(xneti->xni_xbusd->xbusd_dmat,
+			xneti->xni_xstate[i].xs_dmamap);
+			xneti->xni_xstate[i].xs_dmamap = NULL;
+		}
+	}
+
 	if (xneti->xni_txring.sring) {
 		op.host_addr = xneti->xni_tx_ring_va;
 		op.handle = xneti->xni_tx_ring_handle;



CVS commit: src/sys/arch/xen

2020-05-01 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri May  1 19:53:17 UTC 2020

Modified Files:
src/sys/arch/xen/include: xennet_checksum.h
src/sys/arch/xen/xen: if_xennet_xenbus.c xennet_checksum.c
xennetback_xenbus.c

Log Message:
make the csum blank/undefer counters per interface


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/xen/include/xennet_checksum.h
cvs rdiff -u -r1.120 -r1.121 src/sys/arch/xen/xen/if_xennet_xenbus.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/xen/xen/xennet_checksum.c
cvs rdiff -u -r1.99 -r1.100 src/sys/arch/xen/xen/xennetback_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/include/xennet_checksum.h
diff -u src/sys/arch/xen/include/xennet_checksum.h:1.4 src/sys/arch/xen/include/xennet_checksum.h:1.5
--- src/sys/arch/xen/include/xennet_checksum.h:1.4	Sun Mar 22 11:20:59 2020
+++ src/sys/arch/xen/include/xennet_checksum.h	Fri May  1 19:53:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xennet_checksum.h,v 1.4 2020/03/22 11:20:59 jdolecek Exp $	*/
+/*	$NetBSD: xennet_checksum.h,v 1.5 2020/05/01 19:53:17 jdolecek Exp $	*/
 
 /*-
  * Copyright (c)2006 YAMAMOTO Takashi,
@@ -32,6 +32,7 @@
 struct ifnet;
 struct mbuf;
 
-int xennet_checksum_fill(struct ifnet *, struct mbuf *);
+int xennet_checksum_fill(struct ifnet *, struct mbuf *,
+	struct evcnt *, struct evcnt *);
 
 #endif /* !_XEN_XENNET_CHECKSUM_H_ */

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.120 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.121
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.120	Thu Apr 30 11:19:39 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Fri May  1 19:53:17 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.120 2020/04/30 11:19:39 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.121 2020/05/01 19:53:17 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.120 2020/04/30 11:19:39 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.121 2020/05/01 19:53:17 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -204,6 +204,8 @@ struct xennet_xenbus_softc {
 	struct evcnt sc_cnt_tx_drop;
 	struct evcnt sc_cnt_tx_frag;
 	struct evcnt sc_cnt_rx_frag;
+	struct evcnt sc_cnt_rx_cksum_blank;
+	struct evcnt sc_cnt_rx_cksum_undefer;
 };
 
 static pool_cache_t if_xennetrxbuf_cache;
@@ -433,6 +435,10 @@ xennet_xenbus_attach(device_t parent, de
 	NULL, device_xname(sc->sc_dev), "Tx queue full");
 	evcnt_attach_dynamic(>sc_cnt_rx_frag, EVCNT_TYPE_MISC,
 	NULL, device_xname(sc->sc_dev), "Rx multi-segment packet");
+	evcnt_attach_dynamic(>sc_cnt_rx_cksum_blank, EVCNT_TYPE_MISC,
+	NULL, device_xname(sc->sc_dev), "Rx csum blank");
+	evcnt_attach_dynamic(>sc_cnt_rx_cksum_undefer, EVCNT_TYPE_MISC,
+	NULL, device_xname(sc->sc_dev), "Rx csum undeferred");
 
 	if (!pmf_device_register(self, xennet_xenbus_suspend,
 	xennet_xenbus_resume))
@@ -493,6 +499,8 @@ xennet_xenbus_detach(device_t self, int 
 	evcnt_detach(>sc_cnt_tx_drop);
 	evcnt_detach(>sc_cnt_tx_queue_full);
 	evcnt_detach(>sc_cnt_rx_frag);
+	evcnt_detach(>sc_cnt_rx_cksum_blank);
+	evcnt_detach(>sc_cnt_rx_cksum_undefer);
 
 	/* Unhook the entropy source. */
 	rnd_detach_source(>sc_rnd_source);
@@ -1034,9 +1042,10 @@ again:
 			rxflags = m0_rxflags;
 		}
 
-		if (rxflags & NETRXF_csum_blank)
-			xennet_checksum_fill(ifp, m);
-		else if (rxflags & NETRXF_data_validated)
+		if (rxflags & NETRXF_csum_blank) {
+			xennet_checksum_fill(ifp, m, >sc_cnt_rx_cksum_blank,
+			>sc_cnt_rx_cksum_undefer);
+		} else if (rxflags & NETRXF_data_validated)
 			m->m_pkthdr.csum_flags = XN_M_CSUM_SUPPORTED;
 
 		/* We'are done with req */

Index: src/sys/arch/xen/xen/xennet_checksum.c
diff -u src/sys/arch/xen/xen/xennet_checksum.c:1.11 src/sys/arch/xen/xen/xennet_checksum.c:1.12
--- src/sys/arch/xen/xen/xennet_checksum.c:1.11	Sun Apr 26 12:38:21 2020
+++ src/sys/arch/xen/xen/xennet_checksum.c	Fri May  1 19:53:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xennet_checksum.c,v 1.11 2020/04/26 12:38:21 jdolecek Exp $	*/
+/*	$NetBSD: xennet_checksum.c,v 1.12 2020/05/01 19:53:17 jdolecek Exp $	*/
 
 /*-
  * Copyright (c)2006 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennet_checksum.c,v 1.11 2020/04/26 12:38:21 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennet_checksum.c,v 1.12 2020/05/01 19:53:17 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -52,14 +52,6 @@ __KERNEL_RCSID(0, "$NetBSD: xennet_check
 
 #include 
 
-static struct evcnt xn_cksum_defer = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
-NULL, "xennet", "csum blank");
-static struct evcnt xn_cksum_undefer = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
-NULL, "xennet", "csum undeferred");
-

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

2020-04-30 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Apr 30 11:23:44 UTC 2020

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

Log Message:
add support for scatter-gather when accepting packets on frontend Tx path
(frontend -> backend)

don't enable ETHERCAP_JUMBO_MTU nor feature-sg yet, need to implement
support also for the frontend Rx side


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/arch/xen/xen/xennetback_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/xennetback_xenbus.c
diff -u src/sys/arch/xen/xen/xennetback_xenbus.c:1.98 src/sys/arch/xen/xen/xennetback_xenbus.c:1.99
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.98	Sun Apr 26 13:09:52 2020
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Thu Apr 30 11:23:44 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.98 2020/04/26 13:09:52 jdolecek Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.99 2020/04/30 11:23:44 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.98 2020/04/26 13:09:52 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.99 2020/04/30 11:23:44 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -78,6 +78,7 @@ __KERNEL_RCSID(0, "$NetBSD: xennetback_x
  * transmit at once).
  */
 #define NB_XMIT_PAGES_BATCH 64
+CTASSERT(NB_XMIT_PAGES_BATCH >= XEN_NETIF_NR_SLOTS_MIN);
 
 /* ratecheck(9) for pool allocation failures */
 static const struct timeval xni_pool_errintvl = { 30, 0 };  /* 30s, each */
@@ -91,9 +92,10 @@ typedef enum {
 
 struct xnetback_xstate {
 	bus_dmamap_t xs_dmamap;
+	bool xs_loaded;
 	struct mbuf *xs_m;
-	int xs_id;
-	int xs_flags;
+	struct netif_tx_request xs_tx;
+	uint16_t xs_tx_size;		/* Size of data in this Tx fragment */
 };
 
 /* we keep the xnetback instances in a linked list */
@@ -235,8 +237,9 @@ xennetback_xenbus_create(struct xenbus_d
 
 	/* Initialize DMA map, used only for loading PA */
 	for (i = 0; i < __arraycount(xneti->xni_xstate); i++) {
-		if (bus_dmamap_create(xneti->xni_xbusd->xbusd_dmat, PAGE_SIZE,
-		1, PAGE_SIZE, PAGE_SIZE, BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW,
+		if (bus_dmamap_create(xneti->xni_xbusd->xbusd_dmat,
+		ETHER_MAX_LEN_JUMBO, XEN_NETIF_NR_SLOTS_MIN,
+		PAGE_SIZE, PAGE_SIZE, BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW,
 		>xni_xstate[i].xs_dmamap)
 		!= 0) {
 			aprint_error_ifnet(ifp,
@@ -249,7 +252,11 @@ xennetback_xenbus_create(struct xenbus_d
 	/* create pseudo-interface */
 	aprint_verbose_ifnet(ifp, "Ethernet address %s\n",
 	ether_sprintf(xneti->xni_enaddr));
-	xneti->xni_ec.ec_capabilities |= ETHERCAP_VLAN_MTU;
+	xneti->xni_ec.ec_capabilities |= ETHERCAP_VLAN_MTU
+#ifdef notyet
+		| ETHERCAP_JUMBO_MTU
+#endif
+	;
 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
 	ifp->if_snd.ifq_maxlen =
 	uimax(ifqmaxlen, NET_TX_RING_SIZE * 2);
@@ -309,6 +316,16 @@ xennetback_xenbus_create(struct xenbus_d
 			xbusd->xbusd_path, err);
 			goto abort_xbt;
 		}
+#if notyet
+		err = xenbus_printf(xbt, xbusd->xbusd_path,
+		"feature-sg", "%d", 1);
+		if (err) {
+			aprint_error_ifnet(ifp,
+			"failed to write %s/feature-sg: %d\n",
+			xbusd->xbusd_path, err);
+			goto abort_xbt;
+		}
+#endif
 	} while ((err = xenbus_transaction_end(xbt, 0)) == EAGAIN);
 	if (err) {
 		aprint_error_ifnet(ifp,
@@ -624,80 +641,182 @@ xennetback_tx_response(struct xnetback_i
 	}
 }
 
-static inline const char *
-xennetback_tx_check_packet(const netif_tx_request_t *txreq, int vlan)
+static const char *
+xennetback_tx_check_packet(const netif_tx_request_t *txreq)
 {
-	if (__predict_false(txreq->size < ETHER_HDR_LEN))
-		return "too small";
-
-	if (__predict_false(txreq->offset + txreq->size > PAGE_SIZE))
-		return "crossing a page boundary";
+	if (__predict_false((txreq->flags & NETTXF_more_data) == 0 &&
+	txreq->offset + txreq->size > PAGE_SIZE))
+		return "crossing page boundary";
 
-	int maxlen = ETHER_MAX_LEN - ETHER_CRC_LEN;
-	if (vlan)
-		maxlen += ETHER_VLAN_ENCAP_LEN;
-	if (__predict_false(txreq->size > maxlen))
-		return "too big";
-
-	/* Somewhat duplicit, MCLBYTES is > ETHER_MAX_LEN */
-	if (__predict_false(txreq->size > MCLBYTES))
-		return "bigger than MCLBYTES";
+	if (__predict_false(txreq->size > ETHER_MAX_LEN_JUMBO))
+		return "bigger then jumbo";
 
 	return NULL;
 }
 
-static void
-xennetback_tx_copy_process(struct ifnet *ifp, struct xnetback_instance *xneti,
-	int queued)
+static int
+xennetback_copy(struct ifnet *ifp, gnttab_copy_t *gop, int copycnt)
 {
-	int i = 0;
-	gnttab_copy_t *gop;
-	struct xnetback_xstate *xst;
-
 	/*
 	 * Copy the data and ack it. Delaying it until the mbuf is
 	 * freed will stall transmit.
 	 */
-	if (HYPERVISOR_grant_table_op(GNTTABOP_copy, xneti->xni_gop_copy,
-	queued) != 0) {
+	if 

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

2020-04-30 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Apr 30 11:19:39 UTC 2020

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

Log Message:
NETTXF_csum_blank and NETTXF_data_validated should be set only for first
fragment of the packet


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sys/arch/xen/xen/if_xennet_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.119 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.120
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.119	Sun Apr 26 12:58:28 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Thu Apr 30 11:19:39 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.119 2020/04/26 12:58:28 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.120 2020/04/30 11:19:39 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.119 2020/04/26 12:58:28 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.120 2020/04/30 11:19:39 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -1105,13 +1105,15 @@ xennet_submit_tx_request(struct xennet_x
 		txreq->id = req->txreq_id;
 		txreq->gref = req->txreq_gntref;
 		txreq->offset = ds->ds_addr & PAGE_MASK;
-		/* For Tx, first fragment has size always set to total size */
+		/* For Tx, first fragment size is always set to total size */
 		txreq->size = (i == 0) ? m->m_pkthdr.len : ds->ds_len;
 		txreq->flags = 0;
-		if ((m->m_pkthdr.csum_flags & XN_M_CSUM_SUPPORTED) != 0) {
-			txreq->flags |= NETTXF_csum_blank;
-		} else {
-			txreq->flags |= NETTXF_data_validated;
+		if (i == 0) {
+			if (m->m_pkthdr.csum_flags & XN_M_CSUM_SUPPORTED) {
+txreq->flags |= NETTXF_csum_blank;
+			} else {
+txreq->flags |= NETTXF_data_validated;
+			}
 		}
 		if (multiseg && i < lastseg)
 			txreq->flags |= NETTXF_more_data;



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

2020-04-28 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Apr 28 13:27:29 UTC 2020

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

Log Message:
Remove debug printfs


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/arch/xen/xen/hypervisor.c

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

Modified files:

Index: src/sys/arch/xen/xen/hypervisor.c
diff -u src/sys/arch/xen/xen/hypervisor.c:1.76 src/sys/arch/xen/xen/hypervisor.c:1.77
--- src/sys/arch/xen/xen/hypervisor.c:1.76	Sat Apr 25 15:26:18 2020
+++ src/sys/arch/xen/xen/hypervisor.c	Tue Apr 28 13:27:29 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.76 2020/04/25 15:26:18 bouyer Exp $ */
+/* $NetBSD: hypervisor.c,v 1.77 2020/04/28 13:27:29 bouyer Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.76 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.77 2020/04/28 13:27:29 bouyer Exp $");
 
 #include 
 #include 
@@ -219,15 +219,12 @@ xen_check_hypervisordev(void)
 			case FSTATE_NOTFOUND:
 			case FSTATE_FOUND:
 			case FSTATE_STAR:
-printf("xen_check_hypervisordev: enabled\n");
 return true;
 			default:
-printf("xen_check_hypervisordev: disabled\n");
 return false;
 			}
 		}
 	}
-	printf("xen_check_hypervisordev: notfound\n");
 	return 0;
 }
 int



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

2020-04-28 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Apr 28 13:21:01 UTC 2020

Modified Files:
src/sys/arch/xen/xenbus: xenbus_probe.c

Log Message:
Skip block device  with device-type "cdrom", as their emulation can't be
disabled; and the backend driver doesn't handle them either.
Fix hang when booting with 'ioemu:hdc:cdrom' type disks.
While there convert some printf to aprint_error()


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/xen/xenbus/xenbus_probe.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/xenbus/xenbus_probe.c
diff -u src/sys/arch/xen/xenbus/xenbus_probe.c:1.50 src/sys/arch/xen/xenbus/xenbus_probe.c:1.51
--- src/sys/arch/xen/xenbus/xenbus_probe.c:1.50	Sat Apr 25 15:26:18 2020
+++ src/sys/arch/xen/xenbus/xenbus_probe.c	Tue Apr 28 13:21:01 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_probe.c,v 1.50 2020/04/25 15:26:18 bouyer Exp $ */
+/* $NetBSD: xenbus_probe.c,v 1.51 2020/04/28 13:21:01 bouyer Exp $ */
 /**
  * Talks to Xen Store to figure out what devices we have.
  *
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.50 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.51 2020/04/28 13:21:01 bouyer Exp $");
 
 #if 0
 #define DPRINTK(fmt, args...) \
@@ -399,7 +399,7 @@ xenbus_probe_device_type(const char *pat
 		err = xenbus_read_ul(NULL, xbusd->xbusd_path, "state",
 		, 10);
 		if (err) {
-			printf("xenbus: can't get state "
+			aprint_error_dev(xenbus_dev, "can't get state "
 			"for %s (%d)\n", xbusd->xbusd_path, err);
 			kmem_free(xbusd, xbusd->xbusd_sz);
 			err = 0;
@@ -418,8 +418,9 @@ xenbus_probe_device_type(const char *pat
 			xbusd->xbusd_type = XENBUS_BACKEND_DEVICE;
 			err = read_frontend_details(xbusd);
 			if (err != 0) {
-printf("xenbus: can't get frontend details "
-"for %s (%d)\n", xbusd->xbusd_path, err);
+aprint_error_dev(xenbus_dev,
+"can't get frontend details for %s (%d)\n",
+xbusd->xbusd_path, err);
 break;
 			}
 			if (create(xbusd)) {
@@ -432,16 +433,36 @@ xenbus_probe_device_type(const char *pat
 			xa.xa_type = type;
 			xa.xa_id = strtoul(dir[i], , 0);
 			if (dir[i][0] == '\0' || *ep != '\0') {
-printf("xenbus device type %s: id %s is not a"
-" number\n", type, dir[i]);
+aprint_error_dev(xenbus_dev,
+"device type %s: id %s is not a number\n",
+type, dir[i]);
 err = EFTYPE;
 kmem_free(xbusd, xbusd->xbusd_sz);
 break;
 			}
+			if (strcmp(xa.xa_type, "vbd") == 0) {
+char dtype[10];
+if (xenbus_read(NULL, xbusd->xbusd_path,
+"device-type", dtype, sizeof(dtype)) !=0) {
+	aprint_error_dev(xenbus_dev,
+	"%s: can't read device-type\n",
+	xbusd->xbusd_path);
+	kmem_free(xbusd, xbusd->xbusd_sz);
+	break;
+}
+if (strcmp(dtype, "cdrom") == 0) {
+	aprint_verbose_dev(xenbus_dev,
+	"ignoring %s type cdrom\n",
+	xbusd->xbusd_path);
+	kmem_free(xbusd, xbusd->xbusd_sz);
+	continue;
+}
+			}
 			err = read_backend_details(xbusd);
 			if (err != 0) {
-printf("xenbus: can't get backend details "
-"for %s (%d)\n", xbusd->xbusd_path, err);
+aprint_error_dev(xenbus_dev,
+"can't get backend details for %s (%d)\n",
+xbusd->xbusd_path, err);
 kmem_free(xbusd, xbusd->xbusd_sz);
 break;
 			}



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

2020-04-26 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sun Apr 26 20:41:30 UTC 2020

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

Log Message:
Guard xen_wallclock with XENPV.

Thanks to riastradh@


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/xen/xen/xen_clock.c

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

Modified files:

Index: src/sys/arch/xen/xen/xen_clock.c
diff -u src/sys/arch/xen/xen/xen_clock.c:1.2 src/sys/arch/xen/xen/xen_clock.c:1.3
--- src/sys/arch/xen/xen/xen_clock.c:1.2	Sat Apr 25 15:26:18 2020
+++ src/sys/arch/xen/xen/xen_clock.c	Sun Apr 26 20:41:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_clock.c,v 1.2 2020/04/25 15:26:18 bouyer Exp $	*/
+/*	$NetBSD: xen_clock.c,v 1.3 2020/04/26 20:41:30 roy Exp $	*/
 
 /*-
  * Copyright (c) 2017, 2018 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.2 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.3 2020/04/26 20:41:30 roy Exp $");
 
 #include 
 #include 
@@ -382,6 +382,7 @@ xen_vcputime_raw_systime_ns(void)
 	return raw_systime_ns;
 }
 
+#ifdef XENPV
 /*
  * struct xen_wallclock_ticket
  *
@@ -436,6 +437,7 @@ xen_wallclock_exit(struct xen_wallclock_
 
 	return tp->version == HYPERVISOR_shared_info->wc_version;
 }
+#endif
 
 /*
  * xen_global_systime_ns()



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

2020-04-26 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Apr 26 13:09:53 UTC 2020

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

Log Message:
bump send queue to 2*NET_TX_RING_SIZE to make it less likely packets
are dropped on load

m_defrag() short packets before calling bus_dmamap_load_mbuf() -
if it's fragmented load_mbuf would fail anyway, and even with
eventual feature-sg support it's way faster to pass the short packet
in single fragment


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/arch/xen/xen/xennetback_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/xennetback_xenbus.c
diff -u src/sys/arch/xen/xen/xennetback_xenbus.c:1.97 src/sys/arch/xen/xen/xennetback_xenbus.c:1.98
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.97	Sat Apr 25 11:33:28 2020
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Sun Apr 26 13:09:52 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.97 2020/04/25 11:33:28 jdolecek Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.98 2020/04/26 13:09:52 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.97 2020/04/25 11:33:28 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.98 2020/04/26 13:09:52 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -269,6 +269,7 @@ xennetback_xenbus_create(struct xenbus_d
 	ifp->if_init = xennetback_ifinit;
 	ifp->if_stop = xennetback_ifstop;
 	ifp->if_timer = 0;
+	IFQ_SET_MAXLEN(>if_snd, uimax(2 * NET_TX_RING_SIZE, IFQ_MAXLEN));
 	IFQ_SET_READY(>if_snd);
 	if_attach(ifp);
 	if_deferred_start_init(ifp, NULL);
@@ -912,6 +913,15 @@ xennetback_ifsoftstart_copy(struct xnetb
 
 			xst = >xni_xstate[i];
 
+			/*
+			 * For short packets it's always way faster passing
+			 * single defragmented packet, even with feature-sg.
+			 * Try to defragment first if the result is likely
+			 * to fit into a single mbuf.
+			 */
+			if (m->m_pkthdr.len < MCLBYTES && m->m_next)
+(void)m_defrag(m, M_DONTWAIT);
+
 			if (bus_dmamap_load_mbuf(
 			xneti->xni_xbusd->xbusd_dmat,
 			xst->xs_dmamap, m, BUS_DMA_NOWAIT) != 0) {



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

2020-04-26 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Apr 26 12:58:28 UTC 2020

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

Log Message:
support feature-sg

practical offshot of this xennet(4) now supports jumbo frames, it is
also necessary for eventual TSO support

always defrag short Tx packets before passing to backend - even
with feature-sg it's way faster to process the packet if it's
passed as single fragment


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/sys/arch/xen/xen/if_xennet_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.118 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.119
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.118	Sat Apr 25 15:26:18 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Sun Apr 26 12:58:28 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.118 2020/04/25 15:26:18 bouyer Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.119 2020/04/26 12:58:28 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.118 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.119 2020/04/26 12:58:28 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -186,19 +186,28 @@ struct xennet_xenbus_softc {
 	struct xennet_rxreq sc_rxreqs[NET_RX_RING_SIZE];
 	SLIST_HEAD(,xennet_txreq) sc_txreq_head; /* list of free TX requests */
 	SLIST_HEAD(,xennet_rxreq) sc_rxreq_head; /* list of free RX requests */
-	int sc_free_rxreql; /* number of free receive request struct */
+	int sc_free_txreql; /* number of free transmit request structs */
+	int sc_free_rxreql; /* number of free receive request structs */
 
 	int sc_backend_status; /* our status with backend */
 #define BEST_CLOSED		0
 #define BEST_DISCONNECTED	1
 #define BEST_CONNECTED		2
 #define BEST_SUSPENDED		3
-	bool sc_ipv6_csum;	/* whether backend support IPv6 csum offload */
+	int sc_features;
+#define FEATURE_IPV6CSUM	0x01	/* IPv6 checksum offload */
+#define FEATURE_SG		0x02	/* scatter-gatter */
+#define FEATURE_BITS		"\20\1IPV6-CSUM\2SG"
 	krndsource_t sc_rnd_source;
+	struct evcnt sc_cnt_tx_defrag;
+	struct evcnt sc_cnt_tx_queue_full;
+	struct evcnt sc_cnt_tx_drop;
+	struct evcnt sc_cnt_tx_frag;
+	struct evcnt sc_cnt_rx_frag;
 };
 
 static pool_cache_t if_xennetrxbuf_cache;
-static int if_xennetrxbuf_cache_inited=0;
+static int if_xennetrxbuf_cache_inited = 0;
 
 static int  xennet_xenbus_match(device_t, cfdata_t, void *);
 static void xennet_xenbus_attach(device_t, device_t, void *);
@@ -256,6 +265,9 @@ xennet_xenbus_attach(device_t parent, de
 	unsigned long uval;
 	extern int ifqmaxlen; /* XXX */
 	char mac[32];
+	char buf[64];
+	bus_size_t maxsz;
+	int nsegs;
 
 	aprint_normal(": Xen Virtual Network Interface\n");
 	sc->sc_dev = self;
@@ -263,6 +275,18 @@ xennet_xenbus_attach(device_t parent, de
 	sc->sc_xbusd = xa->xa_xbusd;
 	sc->sc_xbusd->xbusd_otherend_changed = xennet_backend_changed;
 
+	/* read feature support flags */
+	err = xenbus_read_ul(NULL, sc->sc_xbusd->xbusd_otherend,
+	"feature-ipv6-csum-offload", , 10);
+	if (!err && uval == 1)
+		sc->sc_features |= FEATURE_IPV6CSUM;
+	err = xenbus_read_ul(NULL, sc->sc_xbusd->xbusd_otherend,
+	"feature-sg", , 10);
+	if (!err && uval == 1)
+		sc->sc_features |= FEATURE_SG;
+	snprintb(buf, sizeof(buf), FEATURE_BITS, sc->sc_features);
+	aprint_normal_dev(sc->sc_dev, "backend features %s\n", buf);
+
 	/* xenbus ensure 2 devices can't be probed at the same time */
 	if (if_xennetrxbuf_cache_inited == 0) {
 		if_xennetrxbuf_cache = pool_cache_init(PAGE_SIZE, 0, 0, 0,
@@ -271,13 +295,26 @@ xennet_xenbus_attach(device_t parent, de
 	}
 
 	/* initialize free RX and RX request lists */
+	if (sc->sc_features & FEATURE_SG) {
+		maxsz = ETHER_MAX_LEN_JUMBO;
+		/*
+		 * Linux netback drops the packet if the request has more
+		 * segments than XEN_NETIF_NR_SLOTS_MIN (== 18). With 2KB
+		 * MCLBYTES this means maximum packet size 36KB, in reality
+		 * less due to mbuf chain fragmentation.
+		 */
+		nsegs = XEN_NETIF_NR_SLOTS_MIN;
+	} else {
+		maxsz = PAGE_SIZE;
+		nsegs = 1;
+	}
 	mutex_init(>sc_tx_lock, MUTEX_DEFAULT, IPL_NET);
 	SLIST_INIT(>sc_txreq_head);
 	for (i = 0; i < NET_TX_RING_SIZE; i++) {
 		struct xennet_txreq *txreq = >sc_txreqs[i];
 	
 		txreq->txreq_id = i;
-		if (bus_dmamap_create(sc->sc_xbusd->xbusd_dmat, PAGE_SIZE, 1,
+		if (bus_dmamap_create(sc->sc_xbusd->xbusd_dmat, maxsz, nsegs,
 		PAGE_SIZE, PAGE_SIZE, BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW,
 		>txreq_dmamap) != 0)
 			break;
@@ -285,13 +322,14 @@ xennet_xenbus_attach(device_t parent, de
 		SLIST_INSERT_HEAD(>sc_txreq_head, >sc_txreqs[i],
 		txreq_next);
 	}
+	sc->sc_free_txreql = i;
 
 	mutex_init(>sc_rx_lock, 

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

2020-04-26 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Apr 26 12:38:22 UTC 2020

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

Log Message:
if part of checksum was undeferred via sw and part not, count it as both


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/xen/xen/xennet_checksum.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/xennet_checksum.c
diff -u src/sys/arch/xen/xen/xennet_checksum.c:1.10 src/sys/arch/xen/xen/xennet_checksum.c:1.11
--- src/sys/arch/xen/xen/xennet_checksum.c:1.10	Sun Mar 22 11:20:59 2020
+++ src/sys/arch/xen/xen/xennet_checksum.c	Sun Apr 26 12:38:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xennet_checksum.c,v 1.10 2020/03/22 11:20:59 jdolecek Exp $	*/
+/*	$NetBSD: xennet_checksum.c,v 1.11 2020/04/26 12:38:21 jdolecek Exp $	*/
 
 /*-
  * Copyright (c)2006 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennet_checksum.c,v 1.10 2020/03/22 11:20:59 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennet_checksum.c,v 1.11 2020/04/26 12:38:21 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -224,6 +224,8 @@ xennet_checksum_fill(struct ifnet *ifp, 
 #endif
 
 	if (m->m_pkthdr.csum_flags != 0) {
+		if (sw_csum)
+			xn_cksum_undefer.ev_count++;
 		xn_cksum_defer.ev_count++;
 #ifdef M_CSUM_BLANK
 		m->m_pkthdr.csum_flags |= M_CSUM_BLANK;



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

2020-04-25 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Apr 25 20:05:25 UTC 2020

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

Log Message:
parse indirect_op using appropriate 32/64-bit access types, this fixes
the BLKIF_OP_INDIRECT handling for 32-bit DomU running against 64-bit Dom0,
problem reported and fix tested by Manuel

make sure to use the provided indirect_op when reporting back errors


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 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.91 src/sys/arch/xen/xen/xbdback_xenbus.c:1.92
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.91	Sat Apr 25 15:26:18 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Sat Apr 25 20:05:25 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.91 2020/04/25 15:26:18 bouyer Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.92 2020/04/25 20:05:25 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.91 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.92 2020/04/25 20:05:25 jdolecek Exp $");
 
 #include 
 #include 
@@ -966,9 +966,13 @@ xbdback_co_main_loop(struct xbdback_inst
 	blkif_request_t *req, *reqn;
 	blkif_x86_32_request_t *req32;
 	blkif_x86_64_request_t *req64;
-	blkif_request_indirect_t *rin;
+	blkif_request_indirect_t *rinn;
+	blkif_x86_32_request_indirect_t *rin32;
+	blkif_x86_64_request_indirect_t *rin64;
 
 	if (xbdi->xbdi_ring.ring_n.req_cons != xbdi->xbdi_req_prod) {
+		uint8_t real_op = 0xff;
+
 		req = >xbdi_xen_req;
 		memset(req, 0, sizeof(*req));
 
@@ -976,19 +980,31 @@ xbdback_co_main_loop(struct xbdback_inst
 		case XBDIP_NATIVE:
 			reqn = RING_GET_REQUEST(>xbdi_ring.ring_n,
 			xbdi->xbdi_ring.ring_n.req_cons);
-			req->operation = reqn->operation;
+			real_op = req->operation = reqn->operation;
+			if (real_op == BLKIF_OP_INDIRECT) {
+rinn = (blkif_request_indirect_t *)reqn;
+real_op = rinn->indirect_op;
+			}
 			req->id = reqn->id;
 			break;
 		case XBDIP_32:
 			req32 = RING_GET_REQUEST(>xbdi_ring.ring_32,
 			xbdi->xbdi_ring.ring_n.req_cons);
-			req->operation = req32->operation;
+			real_op = req->operation = req32->operation;
+			if (real_op == BLKIF_OP_INDIRECT) {
+rin32 = (blkif_x86_32_request_indirect_t*)req32;
+real_op = rin32->indirect_op;
+			}
 			req->id = req32->id;
 			break;
 		case XBDIP_64:
 			req64 = RING_GET_REQUEST(>xbdi_ring.ring_64,
 			xbdi->xbdi_ring.ring_n.req_cons);
-			req->operation = req64->operation;
+			real_op = req->operation = req64->operation;
+			if (real_op == BLKIF_OP_INDIRECT) {
+rin64 = (blkif_x86_64_request_indirect_t*)req64;
+real_op = rin64->indirect_op;
+			}
 			req->id = req64->id;
 			break;
 		}
@@ -1002,16 +1018,13 @@ xbdback_co_main_loop(struct xbdback_inst
 		switch (req->operation) {
 		case BLKIF_OP_INDIRECT:
 			/* just check indirect_op, rest is handled later */
-			rin = (blkif_request_indirect_t *)
-			RING_GET_REQUEST(>xbdi_ring.ring_n,
-xbdi->xbdi_ring.ring_n.req_cons);
-			if (rin->indirect_op != BLKIF_OP_READ &&
-			rin->indirect_op != BLKIF_OP_WRITE) {
+			if (real_op != BLKIF_OP_READ &&
+			real_op != BLKIF_OP_WRITE) {
 if (ratecheck(>xbdi_lasterr_time,
 _err_intvl)) {
 	printf("%s: unknown ind operation %d\n",
 	xbdi->xbdi_name,
-	rin->indirect_op);
+	real_op);
 }
 goto fail;
 			}
@@ -1031,7 +1044,7 @@ xbdback_co_main_loop(struct xbdback_inst
 xbdi->xbdi_name, req->operation);
 			}
 fail:
-			xbdback_send_reply(xbdi, req->id, req->operation,
+			xbdback_send_reply(xbdi, req->id, real_op,
 			BLKIF_RSP_ERROR);
 			xbdi->xbdi_cont = xbdback_co_main_incr;
 			break;
@@ -1136,12 +1149,6 @@ xbdback_co_io(struct xbdback_instance *x
 	KASSERT(req->operation == BLKIF_OP_READ ||
 	req->operation == BLKIF_OP_WRITE ||
 	req->operation == BLKIF_OP_INDIRECT);
-	if (req->operation == BLKIF_OP_WRITE) {
-		if (xbdi->xbdi_ro) {
-			error = EROFS;
-			goto end;
-		}
-	}
 
 	/* copy request segments */
 	switch (xbdi->xbdi_proto) {
@@ -1212,6 +1219,13 @@ xbdback_co_io(struct xbdback_instance *x
 		break;
 	}
 
+	if (req->operation == BLKIF_OP_WRITE) {
+		if (xbdi->xbdi_ro) {
+			error = EROFS;
+			goto end;
+		}
+	}
+
 	/* Max value checked already earlier */
 	if (req->nr_segments < 1)
 		goto bad_nr_segments;
@@ -1228,8 +1242,7 @@ xbdback_co_io(struct xbdback_instance *x
 	/* FALLTHROUGH */
 
  end:
-	xbdback_send_reply(xbdi, xbdi->xbdi_xen_req.id,
-	xbdi->xbdi_xen_req.operation,
+	xbdback_send_reply(xbdi, req->id, req->operation,
 	(error == EROFS) ? BLKIF_RSP_EOPNOTSUPP : BLKIF_RSP_ERROR);
 	xbdi->xbdi_cont = xbdback_co_main_incr;
 

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

2020-04-25 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Apr 25 11:33:28 UTC 2020

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

Log Message:
use m_defrag() instead of local code now that it returns single mbuf


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/arch/xen/xen/if_xennet_xenbus.c
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/xen/xen/xennetback_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.116 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.117
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.116	Thu Apr 23 15:06:49 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Sat Apr 25 11:33:28 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.116 2020/04/23 15:06:49 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.117 2020/04/25 11:33:28 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.116 2020/04/23 15:06:49 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.117 2020/04/25 11:33:28 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -1002,41 +1002,23 @@ xennet_start(struct ifnet *ifp)
 			txflags = NETTXF_data_validated;
 		}
 
-		/* Try to load the mbuf as-is, if that fails allocate new */
+		/* Try to load the mbuf as-is, if that fails defrag */
 		if (__predict_false(bus_dmamap_load_mbuf(
 		sc->sc_xbusd->xbusd_dmat,
 		req->txreq_dmamap, m, BUS_DMA_NOWAIT) != 0)) {
-			struct mbuf *new_m;
-
-			MGETHDR(new_m, M_DONTWAIT, MT_DATA);
-			if (__predict_false(new_m == NULL)) {
-printf("%s: cannot allocate new mbuf\n",
-   device_xname(sc->sc_dev));
+			if (__predict_false(m_defrag(m, M_DONTWAIT) == NULL)) {
+DPRINTF(("%s: defrag failed\n",
+device_xname(sc->sc_dev)));
 m_freem(m);
 break;
 			}
-			if (m->m_pkthdr.len > MHLEN) {
-MCLGET(new_m, M_DONTWAIT);
-if (__predict_false(
-(new_m->m_flags & M_EXT) == 0)) {
-	DPRINTF(("%s: no mbuf cluster\n",
-	device_xname(sc->sc_dev)));
-	m_freem(new_m);
-	m_freem(m);
-	break;
-}
-			}
-
-			m_copydata(m, 0, m->m_pkthdr.len, mtod(new_m, void *));
-			new_m->m_len = new_m->m_pkthdr.len = m->m_pkthdr.len;
-			m_freem(m);
-			m = new_m;
 
 			if (__predict_false(bus_dmamap_load_mbuf(
 			sc->sc_xbusd->xbusd_dmat,
 			req->txreq_dmamap, m, BUS_DMA_NOWAIT) != 0)) {
-printf("%s: cannot load new mbuf\n",
-   device_xname(sc->sc_dev));
+printf("%s: cannot load new mbuf len %d\n",
+device_xname(sc->sc_dev),
+m->m_pkthdr.len);
 m_freem(m);
 break;
 			}

Index: src/sys/arch/xen/xen/xennetback_xenbus.c
diff -u src/sys/arch/xen/xen/xennetback_xenbus.c:1.96 src/sys/arch/xen/xen/xennetback_xenbus.c:1.97
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.96	Sat Apr 11 11:48:20 2020
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Sat Apr 25 11:33:28 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.96 2020/04/11 11:48:20 jdolecek Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.97 2020/04/25 11:33:28 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.96 2020/04/11 11:48:20 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.97 2020/04/25 11:33:28 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -860,44 +860,6 @@ xennetback_ifstart(struct ifnet *ifp)
 	xennetback_ifsoftstart_copy(xneti);
 }
 
-/*
- * sighly different from m_dup(); for some reason m_dup() can return
- * a chain where the data area can cross a page boundary.
- * This doesn't happens with the function below.
- */
-static struct mbuf *
-xennetback_copymbuf(struct mbuf *m)
-{
-	struct mbuf *new_m;
-
-	MGETHDR(new_m, M_DONTWAIT, MT_DATA);
-	if (__predict_false(new_m == NULL)) {
-		m_freem(m);
-		return NULL;
-	}
-	if (m->m_pkthdr.len > MHLEN) {
-		MCLGET(new_m, M_DONTWAIT);
-		if (__predict_false((new_m->m_flags & M_EXT) == 0)) {
-			m_freem(new_m);
-			m_freem(m);
-			return NULL;
-		}
-	}
-	m_copydata(m, 0, m->m_pkthdr.len,
-	mtod(new_m, void *));
-	new_m->m_len = new_m->m_pkthdr.len =
-	m->m_pkthdr.len;
-
-	/*
-	 * Need to retain csum flags to know if csum was actually computed.
-	 * This is used to set NETRXF_csum_blank/NETRXF_data_validated.
-	 */
-	new_m->m_pkthdr.csum_flags = m->m_pkthdr.csum_flags;
-
-	m_freem(m);
-	return new_m;
-}
-
 static void
 xennetback_ifsoftstart_copy(struct xnetback_instance *xneti)
 {
@@ -953,12 +915,11 @@ xennetback_ifsoftstart_copy(struct xnetb
 			if (bus_dmamap_load_mbuf(
 			xneti->xni_xbusd->xbusd_dmat,
 			xst->xs_dmamap, m, BUS_DMA_NOWAIT) != 0) {
-/* Not possible to load, must copy */

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

2020-04-23 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Apr 23 15:06:50 UTC 2020

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

Log Message:
also let backend know that feature-ipv6-csum-offload is supported


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/sys/arch/xen/xen/if_xennet_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.115 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.116
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.115	Thu Apr 23 14:54:48 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Thu Apr 23 15:06:49 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.115 2020/04/23 14:54:48 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.116 2020/04/23 15:06:49 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.115 2020/04/23 14:54:48 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.116 2020/04/23 15:06:49 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -576,6 +576,12 @@ again:
 		goto abort_transaction;
 	}
 	error = xenbus_printf(xbt, sc->sc_xbusd->xbusd_path,
+	"feature-ipv6-csum-offload", "%u", 1);
+	if (error) {
+		errmsg = "writing feature-ipv6-csum-offload";
+		goto abort_transaction;
+	}
+	error = xenbus_printf(xbt, sc->sc_xbusd->xbusd_path,
 	"event-channel", "%u", sc->sc_evtchn);
 	if (error) {
 		errmsg = "writing event channel";



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

2020-04-23 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Apr 23 14:54:48 UTC 2020

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

Log Message:
g/c unused macro


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/sys/arch/xen/xen/if_xennet_xenbus.c

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

Modified files:

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.114 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.115
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.114	Sun Apr 12 13:57:07 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Thu Apr 23 14:54:48 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.114 2020/04/12 13:57:07 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.115 2020/04/23 14:54:48 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.114 2020/04/12 13:57:07 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.115 2020/04/23 14:54:48 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -195,8 +195,6 @@ struct xennet_xenbus_softc {
 	bool sc_ipv6_csum;	/* whether backend support IPv6 csum offload */
 	krndsource_t sc_rnd_source;
 };
-#define SC_NLIVEREQ(sc) ((sc)->sc_rx_ring.req_prod_pvt - \
-			(sc)->sc_rx_ring.sring->rsp_prod)
 
 static pool_cache_t if_xennetrxbuf_cache;
 static int if_xennetrxbuf_cache_inited=0;



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

2020-04-23 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Apr 23 09:16:21 UTC 2020

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

Log Message:
make xbdback actually MPSAFE and stop using KERNEL_LOCK()

remove no longer necessary atomics, the counters are now always
updated with held mutex


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 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.89 src/sys/arch/xen/xen/xbdback_xenbus.c:1.90
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.89	Thu Apr 23 08:09:25 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Thu Apr 23 09:16:21 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.89 2020/04/23 08:09:25 jdolecek Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.90 2020/04/23 09:16:21 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,9 +26,8 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.89 2020/04/23 08:09:25 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.90 2020/04/23 09:16:21 jdolecek Exp $");
 
-#include 
 #include 
 #include 
 #include 
@@ -227,11 +226,11 @@ struct xbdback_instance {
 	struct timeval xbdi_lasterr_time;/* error time tracking */
 };
 /* Manipulation of the above reference count. */
-#define xbdi_get(xbdip) atomic_inc_uint(&(xbdip)->xbdi_refcnt)
-#define xbdi_put(xbdip)  \
-do { \
-	if (atomic_dec_uint_nv(&(xbdip)->xbdi_refcnt) == 0)  \
-   xbdback_finish_disconnect(xbdip); \
+#define xbdi_get(xbdip) (xbdip)->xbdi_refcnt++
+#define xbdi_put(xbdip)		\
+do {\
+	if (--((xbdip)->xbdi_refcnt) == 0)  			\
+   xbdback_finish_disconnect(xbdip);		\
 } while (/* CONSTCOND */ 0)
 
 static SLIST_HEAD(, xbdback_instance) xbdback_instances;
@@ -269,6 +268,8 @@ static void *xbdback_co_do_io(struct xbd
 
 static void xbdback_io_error(struct xbdback_io *, int);
 static void xbdback_iodone(struct buf *);
+static void xbdback_iodone_locked(struct xbdback_instance *,
+		struct xbdback_io *, struct buf *);
 static void xbdback_send_reply(struct xbdback_instance *, uint64_t , int , int);
 
 static void *xbdback_map_shm(struct xbdback_io *);
@@ -336,10 +337,6 @@ xbdback_xenbus_create(struct xenbus_devi
 		return EFTYPE;
 	}
 
-	/* XXXSMP unlocked search */
-	if (xbdif_lookup(domid, handle)) {
-		return EEXIST;
-	}
 	xbdi = kmem_zalloc(sizeof(*xbdi), KM_SLEEP);
 
 	xbdi->xbdi_domid = domid;
@@ -347,15 +344,21 @@ xbdback_xenbus_create(struct xenbus_devi
 	snprintf(xbdi->xbdi_name, sizeof(xbdi->xbdi_name), "xbdb%di%d",
 	xbdi->xbdi_domid, xbdi->xbdi_handle);
 
+	mutex_enter(_lock);
+	if (xbdif_lookup(domid, handle)) {
+		mutex_exit(_lock);
+		kmem_free(xbdi, sizeof(*xbdi));
+		return EEXIST;
+	}
+	SLIST_INSERT_HEAD(_instances, xbdi, next);
+	mutex_exit(_lock);
+
 	/* initialize status and reference counter */
 	xbdi->xbdi_status = DISCONNECTED;
 	xbdi_get(xbdi);
 
 	mutex_init(>xbdi_lock, MUTEX_DEFAULT, IPL_BIO);
 	cv_init(>xbdi_cv, xbdi->xbdi_name);
-	mutex_enter(_lock);
-	SLIST_INSERT_HEAD(_instances, xbdi, next);
-	mutex_exit(_lock);
 
 	xbusd->xbusd_u.b.b_cookie = xbdi;	
 	xbusd->xbusd_u.b.b_detach = xbdback_xenbus_destroy;
@@ -852,7 +855,7 @@ xbdback_finish_disconnect(struct xbdback
 
 	xbdi->xbdi_status = DISCONNECTED;
 
-	cv_signal(>xbdi_cv);
+	cv_broadcast(>xbdi_cv);
 }
 
 static bool
@@ -861,14 +864,14 @@ xbdif_lookup(domid_t dom , uint32_t hand
 	struct xbdback_instance *xbdi;
 	bool found = false;
 
-	mutex_enter(_lock);
+	KASSERT(mutex_owned(_lock));
+
 	SLIST_FOREACH(xbdi, _instances, next) {
 		if (xbdi->xbdi_domid == dom && xbdi->xbdi_handle == handle) {
 			found = true;
 			break;
 		}
 	}
-	mutex_exit(_lock);
 
 	return found;
 }
@@ -881,7 +884,9 @@ xbdback_evthandler(void *arg)
 	XENPRINTF(("xbdback_evthandler domain %d: cont %p\n",
 	xbdi->xbdi_domid, xbdi->xbdi_cont));
 
+	mutex_enter(>xbdi_lock);
 	xbdback_wakeup_thread(xbdi);
+	mutex_exit(>xbdi_lock);
 
 	return 1;
 }
@@ -895,16 +900,14 @@ xbdback_thread(void *arg)
 {
 	struct xbdback_instance *xbdi = arg;
 
+	mutex_enter(>xbdi_lock);
 	for (;;) {
-		mutex_enter(>xbdi_lock);
 		switch (xbdi->xbdi_status) {
 		case WAITING:
 			cv_wait(>xbdi_cv, >xbdi_lock);
-			mutex_exit(>xbdi_lock);
 			break;
 		case RUN:
 			xbdi->xbdi_status = WAITING; /* reset state */
-			mutex_exit(>xbdi_lock);
 
 			if (xbdi->xbdi_cont == NULL) {
 xbdi->xbdi_cont = xbdback_co_main;
@@ -916,22 +919,24 @@ xbdback_thread(void *arg)
 			if (xbdi->xbdi_pendingreqs > 0) {
 /* there are pending I/Os. Wait for them. */
 cv_wait(>xbdi_cv, >xbdi_lock);
-mutex_exit(>xbdi_lock);
-break;
+continue;
 			}
 			
 			/* All I/Os should have been 

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

2020-04-23 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Apr 23 08:09:25 UTC 2020

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

Log Message:
allocate xbdback_io instances as part of struct xbdback_instance and
stop using pool_cache(9), to remove possibility for the allocation to sleep


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 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.88 src/sys/arch/xen/xen/xbdback_xenbus.c:1.89
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.88	Thu Apr 23 07:39:07 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Thu Apr 23 08:09:25 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.88 2020/04/23 07:39:07 jdolecek Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.89 2020/04/23 08:09:25 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.88 2020/04/23 07:39:07 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.89 2020/04/23 08:09:25 jdolecek Exp $");
 
 #include 
 #include 
@@ -142,6 +142,41 @@ struct xbdback_va {
 	vaddr_t xv_vaddr;
 };
 
+/*
+ * For each I/O operation associated with one of those requests, an
+ * xbdback_io is allocated from a pool.  It may correspond to multiple
+ * Xen disk requests, or parts of them, if several arrive at once that
+ * can be coalesced.
+ */
+struct xbdback_io {
+	SLIST_ENTRY(xbdback_io) xio_next;
+	/* The instance pointer is duplicated for convenience. */
+	struct xbdback_instance *xio_xbdi; /* our xbd instance */
+	uint8_t xio_operation;
+	uint64_t xio_id;
+	union {
+		struct {
+			struct buf xio_buf; /* our I/O */
+			/* the virtual address to map the request at */
+			vaddr_t xio_vaddr;
+			struct xbdback_va *xio_xv;
+			vaddr_t xio_start_offset;	/* I/O start offset */
+			/* grants to map */
+			grant_ref_t xio_gref[VBD_MAX_INDIRECT_SEGMENTS];
+			/* grants release */
+			grant_handle_t xio_gh[VBD_MAX_INDIRECT_SEGMENTS];
+			uint16_t xio_nrma; /* number of guest pages */
+		} xio_rw;
+	} u;
+};
+#define xio_buf		u.xio_rw.xio_buf
+#define xio_vaddr	u.xio_rw.xio_vaddr
+#define xio_start_offset	u.xio_rw.xio_start_offset
+#define xio_xv		u.xio_rw.xio_xv
+#define xio_gref	u.xio_rw.xio_gref
+#define xio_gh		u.xio_rw.xio_gh
+#define xio_nrma	u.xio_rw.xio_nrma
+
 /* we keep the xbdback instances in a linked list */
 struct xbdback_instance {
 	SLIST_ENTRY(xbdback_instance) next;
@@ -154,7 +189,9 @@ struct xbdback_instance {
 	kmutex_t xbdi_lock;
 	kcondvar_t xbdi_cv;	/* wait channel for thread work */
 	xbdback_state_t xbdi_status; /* thread's status */
-	/* KVA for mapping transfers */
+	/* context and KVA for mapping transfers */
+	struct xbdback_io xbdi_io[BLKIF_RING_SIZE];
+	SLIST_HEAD(, xbdback_io) xbdi_io_free;
 	struct xbdback_va xbdi_va[BLKIF_RING_SIZE];
 	SLIST_HEAD(, xbdback_va) xbdi_va_free;
 	/* backing device parameters */
@@ -200,46 +237,6 @@ do {
 static SLIST_HEAD(, xbdback_instance) xbdback_instances;
 static kmutex_t xbdback_lock;
 
-/*
- * For each I/O operation associated with one of those requests, an
- * xbdback_io is allocated from a pool.  It may correspond to multiple
- * Xen disk requests, or parts of them, if several arrive at once that
- * can be coalesced.
- */
-struct xbdback_io {
-	/* The instance pointer is duplicated for convenience. */
-	struct xbdback_instance *xio_xbdi; /* our xbd instance */
-	uint8_t xio_operation;
-	uint64_t xio_id;
-	union {
-		struct {
-			struct buf xio_buf; /* our I/O */
-			/* the virtual address to map the request at */
-			vaddr_t xio_vaddr;
-			struct xbdback_va *xio_xv;
-			vaddr_t xio_start_offset;	/* I/O start offset */
-			/* grants to map */
-			grant_ref_t xio_gref[VBD_MAX_INDIRECT_SEGMENTS];
-			/* grants release */
-			grant_handle_t xio_gh[VBD_MAX_INDIRECT_SEGMENTS];
-			uint16_t xio_nrma; /* number of guest pages */
-		} xio_rw;
-	} u;
-};
-#define xio_buf		u.xio_rw.xio_buf
-#define xio_vaddr	u.xio_rw.xio_vaddr
-#define xio_start_offset	u.xio_rw.xio_start_offset
-#define xio_xv		u.xio_rw.xio_xv
-#define xio_gref	u.xio_rw.xio_gref
-#define xio_gh		u.xio_rw.xio_gh
-#define xio_nrma	u.xio_rw.xio_nrma
-
-/*
- * Pools to manage the chain of block requests and I/Os fragments
- * submitted by frontend.
- */
-static struct pool_cache xbdback_io_pool;
-
 /* Interval between reports of I/O errors from frontend */
 static const struct timeval xbdback_err_intvl = { 1, 0 };
 
@@ -277,9 +274,8 @@ static void xbdback_send_reply(struct xb
 static void *xbdback_map_shm(struct xbdback_io *);
 static void xbdback_unmap_shm(struct xbdback_io *);
 
-static void *xbdback_pool_get(struct pool_cache *,
-			  struct xbdback_instance *);
-static void xbdback_pool_put(struct pool_cache 

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

2020-04-23 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Apr 23 07:39:07 UTC 2020

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

Log Message:
g/c no longer used xbdi_same_page and xbdi_lastfragio_time


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 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.87 src/sys/arch/xen/xen/xbdback_xenbus.c:1.88
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.87	Thu Apr 23 07:24:40 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Thu Apr 23 07:39:07 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.87 2020/04/23 07:24:40 jdolecek Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.88 2020/04/23 07:39:07 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.87 2020/04/23 07:24:40 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.88 2020/04/23 07:39:07 jdolecek Exp $");
 
 #include 
 #include 
@@ -186,12 +186,8 @@ struct xbdback_instance {
 	bus_dmamap_t xbdi_seg_dmamap;
 	grant_ref_t xbdi_in_gntref;
 	/* other state */
-	int xbdi_same_page; /* are we merging two segments on the same page? */
 	uint xbdi_pendingreqs; /* number of I/O in fly */
 	struct timeval xbdi_lasterr_time;/* error time tracking */
-#ifdef DEBUG
-	struct timeval xbdi_lastfragio_time; /* fragmented I/O tracking */
-#endif
 };
 /* Manipulation of the above reference count. */
 #define xbdi_get(xbdip) atomic_inc_uint(&(xbdip)->xbdi_refcnt)



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

2020-04-23 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Apr 23 07:24:40 UTC 2020

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

Log Message:
g/c no longer needed xbdi_io structure member, just pass it as continuation
parameter


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 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.86 src/sys/arch/xen/xen/xbdback_xenbus.c:1.87
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.86	Tue Apr 21 13:56:18 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Thu Apr 23 07:24:40 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.86 2020/04/21 13:56:18 jdolecek Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.87 2020/04/23 07:24:40 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.86 2020/04/21 13:56:18 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.87 2020/04/23 07:24:40 jdolecek Exp $");
 
 #include 
 #include 
@@ -77,7 +77,6 @@ __KERNEL_RCSID(0, "$NetBSD: xbdback_xenb
 
 CTASSERT(XENSHM_MAX_PAGES_PER_REQUEST >= VBD_MAX_INDIRECT_SEGMENTS);
 
-struct xbdback_io;
 struct xbdback_instance;
 
 /*
@@ -186,8 +185,6 @@ struct xbdback_instance {
 	struct blkif_request_segment xbdi_seg[VBD_MAX_INDIRECT_SEGMENTS];
 	bus_dmamap_t xbdi_seg_dmamap;
 	grant_ref_t xbdi_in_gntref;
-	/* _io state: I/O associated to this instance */
-	struct xbdback_io *xbdi_io;
 	/* other state */
 	int xbdi_same_page; /* are we merging two segments on the same page? */
 	uint xbdi_pendingreqs; /* number of I/O in fly */
@@ -1043,7 +1040,6 @@ fail:
 			break;
 		}
 	} else {
-		KASSERT(xbdi->xbdi_io == NULL);
 		xbdi->xbdi_cont = xbdback_co_main_done2;
 	}
 	return xbdi;
@@ -1090,7 +1086,6 @@ xbdback_co_main_done2(struct xbdback_ins
 {
 	int work_to_do;
 
-	KASSERT(xbdi->xbdi_io == NULL);
 	RING_FINAL_CHECK_FOR_REQUESTS(>xbdi_ring.ring_n, work_to_do);
 	if (work_to_do)
 		xbdi->xbdi_cont = xbdback_co_main;
@@ -1126,12 +1121,12 @@ xbdback_co_cache_doflush(struct xbdback_
 	struct xbdback_io *xbd_io;
 
 	XENPRINTF(("xbdback_co_cache_doflush %p %p\n", xbdi, obj));
-	xbd_io = xbdi->xbdi_io = obj;
+	xbd_io = obj;
 	xbd_io->xio_xbdi = xbdi;
 	xbd_io->xio_operation = xbdi->xbdi_xen_req.operation;
 	xbd_io->xio_id = xbdi->xbdi_xen_req.id;
 	xbdi->xbdi_cont = xbdback_co_do_io;
-	return xbdi;
+	return xbd_io;
 }
 
 /*
@@ -1235,7 +1230,6 @@ xbdback_co_io(struct xbdback_instance *x
 	if (req->nr_segments < 1)
 		goto bad_nr_segments;
 
-	KASSERT(xbdi->xbdi_io == NULL);
 	xbdi->xbdi_cont = xbdback_co_io_gotio;
 	return xbdback_pool_get(_io_pool, xbdi);
 
@@ -1268,7 +1262,7 @@ xbdback_co_io_gotio(struct xbdback_insta
 	atomic_inc_uint(>xbdi_pendingreqs);
 	
 	req = >xbdi_xen_req;
-	xbd_io = xbdi->xbdi_io = obj;
+	xbd_io = obj;
 	memset(xbd_io, 0, sizeof(*xbd_io));
 	buf_init(_io->xio_buf);
 	xbd_io->xio_xbdi = xbdi;
@@ -1339,7 +1333,7 @@ xbdback_co_io_gotio(struct xbdback_insta
 	xbd_io->xio_buf.b_private = xbd_io;
 
 	xbdi->xbdi_cont = xbdback_co_do_io;
-	return xbdback_map_shm(xbdi->xbdi_io);
+	return xbdback_map_shm(xbd_io);
 }
 
 static void
@@ -1356,7 +1350,7 @@ xbdback_io_error(struct xbdback_io *xbd_
 static void *
 xbdback_co_do_io(struct xbdback_instance *xbdi, void *obj)
 {
-	struct xbdback_io *xbd_io = xbdi->xbdi_io;
+	struct xbdback_io *xbd_io = obj;
 
 	switch (xbd_io->xio_operation) {
 	case BLKIF_OP_FLUSH_DISKCACHE:
@@ -1379,7 +1373,6 @@ xbdback_co_do_io(struct xbdback_instance
 		xbd_io->xio_operation, error);
 		xbdback_pool_put(_io_pool, xbd_io);
 		xbdi_put(xbdi);
-		xbdi->xbdi_io = NULL;
 		xbdi->xbdi_cont = xbdback_co_main_incr;
 		return xbdi;
 	}
@@ -1395,7 +1388,6 @@ xbdback_co_do_io(struct xbdback_instance
 		}
 		/* will call xbdback_iodone() asynchronously when done */
 		bdev_strategy(_io->xio_buf);
-		xbdi->xbdi_io = NULL;
 		xbdi->xbdi_cont = xbdback_co_main_incr;
 		return xbdi;
 	default:
@@ -1553,16 +1545,16 @@ xbdback_map_shm(struct xbdback_io *xbd_i
 		}
 		printf("\n");
 #endif
-		return xbdi;
+		return xbd_io;
 	default:
 		if (ratecheck(>xbdi_lasterr_time, _err_intvl)) {
 			printf("xbdback_map_shm: xen_shm error %d ", error);
 		}
-		xbdback_io_error(xbdi->xbdi_io, error);
+		/* this will also free xbd_io via xbdback_iodone() */
+		xbdback_io_error(xbd_io, error);
 		SLIST_INSERT_HEAD(>xbdi_va_free, xbd_io->xio_xv, xv_next);
 		xbd_io->xio_xv = NULL;
-		xbdi->xbdi_io = NULL;
-		// do not retry
+		/* do not retry */
 		xbdi->xbdi_cont = xbdback_co_main_incr;
 		return xbdi;
 	}



CVS commit: src/sys/arch/xen

2020-04-21 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Apr 21 19:03:51 UTC 2020

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

Log Message:
adjust so that this at least compiles and links with __HAVE_PCI_MSI_MSIX


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.22 -r1.23 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/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.53 src/sys/arch/xen/include/intr.h:1.54
--- src/sys/arch/xen/include/intr.h:1.53	Mon Dec 23 13:35:37 2019
+++ src/sys/arch/xen/include/intr.h	Tue Apr 21 19:03:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.53 2019/12/23 13:35:37 thorpej Exp $	*/
+/*	$NetBSD: intr.h,v 1.54 2020/04/21 19:03:51 jdolecek Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -95,6 +95,9 @@ void xen_intr_mask(struct intrhand *);
 void xen_intr_unmask(struct intrhand *);
 void xen_intr_disestablish(struct intrhand *);
 
+struct intrsource *xen_intr_allocate_io_intrsource(const char *);
+void xen_intr_free_io_intrsource(const char *);
+
 #endif /* !_LOCORE */
 
 #endif /* _XEN_INTR_H_ */

Index: src/sys/arch/xen/x86/xen_intr.c
diff -u src/sys/arch/xen/x86/xen_intr.c:1.22 src/sys/arch/xen/x86/xen_intr.c:1.23
--- src/sys/arch/xen/x86/xen_intr.c:1.22	Mon Apr 13 22:54:12 2020
+++ src/sys/arch/xen/x86/xen_intr.c	Tue Apr 21 19:03:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_intr.c,v 1.22 2020/04/13 22:54:12 bouyer Exp $	*/
+/*	$NetBSD: xen_intr.c,v 1.23 2020/04/21 19:03:51 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.22 2020/04/13 22:54:12 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.23 2020/04/21 19:03:51 jdolecek Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -67,6 +67,10 @@ __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v
 
 #if NPCI > 0
 #include 
+#ifdef __HAVE_PCI_MSI_MSIX
+#include 
+#include 
+#endif
 #endif
 
 #if defined(MULTIPROCESSOR)
@@ -527,6 +531,21 @@ xen_intr_create_intrid(int legacy_irq, s
 	return NULL; /* No pic found! */
 }
 
+static struct intrsource xen_dummy_intrsource;
+
+struct intrsource *
+xen_intr_allocate_io_intrsource(const char *intrid)
+{
+	/* Nothing to do, required by MSI code */
+	return _dummy_intrsource;
+}
+
+void
+xen_intr_free_io_intrsource(const char *intrid)
+{
+	/* Nothing to do, required by MSI code */
+}
+
 #if !defined(XENPVHVM)
 __strong_alias(spllower, xen_spllower);
 __strong_alias(x86_read_psl, xen_read_psl);
@@ -542,4 +561,6 @@ __strong_alias(intr_disestablish, xen_in
 __strong_alias(cpu_intr_redistribute, xen_cpu_intr_redistribute);
 __strong_alias(cpu_intr_count, xen_cpu_intr_count);
 __strong_alias(cpu_intr_init, xen_cpu_intr_init);
+__strong_alias(intr_allocate_io_intrsource, xen_intr_allocate_io_intrsource);
+__strong_alias(intr_free_io_intrsource, xen_intr_free_io_intrsource);
 #endif /* !XENPVHVM */



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

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

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

Log Message:
XEN_IPI_KICK was replaced by XEN_IPI_AST.


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

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

Modified files:

Index: src/sys/arch/xen/include/intrdefs.h
diff -u src/sys/arch/xen/include/intrdefs.h:1.15 src/sys/arch/xen/include/intrdefs.h:1.16
--- src/sys/arch/xen/include/intrdefs.h:1.15	Fri Apr  3 22:20:36 2020
+++ src/sys/arch/xen/include/intrdefs.h	Tue Apr 21 18:25:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: intrdefs.h,v 1.15 2020/04/03 22:20:36 ad Exp $ */
+/* $NetBSD: intrdefs.h,v 1.16 2020/04/21 18:25:11 ad Exp $ */
 
 /* This file co-exists, and is included via machine/intrdefs.h */
 
@@ -6,7 +6,6 @@
 #define _XEN_INTRDEFS_H_
 
 /* Xen IPI types */
-#define XEN_IPI_KICK		0x
 #define XEN_IPI_HALT		0x0001
 #define XEN_IPI_SYNCH_FPU	0x0002
 #define XEN_IPI_DDB		0x0004



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

2020-04-21 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Apr 21 14:51:07 UTC 2020

Modified Files:
src/sys/arch/xen/include: xenring.h

Log Message:
add blkif_x86_{32,64}_request_indirect types


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/xen/include/xenring.h

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

Modified files:

Index: src/sys/arch/xen/include/xenring.h
diff -u src/sys/arch/xen/include/xenring.h:1.4 src/sys/arch/xen/include/xenring.h:1.5
--- src/sys/arch/xen/include/xenring.h:1.4	Sun Apr  7 12:23:54 2019
+++ src/sys/arch/xen/include/xenring.h	Tue Apr 21 14:51:06 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xenring.h,v 1.4 2019/04/07 12:23:54 bouyer Exp $ */
+/* $NetBSD: xenring.h,v 1.5 2020/04/21 14:51:06 jdolecek Exp $ */
 
 /*
  * Glue goop for xbd ring request/response protocol structures.
@@ -51,6 +51,19 @@ struct blkif_x86_32_response {
 } __packed;
 typedef struct blkif_x86_32_response blkif_x86_32_response_t;
 
+struct blkif_x86_32_request_indirect {
+uint8_toperation;/* BLKIF_OP_INDIRECT*/
+uint8_tindirect_op;  /* BLKIF_OP_{READ/WRITE}*/
+uint16_t   nr_segments;  /* number of segments   */
+uint64_t   id;		 /* private guest value, echoed in resp  */
+blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
+blkif_vdev_t   handle;   /* only for read/write requests */
+uint16_t	   _pad2;
+grant_ref_tindirect_grefs[BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST];
+uint64_t   _pad3;	 /* make it 64 byte aligned */
+} __packed;
+typedef struct blkif_x86_32_request_indirect blkif_x86_32_request_indirect_t;
+
 /* amd64-type requests/responses (always used in frontends ) */
 
 struct blkif_x86_64_request {
@@ -70,6 +83,25 @@ struct blkif_x86_64_response {
 };
 typedef struct blkif_x86_64_response blkif_x86_64_response_t;
 
+struct blkif_x86_64_request_indirect {
+uint8_toperation;/* BLKIF_OP_INDIRECT*/
+uint8_tindirect_op;  /* BLKIF_OP_{READ/WRITE}*/
+uint16_t   nr_segments;  /* number of segments   */
+uint32_t   _pad1;
+uint64_t   id;   /* private guest value, echoed in resp  */
+blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
+blkif_vdev_t   handle;   /* only for read/write requests */
+uint16_t	   _pad2;
+grant_ref_tindirect_grefs[BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST];
+uint32_t   _pad3;	 /* make it 64 byte aligned */
+} __packed;
+typedef struct blkif_x86_64_request_indirect blkif_x86_64_request_indirect_t;
+
+CTASSERT(sizeof(struct blkif_x86_32_request_indirect)
+	== sizeof(struct blkif_x86_64_request_indirect));
+CTASSERT(sizeof(struct blkif_request_indirect)
+	== sizeof(struct blkif_x86_64_request_indirect));
+
 DEFINE_RING_TYPES(blkif_x86_32, struct blkif_x86_32_request, struct blkif_x86_32_response);
 DEFINE_RING_TYPES(blkif_x86_64, struct blkif_x86_64_request, struct blkif_x86_64_response);
 



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

2020-04-21 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Apr 21 13:56:18 UTC 2020

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

Log Message:
add support for indirect segments, which makes it possible to pass
up to MAXPHYS (implementation limit, interface allows more) using
single request

request using indirect segment requires 1 extra copy hypercall per
request, but saves 2 shared memory hypercalls (map_grant/unmap_grant),
so should be net performance boost due to less TLB flushing

this also effectively doubles disk queue size for xbd(4)


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 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.85 src/sys/arch/xen/xen/xbdback_xenbus.c:1.86
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.85	Mon Apr 20 19:29:09 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Tue Apr 21 13:56:18 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.85 2020/04/20 19:29:09 jdolecek Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.86 2020/04/21 13:56:18 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.85 2020/04/20 19:29:09 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.86 2020/04/21 13:56:18 jdolecek Exp $");
 
 #include 
 #include 
@@ -73,6 +73,9 @@ __KERNEL_RCSID(0, "$NetBSD: xbdback_xenb
 
 /* Need to alloc one extra page to account for possible mapping offset */
 #define VBD_VA_SIZE	(MAXPHYS + PAGE_SIZE)
+#define VBD_MAX_INDIRECT_SEGMENTS	VBD_VA_SIZE >> PAGE_SHIFT
+
+CTASSERT(XENSHM_MAX_PAGES_PER_REQUEST >= VBD_MAX_INDIRECT_SEGMENTS);
 
 struct xbdback_io;
 struct xbdback_instance;
@@ -179,8 +182,10 @@ struct xbdback_instance {
 	RING_IDX xbdi_req_prod; /* limit on request indices */
 	xbdback_cont_t xbdi_cont;
 	/* _request state: track requests fetched from ring */
-	struct xbdback_request *xbdi_req; /* if NULL, ignore following */
 	blkif_request_t xbdi_xen_req;
+	struct blkif_request_segment xbdi_seg[VBD_MAX_INDIRECT_SEGMENTS];
+	bus_dmamap_t xbdi_seg_dmamap;
+	grant_ref_t xbdi_in_gntref;
 	/* _io state: I/O associated to this instance */
 	struct xbdback_io *xbdi_io;
 	/* other state */
@@ -221,9 +226,9 @@ struct xbdback_io {
 			struct xbdback_va *xio_xv;
 			vaddr_t xio_start_offset;	/* I/O start offset */
 			/* grants to map */
-			grant_ref_t xio_gref[XENSHM_MAX_PAGES_PER_REQUEST];
+			grant_ref_t xio_gref[VBD_MAX_INDIRECT_SEGMENTS];
 			/* grants release */
-			grant_handle_t xio_gh[XENSHM_MAX_PAGES_PER_REQUEST];
+			grant_handle_t xio_gh[VBD_MAX_INDIRECT_SEGMENTS];
 			uint16_t xio_nrma; /* number of guest pages */
 		} xio_rw;
 	} u;
@@ -374,6 +379,22 @@ xbdback_xenbus_create(struct xenbus_devi
 	xbusd->xbusd_otherend_changed = xbdback_frontend_changed;
 	xbdi->xbdi_xbusd = xbusd;
 
+	if (bus_dmamap_create(xbdi->xbdi_xbusd->xbusd_dmat, PAGE_SIZE,
+	1, PAGE_SIZE, PAGE_SIZE, BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW,
+	>xbdi_seg_dmamap) != 0) {
+		printf("%s: can't create dma map for indirect segments\n",
+		xbdi->xbdi_name);
+		goto fail;
+	}
+	if (bus_dmamap_load(xbdi->xbdi_xbusd->xbusd_dmat,
+	xbdi->xbdi_seg_dmamap, xbdi->xbdi_seg,
+	sizeof(xbdi->xbdi_seg), NULL, BUS_DMA_WAITOK) != 0) {
+		printf("%s: can't load dma map for indirect segments\n",
+		xbdi->xbdi_name);
+		goto fail;
+	}
+	KASSERT(xbdi->xbdi_seg_dmamap->dm_nsegs == 1);
+
 	SLIST_INIT(>xbdi_va_free);
 	for (i = 0; i < BLKIF_RING_SIZE; i++) {
 		xbdi->xbdi_va[i].xv_vaddr = uvm_km_alloc(kernel_map,
@@ -457,6 +478,9 @@ xbdback_xenbus_destroy(void *arg)
 		}
 	}
 
+	bus_dmamap_unload(xbdi->xbdi_xbusd->xbusd_dmat, xbdi->xbdi_seg_dmamap);
+	bus_dmamap_destroy(xbdi->xbdi_xbusd->xbusd_dmat, xbdi->xbdi_seg_dmamap);
+
 	mutex_destroy(>xbdi_lock);
 	cv_destroy(>xbdi_cv);
 	kmem_free(xbdi, sizeof(*xbdi));
@@ -804,6 +828,13 @@ again:
 		xbusd->xbusd_path, err);
 		goto abort;
 	}
+	err = xenbus_printf(xbt, xbusd->xbusd_path,
+	"feature-max-indirect-segments", "%u", VBD_MAX_INDIRECT_SEGMENTS);
+	if (err) {
+		printf("xbdback: failed to write %s/feature-indirect: %d\n",
+		xbusd->xbusd_path, err);
+		goto abort;
+	}
 	err = xenbus_transaction_end(xbt, 0);
 	if (err == EAGAIN)
 		goto again;
@@ -936,39 +967,35 @@ xbdback_co_main(struct xbdback_instance 
  * the ring.
  */
 static void *
-xbdback_co_main_loop(struct xbdback_instance *xbdi, void *obj) 
+xbdback_co_main_loop(struct xbdback_instance *xbdi, void *obj __unused) 
 {
-	blkif_request_t *req;
+	blkif_request_t *req, *reqn;
 	blkif_x86_32_request_t *req32;
 	blkif_x86_64_request_t *req64;
+	blkif_request_indirect_t *rin;
 
-	(void)obj;
-	req = >xbdi_xen_req;
 	if (xbdi->xbdi_ring.ring_n.req_cons != xbdi->xbdi_req_prod) {
+		req = >xbdi_xen_req;
+		memset(req, 0, 

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

2020-04-21 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Apr 21 13:31:09 UTC 2020

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

Log Message:
adjust the condition for max indirect segments to make it clear what
is really needed (enough to map MAXPHYS + 1 page); no functional difference


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/sys/arch/xen/xen/xbd_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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.121 src/sys/arch/xen/xen/xbd_xenbus.c:1.122
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.121	Sun Apr 19 16:45:08 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Tue Apr 21 13:31:08 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.121 2020/04/19 16:45:08 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.122 2020/04/21 13:31:08 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.121 2020/04/19 16:45:08 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.122 2020/04/21 13:31:08 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -769,7 +769,7 @@ xbd_features(struct xbd_xenbus_softc *sc
 	"feature-max-indirect-segments", , 10);
 	if (err)
 		val = 0;
-	if (val > (MAXPHYS >> PAGE_SHIFT)) {
+	if (val >= (MAXPHYS >> PAGE_SHIFT) + 1) {
 		/* We can use indirect segments, the limit is big enough */
 		sc->sc_features |= BLKIF_FEATURE_INDIRECT;
 	}



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

2020-04-20 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Apr 20 20:03:21 UTC 2020

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

Log Message:
Pull from bouyer-xenpvh:
Bad news:
 * grant table v2 is not supported for HVM guests on 4.11 at last.
 * see xen/arch/x86/hvm/hypercall.c in Xen sources (missing
 * GNTTABOP_get_status_frames)

So restore grant table v1 for !XENPV


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 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.35 src/sys/arch/xen/xen/xengnt.c:1.36
--- src/sys/arch/xen/xen/xengnt.c:1.35	Tue Apr 14 07:41:05 2020
+++ src/sys/arch/xen/xen/xengnt.c	Mon Apr 20 20:03:21 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xengnt.c,v 1.35 2020/04/14 07:41:05 jdolecek Exp $  */
+/*  $NetBSD: xengnt.c,v 1.36 2020/04/20 20:03:21 bouyer Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.35 2020/04/14 07:41:05 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.36 2020/04/20 20:03:21 bouyer Exp $");
 
 #include 
 #include 
@@ -42,6 +42,18 @@ __KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1
 #include 
 #include 
 
+#include "opt_xen.h"
+
+/* 
+ * grant table v2 is not supported for HVM guests on 4.11 at last.
+ * see xen/arch/x86/hvm/hypercall.c in Xen sources (missing
+ * GNTTABOP_get_status_frames)
+ */
+
+#ifdef XENPV
+#define USE_GRANT_V2
+#endif
+
 /* #define XENDEBUG */
 #ifdef XENDEBUG
 #define DPRINTF(x) printf x
@@ -49,9 +61,6 @@ __KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1
 #define DPRINTF(x)
 #endif
 
-#define NR_GRANT_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v2_t))
-#define NR_GRANT_STATUS_PER_PAGE (PAGE_SIZE / sizeof(grant_status_t))
-
 /* External tools reserve first few grant table entries. */
 #define NR_RESERVED_ENTRIES 8
 
@@ -59,8 +68,6 @@ __KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1
 int gnt_nr_grant_frames;
 /* Maximum number of frames that can make up the grant table */
 int gnt_max_grant_frames;
-/* Number of grant status frames */
-int gnt_status_frames;
 
 /* table of free grant entries */
 grant_ref_t *gnt_entries;
@@ -70,8 +77,19 @@ int last_gnt_entry;
 #define XENGNT_NO_ENTRY 0x
 
 /* VM address of the grant table */
+#ifdef USE_GRANT_V2
+#define NR_GRANT_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v2_t))
+#define NR_GRANT_STATUS_PER_PAGE (PAGE_SIZE / sizeof(grant_status_t))
+
 grant_entry_v2_t *grant_table;
+/* Number of grant status frames */
+int gnt_status_frames;
+
 grant_status_t *grant_status;
+#else /* USE_GRANT_V2 */
+#define NR_GRANT_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v1_t))
+grant_entry_v1_t *grant_table;
+#endif /* USE_GRANT_V2 */
 kmutex_t grant_lock;
 
 static grant_ref_t xengnt_get_entry(void);
@@ -83,7 +101,6 @@ void
 xengnt_init(void)
 {
 	struct gnttab_query_size query;
-	struct gnttab_set_version gntversion;
 	int rc;
 	int nr_grant_entries;
 	int i;
@@ -100,10 +117,14 @@ xengnt_init(void)
 	 */
 	gnt_nr_grant_frames = gnt_max_grant_frames;
 
+
+#ifdef USE_GRANT_V2
+	struct gnttab_set_version gntversion;
 	gntversion.version = 2;
 	rc = HYPERVISOR_grant_table_op(GNTTABOP_set_version, , 1);
 	if (rc < 0 || gntversion.version != 2)
 		panic("GNTTABOP_set_version 2 failed %d", rc);
+#endif /* USE_GRANT_V2 */
 
 	nr_grant_entries =
 	gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE;
@@ -118,12 +139,14 @@ xengnt_init(void)
 	for (i = 0; i <= nr_grant_entries; i++)
 		gnt_entries[i] = XENGNT_NO_ENTRY;
 
+#ifdef USE_GRANT_V2
 	gnt_status_frames =
 	round_page(nr_grant_entries * sizeof(grant_status_t)) / PAGE_SIZE;
 	grant_status = (void *)uvm_km_alloc(kernel_map,
 	gnt_status_frames * PAGE_SIZE, 0, UVM_KMF_VAONLY);
 	if (grant_status == NULL)
 		panic("xengnt_init() status no VM space");
+#endif /* USE_GRANT_V2 */
 
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_VM);
 
@@ -171,8 +194,10 @@ xengnt_suspend(void) {
 	/* Remove virtual => machine mapping for grant table */
 	pmap_kremove((vaddr_t)grant_table, gnt_nr_grant_frames * PAGE_SIZE);
 
+#ifdef USE_GRANT_V2
 	/* Remove virtual => machine mapping for status table */
 	pmap_kremove((vaddr_t)grant_status, gnt_status_frames * PAGE_SIZE);
+#endif
 
 	pmap_update(pmap_kernel());
 	mutex_exit(_lock);
@@ -185,9 +210,11 @@ xengnt_suspend(void) {
 static int
 xengnt_map_status(void)
 {
+#ifdef USE_GRANT_V2
 	gnttab_get_status_frames_t getstatus;
 	uint64_t *pages;
 	size_t sz;
+	int err;
 
 	KASSERT(mutex_owned(_lock));
 
@@ -204,9 +231,9 @@ xengnt_map_status(void)
 	 * get the status frames, and return the list of their virtual
 	 * addresses in 'pages'
 	 */
-	if (HYPERVISOR_grant_table_op(GNTTABOP_get_status_frames,
-	, 1) != 0)
-		panic("%s: get_status_frames failed", __func__);
+	if ((err = HYPERVISOR_grant_table_op(GNTTABOP_get_status_frames,
+	   

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

2020-04-20 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Apr 20 19:29:09 UTC 2020

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

Log Message:
xbdback_fragio_intvl is also no longer used


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 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.84 src/sys/arch/xen/xen/xbdback_xenbus.c:1.85
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.84	Mon Apr 20 19:20:35 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Mon Apr 20 19:29:09 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.84 2020/04/20 19:20:35 bouyer Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.85 2020/04/20 19:29:09 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.84 2020/04/20 19:20:35 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.85 2020/04/20 19:29:09 jdolecek Exp $");
 
 #include 
 #include 
@@ -245,9 +245,6 @@ static struct pool_cache xbdback_io_pool
 /* Interval between reports of I/O errors from frontend */
 static const struct timeval xbdback_err_intvl = { 1, 0 };
 
-#ifdef DEBUG
-static const struct timeval xbdback_fragio_intvl = { 60, 0 };
-#endif
void xbdbackattach(int);
 static int  xbdback_xenbus_create(struct xenbus_device *);
 static int  xbdback_xenbus_destroy(void *);



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

2020-04-20 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Apr 20 19:20:36 UTC 2020

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

Log Message:
Fix build with DIAGNOSTIC


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 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.83 src/sys/arch/xen/xen/xbdback_xenbus.c:1.84
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.83	Mon Apr 20 16:12:28 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Mon Apr 20 19:20:35 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.83 2020/04/20 16:12:28 jdolecek Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.84 2020/04/20 19:20:35 bouyer Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.83 2020/04/20 16:12:28 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.84 2020/04/20 19:20:35 bouyer Exp $");
 
 #include 
 #include 
@@ -1049,7 +1049,6 @@ xbdback_co_main_done2(struct xbdback_ins
 {
 	int work_to_do;
 
-	KASSERT(xbdi->xbdio_io == NULL);
 	RING_FINAL_CHECK_FOR_REQUESTS(>xbdi_ring.ring_n, work_to_do);
 	if (work_to_do)
 		xbdi->xbdi_cont = xbdback_co_main;
@@ -1233,7 +1232,6 @@ static void *
 xbdback_co_do_io(struct xbdback_instance *xbdi, void *obj)
 {
 	struct xbdback_io *xbd_io = xbdi->xbdi_io;
-	int nsegs __diagused;
 
 	switch (xbd_io->xio_operation) {
 	case BLKIF_OP_FLUSH_DISKCACHE:



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

2020-04-20 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Apr 20 16:12:28 UTC 2020

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

Log Message:
remove I/O defragmentation logic, pass requests straight to the
underlying block device without trying to coalesce them

it seems rarely useful, and it makes the handling logic unnecessarily complex -
ultimately it's the DomU operating system responsibility to issue optimal I/O

might also help with the ZFS problem reported on port-xen, and will surely
simplify eventual indirect segment support


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 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.82 src/sys/arch/xen/xen/xbdback_xenbus.c:1.83
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.82	Mon Apr 20 14:11:04 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Mon Apr 20 16:12:28 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.82 2020/04/20 14:11:04 jdolecek Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.83 2020/04/20 16:12:28 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.82 2020/04/20 14:11:04 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.83 2020/04/20 16:12:28 jdolecek Exp $");
 
 #include 
 #include 
@@ -74,9 +74,7 @@ __KERNEL_RCSID(0, "$NetBSD: xbdback_xenb
 /* Need to alloc one extra page to account for possible mapping offset */
 #define VBD_VA_SIZE	(MAXPHYS + PAGE_SIZE)
 
-struct xbdback_request;
 struct xbdback_io;
-struct xbdback_fragment;
 struct xbdback_instance;
 
 /*
@@ -98,8 +96,8 @@ typedef enum {WAITING, RUN, DISCONNECTIN
  * callback), the return value of a continuation can be set to NULL. In that
  * case, the thread will go back to sleeping and wait for the proper
  * condition before it starts processing requests again from where it left.
- * Continuation state is "stored" in the xbdback instance (xbdi_cont and
- * xbdi_cont_aux), and should only be manipulated by the instance thread.
+ * Continuation state is "stored" in the xbdback instance (xbdi_cont),
+ * and should only be manipulated by the instance thread.
  *
  * As xbdback(4) has to handle different sort of asynchronous events (Xen
  * event channels, biointr() soft interrupts, xenbus commands), the xbdi_lock
@@ -109,36 +107,23 @@ typedef enum {WAITING, RUN, DISCONNECTIN
  * Here's how the call graph is supposed to be for a single I/O:
  *
  * xbdback_co_main()
- *|
- *|   --> xbdback_co_cache_doflush() or NULL
- *|   |
- *|   - xbdback_co_cache_flush2() <- xbdback_co_do_io() <-
- *|| |
- *|   |-> xbdback_co_cache_flush() -> xbdback_co_map_io()-
+ *|   --> xbdback_co_cache_flush()
+ *|   ||
+ *|   |-> xbdback_co_cache_doflush() or NULL
+ *|   ||
+ *|   |-> xbdback_co_do_io()
  * xbdback_co_main_loop()-|
- *|   |-> xbdback_co_main_done() ---> xbdback_co_map_io()-
- *|   |  |
- *|   -- xbdback_co_main_done2() <-- xbdback_co_do_io() <-
+ *|   |-> xbdback_co_main_done2() or NULL
  *|   |
- *|   --> xbdback_co_main() or NULL
+ *|   --> xbdback_co_main_incr() -> xbdback_co_main_loop()
  *|
  * xbdback_co_io() -> xbdback_co_main_incr() -> xbdback_co_main_loop()
  *|
- * xbdback_co_io_gotreq()--+--> xbdback_co_map_io() ---
- *||  |
- *  -> xbdback_co_io_loop()|  <- xbdback_co_do_io() <--
- *  | | | |
- *  | | | |--> xbdback_co_io_gotio()
- *  | | | |
- *  | |   xbdback_co_main_incr()  |
- *  | | | |
- *  | |   xbdback_co_main_loop()  |
- *  | |   |
- *  |  xbdback_co_io_gotio2() <---|
- *  | |   |
- *  | |   |--> xbdback_co_io_gotfrag()
- *  | |   |
- *  -- xbdback_co_io_gotfrag2() <-|
+ * xbdback_co_io_gotio() -> xbdback_map_shm()
+ *| |
+ *| xbdback_co_main_incr() -> xbdback_co_main_loop()
+ *|
+ * xbdback_co_do_io() 
  *|
  * xbdback_co_main_incr() -> xbdback_co_main_loop()
  */
@@ -192,17 +177,12 @@ struct xbdback_instance {
 	 * continuation-ness (see above).
 	 */
 	

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

2020-04-20 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Apr 20 14:11:05 UTC 2020

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

Log Message:
do not retry when xen_shm_map() fails after having returned error for it,
it corrupts the ring; just go to next request

should fix the problem with ZFS causing failscade when req fails,
reported by Brian Buhrow on port-xen


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 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.81 src/sys/arch/xen/xen/xbdback_xenbus.c:1.82
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.81	Mon Apr 20 03:00:33 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Mon Apr 20 14:11:04 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.81 2020/04/20 03:00:33 msaitoh Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.82 2020/04/20 14:11:04 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.81 2020/04/20 03:00:33 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.82 2020/04/20 14:11:04 jdolecek Exp $");
 
 #include 
 #include 
@@ -1804,7 +1804,8 @@ xbdback_map_shm(struct xbdback_io *xbd_i
 		SLIST_INSERT_HEAD(>xbdi_va_free, xbd_io->xio_xv, xv_next);
 		xbd_io->xio_xv = NULL;
 		xbdi->xbdi_io = NULL;
-		xbdi->xbdi_cont = xbdi->xbdi_cont_aux;
+		// do not retry
+		xbdi->xbdi_cont = xbdback_co_main_incr;
 		return xbdi;
 	}
 }



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

2020-04-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Apr 20 03:00:33 UTC 2020

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

Log Message:
 Fix typo to make compilable.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 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.80 src/sys/arch/xen/xen/xbdback_xenbus.c:1.81
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.80	Sun Apr 19 20:53:20 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Mon Apr 20 03:00:33 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.80 2020/04/19 20:53:20 jdolecek Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.81 2020/04/20 03:00:33 msaitoh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.80 2020/04/19 20:53:20 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.81 2020/04/20 03:00:33 msaitoh Exp $");
 
 #include 
 #include 
@@ -1580,7 +1580,7 @@ xbdback_co_do_io(struct xbdback_instance
 	case BLKIF_OP_READ:
 	case BLKIF_OP_WRITE:
 		start_offset = (vaddr_t)xbd_io->xio_buf.b_data;
-		KASSERT(xbd_io->xio_buf.b_bcount + start_offset < VDB_VA_SIZE);
+		KASSERT(xbd_io->xio_buf.b_bcount + start_offset < VBD_VA_SIZE);
 		xbd_io->xio_buf.b_data = (void *)
 		(start_offset + xbd_io->xio_vaddr);
 #ifdef DIAGNOSTIC



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

2020-04-19 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Apr 19 20:53:20 UTC 2020

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

Log Message:
SLIST_INIT() xbdi->xbdi_va_free just for clarity


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 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.79 src/sys/arch/xen/xen/xbdback_xenbus.c:1.80
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.79	Sun Apr 19 18:47:40 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Sun Apr 19 20:53:20 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.79 2020/04/19 18:47:40 jdolecek Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.80 2020/04/19 20:53:20 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.79 2020/04/19 18:47:40 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.80 2020/04/19 20:53:20 jdolecek Exp $");
 
 #include 
 #include 
@@ -449,6 +449,7 @@ xbdback_xenbus_create(struct xenbus_devi
 	xbusd->xbusd_otherend_changed = xbdback_frontend_changed;
 	xbdi->xbdi_xbusd = xbusd;
 
+	SLIST_INIT(>xbdi_va_free);
 	for (i = 0; i < BLKIF_RING_SIZE; i++) {
 		xbdi->xbdi_va[i].xv_vaddr = uvm_km_alloc(kernel_map,
 		VBD_VA_SIZE, 0, UVM_KMF_VAONLY|UVM_KMF_WAITVA);



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

2020-04-19 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Apr 19 20:07:54 UTC 2020

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

Log Message:
make privpgops const


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/xen/xen/privcmd.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/privcmd.c
diff -u src/sys/arch/xen/xen/privcmd.c:1.54 src/sys/arch/xen/xen/privcmd.c:1.55
--- src/sys/arch/xen/xen/privcmd.c:1.54	Tue Apr  7 08:14:42 2020
+++ src/sys/arch/xen/xen/privcmd.c	Sun Apr 19 20:07:53 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: privcmd.c,v 1.54 2020/04/07 08:14:42 jdolecek Exp $ */
+/* $NetBSD: privcmd.c,v 1.55 2020/04/19 20:07:53 jdolecek Exp $ */
 
 /*-
  * Copyright (c) 2004 Christian Limpach.
@@ -27,7 +27,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.54 2020/04/07 08:14:42 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.55 2020/04/19 20:07:53 jdolecek Exp $");
 
 #include 
 #include 
@@ -440,7 +440,7 @@ privcmd_ioctl(void *v)
 	return error;
 }
 
-static struct uvm_pagerops privpgops = {
+static const struct uvm_pagerops privpgops = {
   .pgo_reference = privpgop_reference,
   .pgo_detach = privpgop_detach,
   .pgo_fault = privpgop_fault,



CVS commit: src/sys/arch/xen

2020-04-19 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Apr 19 18:47:40 UTC 2020

Modified Files:
src/sys/arch/xen/include: xen_shm.h
src/sys/arch/xen/x86: xen_shm_machdep.c
src/sys/arch/xen/xen: hypervisor.c xbdback_xenbus.c

Log Message:
change interface for xen_shm_map() so that caller always supplies the VA,
it now fails only if the Xen hypercall fails, in which case the failure
is final

change xbdback to pre-allocate KVA on xbdback attach (and free on detach),
so it has always KVA to map the request pages

remove no longer needed KVA allocation failure handling


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/xen/include/xen_shm.h
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/xen/x86/xen_shm_machdep.c
cvs rdiff -u -r1.74 -r1.75 src/sys/arch/xen/xen/hypervisor.c
cvs rdiff -u -r1.78 -r1.79 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/include/xen_shm.h
diff -u src/sys/arch/xen/include/xen_shm.h:1.10 src/sys/arch/xen/include/xen_shm.h:1.11
--- src/sys/arch/xen/include/xen_shm.h:1.10	Tue Jan  8 19:59:24 2019
+++ src/sys/arch/xen/include/xen_shm.h	Sun Apr 19 18:47:40 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xen_shm.h,v 1.10 2019/01/08 19:59:24 jdolecek Exp $  */
+/*  $NetBSD: xen_shm.h,v 1.11 2020/04/19 18:47:40 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -27,7 +27,7 @@
 
 #include "opt_xen.h"
 
-#define XENSHM_MAX_PAGES_PER_REQUEST (MAXPHYS >> PAGE_SHIFT)
+#define XENSHM_MAX_PAGES_PER_REQUEST ((MAXPHYS + PAGE_SIZE) >> PAGE_SHIFT)
 
 /*
  * Helper routines for the backend drivers. This implement the necessary
@@ -35,10 +35,8 @@
  * space, do I/O to it, and unmap it.
  */
 
-int  xen_shm_map(int, int, grant_ref_t *, vaddr_t *, grant_handle_t *, int);
+int  xen_shm_map(int, int, grant_ref_t *, vaddr_t, grant_handle_t *, int);
 void xen_shm_unmap(vaddr_t, int, grant_handle_t *);
-int xen_shm_callback(int (*)(void *), void *);
 
 /* flags for xen_shm_map() */
-#define XSHM_CALLBACK 0x01	/* called from a callback */
 #define XSHM_RO 0x02		/* map the guest's memory read-only */

Index: src/sys/arch/xen/x86/xen_shm_machdep.c
diff -u src/sys/arch/xen/x86/xen_shm_machdep.c:1.14 src/sys/arch/xen/x86/xen_shm_machdep.c:1.15
--- src/sys/arch/xen/x86/xen_shm_machdep.c:1.14	Mon Apr 13 00:27:16 2020
+++ src/sys/arch/xen/x86/xen_shm_machdep.c	Sun Apr 19 18:47:40 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xen_shm_machdep.c,v 1.14 2020/04/13 00:27:16 chs Exp $  */
+/*  $NetBSD: xen_shm_machdep.c,v 1.15 2020/04/19 18:47:40 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.14 2020/04/13 00:27:16 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.15 2020/04/19 18:47:40 jdolecek Exp $");
 
 #include 
 #include 
@@ -55,71 +55,12 @@ __KERNEL_RCSID(0, "$NetBSD: xen_shm_mach
  * available.
  */
 
-/* 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)
-
-/* vm space management */
-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;
-
-#ifdef DEBUG
-/* for ratecheck(9) */
-static struct timeval xen_shm_errintvl = { 60, 0 };  /* a minute, each */
-#endif
-
-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);
-	/* ensure we'll always get items */
-	pool_prime(_shm_callback_pool, 1);
-
-	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;
-	xen_shm_base_address_pg = xen_shm_base_address >> PAGE_SHIFT;
-	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_end_address >> PAGE_SHIFT) - 1 - xen_shm_base_address_pg,
-	1, NULL, NULL, NULL, 1, VM_NOSLEEP, IPL_VM);
-	if (xen_shm_arena == NULL) {
-		panic("xen_shm_init no arena");
-	}
-}
-
 int
-xen_shm_map(int 

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

2020-04-19 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Apr 19 16:45:09 UTC 2020

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

Log Message:
fix calculation of remaining bytes in xbd_diskstart_submit() for second
part of exactly I/O over 32KB when the remaining size was less than 1 page,
loop just finished without filling the last segment

triggered by anita run by Manuel


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/sys/arch/xen/xen/xbd_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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.120 src/sys/arch/xen/xen/xbd_xenbus.c:1.121
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.120	Sat Apr 18 23:24:49 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Sun Apr 19 16:45:08 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.120 2020/04/18 23:24:49 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.121 2020/04/19 16:45:08 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.120 2020/04/18 23:24:49 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.121 2020/04/19 16:45:08 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -850,6 +850,7 @@ again:
 		if (bp->b_error == 0)
 			bp->b_resid = 0;
 
+		KASSERT(xbdreq->req_dmamap->dm_nsegs > 0);
 		for (seg = 0; seg < xbdreq->req_dmamap->dm_nsegs; seg++) {
 			/*
 			 * We are not allowing persistent mappings, so
@@ -1045,6 +1046,7 @@ xbdioctl(dev_t dev, u_long cmd, void *da
 		mutex_enter(>sc_lock);
 		while ((xbdreq = SLIST_FIRST(>sc_xbdreq_head)) == NULL)
 			cv_wait(>sc_req_cv, >sc_lock);
+		KASSERT(!RING_FULL(>sc_ring));
 
 		SLIST_REMOVE_HEAD(>sc_xbdreq_head, req_next);
 		req = RING_GET_REQUEST(>sc_ring,
@@ -1139,6 +1141,7 @@ xbd_diskstart(device_t self, struct buf 
 		error = EAGAIN;
 		goto out;
 	}
+	KASSERT(!RING_FULL(>sc_ring));
 
 	if ((sc->sc_features & BLKIF_FEATURE_INDIRECT) == 0
 	&& bp->b_bcount > XBD_MAX_CHUNK) {
@@ -1170,6 +1173,8 @@ xbd_diskstart(device_t self, struct buf 
 		error = EINVAL;
 		goto out;
 	}
+	KASSERTMSG(xbdreq->req_dmamap->dm_nsegs > 0,
+	"dm_nsegs == 0 with bcount %d", bp->b_bcount);
 
 	for (int seg = 0; seg < xbdreq->req_dmamap->dm_nsegs; seg++) {
 		KASSERT(seg < __arraycount(xbdreq->req_gntref));
@@ -1212,6 +1217,7 @@ xbd_diskstart(device_t self, struct buf 
 	bp, 0, xbdreq->req_dmamap, xbdreq->req_gntref);
 
 	if (bp->b_bcount > XBD_MAX_CHUNK) {
+		KASSERT(!RING_FULL(>sc_ring));
 		struct xbd_req *xbdreq2 = SLIST_FIRST(>sc_xbdreq_head);
 		KASSERT(xbdreq2 != NULL); /* Checked earlier */
 		SLIST_REMOVE_HEAD(>sc_xbdreq_head, req_next);
@@ -1258,7 +1264,7 @@ xbd_diskstart_submit(struct xbd_xenbus_s
 		bus_dma_segment_t *ds = >dm_segs[dmaseg];
 
 		ma = ds->ds_addr;
-		nbytes = imin(ds->ds_len, size);
+		nbytes = ds->ds_len;
 
 		if (start > 0) {
 			if (start >= nbytes) {
@@ -1285,6 +1291,7 @@ xbd_diskstart_submit(struct xbd_xenbus_s
 
 		reqseg->gref = gntref[dmaseg];
 	}
+	KASSERT(segidx > 0);
 	req->nr_segments = segidx;
 	sc->sc_ring.req_prod_pvt++;
 }



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

2020-04-18 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Apr 18 23:24:49 UTC 2020

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

Log Message:
read feature-persistent value on connect, e.g. the Linux Dom0 writes
the value only together with the device info; no functional difference,
since we don't allow persistent mappings


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sys/arch/xen/xen/xbd_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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.119 src/sys/arch/xen/xen/xbd_xenbus.c:1.120
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.119	Sat Apr 18 16:58:00 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Sat Apr 18 23:24:49 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.119 2020/04/18 16:58:00 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.120 2020/04/18 23:24:49 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.119 2020/04/18 16:58:00 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.120 2020/04/18 23:24:49 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -702,6 +702,18 @@ xbd_connect(struct xbd_xenbus_softc *sc)
 {
 	int err;
 	unsigned long long sectors;
+	u_long val;
+
+	/*
+	 * Must read feature-persistent later, e.g. Linux Dom0 writes
+	 * this together with the device info.
+	 */
+	err = xenbus_read_ul(NULL, sc->sc_xbusd->xbusd_otherend,
+	"feature-persistent", , 10);
+	if (err)
+		val = 0;
+	if (val > 0)
+		sc->sc_features |= BLKIF_FEATURE_PERSISTENT;
 
 	err = xenbus_read_ul(NULL,
 	sc->sc_xbusd->xbusd_path, "virtual-device", >sc_handle, 10);
@@ -754,13 +766,6 @@ xbd_features(struct xbd_xenbus_softc *sc
 		sc->sc_features |= BLKIF_FEATURE_BARRIER;
 
 	err = xenbus_read_ul(NULL, sc->sc_xbusd->xbusd_otherend,
-	"feature-persistent", , 10);
-	if (err)
-		val = 0;
-	if (val > 0)
-		sc->sc_features |= BLKIF_FEATURE_PERSISTENT;
-
-	err = xenbus_read_ul(NULL, sc->sc_xbusd->xbusd_otherend,
 	"feature-max-indirect-segments", , 10);
 	if (err)
 		val = 0;



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

2020-04-18 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Apr 18 16:58:00 UTC 2020

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

Log Message:
make compile with XBD_DEBUG


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/sys/arch/xen/xen/xbd_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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.118 src/sys/arch/xen/xen/xbd_xenbus.c:1.119
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.118	Fri Apr 17 10:35:06 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Sat Apr 18 16:58:00 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.118 2020/04/17 10:35:06 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.119 2020/04/18 16:58:00 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.118 2020/04/17 10:35:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.119 2020/04/18 16:58:00 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -281,12 +281,6 @@ xbd_xenbus_attach(device_t parent, devic
 	struct xenbusdev_attach_args *xa = aux;
 	blkif_sring_t *ring;
 	RING_IDX i;
-#ifdef XBD_DEBUG
-	char **dir, *val;
-	int dir_n = 0;
-	char id_str[20];
-	int err;
-#endif
 
 	config_pending_incr(self);
 	aprint_normal(": Xen Virtual Block Device Interface\n");
@@ -933,7 +927,7 @@ xbdopen(dev_t dev, int flags, int fmt, s
 	if ((flags & FWRITE) && (sc->sc_info & VDISK_READONLY))
 		return EROFS;
 
-	DPRINTF(("xbdopen(0x%04x, %d)\n", dev, flags));
+	DPRINTF(("xbdopen(%" PRIx64 ", %d)\n", dev, flags));
 	return dk_open(>sc_dksc, dev, flags, fmt, l);
 }
 
@@ -944,7 +938,7 @@ xbdclose(dev_t dev, int flags, int fmt, 
 
 	sc = device_lookup_private(_cd, DISKUNIT(dev));
 
-	DPRINTF(("xbdclose(%d, %d)\n", dev, flags));
+	DPRINTF(("xbdclose(%" PRIx64 ", %d)\n", dev, flags));
 	return dk_close(>sc_dksc, dev, flags, fmt, l);
 }
 
@@ -979,7 +973,7 @@ xbdsize(dev_t dev)
 {
 	struct	xbd_xenbus_softc *sc;
 
-	DPRINTF(("xbdsize(%d)\n", dev));
+	DPRINTF(("xbdsize(%" PRIx64 ")\n", dev));
 
 	sc = device_lookup_private(_cd, DISKUNIT(dev));
 	if (sc == NULL || sc->sc_shutdown != BLKIF_SHUTDOWN_RUN)
@@ -1024,7 +1018,7 @@ xbdioctl(dev_t dev, u_long cmd, void *da
 	blkif_request_t *req;
 	int notify;
 
-	DPRINTF(("xbdioctl(%d, %08lx, %p, %d, %p)\n",
+	DPRINTF(("xbdioctl(%" PRIx64 ", %08lx, %p, %d, %p)\n",
 	dev, cmd, data, flag, l));
 	dksc = >sc_dksc;
 
@@ -1093,7 +1087,7 @@ xbddump(dev_t dev, daddr_t blkno, void *
 	if (sc == NULL)
 		return (ENXIO);
 
-	DPRINTF(("xbddump(%d, %" PRId64 ", %p, %lu)\n", dev, blkno, va,
+	DPRINTF(("xbddump(%" PRIx64 ", %" PRId64 ", %p, %lu)\n", dev, blkno, va,
 	(unsigned long)size));
 	return dk_dump(>sc_dksc, dev, blkno, va, size, 0);
 }



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

2020-04-17 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Apr 17 10:35:06 UTC 2020

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

Log Message:
constify xbddkdriver


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/sys/arch/xen/xen/xbd_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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.117 src/sys/arch/xen/xen/xbd_xenbus.c:1.118
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.117	Fri Apr 17 10:32:19 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Fri Apr 17 10:35:06 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.117 2020/04/17 10:32:19 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.118 2020/04/17 10:35:06 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.117 2020/04/17 10:32:19 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.118 2020/04/17 10:35:06 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -250,7 +250,7 @@ const struct cdevsw xbd_cdevsw = {
 
 extern struct cfdriver xbd_cd;
 
-static struct dkdriver xbddkdriver = {
+static const struct dkdriver xbddkdriver = {
 .d_strategy = xbdstrategy,
 	.d_minphys = xbdminphys,
 	.d_open = xbdopen,



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

2020-04-17 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Apr 17 10:32:19 UTC 2020

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

Log Message:
remove some old #if 0 code


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/arch/xen/xen/xbd_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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.116 src/sys/arch/xen/xen/xbd_xenbus.c:1.117
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.116	Thu Apr 16 16:38:43 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Fri Apr 17 10:32:19 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.116 2020/04/16 16:38:43 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.117 2020/04/17 10:32:19 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.116 2020/04/16 16:38:43 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.117 2020/04/17 10:32:19 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -186,12 +186,6 @@ struct xbd_xenbus_softc {
 	struct evcnt sc_cnt_indirect;
 };
 
-#if 0
-/* too big to be on stack */
-static multicall_entry_t rq_mcl[XBD_RING_SIZE+1];
-static paddr_t rq_pages[XBD_RING_SIZE];
-#endif
-
 static int  xbd_xenbus_match(device_t, cfdata_t, void *);
 static void xbd_xenbus_attach(device_t, device_t, void *);
 static int  xbd_xenbus_detach(device_t, int);



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

2020-04-16 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Apr 16 16:38:43 UTC 2020

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

Log Message:
if backend supports it, use indirect segment for I/O requests over 32KB

there is some overhead for backend without persistent mappings
(backend needs to map the extra indirect segment page), but this
makes it possible to queue more I/O if using 64KB block size

tested on NetBSD/amd64 DomU against Linux/amd64 Dom0


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/sys/arch/xen/xen/xbd_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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.115 src/sys/arch/xen/xen/xbd_xenbus.c:1.116
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.115	Thu Apr 16 09:51:40 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Thu Apr 16 16:38:43 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.115 2020/04/16 09:51:40 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.116 2020/04/16 16:38:43 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.115 2020/04/16 09:51:40 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.116 2020/04/16 16:38:43 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -103,6 +103,12 @@ __KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c
 CTASSERT((MAXPHYS <= 2*XBD_MAX_CHUNK));
 CTASSERT(XEN_BSIZE == DEV_BSIZE);
 
+struct xbd_indirect {
+	SLIST_ENTRY(xbd_indirect) in_next;
+	struct blkif_request_segment *in_addr;
+	grant_ref_t in_gntref;
+};
+
 struct xbd_req {
 	SLIST_ENTRY(xbd_req) req_next;
 	uint16_t req_id; /* ID passed to backend */
@@ -114,6 +120,7 @@ struct xbd_req {
 		grant_ref_t req_gntref[XBD_XFER_LIMIT >> PAGE_SHIFT];
 		struct buf *req_bp; /* buffer associated with this request */
 		void *req_data; /* pointer to the data buffer */
+		struct xbd_indirect *req_indirect;	/* indirect page */
 	} req_rw;
 	struct {
 		int s_error;
@@ -124,6 +131,7 @@ struct xbd_req {
 #define req_gntref	u.req_rw.req_gntref
 #define req_bp		u.req_rw.req_bp
 #define req_data	u.req_rw.req_data
+#define req_indirect	u.req_rw.req_indirect
 #define req_sync	u.req_sync
 
 struct xbd_xenbus_softc {
@@ -144,6 +152,9 @@ struct xbd_xenbus_softc {
 	struct xbd_req sc_reqs[XBD_RING_SIZE];
 	SLIST_HEAD(,xbd_req) sc_xbdreq_head; /* list of free requests */
 
+	struct xbd_indirect sc_indirect[XBD_RING_SIZE];
+	SLIST_HEAD(,xbd_indirect) sc_indirect_head;
+
 	vmem_addr_t sc_unalign_buffer;
 	struct xbd_req *sc_unalign_used;
 
@@ -166,11 +177,13 @@ struct xbd_xenbus_softc {
 #define BLKIF_FEATURE_CACHE_FLUSH	0x1
 #define BLKIF_FEATURE_BARRIER		0x2
 #define BLKIF_FEATURE_PERSISTENT	0x4
+#define BLKIF_FEATURE_INDIRECT		0x8
 #define BLKIF_FEATURE_BITS		\
-	"\20\1CACHE-FLUSH\2BARRIER\3PERSISTENT"
+	"\20\1CACHE-FLUSH\2BARRIER\3PERSISTENT\4INDIRECT"
 	struct evcnt sc_cnt_map_unalign;
 	struct evcnt sc_cnt_unalign_busy;
 	struct evcnt sc_cnt_queue_full;
+	struct evcnt sc_cnt_indirect;
 };
 
 #if 0
@@ -191,9 +204,12 @@ static int  xbd_diskstart(device_t, stru
 static void xbd_iosize(device_t, int *);
 static void xbd_backend_changed(void *, XenbusState);
 static void xbd_connect(struct xbd_xenbus_softc *);
+static void xbd_features(struct xbd_xenbus_softc *);
 
 static void xbd_diskstart_submit(struct xbd_xenbus_softc *, int,
 	struct buf *bp, int, bus_dmamap_t, grant_ref_t *);
+static void xbd_diskstart_submit_indirect(struct xbd_xenbus_softc *,
+	struct xbd_req *, struct buf *bp);
 static int  xbd_map_align(struct xbd_xenbus_softc *, struct xbd_req *);
 static void xbd_unmap_align(struct xbd_xenbus_softc *, struct xbd_req *, bool);
 
@@ -293,6 +309,8 @@ xbd_xenbus_attach(device_t parent, devic
 	cv_init(>sc_detach_cv, "xbddetach");
 	cv_init(>sc_suspend_cv, "xbdsuspend");
 
+	xbd_features(sc);
+
 	/* initialize free requests list */
 	SLIST_INIT(>sc_xbdreq_head);
 	for (i = 0; i < XBD_RING_SIZE; i++) {
@@ -301,6 +319,22 @@ xbd_xenbus_attach(device_t parent, devic
 		req_next);
 	}
 
+	if (sc->sc_features & BLKIF_FEATURE_INDIRECT) {
+		/* initialize indirect page list */
+		for (i = 0; i < XBD_RING_SIZE; i++) {
+			vmem_addr_t va;
+			if (uvm_km_kmem_alloc(kmem_va_arena,
+			PAGE_SIZE, VM_SLEEP | VM_INSTANTFIT, ) != 0) {
+aprint_error_dev(self,
+"can't alloc indirect pages\n");
+return;
+			}
+			sc->sc_indirect[i].in_addr = (void *)va;
+			SLIST_INSERT_HEAD(>sc_indirect_head,
+			>sc_indirect[i], in_next);
+		}
+	}
+
 	sc->sc_backend_status = BLKIF_STATE_DISCONNECTED;
 	sc->sc_shutdown = BLKIF_SHUTDOWN_REMOTE;
 
@@ -315,6 +349,8 @@ xbd_xenbus_attach(device_t parent, devic
 	NULL, device_xname(self), "map unaligned");
 	evcnt_attach_dynamic(>sc_cnt_queue_full, EVCNT_TYPE_MISC,
 	NULL, device_xname(self), "queue full");
+	evcnt_attach_dynamic(>sc_cnt_indirect, 

  1   2   3   4   5   6   >