linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86: Fix AMD K6 indirect call check v2
@ 2013-04-21 16:49 Andi Kleen
  2013-04-21 17:06 ` H. Peter Anvin
  0 siblings, 1 reply; 8+ messages in thread
From: Andi Kleen @ 2013-04-21 16:49 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

The AMD K6 errata check relies on timing a indirect call.
But the way it was written it could be optimized to a direct call.
Force gcc to actually do a indirect call and not just
constant resolve the target address.

Found during code review, no runtime testing due to lack
of hardware.

v2: More description
Signed-off-by: Andi Kleen <ak@linux.intel.com>

diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 4a549db..11ea6f6 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -115,7 +115,7 @@ static void __cpuinit init_amd_k6(struct cpuinfo_x86 *c)
 		 */
 
 		n = K6_BUG_LOOP;
-		f_vide = vide;
+		asm("" : "=g" (f_vide) : "0" (vide));
 		rdtscl(d);
 		while (n--)
 			f_vide();

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

* Re: [PATCH] x86: Fix AMD K6 indirect call check v2
  2013-04-21 16:49 [PATCH] x86: Fix AMD K6 indirect call check v2 Andi Kleen
@ 2013-04-21 17:06 ` H. Peter Anvin
  2013-04-21 17:13   ` Andi Kleen
  2013-04-21 17:44   ` Borislav Petkov
  0 siblings, 2 replies; 8+ messages in thread
From: H. Peter Anvin @ 2013-04-21 17:06 UTC (permalink / raw)
  To: Andi Kleen; +Cc: x86, linux-kernel, Andi Kleen, Borislav Petkov

On 04/21/2013 09:49 AM, Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
> 
> The AMD K6 errata check relies on timing a indirect call.
> But the way it was written it could be optimized to a direct call.
> Force gcc to actually do a indirect call and not just
> constant resolve the target address.
> 
> Found during code review, no runtime testing due to lack
> of hardware.

Maybe it would be even better to just code the indirect call instruction
in assembly?

Something like:

	asm volatile("call *%0"
		     : : "r" (vide)
		     : "eax", "ecx", "edx");

Gotta love the metal mask(?) fix without bumping the stepping number...

	-hpa


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

* Re: [PATCH] x86: Fix AMD K6 indirect call check v2
  2013-04-21 17:06 ` H. Peter Anvin
@ 2013-04-21 17:13   ` Andi Kleen
  2013-04-21 17:44   ` Borislav Petkov
  1 sibling, 0 replies; 8+ messages in thread
From: Andi Kleen @ 2013-04-21 17:13 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Andi Kleen, x86, linux-kernel, Andi Kleen, Borislav Petkov

> Maybe it would be even better to just code the indirect call instruction
> in assembly?

I only have the simple low risk fix to offer. If you want something
gold plated you have to do/test it yourself.

-Andi


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

* Re: [PATCH] x86: Fix AMD K6 indirect call check v2
  2013-04-21 17:06 ` H. Peter Anvin
  2013-04-21 17:13   ` Andi Kleen
@ 2013-04-21 17:44   ` Borislav Petkov
  2013-04-21 22:35     ` H. Peter Anvin
  1 sibling, 1 reply; 8+ messages in thread
From: Borislav Petkov @ 2013-04-21 17:44 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Andi Kleen, x86, linux-kernel, Andi Kleen

On Sun, Apr 21, 2013 at 10:06:58AM -0700, H. Peter Anvin wrote:
> On 04/21/2013 09:49 AM, Andi Kleen wrote:
> > From: Andi Kleen <ak@linux.intel.com>
> > 
> > The AMD K6 errata check relies on timing a indirect call.
> > But the way it was written it could be optimized to a direct call.
> > Force gcc to actually do a indirect call and not just
> > constant resolve the target address.
> > 
> > Found during code review, no runtime testing due to lack
> > of hardware.
> 
> Maybe it would be even better to just code the indirect call instruction
> in assembly?
> 
> Something like:
> 
> 	asm volatile("call *%0"
> 		     : : "r" (vide)
> 		     : "eax", "ecx", "edx");
> 
> Gotta love the metal mask(?) fix without bumping the stepping number...

They fixed it in the next revision:

"Resolution Status. This erratum is corrected in the C stepping of the
AMD-K6 processor."

On page 12 here http://www.datasheetcatalog.org/datasheet/AdvancedMicroDevices/mXwsxv.pdf

But it looks some revBs got fixed too reportedly: "... before B
9730xxxx...". Who knows.

Btw, I can't help but cringe everytime I see the wording "...
instruction is speculatively executed... " in an erratum :-).

So the poor K6 had some issues with SMC, that's sad.

But I have hard time understanding what that test with the 10^6 loop
iterations is supposed to achieve. And what makes sure that the RDTSCs
don't get reordered? Or maybe K6 wasn't reordering that aggressively...

Erratum says "unpredictable system behavior" but it seems it wasn't that
unpredictable after all - otherwise the fix would've been "HLT" right
then and there. :)

Oh well.

-- 
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--

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

* Re: [PATCH] x86: Fix AMD K6 indirect call check v2
  2013-04-21 17:44   ` Borislav Petkov
