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 <sys/cdefs.h>
-__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 <sys/types.h>
 #include <sys/param.h>
@@ -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(&xneti->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(&xneti->xni_txring, req_cons,
 		    &txreq);
-		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(&xneti->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",

Reply via email to