public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH]: x86_64: Remove unnecessary cast in prefetch()
@ 2007-09-06 21:27 Serge Belyshev
  2007-09-07  7:18 ` Andi Kleen
  0 siblings, 1 reply; 5+ messages in thread
From: Serge Belyshev @ 2007-09-06 21:27 UTC (permalink / raw)
  To: Andi Kleen; +Cc: patches, linux-kernel


It is ok to call prefetch() function with NULL argument, as specifically
commented in include/linux/prefetch.h.  But in standard C, it is invalid to
dereference NULL pointer (see C99 standard 6.5.3.2 paragraph 4 and note #84).
Newer gcc versions (4.3 and above) will use that to conclude that "x"
argument is non-null and thus wreaking havok everywhere prefetch() was inlined.
Fixed by removing cast and changing asm constraint.

This can be fixed better by using gcc's __builtin_prefetch().

Signed-off-by: Serge Belyshev <belyshev@depni.sinp.msu.ru>

---
 include/asm-x86_64/processor.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux/include/asm-x86_64/processor.h
===================================================================
--- linux.orig/include/asm-x86_64/processor.h
+++ linux/include/asm-x86_64/processor.h
@@ -373,7 +373,7 @@ static inline void sync_core(void)
 #define ARCH_HAS_PREFETCH
 static inline void prefetch(void *x) 
 { 
-	asm volatile("prefetcht0 %0" :: "m" (*(unsigned long *)x));
+	asm volatile("prefetcht0 (%0)" :: "r" (x));
 } 
 
 #define ARCH_HAS_PREFETCHW 1

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

* Re: [PATCH]: x86_64: Remove unnecessary cast in prefetch()
  2007-09-06 21:27 [PATCH]: x86_64: Remove unnecessary cast in prefetch() Serge Belyshev
@ 2007-09-07  7:18 ` Andi Kleen
  2007-09-15  6:40   ` Serge Belyshev
  0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2007-09-07  7:18 UTC (permalink / raw)
  To: Serge Belyshev; +Cc: patches, linux-kernel

On Thursday 06 September 2007 22:27, Serge Belyshev wrote:
> It is ok to call prefetch() function with NULL argument, as specifically
> commented in include/linux/prefetch.h.  But in standard C, it is invalid to
> dereference NULL pointer (see C99 standard 6.5.3.2 paragraph 4 and note
> #84). Newer gcc versions (4.3 and above) will use that to conclude that "x"
> argument is non-null and thus wreaking havok everywhere prefetch() was
> inlined. Fixed by removing cast and changing asm constraint.
>
> This can be fixed better by using gcc's __builtin_prefetch().

I changed it to just use that. Thanks.

It seems like gcc 3.1/3.2 already supported it and that's the earliest gcc
still supported so it can be used unconditionally.

-Andi

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

* Re: [PATCH]: x86_64: Remove unnecessary cast in prefetch()
  2007-09-07  7:18 ` Andi Kleen
@ 2007-09-15  6:40   ` Serge Belyshev
  2007-09-15 20:01     ` Andi Kleen
  0 siblings, 1 reply; 5+ messages in thread
From: Serge Belyshev @ 2007-09-15  6:40 UTC (permalink / raw)
  To: Andi Kleen; +Cc: patches, linux-kernel

Andi Kleen <ak@suse.de> writes:

>> This can be fixed better by using gcc's __builtin_prefetch().
>
> I changed it to just use that. Thanks.
>
> It seems like gcc 3.1/3.2 already supported it and that's the earliest gcc
> still supported so it can be used unconditionally.
>

Hi!

Will you submit this patch for inclusion into 2.6.23?  It is important
to make kernel work with GCC 4.3 and above.  (Also note that gcc 4.2 already
smart enough to break that code, but kernel is just lucky currently).

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

* Re: [PATCH]: x86_64: Remove unnecessary cast in prefetch()
  2007-09-15  6:40   ` Serge Belyshev
@ 2007-09-15 20:01     ` Andi Kleen
  2007-09-15 21:16       ` Serge Belyshev
  0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2007-09-15 20:01 UTC (permalink / raw)
  To: Serge Belyshev; +Cc: Andi Kleen, patches, linux-kernel

On Sat, Sep 15, 2007 at 10:40:26AM +0400, Serge Belyshev wrote:
> Andi Kleen <ak@suse.de> writes:
> 
> >> This can be fixed better by using gcc's __builtin_prefetch().
> >
> > I changed it to just use that. Thanks.
> >
> > It seems like gcc 3.1/3.2 already supported it and that's the earliest gcc
> > still supported so it can be used unconditionally.
> >
> 
> Hi!
> 
> Will you submit this patch for inclusion into 2.6.23?  It is important

Didn't plan it currently.

> to make kernel work with GCC 4.3 and above.  (Also note that gcc 4.2 already
> smart enough to break that code, but kernel is just lucky currently).

How would it break the code exactly?  It more sounded like an optimization
to me. Would it generate incorrect code without it?

-Andi

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

* Re: [PATCH]: x86_64: Remove unnecessary cast in prefetch()
  2007-09-15 20:01     ` Andi Kleen
@ 2007-09-15 21:16       ` Serge Belyshev
  0 siblings, 0 replies; 5+ messages in thread
From: Serge Belyshev @ 2007-09-15 21:16 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Andi Kleen, patches, linux-kernel

Andi Kleen <andi@firstfloor.org> writes:

...
>> to make kernel work with GCC 4.3 and above.  (Also note that gcc 4.2 already
>> smart enough to break that code, but kernel is just lucky currently).
>
> How would it break the code exactly?  It more sounded like an optimization
> to me. Would it generate incorrect code without it?


See http://gcc.gnu.org/PR33294 for testcase which fails if compiled with gcc 4.2
and above.  Yes, incorrect code can be generated without the patch as demonstrated by
testcase, but i didn't analyze why kernel appears to work with 4.2 currently.

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

end of thread, other threads:[~2007-09-15 21:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-06 21:27 [PATCH]: x86_64: Remove unnecessary cast in prefetch() Serge Belyshev
2007-09-07  7:18 ` Andi Kleen
2007-09-15  6:40   ` Serge Belyshev
2007-09-15 20:01     ` Andi Kleen
2007-09-15 21:16       ` Serge Belyshev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox