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

2023-11-06 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov  6 17:01:07 UTC 2023

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

Log Message:
xen_ipi: valid_ipimask: Sprinkle __diagused to fix clang !DIAGNOSTIC build


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/xen/x86/xen_ipi.c

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



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

2023-11-06 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov  6 17:01:07 UTC 2023

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

Log Message:
xen_ipi: valid_ipimask: Sprinkle __diagused to fix clang !DIAGNOSTIC build


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/xen/x86/xen_ipi.c

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

Modified files:

Index: src/sys/arch/xen/x86/xen_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.41 src/sys/arch/xen/x86/xen_ipi.c:1.42
--- src/sys/arch/xen/x86/xen_ipi.c:1.41	Sun Aug  6 16:07:53 2023
+++ src/sys/arch/xen/x86/xen_ipi.c	Mon Nov  6 17:01:07 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.41 2023/08/06 16:07:53 riastradh Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.42 2023/11/06 17:01:07 rin Exp $ */
 
 /*-
  * Copyright (c) 2011, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  * Based on: x86/ipi.c
  */
 
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.41 2023/08/06 16:07:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.42 2023/11/06 17:01:07 rin Exp $");
 
 #include "opt_ddb.h"
 
@@ -149,7 +149,7 @@ xen_ipi_init(void)
 	hypervisor_unmask_event(evtchn);
 }
 
