WHvCapabilityCodeProcessorFeaturesBanks and the matching partition
property are only implemented from Windows Server 2022 (build 20348),
the same cutoff already handled for the perfmon capability in commit
68438cb3cb ("whpx: i386: workaround for Windows 10 support").
On Windows 10 the capability query returns WHV_E_UNKNOWN_CAPABILITY
(0x80370300) and whpx_accel_init() aborts with -ENOSPC, reported to the
user as the misleading "failed to initialize whpx: No space left on
device". This regressed Windows 10 hosts in 8b87283ce4 ("whpx: i386:
enable all supported host features").
Fall back to the original single-bank WHvCapabilityCodeProcessorFeatures
on legacy hosts and skip the corresponding SetPartitionProperty, which
restores the pre-8b87283ce4 behaviour there.
Reported-on: Windows 10 Enterprise LTSC 17763, Intel i7-6700
Signed-off-by: Akshey Taneja <[email protected]>
---
target/i386/whpx/whpx-all.c | 61 +++++++++++++++++++++++++++----------
1 file changed, 45 insertions(+), 16 deletions(-)
diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c
index 113f79afb9..9a9fc7d974 100644
--- a/target/i386/whpx/whpx-all.c
+++ b/target/i386/whpx/whpx-all.c
@@ -3193,13 +3193,35 @@ int whpx_accel_init(AccelState *as, MachineState *ms)
memset(&processor_features, 0, sizeof(WHV_PROCESSOR_FEATURES_BANKS));
processor_features.BanksCount = 2;
- hr = whp_dispatch.WHvGetCapability(
- WHvCapabilityCodeProcessorFeaturesBanks, &processor_features,
- sizeof(WHV_PROCESSOR_FEATURES_BANKS), &whpx_cap_size);
- if (FAILED(hr)) {
- error_report("WHPX: Failed to get processor features, hr=%08lx", hr);
- ret = -ENOSPC;
- goto error;
+ if (whpx_is_legacy_os()) {
+ /*
+ * WHvCapabilityCodeProcessorFeaturesBanks, like the perfmon capability
+ * probed above, is only implemented from Windows Server 2022 (build
+ * 20348) onwards. Fall back to the original single-bank capability,
+ * which Windows 10 does implement, and treat failure as non-fatal:
+ * the banked feature set is an optimisation, not a requirement.
+ */
+ WHV_PROCESSOR_FEATURES legacy_features = {0};
+
+ processor_features.BanksCount = 1;
+ hr = whp_dispatch.WHvGetCapability(
+ WHvCapabilityCodeProcessorFeatures, &legacy_features,
+ sizeof(legacy_features), &whpx_cap_size);
+ if (FAILED(hr)) {
+ warn_report("WHPX: Failed to get legacy processor features, "
+ "hr=%08lx", hr);
+ } else {
+ processor_features.Bank0 = legacy_features;
+ }
+ } else {
+ hr = whp_dispatch.WHvGetCapability(
+ WHvCapabilityCodeProcessorFeaturesBanks, &processor_features,
+ sizeof(WHV_PROCESSOR_FEATURES_BANKS), &whpx_cap_size);
+ if (FAILED(hr)) {
+ error_report("WHPX: Failed to get processor features, hr=%08lx",
hr);
+ ret = -ENOSPC;
+ goto error;
+ }
}
whpx_rdtsc_cap = processor_features.Bank0.RdtscpSupport;
@@ -3246,15 +3268,22 @@ int whpx_accel_init(AccelState *as, MachineState *ms)
}
}
- hr = whp_dispatch.WHvSetPartitionProperty(
- whpx->partition,
- WHvPartitionPropertyCodeProcessorFeaturesBanks,
- &processor_features,
- sizeof(WHV_PROCESSOR_FEATURES_BANKS));
- if (FAILED(hr)) {
- error_report("WHPX: Failed to set processor features, hr=%08lx", hr);
- ret = -EINVAL;
- goto error;
+ /*
+ * The matching partition property is also Windows Server 2022 and later.
+ * Legacy hosts simply keep the features the hypervisor gave them, which
+ * is how WHPX behaved before the banked feature set was introduced.
+ */
+ if (!whpx_is_legacy_os()) {
+ hr = whp_dispatch.WHvSetPartitionProperty(
+ whpx->partition,
+ WHvPartitionPropertyCodeProcessorFeaturesBanks,
+ &processor_features,
+ sizeof(WHV_PROCESSOR_FEATURES_BANKS));
+ if (FAILED(hr)) {
+ error_report("WHPX: Failed to set processor features, hr=%08lx",
hr);
+ ret = -EINVAL;
+ goto error;
+ }
}
--
2.50.1.windows.1