linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86: Add an explicit barrier() to clflushopt()
@ 2015-10-19  9:58 Chris Wilson
  2015-10-19 10:16 ` Borislav Petkov
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Chris Wilson @ 2015-10-19  9:58 UTC (permalink / raw)
  To: linux-kernel
  Cc: Chris Wilson, Ross Zwisler, H . Peter Anvin, Imre Deak,
	Daniel Vetter, dri-devel

During testing we observed that the last cacheline was not being flushed
from a

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

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...

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92501
Testcase: gem_tiled_partial_pwrite_pread/read
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: H. Peter Anvin <hpa@linux.intel.com>
Cc: Imre Deak <imre.deak@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
---
 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",
 		       X86_FEATURE_CLFLUSHOPT,
 		       "+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)
-- 
2.6.1


^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2016-01-13 18:45 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-19  9:58 [PATCH] x86: Add an explicit barrier() to clflushopt() Chris Wilson
2015-10-19 10:16 ` Borislav Petkov
2015-10-19 11:05   ` Chris Wilson
2015-10-19 11:25     ` Borislav Petkov
2015-10-19 18:29 ` Ross Zwisler
2016-01-07 10:16 ` Chris Wilson
2016-01-07 17:55   ` Andy Lutomirski
2016-01-07 19:44     ` Chris Wilson
2016-01-07 21:05       ` H. Peter Anvin
2016-01-07 21:54         ` Chris Wilson
2016-01-07 22:29           ` H. Peter Anvin
2016-01-07 22:32             ` H. Peter Anvin
2016-01-09  5:55               ` H. Peter Anvin
2016-01-09  8:01               ` Chris Wilson
2016-01-09 22:36                 ` Andy Lutomirski
2016-01-11 11:28                   ` Chris Wilson
2016-01-11 20:11                     ` Linus Torvalds
2016-01-11 21:05                       ` Chris Wilson
2016-01-12 16:37                         ` Chris Wilson
2016-01-12 17:05                           ` Linus Torvalds
2016-01-12 21:13                             ` Chris Wilson
2016-01-12 22:07                               ` Linus Torvalds
2016-01-13  0:55                                 ` Chris Wilson
2016-01-13  2:06                                   ` Linus Torvalds
2016-01-13  2:42                                     ` Andy Lutomirski
2016-01-13  4:39                                       ` Linus Torvalds
2016-01-13 12:34                                     ` Chris Wilson
2016-01-13 18:45                                       ` Linus Torvalds
2016-01-12 17:17                     ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).