-static inline bool /* helper */
+static inline bool __diagused
 valid_ipimask(uint32_t ipimask)
 {
 	uint32_t masks = XEN_IPI_GENERIC | XEN_IPI_HVCB | XEN_IPI_XCALL |



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

2023-10-17 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Oct 17 13:27:58 UTC 2023

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

Log Message:
Make sure to always fall back to xen_early_console, even for dom0


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

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



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

2023-10-17 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Oct 17 13:27:58 UTC 2023

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

Log Message:
Make sure to always fall back to xen_early_console, even for dom0


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

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

Modified files:

Index: src/sys/arch/xen/x86/pvh_consinit.c
diff -u src/sys/arch/xen/x86/pvh_consinit.c:1.5 src/sys/arch/xen/x86/pvh_consinit.c:1.6
--- src/sys/arch/xen/x86/pvh_consinit.c:1.5	Mon Oct 16 17:31:18 2023
+++ src/sys/arch/xen/x86/pvh_consinit.c	Tue Oct 17 13:27:58 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: pvh_consinit.c,v 1.5 2023/10/16 17:31:18 bouyer Exp $ */
+/* $NetBSD: pvh_consinit.c,v 1.6 2023/10/17 13:27:58 bouyer Exp $ */
 
 /*
  * Copyright (c) 2020 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pvh_consinit.c,v 1.5 2023/10/16 17:31:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pvh_consinit.c,v 1.6 2023/10/17 13:27:58 bouyer Exp $");
 
 #include "xencons.h"
 #include 
@@ -51,6 +51,11 @@ xen_pvh_consinit(void)
 	 * boot stage.
 	 */
 	static int initted = 0;
+
+	if (initted == 0) {
+		/* fall back to printk() until we can setup our console */
+		xen_early_console();
+	}
 	if (xendomain_is_dom0()) {
 		union xen_cmdline_parseinfo xcp;
 		xen_parse_cmdline(XEN_PARSE_CONSOLE, );
@@ -61,12 +66,12 @@ xen_pvh_consinit(void)
 		if (strcmp(xcp.xcp_console, "tty0") == 0 || /* linux name */
 		strcmp(xcp.xcp_console, "pc") == 0) { /* NetBSD name */
 #endif /* CONS_OVERRIDE */
+			initted++;
 			return 0; /* native console code will do it */
 		}
 	}
 	if (initted == 0 && !xendomain_is_dom0()) {
-		/* pmap not up yet, fall back to printk() */
-		xen_early_console();
+		/* pmap not up yet */
 		initted++;
 		return 1;
 	} else if (initted > 1) {



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

2023-10-17 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Oct 17 11:52:45 UTC 2023

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

Log Message:
xenbus: if dom0 support is not compiled in, panic with a usefull message
instead of waiting for an event which will never happen


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/xen/xenbus/xenbus_probe.c

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



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

2023-10-17 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Oct 17 11:52:45 UTC 2023

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

Log Message:
xenbus: if dom0 support is not compiled in, panic with a usefull message
instead of waiting for an event which will never happen


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/xen/xenbus/xenbus_probe.c

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

Modified files:

Index: src/sys/arch/xen/xenbus/xenbus_probe.c
diff -u src/sys/arch/xen/xenbus/xenbus_probe.c:1.59 src/sys/arch/xen/xenbus/xenbus_probe.c:1.60
--- src/sys/arch/xen/xenbus/xenbus_probe.c:1.59	Tue Aug  1 07:58:41 2023
+++ src/sys/arch/xen/xenbus/xenbus_probe.c	Tue Oct 17 11:52:45 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_probe.c,v 1.59 2023/08/01 07:58:41 mrg Exp $ */
+/* $NetBSD: xenbus_probe.c,v 1.60 2023/10/17 11:52:45 bouyer Exp $ */
 /**
  * Talks to Xen Store to figure out what devices we have.
  *
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.59 2023/08/01 07:58:41 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.60 2023/10/17 11:52:45 bouyer Exp $");
 
 #if 0
 #define DPRINTK(fmt, args...) \
@@ -722,7 +722,7 @@ xenbus_probe_init(void *unused)
 
 		DELAY(1000);
 #else /* DOM0OPS */
-		kthread_exit(0); /* can't get a working xenstore in this case */
+		panic("dom0 support not compiled in");
 #endif /* DOM0OPS */
 	}
 



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

2023-10-16 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Oct 16 17:31:18 UTC 2023

Modified Files:
src/sys/arch/xen/include: hypervisor.h
src/sys/arch/xen/x86: pvh_consinit.c
src/sys/arch/xen/xen: xen_machdep.c

Log Message:
Move the pvh_xencons so xen_machdep.c as early_xencons, so it can be
used in the future as early ouput for plain PV guests too.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/xen/x86/pvh_consinit.c
cvs rdiff -u -r1.27 -r1.28 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/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.58 src/sys/arch/xen/include/hypervisor.h:1.59
--- src/sys/arch/xen/include/hypervisor.h:1.58	Mon Oct 16 17:29:31 2023
+++ src/sys/arch/xen/include/hypervisor.h	Mon Oct 16 17:31:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.58 2023/10/16 17:29:31 bouyer Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.59 2023/10/16 17:31:17 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -214,4 +214,6 @@ hypervisor_notify_via_evtchn(unsigned in
 void xen_init_ksyms(void);
 void xen_map_vcpu(struct cpu_info *);
 
+void xen_early_console(void);
+
 #endif /* _XEN_HYPERVISOR_H_ */

Index: src/sys/arch/xen/x86/pvh_consinit.c
diff -u src/sys/arch/xen/x86/pvh_consinit.c:1.4 src/sys/arch/xen/x86/pvh_consinit.c:1.5
--- src/sys/arch/xen/x86/pvh_consinit.c:1.4	Sat Jul 22 19:13:17 2023
+++ src/sys/arch/xen/x86/pvh_consinit.c	Mon Oct 16 17:31:18 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: pvh_consinit.c,v 1.4 2023/07/22 19:13:17 mrg Exp $ */
+/* $NetBSD: pvh_consinit.c,v 1.5 2023/10/16 17:31:18 bouyer Exp $ */
 
 /*
  * Copyright (c) 2020 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pvh_consinit.c,v 1.4 2023/07/22 19:13:17 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pvh_consinit.c,v 1.5 2023/10/16 17:31:18 bouyer Exp $");
 
 #include "xencons.h"
 #include 
@@ -43,16 +43,6 @@ __KERNEL_RCSID(0, "$NetBSD: pvh_consinit
 
 #include "xen_def_cons.h"
 
-static int pvh_xenconscn_getc(dev_t);
-static void pvh_xenconscn_putc(dev_t, int);
-static void pvh_xenconscn_pollc(dev_t, int);
-
-static struct consdev pvh_xencons = {
-NULL, NULL, pvh_xenconscn_getc, pvh_xenconscn_putc, pvh_xenconscn_pollc,
-	NULL, NULL, NULL, NODEV, CN_NORMAL
-};
-
-
 int
 xen_pvh_consinit(void)
 {
@@ -76,7 +66,7 @@ xen_pvh_consinit(void)
 	}
 	if (initted == 0 && !xendomain_is_dom0()) {
 		/* pmap not up yet, fall back to printk() */
-		cn_tab = _xencons;
+		xen_early_console();
 		initted++;
 		return 1;
 	} else if (initted > 1) {
@@ -116,23 +106,3 @@ xen_pvh_consinit(void)
 #endif
 	return 1;
 }
-
-static int
-pvh_xenconscn_getc(dev_t dev)
-{
-	while(1)
-		;
-	return -1;
-}
-
-static void
-pvh_xenconscn_putc(dev_t dev, int c)
-{
-	printk("%c", c);
-}
-
-static void
-pvh_xenconscn_pollc(dev_t dev, int on)
-{
-	return;
-}

Index: src/sys/arch/xen/xen/xen_machdep.c
diff -u src/sys/arch/xen/xen/xen_machdep.c:1.27 src/sys/arch/xen/xen/xen_machdep.c:1.28
--- src/sys/arch/xen/xen/xen_machdep.c:1.27	Sat Aug 20 23:48:51 2022
+++ src/sys/arch/xen/xen/xen_machdep.c	Mon Oct 16 17:31:18 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_machdep.c,v 1.27 2022/08/20 23:48:51 riastradh Exp $	*/
+/*	$NetBSD: xen_machdep.c,v 1.28 2023/10/16 17:31:18 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.27 2022/08/20 23:48:51 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.28 2023/10/16 17:31:18 bouyer Exp $");
 
 #include "opt_xen.h"
 
@@ -70,6 +70,8 @@ __KERNEL_RCSID(0, "$NetBSD: xen_machdep.
 #include 
 #include 
 
+#include 
+
 #include 
 #include 
 #include 
@@ -440,6 +442,41 @@ printk(const char *fmt, ...)
 	(void)HYPERVISOR_console_io(CONSOLEIO_write, ret, buf);
 }
 
+static int early_xenconscn_getc(dev_t);
+static void early_xenconscn_putc(dev_t, int);
+static void early_xenconscn_pollc(dev_t, int);
+
+static struct consdev early_xencons = {
+	NULL, NULL,
+	early_xenconscn_getc, early_xenconscn_putc, early_xenconscn_pollc,
+	NULL, NULL, NULL, NODEV, CN_NORMAL
+};
+
+void
+xen_early_console(void)
+{
+	cn_tab = _xencons; /* fallback console */
+}
+
+static int
+early_xenconscn_getc(dev_t dev)
+{
+	while(1)
+		;
+	return -1;
+}
+
+static void 
+early_xenconscn_putc(dev_t dev, int c)
+{
+	printk("%c", c);
+}
+
+static void
+early_xenconscn_pollc(dev_t dev, int on)
+{
+	return;
+}
 bool xen_feature_tables[XENFEAT_NR_SUBMAPS * 32];
 
 void



