Module Name:    src
Committed By:   bouyer
Date:           Wed May  6 19:50:26 UTC 2020

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

Log Message:
Make MP-safe: make sure the xpq_queue* are flushed before making the
pages visible to UVM.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/xen/x86/xen_bus_dma.c

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

Modified files:

Index: src/sys/arch/xen/x86/xen_bus_dma.c
diff -u src/sys/arch/xen/x86/xen_bus_dma.c:1.31 src/sys/arch/xen/x86/xen_bus_dma.c:1.32
--- src/sys/arch/xen/x86/xen_bus_dma.c:1.31	Sat Apr 25 15:26:17 2020
+++ src/sys/arch/xen/x86/xen_bus_dma.c	Wed May  6 19:50:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_bus_dma.c,v 1.31 2020/04/25 15:26:17 bouyer Exp $	*/
+/*	$NetBSD: xen_bus_dma.c,v 1.32 2020/05/06 19:50:26 bouyer Exp $	*/
 /*	NetBSD bus_dma.c,v 1.21 2005/04/16 07:53:35 yamt Exp */
 
 /*-
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_bus_dma.c,v 1.31 2020/04/25 15:26:17 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_bus_dma.c,v 1.32 2020/05/06 19:50:26 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -146,15 +146,18 @@ _xen_alloc_contig(bus_size_t size, bus_s
 		pa = VM_PAGE_TO_PHYS(pg);
 		xpmap_ptom_map(pa, ptoa(mfn+i));
 		xpq_queue_machphys_update(((paddr_t)(mfn+i)) << PAGE_SHIFT, pa);
-		/* while here, give extra pages back to UVM */
+	}
+	/* Flush updates through and flush the TLB */
+	xpq_queue_tlb_flush();
+	splx(s);
+	/* now that ptom/mtop are valid, give the extra pages back to UVM */
+	for (pg = mlistp->tqh_first, i = 0; pg != NULL; pg = pgnext, i++) {
+		pgnext = pg->pageq.queue.tqe_next;
 		if (i >= npagesreq) {
 			TAILQ_REMOVE(mlistp, pg, pageq.queue);
 			uvm_pagefree(pg);
 		}
 	}
-	/* Flush updates through and flush the TLB */
-	xpq_queue_tlb_flush();
-	splx(s);
 	return 0;
 
 failed:
@@ -190,11 +193,11 @@ failed:
 		pa = VM_PAGE_TO_PHYS(pg);
 		xpmap_ptom_map(pa, ptoa(mfn));
 		xpq_queue_machphys_update(((paddr_t)mfn) << PAGE_SHIFT, pa);
+		/* slow but we don't care */
+		xpq_queue_tlb_flush();
 		TAILQ_REMOVE(mlistp, pg, pageq.queue);
 		uvm_pagefree(pg);
 	}
-	/* Flush updates through and flush the TLB */
-	xpq_queue_tlb_flush();
 	splx(s);
 	return error;
 }

Reply via email to