qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] WHPX: support for xcr0
@ 2019-11-07 19:48 Sunil Muthuswamy
  2019-11-07 20:05 ` Stefan Weil
                   ` (2 more replies)
  0 siblings, 3 replies; 75+ messages in thread
From: Sunil Muthuswamy @ 2019-11-07 19:48 UTC (permalink / raw)
  To: Paolo Bonzini, Richard Henderson, Eduardo Habkost; +Cc: qemu-devel

Support for xcr0 to be able to enable xsave/xrstor. This by itself
is not sufficient to enable xsave/xrstor. WHPX XSAVE API's also
needs to be hooked up.

Signed-off-by: Sunil Muthuswamy <sunilmut@microsoft.com>
---
You will need the Windows 10 SDK for RS5 (build 17763) or above to
to be able to compile this patch because of the definition of the
XCR0 register.

Changes since v1:
- Added a sign-off line in the patch.

 target/i386/whp-dispatch.h |  3 ++
 target/i386/whpx-all.c     | 88 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)

diff --git a/target/i386/whp-dispatch.h b/target/i386/whp-dispatch.h
index 23791fbb47..b5d56b22a3 100644
--- a/target/i386/whp-dispatch.h
+++ b/target/i386/whp-dispatch.h
@@ -6,6 +6,9 @@
 #include <WinHvPlatform.h>
 #include <WinHvEmulation.h>
 
+/* This should eventually come from the Windows SDK */
+#define WHV_E_UNKNOWN_PROPERTY 0x80370302
+
 #define LIST_WINHVPLATFORM_FUNCTIONS(X) \
   X(HRESULT, WHvGetCapability, (WHV_CAPABILITY_CODE CapabilityCode, VOID* CapabilityBuffer, UINT32 CapabilityBufferSizeInBytes, UINT32* WrittenSizeInBytes)) \
   X(HRESULT, WHvCreatePartition, (WHV_PARTITION_HANDLE* Partition)) \