CVS commit: src/sys/arch/xen

2023-10-16 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Oct 16 17:31:18 UTC 2023

Modified Files:
src/sys/arch/xen/include: hypervisor.h
src/sys/arch/xen/x86: pvh_consinit.c
src/sys/arch/xen/xen: xen_machdep.c

Log Message:
Move the pvh_xencons so xen_machdep.c as early_xencons, so it can be
used in the future as early ouput for plain PV guests too.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/xen/x86/pvh_consinit.c
cvs rdiff -u -r1.27 -r1.28 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/x86

2023-08-06 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Aug  6 16:07:53 UTC 2023

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

Log Message:
xen/x86: Get the right intrframe pointer in ddb ipi.

This was broken with the transition from evtchn_set_handler to
intr_establish_xname in 2017, remained broken with the transition
from intr_establish_xname to xen_intr_establish_xname in 2018, and
still remained broken when xen_intr_establish_xname was changed back
to evtchn_set_handler in 2020.

The mechanism is grody -- instead of a secret second argument to the
interrupt handler, the intrframe pointer should be replaced by a
struct cpu_info member that is saved and restored by the interrupt
handler calling logic.  But we should make sure the replacement
actually works first -- which is not trivial in part because the
users are hidden behind sketchy function pointer casts.

With any luck, this will make `mach cpu N' work in ddb on Xen.

XXX pullup-10
XXX pullup-9 (by patch)


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/xen/x86/xen_ipi.c

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

Modified files:

Index: src/sys/arch/xen/x86/xen_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.40 src/sys/arch/xen/x86/xen_ipi.c:1.41
--- src/sys/arch/xen/x86/xen_ipi.c:1.40	Wed Jan  5 20:21:29 2022
+++ src/sys/arch/xen/x86/xen_ipi.c	Sun Aug  6 16:07:53 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.40 2022/01/05 20:21:29 christos Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.41 2023/08/06 16:07:53 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  * Based on: x86/ipi.c
  */
 
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.40 2022/01/05 20:21:29 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.41 2023/08/06 16:07:53 riastradh Exp $");
 
 #include "opt_ddb.h"
 
@@ -90,18 +90,15 @@ static void (*xen_ipifunc[XEN_NIPIS])(st
 };
 
 static int
-xen_ipi_handler(void *arg)
+xen_ipi_handler(void *arg, struct intrframe *regs)
 {
 	uint32_t pending;
 	int bit;
 	struct cpu_info *ci;
-	struct intrframe *regs;
 
 	ci = curcpu();
-	regs = arg;
 
 	KASSERT(ci == arg);
-	
 	pending = atomic_swap_32(>ci_ipis, 0);
 
 	KDASSERT((pending >> XEN_NIPIS) == 0);
@@ -142,8 +139,9 @@ xen_ipi_init(void)
 	snprintf(intr_xname, sizeof(intr_xname), "%s ipi",
 	device_xname(ci->ci_dev));
 
-	if (event_set_handler(evtchn, xen_ipi_handler, ci, IPL_HIGH, NULL,
-	intr_xname, true, ci) == NULL) {
+	if (event_set_handler(evtchn,
+		__FPTRCAST(int (*)(void *), xen_ipi_handler), ci, IPL_HIGH,
+		NULL, intr_xname, true, ci) == NULL) {
 		panic("%s: unable to register ipi handler\n", __func__);
 		/* NOTREACHED */
 	}



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

2023-08-06 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Aug  6 16:07:53 UTC 2023

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

Log Message:
xen/x86: Get the right intrframe pointer in ddb ipi.

This was broken with the transition from evtchn_set_handler to
intr_establish_xname in 2017, remained broken with the transition
from intr_establish_xname to xen_intr_establish_xname in 2018, and
still remained broken when xen_intr_establish_xname was changed back
to evtchn_set_handler in 2020.

The mechanism is grody -- instead of a secret second argument to the
interrupt handler, the intrframe pointer should be replaced by a
struct cpu_info member that is saved and restored by the interrupt
handler calling logic.  But we should make sure the replacement
actually works first -- which is not trivial in part because the
users are hidden behind sketchy function pointer casts.

With any luck, this will make `mach cpu N' work in ddb on Xen.

