Skip to contentSkip to conversation

Introduce a fpu_initilised field to HVM CPU context

PATCH Superseded Roger Pau Monne 3 participants 18 messages Nov 18, 2015 – Nov 24, 2015

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover Introduce a fpu_initilised field to HVM CPU context

Hello,

This patch series tries to properly solve the problem seen with the HVMlite series, that Xen always assumes the FPU is initialised on CPU context restore.

Roger.

#1 lore raw

PATCH v3 1/4 xen/save: pass a size parameter to the HVM compat functions

In order to cope with types having multiple compat versions pass a size parameter to the fixup function so we can identify which compat version Xen is dealing with.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Tim Deegan <[email protected]>

---
Changes since v2:
- Size is uint32_t not int.
- Pass the actual size of the record and not the size of the whole stream.

---
 xen/include/public/arch-x86/hvm/save.h |  2 +-
 xen/include/public/hvm/save.h          | 10 ++++++----
 xen/include/xen/hvm/save.h             |  4 +++-
 3 files changed, 10 insertions(+), 6 deletions(-)
xen/include/public/arch-x86/hvm/save.h +1 -1
index efb0b62..29d513c 100644
@@ -268,7 +268,7 @@ struct hvm_hw_cpu_compat {
     uint32_t error_code;
 };
 
-static inline int _hvm_hw_fix_cpu(void *h) {
+static inline int _hvm_hw_fix_cpu(void *h, uint32_t size) {
 
     union hvm_hw_cpu_union {
         struct hvm_hw_cpu nat;
xen/include/public/hvm/save.h +6 -4
index cc8b5fd..0bd240d 100644
@@ -63,13 +63,15 @@ struct hvm_save_descriptor {
 
 #ifdef __XEN__
 # define DECLARE_HVM_SAVE_TYPE_COMPAT(_x, _code, _type, _ctype, _fix)     \
-    static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h) { return _fix(h); } \
-    struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[2];}; \
+    static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h, uint32_t size)  \
+        { return _fix(h, size); }                                         \
+    struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[2];};  \
     struct __HVM_SAVE_TYPE_COMPAT_##_x { _ctype t; }                   
 
 # include <xen/lib.h> /* BUG() */
 # define DECLARE_HVM_SAVE_TYPE(_x, _code, _type)                         \
-    static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h) { BUG(); return -1; } \
+    static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h, uint32_t size) \
+        { BUG(); return -1; }                                            \
     struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];}; \
     struct __HVM_SAVE_TYPE_COMPAT_##_x { _type t; }                   
 #else
@@ -89,7 +91,7 @@ struct hvm_save_descriptor {
 # define HVM_SAVE_LENGTH_COMPAT(_x) (sizeof (HVM_SAVE_TYPE_COMPAT(_x)))
 
 # define HVM_SAVE_HAS_COMPAT(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->cpt)-1)
-# define HVM_SAVE_FIX_COMPAT(_x, _dst) __HVM_SAVE_FIX_COMPAT_##_x(_dst)
+# define HVM_SAVE_FIX_COMPAT(_x, _dst, _size) __HVM_SAVE_FIX_COMPAT_##_x(_dst, _size)
 #endif
 
 /* 
xen/include/xen/hvm/save.h +3 -1
index aa27a50..a97694e 100644
@@ -60,6 +60,8 @@ void _hvm_read_entry(struct hvm_domain_context *h,
  */
 #define _hvm_load_entry(_x, _h, _dst, _strict) ({                       \
     int r;                                                              \
+    struct hvm_save_descriptor *d                                       \
+        = (struct hvm_save_descriptor *)&(_h)->data[(_h)->cur];         \
     if ( (r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x),                 \
                HVM_SAVE_LENGTH(_x), (_strict))) == 0 )                  \
         _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH(_x));             \
@@ -67,7 +69,7 @@ void _hvm_read_entry(struct hvm_domain_context *h,
              && (r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x),          \
                        HVM_SAVE_LENGTH_COMPAT(_x), (_strict))) == 0 ) { \
         _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH_COMPAT(_x));      \
-        r=HVM_SAVE_FIX_COMPAT(_x, (_dst));                              \
+        r = HVM_SAVE_FIX_COMPAT(_x, (_dst), d->length);                 \
     }                                                                   \
     r; })
 
Signature · 7 lines
1.9.5 (Apple Git-50.3)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v3 1/4
#2 lore raw

Re: [PATCH v3 1/4] xen/save: pass a size parameter to the HVM compat functions

Quoted 9 lines · Roger Pau Monne