diff --git a/target/i386/whpx-all.c b/target/i386/whpx-all.c
index ed95105eae..1abaac70db 100644
--- a/target/i386/whpx-all.c
+++ b/target/i386/whpx-all.c
@@ -161,10 +161,15 @@ struct whpx_vcpu {
 static bool whpx_allowed;
 static bool whp_dispatch_initialized;
 static HMODULE hWinHvPlatform, hWinHvEmulation;
+static WHV_PROCESSOR_XSAVE_FEATURES whpx_xsave_cap;
 
 struct whpx_state whpx_global;
 struct WHPDispatch whp_dispatch;
 
+static bool whpx_has_xsave(void)
+{
+    return whpx_xsave_cap.XsaveSupport;
+}
 
 /*
  * VP support
@@ -216,6 +221,28 @@ static SegmentCache whpx_seg_h2q(const WHV_X64_SEGMENT_REGISTER *hs)
     return qs;
 }
 
+/* X64 Extended Control Registers */
+static void whpx_set_xcrs(CPUState *cpu)
+{
+    struct CPUX86State *env = (CPUArchState *)(cpu->env_ptr);
+    HRESULT hr;
+    struct whpx_state *whpx = &whpx_global;
+    WHV_REGISTER_VALUE xcr0;
+    WHV_REGISTER_NAME xcr0_name = WHvX64RegisterXCr0;
+
+    if (!whpx_has_xsave()) {
+        return;
+    }
+
+    /* Only xcr0 is supported by the hypervisor currently */
+    xcr0.Reg64 = env->xcr0;
+    hr = whp_dispatch.WHvSetVirtualProcessorRegisters(
+        whpx->partition, cpu->cpu_index, &xcr0_name, 1, &xcr0);
+    if (FAILED(hr)) {
+        error_report("WHPX: Failed to set register xcr0, hr=%08lx", hr);
+    }
+}
+
 static void whpx_set_registers(CPUState *cpu)
 {
     struct whpx_state *whpx = &whpx_global;
@@ -291,6 +318,12 @@ static void whpx_set_registers(CPUState *cpu)
 
     /* 8 Debug Registers - Skipped */
 
+    /*
+     * Extended control registers needs to be handled separately depending
+     * on whether xsave is supported/enabled or not.
+     */
+    whpx_set_xcrs(cpu);
+
     /* 16 XMM registers */
     assert(whpx_register_names[idx] == WHvX64RegisterXmm0);
     idx_next = idx + 16;
@@ -380,6 +413,30 @@ static void whpx_set_registers(CPUState *cpu)
     return;
 }
 
+/* X64 Extended Control Registers */
+static void whpx_get_xcrs(CPUState *cpu)
+{
+    struct CPUX86State *env = (CPUArchState *)(cpu->env_ptr);
+    HRESULT hr;
+    struct whpx_state *whpx = &whpx_global;
+    WHV_REGISTER_VALUE xcr0;
+    WHV_REGISTER_NAME xcr0_name = WHvX64RegisterXCr0;
+
+    if (!whpx_has_xsave()) {
+        return;
+    }
+
+    /* Only xcr0 is supported by the hypervisor currently */
+    hr = whp_dispatch.WHvGetVirtualProcessorRegisters(
+        whpx->partition, cpu->cpu_index, &xcr0_name, 1, &xcr0);
+    if (FAILED(hr)) {
+        error_report("WHPX: Failed to get register xcr0, hr=%08lx", hr);
+        return;
+    }
+
+    env->xcr0 = xcr0.Reg64;
+}
+
 static void whpx_get_registers(CPUState *cpu)
 {
     struct whpx_state *whpx = &whpx_global;
@@ -457,6 +514,12 @@ static void whpx_get_registers(CPUState *cpu)
 
     /* 8 Debug Registers - Skipped */
 
+    /*
+     * Extended control registers needs to be handled separately depending
+     * on whether xsave is supported/enabled or not.
+     */
+    whpx_get_xcrs(cpu);
+
     /* 16 XMM registers */
     assert(whpx_register_names[idx] == WHvX64RegisterXmm0);
     idx_next = idx + 16;
@@ -1395,6 +1458,31 @@ static int whpx_accel_init(MachineState *ms)
         goto error;
     }
 
+    /*
+     * Query the XSAVE capability of the partition. Any error here is not
+     * considered fatal.
+     */
+    hr = whp_dispatch.WHvGetPartitionProperty(
+        whpx->partition,
+        WHvPartitionPropertyCodeProcessorXsaveFeatures,
+        &whpx_xsave_cap,
+        sizeof(whpx_xsave_cap),
+        &whpx_cap_size);
+
+    /*
+     * Windows version which don't support this property will return with the
+     * specific error code.
+     */
+    if (FAILED(hr) && hr != WHV_E_UNKNOWN_PROPERTY) {
+        error_report("WHPX: Failed to query XSAVE capability, hr=%08lx", hr);
+    }
+
+    if (whpx_has_xsave()) {
+        printf("WHPX: Partition XSAVE capable\n");
+    } else {
+        printf("WHPX: Partition is not XSAVE capable\n");
+    }
+
     memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY));
     prop.ProcessorCount = ms->smp.cpus;
     hr = whp_dispatch.WHvSetPartitionProperty(
-- 
2.16.4



^ permalink raw reply related	[flat|nested] 75+ messages in thread
* [Bug 1879672] [NEW] QEMU installer with WHPX support
@ 2020-05-20 10:14 Philippe Mathieu-Daudé
  2020-05-20 10:25 ` [Bug 1879672] " Daniel Berrange
                   ` (6 more replies)
  0 siblings, 7 replies; 75+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-20 10:14 UTC (permalink / raw)
  To: qemu-devel

Public bug reported:

People often ask the community to add WHPX support to the QEMU installer for Windows,
but it is impossible due to the license limitations of the WHPX SDK.

The WinHvEmulation.h and WinHvPlatform.h header files needed are "All
rights reserved".

However these headers only contain struct definitions and integer constants,
no functional code in macros or inline functions. See:
https://www.mail-archive.com/qemu-devel@nongnu.org/msg645815.html
It is questionable whether the headers alone can be considered copyrightable material.

** Affects: qemu
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1879672

Title:
  QEMU installer with WHPX support

Status in QEMU:
  New

Bug description:
  People often ask the community to add WHPX support to the QEMU installer for Windows,
  but it is impossible due to the license limitations of the WHPX SDK.

  The WinHvEmulation.h and WinHvPlatform.h header files needed are "All
  rights reserved".

  However these headers only contain struct definitions and integer constants,
  no functional code in macros or inline functions. See:
  https://www.mail-archive.com/qemu-devel@nongnu.org/msg645815.html
  It is questionable whether the headers alone can be considered copyrightable material.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1879672/+subscriptions


^ permalink raw reply	[flat|nested] 75+ messages in thread
* [PATCH] WHPX: Assigning maintainer for Windows Hypervisor Platform
@ 2020-02-18 20:38 Sunil Muthuswamy
  2020-02-18 20:51 ` Justin Terry (SF)
  2020-02-21 17:15 ` Paolo Bonzini
  0 siblings, 2 replies; 75+ messages in thread
From: Sunil Muthuswamy @ 2020-02-18 20:38 UTC (permalink / raw)
  To: Eduardo Habkost, Paolo Bonzini, Richard Henderson
  Cc: Stefan Weil, qemu-devel, Justin Terry (SF)

Signed-off-by: Sunil Muthuswamy <sunilmut@microsoft.com>
---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 1740a4fddc..9b3ba4e1b5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -404,6 +404,14 @@ S: Supported
 F: target/i386/kvm.c
 F: scripts/kvm/vmxcap
 
+WHPX CPUs
+M: Sunil Muthuswamy <sunilmut@microsoft.com>
+S: Supported
+F: target/i386/whpx-all.c
+F: target/i386/whp-dispatch.h
+F: accel/stubs/whpx-stub.c
+F: include/sysemu/whpx.h
+
 Guest CPU Cores (Xen)
 ---------------------
 X86 Xen CPUs
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 75+ messages in thread
* [PATCH v2 0/3] testing: Build WHPX enabled binaries
@ 2019-09-20 11:33 Philippe Mathieu-Daudé
  2019-09-20 11:33 ` [PATCH v2 1/3] target/i386: Fix broken build with WHPX enabled Philippe Mathieu-Daudé
                   ` (4 more replies)
  0 siblings, 5 replies; 75+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-09-20 11:33 UTC (permalink / raw)
  To: qemu-devel, Justin Terry
  Cc: Fam Zheng, Thomas Huth, Daniel P . Berrangé,
	Eduardo Habkost, Alex Bennée, Stefan Weil, Paolo Bonzini,
	Philippe Mathieu-Daudé,
	Richard Henderson

Add a job to cross-build QEMU with WHPX enabled.

Since the WHPX is currently broken, include the patch required to have
successful Shippable build.

I previously included the WHPX headers shared by the Android project,
and Daniel asked me to check the EULA. While trying to manually
install the Windows SDK, I noticed the installer fetches archives
directly, kindly asking where they are stored via the /fwlink API.
Do the same, fetch the required archives and extract them. No need
to accept EULA...

Docker build the image first, then build QEMU in a instance of this
image. The image is internal to Shippable, the instances are not
reachable and are thrown once the build is finished. What we collect
from Shippable is the console output of QEMU build process, and if
the build process succeed or failed. So far we do not redistribute
the image or built binaries.

Philippe Mathieu-Daudé (3):
  target/i386: Fix broken build with WHPX enabled
  tests/docker: Add fedora-win10sdk-cross image
  .shippable.yml: Build WHPX enabled binaries

 .shippable.yml                                |  2 ++
 target/i386/whpx-all.c                        |  1 +
 tests/docker/Makefile.include                 |  2 ++
 .../dockerfiles/fedora-win10sdk-cross.docker  | 23 ++++++++++++++++
 tests/docker/dockerfiles/win10sdk-dl.sh       | 27 +++++++++++++++++++
 5 files changed, 55 insertions(+)
 create mode 100644 tests/docker/dockerfiles/fedora-win10sdk-cross.docker
 create mode 100755 tests/docker/dockerfiles/win10sdk-dl.sh

-- 
2.20.1



^ permalink raw reply	[flat|nested] 75+ messages in thread
* [Qemu-devel] [PATCH 0/2] testing: Build WHPX enabled binaries
@ 2019-09-19 10:59 Philippe Mathieu-Daudé
  2019-09-19 10:59 ` [Qemu-devel] [PATCH 1/2] tests/docker: Add fedora-win10sdk-cross image Philippe Mathieu-Daudé
                   ` (3 more replies)
  0 siblings, 4 replies; 75+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-09-19 10:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Lucian Petrut, Philippe Mathieu-Daudé,
	Justin Terry, Stefan Weil, Alex Bennée, Ilias Maratos

Add a job to cross-build QEMU with WHPX enabled.

Use the Win10SDK headers from the Android Project, as commented
in https://lists.gnu.org/archive/html/qemu-devel/2019-09/msg03842.html

Based-on: <20190918121101.30690-1-philmd@redhat.com>
https://lists.gnu.org/archive/html/qemu-devel/2019-09/msg03844.html

Philippe Mathieu-Daudé (2):
  tests/docker: Add fedora-win10sdk-cross image
  .shippable.yml: Build WHPX enabled binaries

 .shippable.yml                                |  2 ++
 tests/docker/Makefile.include                 |  1 +
 .../dockerfiles/fedora-win10sdk-cross.docker  | 21 +++++++++++++++++++
 3 files changed, 24 insertions(+)
 create mode 100644 tests/docker/dockerfiles/fedora-win10sdk-cross.docker

-- 
2.20.1



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

end of thread, other threads:[~2022-04-28  6:35 UTC | newest]

Thread overview: 75+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-07 19:48 [PATCH v2] WHPX: support for xcr0 Sunil Muthuswamy
2019-11-07 20:05 ` Stefan Weil
2019-11-07 22:52   ` Sunil Muthuswamy
2020-05-20 10:27     ` Philippe Mathieu-Daudé
2020-05-20 10:27       ` [Bug 1879672] " Philippe Mathieu-Daudé
2019-11-12 18:52 ` Sunil Muthuswamy
2019-11-13 14:56   ` Paolo Bonzini
2022-04-28  6:31 ` Paolo Bonzini
  -- strict thread matches above, loose matches on Subject: below --
2020-05-20 10:14 [Bug 1879672] [NEW] QEMU installer with WHPX support Philippe Mathieu-Daudé
2020-05-20 10:25 ` [Bug 1879672] " Daniel Berrange
2020-05-20 12:30 ` Stefan Weil
2020-06-08  7:18 ` Philippe Mathieu-Daudé
2020-11-04 20:01 ` John Snow
2020-11-04 23:12   ` Philippe Mathieu-Daudé
2020-11-04 23:12     ` Philippe Mathieu-Daudé
2021-05-09 15:38 ` Philippe Mathieu-Daudé
2021-05-09 18:33 ` Stefan Weil
2021-05-27  7:45 ` Philippe Mathieu-Daudé
2020-02-18 20:38 [PATCH] WHPX: Assigning maintainer for Windows Hypervisor Platform Sunil Muthuswamy
2020-02-18 20:51 ` Justin Terry (SF)
2020-02-19  8:31   ` Philippe Mathieu-Daudé
2020-02-19 15:50     ` [EXTERNAL] " Justin Terry (SF)
2020-02-21  7:54       ` Stefan Weil
2020-02-24 19:43         ` Sunil Muthuswamy
2020-05-20 10:29           ` Philippe Mathieu-Daudé
2020-05-20 10:29             ` [Bug 1879672] " Philippe Mathieu-Daudé
2020-05-19 21:59         ` Sunil Muthuswamy
2020-05-20 10:29           ` Philippe Mathieu-Daudé
2020-05-20 10:29             ` [Bug 1879672] " Philippe Mathieu-Daudé
2020-02-21 17:15 ` Paolo Bonzini
2019-09-20 11:33 [PATCH v2 0/3] testing: Build WHPX enabled binaries Philippe Mathieu-Daudé
2019-09-20 11:33 ` [PATCH v2 1/3] target/i386: Fix broken build with WHPX enabled Philippe Mathieu-Daudé
2019-09-20 11:37   ` Paolo Bonzini
2019-09-20 11:33 ` [PATCH v2 2/3] tests/docker: Add fedora-win10sdk-cross image Philippe Mathieu-Daudé
2019-09-20 11:33 ` [PATCH v2 3/3] .shippable.yml: Build WHPX enabled binaries Philippe Mathieu-Daudé
2019-09-20 15:17 ` [PATCH v2 0/3] testing: " Philippe Mathieu-Daudé
2019-09-20 16:53   ` Justin Terry (VM)
2020-05-20 10:26     ` Philippe Mathieu-Daudé
2020-05-20 10:26       ` [Bug 1879672] " Philippe Mathieu-Daudé
2020-07-31  8:33       ` Philippe Mathieu-Daudé
2020-07-31  8:33         ` [Bug 1879672] " Philippe Mathieu-Daudé
2020-07-31 23:31         ` [EXTERNAL] " Sunil Muthuswamy
2020-08-03 10:51           ` Philippe Mathieu-Daudé
2020-08-03 10:51             ` [Bug 1879672] " Philippe Mathieu-Daudé
2020-08-03 11:28             ` Stefan Weil
2020-08-03 20:25               ` Stefan Weil
2020-08-04  6:43                 ` Thomas Huth
2020-08-04  6:55                   ` Stefan Weil
2020-08-04  7:23                     ` Philippe Mathieu-Daudé
2020-08-04  7:23                       ` [Bug 1879672] " Philippe Mathieu-Daudé
2020-08-04  7:42                       ` Stefan Weil
2020-08-04  7:52                         ` Philippe Mathieu-Daudé
2020-08-04  7:52                           ` [Bug 1879672] " Philippe Mathieu-Daudé
2020-08-04  8:10                         ` Thomas Huth
2020-08-04  9:23                           ` Daniel P. Berrangé
2020-08-04  9:23                             ` [Bug 1879672] " Daniel Berrange
2020-08-18 21:20                         ` [EXTERNAL] " Sunil Muthuswamy
2020-08-19  3:36                           ` Philippe Mathieu-Daudé
2020-08-19  3:36                             ` [Bug 1879672] " Philippe Mathieu-Daudé
2019-09-21  6:34 ` no-reply
2019-09-19 10:59 [Qemu-devel] [PATCH 0/2] " Philippe Mathieu-Daudé
2019-09-19 10:59 ` [Qemu-devel] [PATCH 1/2] tests/docker: Add fedora-win10sdk-cross image Philippe Mathieu-Daudé
2019-09-19 11:28   ` Alex Bennée
2019-09-19 11:35     ` Philippe Mathieu-Daudé
2019-09-19 10:59 ` [Qemu-devel] [PATCH 2/2] .shippable.yml: Build WHPX enabled binaries Philippe Mathieu-Daudé
2019-09-19 11:02   ` Philippe Mathieu-Daudé
2019-09-19 11:09 ` [Qemu-devel] [PATCH 0/2] testing: " Thomas Huth
2019-09-19 11:21   ` Philippe Mathieu-Daudé
2019-09-19 11:18 ` Stefan Weil
2019-09-19 11:26   ` Philippe Mathieu-Daudé
2020-05-20 10:25     ` Philippe Mathieu-Daudé
2020-05-20 10:25       ` [Bug 1879672] " Philippe Mathieu-Daudé
2019-09-19 11:41   ` [Qemu-devel] " Daniel P. Berrangé
2019-09-19 11:54     ` Philippe Mathieu-Daudé
2019-09-19 13:25       ` Daniel P. Berrangé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).