@ 2013-04-21 22:35     ` H. Peter Anvin
  2013-04-21 22:48       ` Borislav Petkov
  0 siblings, 1 reply; 8+ messages in thread
From: H. Peter Anvin @ 2013-04-21 22:35 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: Andi Kleen, x86, linux-kernel, Andi Kleen

On 04/21/2013 10:44 AM, Borislav Petkov wrote:
> 
> But I have hard time understanding what that test with the 10^6 loop
> iterations is supposed to achieve. And what makes sure that the RDTSCs
> don't get reordered? Or maybe K6 wasn't reordering that aggressively...
> 
> Erratum says "unpredictable system behavior" but it seems it wasn't that
> unpredictable after all - otherwise the fix would've been "HLT" right
> then and there. :)
> 

Looks like it is just trying to sense the bug... but then it doesn't
actually do anything about it.  At least it should taint the kernel.

	-hpa



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

* Re: [PATCH] x86: Fix AMD K6 indirect call check v2
  2013-04-21 22:35     ` H. Peter Anvin
@ 2013-04-21 22:48       ` Borislav Petkov
  2013-04-22 11:25         ` Wolfram Gloger
  0 siblings, 1 reply; 8+ messages in thread
From: Borislav Petkov @ 2013-04-21 22:48 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Andi Kleen, x86, linux-kernel, Andi Kleen

On Sun, Apr 21, 2013 at 03:35:41PM -0700, H. Peter Anvin wrote:
> Looks like it is just trying to sense the bug... but then it doesn't
> actually do anything about it. At least it should taint the kernel.

Yeah, I was thinking of asking my old contacts about it but it is simply
not worth it. Those CPUs are on their way to the museum if they're not
there already.

-- 
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--

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

* Re: [PATCH] x86: Fix AMD K6 indirect call check v2
  2013-04-21 22:48       ` Borislav Petkov
@ 2013-04-22 11:25         ` Wolfram Gloger
  2013-04-22 12:58           ` Ondrej Zary
  0 siblings, 1 reply; 8+ messages in thread
From: Wolfram Gloger @ 2013-04-22 11:25 UTC (permalink / raw)
  To: linux-kernel; +Cc: wmglo

Hi,

>Yeah, I was thinking of asking my old contacts about it but it is simply
>not worth it. Those CPUs are on their way to the museum if they're not
>there already.

I have a perfectly running K6 system (the legendary K6-III I believe),
though I am about to have it taken to recycling.
If you want anything tested, I can still do it this week.

Regards,
Wolfram.

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

* Re: [PATCH] x86: Fix AMD K6 indirect call check v2
  2013-04-22 11:25         ` Wolfram Gloger
@ 2013-04-22 12:58           ` Ondrej Zary
  0 siblings, 0 replies; 8+ messages in thread
From: Ondrej Zary @ 2013-04-22 12:58 UTC (permalink / raw)
  To: Wolfram Gloger; +Cc: linux-kernel

On Monday 22 April 2013, Wolfram Gloger wrote:
> Hi,
>
> >Yeah, I was thinking of asking my old contacts about it but it is simply
> >not worth it. Those CPUs are on their way to the museum if they're not
> >there already.
>
> I have a perfectly running K6 system (the legendary K6-III I believe),
> though I am about to have it taken to recycling.
> If you want anything tested, I can still do it this week.

This bug was present on the original K6 only, not K6-2 or K6-3. I think that I 
have a K6 somewhere but I doubt that it's one of the early buggy ones.

Here are the details: http://membres.multimania.fr/poulot/k6bug_faq.html

-- 
Ondrej Zary

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

end of thread, other threads:[~2013-04-22 13:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-21 16:49 [PATCH] x86: Fix AMD K6 indirect call check v2 Andi Kleen
2013-04-21 17:06 ` H. Peter Anvin
2013-04-21 17:13   ` Andi Kleen
2013-04-21 17:44   ` Borislav Petkov
2013-04-21 22:35     ` H. Peter Anvin
2013-04-21 22:48       ` Borislav Petkov
2013-04-22 11:25         ` Wolfram Gloger
2013-04-22 12:58           ` Ondrej Zary

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