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: reduce magic number usage in XSAVE code (RE: [P

To: "wei.huang2@xxxxxxx" <wei.huang2@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] x86: reduce magic number usage in XSAVE code (RE: [PATCH][HVM] fix XSAVE leaf 0 EBX size calculation)
From: "Wei, Gang" <gang.wei@xxxxxxxxx>
Date: Wed, 9 Feb 2011 13:32:02 +0800
Accept-language: zh-CN, en-US
Acceptlanguage: zh-CN, en-US
Cc: Keir Fraser <keir@xxxxxxx>, "Wei, Gang" <gang.wei@xxxxxxxxx>
Delivery-date: Tue, 08 Feb 2011 21:33:34 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1296841768.2570.9.camel@weilaptop>
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>
References: <1296841768.2570.9.camel@weilaptop>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AcvEk+OzpvPtLGcTTKWkp+iZIyGnSQDhYhmQ
Thread-topic: [PATCH] x86: reduce magic number usage in XSAVE code (RE: [PATCH][HVM] fix XSAVE leaf 0 EBX size calculation)
Wei Huang wrote on 2011-02-05:
> Fixes a size calculation bug when enabled bits in XFEATURE_MASK (xcr0) 
> aren't contiguous.
> 
> Current for_loop will stop when xcr0 feature bit is 0. But in reality, 
> the bits can be non-contiguous. One example is that LWP is bit 62 on 
> AMD platform. This patch iterates through all bits to calculate the size for 
> enabled features.
> 
> Signed-off-by: Wei Huang <wei.huang2@xxxxxxx>

ACK on the patch despite it was checked in already. BTW, I want to add a 
trivial patch to limit the magic number usage in XSAVE code.

x86: reduce magic number usage in XSAVE code

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

diff -r aeda4adecaf8 xen/arch/x86/hvm/hvm.c
--- a/xen/arch/x86/hvm/hvm.c    Tue Feb 08 16:35:35 2011 +0000
+++ b/xen/arch/x86/hvm/hvm.c    Thu Feb 10 19:12:29 2011 +0800
@@ -2223,7 +2223,7 @@ void hvm_cpuid(unsigned int input, unsig
         if ( count == 0 && v->arch.xcr0 ) 
         {
             /* reset EBX to default value first */
-            *ebx = 576; 
+            *ebx = XSAVE_AREA_MIN_SIZE; 
             for ( sub_leaf = 2; sub_leaf < 64; sub_leaf++ )
             {
                 if ( !(v->arch.xcr0 & (1ULL << sub_leaf)) )
diff -r aeda4adecaf8 xen/arch/x86/i387.c
--- a/xen/arch/x86/i387.c       Tue Feb 08 16:35:35 2011 +0000
+++ b/xen/arch/x86/i387.c       Thu Feb 10 19:14:02 2011 +0800
@@ -221,7 +221,6 @@ static void restore_fpu(struct vcpu *v)
 }
 
 #define XSTATE_CPUID 0xd
-#define XSAVE_AREA_MIN_SIZE (512 + 64) /* FP/SSE + XSAVE.HEADER */
 
 /*
  * Maximum size (in byte) of the XSAVE/XRSTOR save area required by all
diff -r aeda4adecaf8 xen/include/asm-x86/i387.h
--- a/xen/include/asm-x86/i387.h        Tue Feb 08 16:35:35 2011 +0000
+++ b/xen/include/asm-x86/i387.h        Thu Feb 10 19:11:37 2011 +0800
@@ -21,13 +21,14 @@ int xsave_alloc_save_area(struct vcpu *v
 int xsave_alloc_save_area(struct vcpu *v);
 void xsave_free_save_area(struct vcpu *v);
 
+#define XSAVE_AREA_MIN_SIZE (512 + 64) /* FP/SSE + XSAVE.HEADER */
 #define XSTATE_FP       (1ULL << 0)
 #define XSTATE_SSE      (1ULL << 1)
 #define XSTATE_YMM      (1ULL << 2)
 #define XSTATE_LWP      (1ULL << 62) /* AMD lightweight profiling */
 #define XSTATE_FP_SSE   (XSTATE_FP | XSTATE_SSE)
 #define XCNTXT_MASK     (XSTATE_FP | XSTATE_SSE | XSTATE_YMM | XSTATE_LWP)
-#define XSTATE_YMM_OFFSET  (512 + 64)
+#define XSTATE_YMM_OFFSET  XSAVE_AREA_MIN_SIZE
 #define XSTATE_YMM_SIZE    256
 #define XSAVEOPT        (1 << 0)


Jimmy

Attachment: xsave_trivial_change.patch
Description: xsave_trivial_change.patch

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>