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

2024-01-09 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Jan  9 18:39:53 UTC 2024

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

Log Message:
disable TX checksum optimization, it's causing ARP lossage in some
configurations using Linux dom0

PR port-xen/57743 by Brian Marcotte, thanks for the patch


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 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.129 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.130
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.129	Sat Feb 25 00:32:49 2023
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Tue Jan  9 18:39:53 2024
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.129 2023/02/25 00:32:49 riastradh Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.130 2024/01/09 18:39:53 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.129 2023/02/25 00:32:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.130 2024/01/09 18:39:53 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -1122,7 +1122,13 @@ xennet_submit_tx_request(struct xennet_x
 			if (m->m_pkthdr.csum_flags & XN_M_CSUM_SUPPORTED) {
 txreq->flags |= NETTXF_csum_blank;
 			} else {
+#if 0
+/*
+ * XXX Checksum optimization disabled 
+ * to avoid port-xen/57743.
+ */
 txreq->flags |= NETTXF_data_validated;
+#endif
 			}
 		}
 		if (multiseg && i < lastseg)



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

2024-01-09 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Jan  9 18:39:53 UTC 2024

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

Log Message:
disable TX checksum optimization, it's causing ARP lossage in some
configurations using Linux dom0

PR port-xen/57743 by Brian Marcotte, thanks for the patch


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 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.



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

2023-12-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Dec 30 21:46:52 UTC 2023

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

Log Message:
xennetback_xenbus.c: Nix trailing whitespace again.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 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.124 src/sys/arch/xen/xen/xennetback_xenbus.c:1.125
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.124	Fri Dec 22 10:22:00 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Sat Dec 30 21:46:52 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.124 2023/12/22 10:22:00 bouyer Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.125 2023/12/30 21:46:52 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.124 2023/12/22 10:22:00 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.125 2023/12/30 21:46:52 riastradh Exp $");
 
 #include 
 #include 
@@ -794,7 +794,7 @@ xennetback_tx_m0len_fragment(struct xnet
 			return -1;
 		if (RING_REQUEST_CONS_OVERFLOW(>xni_txring, req_cons))
 			return -1;
-			
+
 		m0_len -= txreq->size;
 		req_cons++;
 		(*cntp)++;



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

2023-12-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Dec 30 21:46:52 UTC 2023

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

Log Message:
xennetback_xenbus.c: Nix trailing whitespace again.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 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.



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

2023-12-22 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Dec 22 10:22:00 UTC 2023

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

Log Message:
sanity check the fragments we get from the guest and reject the whole packet
if it fails. Make sure we don't KASSERT() on data we get from the frontend.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 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.123 src/sys/arch/xen/xen/xennetback_xenbus.c:1.124
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.123	Wed Aug  9 08:38:57 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Fri Dec 22 10:22:00 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.123 2023/08/09 08:38:57 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.124 2023/12/22 10:22:00 bouyer Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.123 2023/08/09 08:38:57 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.124 2023/12/22 10:22:00 bouyer Exp $");
 
 #include 
 #include 
@@ -613,7 +613,7 @@ xennetback_tx_response(struct xnetback_i
 }
 
 static const char *
-xennetback_tx_check_packet(const netif_tx_request_t *txreq)
+xennetback_tx_check_packet(const netif_tx_request_t *txreq, bool first)
 {
 	if (__predict_false((txreq->flags & NETTXF_more_data) == 0 &&
 	txreq->offset + txreq->size > PAGE_SIZE))
@@ -622,6 +622,10 @@ xennetback_tx_check_packet(const netif_t
 	if (__predict_false(txreq->size > ETHER_MAX_LEN_JUMBO))
 		return "bigger then jumbo";
 
+	if (first &&
+	__predict_false(txreq->size < ETHER_HDR_LEN))
+		return "too short";
+
 	return NULL;
 }
 
@@ -786,7 +790,11 @@ xennetback_tx_m0len_fragment(struct xnet
 	*cntp = 1;
 	do {
 		txreq = RING_GET_REQUEST(>xni_txring, req_cons);
-		KASSERT(m0_len > txreq->size);
+		if (m0_len <= txreq->size || *cntp > XEN_NETIF_NR_SLOTS_MIN)
+			return -1;
+		if (RING_REQUEST_CONS_OVERFLOW(>xni_txring, req_cons))
+			return -1;
+			
 		m0_len -= txreq->size;
 		req_cons++;
 		(*cntp)++;
@@ -805,8 +813,9 @@ xennetback_evthandler(void *arg)
 	int receive_pending;
 	int queued = 0, m0_len = 0;
 	struct xnetback_xstate *xst;
-	const bool discard = ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) !=
+	const bool nupnrun = ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) !=
 	(IFF_UP | IFF_RUNNING));
+	bool discard = 0;
 
 	XENPRINTF(("xennetback_evthandler "));
 again:
@@ -824,9 +833,10 @@ again:
 		XENPRINTF(("%s pkt size %d\n", xneti->xni_if.if_xname,
 		txreq.size));
 		xneti->xni_txring.req_cons++;
-		if (__predict_false(discard)) {
+		if (__predict_false(nupnrun || discard)) {
 			/* interface not up, drop all requests */
 			if_statinc(ifp, if_iqdrops);
+			discard = (txreq.flags & NETTXF_more_data) != 0;
 			xennetback_tx_response(xneti, txreq.id,
 			NETIF_RSP_DROPPED);
 			continue;
@@ -835,10 +845,12 @@ again:
 		/*
 		 * Do some sanity checks, and queue copy of the data.
 		 */
-		const char *msg = xennetback_tx_check_packet();
+		const char *msg = xennetback_tx_check_packet(,
+		m0 == NULL);
 		if (__predict_false(msg != NULL)) {
 			printf("%s: packet with size %d is %s\n",
 			ifp->if_xname, txreq.size, msg);
+			discard = (txreq.flags & NETTXF_more_data) != 0;
 			xennetback_tx_response(xneti, txreq.id,
 			NETIF_RSP_ERROR);
 			if_statinc(ifp, if_ierrors);
@@ -856,6 +868,7 @@ mbuf_fail:
 			xennetback_tx_copy_abort(ifp, xneti, queued);
 			queued = 0;
 			m0 = NULL;
+			discard = (txreq.flags & NETTXF_more_data) != 0;
 			xennetback_tx_response(xneti, txreq.id,
 			NETIF_RSP_DROPPED);
 			if_statinc(ifp, if_ierrors);
@@ -873,6 +886,14 @@ mbuf_fail:
 			int cnt;
 			m0_len = xennetback_tx_m0len_fragment(xneti,
 			txreq.size, xneti->xni_txring.req_cons, );
+			if (m0_len < 0) {
+m_freem(m);
+discard = 1;
+xennetback_tx_response(xneti, txreq.id,
+NETIF_RSP_DROPPED);
+if_statinc(ifp, if_ierrors);
+continue;
+			}
 			m->m_len = m0_len;
 			KASSERT(cnt <= XEN_NETIF_NR_SLOTS_MIN);
 
@@ -881,7 +902,6 @@ 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

2023-12-22 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Dec 22 10:22:00 UTC 2023

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

Log Message:
sanity check the fragments we get from the guest and reject the whole packet
if it fails. Make sure we don't KASSERT() on data we get from the frontend.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 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.



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

2023-10-17 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Oct 17 16:09:12 UTC 2023

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

Log Message:
for a dom0 PVH, the dom0_vga_console_info structure has to be retrieved
using a platform hypercall; do so in the XENPVHVM case.
Now genfb works in a PVH dom0 running on Xen 4.18 (Xen 4.15 doesn't support
this platoform op, so no way to make it work here).


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

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



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

2023-10-17 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Oct 17 16:09:12 UTC 2023

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

Log Message:
for a dom0 PVH, the dom0_vga_console_info structure has to be retrieved
using a platform hypercall; do so in the XENPVHVM case.
Now genfb works in a PVH dom0 running on Xen 4.18 (Xen 4.15 doesn't support
this platoform op, so no way to make it work here).


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

Please note 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/genfb_xen.c
diff -u src/sys/arch/xen/xen/genfb_xen.c:1.1 src/sys/arch/xen/xen/genfb_xen.c:1.2
--- src/sys/arch/xen/xen/genfb_xen.c:1.1	Tue Oct 17 12:07:42 2023
+++ src/sys/arch/xen/xen/genfb_xen.c	Tue Oct 17 16:09:12 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: genfb_xen.c,v 1.1 2023/10/17 12:07:42 bouyer Exp $  */
+/*  $NetBSD: genfb_xen.c,v 1.2 2023/10/17 16:09:12 bouyer Exp $  */
 
 /*
  * Copyright (c) 2023 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb_xen.c,v 1.1 2023/10/17 12:07:42 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb_xen.c,v 1.2 2023/10/17 16:09:12 bouyer Exp $");
 
 
 #include 
@@ -42,6 +42,7 @@ const struct btinfo_framebuffer *
 xen_genfb_getbtinfo(void)
 {
 	dom0_vga_console_info_t *d0_consi;
+	int info_size;
 
 	if (!xendomain_is_dom0())
 		return NULL;
@@ -49,8 +50,21 @@ xen_genfb_getbtinfo(void)
 	if (_xen_genfb_btinfo.common.type == BTINFO_FRAMEBUFFER)
 		return &_xen_genfb_btinfo;
 
+#ifdef XENPVHVM
+	struct xen_platform_op op = {
+		.cmd = XENPF_get_dom0_console,
+	};
+	info_size = HYPERVISOR_platform_op();
+	if (info_size < sizeof(dom0_vga_console_info_t)) {
+		printf("XENPF_get_dom0_console fail %d\n", info_size);
+		return NULL;
+	}
+	d0_consi = _console;
+#else
 	d0_consi = (void *)((char *)_start_info +
 	xen_start_info.console.dom0.info_off);
+	info_size = xen_start_info.console.dom0.info_size;
+#endif
 
 	if (d0_consi->video_type != XEN_VGATYPE_VESA_LFB &&
 	d0_consi->video_type != XEN_VGATYPE_EFI_LFB)
@@ -59,7 +73,7 @@ xen_genfb_getbtinfo(void)
 	_xen_genfb_btinfo.common.type = BTINFO_FRAMEBUFFER;
 	_xen_genfb_btinfo.common.len = sizeof(struct btinfo_framebuffer);
 	_xen_genfb_btinfo.physaddr = d0_consi->u.vesa_lfb.lfb_base;
-	if (xen_start_info.console.dom0.info_size >=
+	if (info_size >=
 	offsetof(dom0_vga_console_info_t, u.vesa_lfb.ext_lfb_base)) {
 		_xen_genfb_btinfo.physaddr |=
 		(uint64_t)d0_consi->u.vesa_lfb.ext_lfb_base << 32;



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

2023-10-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 17 10:24:11 UTC 2023

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

Log Message:
xen_machdep.c: Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 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.28 src/sys/arch/xen/xen/xen_machdep.c:1.29
--- src/sys/arch/xen/xen/xen_machdep.c:1.28	Mon Oct 16 17:31:18 2023
+++ src/sys/arch/xen/xen/xen_machdep.c	Tue Oct 17 10:24:11 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_machdep.c,v 1.28 2023/10/16 17:31:18 bouyer Exp $	*/
+/*	$NetBSD: xen_machdep.c,v 1.29 2023/10/17 10:24:11 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.28 2023/10/16 17:31:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.29 2023/10/17 10:24:11 riastradh Exp $");
 
 #include "opt_xen.h"
 
@@ -466,7 +466,7 @@ early_xenconscn_getc(dev_t dev)
 	return -1;
 }
 
-static void 
+static void
 early_xenconscn_putc(dev_t dev, int c)
 {
 	printk("%c", c);



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

2023-10-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 17 10:24:11 UTC 2023

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

Log Message:
xen_machdep.c: Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 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.



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

2023-09-10 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sun Sep 10 15:23:01 UTC 2023

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

Log Message:
If Xen system time went backward, instead of ignoring the event assume
one tick passed and reinitialise the local state.
If we need to call the hardclock timer several time to catch up missed events,
don't do more than one second in a single event; and schedule the next
event faster.

Hopefully fixes occasionnal
panic: cpu1: time has not advanced in 1501 heartbeats
or
panic: cpu0: softints stuck for 16 seconds
seen in daily Xen atf runs.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 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.17 src/sys/arch/xen/xen/xen_clock.c:1.18
--- src/sys/arch/xen/xen/xen_clock.c:1.17	Tue Aug  1 20:11:13 2023
+++ src/sys/arch/xen/xen/xen_clock.c	Sun Sep 10 15:23:01 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_clock.c,v 1.17 2023/08/01 20:11:13 riastradh Exp $	*/
+/*	$NetBSD: xen_clock.c,v 1.18 2023/09/10 15:23:01 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.17 2023/08/01 20:11:13 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.18 2023/09/10 15:23:01 bouyer Exp $");
 
 #include 
 #include 
@@ -800,7 +800,6 @@ xen_timer_handler(void *cookie, struct c
 #if defined(XENPV)
 	frame = NULL; /* We use values cached in curcpu()  */
 #endif
-again:
 	/*
 	 * Find how many nanoseconds of Xen system time has elapsed
 	 * since the last hardclock tick.
@@ -817,7 +816,11 @@ again:
 		last - now);
 #endif
 		ci->ci_xen_systime_backwards_hardclock_evcnt.ev_count++;
-		now = last;
+		/*
+		 * we've lost track of time. Just pretends that one
+		 * tick elapsed, and reset our idea of last tick.
+		 */
+		ci->ci_xen_hardclock_systime_ns = last = now - ns_per_tick;
 	}
 	delta = now - last;
 
@@ -845,6 +848,9 @@ again:
 			xen_timecounter.tc_counter_mask);
 			ci->ci_xen_timecounter_jump_evcnt.ev_count++;
 		}
+		/* don't try to catch up more than one second at once */
+		if (delta > 10UL)
+			delta = 10UL;
 	}
 	while (delta >= ns_per_tick) {
 		ci->ci_xen_hardclock_systime_ns += ns_per_tick;
@@ -859,13 +865,19 @@ again:
 
 	/*
 	 * Re-arm the timer.  If it fails, it's probably because the
-	 * time is in the past, so update our idea of what the Xen
-	 * system time is and try again.
+	 * time is in the past, possibly because we're in the
+	 * process of catching up missed hardclock calls.
+	 * In this case schedule a tick in the nead future.
 	 */
 	next = ci->ci_xen_hardclock_systime_ns + ns_per_tick;
 	error = HYPERVISOR_set_timer_op(next);
-	if (error)
-		goto again;
+	if (error) {
+		next = xen_vcputime_systime_ns() + ns_per_tick / 2;
+		error = HYPERVISOR_set_timer_op(next);
+		if (error) {
+			panic("failed to re-arm Xen timer %d", error);
+		}
+	}
 
 	/* Success!  */
 	return 0;



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

2023-09-10 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sun Sep 10 15:23:01 UTC 2023

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

Log Message:
If Xen system time went backward, instead of ignoring the event assume
one tick passed and reinitialise the local state.
If we need to call the hardclock timer several time to catch up missed events,
don't do more than one second in a single event; and schedule the next
event faster.

Hopefully fixes occasionnal
panic: cpu1: time has not advanced in 1501 heartbeats
or
panic: cpu0: softints stuck for 16 seconds
seen in daily Xen atf runs.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 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.



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:38:57 UTC 2023

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

Log Message:
xvif(4): Omit needless membars in xennetback_connect.

xneti is a private data structure to which we have exclusive access
here; ordering the stores doesn't make sense.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 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.



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:38:47 UTC 2023

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

Log Message:
xvif(4): Omit needless membars in xennetback_rx_copy_process.

- No need for barrier around touching req_cons and rsp_prod_pvt,
  which are private.

- RING_PUSH_RESPONSES_AND_CHECK_NOTIFY updates the shared req_prod and
  then issues xen_mb, which is all that we need between the update of
  shared req_prod and hypervisor_notify_via_evtchn.

  (Between updating the shared req_prod and issuing
  hypervisor_notify_via_evtchn, only xen_wmb is needed.  But after
  writing to the shared req_prod, RING_PUSH_REQUESTS_AND_CHECK_NOTIFY
  must also read from the shared rsp_event, which requires the
  store-before-load ordering that only xen_mb provides.)


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 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.



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:38:37 UTC 2023

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

Log Message:
xvif(4): Simplify while loop in xennetback_evthandler.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 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.



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:37:55 UTC 2023

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

Log Message:
xvif(4): Add missing xen_rmb in xennetback_evthandler.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 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.116 src/sys/arch/xen/xen/xennetback_xenbus.c:1.117
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.116	Wed Aug  9 08:37:44 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Wed Aug  9 08:37:55 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.116 2023/08/09 08:37:44 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.117 2023/08/09 08:37:55 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.116 2023/08/09 08:37:44 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.117 2023/08/09 08:37:55 riastradh Exp $");
 
 #include 
 #include 
@@ -833,6 +833,13 @@ xennetback_evthandler(void *arg)
 		receive_pending);
 		if (receive_pending == 0)
 			break;