XXX pullup-10
XXX pullup-9 (by patch)


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/xen/x86/xen_ipi.c

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



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

2023-07-22 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Jul 22 19:13:17 UTC 2023

Modified Files:
src/sys/arch/xen/x86: consinit.c pvh_consinit.c
Added Files:
src/sys/arch/xen/x86: xen_def_cons.h

Log Message:
xen: declare 'default_consinfo' as extern in a header

this makes pvh_consinit.c actually compile with CONS_OVERRIDE set.
i didn't see any good header to add to (bootinfo.h and cpu.h both
seem to be poor choices but were considered), hence the new one
with just this definition.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/xen/x86/consinit.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/xen/x86/pvh_consinit.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/xen/x86/xen_def_cons.h

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

2023-07-22 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Jul 22 19:13:17 UTC 2023

Modified Files:
src/sys/arch/xen/x86: consinit.c pvh_consinit.c
Added Files:
src/sys/arch/xen/x86: xen_def_cons.h

Log Message:
xen: declare 'default_consinfo' as extern in a header

this makes pvh_consinit.c actually compile with CONS_OVERRIDE set.
i didn't see any good header to add to (bootinfo.h and cpu.h both
seem to be poor choices but were considered), hence the new one
with just this definition.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/xen/x86/consinit.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/xen/x86/pvh_consinit.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/xen/x86/xen_def_cons.h

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

Modified files:

