WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] x86: add volatile prefix for cpuid asm clauses

To: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] x86: add volatile prefix for cpuid asm clauses
From: "Wei, Gang" <gang.wei@xxxxxxxxx>
Date: Mon, 14 Mar 2011 21:20:12 +0800
Accept-language: zh-CN, en-US
Acceptlanguage: zh-CN, en-US
Cc: "keir.xen@xxxxxxxxx" <keir.xen@xxxxxxxxx>, "Wei, Gang" <gang.wei@xxxxxxxxx>
Delivery-date: Mon, 14 Mar 2011 06:21:55 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AcviSoxm8fAkSaikRcSaUNVkKnDYxw==
Thread-topic: [PATCH] x86: add volatile prefix for cpuid asm clauses
This is a bug fixing. So it needs go into 4.1.

x86: add volatile prefix for cpuid asm clauses

cpuid results are possible to be changed now. For example, changing CR4.OSXSAVE 
bit or setting MSR XCR_XFEATURE_ENABLED_MASK may change XSAVE related cpuid 
leave return values.

The volatile prefix is required to avoid the second cpuid calls following some 
possible changing operations being optimized in incorrect way by compiler.

The sample bug is in xsave_init while debug=n. The second call to cpuid_count() 
may be optimized and lead to a BUG_ON case while compare xsave_cntxt_size with 
ebx.

Signed-off-by: Wei Gang <gang.wei@xxxxxxxxx>

diff -r dc902ffeed73 xen/include/asm-x86/processor.h
--- a/xen/include/asm-x86/processor.h   Thu Mar 10 18:37:40 2011 +0000
+++ b/xen/include/asm-x86/processor.h   Wed Mar 16 02:30:49 2011 +0800
@@ -223,7 +223,7 @@ static always_inline void detect_ht(stru
  * resulting in stale register contents being returned.
  */
 #define cpuid(_op,_eax,_ebx,_ecx,_edx)          \
-    asm ( "cpuid"                               \
+    asm volatile ( "cpuid"                      \
           : "=a" (*(int *)(_eax)),              \
             "=b" (*(int *)(_ebx)),              \
             "=c" (*(int *)(_ecx)),              \
@@ -239,7 +239,7 @@ static inline void cpuid_count(
     unsigned int *ecx,
     unsigned int *edx)
 {
-    asm ( "cpuid"
+    asm volatile ( "cpuid"
           : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
           : "0" (op), "c" (count) );
 }
@@ -251,7 +251,7 @@ static always_inline unsigned int cpuid_
 {
     unsigned int eax;
 
-    asm ( "cpuid"
+    asm volatile ( "cpuid"
           : "=a" (eax)
           : "0" (op)
           : "bx", "cx", "dx" );
@@ -262,7 +262,7 @@ static always_inline unsigned int cpuid_
 {
     unsigned int eax, ebx;
 
-    asm ( "cpuid"
+    asm volatile ( "cpuid"
           : "=a" (eax), "=b" (ebx)
           : "0" (op)
           : "cx", "dx" );
@@ -273,7 +273,7 @@ static always_inline unsigned int cpuid_
 {
     unsigned int eax, ecx;
 
-    asm ( "cpuid"
+    asm volatile ( "cpuid"
           : "=a" (eax), "=c" (ecx)
           : "0" (op)
           : "bx", "dx" );
@@ -284,7 +284,7 @@ static always_inline unsigned int cpuid_
 {
     unsigned int eax, edx;
 
-    asm ( "cpuid"
+    asm volatile ( "cpuid"
           : "=a" (eax), "=d" (edx)
           : "0" (op)
           : "bx", "cx" );

Attachment: volatile_cpuid_macro.patch
Description: volatile_cpuid_macro.patch

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] x86: add volatile prefix for cpuid asm clauses, Wei, Gang <=