In order to cope with types having multiple compat versions pass a size parameter to the fixup function so we can identify which compat version Xen is dealing with.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Tim Deegan <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH v3 1/4] xen/save: pass a size parameter to the HVM compat functions

In reply to Roger Pau Monne

xen/include/xen/hvm/save.h void _hvm_read_entry(struct hvm_domain_context *h, · line 64

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 18.11.15 at 17:37, <[email protected]> wrote:
xen/include/xen/hvm/save.h +2 -0
@@ -60,6 +60,8 @@ void _hvm_read_entry(struct hvm_domain_context *h,
  */
 #define _hvm_load_entry(_x, _h, _dst, _strict) ({                       \
     int r;                                                              \
+    struct hvm_save_descriptor *d                                       \
+        = (struct hvm_save_descriptor *)&(_h)->data[(_h)->cur];         \

This would seem to belong in the else if() body below. Also I don't think "d" is a suitable name for a variable inside a macro (albeit the same would apply to "r" too).

Jan

#4 lore raw

Re: [PATCH v3 1/4] xen/save: pass a size parameter to the HVM compat functions

El 20/11/15 a les 16.37, Jan Beulich ha escrit:

Quoted 13 lines

xen/include/xen/hvm/save.h void _hvm_read_entry(struct hvm_domain_context *h, · line 64

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 18.11.15 at 17:37, <[email protected]> wrote:
xen/include/xen/hvm/save.h +2 -0
@@ -60,6 +60,8 @@ void _hvm_read_entry(struct hvm_domain_context *h,
  */
 #define _hvm_load_entry(_x, _h, _dst, _strict) ({                       \
     int r;                                                              \
+    struct hvm_save_descriptor *d                                       \
+        = (struct hvm_save_descriptor *)&(_h)->data[(_h)->cur];         \

This would seem to belong in the else if() body below. Also I don't think "d" is a suitable name for a variable inside a macro (albeit the same would apply to "r" too).

Patch #2 makes use of "d" in the first "if" branch also. I don't think it makes much sense to put it inside of the "else if" branch if I have to move it in the following patch.

Regarding the name, I don't have a strong opinion, desc is more descriptive, but it's also longer which means I might have to break some lines inside of the macro even more.

Roger.

#5 lore raw

Re: [PATCH v3 1/4] xen/save: pass a size parameter to the HVM compat functions

Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 24.11.15 at 13:54, <[email protected]> wrote:

El 20/11/15 a les 16.37, Jan Beulich ha escrit:

Quoted 13 lines

xen/include/xen/hvm/save.h void _hvm_read_entry(struct hvm_domain_context *h, · line 64

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 18.11.15 at 17:37, <[email protected]> wrote:
xen/include/xen/hvm/save.h +2 -0
@@ -60,6 +60,8 @@ void _hvm_read_entry(struct hvm_domain_context *h,
  */
 #define _hvm_load_entry(_x, _h, _dst, _strict) ({                       \
     int r;                                                              \
+    struct hvm_save_descriptor *d                                       \
+        = (struct hvm_save_descriptor *)&(_h)->data[(_h)->cur];         \

This would seem to belong in the else if() body below. Also I don't think "d" is a suitable name for a variable inside a macro (albeit the same would apply to "r" too).

Quoted 3 lines

Patch #2 makes use of "d" in the first "if" branch also. I don't think it makes much sense to put it inside of the "else if" branch if I have to move it in the following patch.

Yes, I saw that, and while you could move in patch 2 I agree it doesn't make much sense.

Quoted 3 lines

Regarding the name, I don't have a strong opinion, desc is more descriptive, but it's also longer which means I might have to break some lines inside of the macro even more.

At least d_ perhaps then?

Jan

#6 lore raw

Re: [PATCH v3 1/4] xen/save: pass a size parameter to the HVM compat functions

El 24/11/15 a les 14.06, Jan Beulich ha escrit:

Quoted 20 lines
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 24.11.15 at 13:54, <[email protected]> wrote:

El 20/11/15 a les 16.37, Jan Beulich ha escrit:

Quoted 13 lines

xen/include/xen/hvm/save.h void _hvm_read_entry(struct hvm_domain_context *h, · line 64

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 18.11.15 at 17:37, <[email protected]> wrote:
xen/include/xen/hvm/save.h +2 -0
@@ -60,6 +60,8 @@ void _hvm_read_entry(struct hvm_domain_context *h,
  */
 #define _hvm_load_entry(_x, _h, _dst, _strict) ({                       \
     int r;                                                              \
+    struct hvm_save_descriptor *d                                       \
+        = (struct hvm_save_descriptor *)&(_h)->data[(_h)->cur];         \

This would seem to belong in the else if() body below. Also I don't think "d" is a suitable name for a variable inside a macro (albeit the same would apply to "r" too).

Quoted 3 lines

Patch #2 makes use of "d" in the first "if" branch also. I don't think it makes much sense to put it inside of the "else if" branch if I have to move it in the following patch.

Quoted 8 lines

Yes, I saw that, and while you could move in patch 2 I agree it doesn't make much sense.

Quoted 3 lines

Regarding the name, I don't have a strong opinion, desc is more descriptive, but it's also longer which means I might have to break some lines inside of the macro even more.

At least d_ perhaps then?

I've called it "desc", I hope it's fine.

Roger.

#7 lore raw

PATCH v3 2/4 xen/save: allow the usage of zeroextend and a fixup function

In reply to Roger Pau Monne

With the current compat implementation in the save/restore context handling, only one compat structure is allowed, and using _zeroextend prevents the fixup function from being called.

In order to allow for the compat handling layer to be able to handle different compat versions allow calling the fixup function with hvm_load_entry_zeroextend.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Tim Deegan <[email protected]>
---
 xen/include/xen/hvm/save.h | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)
xen/include/xen/hvm/save.h +16 -13
index a97694e..22bcdb9 100644
@@ -58,19 +58,22 @@ void _hvm_read_entry(struct hvm_domain_context *h,
  * Unmarshalling: check, then copy. Evaluates to zero on success. This load
  * function requires the save entry to be the same size as the dest structure.
  */
-#define _hvm_load_entry(_x, _h, _dst, _strict) ({                       \
-    int r;                                                              \
-    struct hvm_save_descriptor *d                                       \
-        = (struct hvm_save_descriptor *)&(_h)->data[(_h)->cur];         \
-    if ( (r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x),                 \
-               HVM_SAVE_LENGTH(_x), (_strict))) == 0 )                  \
-        _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH(_x));             \
-    else if (HVM_SAVE_HAS_COMPAT(_x)                                    \
-             && (r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x),          \
-                       HVM_SAVE_LENGTH_COMPAT(_x), (_strict))) == 0 ) { \
-        _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH_COMPAT(_x));      \
-        r = HVM_SAVE_FIX_COMPAT(_x, (_dst), d->length);                 \
-    }                                                                   \
+#define _hvm_load_entry(_x, _h, _dst, _strict) ({                           \
+    int r;                                                                  \
+    struct hvm_save_descriptor *d                                           \
+        = (struct hvm_save_descriptor *)&(_h)->data[(_h)->cur];             \
+    if ( (r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x),                     \
+               HVM_SAVE_LENGTH(_x), (_strict))) == 0 ) {                    \
+        _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH(_x));                 \
+        if ( HVM_SAVE_HAS_COMPAT(_x) && d->length != HVM_SAVE_LENGTH(_x) )  \
+            r = HVM_SAVE_FIX_COMPAT(_x, (_dst), d->length);                 \
+    }                                                                       \
+    else if (HVM_SAVE_HAS_COMPAT(_x)                                        \
+             && (r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x),              \
+                       HVM_SAVE_LENGTH_COMPAT(_x), (_strict))) == 0 ) {     \
+        _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH_COMPAT(_x));          \
+        r = HVM_SAVE_FIX_COMPAT(_x, (_dst), d->length);                     \
+    }                                                                       \
     r; })
 
 #define hvm_load_entry(_x, _h, _dst)            \