Index: src/sys/arch/xen/x86/consinit.c
diff -u src/sys/arch/xen/x86/consinit.c:1.16 src/sys/arch/xen/x86/consinit.c:1.17
--- src/sys/arch/xen/x86/consinit.c:1.16	Sat Oct 13 17:58:55 2012
+++ src/sys/arch/xen/x86/consinit.c	Sat Jul 22 19:13:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: consinit.c,v 1.16 2012/10/13 17:58:55 jdc Exp $	*/
+/*	$NetBSD: consinit.c,v 1.17 2023/07/22 19:13:17 mrg Exp $	*/
 /*	NetBSD: consinit.c,v 1.4 2004/03/13 17:31:34 bjh21 Exp 	*/
 
 /*
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.16 2012/10/13 17:58:55 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.17 2023/07/22 19:13:17 mrg Exp $");
 
 #include "opt_kgdb.h"
 
@@ -75,6 +75,7 @@ __KERNEL_RCSID(0, "$NetBSD: consinit.c,v
 #include 
 #include 
 #include 
+#include "xen_def_cons.h"
 #endif
 
 #include "com.h"

Index: src/sys/arch/xen/x86/pvh_consinit.c
diff -u src/sys/arch/xen/x86/pvh_consinit.c:1.3 src/sys/arch/xen/x86/pvh_consinit.c:1.4
--- src/sys/arch/xen/x86/pvh_consinit.c:1.3	Fri Mar 24 12:28:42 2023
+++ src/sys/arch/xen/x86/pvh_consinit.c	Sat Jul 22 19:13:17 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: pvh_consinit.c,v 1.3 2023/03/24 12:28:42 bouyer Exp $ */
+/* $NetBSD: pvh_consinit.c,v 1.4 2023/07/22 19:13:17 mrg Exp $ */
 
 /*
  * Copyright (c) 2020 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pvh_consinit.c,v 1.3 2023/03/24 12:28:42 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pvh_consinit.c,v 1.4 2023/07/22 19:13:17 mrg Exp $");
 
 #include "xencons.h"
 #include 
@@ -41,6 +41,8 @@ __KERNEL_RCSID(0, "$NetBSD: pvh_consinit
 #include 
 #include 
 
+#include "xen_def_cons.h"
+
 static int pvh_xenconscn_getc(dev_t);
 static void pvh_xenconscn_putc(dev_t, int);
 static void pvh_xenconscn_pollc(dev_t, int);

Added files:

Index: src/sys/arch/xen/x86/xen_def_cons.h
diff -u /dev/null src/sys/arch/xen/x86/xen_def_cons.h:1.1
--- /dev/null	Sat Jul 22 19:13:17 2023
+++ src/sys/arch/xen/x86/xen_def_cons.h	Sat Jul 22 19:13:17 2023
@@ -0,0 +1,10 @@
+/*	$NetBSD: xen_def_cons.h,v 1.1 2023/07/22 19:13:17 mrg Exp $	*/
+
+/*
+ * Written by Matthew R. Green, July 20, 2023
+ * Public domain.
+ */
+
+#include 
+
+extern const struct btinfo_console default_consinfo;



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

2023-03-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar  1 08:13:44 UTC 2023

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

Log Message:
xen/x86: Need kpreempt_disable/enable around curcpu() access.

This is called with `hardware' interrupts enabled (between sti and
cli), so presumably preemption is possible here.

XXX pullup-8
XXX pullup-9
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/xen/x86/hypervisor_machdep.c

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

Modified files:

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.45 src/sys/arch/xen/x86/hypervisor_machdep.c:1.46
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.45	Wed Sep  7 00:40:19 2022
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Wed Mar  1 08:13:44 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.45 2022/09/07 00:40:19 knakahara Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.46 2023/03/01 08:13:44 riastradh Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.45 2022/09/07 00:40:19 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.46 2023/03/01 08:13:44 riastradh Exp $");
 
 #include 
 #include 
@@ -192,6 +192,8 @@ stipending(void)
 	volatile struct vcpu_info *vci;
 	int ret;
 
+	kpreempt_disable();
+
 	ret = 0;
 	ci = curcpu();
 	vci = ci->ci_vcpu;
@@ -227,6 +229,8 @@ stipending(void)
 		x86_enable_intr();
 	}
 
+	kpreempt_enable();
+
 	return (ret);
 }
 



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

2023-03-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar  1 08:13:44 UTC 2023

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

Log Message:
xen/x86: Need kpreempt_disable/enable around curcpu() access.

This is called with `hardware' interrupts enabled (between sti and
cli), so presumably preemption is possible here.

