- i386/cpuid: Move leaf 7 to correct group - i386/cpuid: Decrease cpuid_i when skipping CPUID leaf 1F - i386/cpu: Mask with XCR0/XSS mask for FEAT_XSAVE_XCR0_HI and FEAT_XSAVE_XSS_HI leafs - i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs when CPUID_EXT_XSAVE is not available - target/i386: Change wrong XFRM value in SGX CPUID leaf - target/i386: Enable support for XSAVES based features - target/i386: Add kvm_get_one_msr helper - hw/block/hd-geometry: Do not override specified bios-chs-trans mainline inclusion commit fd8a68ad6823d33bedeba20a22857867a1c3890e category: bugfix - linux-user/riscv: Align signal frame to 16 bytes mainline inclusion commit 1eaa63429a9944265c92efdb94c02fabb231f564 category: bugfix - ipmi:smbus: Add a check around a memcpy mainline inclusion commit 3fde641e7286f9b968bdb3b4b922c6465f2a9abc category: bugfix - tests/tcg/linux-test: Fix random hangs in test_socket mainline inclusion commit b9e6074fc5b429b1e956e9c60db7e284a91e0f3d category: bugfix - qemu-options.hx: Don't claim "-serial" has limit of 4 serial ports Before v2.12, the implementation of serial ports was limited to a value of MAX_SERIAL_PORTS = 4. We now dynamically allocate the data structures for serial ports, so this limit is no longer present, but the documentation for the -serial options still reads: - target/ppc: Modify the uncorrect value irq to n_IRQ - block-migration: Ensure we don't crash during migration cleanup - target/s390x: fix handling of zeroes in vfmin/vfmax mainline inclusion commit 13c59eb09bd6d1fbc13f08b708226421f14a232b category: bugfix - hw/virtio/virtio-iommu: Enforce power-of-two notify for both MAP and UNMAP mainline inclusion commit 0522be9a0c0094088ccef7aab352c57f483ca250 category: bugfix - configure: Add missing POSIX-required space mainline inclusion commit 35a7a6fc5624b1df828d82f2dfa74d0e4188b3b2 category: bugfix - vga: fix incorrect line height in 640x200x2 mode mainline inclusion commit 37e7b86766244b62a406747bb78e049390d0b528 category: bugfix - hw/ide/core: set ERR_STAT in unsupported command completion - linux-user/flatload.c: Fix setting of image_info::end_code mainline inclusion commit 734a659ad264ac080457167e845ffabbaaa66d0e category: bugfix - load_elf: fix iterator's type for elf file processing - hw/misc/mps2-scc: Free MPS2SCC::oscclk[] array on finalize() - hw/nvram/xlnx-efuse: Free XlnxEFuse::ro_bits[] array on finalize() - hw/nvram/xlnx-efuse-ctrl: Free XlnxVersalEFuseCtrl[] "pg0-lock" array - chardev/char.c: fix "abstract device type" error message - block/rbd: fix handling of holes in .bdrv_co_block_status - qga: treat get-guest-fsinfo as "best effort" mainline inclusion commit bbb0151cf2e82489120a15df5e2eb9653312b0ec category: bugfix - usb/hcd-xhci: check slotid in xhci_wakeup_endpoint() mainline inclusion commit 84218892f05515d20347fde4506e1944eb11cb25 category: bugfix - hw/display/bcm2835_fb: Fix framebuffer allocation address mainline inclusion commit 5865d99fe88d8c8fa437c18c6b63fb2a8165634f category: bugfix - block/parallels: Fix buffer-based write call mainline inclusion commit eba088f91d21d9e42a81bef847173da30c5da961 category: bugfix - vl: Improve error message for conflicting -incoming and -loadvm - hw/smbios: Fix OEM strings table option validation Signed-off-by: Jiabo Feng <fengjiabo1@huawei.com> (cherry picked from commit 5d1a5160936dce1757c09050d97d12f42642794b)
287 lines
11 KiB
Diff
287 lines
11 KiB
Diff
From 0a83478189efce4e6775977dc3c76a5750b52fb4 Mon Sep 17 00:00:00 2001
|
|
From: Yang Weijiang <weijiang.yang@intel.com>
|
|
Date: Tue, 15 Feb 2022 14:52:54 -0500
|
|
Subject: [PATCH] target/i386: Enable support for XSAVES based features
|
|
|
|
commit 301e90675c3fed6cdc48682021a1ab42bc0e0d76 upstream.
|
|
|
|
There're some new features, including Arch LBR, depending
|
|
on XSAVES/XRSTORS support, the new instructions will
|
|
save/restore data based on feature bits enabled in XCR0 | XSS.
|
|
This patch adds the basic support for related CPUID enumeration
|
|
and meanwhile changes the name from FEAT_XSAVE_COMP_{LO|HI} to
|
|
FEAT_XSAVE_XCR0_{LO|HI} to differentiate clearly the feature
|
|
bits in XCR0 and those in XSS.
|
|
|
|
Intel-SIG: commit 301e90675c3f target/i386: Enable support for XSAVES based features
|
|
Backport i386/cpu bugfixes
|
|
|
|
Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
|
|
Message-Id: <20220215195258.29149-5-weijiang.yang@intel.com>
|
|
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
Signed-off-by: Jason Zeng <jason.zeng@intel.com>
|
|
---
|
|
target/i386/cpu.c | 104 +++++++++++++++++++++++++++++++++++-----------
|
|
target/i386/cpu.h | 14 ++++++-
|
|
2 files changed, 92 insertions(+), 26 deletions(-)
|
|
|
|
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
|
|
index 53a7484ca8..6b098cc832 100644
|
|
--- a/target/i386/cpu.c
|
|
+++ b/target/i386/cpu.c
|
|
@@ -977,6 +977,34 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
|
|
},
|
|
.tcg_features = TCG_XSAVE_FEATURES,
|
|
},
|
|
+ [FEAT_XSAVE_XSS_LO] = {
|
|
+ .type = CPUID_FEATURE_WORD,
|
|
+ .feat_names = {
|
|
+ NULL, NULL, NULL, NULL,
|
|
+ NULL, NULL, NULL, NULL,
|
|
+ NULL, NULL, NULL, NULL,
|
|
+ NULL, NULL, NULL, NULL,
|
|
+ NULL, NULL, NULL, NULL,
|
|
+ NULL, NULL, NULL, NULL,
|
|
+ NULL, NULL, NULL, NULL,
|
|
+ NULL, NULL, NULL, NULL,
|
|
+ },
|
|
+ .cpuid = {
|
|
+ .eax = 0xD,
|
|
+ .needs_ecx = true,
|
|
+ .ecx = 1,
|
|
+ .reg = R_ECX,
|
|
+ },
|
|
+ },
|
|
+ [FEAT_XSAVE_XSS_HI] = {
|
|
+ .type = CPUID_FEATURE_WORD,
|
|
+ .cpuid = {
|
|
+ .eax = 0xD,
|
|
+ .needs_ecx = true,
|
|
+ .ecx = 1,
|
|
+ .reg = R_EDX
|
|
+ },
|
|
+ },
|
|
[FEAT_6_EAX] = {
|
|
.type = CPUID_FEATURE_WORD,
|
|
.feat_names = {
|
|
@@ -992,7 +1020,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
|
|
.cpuid = { .eax = 6, .reg = R_EAX, },
|
|
.tcg_features = TCG_6_EAX_FEATURES,
|
|
},
|
|
- [FEAT_XSAVE_COMP_LO] = {
|
|
+ [FEAT_XSAVE_XCR0_LO] = {
|
|
.type = CPUID_FEATURE_WORD,
|
|
.cpuid = {
|
|
.eax = 0xD,
|
|
@@ -1005,7 +1033,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
|
|
XSTATE_OPMASK_MASK | XSTATE_ZMM_Hi256_MASK | XSTATE_Hi16_ZMM_MASK |
|
|
XSTATE_PKRU_MASK,
|
|
},
|
|
- [FEAT_XSAVE_COMP_HI] = {
|
|
+ [FEAT_XSAVE_XCR0_HI] = {
|
|
.type = CPUID_FEATURE_WORD,
|
|
.cpuid = {
|
|
.eax = 0xD,
|
|
@@ -1422,6 +1450,9 @@ static const X86RegisterInfo32 x86_reg_info_32[CPU_NB_REGS32] = {
|
|
};
|
|
#undef REGISTER
|
|
|
|
+/* CPUID feature bits available in XSS */
|
|
+#define CPUID_XSTATE_XSS_MASK (0)
|
|
+
|
|
ExtSaveArea x86_ext_save_areas[XSAVE_STATE_AREA_COUNT] = {
|
|
[XSTATE_FP_BIT] = {
|
|
/* x87 FP state component is always enabled if XSAVE is supported */
|
|
@@ -1464,15 +1495,18 @@ ExtSaveArea x86_ext_save_areas[XSAVE_STATE_AREA_COUNT] = {
|
|
},
|
|
};
|
|
|
|
-static uint32_t xsave_area_size(uint64_t mask)
|
|
+static uint32_t xsave_area_size(uint64_t mask, bool compacted)
|
|
{
|
|
+ uint64_t ret = x86_ext_save_areas[0].size;
|
|
+ const ExtSaveArea *esa;
|
|
+ uint32_t offset = 0;
|
|
int i;
|
|
- uint64_t ret = 0;
|
|
|
|
- for (i = 0; i < ARRAY_SIZE(x86_ext_save_areas); i++) {
|
|
- const ExtSaveArea *esa = &x86_ext_save_areas[i];
|
|
+ for (i = 2; i < ARRAY_SIZE(x86_ext_save_areas); i++) {
|
|
+ esa = &x86_ext_save_areas[i];
|
|
if ((mask >> i) & 1) {
|
|
- ret = MAX(ret, esa->offset + esa->size);
|
|
+ offset = compacted ? ret : esa->offset;
|
|
+ ret = MAX(ret, offset + esa->size);
|
|
}
|
|
}
|
|
return ret;
|
|
@@ -1483,10 +1517,10 @@ static inline bool accel_uses_host_cpuid(void)
|
|
return kvm_enabled() || hvf_enabled();
|
|
}
|
|
|
|
-static inline uint64_t x86_cpu_xsave_components(X86CPU *cpu)
|
|
+static inline uint64_t x86_cpu_xsave_xcr0_components(X86CPU *cpu)
|
|
{
|
|
- return ((uint64_t)cpu->env.features[FEAT_XSAVE_COMP_HI]) << 32 |
|
|
- cpu->env.features[FEAT_XSAVE_COMP_LO];
|
|
+ return ((uint64_t)cpu->env.features[FEAT_XSAVE_XCR0_HI]) << 32 |
|
|
+ cpu->env.features[FEAT_XSAVE_XCR0_LO];
|
|
}
|
|
|
|
/* Return name of 32-bit register, from a R_* constant */
|
|
@@ -1498,6 +1532,12 @@ static const char *get_register_name_32(unsigned int reg)
|
|
return x86_reg_info_32[reg].name;
|
|
}
|
|
|
|
+static inline uint64_t x86_cpu_xsave_xss_components(X86CPU *cpu)
|
|
+{
|
|
+ return ((uint64_t)cpu->env.features[FEAT_XSAVE_XSS_HI]) << 32 |
|
|
+ cpu->env.features[FEAT_XSAVE_XSS_LO];
|
|
+}
|
|
+
|
|
/*
|
|
* Returns the set of feature flags that are supported and migratable by
|
|
* QEMU, for a given FeatureWord.
|
|
@@ -4940,8 +4980,8 @@ static const char *x86_cpu_feature_name(FeatureWord w, int bitnr)
|
|
/* XSAVE components are automatically enabled by other features,
|
|
* so return the original feature name instead
|
|
*/
|
|
- if (w == FEAT_XSAVE_COMP_LO || w == FEAT_XSAVE_COMP_HI) {
|
|
- int comp = (w == FEAT_XSAVE_COMP_HI) ? bitnr + 32 : bitnr;
|
|
+ if (w == FEAT_XSAVE_XCR0_LO || w == FEAT_XSAVE_XCR0_HI) {
|
|
+ int comp = (w == FEAT_XSAVE_XCR0_HI) ? bitnr + 32 : bitnr;
|
|
|
|
if (comp < ARRAY_SIZE(x86_ext_save_areas) &&
|
|
x86_ext_save_areas[comp].bits) {
|
|
@@ -5831,25 +5871,36 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
|
|
}
|
|
|
|
if (count == 0) {
|
|
- *ecx = xsave_area_size(x86_cpu_xsave_components(cpu));
|
|
- *eax = env->features[FEAT_XSAVE_COMP_LO];
|
|
- *edx = env->features[FEAT_XSAVE_COMP_HI];
|
|
+ *ecx = xsave_area_size(x86_cpu_xsave_xcr0_components(cpu), false);
|
|
+ *eax = env->features[FEAT_XSAVE_XCR0_LO];
|
|
+ *edx = env->features[FEAT_XSAVE_XCR0_HI];
|
|
/*
|
|
* The initial value of xcr0 and ebx == 0, On host without kvm
|
|
* commit 412a3c41(e.g., CentOS 6), the ebx's value always == 0
|
|
* even through guest update xcr0, this will crash some legacy guest
|
|
* (e.g., CentOS 6), So set ebx == ecx to workaroud it.
|
|
*/
|
|
- *ebx = kvm_enabled() ? *ecx : xsave_area_size(env->xcr0);
|
|
+ *ebx = kvm_enabled() ? *ecx : xsave_area_size(env->xcr0, false);
|
|
} else if (count == 1) {
|
|
+ uint64_t xstate = x86_cpu_xsave_xcr0_components(cpu) |
|
|
+ x86_cpu_xsave_xss_components(cpu);
|
|
+
|
|
*eax = env->features[FEAT_XSAVE];
|
|
+ *ebx = xsave_area_size(xstate, true);
|
|
+ *ecx = env->features[FEAT_XSAVE_XSS_LO];
|
|
+ *edx = env->features[FEAT_XSAVE_XSS_HI];
|
|
} else if (count < ARRAY_SIZE(x86_ext_save_areas)) {
|
|
- if ((x86_cpu_xsave_components(cpu) >> count) & 1) {
|
|
- const ExtSaveArea *esa = &x86_ext_save_areas[count];
|
|
+ const ExtSaveArea *esa = &x86_ext_save_areas[count];
|
|
+
|
|
+ if (x86_cpu_xsave_xcr0_components(cpu) & (1ULL << count)) {
|
|
*eax = esa->size;
|
|
*ebx = esa->offset;
|
|
*ecx = esa->ecx &
|
|
(ESA_FEATURE_ALIGN64_MASK | ESA_FEATURE_XFD_MASK);
|
|
+ } else if (x86_cpu_xsave_xss_components(cpu) & (1ULL << count)) {
|
|
+ *eax = esa->size;
|
|
+ *ebx = 0;
|
|
+ *ecx = 1;
|
|
}
|
|
}
|
|
break;
|
|
@@ -5900,8 +5951,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
|
|
} else {
|
|
*eax &= env->features[FEAT_SGX_12_1_EAX];
|
|
*ebx &= 0; /* ebx reserve */
|
|
- *ecx &= env->features[FEAT_XSAVE_COMP_LO];
|
|
- *edx &= env->features[FEAT_XSAVE_COMP_HI];
|
|
+ *ecx &= env->features[FEAT_XSAVE_XSS_LO];
|
|
+ *edx &= env->features[FEAT_XSAVE_XSS_HI];
|
|
|
|
/* FP and SSE are always allowed regardless of XSAVE/XCR0. */
|
|
*ecx |= XSTATE_FP_MASK | XSTATE_SSE_MASK;
|
|
@@ -6306,6 +6357,9 @@ static void x86_cpu_reset(DeviceState *dev)
|
|
}
|
|
for (i = 2; i < ARRAY_SIZE(x86_ext_save_areas); i++) {
|
|
const ExtSaveArea *esa = &x86_ext_save_areas[i];
|
|
+ if (!((1 << i) & CPUID_XSTATE_XCR0_MASK)) {
|
|
+ continue;
|
|
+ }
|
|
if (env->features[esa->feature] & esa->bits) {
|
|
xcr0 |= 1ull << i;
|
|
}
|
|
@@ -6423,8 +6477,8 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
|
|
static bool request_perm;
|
|
|
|
if (!(env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE)) {
|
|
- env->features[FEAT_XSAVE_COMP_LO] = 0;
|
|
- env->features[FEAT_XSAVE_COMP_HI] = 0;
|
|
+ env->features[FEAT_XSAVE_XCR0_LO] = 0;
|
|
+ env->features[FEAT_XSAVE_XCR0_HI] = 0;
|
|
return;
|
|
}
|
|
|
|
@@ -6442,8 +6496,10 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
|
|
request_perm = true;
|
|
}
|
|
|
|
- env->features[FEAT_XSAVE_COMP_LO] = mask;
|
|
- env->features[FEAT_XSAVE_COMP_HI] = mask >> 32;
|
|
+ env->features[FEAT_XSAVE_XCR0_LO] = mask & CPUID_XSTATE_XCR0_MASK;
|
|
+ env->features[FEAT_XSAVE_XCR0_HI] = mask >> 32;
|
|
+ env->features[FEAT_XSAVE_XSS_LO] = mask & CPUID_XSTATE_XSS_MASK;
|
|
+ env->features[FEAT_XSAVE_XSS_HI] = mask >> 32;
|
|
}
|
|
|
|
/***** Steps involved on loading and filtering CPUID data
|
|
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
|
|
index 32ecec5fa7..e8322a928b 100644
|
|
--- a/target/i386/cpu.h
|
|
+++ b/target/i386/cpu.h
|
|
@@ -565,6 +565,14 @@ typedef enum X86Seg {
|
|
#define ESA_FEATURE_XFD_MASK (1U << ESA_FEATURE_XFD_BIT)
|
|
|
|
|
|
+/* CPUID feature bits available in XCR0 */
|
|
+#define CPUID_XSTATE_XCR0_MASK (XSTATE_FP_MASK | XSTATE_SSE_MASK | \
|
|
+ XSTATE_YMM_MASK | XSTATE_BNDREGS_MASK | \
|
|
+ XSTATE_BNDCSR_MASK | XSTATE_OPMASK_MASK | \
|
|
+ XSTATE_ZMM_Hi256_MASK | \
|
|
+ XSTATE_Hi16_ZMM_MASK | XSTATE_PKRU_MASK | \
|
|
+ XSTATE_XTILE_CFG_MASK | XSTATE_XTILE_DATA_MASK)
|
|
+
|
|
/* CPUID feature words */
|
|
typedef enum FeatureWord {
|
|
FEAT_1_EDX, /* CPUID[1].EDX */
|
|
@@ -583,8 +591,8 @@ typedef enum FeatureWord {
|
|
FEAT_SVM, /* CPUID[8000_000A].EDX */
|
|
FEAT_XSAVE, /* CPUID[EAX=0xd,ECX=1].EAX */
|
|
FEAT_6_EAX, /* CPUID[6].EAX */
|
|
- FEAT_XSAVE_COMP_LO, /* CPUID[EAX=0xd,ECX=0].EAX */
|
|
- FEAT_XSAVE_COMP_HI, /* CPUID[EAX=0xd,ECX=0].EDX */
|
|
+ FEAT_XSAVE_XCR0_LO, /* CPUID[EAX=0xd,ECX=0].EAX */
|
|
+ FEAT_XSAVE_XCR0_HI, /* CPUID[EAX=0xd,ECX=0].EDX */
|
|
FEAT_ARCH_CAPABILITIES,
|
|
FEAT_CORE_CAPABILITY,
|
|
FEAT_PERF_CAPABILITIES,
|
|
@@ -601,6 +609,8 @@ typedef enum FeatureWord {
|
|
FEAT_SGX_12_0_EAX, /* CPUID[EAX=0x12,ECX=0].EAX (SGX) */
|
|
FEAT_SGX_12_0_EBX, /* CPUID[EAX=0x12,ECX=0].EBX (SGX MISCSELECT[31:0]) */
|
|
FEAT_SGX_12_1_EAX, /* CPUID[EAX=0x12,ECX=1].EAX (SGX ATTRIBUTES[31:0]) */
|
|
+ FEAT_XSAVE_XSS_LO, /* CPUID[EAX=0xd,ECX=1].ECX */
|
|
+ FEAT_XSAVE_XSS_HI, /* CPUID[EAX=0xd,ECX=1].EDX */
|
|
FEAT_7_1_EDX, /* CPUID[EAX=7,ECX=1].EDX */
|
|
FEAT_7_2_EDX, /* CPUID[EAX=7,ECX=2].EDX */
|
|
FEATURE_WORDS,
|
|
--
|
|
2.27.0
|
|
|