Signature · 7 lines
1.9.5 (Apple Git-50.3)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#8 lore raw

Re: [PATCH v3 2/4] xen/save: allow the usage of zeroextend and a fixup function

Quoted 8 lines · Roger Pau Monne

With the current compat implementation in the save/restore context handling, only one compat structure is allowed, and using _zeroextend prevents the fixup function from being called.

In order to allow for the compat handling layer to be able to handle different compat versions allow calling the fixup function with hvm_load_entry_zeroextend.

Quoted 5 lines
Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Tim Deegan <[email protected]>

Eww - how nasty.

I believe the only actual change here is:

+ if ( HVM_SAVE_HAS_COMPAT(_x) && d->length !=
HVM_SAVE_LENGTH(_x) ) \
+ r = HVM_SAVE_FIX_COMPAT(_x, (_dst),
d->length); \

which looks to be appropriate.

If so, Reviewed-by: Andrew Cooper <[email protected]>

Quoted 34 lines
---
 xen/include/xen/hvm/save.h | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)
xen/include/xen/hvm/save.h +9 -13
index a97694e..22bcdb9 100644
@@ -58,19 +58,22 @@ void _hvm_read_entry(struct hvm_domain_context *h,
  * Unmarshalling: check, then copy. Evaluates to zero on success. This load
  * function requires the save entry to be the same size as the dest structure.
  */
-#define _hvm_load_entry(_x, _h, _dst, _strict) ({                       \
-    int r;                                                              \
-    struct hvm_save_descriptor *d                                       \
-        = (struct hvm_save_descriptor *)&(_h)->data[(_h)->cur];         \
-    if ( (r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x),                 \
-               HVM_SAVE_LENGTH(_x), (_strict))) == 0 )                  \
-        _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH(_x));             \
-    else if (HVM_SAVE_HAS_COMPAT(_x)                                    \
-             && (r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x),          \
-                       HVM_SAVE_LENGTH_COMPAT(_x), (_strict))) == 0 ) { \
-        _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH_COMPAT(_x));      \
-        r = HVM_SAVE_FIX_COMPAT(_x, (_dst), d->length);                 \
-    }                                                                   \
+#define _hvm_load_entry(_x, _h, _dst, _strict) ({                           \
+    int r;                                                                  \
+    struct hvm_save_descriptor *d                                           \
+        = (struct hvm_save_descriptor *)&(_h)->data[(_h)->cur];             \
+    if ( (r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x),                     \
+               HVM_SAVE_LENGTH(_x), (_strict))) == 0 ) {                    \
+        _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH(_x));                 \
+        if ( HVM_SAVE_HAS_COMPAT(_x) && d->length != HVM_SAVE_LENGTH(_x) )  \
+            r = HVM_SAVE_FIX_COMPAT(_x, (_dst), d->length);                 \

