Skip to contentSkip to conversation

x86: Fix AMD K6 indirect call check

PATCH In review Andi Kleen 2 participants 3 messages Apr 21, 2013 x86

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 x86: Fix AMD K6 indirect call check

From: Andi Kleen <[email protected]>

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.

arch/x86/kernel/cpu/amd.c +1 -1
index 4a549db..11ea6f6 100644
@@ -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();
#1 lore raw
Quoted 14 lines · Andi Kleen

From: Andi Kleen <[email protected]>

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.

arch/x86/kernel/cpu/amd.c +0 -0
index 4a549db..11ea6f6 100644

arch/x86/kernel/cpu/amd.c static void __cpuinit init_amd_k6(struct cpuinfo_x86 *c) · line 121

Quoted 8 lines
arch/x86/kernel/cpu/amd.c +1 -1
@@ -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();

Would be useful to read in the changelog about how you found the bug:

- saw miscalculated values and figured out the reason
- saw a new warning in GCC
- saw it during review

?

Ingo

author
#2 lore raw
Quoted 7 lines

Would be useful to read in the changelog about how you found the bug:

- saw miscalculated values and figured out the reason
- saw a new warning in GCC
- saw it during review

?

Saw it during code review when I was fixing the code for LTO. I don't have a K6 anymore, but I still have fond memories of my K6 system.

-Andi