Skip to contentSkip to conversation

x86, cpuid: add "volatile" to asm in native_cpuid()

PATCH In review Suresh Siddha 1 participant 2 messages Dec 17, 2009 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86, cpuid: add "volatile" to asm in native_cpuid()

xsave_cntxt_init() does something like:

	cpuid(0xd, ..);	// find out what features FP/SSE/.. etc are supported

	xsetbv();	// enable the features known to OS

	cpuid(0xd, ..);	// find out the size of the context for features enabled

Depending on what features get enabled in xsetbv(), value of the cpuid.eax=0xd.ecx=0.ebx changes correspondingly (representing the size of the context that is enabled).

As we don't have volatile keyword for native_cpuid(), gcc 4.1.2 optimizes away the second cpuid and the kernel continues to use the cpuid information obtained before xsetbv(), ultimately leading to kernel crash on processors supporting more state than the legacy FP/SSE.

Add "volatile" for native_cpuid().

---

arch/x86/include/asm/processor.h +1 -1
index 6f8ec1c..fc801ba 100644
@@ -181,7 +181,7 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
 				unsigned int *ecx, unsigned int *edx)
 {
 	/* ecx is often an input as well as an output. */
-	asm("cpuid"
+	asm volatile("cpuid"
 	    : "=a" (*eax),
 	      "=b" (*ebx),
 	      "=c" (*ecx),
#1 lore raw

[tip:x86/urgent] x86, cpuid: Add "volatile" to asm in native_cpuid()

Commit-ID:  45a94d7cd45ed991914011919e7d40eb6d2546d1
Gitweb:     http://git.kernel.org/tip/45a94d7cd45ed991914011919e7d40eb6d2546d1
Author:     Suresh Siddha <[email protected]>
AuthorDate: Wed, 16 Dec 2009 16:25:42 -0800
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Wed, 16 Dec 2009 16:30:57 -0800

x86, cpuid: Add "volatile" to asm in native_cpuid()

xsave_cntxt_init() does something like:

	cpuid(0xd, ..);	// find out what features FP/SSE/.. etc are supported

	xsetbv();	// enable the features known to OS

	cpuid(0xd, ..);	// find out the size of the context for features enabled

Depending on what features get enabled in xsetbv(), value of the cpuid.eax=0xd.ecx=0.ebx changes correspondingly (representing the size of the context that is enabled).

As we don't have volatile keyword for native_cpuid(), gcc 4.1.2 optimizes away the second cpuid and the kernel continues to use the cpuid information obtained before xsetbv(), ultimately leading to kernel crash on processors supporting more state than the legacy FP/SSE.

Add "volatile" for native_cpuid().

LKML-Reference: <[email protected]>

---
 arch/x86/include/asm/processor.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/include/asm/processor.h +1 -1
index 6f8ec1c..fc801ba 100644
@@ -181,7 +181,7 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
 				unsigned int *ecx, unsigned int *edx)
 {
 	/* ecx is often an input as well as an output. */
-	asm("cpuid"
+	asm volatile("cpuid"
 	    : "=a" (*eax),
 	      "=b" (*ebx),
 	      "=c" (*ecx),