xen/include/xen/hvm/save.h void _hvm_read_entry(struct hvm_domain_context *h, · line 79

Quoted 10 lines
xen/include/xen/hvm/save.h +7 -0
+    }                                                                       \
+    else if (HVM_SAVE_HAS_COMPAT(_x)                                        \
+             && (r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x),              \
+                       HVM_SAVE_LENGTH_COMPAT(_x), (_strict))) == 0 ) {     \
+        _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH_COMPAT(_x));          \
+        r = HVM_SAVE_FIX_COMPAT(_x, (_dst), d->length);                     \
+    }                                                                       \
     r; })
 
 #define hvm_load_entry(_x, _h, _dst)            \

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#9 lore raw

Re: [PATCH v3 2/4] xen/save: allow the usage of zeroextend and a fixup function

In reply to Roger Pau Monne
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 18.11.15 at 17:37, <[email protected]> wrote:

+ if ( HVM_SAVE_HAS_COMPAT(_x) && d->length != HVM_SAVE_LENGTH(_x) ) \

If you broke this line at the && you could avoid all the churn to move out the \ by a few spaces. That would also have avoided Andrew's request for re-assurance that the addition here was the only actual change.

Jan

#10 lore raw

PATCH v3 3/4 xen/hvm: introduce a fpu_uninitialised field to the CPU save record

In reply to Roger Pau Monne

Introduce a new field to signal if the FPU has been initialised or not. Xen needs this new field in order to know whether to set the FPU as initialised or not during restore of CPU context. Previously Xen always wrongly assumed the FPU was initialised on restore.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>

---
Changes since v1:
- Don't add yet another compat structure, new fields should always be added to the end of the existing structure and offsetof should be used to compare sizes.
- Leave the previous compat structure as-is, since the field was not added to the end we cannot remove it and use offsetof in this case.
- Set xstate_bv based on fpu_initialised value instead of unconditionally setting it to XSTATE_FP_SSE.

---
 xen/arch/x86/hvm/hvm.c                 |  8 +++++---
 xen/include/public/arch-x86/hvm/save.h | 26 +++++++++++++++++++-------
 2 files changed, 24 insertions(+), 10 deletions(-)
xen/arch/x86/hvm/hvm.c +5 -3
index ea982e2..72a4e4f 100644
@@ -1800,6 +1800,7 @@ static int hvm_save_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
             memcpy(ctxt.fpu_regs, v->arch.fpu_ctxt, sizeof(ctxt.fpu_regs));
         else 
             memset(ctxt.fpu_regs, 0, sizeof(ctxt.fpu_regs));
+        ctxt.fpu_initialised = v->fpu_initialised;
 
         ctxt.rax = v->arch.user_regs.eax;
         ctxt.rbx = v->arch.user_regs.ebx;
@@ -1979,7 +1980,7 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
         return -EINVAL;
     }
 
-    if ( hvm_load_entry(CPU, h, &ctxt) != 0 ) 
+    if ( hvm_load_entry_zeroextend(CPU, h, &ctxt) != 0 )
         return -EINVAL;
 
     /* Sanity check some control registers. */