+		/*
+		 * Ensure we have read the producer's queue index in
+		 * RING_FINAL_CHECK_FOR_REQUESTS before we read the
+		 * content of the producer's next request in
+		 * RING_COPY_REQUEST.
+		 */
+		xen_rmb();
 		RING_COPY_REQUEST(>xni_txring, req_cons,
 		);
 		/* XXX Unclear what this xen_rmb is for. */



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:38:27 UTC 2023

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

Log Message:
xvif(4): Omit needless membars in xennetback_evthandler.

This should improve throughput without any impact on correctness.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 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.



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:38:16 UTC 2023

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

Log Message:
xvif(4): Move expensive xen_mb out of xennetback_evthandler loop.

Use the cheaper RING_HAS_UNCONFIRMED_REQUESTS for most of the loop.

This should improve throughput without any impact on correctness.


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 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.



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:38:16 UTC 2023

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

Log Message:
xvif(4): Move expensive xen_mb out of xennetback_evthandler loop.

Use the cheaper RING_HAS_UNCONFIRMED_REQUESTS for most of the loop.

This should improve throughput without any impact on correctness.


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 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.118 src/sys/arch/xen/xen/xennetback_xenbus.c:1.119
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.118	Wed Aug  9 08:38:05 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Wed Aug  9 08:38:16 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.118 2023/08/09 08:38:05 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.119 2023/08/09 08:38:16 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.118 2023/08/09 08:38:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.119 2023/08/09 08:38:16 riastradh Exp $");
 
 #include 
 #include 
@@ -811,6 +811,7 @@ xennetback_evthandler(void *arg)
 	(IFF_UP | IFF_RUNNING));
 
 	XENPRINTF(("xennetback_evthandler "));
