[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 15/19] hvf: Guard xgetbv call
From: |
Paolo Bonzini |
Subject: |
[PULL 15/19] hvf: Guard xgetbv call |
Date: |
Mon, 15 Feb 2021 14:16:22 +0100 |
From: Hill Ma <maahiuzeon@gmail.com>
This prevents illegal instruction on cpus that do not support xgetbv.
Buglink: https://bugs.launchpad.net/qemu/+bug/1758819
Reviewed-by: Cameron Esfahani <dirty@apple.com>
Signed-off-by: Hill Ma <maahiuzeon@gmail.com>
Message-Id: <X/6OJ7qk0W6bHkHQ@Hills-Mac-Pro.local>
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/hvf/x86_cpuid.c | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/target/i386/hvf/x86_cpuid.c b/target/i386/hvf/x86_cpuid.c
index a6842912f5..32b0d131df 100644
--- a/target/i386/hvf/x86_cpuid.c
+++ b/target/i386/hvf/x86_cpuid.c
@@ -27,15 +27,22 @@
#include "vmx.h"
#include "sysemu/hvf.h"
-static uint64_t xgetbv(uint32_t xcr)
+static bool xgetbv(uint32_t cpuid_ecx, uint32_t idx, uint64_t *xcr)
{
- uint32_t eax, edx;
+ uint32_t xcrl, xcrh;
- __asm__ volatile ("xgetbv"
- : "=a" (eax), "=d" (edx)
- : "c" (xcr));
+ if (cpuid_ecx & CPUID_EXT_OSXSAVE) {
+ /*
+ * The xgetbv instruction is not available to older versions of
+ * the assembler, so we encode the instruction manually.
+ */
+ asm(".byte 0x0f, 0x01, 0xd0" : "=a" (xcrl), "=d" (xcrh) : "c" (idx));
- return (((uint64_t)edx) << 32) | eax;
+ *xcr = (((uint64_t)xcrh) << 32) | xcrl;
+ return true;
+ }
+
+ return false;
}
uint32_t hvf_get_supported_cpuid(uint32_t func, uint32_t idx,
@@ -100,12 +107,15 @@ uint32_t hvf_get_supported_cpuid(uint32_t func, uint32_t
idx,
break;
case 0xD:
if (idx == 0) {
- uint64_t host_xcr0 = xgetbv(0);
- uint64_t supp_xcr0 = host_xcr0 & (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);
- eax &= supp_xcr0;
+ uint64_t host_xcr0;
+ if (xgetbv(ecx, 0, &host_xcr0)) {
+ uint64_t supp_xcr0 = host_xcr0 & (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);
+ eax &= supp_xcr0;
+ }
} else if (idx == 1) {
hv_vmx_read_capability(HV_VMX_CAP_PROCBASED2, &cap);
eax &= CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XGETBV1;
--
2.29.2
- [PULL 07/19] kvm/i386: Use a per-VM check for SMM capability, (continued)
- [PULL 07/19] kvm/i386: Use a per-VM check for SMM capability, Paolo Bonzini, 2021/02/15
- [PULL 10/19] libqos/qgraph_internal: add qos_printf() and qos_printf_literal(), Paolo Bonzini, 2021/02/15
- [PULL 08/19] sev/i386: Enable an SEV-ES guest based on SEV policy, Paolo Bonzini, 2021/02/15
- [PULL 09/19] libqos/qgraph: add qos_node_create_driver_named(), Paolo Bonzini, 2021/02/15
- [PULL 11/19] tests/qtest/qos-test: dump qos graph if verbose, Paolo Bonzini, 2021/02/15
- [PULL 13/19] tests/qtest/qos-test: dump QEMU command if verbose, Paolo Bonzini, 2021/02/15
- [PULL 12/19] tests/qtest/qos-test: dump environment variables if verbose, Paolo Bonzini, 2021/02/15
- [PULL 14/19] util/cutils: Skip "." when looking for next directory component, Paolo Bonzini, 2021/02/15
- [PULL 17/19] hvf: x86: Remove unused definitions, Paolo Bonzini, 2021/02/15
- [PULL 15/19] hvf: Guard xgetbv call,
Paolo Bonzini <=
- [PULL 16/19] target/i386/hvf: add vmware-cpuid-freq cpu feature, Paolo Bonzini, 2021/02/15
- [PULL 18/19] target/i386/hvf: add rdmsr 35H MSR_CORE_THREAD_COUNT, Paolo Bonzini, 2021/02/15
- [PULL 19/19] hvf: Fetch cr4 before evaluating CPUID(1), Paolo Bonzini, 2021/02/15
- Re: [PULL 00/19] i386, qgraph patches for 2020-02-15, Thomas Huth, 2021/02/15
- Re: [PULL 00/19] i386, qgraph patches for 2020-02-15, Philippe Mathieu-Daudé, 2021/02/15
- Re: [PULL 00/19] i386, qgraph patches for 2020-02-15, no-reply, 2021/02/15
- Re: [PULL 00/19] i386, qgraph patches for 2020-02-15, Eric Blake, 2021/02/15