@@ -2091,7 +2092,8 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
         struct xsave_struct *xsave_area = v->arch.xsave_area;
 
         memcpy(v->arch.xsave_area, ctxt.fpu_regs, sizeof(ctxt.fpu_regs));
-        xsave_area->xsave_hdr.xstate_bv = XSTATE_FP_SSE;
+        xsave_area->xsave_hdr.xstate_bv = ctxt.fpu_initialised ?
+                                                    XSTATE_FP_SSE : 0;
     }
     else
         memcpy(v->arch.fpu_ctxt, ctxt.fpu_regs, sizeof(ctxt.fpu_regs));
@@ -2122,7 +2124,7 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
     v->arch.debugreg[7] = ctxt.dr7;
 
     v->arch.vgc_flags = VGCF_online;
-    v->fpu_initialised = 1;
+    v->fpu_initialised = !!ctxt.fpu_initialised;
 
     /* Auxiliary processors should be woken immediately. */
     v->is_initialised = 1;
xen/include/public/arch-x86/hvm/save.h +19 -7
index 29d513c..0f7ef5a 100644
@@ -47,7 +47,9 @@ DECLARE_HVM_SAVE_TYPE(HEADER, 1, struct hvm_save_header);
 /*
  * Processor
  *
- * Compat: Pre-3.4 didn't have msr_tsc_aux
+ * Compat:
+ *     - Pre-3.4 didn't have msr_tsc_aux
+ *     - Pre-4.7 didn't have fpu_initialised
  */
 
 struct hvm_hw_cpu {
@@ -157,6 +159,8 @@ struct hvm_hw_cpu {
     };
     /* error code for pending event */
     uint32_t error_code;
+    /* is fpu initialised? */
+    uint32_t fpu_initialised;
 };
 
 struct hvm_hw_cpu_compat {
@@ -266,6 +270,7 @@ struct hvm_hw_cpu_compat {
     };
     /* error code for pending event */
     uint32_t error_code;
+    /*uint32_t fpu_initialised; COMPAT */
 };
 
 static inline int _hvm_hw_fix_cpu(void *h, uint32_t size) {
@@ -275,12 +280,19 @@ static inline int _hvm_hw_fix_cpu(void *h, uint32_t size) {
         struct hvm_hw_cpu_compat cmp;
     } *ucpu = (union hvm_hw_cpu_union *)h;
 
-    /* If we copy from the end backwards, we should
-     * be able to do the modification in-place */
-    ucpu->nat.error_code = ucpu->cmp.error_code;
-    ucpu->nat.pending_event = ucpu->cmp.pending_event;
-    ucpu->nat.tsc = ucpu->cmp.tsc;
-    ucpu->nat.msr_tsc_aux = 0;
+    if ( size == sizeof(struct hvm_hw_cpu_compat) )
+    {
+        /*
+         * If we copy from the end backwards, we should
+         * be able to do the modification in-place.
+         */
+        ucpu->nat.error_code = ucpu->cmp.error_code;
+        ucpu->nat.pending_event = ucpu->cmp.pending_event;
+        ucpu->nat.tsc = ucpu->cmp.tsc;
+        ucpu->nat.msr_tsc_aux = 0;
+    }
+    /* Mimic the old behaviour by unconditionally setting fpu_initialised. */
+    ucpu->nat.fpu_initialised = 1;
 
     return 0;
 }
Signature · 7 lines
1.9.5 (Apple Git-50.3)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v3 3/4
#11 lore raw

Re: [PATCH v3 3/4] xen/hvm: introduce a fpu_uninitialised field to the CPU save record

Quoted 8 lines · Roger Pau Monne

Introduce a new field to signal if the FPU has been initialised or not. Xen needs this new field in order to know whether to set the FPU as initialised or not during restore of CPU context. Previously Xen always wrongly assumed the FPU was initialised on restore.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#12 lore raw

Re: [PATCH v3 3/4] xen/hvm: introduce a fpu_uninitialised field to the CPU save record

In reply to Roger Pau Monne

xen/arch/x86/hvm/hvm.c static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 2099

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 18.11.15 at 17:37, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +2 -1
@@ -2091,7 +2092,8 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
         struct xsave_struct *xsave_area = v->arch.xsave_area;
 
         memcpy(v->arch.xsave_area, ctxt.fpu_regs, sizeof(ctxt.fpu_regs));