+again:
 	while (1) {
 		/*
 		 * XXX The xen_rmb here and comment make no sense:
@@ -819,16 +820,7 @@ xennetback_evthandler(void *arg)
 		xen_rmb(); /* be sure to read the request before updating */
 		/* XXX Unclear what this xen_wmb is for.  */
 		xen_wmb();
-		/*
-		 * XXX RING_FINAL_CHECK_FOR_REQUESTS issues the most
-		 * expensive memory barrier, xen_mb.  This should be
-		 * used only at the end of the loop after we updating
-		 * the producer with the last index of the requests we
-		 * consumed in the queue.
-		 */
-		RING_FINAL_CHECK_FOR_REQUESTS(>xni_txring,
-		receive_pending);
-		if (receive_pending == 0)
+		if (!RING_HAS_UNCONSUMED_REQUESTS(>xni_txring))
 			break;
 		/*
 		 * Ensure we have read the producer's queue index in
@@ -981,6 +973,9 @@ mbuf_fail:
 			queued = 0;
 		}
 	}
+	RING_FINAL_CHECK_FOR_REQUESTS(>xni_txring, receive_pending);
+	if (receive_pending)
+		goto again;
 	if (m0) {
 		/* Queue empty, and still unfinished multi-fragment request */
 		printf("%s: dropped unfinished multi-fragment\n",



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:37:55 UTC 2023

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

Log Message:
xvif(4): Add missing xen_rmb in xennetback_evthandler.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 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.



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:37:44 UTC 2023

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

Log Message:
xvif(4): Comment on memory barriers in xennetback_evthandler.

Note which ones appear unnecessary and which ones appear too strong,
but don't change them.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 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.



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:38:57 UTC 2023

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

Log Message:
xvif(4): Omit needless membars in xennetback_connect.

xneti is a private data structure to which we have exclusive access
here; ordering the stores doesn't make sense.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 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.122 src/sys/arch/xen/xen/xennetback_xenbus.c:1.123
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.122	Wed Aug  9 08:38:47 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Wed Aug  9 08:38:57 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.122 2023/08/09 08:38:47 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.123 2023/08/09 08:38:57 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.122 2023/08/09 08:38:47 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.123 2023/08/09 08:38:57 riastradh Exp $");
 
 #include 
 #include 
@@ -497,9 +497,7 @@ xennetback_connect(struct xnetback_insta
 		goto err2;
 	}
 	xneti->xni_evtchn = evop.u.bind_interdomain.local_port;
-	xen_wmb();
 	xneti->xni_status = CONNECTED;
-	xen_wmb();
 
 	xneti->xni_ih = xen_intr_establish_xname(-1, _pic,
 	xneti->xni_evtchn, IST_LEVEL, IPL_NET, xennetback_evthandler,



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:38:47 UTC 2023

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

Log Message:
xvif(4): Omit needless membars in xennetback_rx_copy_process.

- No need for barrier around touching req_cons and rsp_prod_pvt,
  which are private.

- RING_PUSH_RESPONSES_AND_CHECK_NOTIFY updates the shared req_prod and
  then issues xen_mb, which is all that we need between the update of
  shared req_prod and hypervisor_notify_via_evtchn.

  (Between updating the shared req_prod and issuing
  hypervisor_notify_via_evtchn, only xen_wmb is needed.  But after
  writing to the shared req_prod, RING_PUSH_REQUESTS_AND_CHECK_NOTIFY
  must also read from the shared rsp_event, which requires the
  store-before-load ordering that only xen_mb provides.)


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 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.121 src/sys/arch/xen/xen/xennetback_xenbus.c:1.122
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.121	Wed Aug  9 08:38:37 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Wed Aug  9 08:38:47 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.121 2023/08/09 08:38:37 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.122 2023/08/09 08:38:47 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.121 2023/08/09 08:38:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.122 2023/08/09 08:38:47 riastradh Exp $");
 
 #include 
 #include 
@@ -1024,14 +1024,12 @@ xennetback_rx_copy_process(struct ifnet 
 	}
 
 	/* 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);



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:38:37 UTC 2023

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

Log Message:
xvif(4): Simplify while loop in xennetback_evthandler.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 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.120 src/sys/arch/xen/xen/xennetback_xenbus.c:1.121
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.120	Wed Aug  9 08:38:27 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Wed Aug  9 08:38:37 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.120 2023/08/09 08:38:27 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.121 2023/08/09 08:38:37 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.120 2023/08/09 08:38:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.121 2023/08/09 08:38:37 riastradh Exp $");
 
 #include 
 #include 
@@ -812,9 +812,7 @@ xennetback_evthandler(void *arg)
 
 	XENPRINTF(("xennetback_evthandler "));
 again:
-	while (1) {
-		if (!RING_HAS_UNCONSUMED_REQUESTS(>xni_txring))
-			break;
+	while (RING_HAS_UNCONSUMED_REQUESTS(>xni_txring)) {
 		/*
 		 * Ensure we have read the producer's queue index in
 		 * RING_FINAL_CHECK_FOR_REQUESTS before we read the



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:38:27 UTC 2023

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

Log Message:
xvif(4): Omit needless membars in xennetback_evthandler.

This should improve throughput without any impact on correctness.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 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.119 src/sys/arch/xen/xen/xennetback_xenbus.c:1.120
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.119	Wed Aug  9 08:38:16 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Wed Aug  9 08:38:27 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.119 2023/08/09 08:38:16 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.120 2023/08/09 08:38:27 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.119 2023/08/09 08:38:16 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.120 2023/08/09 08:38:27 riastradh Exp $");
 
 #include 
 #include 
@@ -813,13 +813,6 @@ xennetback_evthandler(void *arg)
 	XENPRINTF(("xennetback_evthandler "));
 again:
 	while (1) {
-		/*
-		 * XXX The xen_rmb here and comment make no sense:
-		 * xneti->xni_txring.req_cons is a private variable.
-		 */
-		xen_rmb(); /* be sure to read the request before updating */
-		/* XXX Unclear what this xen_wmb is for.  */
-		xen_wmb();
 		if (!RING_HAS_UNCONSUMED_REQUESTS(>xni_txring))
 			break;
 		/*
@@ -832,8 +825,6 @@ again:
 		RING_COPY_REQUEST(>xni_txring,
 		xneti->xni_txring.req_cons,
 		);
-		/* XXX Unclear what this xen_rmb is for. */
-		xen_rmb();
 		XENPRINTF(("%s pkt size %d\n", xneti->xni_if.if_xname,
 		txreq.size));
 		xneti->xni_txring.req_cons++;



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:38:05 UTC 2023

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

Log Message:
xvif(4): Omit local variable aliasing xneti->xni_txring.req_cons.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 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.



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:38:05 UTC 2023

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

Log Message:
xvif(4): Omit local variable aliasing xneti->xni_txring.req_cons.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 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.117 src/sys/arch/xen/xen/xennetback_xenbus.c:1.118
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.117	Wed Aug  9 08:37:55 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Wed Aug  9 08:38:05 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.117 2023/08/09 08:37:55 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.118 2023/08/09 08:38:05 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.117 2023/08/09 08:37:55 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.118 2023/08/09 08:38:05 riastradh Exp $");
 
 #include 
 #include 
@@ -805,21 +805,18 @@ xennetback_evthandler(void *arg)
 	netif_tx_request_t txreq;
 	struct mbuf *m, *m0 = NULL, *mlast = NULL;
 	int receive_pending;
-	RING_IDX req_cons;
 	int queued = 0, m0_len = 0;
 	struct xnetback_xstate *xst;
 	const bool discard = ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) !=
 	(IFF_UP | IFF_RUNNING));
 
 	XENPRINTF(("xennetback_evthandler "));
-	req_cons = xneti->xni_txring.req_cons;
 	while (1) {
 		/*
 		 * XXX The xen_rmb here and comment make no sense:
 		 * xneti->xni_txring.req_cons is a private variable.
 		 */
 		xen_rmb(); /* be sure to read the request before updating */
-		xneti->xni_txring.req_cons = req_cons;
 		/* XXX Unclear what this xen_wmb is for.  */
 		xen_wmb();
 		/*
@@ -840,13 +837,14 @@ xennetback_evthandler(void *arg)
 		 * RING_COPY_REQUEST.
 		 */
 		xen_rmb();
-		RING_COPY_REQUEST(>xni_txring, req_cons,
+		RING_COPY_REQUEST(>xni_txring,
+		xneti->xni_txring.req_cons,
 		);
 		/* XXX Unclear what this xen_rmb is for. */
 		xen_rmb();
 		XENPRINTF(("%s pkt size %d\n", xneti->xni_if.if_xname,
 		txreq.size));
-		req_cons++;
+		xneti->xni_txring.req_cons++;
 		if (__predict_false(discard)) {
 			/* interface not up, drop all requests */
 			if_statinc(ifp, if_iqdrops);
@@ -895,7 +893,7 @@ mbuf_fail:
 			 */
 			int cnt;
 			m0_len = xennetback_tx_m0len_fragment(xneti,
-			txreq.size, req_cons, );
+			txreq.size, xneti->xni_txring.req_cons, );
 			m->m_len = m0_len;
 			KASSERT(cnt <= XEN_NETIF_NR_SLOTS_MIN);
 
@@ -961,7 +959,8 @@ mbuf_fail:
 
 		XENPRINTF(("%s pkt offset %d size %d id %d req_cons %d\n",
 		xneti->xni_if.if_xname, txreq.offset,
-		txreq.size, txreq.id, req_cons & (RING_SIZE(>xni_txring) - 1)));
+		txreq.size, txreq.id,
+		xneti->xni_txring.req_cons & (RING_SIZE(>xni_txring) - 1)));
 
 		xst = >xni_xstate[queued];
 		xst->xs_m = (m0 == NULL || m == m0) ? m : NULL;



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

2023-08-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug  9 08:37:44 UTC 2023

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

Log Message:
xvif(4): Comment on memory barriers in xennetback_evthandler.

Note which ones appear unnecessary and which ones appear too strong,
but don't change them.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 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.115 src/sys/arch/xen/xen/xennetback_xenbus.c:1.116
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.115	Fri Aug  4 18:41:01 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Wed Aug  9 08:37:44 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.115 2023/08/04 18:41:01 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.116 2023/08/09 08:37:44 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.115 2023/08/04 18:41:01 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.116 2023/08/09 08:37:44 riastradh Exp $");
 
 #include 
 #include 
@@ -814,15 +814,28 @@ xennetback_evthandler(void *arg)
 	XENPRINTF(("xennetback_evthandler "));
 	req_cons = xneti->xni_txring.req_cons;
 	while (1) {
+		/*
+		 * XXX The xen_rmb here and comment make no sense:
+		 * xneti->xni_txring.req_cons is a private variable.
+		 */
 		xen_rmb(); /* be sure to read the request before updating */
 		xneti->xni_txring.req_cons = req_cons;
+		/* XXX Unclear what this xen_wmb is for.  */
 		xen_wmb();
+		/*
+		 * XXX RING_FINAL_CHECK_FOR_REQUESTS issues the most
+		 * expensive memory barrier, xen_mb.  This should be
+		 * used only at the end of the loop after we updating
+		 * the producer with the last index of the requests we
+		 * consumed in the queue.
+		 */
 		RING_FINAL_CHECK_FOR_REQUESTS(>xni_txring,
 		receive_pending);
 		if (receive_pending == 0)
 			break;
 		RING_COPY_REQUEST(>xni_txring, req_cons,
 		);
+		/* XXX Unclear what this xen_rmb is for. */
 		xen_rmb();
 		XENPRINTF(("%s pkt size %d\n", xneti->xni_if.if_xname,
 		txreq.size));



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

2023-08-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug  4 18:41:01 UTC 2023

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

Log Message:
Revert "xennetback(4): Fix xennetback_evthandler loop."

PR kern/57560


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 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.114 src/sys/arch/xen/xen/xennetback_xenbus.c:1.115
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.114	Fri Aug  4 18:40:49 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Fri Aug  4 18:41:01 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.114 2023/08/04 18:40:49 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.115 2023/08/04 18:41:01 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.114 2023/08/04 18:40:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.115 2023/08/04 18:41:01 riastradh Exp $");
 
 #include 
 #include 
@@ -805,7 +805,7 @@ xennetback_evthandler(void *arg)
 	netif_tx_request_t txreq;
 	struct mbuf *m, *m0 = NULL, *mlast = NULL;
 	int receive_pending;
-	RING_IDX req_cons, req_prod;
+	RING_IDX req_cons;
 	int queued = 0, m0_len = 0;
 	struct xnetback_xstate *xst;
 	const bool discard = ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) !=
@@ -813,12 +813,17 @@ xennetback_evthandler(void *arg)
 
 	XENPRINTF(("xennetback_evthandler "));
 	req_cons = xneti->xni_txring.req_cons;
-again:
-	req_prod = xneti->xni_txring.sring->req_prod;
-	xen_rmb();
-	while (req_cons != req_prod) {
+	while (1) {
+		xen_rmb(); /* be sure to read the request before updating */
+		xneti->xni_txring.req_cons = req_cons;
+		xen_wmb();
+		RING_FINAL_CHECK_FOR_REQUESTS(>xni_txring,
+		receive_pending);
+		if (receive_pending == 0)
+			break;
 		RING_COPY_REQUEST(>xni_txring, req_cons,
 		);
+		xen_rmb();
 		XENPRINTF(("%s pkt size %d\n", xneti->xni_if.if_xname,
 		txreq.size));
 		req_cons++;
@@ -957,12 +962,6 @@ mbuf_fail:
 			queued = 0;
 		}
 	}
-	xen_wmb();
-	RING_FINAL_CHECK_FOR_REQUESTS(>xni_txring, receive_pending);
-	if (receive_pending)
-		goto again;
-	xneti->xni_txring.req_cons = req_cons;
-
 	if (m0) {
 		/* Queue empty, and still unfinished multi-fragment request */
 		printf("%s: dropped unfinished multi-fragment\n",



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

2023-08-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug  4 18:41:01 UTC 2023

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

Log Message:
Revert "xennetback(4): Fix xennetback_evthandler loop."

PR kern/57560


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 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.



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

2023-08-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug  4 18:40:49 UTC 2023

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

Log Message:
Revert "xennetback(4): Fix membars in xennetback_rx_copy_process."

PR kern/57560


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 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.113 src/sys/arch/xen/xen/xennetback_xenbus.c:1.114
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.113	Fri Aug  4 18:40:36 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Fri Aug  4 18:40:49 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.113 2023/08/04 18:40:36 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.114 2023/08/04 18:40:49 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.113 2023/08/04 18:40:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.114 2023/08/04 18:40:49 riastradh Exp $");
 
 #include 
 #include 
@@ -1022,13 +1022,14 @@ xennetback_rx_copy_process(struct ifnet 
 	}
 
 	/* 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_wmb();
+		xen_rmb();
 		XENPRINTF(("%s receive event\n",
 		xneti->xni_if.if_xname));
 		hypervisor_notify_via_evtchn(xneti->xni_evtchn);



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

2023-08-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug  4 18:40:49 UTC 2023

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

Log Message:
Revert "xennetback(4): Fix membars in xennetback_rx_copy_process."

PR kern/57560


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 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.



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

2023-08-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug  4 18:40:36 UTC 2023

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

Log Message:
Revert "xennetback(4): Omit needless membars in xennetback_connect."

PR kern/57560


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 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.112 src/sys/arch/xen/xen/xennetback_xenbus.c:1.113
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.112	Sat Feb 25 00:37:47 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Fri Aug  4 18:40:36 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.112 2023/02/25 00:37:47 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.113 2023/08/04 18:40:36 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.112 2023/02/25 00:37:47 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.113 2023/08/04 18:40:36 riastradh Exp $");
 
 #include 
 #include 
@@ -497,7 +497,9 @@ xennetback_connect(struct xnetback_insta
 		goto err2;
 	}
 	xneti->xni_evtchn = evop.u.bind_interdomain.local_port;
+	xen_wmb();
 	xneti->xni_status = CONNECTED;
+	xen_wmb();
 
 	xneti->xni_ih = xen_intr_establish_xname(-1, _pic,
 	xneti->xni_evtchn, IST_LEVEL, IPL_NET, xennetback_evthandler,



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

2023-08-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug  4 18:40:36 UTC 2023

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

Log Message:
Revert "xennetback(4): Omit needless membars in xennetback_connect."

PR kern/57560


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 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.



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

2023-08-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug  1 20:11:13 UTC 2023

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

Log Message:
xen: Fix previous commit, forgot to amend it before committing.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 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.



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

2023-08-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug  1 20:11:13 UTC 2023

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

Log Message:
xen: Fix previous commit, forgot to amend it before committing.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 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.16 src/sys/arch/xen/xen/xen_clock.c:1.17
--- src/sys/arch/xen/xen/xen_clock.c:1.16	Tue Aug  1 19:36:57 2023
+++ src/sys/arch/xen/xen/xen_clock.c	Tue Aug  1 20:11:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_clock.c,v 1.16 2023/08/01 19:36:57 riastradh Exp $	*/
+/*	$NetBSD: xen_clock.c,v 1.17 2023/08/01 20:11:13 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.16 2023/08/01 19:36:57 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.17 2023/08/01 20:11:13 riastradh Exp $");
 
 #include 
 #include 
@@ -834,9 +834,7 @@ again:
 		 * Warn if we violate timecounter(9) contract: with a
 		 * k-bit timeocunter (here k = 32), and timecounter
 		 * frequency f (here f = 1 GHz), the maximum period
-		 * between hardclock calls is 2^k / f.  This comes out
-		 * to 2^32 ns, in what is conveneintly already the
-		 * correct unit for the Xen systime clock.
+		 * between hardclock calls is 2^k / f.
 		 */
 		if (delta > xen_timecounter.tc_counter_mask) {
 			printf("WARNING: hardclock skipped %"PRIu64"ns"
@@ -911,6 +909,9 @@ xen_initclocks(void)
 	evcnt_attach_dynamic(>ci_xen_timecounter_backwards_evcnt,
 	EVCNT_TYPE_INTR, NULL, device_xname(ci->ci_dev),
 	"timecounter went backwards");
+	evcnt_attach_dynamic(>ci_xen_timecounter_jump_evcnt,
+	EVCNT_TYPE_INTR, NULL, device_xname(ci->ci_dev),
+	"hardclock jumped past timecounter max");
 
 	/* Fire up the clocks.  */
 	xen_resumeclocks(ci);



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

2023-07-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul 28 10:39:14 UTC 2023

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

Log Message:
xen_clock(4): New hardclock dtrace probes.

sdt:xen:hardclock:tick(last, now)
  fires on every hardclock tick

sdt:xen:hardclock:jump(last, now, nticks)
  fires on every hardclock tick when (now - last) >= 2*NS_PER_TICK,
  i.e., this call to the timer interrupt handler requires multiple
  hardclock ticks


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 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.14 src/sys/arch/xen/xen/xen_clock.c:1.15
--- src/sys/arch/xen/xen/xen_clock.c:1.14	Fri Jul 28 10:39:01 2023
+++ src/sys/arch/xen/xen/xen_clock.c	Fri Jul 28 10:39:14 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_clock.c,v 1.14 2023/07/28 10:39:01 riastradh Exp $	*/
+/*	$NetBSD: xen_clock.c,v 1.15 2023/07/28 10:39:14 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.14 2023/07/28 10:39:01 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.15 2023/07/28 10:39:14 riastradh Exp $");
 
 #include 
 #include 
@@ -120,6 +120,13 @@ SDT_PROBE_DEFINE3(sdt, xen, timecounter,
 SDT_PROBE_DEFINE2(sdt, xen, hardclock, systime__backward,
 "uint64_t"/*last_systime_ns*/,
 "uint64_t"/*this_systime_ns*/);
+SDT_PROBE_DEFINE2(sdt, xen, hardclock, tick,
+"uint64_t"/*last_systime_ns*/,
+"uint64_t"/*this_systime_ns*/);
+SDT_PROBE_DEFINE3(sdt, xen, hardclock, jump,
+"uint64_t"/*last_systime_ns*/,
+"uint64_t"/*this_systime_ns*/,
+"uint64_t"/*nticks*/);
 SDT_PROBE_DEFINE3(sdt, xen, hardclock, missed,
 "uint64_t"/*last_systime_ns*/,
 "uint64_t"/*this_systime_ns*/,
@@ -800,7 +807,8 @@ again:
 	 */
 	last = ci->ci_xen_hardclock_systime_ns;
 	now = xen_vcputime_systime_ns();
-	if (now < last) {
+	SDT_PROBE2(sdt, xen, hardclock, tick,  last, now);
+	if (__predict_false(now < last)) {
 		SDT_PROBE2(sdt, xen, hardclock, systime__backward,
 		last, now);
 #if XEN_CLOCK_DEBUG
@@ -818,6 +826,10 @@ again:
 	 * times as appears necessary based on how much time has
 	 * passed.
 	 */
+	if (__predict_false(delta >= 2*ns_per_tick)) {
+		SDT_PROBE3(sdt, xen, hardclock, jump,
+		last, now, delta/ns_per_tick);
+	}
 	while (delta >= ns_per_tick) {
 		ci->ci_xen_hardclock_systime_ns += ns_per_tick;
 		delta -= ns_per_tick;



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

2023-07-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul 28 10:39:14 UTC 2023

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

Log Message:
xen_clock(4): New hardclock dtrace probes.

sdt:xen:hardclock:tick(last, now)
  fires on every hardclock tick

sdt:xen:hardclock:jump(last, now, nticks)
  fires on every hardclock tick when (now - last) >= 2*NS_PER_TICK,
  i.e., this call to the timer interrupt handler requires multiple
  hardclock ticks


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 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.



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

2023-07-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul 28 10:39:01 UTC 2023

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

Log Message:
xen_clock(4): Compute NS_PER_TICK only once per call.

This involves a division by an unknown number, so let's cache it.

XXX Could do better by precomputing it in xen_resumeclocks, with some
effort to ensure concurrent calls don't stomp on each other.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 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.13 src/sys/arch/xen/xen/xen_clock.c:1.14
--- src/sys/arch/xen/xen/xen_clock.c:1.13	Fri Jul 28 10:38:44 2023
+++ src/sys/arch/xen/xen/xen_clock.c	Fri Jul 28 10:39:01 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_clock.c,v 1.13 2023/07/28 10:38:44 riastradh Exp $	*/
+/*	$NetBSD: xen_clock.c,v 1.14 2023/07/28 10:39:01 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.13 2023/07/28 10:38:44 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.14 2023/07/28 10:39:01 riastradh Exp $");
 
 #include 
 #include 
@@ -782,6 +782,7 @@ xen_resumeclocks(struct cpu_info *ci)
 static int
 xen_timer_handler(void *cookie, struct clockframe *frame)
 {
+	const uint64_t ns_per_tick = NS_PER_TICK;
 	struct cpu_info *ci = curcpu();
 	uint64_t last, now, delta, next;
 	int error;
@@ -817,11 +818,11 @@ again:
 	 * times as appears necessary based on how much time has
 	 * passed.
 	 */
-	while (delta >= NS_PER_TICK) {
-		ci->ci_xen_hardclock_systime_ns += NS_PER_TICK;
-		delta -= NS_PER_TICK;
+	while (delta >= ns_per_tick) {
+		ci->ci_xen_hardclock_systime_ns += ns_per_tick;
+		delta -= ns_per_tick;
 		hardclock(frame);
-		if (__predict_false(delta >= NS_PER_TICK)) {
+		if (__predict_false(delta >= ns_per_tick)) {
 			SDT_PROBE3(sdt, xen, hardclock, missed,
 			last, now, delta);
 			ci->ci_xen_missed_hardclock_evcnt.ev_count++;
@@ -833,7 +834,7 @@ again:
 	 * time is in the past, so update our idea of what the Xen
 	 * system time is and try again.
 	 */
-	next = ci->ci_xen_hardclock_systime_ns + NS_PER_TICK;
+	next = ci->ci_xen_hardclock_systime_ns + ns_per_tick;
 	error = HYPERVISOR_set_timer_op(next);
 	if (error)
 		goto again;



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

2023-07-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul 28 10:39:01 UTC 2023

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

Log Message:
xen_clock(4): Compute NS_PER_TICK only once per call.

This involves a division by an unknown number, so let's cache it.

XXX Could do better by precomputing it in xen_resumeclocks, with some
effort to ensure concurrent calls don't stomp on each other.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 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.



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

2023-07-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul 28 10:38:44 UTC 2023

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

Log Message:
xen_clock(4): Fix whitespace and sprinkle comments.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 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.12 src/sys/arch/xen/xen/xen_clock.c:1.13
--- src/sys/arch/xen/xen/xen_clock.c:1.12	Mon Jul 17 10:12:54 2023
+++ src/sys/arch/xen/xen/xen_clock.c	Fri Jul 28 10:38:44 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_clock.c,v 1.12 2023/07/17 10:12:54 bouyer Exp $	*/
+/*	$NetBSD: xen_clock.c,v 1.13 2023/07/28 10:38:44 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.12 2023/07/17 10:12:54 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.13 2023/07/28 10:38:44 riastradh Exp $");
 
 #include 
 #include 
@@ -673,11 +673,31 @@ xen_suspendclocks(struct cpu_info *ci)
 	KASSERT(ci == curcpu());
 	KASSERT(kpreempt_disabled());
 
+	/*
+	 * Find the VIRQ_TIMER event channel and close it so new timer
+	 * interrupt events stop getting delivered to it.
+	 *
+	 * XXX Should this happen later?  This is not the reverse order
+	 * of xen_resumeclocks.  It is apparently necessary in this
+	 * order only because we don't stash evtchn anywhere, but we
+	 * could stash it.
+	 */
 	evtch = unbind_virq_from_evtch(VIRQ_TIMER);
 	KASSERT(evtch != -1);
 
+	/*
+	 * Mask the event channel so we stop getting new interrupts on
+	 * it.
+	 */
 	hypervisor_mask_event(evtch);
-	event_remove_handler(evtch, 
+
+	/*
+	 * Now that we are no longer getting new interrupts, remove the
+	 * handler and wait for any existing calls to the handler to
+	 * complete.  After this point, there can be no concurrent
+	 * calls to xen_timer_handler.
+	 */
+	event_remove_handler(evtch,
 	__FPTRCAST(int (*)(void *), xen_timer_handler), ci);
 
 	aprint_verbose("Xen clock: removed event channel %d\n", evtch);
@@ -705,9 +725,16 @@ xen_resumeclocks(struct cpu_info *ci)
 	KASSERT(ci == curcpu());
 	KASSERT(kpreempt_disabled());
 
+	/*
+	 * Allocate an event channel to receive VIRQ_TIMER events.
+	 */
 	evtch = bind_virq_to_evtch(VIRQ_TIMER);
 	KASSERT(evtch != -1);
 
+	/*
+	 * Set an event handler for VIRQ_TIMER events to call
+	 * xen_timer_handler.
+	 */
 	snprintf(intr_xname, sizeof(intr_xname), "%s clock",
 	device_xname(ci->ci_dev));
 	/* XXX sketchy function pointer cast -- fix the API, please */
@@ -716,7 +743,6 @@ xen_resumeclocks(struct cpu_info *ci)
 	ci, IPL_CLOCK, NULL, intr_xname, true, ci) == NULL)
 		panic("failed to establish timer interrupt handler");
 
-
 	aprint_verbose("Xen %s: using event channel %d\n", intr_xname, evtch);
 
 	/* Disarm the periodic timer on Xen>=3.1 which is allegedly buggy.  */
@@ -729,11 +755,15 @@ xen_resumeclocks(struct cpu_info *ci)
 	/* Pretend the last hardclock happened right now.  */
 	ci->ci_xen_hardclock_systime_ns = xen_vcputime_systime_ns();
 
-
 	/* Arm the one-shot timer.  */
 	error = HYPERVISOR_set_timer_op(ci->ci_xen_hardclock_systime_ns +
 	NS_PER_TICK);
 	KASSERT(error == 0);
+
+	/*
+	 * Ready to go.  Unmask the event.  After this point, Xen may
+	 * start calling xen_timer_handler.
+	 */
 	hypervisor_unmask_event(evtch);
 
 	/* We'd better not have switched CPUs.  */



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

2023-07-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul 28 10:38:44 UTC 2023

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

Log Message:
xen_clock(4): Fix whitespace and sprinkle comments.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 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.



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

2023-07-25 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Jul 25 16:15:50 UTC 2023

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

Log Message:
Propoerly handle 4k sector size backends:
- report the backend's sector size to upper layers, not DEV_BSIZE.
  Adjust the number of sectors accordingly.
- Use sc_secsize instead of XEN_BSIZE where appropriate. The sectors numbers
  in I/O requests are still in XEN_BSIZE units, but must be a multiple
  of sc_secsize/XEN_BSIZE.
- As a consequence of previous, the buffer has to be aligned to sc_secsize,
  aligned to XEN_BSIZE may not be enough. This means that we may have to
  xbd_map_align() more buffer, including some without B_PHYS set.
- Add some more DPRINTF lines, related to I/O requests

Tested with a linux dom0.
thanks to Christian Kujau for providing access to his hardware for testing
and debugging.


To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 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.



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

2023-07-25 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Jul 25 16:15:50 UTC 2023

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

Log Message:
Propoerly handle 4k sector size backends:
- report the backend's sector size to upper layers, not DEV_BSIZE.
  Adjust the number of sectors accordingly.
- Use sc_secsize instead of XEN_BSIZE where appropriate. The sectors numbers
  in I/O requests are still in XEN_BSIZE units, but must be a multiple
  of sc_secsize/XEN_BSIZE.
- As a consequence of previous, the buffer has to be aligned to sc_secsize,
  aligned to XEN_BSIZE may not be enough. This means that we may have to
  xbd_map_align() more buffer, including some without B_PHYS set.
- Add some more DPRINTF lines, related to I/O requests

Tested with a linux dom0.
thanks to Christian Kujau for providing access to his hardware for testing
and debugging.


To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 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.133 src/sys/arch/xen/xen/xbd_xenbus.c:1.134
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.133	Fri Jul 21 11:28:50 2023
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Tue Jul 25 16:15:50 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.133 2023/07/21 11:28:50 bouyer Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.134 2023/07/25 16:15:50 bouyer Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.133 2023/07/21 11:28:50 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.134 2023/07/25 16:15:50 bouyer Exp $");
 
 #include "opt_xen.h"
 
@@ -169,7 +169,7 @@ struct xbd_xenbus_softc {
 #define BLKIF_SHUTDOWN_REMOTE 1 /* backend-initiated shutdown in progress */
 #define BLKIF_SHUTDOWN_LOCAL  2 /* locally-initiated shutdown in progress */
 
-	uint64_t sc_sectors; /* number of XEN_BSIZE sectors for this device */
+	uint64_t sc_sectors; /* number of sc_secsize sectors for this device */
 	u_long sc_secsize; /* sector size */
 	uint64_t sc_xbdsize; /* size of disk in DEV_BSIZE */
 	u_long sc_info; /* VDISK_* */
@@ -674,15 +674,14 @@ xbd_backend_changed(void *arg, XenbusSta
 		xbd_connect(sc);
 		sc->sc_shutdown = BLKIF_SHUTDOWN_RUN;
 		sc->sc_xbdsize =
-		sc->sc_sectors * (uint64_t)XEN_BSIZE / DEV_BSIZE;
+		sc->sc_sectors * (uint64_t)sc->sc_secsize / DEV_BSIZE;
 		dg = >sc_dksc.sc_dkdev.dk_geom;
 		memset(dg, 0, sizeof(*dg));
 
-		dg->dg_secperunit = sc->sc_xbdsize;
-		dg->dg_secsize = DEV_BSIZE;
+		dg->dg_secperunit = sc->sc_sectors;
+		dg->dg_secsize = sc->sc_secsize;
 		dg->dg_ntracks = 1;
-		// XXX: Ok to hard-code DEV_BSIZE?
-		dg->dg_nsectors = 1024 * (1024 / dg->dg_secsize);
+		dg->dg_nsectors = (1024 * 1024) / dg->dg_secsize;
 		dg->dg_ncylinders = dg->dg_secperunit / dg->dg_nsectors;
 
 		bufq_alloc(>sc_dksc.sc_bufq, "fcfs", 0);
@@ -693,10 +692,10 @@ xbd_backend_changed(void *arg, XenbusSta
 		hypervisor_unmask_event(sc->sc_evtchn);
 
 		format_bytes(buf, uimin(9, sizeof(buf)),
-		sc->sc_sectors * XEN_BSIZE);
+		sc->sc_sectors * dg->dg_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);
+buf, (int)dg->dg_secsize, sc->sc_sectors);
 		snprintb(buf, sizeof(buf), BLKIF_FEATURE_BITS,
 		sc->sc_features);
 		aprint_normal_dev(sc->sc_dksc.sc_dev,
@@ -739,14 +738,6 @@ xbd_connect(struct xbd_xenbus_softc *sc)
 		panic("%s: can't read number from %s/virtual-device\n",
 		device_xname(sc->sc_dksc.sc_dev),
 		sc->sc_xbusd->xbusd_otherend);
-	err = xenbus_read_ull(NULL,
-	sc->sc_xbusd->xbusd_otherend, "sectors", , 10);
-	if (err)
-		panic("%s: can't read number from %s/sectors\n",
-		device_xname(sc->sc_dksc.sc_dev),
-		sc->sc_xbusd->xbusd_otherend);
-	sc->sc_sectors = sectors;
-
 	err = xenbus_read_ul(NULL,
 	sc->sc_xbusd->xbusd_otherend, "info", >sc_info, 10);
 	if (err)
@@ -760,6 +751,14 @@ xbd_connect(struct xbd_xenbus_softc *sc)
 		device_xname(sc->sc_dksc.sc_dev),
 		sc->sc_xbusd->xbusd_otherend);
 
+	err = xenbus_read_ull(NULL,
+	sc->sc_xbusd->xbusd_otherend, "sectors", , 10);
+	if (err)
+		panic("%s: can't read number from %s/sectors\n",
+		device_xname(sc->sc_dksc.sc_dev),
+		sc->sc_xbusd->xbusd_otherend);
+	sc->sc_sectors = sectors * (uint64_t)XEN_BSIZE / sc->sc_secsize;
+
 	xenbus_switch_state(sc->sc_xbusd, NULL, XenbusStateConnected);
 }
 
@@ -839,6 +838,8 @@ again:
 		bp, (long)bp->b_bcount));
 
 		if (bp->b_error != 0 || rep->status != BLKIF_RSP_OKAY) {
+			DPRINTF(("%s: error %d status %d\n", __func__,
+			bp->b_error, rep->status));
 			bp->b_error = EIO;
 			bp->b_resid = bp->b_bcount;
 		}
@@ -1137,7 +1138,7 @@ xbd_diskstart(device_t self, struct buf 
 		goto out;
 	}
 
-	if 

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

2023-07-21 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Jul 21 11:28:50 UTC 2023

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

Log Message:
Also use XEN_BSIZE when computing the number of bytes for format_bytes().
While there note in a comment that sc_sectors is in XEN_BSIZE units


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 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.132 src/sys/arch/xen/xen/xbd_xenbus.c:1.133
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.132	Fri Jul 21 11:21:55 2023
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Fri Jul 21 11:28:50 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.132 2023/07/21 11:21:55 bouyer Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.133 2023/07/21 11:28:50 bouyer Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.132 2023/07/21 11:21:55 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.133 2023/07/21 11:28:50 bouyer Exp $");
 
 #include "opt_xen.h"
 
@@ -169,7 +169,7 @@ struct xbd_xenbus_softc {
 #define BLKIF_SHUTDOWN_REMOTE 1 /* backend-initiated shutdown in progress */
 #define BLKIF_SHUTDOWN_LOCAL  2 /* locally-initiated shutdown in progress */
 
-	uint64_t sc_sectors; /* number of sectors for this device */
+	uint64_t sc_sectors; /* number of XEN_BSIZE sectors for this device */
 	u_long sc_secsize; /* sector size */
 	uint64_t sc_xbdsize; /* size of disk in DEV_BSIZE */
 	u_long sc_info; /* VDISK_* */
@@ -693,7 +693,7 @@ xbd_backend_changed(void *arg, XenbusSta
 		hypervisor_unmask_event(sc->sc_evtchn);
 
 		format_bytes(buf, uimin(9, sizeof(buf)),
-		sc->sc_sectors * sc->sc_secsize);
+		sc->sc_sectors * XEN_BSIZE);
 		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

2023-07-21 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Jul 21 11:28:50 UTC 2023

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

Log Message:
Also use XEN_BSIZE when computing the number of bytes for format_bytes().
While there note in a comment that sc_sectors is in XEN_BSIZE units


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 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.



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

2023-07-21 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Jul 21 11:21:56 UTC 2023

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

Log Message:
The disk size reported in the xenstore is always in XEN_BSIZE units,
not sector-size. Should fix the issue reported by Christian Kujau
on netbsd-users and port-xen.


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 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.131 src/sys/arch/xen/xen/xbd_xenbus.c:1.132
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.131	Sat Feb 25 00:35:15 2023
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Fri Jul 21 11:21:55 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.131 2023/02/25 00:35:15 riastradh Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.132 2023/07/21 11:21:55 bouyer Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.131 2023/02/25 00:35:15 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.132 2023/07/21 11:21:55 bouyer Exp $");
 
 #include "opt_xen.h"
 
@@ -674,7 +674,7 @@ xbd_backend_changed(void *arg, XenbusSta
 		xbd_connect(sc);
 		sc->sc_shutdown = BLKIF_SHUTDOWN_RUN;
 		sc->sc_xbdsize =
-		sc->sc_sectors * (uint64_t)sc->sc_secsize / DEV_BSIZE;
+		sc->sc_sectors * (uint64_t)XEN_BSIZE / DEV_BSIZE;
 		dg = >sc_dksc.sc_dkdev.dk_geom;
 		memset(dg, 0, sizeof(*dg));
 



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

2023-07-21 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Jul 21 11:21:56 UTC 2023

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

Log Message:
The disk size reported in the xenstore is always in XEN_BSIZE units,
not sector-size. Should fix the issue reported by Christian Kujau
on netbsd-users and port-xen.


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 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.



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

2023-07-17 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Jul 17 10:12:54 UTC 2023

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

Log Message:
Unmask event after arming the one-shot timer in clock initialisation,
to avoid a possible race with xen_timer_handler() updating
ci_xen_hardclock_systime_ns while we're reading it.
Pointed out by Taylor R Campbell


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 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.11 src/sys/arch/xen/xen/xen_clock.c:1.12
--- src/sys/arch/xen/xen/xen_clock.c:1.11	Thu Jul 13 13:34:15 2023
+++ src/sys/arch/xen/xen/xen_clock.c	Mon Jul 17 10:12:54 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_clock.c,v 1.11 2023/07/13 13:34:15 riastradh Exp $	*/
+/*	$NetBSD: xen_clock.c,v 1.12 2023/07/17 10:12:54 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.11 2023/07/13 13:34:15 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.12 2023/07/17 10:12:54 bouyer Exp $");
 
 #include 
 #include 
@@ -729,12 +729,12 @@ xen_resumeclocks(struct cpu_info *ci)
 	/* Pretend the last hardclock happened right now.  */
 	ci->ci_xen_hardclock_systime_ns = xen_vcputime_systime_ns();
 
-	hypervisor_unmask_event(evtch);
 
 	/* Arm the one-shot timer.  */
 	error = HYPERVISOR_set_timer_op(ci->ci_xen_hardclock_systime_ns +
 	NS_PER_TICK);
 	KASSERT(error == 0);
+	hypervisor_unmask_event(evtch);
 
 	/* We'd better not have switched CPUs.  */
 	KASSERT(ci == curcpu());



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

2023-07-17 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Jul 17 10:12:54 UTC 2023

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

Log Message:
Unmask event after arming the one-shot timer in clock initialisation,
to avoid a possible race with xen_timer_handler() updating
ci_xen_hardclock_systime_ns while we're reading it.
Pointed out by Taylor R Campbell


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 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.



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

2023-07-07 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Jul  7 15:13:41 UTC 2023

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

Log Message:
Unmask event after VCPUOP_stop_periodic_timer and
initializing ci->ci_xen_hardclock_systime_ns, to avoid a possible race with
xen_timer_handler()


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 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.



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

2023-07-07 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Jul  7 15:13:41 UTC 2023

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

Log Message:
Unmask event after VCPUOP_stop_periodic_timer and
initializing ci->ci_xen_hardclock_systime_ns, to avoid a possible race with
xen_timer_handler()


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 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.9 src/sys/arch/xen/xen/xen_clock.c:1.10
--- src/sys/arch/xen/xen/xen_clock.c:1.9	Mon May  1 09:03:19 2023
+++ src/sys/arch/xen/xen/xen_clock.c	Fri Jul  7 15:13:41 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_clock.c,v 1.9 2023/05/01 09:03:19 riastradh Exp $	*/
+/*	$NetBSD: xen_clock.c,v 1.10 2023/07/07 15:13:41 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.9 2023/05/01 09:03:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.10 2023/07/07 15:13:41 bouyer Exp $");
 
 #include 
 #include 
@@ -700,7 +700,6 @@ xen_resumeclocks(struct cpu_info *ci)
 	ci, IPL_CLOCK, NULL, intr_xname, true, ci) == NULL)
 		panic("failed to establish timer interrupt handler");
 
-	hypervisor_unmask_event(evtch);
 
 	aprint_verbose("Xen %s: using event channel %d\n", intr_xname, evtch);
 
@@ -714,6 +713,8 @@ xen_resumeclocks(struct cpu_info *ci)
 	/* Pretend the last hardclock happened right now.  */
 	ci->ci_xen_hardclock_systime_ns = xen_vcputime_systime_ns();
 
+	hypervisor_unmask_event(evtch);
+
 	/* Arm the one-shot timer.  */
 	error = HYPERVISOR_set_timer_op(ci->ci_xen_hardclock_systime_ns +
 	NS_PER_TICK);



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

2023-05-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May  1 09:03:19 UTC 2023

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

Log Message:
xen_clock(4): Sprinkle dtrace probes.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 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.8 src/sys/arch/xen/xen/xen_clock.c:1.9
--- src/sys/arch/xen/xen/xen_clock.c:1.8	Mon Nov 30 17:05:02 2020
+++ src/sys/arch/xen/xen/xen_clock.c	Mon May  1 09:03:19 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_clock.c,v 1.8 2020/11/30 17:05:02 bouyer Exp $	*/
+/*	$NetBSD: xen_clock.c,v 1.9 2023/05/01 09:03:19 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.8 2020/11/30 17:05:02 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.9 2023/05/01 09:03:19 riastradh Exp $");
 
 #include 
 #include 
@@ -49,6 +49,7 @@ __KERNEL_RCSID(0, "$NetBSD: xen_clock.c,
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -76,6 +77,50 @@ static unsigned	xen_get_timecount(struct
 static int	xen_timer_handler(void *, struct clockframe *);
 
 /*
+ * dtrace probes
+ */
+SDT_PROBE_DEFINE7(sdt, xen, clock, tsc__backward,
+"uint64_t"/*raw_systime_ns*/,
+"uint64_t"/*tsc_timestamp*/,
+"uint64_t"/*tsc_to_system_mul*/,
+"int"/*tsc_shift*/,
+"uint64_t"/*delta_ns*/,
+"uint64_t"/*tsc*/,
+"uint64_t"/*systime_ns*/);
+SDT_PROBE_DEFINE7(sdt, xen, clock, tsc__delta__negative,
+"uint64_t"/*raw_systime_ns*/,
+"uint64_t"/*tsc_timestamp*/,
+"uint64_t"/*tsc_to_system_mul*/,
+"int"/*tsc_shift*/,
+"uint64_t"/*delta_ns*/,
+"uint64_t"/*tsc*/,
+"uint64_t"/*systime_ns*/);
+SDT_PROBE_DEFINE7(sdt, xen, clock, systime__wraparound,
+"uint64_t"/*raw_systime_ns*/,
+"uint64_t"/*tsc_timestamp*/,
+"uint64_t"/*tsc_to_system_mul*/,
+"int"/*tsc_shift*/,
+"uint64_t"/*delta_ns*/,
+"uint64_t"/*tsc*/,
+"uint64_t"/*systime_ns*/);
+SDT_PROBE_DEFINE7(sdt, xen, clock, systime__backward,
+"uint64_t"/*raw_systime_ns*/,
+"uint64_t"/*tsc_timestamp*/,
+"uint64_t"/*tsc_to_system_mul*/,
+"int"/*tsc_shift*/,
+"uint64_t"/*delta_ns*/,
+"uint64_t"/*tsc*/,
+"uint64_t"/*systime_ns*/);
+
+SDT_PROBE_DEFINE2(sdt, xen, hardclock, systime__backward,
+"uint64_t"/*last_systime_ns*/,
+"uint64_t"/*this_systime_ns*/);
+SDT_PROBE_DEFINE3(sdt, xen, hardclock, missed,
+"uint64_t"/*last_systime_ns*/,
+"uint64_t"/*this_systime_ns*/,
+"uint64_t"/*remaining_ns*/);
+
+/*
  * xen timecounter:
  *
  *	Xen vCPU system time, plus an adjustment with rdtsc.
@@ -277,7 +322,11 @@ xen_vcputime_systime_ns(void)
 		 * Notify the console that the CPU's tsc appeared to
 		 * run behind Xen's idea of it, and pretend it hadn't.
 		 */
-#if XEN_CLOCK_DEBUG		/* XXX dtrace hook */
+		SDT_PROBE7(sdt, xen, clock, tsc__backward,
+		raw_systime_ns, tsc_timestamp,
+		tsc_to_system_mul, tsc_shift, /*delta_ns*/0, tsc,
+		/*systime_ns*/raw_systime_ns);
+#if XEN_CLOCK_DEBUG
 		device_printf(ci->ci_dev, "xen cpu tsc %"PRIu64
 		" ran backwards from timestamp %"PRIu64
 		" by %"PRIu64"\n",
@@ -301,9 +350,13 @@ xen_vcputime_systime_ns(void)
 	 * This doesn't make sense but I include it out of paranoia.
 	 */
 	if (__predict_false((int64_t)delta_ns < 0)) {
-#if XEN_CLOCK_DEBUG		/* XXX dtrace hook */
-		device_printf(ci->ci_dev, "xen tsc delta in ns went negative: %"PRId64"\n",
-		delta_ns);
+		SDT_PROBE7(sdt, xen, clock, tsc__delta__negative,
+		raw_systime_ns, tsc_timestamp,
+		tsc_to_system_mul, tsc_shift, delta_ns, tsc,
+		/*systime_ns*/raw_systime_ns);
+#if XEN_CLOCK_DEBUG
+		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++;
 		delta_ns = 0;
@@ -322,7 +375,11 @@ xen_vcputime_systime_ns(void)
 	 * (2^64 ns is approximately half a millennium.)
 	 */
 	if (__predict_false(systime_ns < raw_systime_ns)) {
-#if XEN_CLOCK_DEBUG		/* XXX dtrace hook */
+		SDT_PROBE7(sdt, xen, clock, systime__wraparound,
+		raw_systime_ns, tsc_timestamp,
+		tsc_to_system_mul, tsc_shift, delta_ns, tsc,
+		systime_ns);
+#if XEN_CLOCK_DEBUG
 		printf("xen raw systime + tsc delta wrapped around:"
 		" %"PRIu64" + %"PRIu64" = %"PRIu64"\n",
 		raw_systime_ns, delta_ns, systime_ns);
@@ -336,7 +393,11 @@ xen_vcputime_systime_ns(void)
 	 * forward.  This seems to happen pretty regularly under load.
 	 */
 	if (__predict_false(ci->ci_xen_last_systime_ns > systime_ns)) {
-#if XEN_CLOCK_DEBUG		/* XXX dtrace hook */
+		SDT_PROBE7(sdt, xen, clock, systime__backward,
+		raw_systime_ns, tsc_timestamp,
+		tsc_to_system_mul, tsc_shift, 

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

2023-05-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May  1 09:03:19 UTC 2023

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

Log Message:
xen_clock(4): Sprinkle dtrace probes.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:37:47 UTC 2023

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

Log Message:
xennetback(4): Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 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.111 src/sys/arch/xen/xen/xennetback_xenbus.c:1.112
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.111	Sat Feb 25 00:34:36 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Sat Feb 25 00:37:47 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.111 2023/02/25 00:34:36 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.112 2023/02/25 00:37:47 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.111 2023/02/25 00:34:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.112 2023/02/25 00:37:47 riastradh Exp $");
 
 #include 
 #include 
@@ -117,7 +117,7 @@ struct xnetback_instance {
 	grant_handle_t xni_tx_ring_handle; /* to unmap the ring */
 	grant_handle_t xni_rx_ring_handle;
 	vaddr_t xni_tx_ring_va; /* to unmap the ring */
-	vaddr_t xni_rx_ring_va; 
+	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];
@@ -782,7 +782,7 @@ xennetback_tx_m0len_fragment(struct xnet
 {
 	netif_tx_request_t *txreq;
 
-	/* This assumes all the requests are already pushed into the ring */ 
+	/* This assumes all the requests are already pushed into the ring */
 	*cntp = 1;
 	do {
 		txreq = RING_GET_REQUEST(>xni_txring, req_cons);
@@ -1269,7 +1269,7 @@ again:
 		 * here, as the frontend doesn't notify when adding
 		 * requests anyway
 		 */
-		if (__predict_false(abort || 
+		if (__predict_false(abort ||
 		!RING_HAS_UNCONSUMED_REQUESTS(>xni_rxring))) {
 			/* ring full */
 			ifp->if_timer = 1;



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:37:47 UTC 2023

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

Log Message:
xennetback(4): Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:35:52 UTC 2023

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

Log Message:
xengnt(4): Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 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.40 src/sys/arch/xen/xen/xengnt.c:1.41
--- src/sys/arch/xen/xen/xengnt.c:1.40	Sat Feb 25 00:33:50 2023
+++ src/sys/arch/xen/xen/xengnt.c	Sat Feb 25 00:35:52 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xengnt.c,v 1.40 2023/02/25 00:33:50 riastradh Exp $  */
+/*  $NetBSD: xengnt.c,v 1.41 2023/02/25 00:35:52 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.40 2023/02/25 00:33:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.41 2023/02/25 00:35:52 riastradh Exp $");
 
 #include 
 #include 
@@ -212,7 +212,7 @@ xengnt_suspend(void) {
 		/* invalidate all grant entries (necessary for resume) */
 		gnt_entries[i] = XENGNT_NO_ENTRY;
 	}
-	
+
 	/* Remove virtual => machine mapping for grant table */
 	pmap_kremove((vaddr_t)grant_table.gntt, gnt_nr_grant_frames * PAGE_SIZE);
 
@@ -450,7 +450,7 @@ xengnt_grant_access(domid_t dom, paddr_t
 		grant_table.gntt_v2[*entryp].full_page.frame = ma >> PAGE_SHIFT;
 		grant_table.gntt_v2[*entryp].hdr.domid = dom;
 		/*
-		 * ensure that the above values reach global visibility 
+		 * ensure that the above values reach global visibility
 		 * before permitting frame's access (done when we set flags)
 		 */
 		xen_wmb();
@@ -459,9 +459,9 @@ xengnt_grant_access(domid_t dom, paddr_t
 	} else {
 		grant_table.gntt_v1[*entryp].frame = ma >> PAGE_SHIFT;
 		grant_table.gntt_v1[*entryp].domid = dom;
-		/*  
+		/*
 		* ensure that the above values reach global visibility
-		* before permitting frame's access (done when we set flags)
+		* before permitting frame's access (done when we set flags)
 		*/
 		xen_wmb();
 		grant_table.gntt_v1[*entryp].flags =
@@ -472,7 +472,7 @@ xengnt_grant_access(domid_t dom, paddr_t
 }
 
 static inline uint16_t
-xen_atomic_cmpxchg16(volatile uint16_t *ptr, uint16_t  val, uint16_t newval) 
+xen_atomic_cmpxchg16(volatile uint16_t *ptr, uint16_t  val, uint16_t newval)
 {
 	unsigned long result;
 



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:35:52 UTC 2023

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

Log Message:
xengnt(4): Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:35:40 UTC 2023

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

Log Message:
xencons(4): Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 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/xencons.c
diff -u src/sys/arch/xen/xen/xencons.c:1.52 src/sys/arch/xen/xen/xencons.c:1.53
--- src/sys/arch/xen/xen/xencons.c:1.52	Sat Feb 25 00:33:38 2023
+++ src/sys/arch/xen/xen/xencons.c	Sat Feb 25 00:35:40 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: xencons.c,v 1.52 2023/02/25 00:33:38 riastradh Exp $	*/
+/*	$NetBSD: xencons.c,v 1.53 2023/02/25 00:35:40 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xencons.c,v 1.52 2023/02/25 00:33:38 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xencons.c,v 1.53 2023/02/25 00:35:40 riastradh Exp $");
 
 #include "opt_xen.h"
 
@@ -82,10 +82,10 @@ __KERNEL_RCSID(0, "$NetBSD: xencons.c,v 
 #endif
 
 #undef XENDEBUG
- 
+
 #ifdef XENDEBUG
 #define XENPRINTK(x) printk x
-#else 
+#else
 #define XENPRINTK(x)
 #endif
 
@@ -127,7 +127,7 @@ const struct cdevsw xencons_cdevsw = {
 	.d_close = xencons_close,
 	.d_read = xencons_read,
 	.d_write = xencons_write,
-	.d_ioctl = xencons_ioctl, 
+	.d_ioctl = xencons_ioctl,
 	.d_stop = xencons_stop,
 	.d_tty = xencons_tty,
 	.d_poll = xencons_poll,
@@ -328,7 +328,7 @@ xencons_poll(dev_t dev, int events, stru
 	struct xencons_softc *sc = device_lookup_private(_cd,
 	XENCONS_UNIT(dev));
 	struct tty *tp = sc->sc_tty;
- 
+
 	return ((*tp->t_linesw->l_poll)(tp, events, l));
 }
 
@@ -442,7 +442,7 @@ xencons_stop(struct tty *tp, int flag)
 }
 
 /* Non-privileged console interrupt routine */
-static int 
+static int
 xencons_handler(void *arg)
 {
 	struct xencons_softc *sc = arg;
@@ -453,7 +453,7 @@ xencons_handler(void *arg)
 		splx(s);
 		return 1;
 	}
-		
+
 
 #define XNC_IN (xencons_interface->in)
 



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:35:40 UTC 2023

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

Log Message:
xencons(4): Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:35:28 UTC 2023

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

Log Message:
xbdback(4): Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 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.102 src/sys/arch/xen/xen/xbdback_xenbus.c:1.103
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.102	Sat Feb 25 00:33:15 2023
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Sat Feb 25 00:35:28 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.102 2023/02/25 00:33:15 riastradh Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.103 2023/02/25 00:35:28 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.102 2023/02/25 00:33:15 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.103 2023/02/25 00:35:28 riastradh Exp $");
 
 #include 
 #include 
@@ -105,7 +105,7 @@ typedef enum {WAITING, RUN, DISCONNECTIN
  * event channels, biointr() soft interrupts, xenbus commands), the xbdi_lock
  * mutex is used to protect specific elements of the xbdback instance from
  * concurrent access: thread status and ring access (when pushing responses).
- * 
+ *
  * Here's how the call graph is supposed to be for a single I/O:
  *
  * xbdback_co_main()
@@ -125,7 +125,7 @@ typedef enum {WAITING, RUN, DISCONNECTIN
  *| |
  *| xbdback_co_main_incr() -> xbdback_co_main_loop()
  *|
- * xbdback_co_do_io() 
+ * xbdback_co_do_io()
  *|
  * xbdback_co_main_incr() -> xbdback_co_main_loop()
  */
@@ -210,7 +210,7 @@ struct xbdback_instance {
 	vaddr_t xbdi_ring_va; /* to unmap the ring */
 	/* disconnection must be postponed until all I/O is done */
 	int xbdi_refcnt;
-	/* 
+	/*
 	 * State for I/O processing/coalescing follows; this has to
 	 * live here instead of on the stack because of the
 	 * continuation-ness (see above).
@@ -361,7 +361,7 @@ xbdback_xenbus_create(struct xenbus_devi
 	mutex_init(>xbdi_lock, MUTEX_DEFAULT, IPL_BIO);
 	cv_init(>xbdi_cv, xbdi->xbdi_name);
 
-	xbusd->xbusd_u.b.b_cookie = xbdi;	
+	xbusd->xbusd_u.b.b_cookie = xbdi;
 	xbusd->xbusd_u.b.b_detach = xbdback_xenbus_destroy;
 	xbusd->xbusd_otherend_changed = xbdback_frontend_changed;
 	xbdi->xbdi_xbusd = xbusd;
@@ -615,7 +615,7 @@ err1:
 static void
 xbdback_disconnect(struct xbdback_instance *xbdi)
 {
-	
+
 	mutex_enter(>xbdi_lock);
 	if (xbdi->xbdi_status == DISCONNECTED) {
 		mutex_exit(>xbdi_lock);
@@ -759,7 +759,7 @@ xbdback_backend_changed(struct xenbus_wa
 		/* If both Ioctls failed set device size to 0 and return */
 		printf("xbdback %s: can't DIOCGWEDGEINFO device "
 		"0x%"PRIx64": %d\n", xbusd->xbusd_path,
-		xbdi->xbdi_dev, err);		
+		xbdi->xbdi_dev, err);
 		xbdi->xbdi_size = xbdi->xbdi_dev = 0;
 		vn_close(xbdi->xbdi_vp, FREAD, NOCRED);
 		xbdi->xbdi_vp = NULL;
@@ -901,7 +901,7 @@ xbdback_thread(void *arg)
 cv_wait(>xbdi_cv, >xbdi_lock);
 continue;
 			}
-			
+
 			/* All I/Os should have been processed by now,
 			 * xbdi_refcnt should drop to 0 */
 			xbdi_put(xbdi);
@@ -941,7 +941,7 @@ xbdback_co_main(struct xbdback_instance 
  * the ring.
  */
 static void *
-xbdback_co_main_loop(struct xbdback_instance *xbdi, void *obj __unused) 
+xbdback_co_main_loop(struct xbdback_instance *xbdi, void *obj __unused)
 {
 	blkif_request_t *req, *reqn;
 	blkif_x86_32_request_t *req32;
@@ -1115,7 +1115,7 @@ xbdback_co_cache_doflush(struct xbdback_
  */
 static void *
 xbdback_co_io(struct xbdback_instance *xbdi, void *obj __unused)
-{	
+{
 	int i, error;
 	blkif_request_t *req, *reqn;
 	blkif_x86_32_request_t *req32;
@@ -1242,7 +1242,7 @@ xbdback_co_io_gotio(struct xbdback_insta
 
 	xbdi_get(xbdi);
 	xbdi->xbdi_pendingreqs++;
-	
+
 	req = >xbdi_xen_req;
 	xbd_io = obj;
 	memset(xbd_io, 0, sizeof(*xbd_io));
@@ -1432,7 +1432,7 @@ xbdback_iodone_locked(struct xbdback_ins
 		status = BLKIF_RSP_ERROR;
 	} else
 		status = BLKIF_RSP_OKAY;
-	
+
 	xbdback_send_reply(xbdi, xbd_io->xio_id, xbd_io->xio_operation, status);
 
 	xbdi_put(xbdi);
@@ -1536,7 +1536,7 @@ xbdback_map_shm(struct xbdback_io *xbd_i
 	xbd_io->xio_vaddr = xbd_io->xio_xv->xv_vaddr;
 
 	error = xen_shm_map(xbd_io->xio_nrma, xbdi->xbdi_domid,
-	xbd_io->xio_gref, xbd_io->xio_vaddr, xbd_io->xio_gh, 
+	xbd_io->xio_gref, xbd_io->xio_vaddr, xbd_io->xio_gh,
 	(xbd_io->xio_operation == BLKIF_OP_WRITE) ? XSHM_RO : 0);
 
 	switch(error) {



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:35:28 UTC 2023

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

Log Message:
xbdback(4): Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:35:15 UTC 2023

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

Log Message:
xbd(4): Nix trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 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.130 src/sys/arch/xen/xen/xbd_xenbus.c:1.131
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.130	Sat Feb 25 00:33:03 2023
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Sat Feb 25 00:35:15 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.130 2023/02/25 00:33:03 riastradh Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.131 2023/02/25 00:35:15 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.130 2023/02/25 00:33:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.131 2023/02/25 00:35:15 riastradh Exp $");
 
 #include "opt_xen.h"
 
@@ -99,7 +99,7 @@ __KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c
 #define XBD_XFER_LIMIT	(2*XBD_MAX_XFER)
 
 #define XEN_BSHIFT  9   /* log2(XEN_BSIZE) */
-#define XEN_BSIZE   (1 << XEN_BSHIFT) 
+#define XEN_BSIZE   (1 << XEN_BSHIFT)
 
 CTASSERT((MAXPHYS <= 2*XBD_MAX_CHUNK));
 CTASSERT(XEN_BSIZE == DEV_BSIZE);
@@ -676,7 +676,7 @@ xbd_backend_changed(void *arg, XenbusSta
 		sc->sc_xbdsize =
 		sc->sc_sectors * (uint64_t)sc->sc_secsize / DEV_BSIZE;
 		dg = >sc_dksc.sc_dkdev.dk_geom;
-		memset(dg, 0, sizeof(*dg));	
+		memset(dg, 0, sizeof(*dg));
 
 		dg->dg_secperunit = sc->sc_xbdsize;
 		dg->dg_secsize = DEV_BSIZE;
@@ -736,13 +736,13 @@ xbd_connect(struct xbd_xenbus_softc *sc)
 	err = xenbus_read_ul(NULL,
 	sc->sc_xbusd->xbusd_path, "virtual-device", >sc_handle, 10);
 	if (err)
-		panic("%s: can't read number from %s/virtual-device\n", 
+		panic("%s: can't read number from %s/virtual-device\n",
 		device_xname(sc->sc_dksc.sc_dev),
 		sc->sc_xbusd->xbusd_otherend);
 	err = xenbus_read_ull(NULL,
 	sc->sc_xbusd->xbusd_otherend, "sectors", , 10);
 	if (err)
-		panic("%s: can't read number from %s/sectors\n", 
+		panic("%s: can't read number from %s/sectors\n",
 		device_xname(sc->sc_dksc.sc_dev),
 		sc->sc_xbusd->xbusd_otherend);
 	sc->sc_sectors = sectors;
@@ -750,13 +750,13 @@ xbd_connect(struct xbd_xenbus_softc *sc)
 	err = xenbus_read_ul(NULL,
 	sc->sc_xbusd->xbusd_otherend, "info", >sc_info, 10);
 	if (err)
-		panic("%s: can't read number from %s/info\n", 
+		panic("%s: can't read number from %s/info\n",
 		device_xname(sc->sc_dksc.sc_dev),
 		sc->sc_xbusd->xbusd_otherend);
 	err = xenbus_read_ul(NULL,
 	sc->sc_xbusd->xbusd_otherend, "sector-size", >sc_secsize, 10);
 	if (err)
-		panic("%s: can't read number from %s/sector-size\n", 
+		panic("%s: can't read number from %s/sector-size\n",
 		device_xname(sc->sc_dksc.sc_dev),
 		sc->sc_xbusd->xbusd_otherend);
 
@@ -934,7 +934,7 @@ 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. 
+	 * so that it uses as little memory as possible.
 	 */
 	if (*maxxfer > XBD_MAX_XFER)
 		*maxxfer = XBD_MAX_XFER;
@@ -1008,7 +1008,7 @@ xbdsize(dev_t dev)
 static int
 xbdread(dev_t dev, struct uio *uio, int flags)
 {
-	struct xbd_xenbus_softc *sc = 
+	struct xbd_xenbus_softc *sc =
 	device_lookup_private(_cd, DISKUNIT(dev));
 	struct  dk_softc *dksc = >sc_dksc;
 
@@ -1277,7 +1277,7 @@ xbd_diskstart_submit(struct xbd_xenbus_s
 	req->sector_number = bp->b_rawblkno + (start >> XEN_BSHIFT);
 	req->handle = sc->sc_handle;
 
-	size = uimin(bp->b_bcount - start, XBD_MAX_CHUNK); 
+	size = uimin(bp->b_bcount - start, XBD_MAX_CHUNK);
 	for (dmaseg = 0; dmaseg < dmamap->dm_nsegs && size > 0; dmaseg++) {
 		bus_dma_segment_t *ds = >dm_segs[dmaseg];
 



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:35:15 UTC 2023

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

Log Message:
xbd(4): Nix trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:34:36 UTC 2023

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

Log Message:
xennetback(4): Omit needless membars in xennetback_connect.

xneti is a private data structure to which we have exclusive access
here; ordering the stores doesn't make sense.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 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.110 src/sys/arch/xen/xen/xennetback_xenbus.c:1.111
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.110	Sat Feb 25 00:34:25 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Sat Feb 25 00:34:36 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.110 2023/02/25 00:34:25 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.111 2023/02/25 00:34:36 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.110 2023/02/25 00:34:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.111 2023/02/25 00:34:36 riastradh Exp $");
 
 #include 
 #include 
@@ -497,9 +497,7 @@ xennetback_connect(struct xnetback_insta
 		goto err2;
 	}
 	xneti->xni_evtchn = evop.u.bind_interdomain.local_port;
-	xen_wmb();
 	xneti->xni_status = CONNECTED;
-	xen_wmb();
 
 	xneti->xni_ih = xen_intr_establish_xname(-1, _pic,
 	xneti->xni_evtchn, IST_LEVEL, IPL_NET, xennetback_evthandler,



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:34:36 UTC 2023

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

Log Message:
xennetback(4): Omit needless membars in xennetback_connect.

xneti is a private data structure to which we have exclusive access
here; ordering the stores doesn't make sense.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:34:25 UTC 2023

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

Log Message:
xennetback(4): Fix membars in xennetback_rx_copy_process.

- No need for barrier around touching req_cons and rsp_prod_pvt,
  which are private.

- RING_PUSH_RESPONSES_AND_CHECK_NOTIFY already issues xen_wmb, no
  need to add one explicitly.

- After pushing responses, must issue xen_wmb (not xen_rmb) before
  hypervisor_notify_via_evtchn.


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 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.109 src/sys/arch/xen/xen/xennetback_xenbus.c:1.110
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.109	Sat Feb 25 00:34:13 2023
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Sat Feb 25 00:34:25 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.109 2023/02/25 00:34:13 riastradh Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.110 2023/02/25 00:34:25 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.109 2023/02/25 00:34:13 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.110 2023/02/25 00:34:25 riastradh Exp $");
 
 #include 
 #include 
@@ -1022,14 +1022,13 @@ xennetback_rx_copy_process(struct ifnet 
 	}
 
 	/* 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();
+		xen_wmb();
 		XENPRINTF(("%s receive event\n",
 		xneti->xni_if.if_xname));
 		hypervisor_notify_via_evtchn(xneti->xni_evtchn);



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:34:25 UTC 2023

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

Log Message:
xennetback(4): Fix membars in xennetback_rx_copy_process.

- No need for barrier around touching req_cons and rsp_prod_pvt,
  which are private.

- RING_PUSH_RESPONSES_AND_CHECK_NOTIFY already issues xen_wmb, no
  need to add one explicitly.

- After pushing responses, must issue xen_wmb (not xen_rmb) before
  hypervisor_notify_via_evtchn.


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:34:13 UTC 2023

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

Log Message:
xennetback(4): Fix xennetback_evthandler loop.

- After observing the other side has produced pending tx requests by
  reading sring->req_prod, must issue xen_rmb before touching them.

  Despite all the effort to use the heavy-weight
  RING_FINAL_CHECK_FOR_REQUESTS on each request in the loop, this
  barrier was missing.

- No need to update req_cons at each iteration in the loop.  It's
  private.  Just update it once at the end.

- After consuming requests, must issue xen_wmb before releasing the
  slots with RING_FINAL_CHECK_FOR_REQUEST for the other side to
  reuse.

XXX pullup-8 (requires patch; at least add xen_rmb between
RING_FINAL_CHECK_FOR_REQUESTS and RING_COPY_REQUEST)
XXX pullup-9 (requires patch; at least add xen_rmb between
RING_FINAL_CHECK_FOR_REQUESTS and RING_COPY_REQUEST)
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 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.108 src/sys/arch/xen/xen/xennetback_xenbus.c:1.109
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.108	Fri Sep  2 23:48:10 2022
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Sat Feb 25 00:34:13 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.108 2022/09/02 23:48:10 thorpej Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.109 2023/02/25 00:34:13 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.108 2022/09/02 23:48:10 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.109 2023/02/25 00:34:13 riastradh Exp $");
 
 #include 
 #include 
@@ -805,7 +805,7 @@ xennetback_evthandler(void *arg)
 	netif_tx_request_t txreq;
 	struct mbuf *m, *m0 = NULL, *mlast = NULL;
 	int receive_pending;
-	RING_IDX req_cons;
+	RING_IDX req_cons, req_prod;
 	int queued = 0, m0_len = 0;
 	struct xnetback_xstate *xst;
 	const bool discard = ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) !=
@@ -813,17 +813,12 @@ xennetback_evthandler(void *arg)
 
 	XENPRINTF(("xennetback_evthandler "));
 	req_cons = xneti->xni_txring.req_cons;
-	while (1) {
-		xen_rmb(); /* be sure to read the request before updating */
-		xneti->xni_txring.req_cons = req_cons;
-		xen_wmb();
-		RING_FINAL_CHECK_FOR_REQUESTS(>xni_txring,
-		receive_pending);
-		if (receive_pending == 0)
-			break;
+again:
+	req_prod = xneti->xni_txring.sring->req_prod;
+	xen_rmb();
+	while (req_cons != req_prod) {
 		RING_COPY_REQUEST(>xni_txring, req_cons,
 		);
-		xen_rmb();
 		XENPRINTF(("%s pkt size %d\n", xneti->xni_if.if_xname,
 		txreq.size));
 		req_cons++;
@@ -962,6 +957,12 @@ mbuf_fail:
 			queued = 0;
 		}
 	}
+	xen_wmb();
+	RING_FINAL_CHECK_FOR_REQUESTS(>xni_txring, receive_pending);
+	if (receive_pending)
+		goto again;
+	xneti->xni_txring.req_cons = req_cons;
+
 	if (m0) {
 		/* Queue empty, and still unfinished multi-fragment request */
 		printf("%s: dropped unfinished multi-fragment\n",



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:34:13 UTC 2023

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

Log Message:
xennetback(4): Fix xennetback_evthandler loop.

- After observing the other side has produced pending tx requests by
  reading sring->req_prod, must issue xen_rmb before touching them.

  Despite all the effort to use the heavy-weight
  RING_FINAL_CHECK_FOR_REQUESTS on each request in the loop, this
  barrier was missing.

- No need to update req_cons at each iteration in the loop.  It's
  private.  Just update it once at the end.

- After consuming requests, must issue xen_wmb before releasing the
  slots with RING_FINAL_CHECK_FOR_REQUEST for the other side to
  reuse.

XXX pullup-8 (requires patch; at least add xen_rmb between
RING_FINAL_CHECK_FOR_REQUESTS and RING_COPY_REQUEST)
XXX pullup-9 (requires patch; at least add xen_rmb between
RING_FINAL_CHECK_FOR_REQUESTS and RING_COPY_REQUEST)
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:33:50 UTC 2023

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

Log Message:
xengnt(4): Membar audit.

This had the sense of membars reversed, presumably because xen_rmb
and xen_wmb had gotten reversed at some point.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 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.39 src/sys/arch/xen/xen/xengnt.c:1.40
--- src/sys/arch/xen/xen/xengnt.c:1.39	Fri Jun  3 10:42:17 2022
+++ src/sys/arch/xen/xen/xengnt.c	Sat Feb 25 00:33:50 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xengnt.c,v 1.39 2022/06/03 10:42:17 bouyer Exp $  */
+/*  $NetBSD: xengnt.c,v 1.40 2023/02/25 00:33:50 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.39 2022/06/03 10:42:17 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.40 2023/02/25 00:33:50 riastradh Exp $");
 
 #include 
 #include 
@@ -453,7 +453,7 @@ xengnt_grant_access(domid_t dom, paddr_t
 		 * ensure that the above values reach global visibility 
 		 * before permitting frame's access (done when we set flags)
 		 */
-		xen_rmb();
+		xen_wmb();
 		grant_table.gntt_v2[*entryp].hdr.flags =
 		GTF_permit_access | (ro ? GTF_readonly : 0);
 	} else {
@@ -463,8 +463,8 @@ xengnt_grant_access(domid_t dom, paddr_t
 		* ensure that the above values reach global visibility
 		* before permitting frame's access (done when we set flags)
 		*/
-		xen_rmb();
-		grant_table.gntt_v1[*entryp].flags =  
+		xen_wmb();
+		grant_table.gntt_v1[*entryp].flags =
 		   GTF_permit_access | (ro ? GTF_readonly : 0);
 	}
 	mutex_exit(_lock);



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:33:50 UTC 2023

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

Log Message:
xengnt(4): Membar audit.

This had the sense of membars reversed, presumably because xen_rmb
and xen_wmb had gotten reversed at some point.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:33:39 UTC 2023

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

Log Message:
xencons(4): Reduce unnecessary membars.

- xencons_handler: After advancing in_cons, only need one xen_wmb
  before notifying the hypervisor that we're ready for more.

  (XXX Should this do xen_mb and re-check in_prod at that point, or
  does hypervisor_notify_via_evtchn obviate the need for this?)

- xenvonscn_getc: After reading in_prod, only need one xen_rmb before
  using the slots it is telling us are now ready.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:33:39 UTC 2023

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

Log Message:
xencons(4): Reduce unnecessary membars.

- xencons_handler: After advancing in_cons, only need one xen_wmb
  before notifying the hypervisor that we're ready for more.

  (XXX Should this do xen_mb and re-check in_prod at that point, or
  does hypervisor_notify_via_evtchn obviate the need for this?)

- xenvonscn_getc: After reading in_prod, only need one xen_rmb before
  using the slots it is telling us are now ready.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 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/xencons.c
diff -u src/sys/arch/xen/xen/xencons.c:1.51 src/sys/arch/xen/xen/xencons.c:1.52
--- src/sys/arch/xen/xen/xencons.c:1.51	Sat Feb 25 00:33:27 2023
+++ src/sys/arch/xen/xen/xencons.c	Sat Feb 25 00:33:38 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: xencons.c,v 1.51 2023/02/25 00:33:27 riastradh Exp $	*/
+/*	$NetBSD: xencons.c,v 1.52 2023/02/25 00:33:38 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xencons.c,v 1.51 2023/02/25 00:33:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xencons.c,v 1.52 2023/02/25 00:33:38 riastradh Exp $");
 
 #include "opt_xen.h"
 
@@ -479,9 +479,9 @@ xencons_handler(void *arg)
 			cons += len;
 			xen_wmb();
 			xencons_interface->in_cons = cons;
-			xen_wmb();
 		}
 	}
+	xen_wmb();
 	hypervisor_notify_via_evtchn(xen_start_info.console.domU.evtchn);
 	splx(s);
 	return 1;
@@ -575,7 +575,6 @@ xenconscn_getc(dev_t dev)
 
 	cons = xencons_interface->in_cons;
 	prod = xencons_interface->in_prod;
-	xen_rmb();
 	while (cons == prod) {
 		HYPERVISOR_yield();
 		prod = xencons_interface->in_prod;



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:33:27 UTC 2023

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

Log Message:
xencons(4): Membar audit.

- xenconscn_getc: Once we have consumed an input slot, it is clearer
  to issue xen_wmb (release, i.e., load/store-before-store) before
  advancing in_cons so that the update becomes a store-release
  freeing the input slot for the other side to reuse.

- xenconscn_putc: After filling an output slot, must issue xen_wmb
  (release, i.e., load/store-before-store) before advancing out_prod,
  and another one before notifying the other side of the advance.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:33:27 UTC 2023

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

Log Message:
xencons(4): Membar audit.

- xenconscn_getc: Once we have consumed an input slot, it is clearer
  to issue xen_wmb (release, i.e., load/store-before-store) before
  advancing in_cons so that the update becomes a store-release
  freeing the input slot for the other side to reuse.

- xenconscn_putc: After filling an output slot, must issue xen_wmb
  (release, i.e., load/store-before-store) before advancing out_prod,
  and another one before notifying the other side of the advance.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 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/xencons.c
diff -u src/sys/arch/xen/xen/xencons.c:1.50 src/sys/arch/xen/xen/xencons.c:1.51
--- src/sys/arch/xen/xen/xencons.c:1.50	Thu May  7 19:25:57 2020
+++ src/sys/arch/xen/xen/xencons.c	Sat Feb 25 00:33:27 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: xencons.c,v 1.50 2020/05/07 19:25:57 maxv Exp $	*/
+/*	$NetBSD: xencons.c,v 1.51 2023/02/25 00:33:27 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xencons.c,v 1.50 2020/05/07 19:25:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xencons.c,v 1.51 2023/02/25 00:33:27 riastradh Exp $");
 
 #include "opt_xen.h"
 
@@ -583,7 +583,7 @@ xenconscn_getc(dev_t dev)
 	xen_rmb();
 	c = xencons_interface->in[MASK_XENCONS_IDX(xencons_interface->in_cons,
 	xencons_interface->in)];
-	xen_rmb();
+	xen_wmb();
 	xencons_interface->in_cons = cons + 1;
 	cn_check_magic(dev, c, xencons_cnm_state);
 	splx(s);
@@ -614,9 +614,9 @@ xenconscn_putc(dev_t dev, int c)
 		}
 		xencons_interface->out[MASK_XENCONS_IDX(xencons_interface->out_prod,
 		xencons_interface->out)] = c;
-		xen_rmb();
+		xen_wmb();
 		xencons_interface->out_prod++;
-		xen_rmb();
+		xen_wmb();
 		hypervisor_notify_via_evtchn(xen_start_info.console.domU.evtchn);
 		splx(s);
 	}



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:33:15 UTC 2023

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

Log Message:
xbdback(4): Membar audit.

After consuming request slots, must issue xen_wmb notifying the other
side that we've consumed them in RING_FINAL_CHECK_FOR_REQUESTS.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:33:15 UTC 2023

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

Log Message:
xbdback(4): Membar audit.

After consuming request slots, must issue xen_wmb notifying the other
side that we've consumed them in RING_FINAL_CHECK_FOR_REQUESTS.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 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.101 src/sys/arch/xen/xen/xbdback_xenbus.c:1.102
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.101	Thu Sep  1 15:33:23 2022
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Sat Feb 25 00:33:15 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.101 2022/09/01 15:33:23 bouyer Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.102 2023/02/25 00:33:15 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.101 2022/09/01 15:33:23 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.102 2023/02/25 00:33:15 riastradh Exp $");
 
 #include 
 #include 
@@ -1065,6 +1065,7 @@ xbdback_co_main_done2(struct xbdback_ins
 {
 	int work_to_do;
 
+	xen_wmb();
 	RING_FINAL_CHECK_FOR_REQUESTS(>xbdi_ring.ring_n, work_to_do);
 	if (work_to_do)
 		xbdi->xbdi_cont = xbdback_co_main;



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:33:04 UTC 2023

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

Log Message:
xbd(4): Membar audit.

After consuming slots, must issue xen_wmb before notifying the other
side that we've consumed them in RING_FINAL_CHECK_FOR_RESPONSES.


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 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.129 src/sys/arch/xen/xen/xbd_xenbus.c:1.130
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.129	Mon Jul 13 21:21:56 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Sat Feb 25 00:33:03 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.129 2020/07/13 21:21:56 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.130 2023/02/25 00:33:03 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.129 2020/07/13 21:21:56 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.130 2023/02/25 00:33:03 riastradh Exp $");
 
 #include "opt_xen.h"
 
@@ -905,10 +905,9 @@ again:
 		}
 		SLIST_INSERT_HEAD(>sc_xbdreq_head, xbdreq, req_next);
 	}
-
-	xen_rmb();
 	sc->sc_ring.rsp_cons = i;
 
+	xen_wmb();
 	RING_FINAL_CHECK_FOR_RESPONSES(>sc_ring, more_to_do);
 	if (more_to_do)
 		goto again;



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:33:04 UTC 2023

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

Log Message:
xbd(4): Membar audit.

After consuming slots, must issue xen_wmb before notifying the other
side that we've consumed them in RING_FINAL_CHECK_FOR_RESPONSES.


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:32:49 UTC 2023

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

Log Message:
xennet(4): Membar audit.

- xennet_tx_complete: Other side owns rsp_prod, giving us responses
  to tx commands.  We own rsp_cons, recording which responess we've
  processed already.

  1. Other side initializes responses before advancing rsp_prod, so
 we must observe rsp_prod before trying to examine the responses.
 Hence load from rsp_prod must be followed by xen_rmb.

 (Can this just use atomic_load_acquire?)

  2. As soon as other side observes rsp_event, it may start to
 overwrite now-unused response slots, so we must finish using the
 response before advancing rsp_cons.  Hence we must issue xen_wmb
 before store to rsp_event.

 (Can this just use atomic_store_release?)

 (Should this use RING_FINAL_CHECK_FOR_RESPONSES?)

  3. When loop is done and we set rsp_event, we must ensure the other
 side has had a chance to see that we want more before we check
 whether there is more to consume; otherwise the other side might
 not bother to send us an interrupt.  Hence after setting
 rsp_event, we must issue xen_mb (store-before-load) before
 re-checking rsp_prod.

- xennet_handler (rx): Same deal, except the xen_mb is buried in
  RING_FINAL_CHECK_FOR_RESPONSES.  Unclear why xennet_tx_complete has
  this open-coded while xennet_handler (rx) uses the macro.

XXX pullup-8 (at least the xen_mb part; requires patch)
XXX pullup-9 (at least the xen_mb part; requires patch)
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 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.



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

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:32:49 UTC 2023

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

Log Message:
xennet(4): Membar audit.

- xennet_tx_complete: Other side owns rsp_prod, giving us responses
  to tx commands.  We own rsp_cons, recording which responess we've
  processed already.

  1. Other side initializes responses before advancing rsp_prod, so
 we must observe rsp_prod before trying to examine the responses.
 Hence load from rsp_prod must be followed by xen_rmb.

 (Can this just use atomic_load_acquire?)

  2. As soon as other side observes rsp_event, it may start to
 overwrite now-unused response slots, so we must finish using the
 response before advancing rsp_cons.  Hence we must issue xen_wmb
 before store to rsp_event.

 (Can this just use atomic_store_release?)

 (Should this use RING_FINAL_CHECK_FOR_RESPONSES?)

  3. When loop is done and we set rsp_event, we must ensure the other
 side has had a chance to see that we want more before we check
 whether there is more to consume; otherwise the other side might
 not bother to send us an interrupt.  Hence after setting
 rsp_event, we must issue xen_mb (store-before-load) before
 re-checking rsp_prod.

- xennet_handler (rx): Same deal, except the xen_mb is buried in
  RING_FINAL_CHECK_FOR_RESPONSES.  Unclear why xennet_tx_complete has
  this open-coded while xennet_handler (rx) uses the macro.

XXX pullup-8 (at least the xen_mb part; requires patch)
XXX pullup-9 (at least the xen_mb part; requires patch)
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 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.128 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.129
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.128	Wed Aug 26 15:54:10 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Sat Feb 25 00:32:49 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.128 2020/08/26 15:54:10 riastradh Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.129 2023/02/25 00:32:49 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.128 2020/08/26 15:54:10 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.129 2023/02/25 00:32:49 riastradh Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -951,12 +951,12 @@ again:
 		SLIST_INSERT_HEAD(>sc_txreq_head, req, txreq_next);
 		sc->sc_free_txreql++;
 	}
-
 	sc->sc_tx_ring.rsp_cons = resp_prod;
 	/* set new event and check for race with rsp_cons update */
+	xen_wmb();
 	sc->sc_tx_ring.sring->rsp_event =
 	resp_prod + ((sc->sc_tx_ring.sring->req_prod - resp_prod) >> 1) + 1;
-	xen_wmb();
+	xen_mb();
 	if (resp_prod != sc->sc_tx_ring.sring->rsp_prod)
 		goto again;
 }
@@ -1060,8 +1060,8 @@ again:
 		if_statinc(ifp, if_iqdrops);
 		m_freem(m0);
 	}
-	xen_rmb();
 	sc->sc_rx_ring.rsp_cons = i;
+	xen_wmb();
 	RING_FINAL_CHECK_FOR_RESPONSES(>sc_rx_ring, more_to_do);
 	mutex_exit(>sc_rx_lock);
 



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

2022-09-22 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep 22 16:21:34 UTC 2022

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

Log Message:
Fix fallout from previous: ci_ipending is in the low bytes of ci_istate,
so we should not left-shift by 8 the ci_ipending value we want to add there.
Should fix KASSERT in Xen's idle_block() reported by Frank Kardel in private
mail.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 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.



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

2022-09-22 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep 22 16:21:34 UTC 2022

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

Log Message:
Fix fallout from previous: ci_ipending is in the low bytes of ci_istate,
so we should not left-shift by 8 the ci_ipending value we want to add there.
Should fix KASSERT in Xen's idle_block() reported by Frank Kardel in private
mail.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 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.67 src/sys/arch/xen/xen/xenevt.c:1.68
--- src/sys/arch/xen/xen/xenevt.c:1.67	Wed Sep  7 00:40:19 2022
+++ src/sys/arch/xen/xen/xenevt.c	Thu Sep 22 16:21:34 2022
@@ -1,4 +1,4 @@
-/*  $NetBSD: xenevt.c,v 1.67 2022/09/07 00:40:19 knakahara Exp $  */
+/*  $NetBSD: xenevt.c,v 1.68 2022/09/22 16:21:34 bouyer Exp $  */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.67 2022/09/07 00:40:19 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.68 2022/09/22 16:21:34 bouyer Exp $");
 
 #include "opt_xen.h"
 #include 
@@ -210,7 +210,7 @@ xenevt_setipending(int l1, int l2)
 	KASSERT(xenevt_ih->ih_cpu->ci_ilevel >= IPL_HIGH);
 	atomic_or_ulong(_ev1, 1UL << l1);
 	atomic_or_ulong(_ev2[l1], 1UL << l2);
-	atomic_or_64(_ih->ih_cpu->ci_istate, (1ULL << SIR_XENIPL_HIGH) << 8);
+	atomic_or_64(_ih->ih_cpu->ci_istate, (1ULL << SIR_XENIPL_HIGH));
 	atomic_add_int(_ih->ih_pending, 1);
 	evtsource[xenevt_ev]->ev_evcnt.ev_count++;
 }



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

2022-09-04 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sun Sep  4 11:20:33 UTC 2022

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

Log Message:
Release mutexes earlier in xenevt_free(), to call *destroy and kmem_free
without holding spin locks. Fixes an occasional deadlock seen when the qemu
backing a HVM domU exits.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 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.65 src/sys/arch/xen/xen/xenevt.c:1.66
--- src/sys/arch/xen/xen/xenevt.c:1.65	Fri May 27 18:35:38 2022
+++ src/sys/arch/xen/xen/xenevt.c	Sun Sep  4 11:20:33 2022
@@ -1,4 +1,4 @@
-/*  $NetBSD: xenevt.c,v 1.65 2022/05/27 18:35:38 bouyer Exp $  */
+/*  $NetBSD: xenevt.c,v 1.66 2022/09/04 11:20:33 bouyer Exp $  */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.65 2022/05/27 18:35:38 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.66 2022/09/04 11:20:33 bouyer Exp $");
 
 #include "opt_xen.h"
 #include 
@@ -278,8 +278,7 @@ xenevt_notify(void)
 		d->pending = false;
 		mutex_enter(>lock);
 		if (d->flags & XENEVT_F_FREE) {
-			xenevt_free(d);
-			mutex_exit(_lock);
+			xenevt_free(d); /* releases devevent_lock */
 		} else {
 			mutex_exit(_lock);
 			selnotify(>sel, 0, 1);
@@ -402,7 +401,6 @@ xenevt_free(struct xenevt_d *d)
 			hypervisor_mask_event(i);
 			xen_atomic_clear_bit(>ci->ci_evtmask[0], i);
 			devevent[i] = NULL;
-
 			op.cmd = EVTCHNOP_close;
 			op.u.close.port = i;
 			if ((error = HYPERVISOR_event_channel_op())) {
@@ -412,6 +410,7 @@ xenevt_free(struct xenevt_d *d)
 		}
 	}
 	mutex_exit(>lock);
+	mutex_exit(_lock);
 	seldestroy(>sel);
 	cv_destroy(>cv);
 	mutex_destroy(>lock);
@@ -428,11 +427,11 @@ xenevt_fclose(struct file *fp)
 	if (d->pending) {
 		d->flags |= XENEVT_F_FREE;
 		mutex_exit(>lock);
+		mutex_exit(_lock);
 	} else {
-		xenevt_free(d);
+		xenevt_free(d); /* releases devevent_lock */
 	}
 
-	mutex_exit(_lock);
 	fp->f_data = NULL;
 	return (0);
 }



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

2022-09-04 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sun Sep  4 11:20:33 UTC 2022

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

Log Message:
Release mutexes earlier in xenevt_free(), to call *destroy and kmem_free
without holding spin locks. Fixes an occasional deadlock seen when the qemu
backing a HVM domU exits.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 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.



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

2022-09-01 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Sep  2 05:09:49 UTC 2022

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

Log Message:
Fix the syntax of the non _LP64 code fragment to match that in the
_LP64 fragment, so hopefully 32 bit ports with XEN (i386) will
build again.


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

Please note 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/xenmem.c
diff -u src/sys/arch/xen/xen/xenmem.c:1.3 src/sys/arch/xen/xen/xenmem.c:1.4
--- src/sys/arch/xen/xen/xenmem.c:1.3	Thu Sep  1 16:28:08 2022
+++ src/sys/arch/xen/xen/xenmem.c	Fri Sep  2 05:09:49 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: xenmem.c,v 1.3 2022/09/01 16:28:08 bouyer Exp $ */
+/* $NetBSD: xenmem.c,v 1.4 2022/09/02 05:09:49 kre Exp $ */
 /*
  * Copyright (c) 2022 Manuel Bouyer.
  *
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenmem.c,v 1.3 2022/09/01 16:28:08 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenmem.c,v 1.4 2022/09/02 05:09:49 kre Exp $");
 
 #include 
 #include 
@@ -62,7 +62,7 @@ xenmem_alloc_pa(u_long size, u_long alig
 	);
 #else
 	error = extent_alloc(XENMEM_EX, size, align, 0,
-	waitok ? ((EX_WAITSPACE | EX_WAITOK) : EX_NOWAIT) | EX_MALLOCOK,
+	(waitok ? (EX_WAITSPACE | EX_WAITOK) : EX_NOWAIT) | EX_MALLOCOK,
 	);
 #endif
 	if (error) {



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

2022-09-01 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Sep  2 05:09:49 UTC 2022

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

Log Message:
Fix the syntax of the non _LP64 code fragment to match that in the
_LP64 fragment, so hopefully 32 bit ports with XEN (i386) will
build again.


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

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



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

2022-09-01 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep  1 16:28:08 UTC 2022

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

Log Message:
Call extent_alloc_subregion() with EX_MALLOCOK; under heavy I/O load we need
lots of them and the preallocatted extent descriptors are not enough.


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

Please note 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/xenmem.c
diff -u src/sys/arch/xen/xen/xenmem.c:1.2 src/sys/arch/xen/xen/xenmem.c:1.3
--- src/sys/arch/xen/xen/xenmem.c:1.2	Wed Aug 31 12:53:27 2022
+++ src/sys/arch/xen/xen/xenmem.c	Thu Sep  1 16:28:08 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: xenmem.c,v 1.2 2022/08/31 12:53:27 bouyer Exp $ */
+/* $NetBSD: xenmem.c,v 1.3 2022/09/01 16:28:08 bouyer Exp $ */
 /*
  * Copyright (c) 2022 Manuel Bouyer.
  *
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenmem.c,v 1.2 2022/08/31 12:53:27 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenmem.c,v 1.3 2022/09/01 16:28:08 bouyer Exp $");
 
 #include 
 #include 
@@ -57,11 +57,13 @@ xenmem_alloc_pa(u_long size, u_long alig
 #ifdef _LP64
 	/* allocate above the 4Gb range to not collide wit devices */
 	error = extent_alloc_subregion(XENMEM_EX, 0x1UL, MAXIOMEM,
-	size, align, 0, waitok ? (EX_WAITSPACE | EX_WAITOK) : EX_NOWAIT,
+	size, align, 0,
+	(waitok ? (EX_WAITSPACE | EX_WAITOK) : EX_NOWAIT) | EX_MALLOCOK,
 	);
 #else
 	error = extent_alloc(XENMEM_EX, size, align, 0,
-	waitok ? (EX_WAITSPACE | EX_WAITOK) : EX_NOWAIT, );
+	waitok ? ((EX_WAITSPACE | EX_WAITOK) : EX_NOWAIT) | EX_MALLOCOK,
+	);
 #endif
 	if (error) {
 		printf("xenmem_alloc_pa: failed %d\n", error);



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

2022-09-01 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep  1 16:28:08 UTC 2022

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

Log Message:
Call extent_alloc_subregion() with EX_MALLOCOK; under heavy I/O load we need
lots of them and the preallocatted extent descriptors are not enough.


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

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



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

2022-09-01 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep  1 15:33:23 UTC 2022

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

Log Message:
in backend drivers, use xen_shm_(un)map for the rings instead of inline,
mostly duplicate code.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/xen/xen/pciback.c
cvs rdiff -u -r1.100 -r1.101 src/sys/arch/xen/xen/xbdback_xenbus.c
cvs rdiff -u -r1.106 -r1.107 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/pciback.c
diff -u src/sys/arch/xen/xen/pciback.c:1.22 src/sys/arch/xen/xen/pciback.c:1.23
--- src/sys/arch/xen/xen/pciback.c:1.22	Thu Sep  1 12:29:00 2022
+++ src/sys/arch/xen/xen/pciback.c	Thu Sep  1 15:33:23 2022
@@ -1,4 +1,4 @@
-/*  $NetBSD: pciback.c,v 1.22 2022/09/01 12:29:00 bouyer Exp $  */
+/*  $NetBSD: pciback.c,v 1.23 2022/09/01 15:33:23 bouyer Exp $  */
 
 /*
  * Copyright (c) 2009 Manuel Bouyer.
@@ -26,10 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.22 2022/09/01 12:29:00 bouyer Exp $");
-
-#include "opt_xen.h"
-
+__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.23 2022/09/01 15:33:23 bouyer Exp $");
 
 #include 
 #include 
@@ -48,7 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: pciback.c,v 
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 
@@ -189,7 +186,6 @@ struct pb_xenbus_instance {
 	/* communication with the domU */
 unsigned int pbx_evtchn; /* our even channel */
 	struct intrhand *pbx_ih;
-paddr_t *pbx_sh_info_pa;
 struct xen_pci_sharedinfo *pbx_sh_info;
 struct xen_pci_op op;
 grant_handle_t pbx_shinfo_handle; /* to unmap shared page */
@@ -521,8 +517,6 @@ pciback_xenbus_destroy(void *arg)
 {
 	struct pb_xenbus_instance *pbxi = arg;
 	struct pciback_pci_dev *pbd;
-	struct gnttab_unmap_grant_ref op;
-	int err;
 
 	hypervisor_mask_event(pbxi->pbx_evtchn);
 	xen_intr_disestablish(pbxi->pbx_ih);
@@ -533,30 +527,14 @@ pciback_xenbus_destroy(void *arg)
 
 
 	if (pbxi->pbx_sh_info) {
-#ifndef XENPV
-		op.host_addr = pbxi->pbx_sh_info_pa;
-#else
-		op.host_addr = (vaddr_t)pbxi->pbx_sh_info;
-#endif
-		op.handle = pbxi->pbx_shinfo_handle;
-		op.dev_bus_addr = 0;
-		err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
-		, 1);
-		if (err)
-			aprint_error("pciback: unmap_grant_ref failed: %d\n",
-			err);
-	}
-#ifndef XENPV
-	if (pbxi->pbx_sh_info_pa) {
-		pmap_kremove((vaddr_t)pbxi->pbx_sh_info, PAGE_SIZE);
-		xenmem_free_pa(pbxi->pbx_sh_info_pa, PAGE_SIZE);
+		xen_shm_unmap((vaddr_t)pbxi->pbx_sh_info, 1,
+		>pbx_shinfo_handle);
+		uvm_km_free(kernel_map, (vaddr_t)pbxi->pbx_sh_info,
+		PAGE_SIZE, UVM_KMF_VAONLY);
 	}
-#endif
 	SLIST_FOREACH(pbd, >pbx_pb_pci_dev, pb_guest_next) {
 		pbd->pbx_instance = NULL;
 	}
-	uvm_km_free(kernel_map, (vaddr_t)pbxi->pbx_sh_info,
-	PAGE_SIZE, UVM_KMF_VAONLY);
 	kmem_free(pbxi, sizeof(*pbxi));
 	return 0;
 }
@@ -567,9 +545,9 @@ pciback_xenbus_frontend_changed(void *ar
 	struct pb_xenbus_instance *pbxi = arg;
 	struct xenbus_device *xbusd = pbxi->pbx_xbusd;
 	int err;
-	struct gnttab_map_grant_ref op;
 	evtchn_op_t evop;
 	u_long shared_ref;
+	grant_ref_t gshared_ref;
 	u_long revtchn;
 
 	/* do it only once */
@@ -606,30 +584,13 @@ pciback_xenbus_frontend_changed(void *ar
 			xbusd->xbusd_otherend);
 			break;
 		}
-#ifndef XENPV
-		pbxi->pbx_sh_info_pa =
-		xenmem_alloc_pa(PAGE_SIZE, PAGE_SIZE, false);
-		if (pbxi->pbx_sh_info_pa == 0) {
-			xenbus_dev_fatal(xbusd, ENOMEM,
-			"can't get PA for ring", xbusd->xbusd_otherend);
+		gshared_ref = shared_ref;
+		if (xen_shm_map(1, pbxi->pbx_domid, _ref,
+		(vaddr_t)pbxi->pbx_sh_info,
+		>pbx_shinfo_handle, 0) != 0) {
+			aprint_error("pciback: can't map shared grant ref\n");
 			goto err2;
 		}
-		pmap_kenter_pa((vaddr_t)pbxi->pbx_sh_info, pbxi->pbx_sh_info_pa,
-		VM_PROT_READ | VM_PROT_WRITE, 0);
-		op.host_addr = pbxi->pbx_sh_info_pa;
-#else
-		op.host_addr = (vaddr_t)pbxi->pbx_sh_info;
-#endif
-		op.flags = GNTMAP_host_map;
-		op.ref = shared_ref;
-		op.dom = pbxi->pbx_domid;
-		err = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, , 1);
-		if (err || op.status) {
-			aprint_error("pciback: can't map shared grant ref: "
-			"%d/%d\n", err, op.status);
-			goto err1;
-		}
-		pbxi->pbx_shinfo_handle = op.handle;
 
 		evop.cmd = EVTCHNOP_bind_interdomain;
 		evop.u.bind_interdomain.remote_dom = pbxi->pbx_domid;
@@ -666,11 +627,8 @@ pciback_xenbus_frontend_changed(void *ar
 	}
 	return;
 err1:
-#ifndef XENPV
-	pmap_kremove((vaddr_t)pbxi->pbx_sh_info, PAGE_SIZE);
-	xenmem_free_pa(pbxi->pbx_sh_info_pa, PAGE_SIZE);
+	xen_shm_unmap((vaddr_t)pbxi->pbx_sh_info, 1, >pbx_shinfo_handle);
 err2:
-#endif
 	uvm_km_free(kernel_map, (vaddr_t)pbxi->pbx_sh_info,
 	PAGE_SIZE, UVM_KMF_VAONLY);
 }

Index: 

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

2022-09-01 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep  1 15:33:23 UTC 2022

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

Log Message:
in backend drivers, use xen_shm_(un)map for the rings instead of inline,
mostly duplicate code.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/xen/xen/pciback.c
cvs rdiff -u -r1.100 -r1.101 src/sys/arch/xen/xen/xbdback_xenbus.c
cvs rdiff -u -r1.106 -r1.107 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.



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

2022-09-01 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep  1 15:32:16 UTC 2022

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

Log Message:
Redo previous; kill the right printf()


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 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.65 src/sys/arch/xen/xen/privcmd.c:1.66
--- src/sys/arch/xen/xen/privcmd.c:1.65	Thu Sep  1 12:31:26 2022
+++ src/sys/arch/xen/xen/privcmd.c	Thu Sep  1 15:32:16 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: privcmd.c,v 1.65 2022/09/01 12:31:26 bouyer Exp $ */
+/* $NetBSD: privcmd.c,v 1.66 2022/09/01 15:32:16 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2004 Christian Limpach.
@@ -27,7 +27,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.65 2022/09/01 12:31:26 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.66 2022/09/01 15:32:16 bouyer Exp $");
 
 #include "opt_xen.h"
 
@@ -554,14 +554,13 @@ privcmd_mmapbatch_v2(struct vop_ioctl_ar
 		set_xen_guest_handle(add.errs, );
 		err = HYPERVISOR_memory_op(XENMEM_add_to_physmap_batch, );
 		if (err < 0) {
+			printf("privcmd_mmapbatch_v2: XENMEM_add_to_physmap_batch failed %d\n", err);
 			privpgop_detach(>uobj);
 			return privcmd_xen2bsd_errno(err);
 		}
 		err = err2;
 		if (err == 0) 
 			maddr[i] = base_paddr + i * PAGE_SIZE;
-		else
-			printf("privcmd_mmapbatch_v2: XENMEM_add_to_physmap_batch failed %d for entry %d\n", err, i);
 #endif /* XENPV */
 
 		cerr = copyout(, >err[i], sizeof(pmb->err[i]));



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

2022-09-01 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep  1 15:32:16 UTC 2022

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

Log Message:
Redo previous; kill the right printf()


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 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.



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

2022-09-01 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep  1 12:31:26 UTC 2022

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

Log Message:
Remove a noisy printf; HVM guests triggers it (a lot) and it seems to be
expected.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 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.64 src/sys/arch/xen/xen/privcmd.c:1.65
--- src/sys/arch/xen/xen/privcmd.c:1.64	Thu Sep  1 12:26:00 2022
+++ src/sys/arch/xen/xen/privcmd.c	Thu Sep  1 12:31:26 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: privcmd.c,v 1.64 2022/09/01 12:26:00 bouyer Exp $ */
+/* $NetBSD: privcmd.c,v 1.65 2022/09/01 12:31:26 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2004 Christian Limpach.
@@ -27,7 +27,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.64 2022/09/01 12:26:00 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.65 2022/09/01 12:31:26 bouyer Exp $");
 
 #include "opt_xen.h"
 
@@ -554,7 +554,6 @@ privcmd_mmapbatch_v2(struct vop_ioctl_ar
 		set_xen_guest_handle(add.errs, );
 		err = HYPERVISOR_memory_op(XENMEM_add_to_physmap_batch, );
 		if (err < 0) {
-			printf("privcmd_mmapbatch_v2: XENMEM_add_to_physmap_batch failed %d\n", err);
 			privpgop_detach(>uobj);
 			return privcmd_xen2bsd_errno(err);
 		}



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

2022-09-01 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep  1 12:31:26 UTC 2022

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

Log Message:
Remove a noisy printf; HVM guests triggers it (a lot) and it seems to be
expected.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 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.



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

2022-09-01 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep  1 12:26:00 UTC 2022

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

Log Message:
Adjust privcmd_notify() so it has a chance to work in a PVH environnement too.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 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.63 src/sys/arch/xen/xen/privcmd.c:1.64
--- src/sys/arch/xen/xen/privcmd.c:1.63	Wed Aug 31 14:00:44 2022
+++ src/sys/arch/xen/xen/privcmd.c	Thu Sep  1 12:26:00 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: privcmd.c,v 1.63 2022/08/31 14:00:44 bouyer Exp $ */
+/* $NetBSD: privcmd.c,v 1.64 2022/09/01 12:26:00 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2004 Christian Limpach.
@@ -27,7 +27,9 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.63 2022/08/31 14:00:44 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.64 2022/09/01 12:26:00 bouyer Exp $");
+
+#include "opt_xen.h"
 
 #include "opt_xen.h"
 
@@ -927,11 +929,19 @@ privcmd_notify(struct ioctl_gntdev_grant
 		int i = notify->offset / PAGE_SIZE;
 		int o = notify->offset % PAGE_SIZE;
 		int err;
+#ifndef XENPV
+		paddr_t base_paddr;
+		base_paddr = xenmem_alloc_pa(PAGE_SIZE, PAGE_SIZE, true);
+#endif
 
 		KASSERT(gmops != NULL);
 		va = uvm_km_alloc(kernel_map, PAGE_SIZE, PAGE_SIZE,
 		UVM_KMF_VAONLY | UVM_KMF_WAITVA);
+#ifndef XENPV
+		op.host_addr = base_paddr;
+#else
 		op.host_addr = va;
+#endif
 		op.dev_bus_addr = 0;
 		op.ref = gmops[i].ref;
 		op.dom = gmops[i].dom;
@@ -939,15 +949,27 @@ privcmd_notify(struct ioctl_gntdev_grant
 		op.flags = GNTMAP_host_map;
 		err = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, , 1);
 		if (err == 0 && op.status == GNTST_okay) {
+#ifndef XENPV
+			pmap_kenter_pa(va, base_paddr,
+			VM_PROT_READ | VM_PROT_WRITE, 0);
+#endif
 			char *n = (void *)(va + o);
 			*n = 0;
+#ifndef XENPV
+			pmap_kremove(va, PAGE_SIZE);
+			uop.host_addr = base_paddr;
+#else
 			uop.host_addr = va;
+#endif
 			uop.handle = op.handle;
 			uop.dev_bus_addr = 0;
 			(void)HYPERVISOR_grant_table_op(
 			GNTTABOP_unmap_grant_ref, , 1);
 		}
 		uvm_km_free(kernel_map, va, PAGE_SIZE, UVM_KMF_VAONLY);
+#ifndef XENPV
+		xenmem_free_pa(base_paddr, PAGE_SIZE);
+#endif
 	} else {
 		KASSERT(gmops == NULL);
 		char *n = (void *)(va + notify->offset);



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

2022-09-01 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep  1 12:26:00 UTC 2022

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

Log Message:
Adjust privcmd_notify() so it has a chance to work in a PVH environnement too.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 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.



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

2022-08-31 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Aug 31 14:00:44 UTC 2022

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

Log Message:
If we check XENPV, make sure to #include "opt_xen.h"


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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.62 src/sys/arch/xen/xen/privcmd.c:1.63
--- src/sys/arch/xen/xen/privcmd.c:1.62	Wed Aug 31 12:51:56 2022
+++ src/sys/arch/xen/xen/privcmd.c	Wed Aug 31 14:00:44 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: privcmd.c,v 1.62 2022/08/31 12:51:56 bouyer Exp $ */
+/* $NetBSD: privcmd.c,v 1.63 2022/08/31 14:00:44 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2004 Christian Limpach.
@@ -27,7 +27,9 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.62 2022/08/31 12:51:56 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.63 2022/08/31 14:00:44 bouyer Exp $");
+
+#include "opt_xen.h"
 
 #include 
 #include 



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

2022-08-31 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Aug 31 14:00:44 UTC 2022

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

Log Message:
If we check XENPV, make sure to #include "opt_xen.h"


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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.



  1   2   3   4   5   6   7   8   >