summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2016-05-16 15:13:50 +0000
committerkettenis <kettenis@openbsd.org>2016-05-16 15:13:50 +0000
commitc09abd39741bc997b77876567edbeecf6724e1c3 (patch)
treee9b62cf63ca70547b26ad1ec10b8faa1e4a28196
parentpcfrtc(4) (diff)
downloadwireguard-openbsd-c09abd39741bc997b77876567edbeecf6724e1c3.tar.xz
wireguard-openbsd-c09abd39741bc997b77876567edbeecf6724e1c3.zip
POSTREAD needs to flush the D-cache since speculative loads might (and do)
bring back cache lines after a PREREAD. Eliminates random data corruption on my CuBox-i4Pro. ok jsg@
-rw-r--r--sys/arch/arm/arm/bus_dma.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/sys/arch/arm/arm/bus_dma.c b/sys/arch/arm/arm/bus_dma.c
index 4290e5406b1..cdd7c21282b 100644
--- a/sys/arch/arm/arm/bus_dma.c
+++ b/sys/arch/arm/arm/bus_dma.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bus_dma.c,v 1.29 2016/03/10 10:22:43 tobiasu Exp $ */
+/* $OpenBSD: bus_dma.c,v 1.30 2016/05/16 15:13:50 kettenis Exp $ */
/* $NetBSD: bus_dma.c,v 1.38 2003/10/30 08:44:13 scw Exp $ */
/*-
@@ -421,6 +421,19 @@ _bus_dmamap_sync_segment(vaddr_t va, paddr_t pa, vsize_t len, int ops)
cpu_dcache_wb_range(va, len);
cpu_sdcache_wb_range(va, pa, len);
break;
+
+ /*
+ * Cortex CPUs can do speculative loads so we need to clean the cache
+ * after a DMA read to deal with any speculatively loaded cache lines.
+ * Since these can't be dirty, we can just invalidate them and don't
+ * have to worry about having to write back their contents.
+ */
+ case BUS_DMASYNC_POSTREAD:
+ case BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE:
+ membar_sync();
+ cpu_dcache_inv_range(va, len);
+ cpu_sdcache_inv_range(va, pa, len);
+ break;
}
}