-        xsave_area->xsave_hdr.xstate_bv = XSTATE_FP_SSE;
+        xsave_area->xsave_hdr.xstate_bv = ctxt.fpu_initialised ?
+                                                    XSTATE_FP_SSE : 0;
     }
     else
         memcpy(v->arch.fpu_ctxt, ctxt.fpu_regs, sizeof(ctxt.fpu_regs));

Question is - are the memcpy()s here really meaningful/valid when !ctxt.fpu_initialized? I.e. shouldn't this code rather be skipped instead of getting modified?

xen/include/public/arch-x86/hvm/save.h struct hvm_hw_cpu { · line 163

Quoted 6 lines
xen/include/public/arch-x86/hvm/save.h +2 -0
@@ -157,6 +159,8 @@ struct hvm_hw_cpu {
     };
     /* error code for pending event */
     uint32_t error_code;
+    /* is fpu initialised? */
+    uint32_t fpu_initialised;

A whole uint32_t for just one bit? Didn't we talk about making this new field a flags one, consuming just one bit from it?

xen/include/public/arch-x86/hvm/save.h struct hvm_hw_cpu_compat { · line 274

Quoted 6 lines
xen/include/public/arch-x86/hvm/save.h +1 -0
@@ -266,6 +270,7 @@ struct hvm_hw_cpu_compat {
     };
     /* error code for pending event */
     uint32_t error_code;
+    /*uint32_t fpu_initialised; COMPAT */
 };

I think this is misleading - the compat structure never has this field.

Jan

#13 lore raw

Re: [PATCH v3 3/4] xen/hvm: introduce a fpu_uninitialised field to the CPU save record

El 20/11/15 a les 16.49, Jan Beulich ha escrit:

Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.11.15 at 17:37, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +0 -0
@@ -2091,7 +2092,8 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
         struct xsave_struct *xsave_area = v->arch.xsave_area;
 
Quoted 11 lines

xen/arch/x86/hvm/hvm.c static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 2099

Quoted 7 lines
xen/arch/x86/hvm/hvm.c +2 -1
         memcpy(v->arch.xsave_area, ctxt.fpu_regs, sizeof(ctxt.fpu_regs));
-        xsave_area->xsave_hdr.xstate_bv = XSTATE_FP_SSE;
+        xsave_area->xsave_hdr.xstate_bv = ctxt.fpu_initialised ?
+                                                    XSTATE_FP_SSE : 0;
     }
     else
         memcpy(v->arch.fpu_ctxt, ctxt.fpu_regs, sizeof(ctxt.fpu_regs));

Question is - are the memcpy()s here really meaningful/valid when !ctxt.fpu_initialized? I.e. shouldn't this code rather be skipped instead of getting modified?

If !fpu_initialized the fpu context save record is all zeroed out. I don't think it matters much (apart from saving a few CPU cycles). I can send a new version that doesn't save/restore the fpu context at all if !fpu_initialised.

Quoted 9 lines

xen/include/public/arch-x86/hvm/save.h struct hvm_hw_cpu { · line 163

Quoted 6 lines
xen/include/public/arch-x86/hvm/save.h +2 -0
@@ -157,6 +159,8 @@ struct hvm_hw_cpu {
     };
     /* error code for pending event */
     uint32_t error_code;
+    /* is fpu initialised? */
+    uint32_t fpu_initialised;

A whole uint32_t for just one bit? Didn't we talk about making this new field a flags one, consuming just one bit from it?

AFAIK we agreed on adding this field to the tail and making it a uint32_t so that when new fields are added they can be detected by looking at the size of the structure:

http://marc.info/?l=xen-devel&m=144490321208291

Quoted 8 lines

xen/include/public/arch-x86/hvm/save.h struct hvm_hw_cpu_compat { · line 274

Quoted 6 lines
xen/include/public/arch-x86/hvm/save.h +1 -0
@@ -266,6 +270,7 @@ struct hvm_hw_cpu_compat {
     };
     /* error code for pending event */
     uint32_t error_code;
+    /*uint32_t fpu_initialised; COMPAT */
 };

I think this is misleading - the compat structure never has this field.

Right, I will remove it.

Roger.

#14 lore raw

Re: [PATCH v3 3/4] xen/hvm: introduce a fpu_uninitialised field to the CPU save record

Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 24.11.15 at 14:10, <[email protected]> wrote:

El 20/11/15 a les 16.49, Jan Beulich ha escrit:

Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.11.15 at 17:37, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +0 -0
@@ -2091,7 +2092,8 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
         struct xsave_struct *xsave_area = v->arch.xsave_area;
 
Quoted 11 lines

xen/arch/x86/hvm/hvm.c static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 2099

Quoted 7 lines
xen/arch/x86/hvm/hvm.c +2 -1
         memcpy(v->arch.xsave_area, ctxt.fpu_regs, sizeof(ctxt.fpu_regs));
-        xsave_area->xsave_hdr.xstate_bv = XSTATE_FP_SSE;
+        xsave_area->xsave_hdr.xstate_bv = ctxt.fpu_initialised ?
+                                                    XSTATE_FP_SSE : 0;
     }
     else
         memcpy(v->arch.fpu_ctxt, ctxt.fpu_regs, sizeof(ctxt.fpu_regs));

