[lkml]   [2015]   [Oct]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH] x86: Add an explicit barrier() to clflushopt()
During testing we observed that the last cacheline was not being flushed
from a

for (addr = addr & -clflush_size; addr < end; addr += clflush_size)

loop (where the initial addr and end were not cacheline aligned).

Changing the loop from addr < end to addr <= end, or replacing the
clflushopt() with clflush() both fixed the testcase. Hinting that GCC
was miscompling the assembly within the loop and specifically the
alternative within clflushopt() was confusing the loop optimizer.

Adding a barrier() into clflushopt() is enough for GCC to dtrt, but
solving why GCC is not seeing the constraints from the alternative_io()
would be smarter...

Testcase: gem_tiled_partial_pwrite_pread/read
Signed-off-by: Chris Wilson <>
Cc: Ross Zwisler <>
Cc: H. Peter Anvin <>
Cc: Imre Deak <>
Cc: Daniel Vetter <>
arch/x86/include/asm/special_insns.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h
index 2270e41b32fd..0c7aedbf8930 100644
--- a/arch/x86/include/asm/special_insns.h
+++ b/arch/x86/include/asm/special_insns.h
@@ -199,6 +199,11 @@ static inline void clflushopt(volatile void *__p)
".byte 0x66; clflush %P0",
"+m" (*(volatile char __force *)__p));
+ /* GCC (4.9.1 and 5.2.1 at least) appears to be very confused when
+ * meeting this alternative() and demonstrably miscompiles loops
+ * iterating over clflushopts.
+ */
+ barrier();

static inline void clwb(volatile void *__p)

 \ /
  Last update: 2015-10-19 12:21    [W:0.151 / U:4.456 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site