All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] libxc: create an initial FPU state for HVM guests
@ 2015-10-13 16:27 Roger Pau Monne
  2015-10-14  9:59 ` Wei Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Roger Pau Monne @ 2015-10-13 16:27 UTC (permalink / raw)
  To: xen-devel
  Cc: Wei Liu, Ian Campbell, Stefano Stabellini, Andrew Cooper,
	Ian Jackson, Jan Beulich, Roger Pau Monne

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 is 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.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Suggested-by: Jan Beulich <jbeulich@suse.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
---
Changes since v1:
 - Add a comment to clarify that the layout of the FPU context structure is
   the same for both 32 and 64bits.
 - Add Jan Beulich Suggested-by.
 - Add Andrew Cooper Reviewed-by.
---
 tools/libxc/xc_dom_x86.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/tools/libxc/xc_dom_x86.c b/tools/libxc/xc_dom_x86.c
index dd331bf..034abe0 100644
--- a/tools/libxc/xc_dom_x86.c
+++ b/tools/libxc/xc_dom_x86.c
@@ -841,6 +841,27 @@ 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;
 
@@ -908,6 +929,23 @@ 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;
 
-- 
1.9.5 (Apple Git-50.3)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] libxc: create an initial FPU state for HVM guests
  2015-10-13 16:27 [PATCH v2] libxc: create an initial FPU state for HVM guests Roger Pau Monne
@ 2015-10-14  9:59 ` Wei Liu
  2015-10-14 10:48   ` Ian Campbell
  0 siblings, 1 reply; 3+ messages in thread
From: Wei Liu @ 2015-10-14  9:59 UTC (permalink / raw)
  To: Roger Pau Monne
  Cc: Wei Liu, Ian Campbell, Stefano Stabellini, Andrew Cooper,
	Ian Jackson, Jan Beulich, xen-devel

On Tue, Oct 13, 2015 at 06:27:20PM +0200, Roger Pau Monne wrote:
> 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 is 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.
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
> Suggested-by: Jan Beulich <jbeulich@suse.com>
> Cc: Jan Beulich <jbeulich@suse.com>
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>

I think all concerns in previous version have been addressed, so this
patch is fine by me:

Acked-by: Wei Liu <wei.liu2@citrix.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] libxc: create an initial FPU state for HVM guests
  2015-10-14  9:59 ` Wei Liu
@ 2015-10-14 10:48   ` Ian Campbell
  0 siblings, 0 replies; 3+ messages in thread
From: Ian Campbell @ 2015-10-14 10:48 UTC (permalink / raw)
  To: Wei Liu, Roger Pau Monne
  Cc: xen-devel, Stefano Stabellini, Ian Jackson, Jan Beulich,
	Andrew Cooper

On Wed, 2015-10-14 at 10:59 +0100, Wei Liu wrote:
> On Tue, Oct 13, 2015 at 06:27:20PM +0200, Roger Pau Monne wrote:
> > 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 is 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.
> > 
> > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> > Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
> > Suggested-by: Jan Beulich <jbeulich@suse.com>
> > Cc: Jan Beulich <jbeulich@suse.com>
> > Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> > Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> > Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> > Cc: Ian Campbell <ian.campbell@citrix.com>
> > Cc: Wei Liu <wei.liu2@citrix.com>
> 
> I think all concerns in previous version have been addressed, so this
> patch is fine by me:
> 
> Acked-by: Wei Liu <wei.liu2@citrix.com>

I was thinking the same, so acked by me as well and applied.



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-10-14 10:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-13 16:27 [PATCH v2] libxc: create an initial FPU state for HVM guests Roger Pau Monne
2015-10-14  9:59 ` Wei Liu
2015-10-14 10:48   ` Ian Campbell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.