Question is - are the memcpy()s here really meaningful/valid when !ctxt.fpu_initialized? I.e. shouldn't this code rather be skipped instead of getting modified?

Quoted 4 lines

If !fpu_initialized the fpu context save record is all zeroed out. I don't think it matters much (apart from saving a few CPU cycles). I can send a new version that doesn't save/restore the fpu context at all if !fpu_initialised.

I'd appreciate that (ideally with if(!fpu_initialised) memset(); else if ...).

Quoted 10 lines
Quoted 9 lines

xen/include/public/arch-x86/hvm/save.h struct hvm_hw_cpu { · line 163

Quoted 6 lines
xen/include/public/arch-x86/hvm/save.h +2 -0
@@ -157,6 +159,8 @@ struct hvm_hw_cpu {
     };
     /* error code for pending event */
     uint32_t error_code;
+    /* is fpu initialised? */
+    uint32_t fpu_initialised;

A whole uint32_t for just one bit? Didn't we talk about making this new field a flags one, consuming just one bit from it?

Quoted 5 lines

AFAIK we agreed on adding this field to the tail and making it a uint32_t so that when new fields are added they can be detected by looking at the size of the structure:

http://marc.info/?l=xen-devel&m=144490321208291

Admittedly it's a little implicit, but that mail has, in its quoting parts,

"... (and validate unused tail bits are zero, so they can be used for something later on)"

going back to that intention of using just a single bit here afaict.

Jan

#15 lore raw

Re: [PATCH v3 3/4] xen/hvm: introduce a fpu_uninitialised field to the CPU save record

El 24/11/15 a les 14.34, Jan Beulich ha escrit:

Quoted 39 lines
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 24.11.15 at 14:10, <[email protected]> wrote:

El 20/11/15 a les 16.49, Jan Beulich ha escrit:

Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.11.15 at 17:37, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +0 -0
@@ -2091,7 +2092,8 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
         struct xsave_struct *xsave_area = v->arch.xsave_area;
 
Quoted 11 lines

xen/arch/x86/hvm/hvm.c static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 2099

Quoted 7 lines
xen/arch/x86/hvm/hvm.c +2 -1
         memcpy(v->arch.xsave_area, ctxt.fpu_regs, sizeof(ctxt.fpu_regs));
-        xsave_area->xsave_hdr.xstate_bv = XSTATE_FP_SSE;
+        xsave_area->xsave_hdr.xstate_bv = ctxt.fpu_initialised ?
+                                                    XSTATE_FP_SSE : 0;
     }
     else
         memcpy(v->arch.fpu_ctxt, ctxt.fpu_regs, sizeof(ctxt.fpu_regs));

Question is - are the memcpy()s here really meaningful/valid when !ctxt.fpu_initialized? I.e. shouldn't this code rather be skipped instead of getting modified?

Quoted 4 lines

If !fpu_initialized the fpu context save record is all zeroed out. I don't think it matters much (apart from saving a few CPU cycles). I can send a new version that doesn't save/restore the fpu context at all if !fpu_initialised.

I'd appreciate that (ideally with if(!fpu_initialised) memset(); else if ...).

Quoted 14 lines
Quoted 9 lines

