On Mon, May 16, 2016 at 02:21:26PM +1000, Jonathan Gray wrote:
> On Mon, May 16, 2016 at 01:01:01PM +1000, Jonathan Gray wrote:
> > On Mon, May 16, 2016 at 12:53:54AM +0200, Mark Kettenis wrote:
> > > So Theo's SROP mitigation diff made my armv7 machine completely
> > > unstable.  Filesystem-related panics, random core dumps, files with
> > > blocks of zeroes on them, etc.
> > > 
> > > Looking at the changes in question, there is no way they're
> > > responsible for this behavior.  This smells like cache-related bug
> > > triggered by changes in the memory layout in the kernel.  Since I'm
> > > running with root on an SD card hanging off imxesdhc(4), I started
> > > looking for missing bus_dmamap_sync() calls in that driver.  Found
> > > one, but notone that actually mattered.  Then I turned to the actual
> > > bus_dmamap_sync(9) implementation.  It has a nice comment explaining
> > > when cache maintenance is needed.  It mentions that the D-Cache needs
> > > to be invalidated for a POSTREAD operation.  But it doesn't actually
> > > do that.
> > > 
> > > The NetBSD code (from which our code is derived) does implement this,
> > > and has an additional comment:
> > > 
> > >         /*
> > >          * 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.
> > >          */
> > > 
> > > Adding the relevant bit of code seems to fix the issue.
> > > 
> > > So here's the diff.  It seems that this code isn't needed on the
> > > pre-ARMv7 hardware.  So I could sprinkle in an #ifdef CPU_ARMv7 if
> > > people think that is worth it.  But that might make us forget this
> > > code for future ARM processor generations.
> > > 
> > > ok?
> > 
> > membar_sync() only exists for CPU_ARMv7 currently, I'm not sure
> > exactly when it was introduced (some v5 and all v6?) but we might be
> > able to use CP15DMB for armish/zaurus?
> 
> and with the r0 use flagged in the extended asm syntax:

After consulting an older version of the ARM ARM it seems the cp15
barriers were introduced with armv6 so just do the compiler hint.

Index: atomic.h
===================================================================
RCS file: /cvs/src/sys/arch/arm/include/atomic.h,v
retrieving revision 1.14
diff -u -p -r1.14 atomic.h
--- atomic.h    25 Apr 2016 08:00:43 -0000      1.14
+++ atomic.h    16 May 2016 08:31:29 -0000
@@ -465,6 +465,21 @@ atomic_clearbits_int(volatile unsigned i
            : "memory", "cc"
        );
 }
+#endif /* CPU_ARMv7 */
+
+#if !defined(CPU_ARMv7)
+
+#define __membar() do { \
+       __asm __volatile("" ::: "memory"); \
+} while (0)
+
+#define membar_enter()         __membar()
+#define membar_exit()          __membar()
+#define membar_producer()      __membar()
+#define membar_consumer()      __membar()
+#define membar_sync()          __membar()
+
+#else /* !CPU_ARMv7 */
 
 #define __membar(_f) do { __asm __volatile(_f ::: "memory"); } while (0)
 

Reply via email to