target-i386: Don't try to enable PT State xsave component

The code that calculates the set of supported XSAVE components on
CPUID looks at ext_save_areas to find out which components should
be enabled. However, if there are zeroed entries in the
ext_save_areas array, the
((env->features[esa->feature] & esa->bits) == esa->bits)
check will always succeed and QEMU will unconditionally try to
enable the component.

Luckily this never caused any problems because the only missing
entry in ext_save_areas is the PT State component (bit 8), and
KVM currently doesn't support it (so it was cleared on ena_mask).
But the code was still incorrect and would break if KVM starts
returning CPUID[EAX=0xD,ECX=0].EAX[bit 8] as supported on
GET_SUPPORTED_CPUID.

Fix the problem by changing the code to not enable a XSAVE
component if ExtSaveArea::bits is zero.

Backports commit 9646f4927faf68e8690588c2fd6dc9834c440b58 from qemu
This commit is contained in:
Eduardo Habkost 2018-02-26 04:30:30 -05:00 committed by Lioncash
parent 6188c6d6e4
commit c3a0cba5b1
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -2541,7 +2541,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
*ecx = 0x240; *ecx = 0x240;
for (i = 2; i < ARRAY_SIZE(x86_ext_save_areas); i++) { for (i = 2; i < ARRAY_SIZE(x86_ext_save_areas); i++) {
const ExtSaveArea *esa = &x86_ext_save_areas[i]; const ExtSaveArea *esa = &x86_ext_save_areas[i];
if ((env->features[esa->feature] & esa->bits) == esa->bits if ((env->features[esa->feature] & esa->bits)
&& ((ena_mask >> i) & 1) != 0) { && ((ena_mask >> i) & 1) != 0) {
if (i < 32) { if (i < 32) {
*eax |= 1u << i; *eax |= 1u << i;
@ -2557,7 +2557,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
*eax = env->features[FEAT_XSAVE]; *eax = env->features[FEAT_XSAVE];
} else if (count < ARRAY_SIZE(x86_ext_save_areas)) { } else if (count < ARRAY_SIZE(x86_ext_save_areas)) {
const ExtSaveArea *esa = &x86_ext_save_areas[count]; const ExtSaveArea *esa = &x86_ext_save_areas[count];
if ((env->features[esa->feature] & esa->bits) == esa->bits if ((env->features[esa->feature] & esa->bits)
&& ((ena_mask >> count) & 1) != 0) { && ((ena_mask >> count) & 1) != 0) {
*eax = esa->size; *eax = esa->size;
*ebx = esa->offset; *ebx = esa->offset;
@ -2793,7 +2793,7 @@ static void x86_cpu_reset(CPUState *s)
} }
for (i = 2; i < ARRAY_SIZE(x86_ext_save_areas); i++) { for (i = 2; i < ARRAY_SIZE(x86_ext_save_areas); i++) {
const ExtSaveArea *esa = &x86_ext_save_areas[i]; const ExtSaveArea *esa = &x86_ext_save_areas[i];
if ((env->features[esa->feature] & esa->bits) == esa->bits) { if (env->features[esa->feature] & esa->bits) {
xcr0 |= 1ull << i; xcr0 |= 1ull << i;
} }
} }