xen/include/public/arch-x86/hvm/save.h struct hvm_hw_cpu { · line 163

Quoted 6 lines
xen/include/public/arch-x86/hvm/save.h +2 -0
@@ -157,6 +159,8 @@ struct hvm_hw_cpu {
     };
     /* error code for pending event */
     uint32_t error_code;
+    /* is fpu initialised? */
+    uint32_t fpu_initialised;

A whole uint32_t for just one bit? Didn't we talk about making this new field a flags one, consuming just one bit from it?

AFAIK we agreed on adding this field to the tail and making it a uint32_t so that when new fields are added they can be detected by looking at the size of the structure:

Quoted 8 lines
Quoted 1 line

http://marc.info/?l=xen-devel&m=144490321208291

Admittedly it's a little implicit, but that mail has, in its quoting parts,

"... (and validate unused tail bits are zero, so they can be used for something later on)"

going back to that intention of using just a single bit here afaict.

Ack. I have to admit I've misunderstood that part. Then I guess the field should also have a more generic name, like "flags", and fpu_initialised should be defined as (1U << 0). Or do you want me to use the MSB in order to store the fpu_initialised bit?

Roger.

#16 lore raw

Re: [PATCH v3 3/4] xen/hvm: introduce a fpu_uninitialised field to the CPU save record

Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 24.11.15 at 15:38, <[email protected]> wrote:

El 24/11/15 a les 14.34, Jan Beulich ha escrit:

Quoted 21 lines
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 24.11.15 at 14:10, <[email protected]> wrote:

El 20/11/15 a les 16.49, Jan Beulich ha escrit:

Quoted 10 lines

xen/include/public/arch-x86/hvm/save.h struct hvm_hw_cpu { · line 163

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.11.15 at 17:37, <[email protected]> wrote:
xen/include/public/arch-x86/hvm/save.h +2 -0
@@ -157,6 +159,8 @@ struct hvm_hw_cpu {
     };
     /* error code for pending event */
     uint32_t error_code;
+    /* is fpu initialised? */
+    uint32_t fpu_initialised;

A whole uint32_t for just one bit? Didn't we talk about making this new field a flags one, consuming just one bit from it?

Quoted 5 lines

AFAIK we agreed on adding this field to the tail and making it a uint32_t so that when new fields are added they can be detected by looking at the size of the structure:

http://marc.info/?l=xen-devel&m=144490321208291

Admittedly it's a little implicit, but that mail has, in its quoting parts,

Quoted 8 lines
Quoted 4 lines

"... (and validate unused tail bits are zero, so they can be used for something later on)"

going back to that intention of using just a single bit here afaict.

Ack. I have to admit I've misunderstood that part. Then I guess the field should also have a more generic name, like "flags", and fpu_initialised should be defined as (1U << 0).

Yes.

Jan

#17 lore raw

PATCH v3 4/4 Revert "libxc: create an initial FPU state for HVM guests"

In reply to Roger Pau Monne

This reverts commit d64dbbcc7c9934a46126c59d78536235908377ad:

Xen always set the FPU as initialized when loading a HVM context, so libxc has to provide a valid FPU context when setting the CPU registers.

This was a stop-gap measure in order to unblock OSSTest Windows 7 failures while a proper fix for the HVM CPU save/restore is being worked on.

This can now be reverted because a proper fix is in place and we can signal in the save record whether the FPU is initialized or not.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxc/xc_dom_x86.c | 38 --------------------------------------
 1 file changed, 38 deletions(-)
tools/libxc/xc_dom_x86.c +0 -38
index 7279fa2..b5e155d 100644
@@ -910,27 +910,6 @@ static int vcpu_hvm(struct xc_dom_image *dom)
         struct hvm_save_descriptor end_d;
         HVM_SAVE_TYPE(END) end;
     } bsp_ctx;
-    /*
-     * The layout of the fpu context structure is the same for
-     * both 32 and 64 bits.
-     */
-    struct {
-        uint16_t fcw;
-        uint16_t fsw;
-        uint8_t ftw;
-        uint8_t rsvd1;
-        uint16_t fop;
-        union {
-            uint64_t addr;
-            struct {
-                uint32_t offs;
-                uint16_t sel;
-                uint16_t rsvd;
-            };
-        } fip, fdp;
-        uint32_t mxcsr;
-        uint32_t mxcsr_mask;
-    } *fpu_ctxt;
     uint8_t *full_ctx = NULL;
     int rc;
 
@@ -998,23 +977,6 @@ static int vcpu_hvm(struct xc_dom_image *dom)
     /* Set the control registers. */
     bsp_ctx.cpu.cr0 = X86_CR0_PE | X86_CR0_ET;
 
-    /*
-     * XXX: Set initial FPU state.
-     *
-     * This should be removed once Xen is able to know if the
-     * FPU state saved is valid or not, now Xen always sets
-     * fpu_initialised to true regardless of the FPU state.
-     *
-     * The code below mimics the FPU sate after executing
-     * fninit
-     * ldmxcsr 0x1f80
-     */
-    fpu_ctxt = (typeof(fpu_ctxt))bsp_ctx.cpu.fpu_regs;
-
-    fpu_ctxt->fcw = 0x37f;
-    fpu_ctxt->ftw = 0xff;
-    fpu_ctxt->mxcsr = 0x1f80;
-
     /* Set the IP. */
     bsp_ctx.cpu.rip = dom->parms.phys_entry;
 
Signature · 7 lines
1.9.5 (Apple Git-50.3)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel