Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1303455

Re: [PATCH] x86: Add an explicit barrier() to clflushopt()

From Chris Wilson <chris@chris-wilson.co.uk>
Newsgroups linux.kernel
Subject Re: [PATCH] x86: Add an explicit barrier() to clflushopt()
Date 2016-01-07 11:20 +0100
Message-ID <qOfPH-6JB-7@gated-at.bofh.it> (permalink)
References <qlfou-IV-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, Oct 19, 2015 at 10:58:55AM +0100, Chris Wilson wrote:
> 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();
>  }

Or an alternative:

+#define alternative_output(oldinstr, newinstr, feature, output)        \
+       asm volatile (ALTERNATIVE(oldinstr, newinstr, feature)          \
+               : output : "i" (0) : "memory")

I would really appreciate some knowledgeable folks taking a look at the
asm for clflushopt() as it still affects today's kernel and gcc.

Fwiw, I have confirmed that arch/x86/mm/pageattr.c clflush_cache_range()
is similarly affected.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Chris Wilson <chris@chris-wilson.co.uk> - 2016-01-07 11:20 +0100
  Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Andy Lutomirski <luto@amacapital.net> - 2016-01-07 19:00 +0100
    Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Chris Wilson <chris@chris-wilson.co.uk> - 2016-01-07 20:50 +0100
      Re: [PATCH] x86: Add an explicit barrier() to clflushopt() "H. Peter Anvin" <hpa@zytor.com> - 2016-01-07 22:10 +0100
        Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Chris Wilson <chris@chris-wilson.co.uk> - 2016-01-07 23:00 +0100
          Re: [PATCH] x86: Add an explicit barrier() to clflushopt() "H. Peter Anvin" <hpa@zytor.com> - 2016-01-07 23:40 +0100
            Re: [PATCH] x86: Add an explicit barrier() to clflushopt() "H. Peter Anvin" <hpa@zytor.com> - 2016-01-07 23:40 +0100
              Re: [PATCH] x86: Add an explicit barrier() to clflushopt() "H. Peter Anvin" <hpa@zytor.com> - 2016-01-09 07:00 +0100
              Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Chris Wilson <chris@chris-wilson.co.uk> - 2016-01-09 09:10 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Andy Lutomirski <luto@amacapital.net> - 2016-01-09 23:40 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Chris Wilson <chris@chris-wilson.co.uk> - 2016-01-11 12:30 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Linus Torvalds <torvalds@linux-foundation.org> - 2016-01-11 21:20 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Chris Wilson <chris@chris-wilson.co.uk> - 2016-01-11 22:10 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Chris Wilson <chris@chris-wilson.co.uk> - 2016-01-12 17:40 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Linus Torvalds <torvalds@linux-foundation.org> - 2016-01-12 18:10 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Chris Wilson <chris@chris-wilson.co.uk> - 2016-01-12 22:20 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Linus Torvalds <torvalds@linux-foundation.org> - 2016-01-12 23:10 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Chris Wilson <chris@chris-wilson.co.uk> - 2016-01-13 02:00 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Linus Torvalds <torvalds@linux-foundation.org> - 2016-01-13 03:10 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Andy Lutomirski <luto@amacapital.net> - 2016-01-13 03:50 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Linus Torvalds <torvalds@linux-foundation.org> - 2016-01-13 05:40 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Chris Wilson <chris@chris-wilson.co.uk> - 2016-01-13 13:40 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() Linus Torvalds <torvalds@linux-foundation.org> - 2016-01-13 19:50 +0100
                Re: [PATCH] x86: Add an explicit barrier() to clflushopt() "H. Peter Anvin" <hpa@zytor.com> - 2016-01-12 18:20 +0100

csiph-web