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

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

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

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

Log Message:
when checking for physio request check for B_PHYS in b_flags rather
than an internal field, so this works when the original buf is
wrapped by another one by e.g. dk(4)

fixes misfired assert when doing newfs on a wedge, reported by Manuel Bouyer


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 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.114 src/sys/arch/xen/xen/xbd_xenbus.c:1.115
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.114	Wed Apr 15 10:16:47 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Thu Apr 16 09:51:40 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.114 2020/04/15 10:16:47 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.115 2020/04/16 09:51:40 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.114 2020/04/15 10:16:47 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.115 2020/04/16 09:51:40 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -1207,8 +1207,11 @@ xbd_diskstart_submit(struct xbd_xenbus_s
 static int
 xbd_map_align(struct xbd_xenbus_softc *sc, struct xbd_req *req)
 {
-	/* Only can get here if this is physio() request */
-	KASSERT(req->req_bp->b_saveaddr != NULL);
+	/*
+	 * Only can get here if this is physio() request, block I/O
+	 * uses DEV_BSIZE-aligned buffers.
+	 */
+	KASSERT((req->req_bp->b_flags & B_PHYS) != 0);
 
 	sc->sc_cnt_map_unalign.ev_count++;
 



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

2020-04-15 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Apr 15 10:16:47 UTC 2020

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

Log Message:
make xbd(4) accept 64k (aka regular MAXPHYS) I/O, use two linked requests
for this, so that it does not require MAXPHYS override in kernel config
any more

this is useful even if we get indirect segment support one day,
for compatibility with Dom0's not supporting it, like currently NetBSD


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 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.113 src/sys/arch/xen/xen/xbd_xenbus.c:1.114
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.113	Tue Apr 14 15:16:06 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Wed Apr 15 10:16:47 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.113 2020/04/14 15:16:06 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.114 2020/04/15 10:16:47 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.113 2020/04/14 15:16:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.114 2020/04/15 10:16:47 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -94,17 +94,24 @@ __KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c
 
 #define XBD_RING_SIZE __CONST_RING_SIZE(blkif, PAGE_SIZE)
 #define XBD_MAX_XFER (PAGE_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST)
+#define XBD_MAX_CHUNK	32*1024		/* max I/O size we process in 1 req */
+#define XBD_XFER_LIMIT	(2*XBD_MAX_XFER)
 
 #define XEN_BSHIFT  9   /* log2(XEN_BSIZE) */
 #define XEN_BSIZE   (1 << XEN_BSHIFT) 
 
+CTASSERT((MAXPHYS <= 2*XBD_MAX_CHUNK));
+CTASSERT(XEN_BSIZE == DEV_BSIZE);
+
 struct xbd_req {
 	SLIST_ENTRY(xbd_req) req_next;
 	uint16_t req_id; /* ID passed to backend */
 	bus_dmamap_t req_dmamap;
+	struct xbd_req *req_parent, *req_child;
+	bool req_parent_done;
 	union {
 	struct {
-		grant_ref_t req_gntref[BLKIF_MAX_SEGMENTS_PER_REQUEST];
+		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 */
 	} req_rw;
@@ -138,7 +145,7 @@ struct xbd_xenbus_softc {
 	SLIST_HEAD(,xbd_req) sc_xbdreq_head; /* list of free requests */
 
 	vmem_addr_t sc_unalign_buffer;
-	bool sc_unalign_free;
+	struct xbd_req *sc_unalign_used;
 
 	int sc_backend_status; /* our status with backend */
 #define BLKIF_STATE_DISCONNECTED 0
@@ -185,6 +192,8 @@ 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_diskstart_submit(struct xbd_xenbus_softc *, int,
+	struct buf *bp, int, bus_dmamap_t, grant_ref_t *);
 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);
 
@@ -309,7 +318,7 @@ xbd_xenbus_attach(device_t parent, devic
 
 	for (i = 0; i < XBD_RING_SIZE; i++) {
 		if (bus_dmamap_create(sc->sc_xbusd->xbusd_dmat,
-		XBD_MAX_XFER, BLKIF_MAX_SEGMENTS_PER_REQUEST,
+		MAXPHYS, XBD_XFER_LIMIT >> PAGE_SHIFT,
 		PAGE_SIZE, PAGE_SIZE, BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW,
 		>sc_reqs[i].req_dmamap) != 0) {
 			aprint_error_dev(self, "can't alloc dma maps\n");
@@ -322,7 +331,6 @@ xbd_xenbus_attach(device_t parent, devic
 		aprint_error_dev(self, "can't alloc align buffer\n");
 		return;
 	}
-	sc->sc_unalign_free = true;
 
 	/* resume shared structures and tell backend that we are ready */
 	if (xbd_xenbus_resume(self, PMF_Q_NONE) == false) {
@@ -750,18 +758,37 @@ again:
 		DPRINTF(("%s(%p): b_bcount = %ld\n", __func__,
 		bp, (long)bp->b_bcount));
 
-		if (rep->status != BLKIF_RSP_OKAY) {
+		if (bp->b_error != 0 || rep->status != BLKIF_RSP_OKAY) {
 			bp->b_error = EIO;
 			bp->b_resid = bp->b_bcount;
-		} else {
-			KASSERTMSG(xbdreq->req_dmamap->dm_mapsize <=
-			bp->b_resid, "mapsize %d > b_resid %d",
-			(int)xbdreq->req_dmamap->dm_mapsize,
-			(int)bp->b_resid);
-			bp->b_resid -= xbdreq->req_dmamap->dm_mapsize;
-			KASSERT(bp->b_resid == 0);
 		}
 
+		if (xbdreq->req_parent) {
+			struct xbd_req *req_parent = xbdreq->req_parent;
+
+			/* Unhook and recycle child */
+			xbdreq->req_parent = NULL;
+			req_parent->req_child = NULL;
+			SLIST_INSERT_HEAD(>sc_xbdreq_head, xbdreq,
+req_next);
+
+			if (!req_parent->req_parent_done) {
+/* Finished before parent, nothig else to do */
+continue;
+			}
+
+			/* Must do the cleanup now */
+			xbdreq = req_parent;
+		}
+		if (xbdreq->req_child) {
+			/* Finished before child, child will cleanup */
+			xbdreq->req_parent_done = true;
+			continue;
+		}
+
+		if (bp->b_error == 0)
+			bp->b_resid = 0;
+
 		for (seg = 0; seg < 

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

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

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

Log Message:
fix KASSERT() in xbd_map_align()


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 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.112 src/sys/arch/xen/xen/xbd_xenbus.c:1.113
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.112	Tue Apr 14 14:06:24 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Tue Apr 14 15:16:06 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.112 2020/04/14 14:06:24 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.113 2020/04/14 15:16:06 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.112 2020/04/14 14:06:24 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.113 2020/04/14 15:16:06 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -1132,7 +1132,7 @@ xbd_map_align(struct xbd_xenbus_softc *s
 	}
 	sc->sc_unalign_free = false;
 
-	KASSERT(req->req_bp->b_bcount < MAXPHYS);
+	KASSERT(req->req_bp->b_bcount <= MAXPHYS);
 	req->req_data = (void *)sc->sc_unalign_buffer;
 	if ((req->req_bp->b_flags & B_READ) == 0)
 		memcpy(req->req_data, req->req_bp->b_data,



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

2020-04-14 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Apr 14 14:06:24 UTC 2020

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

Log Message:
rearrange slightly to do proper b_resid accounting, to prepare for partial
transfers


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 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.111 src/sys/arch/xen/xen/xbd_xenbus.c:1.112
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.111	Tue Apr 14 13:10:43 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Tue Apr 14 14:06:24 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.111 2020/04/14 13:10:43 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.112 2020/04/14 14:06:24 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.111 2020/04/14 13:10:43 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.112 2020/04/14 14:06:24 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -745,6 +745,23 @@ again:
 			continue;
 		}
 
+		bp = xbdreq->req_bp;
+		KASSERT(bp != NULL && bp->b_data != NULL);
+		DPRINTF(("%s(%p): b_bcount = %ld\n", __func__,
+		bp, (long)bp->b_bcount));
+
+		if (rep->status != BLKIF_RSP_OKAY) {
+			bp->b_error = EIO;
+			bp->b_resid = bp->b_bcount;
+		} else {
+			KASSERTMSG(xbdreq->req_dmamap->dm_mapsize <=
+			bp->b_resid, "mapsize %d > b_resid %d",
+			(int)xbdreq->req_dmamap->dm_mapsize,
+			(int)bp->b_resid);
+			bp->b_resid -= xbdreq->req_dmamap->dm_mapsize;
+			KASSERT(bp->b_resid == 0);
+		}
+
 		for (seg = 0; seg < xbdreq->req_dmamap->dm_nsegs; seg++) {
 			/*
 			 * We are not allowing persistent mappings, so
@@ -757,21 +774,10 @@ again:
 
 		bus_dmamap_unload(sc->sc_xbusd->xbusd_dmat, xbdreq->req_dmamap);
 
-		bp = xbdreq->req_bp;
-		KASSERT(bp != NULL && bp->b_data != NULL);
-		DPRINTF(("%s(%p): b_bcount = %ld\n", __func__,
-		bp, (long)bp->b_bcount));
-
 		if (__predict_false(bp->b_data != xbdreq->req_data))
 			xbd_unmap_align(sc, xbdreq, true);
 		xbdreq->req_bp = xbdreq->req_data = NULL;
 
-		/* b_resid was set in dk_start, only override on error */
-		if (rep->status != BLKIF_RSP_OKAY) {
-			bp->b_error = EIO;
-			bp->b_resid = bp->b_bcount;
-		}
-
 		dk_done(>sc_dksc, bp);
 
 		SLIST_INSERT_HEAD(>sc_xbdreq_head, xbdreq, req_next);
@@ -1067,7 +1073,7 @@ xbd_diskstart(device_t self, struct buf 
 	req->sector_number = bp->b_rawblkno;
 	req->handle = sc->sc_handle;
 
-	bp->b_resid = 0;
+	bp->b_resid = bp->b_bcount;
 	for (seg = 0; seg < xbdreq->req_dmamap->dm_nsegs; seg++) {
 		bus_dma_segment_t *dmaseg = >req_dmamap->dm_segs[seg];
 



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

2020-04-14 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Apr 14 13:10:43 UTC 2020

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

Log Message:
use single pre-allocated buffer for unaligned I/O - it's rare and not
performance critical path, it's more important to ensure it will succeed
eventually; also return EAGAIN rather than ENOMEM, so the I/O will be
retried by dk_start() when previous I/O finishes

fix yet another leak on the xengnt_grant_access() fail path in
xbd_diskstart() - this time the unalign buffer


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 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.110 src/sys/arch/xen/xen/xbd_xenbus.c:1.111
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.110	Tue Apr 14 13:02:40 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Tue Apr 14 13:10:43 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.110 2020/04/14 13:02:40 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.111 2020/04/14 13:10:43 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.110 2020/04/14 13:02:40 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.111 2020/04/14 13:10:43 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -137,6 +137,9 @@ struct xbd_xenbus_softc {
 	struct xbd_req sc_reqs[XBD_RING_SIZE];
 	SLIST_HEAD(,xbd_req) sc_xbdreq_head; /* list of free requests */
 
+	vmem_addr_t sc_unalign_buffer;
+	bool sc_unalign_free;
+
 	int sc_backend_status; /* our status with backend */
 #define BLKIF_STATE_DISCONNECTED 0
 #define BLKIF_STATE_CONNECTED1
@@ -159,6 +162,8 @@ struct xbd_xenbus_softc {
 #define BLKIF_FEATURE_BITS		\
 	"\20\1CACHE-FLUSH\2BARRIER\3PERSISTENT"
 	struct evcnt sc_cnt_map_unalign;
+	struct evcnt sc_cnt_unalign_busy;
+	struct evcnt sc_cnt_queue_full;
 };
 
 #if 0
@@ -180,8 +185,8 @@ static void xbd_iosize(device_t, int *);
 static void xbd_backend_changed(void *, XenbusState);
 static void xbd_connect(struct xbd_xenbus_softc *);
 
-static int  xbd_map_align(struct xbd_req *);
-static void xbd_unmap_align(struct xbd_req *);
+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 xbdminphys(struct buf *);
 
@@ -297,6 +302,10 @@ xbd_xenbus_attach(device_t parent, devic
 
 	evcnt_attach_dynamic(>sc_cnt_map_unalign, EVCNT_TYPE_MISC,
 	NULL, device_xname(self), "map unaligned");
+	evcnt_attach_dynamic(>sc_cnt_unalign_busy, EVCNT_TYPE_MISC,
+	NULL, device_xname(self), "map unaligned");
+	evcnt_attach_dynamic(>sc_cnt_queue_full, EVCNT_TYPE_MISC,
+	NULL, device_xname(self), "queue full");
 
 	for (i = 0; i < XBD_RING_SIZE; i++) {
 		if (bus_dmamap_create(sc->sc_xbusd->xbusd_dmat,
@@ -308,6 +317,13 @@ xbd_xenbus_attach(device_t parent, devic
 		}
 	}
 
+	if (uvm_km_kmem_alloc(kmem_va_arena,
+	MAXPHYS, VM_SLEEP | VM_INSTANTFIT, >sc_unalign_buffer) != 0) {
+		aprint_error_dev(self, "can't alloc align buffer\n");
+		return;
+	}
+	sc->sc_unalign_free = true;
+
 	/* resume shared structures and tell backend that we are ready */
 	if (xbd_xenbus_resume(self, PMF_Q_NONE) == false) {
 		uvm_km_free(kernel_map, (vaddr_t)ring, PAGE_SIZE,
@@ -407,9 +423,16 @@ xbd_xenbus_detach(device_t dev, int flag
 		}
 	}
 
+	if (sc->sc_unalign_buffer != 0) {
+		uvm_km_kmem_free(kmem_va_arena, sc->sc_unalign_buffer, MAXPHYS);
+		sc->sc_unalign_buffer = 0;
+	}
+
 	mutex_destroy(>sc_lock);
 
 	evcnt_detach(>sc_cnt_map_unalign);
+	evcnt_detach(>sc_cnt_unalign_busy);
+	evcnt_detach(>sc_cnt_queue_full);
 
 	pmf_device_deregister(dev);
 
@@ -740,7 +763,7 @@ again:
 		bp, (long)bp->b_bcount));
 
 		if (__predict_false(bp->b_data != xbdreq->req_data))
-			xbd_unmap_align(xbdreq);
+			xbd_unmap_align(sc, xbdreq, true);
 		xbdreq->req_bp = xbdreq->req_data = NULL;
 
 		/* b_resid was set in dk_start, only override on error */
@@ -1005,6 +1028,7 @@ xbd_diskstart(device_t self, struct buf 
 
 	xbdreq = SLIST_FIRST(>sc_xbdreq_head);
 	if (__predict_false(xbdreq == NULL)) {
+		sc->sc_cnt_queue_full.ev_count++;
 		DPRINTF(("xbd_diskstart: no req\n"));
 		error = EAGAIN;
 		goto out;
@@ -1018,7 +1042,7 @@ xbd_diskstart(device_t self, struct buf 
 
 		sc->sc_cnt_map_unalign.ev_count++;
 
-		if (__predict_false(xbd_map_align(xbdreq) != 0)) {
+		if (__predict_false(xbd_map_align(sc, xbdreq) != 0)) {
 			DPRINTF(("xbd_diskstart: no align\n"));
 			error = EAGAIN;
 			goto out;
@@ -1028,7 +1052,7 @@ xbd_diskstart(device_t self, struct buf 
 	if (__predict_false(bus_dmamap_load(sc->sc_xbusd->xbusd_dmat,
 	xbdreq->req_dmamap, xbdreq->req_data, bp->b_bcount, NULL,
 	BUS_DMA_NOWAIT) != 0)) {
-		printf("%s: %s: xengnt_grant_access failed",
+		printf("%s: 

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

2020-04-14 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Apr 14 13:02:40 UTC 2020

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

Log Message:
add forgotten mutex_exit() in detach, which caused panic in uvm_unmap1()
due to held spin lock


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 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.109 src/sys/arch/xen/xen/xbd_xenbus.c:1.110
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.109	Tue Apr 14 09:27:28 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Tue Apr 14 13:02:40 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.109 2020/04/14 09:27:28 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.110 2020/04/14 13:02:40 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.109 2020/04/14 09:27:28 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.110 2020/04/14 13:02:40 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -393,6 +393,7 @@ xbd_xenbus_detach(device_t dev, int flag
 	mutex_enter(>sc_lock);
 	while (xengnt_status(sc->sc_ring_gntref))
 		cv_timedwait(>sc_detach_cv, >sc_lock, hz/2);
+	mutex_exit(>sc_lock);
 
 	xengnt_revoke_access(sc->sc_ring_gntref);
 	uvm_km_free(kernel_map, (vaddr_t)sc->sc_ring.sring,



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

2020-04-14 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Apr 14 09:27:28 UTC 2020

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

Log Message:
provide d_iosize hook to cap the xfer size used for dumps


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 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.108 src/sys/arch/xen/xen/xbd_xenbus.c:1.109
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.108	Tue Apr 14 08:21:59 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Tue Apr 14 09:27:28 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.108 2020/04/14 08:21:59 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.109 2020/04/14 09:27:28 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.108 2020/04/14 08:21:59 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.109 2020/04/14 09:27:28 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -176,6 +176,7 @@ static bool xbd_xenbus_resume(device_t, 
 
 static int  xbd_handler(void *);
 static int  xbd_diskstart(device_t, struct buf *);
+static void xbd_iosize(device_t, int *);
 static void xbd_backend_changed(void *, XenbusState);
 static void xbd_connect(struct xbd_xenbus_softc *);
 
@@ -231,6 +232,7 @@ static struct dkdriver xbddkdriver = {
 	.d_open = xbdopen,
 	.d_close = xbdclose,
 	.d_diskstart = xbd_diskstart,
+	.d_iosize = xbd_iosize,
 };
 
 static int
@@ -775,6 +777,17 @@ xbdminphys(struct buf *bp)
 	minphys(bp);
 }
 
+static void
+xbd_iosize(device_t dev, int *maxxfer)
+{
+	/*
+	 * Always restrict dumps to XBD_MAX_XFER to avoid indirect segments,
+	 * so that it uses as little memory as possible. 
+	 */
+	if (*maxxfer > XBD_MAX_XFER)
+		*maxxfer = XBD_MAX_XFER;
+}
+
 int
 xbdopen(dev_t dev, int flags, int fmt, struct lwp *l)
 {



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

2020-04-14 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Apr 14 08:22:00 UTC 2020

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

Log Message:
if grant fails also revoke the grants for previous segments, fixes
grant leak on grant error


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 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.107 src/sys/arch/xen/xen/xbd_xenbus.c:1.108
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.107	Mon Apr 13 20:09:13 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Tue Apr 14 08:21:59 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.107 2020/04/13 20:09:13 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.108 2020/04/14 08:21:59 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.107 2020/04/13 20:09:13 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.108 2020/04/14 08:21:59 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -1049,6 +1049,12 @@ xbd_diskstart(device_t self, struct buf 
 		>req_gntref[seg]))) {
 			printf("%s: %s: xengnt_grant_access failed",
 			device_xname(sc->sc_dksc.sc_dev), __func__);
+			if (seg > 0) {
+for (; --seg >= 0; ) {
+	xengnt_revoke_access(
+	xbdreq->req_gntref[seg]);
+}
+			}
 			bus_dmamap_unload(sc->sc_xbusd->xbusd_dmat,
 			xbdreq->req_dmamap);
 			SLIST_INSERT_HEAD(>sc_xbdreq_head, xbdreq,



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

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

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

Log Message:
DRY - use pages for sizeof() for the frame allocations, so it get's allocated
the correct size without repeating the type


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 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.34 src/sys/arch/xen/xen/xengnt.c:1.35
--- src/sys/arch/xen/xen/xengnt.c:1.34	Tue Apr 14 07:38:12 2020
+++ src/sys/arch/xen/xen/xengnt.c	Tue Apr 14 07:41:05 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xengnt.c,v 1.34 2020/04/14 07:38:12 jdolecek Exp $  */
+/*  $NetBSD: xengnt.c,v 1.35 2020/04/14 07:41:05 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.34 2020/04/14 07:38:12 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.35 2020/04/14 07:41:05 jdolecek Exp $");
 
 #include 
 #include 
@@ -191,7 +191,7 @@ xengnt_map_status(void)
 
 	KASSERT(mutex_owned(_lock));
 
-	sz = gnt_status_frames * sizeof(uint64_t);
+	sz = gnt_status_frames * sizeof(*pages);
 	pages = kmem_alloc(sz, KM_NOSLEEP);
 	if (pages == NULL)
 		return ENOMEM;
@@ -247,7 +247,7 @@ xengnt_more_entries(void)
 	if (gnt_nr_grant_frames == gnt_max_grant_frames)
 		return ENOMEM;
 
-	sz = nframes_new * sizeof(u_long);
+	sz = nframes_new * sizeof(*pages);
 	pages = kmem_alloc(sz, KM_NOSLEEP);
 	if (pages == NULL)
 		return ENOMEM;



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

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

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

Log Message:
actually fix also the allocated memory size for the getstatus frames on i386


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 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.33 src/sys/arch/xen/xen/xengnt.c:1.34
--- src/sys/arch/xen/xen/xengnt.c:1.33	Fri Apr 10 21:03:20 2020
+++ src/sys/arch/xen/xen/xengnt.c	Tue Apr 14 07:38:12 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xengnt.c,v 1.33 2020/04/10 21:03:20 jdolecek Exp $  */
+/*  $NetBSD: xengnt.c,v 1.34 2020/04/14 07:38:12 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.33 2020/04/10 21:03:20 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.34 2020/04/14 07:38:12 jdolecek Exp $");
 
 #include 
 #include 
@@ -191,7 +191,7 @@ xengnt_map_status(void)
 
 	KASSERT(mutex_owned(_lock));
 
-	sz = gnt_status_frames * sizeof(u_long);
+	sz = gnt_status_frames * sizeof(uint64_t);
 	pages = kmem_alloc(sz, KM_NOSLEEP);
 	if (pages == NULL)
 		return ENOMEM;



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

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

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

Log Message:
KASSERT() that requested I/O size is <= XBD_MAX_XFER - this can happen
e.g. with custom DomU kernel which doesn't have the value for MAXPHYS
reduced to 32k like the XEN3_DOMU config


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 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.106 src/sys/arch/xen/xen/xbd_xenbus.c:1.107
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.106	Mon Apr 13 16:29:59 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Mon Apr 13 20:09:13 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.106 2020/04/13 16:29:59 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.107 2020/04/13 20:09:13 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.106 2020/04/13 16:29:59 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.107 2020/04/13 20:09:13 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -965,6 +965,8 @@ xbd_diskstart(device_t self, struct buf 
 	DPRINTF(("xbd_diskstart(%p): b_bcount = %ld\n",
 	bp, (long)bp->b_bcount));
 
+	KASSERT(bp->b_bcount <= XBD_MAX_XFER);
+
 	mutex_enter(>sc_lock);
 
 	if (sc->sc_shutdown != BLKIF_SHUTDOWN_RUN) {



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

2020-04-13 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Apr 13 16:29:59 UTC 2020

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

Log Message:
make xbd(4) D_MPSAFE


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 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.105 src/sys/arch/xen/xen/xbd_xenbus.c:1.106
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.105	Sun Apr 12 20:17:36 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Mon Apr 13 16:29:59 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.105 2020/04/12 20:17:36 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.106 2020/04/13 16:29:59 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.105 2020/04/12 20:17:36 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.106 2020/04/13 16:29:59 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -68,6 +68,7 @@ __KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -109,7 +110,7 @@ struct xbd_req {
 	} req_rw;
 	struct {
 		int s_error;
-		volatile int s_done;
+		int s_done;
 	} req_sync;
 	} u;
 };
@@ -121,18 +122,20 @@ struct xbd_req {
 struct xbd_xenbus_softc {
 	struct dk_softc sc_dksc;	/* Must be first in this struct */
 	struct xenbus_device *sc_xbusd;
+	unsigned int sc_evtchn;
 
 	struct intrhand *sc_ih; /* Interrupt handler for this instance. */
-	
-	blkif_front_ring_t sc_ring;
-
-	unsigned int sc_evtchn;
+	kmutex_t sc_lock;
+	kcondvar_t sc_cache_flush_cv;
+	kcondvar_t sc_req_cv;
+	kcondvar_t sc_detach_cv;
+	kcondvar_t sc_suspend_cv;
 
+	blkif_front_ring_t sc_ring;
 	grant_ref_t sc_ring_gntref;
 
 	struct xbd_req sc_reqs[XBD_RING_SIZE];
 	SLIST_HEAD(,xbd_req) sc_xbdreq_head; /* list of free requests */
-	bool sc_xbdreq_wait; /* special waiting on xbd_req */
 
 	int sc_backend_status; /* our status with backend */
 #define BLKIF_STATE_DISCONNECTED 0
@@ -202,7 +205,7 @@ const struct bdevsw xbd_bdevsw = {
 	.d_dump = xbddump,
 	.d_psize = xbdsize,
 	.d_discard = nodiscard,
-	.d_flag = D_DISK
+	.d_flag = D_DISK | D_MPSAFE
 };
 
 const struct cdevsw xbd_cdevsw = {
@@ -217,7 +220,7 @@ const struct cdevsw xbd_cdevsw = {
 	.d_mmap = nommap,
 	.d_kqfilter = nokqfilter,
 	.d_discard = nodiscard,
-	.d_flag = D_DISK
+	.d_flag = D_DISK | D_MPSAFE
 };
 
 extern struct cfdriver xbd_cd;
@@ -268,6 +271,12 @@ xbd_xenbus_attach(device_t parent, devic
 	sc->sc_xbusd = xa->xa_xbusd;
 	sc->sc_xbusd->xbusd_otherend_changed = xbd_backend_changed;
 
+	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_BIO);
+	cv_init(>sc_cache_flush_cv, "xbdsync");
+	cv_init(>sc_req_cv, "xbdreq");
+	cv_init(>sc_detach_cv, "xbddetach");
+	cv_init(>sc_suspend_cv, "xbdsuspend");
+
 	/* initialize free requests list */
 	SLIST_INIT(>sc_xbdreq_head);
 	for (i = 0; i < XBD_RING_SIZE; i++) {
@@ -313,37 +322,43 @@ static int
 xbd_xenbus_detach(device_t dev, int flags)
 {
 	struct xbd_xenbus_softc *sc = device_private(dev);
-	int bmaj, cmaj, i, mn, rc, s;
+	int bmaj, cmaj, i, mn, rc;
+
+	DPRINTF(("%s: xbd_detach\n", device_xname(dev)));
 
 	rc = disk_begindetach(>sc_dksc.sc_dkdev, NULL, dev, flags);
 	if (rc != 0)
 		return rc;
 
-	s = splbio(); /* XXXSMP */
-	DPRINTF(("%s: xbd_detach\n", device_xname(dev)));
+	mutex_enter(>sc_lock);
 	if (sc->sc_shutdown == BLKIF_SHUTDOWN_RUN) {
 		sc->sc_shutdown = BLKIF_SHUTDOWN_LOCAL;
+
 		/* wait for requests to complete */
 		while (sc->sc_backend_status == BLKIF_STATE_CONNECTED &&
 		disk_isbusy(>sc_dksc.sc_dkdev)) {
-			/* XXXSMP */
-			tsleep(xbd_xenbus_detach, PRIBIO, "xbddetach", hz/2);
+			cv_timedwait(>sc_detach_cv, >sc_lock, hz/2);
 		}
+		mutex_exit(>sc_lock);
 
+		/* Trigger state transition with backend */
 		xenbus_switch_state(sc->sc_xbusd, NULL, XenbusStateClosing);
+
+		mutex_enter(>sc_lock);
 	}
 	if ((flags & DETACH_FORCE) == 0) {
 		/* xbd_xenbus_detach already in progress */
-		wakeup(xbd_xenbus_detach); /* XXXSMP */
-		splx(s);
+		cv_broadcast(>sc_detach_cv);
+		mutex_exit(>sc_lock);
 		return EALREADY;
 	}
+	mutex_exit(>sc_lock);
 	while (xenbus_read_driver_state(sc->sc_xbusd->xbusd_otherend)
 	!= XenbusStateClosed) {
-		/* XXXSMP */
-		tsleep(xbd_xenbus_detach, PRIBIO, "xbddetach2", hz/2);
+		mutex_enter(>sc_lock);
+		cv_timedwait(>sc_detach_cv, >sc_lock, hz/2);
+		mutex_exit(>sc_lock);
 	}
-	splx(s);
 
 	/* locate the major number */
 	bmaj = bdevsw_lookup_major(_bdevsw);
@@ -355,6 +370,7 @@ xbd_xenbus_detach(device_t dev, int flag
 		vdevgone(bmaj, mn, mn, VBLK);
 		vdevgone(cmaj, mn, mn, VCHR);
 	}
+
 	if (sc->sc_backend_status == BLKIF_STATE_CONNECTED) {
 		/* Delete all of our wedges. */
 		dkwedge_delall(>sc_dksc.sc_dkdev);
@@ -372,10 +388,10 @@ xbd_xenbus_detach(device_t dev, int flag
 	

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

2020-04-12 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Apr 12 20:17:36 UTC 2020

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

Log Message:
convert to bus_dma(9)

simplify and fix error handling in xbd_handler(), expect backend
to not use the grant once request is finished, and avoid leaking
bounce buffer when the request using it happens to end with error

in xbd_diskstart() only do the RING_PUSH_REQUESTS_AND_CHECK_NOTIFY()
when actually the request was pushed successfully


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 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.104 src/sys/arch/xen/xen/xbd_xenbus.c:1.105
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.104	Sun Apr 12 18:14:09 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Sun Apr 12 20:17:36 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.104 2020/04/12 18:14:09 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.105 2020/04/12 20:17:36 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.104 2020/04/12 18:14:09 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.105 2020/04/12 20:17:36 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -100,10 +100,10 @@ __KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c
 struct xbd_req {
 	SLIST_ENTRY(xbd_req) req_next;
 	uint16_t req_id; /* ID passed to backend */
+	bus_dmamap_t req_dmamap;
 	union {
 	struct {
 		grant_ref_t req_gntref[BLKIF_MAX_SEGMENTS_PER_REQUEST];
-		int req_nr_segments; /* number of segments in this request */
 		struct buf *req_bp; /* buffer associated with this request */
 		void *req_data; /* pointer to the data buffer */
 	} req_rw;
@@ -114,7 +114,6 @@ struct xbd_req {
 	} u;
 };
 #define req_gntref	u.req_rw.req_gntref
-#define req_nr_segments	u.req_rw.req_nr_segments
 #define req_bp		u.req_rw.req_bp
 #define req_data	u.req_rw.req_data
 #define req_sync	u.req_sync
@@ -288,6 +287,16 @@ xbd_xenbus_attach(device_t parent, devic
 	evcnt_attach_dynamic(>sc_cnt_map_unalign, EVCNT_TYPE_MISC,
 	NULL, device_xname(self), "map unaligned");
 
+	for (i = 0; i < XBD_RING_SIZE; i++) {
+		if (bus_dmamap_create(sc->sc_xbusd->xbusd_dmat,
+		XBD_MAX_XFER, BLKIF_MAX_SEGMENTS_PER_REQUEST,
+		PAGE_SIZE, PAGE_SIZE, BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW,
+		>sc_reqs[i].req_dmamap) != 0) {
+			aprint_error_dev(self, "can't alloc dma maps\n");
+			return;
+		}
+	}
+
 	/* resume shared structures and tell backend that we are ready */
 	if (xbd_xenbus_resume(self, PMF_Q_NONE) == false) {
 		uvm_km_free(kernel_map, (vaddr_t)ring, PAGE_SIZE,
@@ -371,6 +380,14 @@ xbd_xenbus_detach(device_t dev, int flag
 	uvm_km_free(kernel_map, (vaddr_t)sc->sc_ring.sring,
 	PAGE_SIZE, UVM_KMF_WIRED);
 
+	for (i = 0; i < XBD_RING_SIZE; i++) {
+		if (sc->sc_reqs[i].req_dmamap != NULL) {
+			bus_dmamap_destroy(sc->sc_xbusd->xbusd_dmat,
+			sc->sc_reqs[i].req_dmamap);
+			sc->sc_reqs[i].req_dmamap = NULL;
+		}
+	}
+
 	evcnt_detach(>sc_cnt_map_unalign);
 
 	pmf_device_deregister(dev);
@@ -686,41 +703,38 @@ again:
 			continue;
 		}
 
-		for (seg = xbdreq->req_nr_segments - 1; seg >= 0; seg--) {
-			if (__predict_false(
-			xengnt_status(xbdreq->req_gntref[seg]))) {
-aprint_verbose_dev(sc->sc_dksc.sc_dev,
-	"grant still used by backend\n");
-sc->sc_ring.rsp_cons = i;
-xbdreq->req_nr_segments = seg + 1;
-goto done;
-			}
+		for (seg = 0; seg < xbdreq->req_dmamap->dm_nsegs; seg++) {
+			/*
+			 * We are not allowing persistent mappings, so
+			 * expect the backend to release the grant
+			 * immediately.
+			 */
+			KASSERT(xengnt_status(xbdreq->req_gntref[seg]) == 0);
 			xengnt_revoke_access(xbdreq->req_gntref[seg]);
-			xbdreq->req_nr_segments--;
 		}
-		KASSERT(xbdreq->req_nr_segments == 0);
+
+		bus_dmamap_unload(sc->sc_xbusd->xbusd_dmat, xbdreq->req_dmamap);
 
 		bp = xbdreq->req_bp;
-		KASSERT(bp != NULL);
+		KASSERT(bp != NULL && bp->b_data != NULL);
 		DPRINTF(("%s(%p): b_bcount = %ld\n", __func__,
 		bp, (long)bp->b_bcount));
 
+		if (__predict_false(bp->b_data != xbdreq->req_data))
+			xbd_unmap_align(xbdreq);
+		xbdreq->req_bp = xbdreq->req_data = NULL;
+
+		/* b_resid was set in dk_start, only override on error */
 		if (rep->status != BLKIF_RSP_OKAY) {
 			bp->b_error = EIO;
 			bp->b_resid = bp->b_bcount;
-			goto next;
 		}
-		/* b_resid was set in dk_start */
-		if (__predict_false(
-		xbdreq->req_data != NULL && bp->b_data != xbdreq->req_data))
-			xbd_unmap_align(xbdreq);
-next:
-		xbdreq->req_bp = NULL;
+
 		dk_done(>sc_dksc, bp);
 
 		SLIST_INSERT_HEAD(>sc_xbdreq_head, xbdreq, req_next);
 	}
-done:
+
 	xen_rmb();
 	sc->sc_ring.rsp_cons = i;
 
@@ -937,9 +951,8 @@ xbd_diskstart(device_t self, struct buf 
 	struct 

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

2020-04-12 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Apr 12 18:14:09 UTC 2020

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

Log Message:
add KASSERT() for unaligned case to make sure it indeed happens only
for requests via physio


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 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.103 src/sys/arch/xen/xen/xbd_xenbus.c:1.104
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.103	Sat Apr 11 17:52:01 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Sun Apr 12 18:14:09 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.103 2020/04/11 17:52:01 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.104 2020/04/12 18:14:09 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.103 2020/04/11 17:52:01 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.104 2020/04/12 18:14:09 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -985,6 +985,9 @@ xbd_diskstart(device_t self, struct buf 
 	xbdreq->req_bp = bp;
 	xbdreq->req_data = bp->b_data;
 	if (__predict_false((vaddr_t)bp->b_data & (XEN_BSIZE - 1))) {
+		/* Only can get here if this is physio() request */
+		KASSERT(bp->b_saveaddr != NULL);
+
 		sc->sc_cnt_map_unalign.ev_count++;
 
 		if (__predict_false(xbd_map_align(xbdreq) != 0)) {



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

2020-04-12 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Apr 12 13:57:07 UTC 2020

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

Log Message:
move IFNET_UNLOCK() immediatelly after xennet_stop() call in detach,
doesn't need to be held for the disestablish


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 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.113 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.114
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.113	Sun Apr 12 13:55:06 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Sun Apr 12 13:57:07 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.113 2020/04/12 13:55:06 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.114 2020/04/12 13:57:07 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.113 2020/04/12 13:55:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.114 2020/04/12 13:57:07 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -413,11 +413,11 @@ xennet_xenbus_detach(device_t self, int 
 	/* stop interface */
 	IFNET_LOCK(ifp);
 	xennet_stop(ifp, 1);
+	IFNET_UNLOCK(ifp);
 	if (sc->sc_ih != NULL) {
 		xen_intr_disestablish(sc->sc_ih);
 		sc->sc_ih = NULL;
 	}
-	IFNET_UNLOCK(ifp);
 
 	/* collect any outstanding TX responses */
 	mutex_enter(>sc_tx_lock);



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

2020-04-12 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Apr 12 13:55:06 UTC 2020

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

Log Message:
fix locking against myself panic in xennet_stop() on 'ifconfig xennet0 down'

xennet_stop() is called with IFNET already held


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 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.112 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.113
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.112	Sat Apr 11 11:01:12 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Sun Apr 12 13:55:06 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.112 2020/04/11 11:01:12 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.113 2020/04/12 13:55:06 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.112 2020/04/11 11:01:12 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.113 2020/04/12 13:55:06 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -411,11 +411,13 @@ xennet_xenbus_detach(device_t self, int 
 	DPRINTF(("%s: xennet_xenbus_detach\n", device_xname(self)));
 
 	/* stop interface */
+	IFNET_LOCK(ifp);
 	xennet_stop(ifp, 1);
 	if (sc->sc_ih != NULL) {
 		xen_intr_disestablish(sc->sc_ih);
 		sc->sc_ih = NULL;
 	}
+	IFNET_UNLOCK(ifp);
 
 	/* collect any outstanding TX responses */
 	mutex_enter(>sc_tx_lock);
@@ -1146,9 +1148,9 @@ xennet_stop(struct ifnet *ifp, int disab
 {
 	struct xennet_xenbus_softc *sc = ifp->if_softc;
 
-	IFNET_LOCK(ifp);
+	KASSERT(IFNET_LOCKED(ifp));
+
 	ifp->if_flags &= ~IFF_RUNNING;
-	IFNET_UNLOCK(ifp);
 	hypervisor_mask_event(sc->sc_evtchn);
 }
 



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

2020-04-11 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Apr 11 17:52:01 UTC 2020

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

Log Message:
revert previous - physio arranges for tranfer directly to user-provided
buffers, which are generally not DEV_BSIZE-aligned


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 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.102 src/sys/arch/xen/xen/xbd_xenbus.c:1.103
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.102	Sat Apr 11 16:15:34 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Sat Apr 11 17:52:01 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.102 2020/04/11 16:15:34 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.103 2020/04/11 17:52:01 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.102 2020/04/11 16:15:34 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.103 2020/04/11 17:52:01 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -97,8 +97,6 @@ __KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c
 #define XEN_BSHIFT  9   /* log2(XEN_BSIZE) */
 #define XEN_BSIZE   (1 << XEN_BSHIFT) 
 
-__CTASSERT((DEV_BSIZE == XEN_BSIZE));
-
 struct xbd_req {
 	SLIST_ENTRY(xbd_req) req_next;
 	uint16_t req_id; /* ID passed to backend */
@@ -107,6 +105,7 @@ struct xbd_req {
 		grant_ref_t req_gntref[BLKIF_MAX_SEGMENTS_PER_REQUEST];
 		int req_nr_segments; /* number of segments in this request */
 		struct buf *req_bp; /* buffer associated with this request */
+		void *req_data; /* pointer to the data buffer */
 	} req_rw;
 	struct {
 		int s_error;
@@ -117,6 +116,7 @@ struct xbd_req {
 #define req_gntref	u.req_rw.req_gntref
 #define req_nr_segments	u.req_rw.req_nr_segments
 #define req_bp		u.req_rw.req_bp
+#define req_data	u.req_rw.req_data
 #define req_sync	u.req_sync
 
 struct xbd_xenbus_softc {
@@ -156,6 +156,7 @@ struct xbd_xenbus_softc {
 #define BLKIF_FEATURE_PERSISTENT	0x4
 #define BLKIF_FEATURE_BITS		\
 	"\20\1CACHE-FLUSH\2BARRIER\3PERSISTENT"
+	struct evcnt sc_cnt_map_unalign;
 };
 
 #if 0
@@ -176,6 +177,9 @@ static int  xbd_diskstart(device_t, stru
 static void xbd_backend_changed(void *, XenbusState);
 static void xbd_connect(struct xbd_xenbus_softc *);
 
+static int  xbd_map_align(struct xbd_req *);
+static void xbd_unmap_align(struct xbd_req *);
+
 static void xbdminphys(struct buf *);
 
 CFATTACH_DECL3_NEW(xbd, sizeof(struct xbd_xenbus_softc),
@@ -281,6 +285,9 @@ xbd_xenbus_attach(device_t parent, devic
 		panic("%s: can't alloc ring", device_xname(self));
 	sc->sc_ring.sring = ring;
 
+	evcnt_attach_dynamic(>sc_cnt_map_unalign, EVCNT_TYPE_MISC,
+	NULL, device_xname(self), "map unaligned");
+
 	/* resume shared structures and tell backend that we are ready */
 	if (xbd_xenbus_resume(self, PMF_Q_NONE) == false) {
 		uvm_km_free(kernel_map, (vaddr_t)ring, PAGE_SIZE,
@@ -364,6 +371,8 @@ xbd_xenbus_detach(device_t dev, int flag
 	uvm_km_free(kernel_map, (vaddr_t)sc->sc_ring.sring,
 	PAGE_SIZE, UVM_KMF_WIRED);
 
+	evcnt_detach(>sc_cnt_map_unalign);
+
 	pmf_device_deregister(dev);
 
 	return 0;
@@ -702,6 +711,9 @@ again:
 			goto next;
 		}
 		/* b_resid was set in dk_start */
+		if (__predict_false(
+		xbdreq->req_data != NULL && bp->b_data != xbdreq->req_data))
+			xbd_unmap_align(xbdreq);
 next:
 		xbdreq->req_bp = NULL;
 		dk_done(>sc_dksc, bp);
@@ -971,13 +983,16 @@ xbd_diskstart(device_t self, struct buf 
 	}
 
 	xbdreq->req_bp = bp;
-
-	/*
-	 * All bufs passed by system are aligned to DEV_BSIZE.
-	 * xbd requires this to be the case, as transfer offsets
-	 * are expressed in multiplies of 512 (XEN_BSIZE).
-	 */
-	KASSERT(((vaddr_t)bp->b_data & (XEN_BSIZE - 1)) == 0);
+	xbdreq->req_data = bp->b_data;
+	if (__predict_false((vaddr_t)bp->b_data & (XEN_BSIZE - 1))) {
+		sc->sc_cnt_map_unalign.ev_count++;
+
+		if (__predict_false(xbd_map_align(xbdreq) != 0)) {
+			DPRINTF(("xbd_diskstart: no align\n"));
+			error = EAGAIN;
+			goto out;
+		}
+	}
 
 	SLIST_REMOVE_HEAD(>sc_xbdreq_head, req_next);
 	req = RING_GET_REQUEST(>sc_ring, sc->sc_ring.req_prod_pvt);
@@ -987,8 +1002,8 @@ xbd_diskstart(device_t self, struct buf 
 	req->sector_number = bp->b_rawblkno;
 	req->handle = sc->sc_handle;
 
-	va = (vaddr_t)bp->b_data & ~PAGE_MASK;
-	off = (vaddr_t)bp->b_data & PAGE_MASK;
+	va = (vaddr_t)xbdreq->req_data & ~PAGE_MASK;
+	off = (vaddr_t)xbdreq->req_data & PAGE_MASK;
 	bcount = bp->b_bcount;
 	bp->b_resid = 0;
 	for (seg = 0; bcount > 0;) {
@@ -1028,3 +1043,33 @@ out:
 err:
 	return error;
 }
+
+static int
+xbd_map_align(struct xbd_req *req)
+{
+	int s = splvm(); /* XXXSMP - bogus? */
+	int rc;
+
+	rc = uvm_km_kmem_alloc(kmem_va_arena,
+	req->req_bp->b_bcount, (VM_NOSLEEP | VM_INSTANTFIT),
+	

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

2020-04-11 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Apr 11 16:15:34 UTC 2020

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

Log Message:
now that getebuf() et.al. always returns DEV_BSIZE-aligned buffers
and rest of kernel code doing disk I/O was also converted over to it,
it's finally safe to remove the code to handle misaligned buffers

leave just KASSERT() in place


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 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.101 src/sys/arch/xen/xen/xbd_xenbus.c:1.102
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.101	Sat Apr 11 16:02:41 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Sat Apr 11 16:15:34 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.101 2020/04/11 16:02:41 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.102 2020/04/11 16:15:34 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.101 2020/04/11 16:02:41 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.102 2020/04/11 16:15:34 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -97,6 +97,8 @@ __KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c
 #define XEN_BSHIFT  9   /* log2(XEN_BSIZE) */
 #define XEN_BSIZE   (1 << XEN_BSHIFT) 
 
+__CTASSERT((DEV_BSIZE == XEN_BSIZE));
+
 struct xbd_req {
 	SLIST_ENTRY(xbd_req) req_next;
 	uint16_t req_id; /* ID passed to backend */
@@ -105,7 +107,6 @@ struct xbd_req {
 		grant_ref_t req_gntref[BLKIF_MAX_SEGMENTS_PER_REQUEST];
 		int req_nr_segments; /* number of segments in this request */
 		struct buf *req_bp; /* buffer associated with this request */
-		void *req_data; /* pointer to the data buffer */
 	} req_rw;
 	struct {
 		int s_error;
@@ -116,7 +117,6 @@ struct xbd_req {
 #define req_gntref	u.req_rw.req_gntref
 #define req_nr_segments	u.req_rw.req_nr_segments
 #define req_bp		u.req_rw.req_bp
-#define req_data	u.req_rw.req_data
 #define req_sync	u.req_sync
 
 struct xbd_xenbus_softc {
@@ -156,7 +156,6 @@ struct xbd_xenbus_softc {
 #define BLKIF_FEATURE_PERSISTENT	0x4
 #define BLKIF_FEATURE_BITS		\
 	"\20\1CACHE-FLUSH\2BARRIER\3PERSISTENT"
-	struct evcnt sc_cnt_map_unalign;
 };
 
 #if 0
@@ -177,9 +176,6 @@ static int  xbd_diskstart(device_t, stru
 static void xbd_backend_changed(void *, XenbusState);
 static void xbd_connect(struct xbd_xenbus_softc *);
 
-static int  xbd_map_align(struct xbd_req *);
-static void xbd_unmap_align(struct xbd_req *);
-
 static void xbdminphys(struct buf *);
 
 CFATTACH_DECL3_NEW(xbd, sizeof(struct xbd_xenbus_softc),
@@ -285,9 +281,6 @@ xbd_xenbus_attach(device_t parent, devic
 		panic("%s: can't alloc ring", device_xname(self));
 	sc->sc_ring.sring = ring;
 
-	evcnt_attach_dynamic(>sc_cnt_map_unalign, EVCNT_TYPE_MISC,
-	NULL, device_xname(self), "map unaligned");
-
 	/* resume shared structures and tell backend that we are ready */
 	if (xbd_xenbus_resume(self, PMF_Q_NONE) == false) {
 		uvm_km_free(kernel_map, (vaddr_t)ring, PAGE_SIZE,
@@ -371,8 +364,6 @@ xbd_xenbus_detach(device_t dev, int flag
 	uvm_km_free(kernel_map, (vaddr_t)sc->sc_ring.sring,
 	PAGE_SIZE, UVM_KMF_WIRED);
 
-	evcnt_detach(>sc_cnt_map_unalign);
-
 	pmf_device_deregister(dev);
 
 	return 0;
@@ -711,9 +702,6 @@ again:
 			goto next;
 		}
 		/* b_resid was set in dk_start */
-		if (__predict_false(
-		xbdreq->req_data != NULL && bp->b_data != xbdreq->req_data))
-			xbd_unmap_align(xbdreq);
 next:
 		xbdreq->req_bp = NULL;
 		dk_done(>sc_dksc, bp);
@@ -983,16 +971,13 @@ xbd_diskstart(device_t self, struct buf 
 	}
 
 	xbdreq->req_bp = bp;
-	xbdreq->req_data = bp->b_data;
-	if (__predict_false((vaddr_t)bp->b_data & (XEN_BSIZE - 1))) {
-		sc->sc_cnt_map_unalign.ev_count++;
-
-		if (__predict_false(xbd_map_align(xbdreq) != 0)) {
-			DPRINTF(("xbd_diskstart: no align\n"));
-			error = EAGAIN;
-			goto out;
-		}
-	}
+
+	/*
+	 * All bufs passed by system are aligned to DEV_BSIZE.
+	 * xbd requires this to be the case, as transfer offsets
+	 * are expressed in multiplies of 512 (XEN_BSIZE).
+	 */
+	KASSERT(((vaddr_t)bp->b_data & (XEN_BSIZE - 1)) == 0);
 
 	SLIST_REMOVE_HEAD(>sc_xbdreq_head, req_next);
 	req = RING_GET_REQUEST(>sc_ring, sc->sc_ring.req_prod_pvt);
@@ -1002,8 +987,8 @@ xbd_diskstart(device_t self, struct buf 
 	req->sector_number = bp->b_rawblkno;
 	req->handle = sc->sc_handle;
 
-	va = (vaddr_t)xbdreq->req_data & ~PAGE_MASK;
-	off = (vaddr_t)xbdreq->req_data & PAGE_MASK;
+	va = (vaddr_t)bp->b_data & ~PAGE_MASK;
+	off = (vaddr_t)bp->b_data & PAGE_MASK;
 	bcount = bp->b_bcount;
 	bp->b_resid = 0;
 	for (seg = 0; bcount > 0;) {
@@ -1043,33 +1028,3 @@ out:
 err:
 	return error;
 }
-
-static int
-xbd_map_align(struct xbd_req *req)
-{
-	int s = splvm(); /* XXXSMP - bogus? */
-	int 

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

2020-04-11 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Apr 11 16:02:41 UTC 2020

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

Log Message:
print 'backend features' instead of just 'features' for the detected backend
features, so that it's clear it's just capability rather than something
actually used by the frontend driver


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 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.100 src/sys/arch/xen/xen/xbd_xenbus.c:1.101
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.100	Fri Apr 10 11:41:04 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Sat Apr 11 16:02:41 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.100 2020/04/10 11:41:04 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.101 2020/04/11 16:02:41 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.100 2020/04/10 11:41:04 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.101 2020/04/11 16:02:41 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -576,7 +576,8 @@ xbd_backend_changed(void *arg, XenbusSta
 buf, (int)dg->dg_secsize, sc->sc_xbdsize);
 		snprintb(buf, sizeof(buf), BLKIF_FEATURE_BITS,
 		sc->sc_features);
-		aprint_normal_dev(sc->sc_dksc.sc_dev, "features %s\n", buf);
+		aprint_normal_dev(sc->sc_dksc.sc_dev,
+		"backend features %s\n", buf);
 
 		/* Discover wedges on this disk. */
 		dkwedge_discover(>sc_dksc.sc_dkdev);



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

2020-04-11 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Apr 11 11:48:21 UTC 2020

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

Log Message:
convert to bus_dma(9), no explicit xpmap_*() calls any more

as part of this move some global arrays into struct xnetback_instance,
and fix race for xnetif_lookup()


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 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.95 src/sys/arch/xen/xen/xennetback_xenbus.c:1.96
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.95	Thu Apr  9 10:57:02 2020
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Sat Apr 11 11:48:20 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.95 2020/04/09 10:57:02 jdolecek Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.96 2020/04/11 11:48:20 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.95 2020/04/09 10:57:02 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.96 2020/04/11 11:48:20 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -70,13 +70,14 @@ __KERNEL_RCSID(0, "$NetBSD: xennetback_x
 #define XENPRINTF(x)
 #endif
 
-extern pt_entry_t xpmap_pg_nx;
-
 #define NET_TX_RING_SIZE __RING_SIZE((netif_tx_sring_t *)0, PAGE_SIZE)
 #define NET_RX_RING_SIZE __RING_SIZE((netif_rx_sring_t *)0, PAGE_SIZE)
 
-/* linux wants at last 16 bytes free in front of the packet */
-#define LINUX_REQUESTED_OFFSET 16
+/*
+ * Number of packets to transmit in one hypercall (= number of pages to
+ * transmit at once).
+ */
+#define NB_XMIT_PAGES_BATCH 64
 
 /* ratecheck(9) for pool allocation failures */
 static const struct timeval xni_pool_errintvl = { 30, 0 };  /* 30s, each */
@@ -88,6 +89,13 @@ typedef enum {
 	DISCONNECTED
 } xnetback_state_t;
 
+struct xnetback_xstate {
+	bus_dmamap_t xs_dmamap;
+	struct mbuf *xs_m;
+	int xs_id;
+	int xs_flags;
+};
+
 /* we keep the xnetback instances in a linked list */
 struct xnetback_instance {
 	SLIST_ENTRY(xnetback_instance) next;
@@ -110,6 +118,10 @@ struct xnetback_instance {
 	grant_handle_t xni_rx_ring_handle;
 	vaddr_t xni_tx_ring_va; /* to unmap the ring */
 	vaddr_t xni_rx_ring_va;
+
+	/* arrays used in xennetback_ifstart(), used for both Rx and Tx */
+	gnttab_copy_t 	xni_gop_copy[NB_XMIT_PAGES_BATCH];
+	struct xnetback_xstate	xni_xstate[NB_XMIT_PAGES_BATCH];
 };
 #define xni_ifxni_ec.ec_if
 #define xni_bpf   xni_if.if_bpf
@@ -128,7 +140,6 @@ static void xennetback_frontend_changed(
 
 static inline void xennetback_tx_response(struct xnetback_instance *,
 int, int);
-static void xennetback_mbuf_addr(struct mbuf *, paddr_t *, int *);
 
 static SLIST_HEAD(, xnetback_instance) xnetback_instances;
 static kmutex_t xnetback_lock;
@@ -141,22 +152,6 @@ static struct xenbus_backend_driver xvif
 	.xbakd_type = "vif"
 };
 
-/*
- * Number of packets to transmit in one hypercall (= number of pages to
- * transmit at once).
- */
-#define NB_XMIT_PAGES_BATCH 64
-
-/* arrays used in xennetback_ifstart(), too large to allocate on stack */
-/* XXXSMP */
-static gnttab_copy_t xstart_gop_copy[NB_XMIT_PAGES_BATCH];
-static struct mbuf *mbufs_sent[NB_XMIT_PAGES_BATCH];
-static struct _req_info {
-	int id;
-	int flags;
-} xstart_req[NB_XMIT_PAGES_BATCH];
-
-
 void
 xvifattach(int n)
 {
@@ -193,14 +188,21 @@ xennetback_xenbus_create(struct xenbus_d
 		return err;
 	}
 
-	if (xnetif_lookup(domid, handle)) {
-		return EEXIST;
-	}
 	xneti = kmem_zalloc(sizeof(*xneti), KM_SLEEP);
 	xneti->xni_domid = domid;
 	xneti->xni_handle = handle;
 	xneti->xni_status = DISCONNECTED;
 
+	/* Need to keep the lock for lookup and the list update */
+	mutex_enter(_lock);
+	if (xnetif_lookup(domid, handle)) {
+		mutex_exit(_lock);
+		kmem_free(xneti, sizeof(*xneti));
+		return EEXIST;
+	}
+	SLIST_INSERT_HEAD(_instances, xneti, next);
+	mutex_exit(_lock);
+
 	xbusd->xbusd_u.b.b_cookie = xneti;
 	xbusd->xbusd_u.b.b_detach = xennetback_xenbus_destroy;
 	xneti->xni_xbusd = xbusd;
@@ -230,6 +232,20 @@ xennetback_xenbus_create(struct xenbus_d
 
 	/* we can't use the same MAC addr as our guest */
 	xneti->xni_enaddr[3]++;
+
+	/* 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,
+		>xni_xstate[i].xs_dmamap)
+		!= 0) {
+			aprint_error_ifnet(ifp,
+			"failed to allocate dma map\n");
+			err = ENOMEM;
+			goto fail;
+		}
+	}
+
 	/* create pseudo-interface */
 	aprint_verbose_ifnet(ifp, "Ethernet address %s\n",
 	ether_sprintf(xneti->xni_enaddr));
@@ -258,10 +274,6 @@ xennetback_xenbus_create(struct xenbus_d
 	

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

2020-04-10 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Apr 10 21:03:21 UTC 2020

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

Log Message:
gnttab_get_status_frames frame_list is array if uint64_t values, not u_long
like gnttab_setup_table, fix to use uint64_t

fixes compilation on i386 with XEN3PAE_DOM[0U], pointed out by kre@


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 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.32 src/sys/arch/xen/xen/xengnt.c:1.33
--- src/sys/arch/xen/xen/xengnt.c:1.32	Fri Apr 10 08:35:52 2020
+++ src/sys/arch/xen/xen/xengnt.c	Fri Apr 10 21:03:20 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xengnt.c,v 1.32 2020/04/10 08:35:52 jdolecek Exp $  */
+/*  $NetBSD: xengnt.c,v 1.33 2020/04/10 21:03:20 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.32 2020/04/10 08:35:52 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.33 2020/04/10 21:03:20 jdolecek Exp $");
 
 #include 
 #include 
@@ -186,7 +186,7 @@ static int
 xengnt_map_status(void)
 {
 	gnttab_get_status_frames_t getstatus;
-	u_long *pages;
+	uint64_t *pages;
 	size_t sz;
 
 	KASSERT(mutex_owned(_lock));



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

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

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

Log Message:
use ETHER_ADDR_LEN on one more place


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 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.110 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.111
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.110	Fri Apr 10 18:03:06 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Fri Apr 10 19:08:10 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.110 2020/04/10 18:03:06 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.111 2020/04/10 19:08:10 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.110 2020/04/10 18:03:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.111 2020/04/10 19:08:10 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -167,7 +167,7 @@ struct xennet_rxreq {
 struct xennet_xenbus_softc {
 	device_t sc_dev;
 	struct ethercom sc_ethercom;
-	uint8_t sc_enaddr[6];
+	uint8_t sc_enaddr[ETHER_ADDR_LEN];
 	struct xenbus_device *sc_xbusd;
 	bus_dma_tag_t sc_dmat;
 



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

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

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

Log Message:
convert to bus_dma(9), remove now not necessary XENPVHVM redefines


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 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.109 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.110
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.109	Tue Apr  7 11:47:06 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Fri Apr 10 18:03:06 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.109 2020/04/07 11:47:06 jdolecek Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.110 2020/04/10 18:03:06 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.109 2020/04/07 11:47:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.110 2020/04/10 18:03:06 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -143,21 +143,6 @@ int xennet_debug = 0xff;
 #define DPRINTFN(n,x)
 #endif
 
-#ifdef XENPVHVM
-/* Glue for p2m table stuff. Should be removed eventually */
-#define xpmap_mtop_masked(mpa) (mpa & ~PAGE_MASK)
-#define xpmap_mtop(mpa) (mpa & ~PTE_4KFRAME)
-#define xpmap_ptom_masked(mpa) (mpa & ~PAGE_MASK)
-#define xpmap_ptom(mpa) (mpa & ~PTE_4KFRAME)
-#define xpmap_ptom_map(ppa, mpa)
-#define xpmap_ptom_unmap(ppa)
-#define xpmap_ptom_isvalid 1 /* XXX: valid PA check */
-#define xpmap_pg_nx pmap_pg_nx /* We use the native setting */
-#define xpq_flush_queue() tlbflush()
-#endif /* XENPVHVM */
-
-extern pt_entry_t xpmap_pg_nx;
-
 #define GRANT_INVALID_REF -1 /* entry is free */
 
 #define NET_TX_RING_SIZE __CONST_RING_SIZE(netif_tx, PAGE_SIZE)
@@ -168,15 +153,15 @@ struct xennet_txreq {
 	uint16_t txreq_id; /* ID passed to backend */
 	grant_ref_t txreq_gntref; /* grant ref of this request */
 	struct mbuf *txreq_m; /* mbuf being transmitted */
+	bus_dmamap_t txreq_dmamap;
 };
 
 struct xennet_rxreq {
 	SLIST_ENTRY(xennet_rxreq) rxreq_next;
 	uint16_t rxreq_id; /* ID passed to backend */
 	grant_ref_t rxreq_gntref; /* grant ref of this request */
-/* va/pa for this receive buf. ma will be provided by backend */
-	paddr_t rxreq_pa;
-	vaddr_t rxreq_va;
+	struct mbuf *rxreq_m;
+	bus_dmamap_t rxreq_dmamap;
 };
 
 struct xennet_xenbus_softc {
@@ -184,6 +169,7 @@ struct xennet_xenbus_softc {
 	struct ethercom sc_ethercom;
 	uint8_t sc_enaddr[6];
 	struct xenbus_device *sc_xbusd;
+	bus_dma_tag_t sc_dmat;
 
 	netif_tx_front_ring_t sc_tx_ring;
 	netif_rx_front_ring_t sc_rx_ring;
@@ -272,17 +258,13 @@ xennet_xenbus_attach(device_t parent, de
 	unsigned long uval;
 	extern int ifqmaxlen; /* XXX */
 	char mac[32];
-#ifdef XENNET_DEBUG
-	char **dir;
-	int dir_n = 0;
-	char id_str[20];
-#endif
 
 	aprint_normal(": Xen Virtual Network Interface\n");
 	sc->sc_dev = self;
 
 	sc->sc_xbusd = xa->xa_xbusd;
 	sc->sc_xbusd->xbusd_otherend_changed = xennet_backend_changed;
+	sc->sc_dmat = xa->xa_dmat;
 
 	/* xenbus ensure 2 devices can't be probed at the same time */
 	if (if_xennetrxbuf_cache_inited == 0) {
@@ -295,7 +277,14 @@ xennet_xenbus_attach(device_t parent, de
 	mutex_init(>sc_tx_lock, MUTEX_DEFAULT, IPL_NET);
 	SLIST_INIT(>sc_txreq_head);
 	for (i = 0; i < NET_TX_RING_SIZE; i++) {
-		sc->sc_txreqs[i].txreq_id = i;
+		struct xennet_txreq *txreq = >sc_txreqs[i];
+	
+		txreq->txreq_id = i;
+		if (bus_dmamap_create(sc->sc_dmat, PAGE_SIZE, 1, PAGE_SIZE,
+		PAGE_SIZE, BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW,
+		>txreq_dmamap) != 0)
+			break;
+
 		SLIST_INSERT_HEAD(>sc_txreq_head, >sc_txreqs[i],
 		txreq_next);
 	}
@@ -305,9 +294,9 @@ xennet_xenbus_attach(device_t parent, de
 	for (i = 0; i < NET_RX_RING_SIZE; i++) {
 		struct xennet_rxreq *rxreq = >sc_rxreqs[i];
 		rxreq->rxreq_id = i;
-		rxreq->rxreq_va = (vaddr_t)pool_cache_get_paddr(
-		if_xennetrxbuf_cache, PR_WAITOK, >rxreq_pa);
-		if (rxreq->rxreq_va == 0)
+		if (bus_dmamap_create(sc->sc_dmat, PAGE_SIZE, 1, PAGE_SIZE,
+		PAGE_SIZE, BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW,
+		>rxreq_dmamap) != 0)
 			break;
 		rxreq->rxreq_gntref = GRANT_INVALID_REF;
 		SLIST_INSERT_HEAD(>sc_rxreq_head, rxreq, rxreq_next);
@@ -443,10 +432,9 @@ xennet_xenbus_detach(device_t self, int 
 	xennet_free_rx_buffer(sc);
 	for (i = 0; i < NET_RX_RING_SIZE; i++) {
 		struct xennet_rxreq *rxreq = >sc_rxreqs[i];
-		if (rxreq->rxreq_va != 0) {
-			pool_cache_put_paddr(if_xennetrxbuf_cache,
-			(void *)rxreq->rxreq_va, rxreq->rxreq_pa);
-			rxreq->rxreq_va = 0;
+		if (rxreq->rxreq_m != NULL) {
+			m_freem(rxreq->rxreq_m);
+			rxreq->rxreq_m = NULL;
 		}
 	}
 	mutex_exit(>sc_rx_lock);
@@ -692,7 +680,6 @@ static void 

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

2020-04-10 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Apr 10 11:41:04 UTC 2020

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

Log Message:
update comment for DIOCGCACHE (no DKCACHE_READ)


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 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.99 src/sys/arch/xen/xen/xbd_xenbus.c:1.100
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.99	Fri Apr 10 10:32:18 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Fri Apr 10 11:41:04 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.99 2020/04/10 10:32:18 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.100 2020/04/10 11:41:04 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.99 2020/04/10 10:32:18 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.100 2020/04/10 11:41:04 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -853,10 +853,7 @@ xbdioctl(dev_t dev, u_long cmd, void *da
 	switch (cmd) {
 	case DIOCGCACHE:
 	{
-		/*
-		 * Assume there is read & write cache if cache-flush is
-		 * supported.
-		 */
+		/* Assume there is write cache if cache-flush is supported */
 		int *bitsp = (int *)data;
 		*bitsp = 0;
 		if (sc->sc_features & BLKIF_FEATURE_CACHE_FLUSH)



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

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

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

Log Message:
allow DIOCSSTRATEGY, there is no particular reason why it should be
restricted for xbd(4)


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 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.98 src/sys/arch/xen/xen/xbd_xenbus.c:1.99
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.98	Fri Apr 10 10:30:10 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Fri Apr 10 10:32:18 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.98 2020/04/10 10:30:10 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.99 2020/04/10 10:32:18 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.98 2020/04/10 10:30:10 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.99 2020/04/10 10:32:18 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -851,9 +851,6 @@ xbdioctl(dev_t dev, u_long cmd, void *da
 	dksc = >sc_dksc;
 
 	switch (cmd) {
-	case DIOCSSTRATEGY:
-		error = EOPNOTSUPP;
-		break;
 	case DIOCGCACHE:
 	{
 		/*



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

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

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

Log Message:
implement DIOCGCACHE - assume if CACHE_FLUSH is supported, write cache
is enabled

convert the sc_cache_flush flag to a feature bit field, and recognize
also barrier and persistent features; print the recognized features
on boot, and remove the warning on DIOCCACHESYNC


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 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.97 src/sys/arch/xen/xen/xbd_xenbus.c:1.98
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.97	Tue Apr  7 11:47:06 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Fri Apr 10 10:30:10 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.97 2020/04/07 11:47:06 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.98 2020/04/10 10:30:10 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.97 2020/04/07 11:47:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.98 2020/04/10 10:30:10 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -150,7 +150,12 @@ struct xbd_xenbus_softc {
 	uint64_t sc_xbdsize; /* size of disk in DEV_BSIZE */
 	u_long sc_info; /* VDISK_* */
 	u_long sc_handle; /* from backend */
-	int sc_cache_flush; /* backend supports BLKIF_OP_FLUSH_DISKCACHE */
+	int sc_features;
+#define BLKIF_FEATURE_CACHE_FLUSH	0x1
+#define BLKIF_FEATURE_BARRIER		0x2
+#define BLKIF_FEATURE_PERSISTENT	0x4
+#define BLKIF_FEATURE_BITS		\
+	"\20\1CACHE-FLUSH\2BARRIER\3PERSISTENT"
 	struct evcnt sc_cnt_map_unalign;
 };
 
@@ -509,7 +514,7 @@ xbd_backend_changed(void *arg, XenbusSta
 	struct xbd_xenbus_softc *sc = device_private((device_t)arg);
 	struct disk_geom *dg;
 
-	char buf[9];
+	char buf[32];
 	int s;
 	DPRINTF(("%s: new backend state %d\n",
 	device_xname(sc->sc_dksc.sc_dev), new_state));
@@ -569,6 +574,9 @@ xbd_backend_changed(void *arg, XenbusSta
 		aprint_normal_dev(sc->sc_dksc.sc_dev,
 "%s, %d bytes/sect x %" PRIu64 " sectors\n",
 buf, (int)dg->dg_secsize, sc->sc_xbdsize);
+		snprintb(buf, sizeof(buf), BLKIF_FEATURE_BITS,
+		sc->sc_features);
+		aprint_normal_dev(sc->sc_dksc.sc_dev, "features %s\n", buf);
 
 		/* Discover wedges on this disk. */
 		dkwedge_discover(>sc_dksc.sc_dkdev);
@@ -588,7 +596,7 @@ xbd_connect(struct xbd_xenbus_softc *sc)
 {
 	int err;
 	unsigned long long sectors;
-	u_long cache_flush;
+	u_long val;
 
 	err = xenbus_read_ul(NULL,
 	sc->sc_xbusd->xbusd_path, "virtual-device", >sc_handle, 10);
@@ -618,13 +626,25 @@ xbd_connect(struct xbd_xenbus_softc *sc)
 		sc->sc_xbusd->xbusd_otherend);
 
 	err = xenbus_read_ul(NULL, sc->sc_xbusd->xbusd_otherend,
-	"feature-flush-cache", _flush, 10);
+	"feature-flush-cache", , 10);
 	if (err)
-		cache_flush = 0;
-	if (cache_flush > 0)
-		sc->sc_cache_flush = 1;
-	else
-		sc->sc_cache_flush = 0;
+		val = 0;
+	if (val > 0)
+		sc->sc_features |= BLKIF_FEATURE_CACHE_FLUSH;
+
+	err = xenbus_read_ul(NULL, sc->sc_xbusd->xbusd_otherend,
+	"feature-barrier", , 10);
+	if (err)
+		val = 0;
+	if (val > 0)
+		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;
 
 	xenbus_switch_state(sc->sc_xbusd, NULL, XenbusStateConnected);
 }
@@ -834,16 +854,22 @@ xbdioctl(dev_t dev, u_long cmd, void *da
 	case DIOCSSTRATEGY:
 		error = EOPNOTSUPP;
 		break;
+	case DIOCGCACHE:
+	{
+		/*
+		 * Assume there is read & write cache if cache-flush is
+		 * supported.
+		 */
+		int *bitsp = (int *)data;
+		*bitsp = 0;
+		if (sc->sc_features & BLKIF_FEATURE_CACHE_FLUSH)
+			*bitsp |= DKCACHE_WRITE;
+		error = 0;
+		break;
+	}
 	case DIOCCACHESYNC:
-		if (sc->sc_cache_flush <= 0) {
-			if (sc->sc_cache_flush == 0) {
-aprint_verbose_dev(sc->sc_dksc.sc_dev,
-"WARNING: cache flush not supported "
-"by backend\n");
-sc->sc_cache_flush = -1;
-			}
+		if ((sc->sc_features & BLKIF_FEATURE_CACHE_FLUSH) == 0)
 			return EOPNOTSUPP;
-		}
 
 		s = splbio(); /* XXXSMP */
 



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

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

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

Log Message:
add KASSERT() for owned grant_lock in xengnt_get_entry()


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 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.31 src/sys/arch/xen/xen/xengnt.c:1.32
--- src/sys/arch/xen/xen/xengnt.c:1.31	Thu Apr  9 19:26:38 2020
+++ src/sys/arch/xen/xen/xengnt.c	Fri Apr 10 08:35:52 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xengnt.c,v 1.31 2020/04/09 19:26:38 jdolecek Exp $  */
+/*  $NetBSD: xengnt.c,v 1.32 2020/04/10 08:35:52 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.31 2020/04/09 19:26:38 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.32 2020/04/10 08:35:52 jdolecek Exp $");
 
 #include 
 #include 
@@ -336,6 +336,8 @@ xengnt_get_entry(void)
 	static struct timeval xengnt_nonmemtime;
 	static const struct timeval xengnt_nonmemintvl = {5,0};
 
+	KASSERT(mutex_owned(_lock));
+
 	if (__predict_false(last_gnt_entry == 0)) {
 		if (ratecheck(_nonmemtime, _nonmemintvl))
 			printf("xengnt_get_entry: out of grant "



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

2020-04-09 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Apr  9 15:54:41 UTC 2020

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

Log Message:
xengnt_more_entries() can be called from interrupt context so use
kmem_intr_alloc()/free() here


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 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.29 src/sys/arch/xen/xen/xengnt.c:1.30
--- src/sys/arch/xen/xen/xengnt.c:1.29	Tue Apr  7 09:05:14 2020
+++ src/sys/arch/xen/xen/xengnt.c	Thu Apr  9 15:54:41 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xengnt.c,v 1.29 2020/04/07 09:05:14 jdolecek Exp $  */
+/*  $NetBSD: xengnt.c,v 1.30 2020/04/09 15:54:41 bouyer Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.29 2020/04/07 09:05:14 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.30 2020/04/09 15:54:41 bouyer Exp $");
 
 #include 
 #include 
@@ -170,7 +170,7 @@ xengnt_more_entries(void)
 		return ENOMEM;
 
 	sz = nframes_new * sizeof(u_long);
-	pages = kmem_alloc(sz, KM_NOSLEEP);
+	pages = kmem_intr_alloc(sz, KM_NOSLEEP);
 	if (pages == NULL)
 		return ENOMEM;
 
@@ -209,7 +209,7 @@ xengnt_more_entries(void)
 		if (setup.status != GNTST_okay) {
 			aprint_error("%s: setup table returned %d\n",
 			__func__, setup.status);
-			kmem_free(pages, sz);
+			kmem_intr_free(pages, sz);
 			return ENOMEM;
 		}
 	}
@@ -244,7 +244,7 @@ xengnt_more_entries(void)
 		last_gnt_entry++;
 	}
 	gnt_nr_grant_frames = nframes_new;
-	kmem_free(pages, sz);
+	kmem_intr_free(pages, sz);
 	return 0;
 }
 



  1   2   3   4   >