XXX pullup-8
XXX pullup-9
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/xen/x86/hypervisor_machdep.c

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



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

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

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

Log Message:
xenbus_comms.c: Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/xen/xenbus/xenbus_comms.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/xenbus

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

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

Log Message:
xenbus_comms.c: Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/xen/xenbus/xenbus_comms.c

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

Modified files:

Index: src/sys/arch/xen/xenbus/xenbus_comms.c
diff -u src/sys/arch/xen/xenbus/xenbus_comms.c:1.25 src/sys/arch/xen/xenbus/xenbus_comms.c:1.26
--- src/sys/arch/xen/xenbus/xenbus_comms.c:1.25	Sat Feb 25 00:34:01 2023
+++ src/sys/arch/xen/xenbus/xenbus_comms.c	Sat Feb 25 00:37:34 2023
@@ -1,24 +1,24 @@
-/* $NetBSD: xenbus_comms.c,v 1.25 2023/02/25 00:34:01 riastradh Exp $ */
+/* $NetBSD: xenbus_comms.c,v 1.26 2023/02/25 00:37:34 riastradh Exp $ */
 /**
  * xenbus_comms.c
  *
  * Low level code to talks to Xen Store: ringbuffer and event channel.
  *
  * Copyright (C) 2005 Rusty Russell, IBM Corporation
- * 
+ *
  * This file may be distributed separately from the Linux kernel, or
  * incorporated into other software packages, subject to the following license:
- * 
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this source file (the "Software"), to deal in the Software without
  * restriction, including without limitation the rights to use, copy, modify,
  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
  * and to permit persons to whom the Software is furnished to do so, subject to
  * the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -29,11 +29,11 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.25 2023/02/25 00:34:01 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.26 2023/02/25 00:37:34 riastradh Exp $");
 
 #include 
-#include  
-#include  
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -80,7 +80,7 @@ wake_waiting(void *arg)
 {
 	if (__predict_false(xenstored_ready == 0 && xendomain_is_dom0())) {
 		xb_xenstored_make_ready();
-	} 
+	}
 
 	mutex_enter(_lock);
 	cv_broadcast(_cv);



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

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

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

Log Message:
xen/x86/cpu.c: Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/sys/arch/xen/x86/cpu.c

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

Modified files:

Index: src/sys/arch/xen/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.144 src/sys/arch/xen/x86/cpu.c:1.145
--- src/sys/arch/xen/x86/cpu.c:1.144	Sat Feb 25 00:32:38 2023
+++ src/sys/arch/xen/x86/cpu.c	Sat Feb 25 00:35:01 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.144 2023/02/25 00:32:38 riastradh Exp $	*/
+/*	$NetBSD: cpu.c,v 1.145 2023/02/25 00:35:01 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.144 2023/02/25 00:32:38 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.145 2023/02/25 00:35:01 riastradh Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -521,7 +521,7 @@ cpu_attach_common(device_t parent, devic
 		(void *)pcb->pcb_rsp
 #endif
 		);
-		
+
 	}
 #endif /* MPVERBOSE */
 }
@@ -690,10 +690,10 @@ cpu_boot_secondary(struct cpu_info *ci)
 
 /*
  * APs end up here immediately after initialisation and VCPUOP_up in
- * mp_cpu_start(). 
+ * mp_cpu_start().
  * At this point, we are running in the idle pcb/idle stack of the new
  * CPU.  This function jumps to the idle loop and starts looking for
- * work. 
+ * work.
  */
 extern void x86_64_tls_switch(struct lwp *);
 void
@@ -931,8 +931,8 @@ xen_init_i386_vcpuctxt(struct cpu_info *
 
 	gdt_prepframes(frames, (vaddr_t)ci->ci_gdt, gdt_ents);
 
-	/* 
-	 * Initialise the vcpu context: 
+	/*
+	 * Initialise the vcpu context:
 	 * We use this cpu's idle_loop() pcb context.
 	 */
 
@@ -1160,7 +1160,7 @@ cpu_load_pmap(struct pmap *pmap, struct 
 
 /*
  * pmap_cpu_init_late: perform late per-CPU initialization.
- * 
+ *
  * Short note about percpu PDIR pages. Both the PAE and __x86_64__ architectures
  * have per-cpu PDIR tables, for two different reasons:
  *  - on PAE, this is to get around Xen's pagetable setup constraints (multiple
@@ -1170,7 +1170,7 @@ cpu_load_pmap(struct pmap *pmap, struct 
  *(see cpu_load_pmap()).
  *
  * What this means for us is that the PDIR of the pmap_kernel() is considered
- * to be a canonical "SHADOW" PDIR with the following properties: 
+ * to be a canonical "SHADOW" PDIR with the following properties:
  *  - its recursive mapping points to itself
  *  - per-cpu recursive mappings point to themselves on __x86_64__
  *  - per-cpu L4 pages' kernel entries are expected to be in sync with



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

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

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

Log Message:
xen/x86/cpu.c: Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/sys/arch/xen/x86/cpu.c

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



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

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

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

Log Message:
xen/hypervisor.h: Nix trailing whitespace.

No functional change intended.


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

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

Modified files:

Index: src/sys/arch/xen/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.56 src/sys/arch/xen/include/hypervisor.h:1.57
--- src/sys/arch/xen/include/hypervisor.h:1.56	Sat Feb 25 00:32:26 2023
+++ src/sys/arch/xen/include/hypervisor.h	Sat Feb 25 00:34:48 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.56 2023/02/25 00:32:26 riastradh Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.57 2023/02/25 00:34:48 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,21 +26,21 @@
  */
 
 /*
- * 
+ *
  * Communication to/from hypervisor.
- * 
+ *
  * Copyright (c) 2002-2004, K A Fraser
- * 
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this source file (the "Software"), to deal in the Software without
  * restriction, including without limitation the rights to use, copy, modify,
  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
  * and to permit persons to whom the Software is furnished to do so, subject to
  * the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -187,10 +187,10 @@ void hypervisor_set_ipending(uint64_t, i
 void hypervisor_machdep_attach(void);
 void hypervisor_machdep_resume(void);
 
-/* 
+/*
  * Force a proper event-channel callback from Xen after clearing the
  * callback mask. We do this in a very simple manner, by making a call
- * down into Xen. The pending flag will be checked by Xen on return. 
+ * down into Xen. The pending flag will be checked by Xen on return.
  */
 static __inline void hypervisor_force_callback(void)
 {



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

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

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

Log Message:
xen/hypervisor.h: Nix trailing whitespace.

No functional change intended.


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

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

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

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

Log Message:
xenbus_comms.c: 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.24 -r1.25 src/sys/arch/xen/xenbus/xenbus_comms.c

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

Modified files:

Index: src/sys/arch/xen/xenbus/xenbus_comms.c
diff -u src/sys/arch/xen/xenbus/xenbus_comms.c:1.24 src/sys/arch/xen/xenbus/xenbus_comms.c:1.25
--- src/sys/arch/xen/xenbus/xenbus_comms.c:1.24	Wed May 13 13:19:38 2020
+++ src/sys/arch/xen/xenbus/xenbus_comms.c	Sat Feb 25 00:34:01 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_comms.c,v 1.24 2020/05/13 13:19:38 jdolecek Exp $ */
+/* $NetBSD: xenbus_comms.c,v 1.25 2023/02/25 00:34:01 riastradh Exp $ */
 /**
  * xenbus_comms.c
  *
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.24 2020/05/13 13:19:38 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.25 2023/02/25 00:34:01 riastradh Exp $");
 
 #include 
 #include  
@@ -153,9 +153,9 @@ xb_write(const void *data, unsigned len)
 		len -= avail;
 
 		/* Other side must not see new header until data is there. */
-		xen_rmb();
+		xen_wmb();
 		intf->req_prod += avail;
-		xen_rmb();
+		xen_wmb();
 
 		hypervisor_notify_via_evtchn(xen_start_info.store_evtchn);
 	}
@@ -202,9 +202,9 @@ xb_read(void *data, unsigned len)
 		len -= avail;
 
 		/* Other side must not see free space until we've copied out */
-		xen_rmb();
+		xen_wmb();
 		intf->rsp_cons += avail;
-		xen_rmb();
+		xen_wmb();
 
 		XENPRINTF(("Finished read of %i bytes (%i to go)\n",
 		avail, len));



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

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

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

Log Message:
xenbus_comms.c: 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.24 -r1.25 src/sys/arch/xen/xenbus/xenbus_comms.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;



  1   2   3   >