qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hvf: guard xgetbv call.
@ 2020-12-19  2:13 Hill Ma
  2021-01-09  5:48 ` Roman Bolshakov
  0 siblings, 1 reply; 10+ messages in thread
From: Hill Ma @ 2020-12-19  2:13 UTC (permalink / raw)
  To: dirty, r.bolshakov; +Cc: qemu-devel

This prevents illegal instruction on cpus do not support xgetbv.

Buglink: https://bugs.launchpad.net/qemu/+bug/1758819
Signed-off-by: Hill Ma <maahiuzeon@gmail.com>
---
 target/i386/hvf/x86_cpuid.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/target/i386/hvf/x86_cpuid.c b/target/i386/hvf/x86_cpuid.c
index a6842912f5..b4b7111fc3 100644
--- a/target/i386/hvf/x86_cpuid.c
+++ b/target/i386/hvf/x86_cpuid.c
@@ -100,11 +100,16 @@ 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 |
+            uint64_t supp_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);
+                                  XSTATE_ZMM_Hi256_MASK | XSTATE_Hi16_ZMM_MASK;
+            if ((ecx & CPUID_EXT_AVX) &&
+                (ecx & CPUID_EXT_XSAVE) &&
+                (ecx & CPUID_EXT_OSXSAVE)) {
+                uint64_t host_xcr0 = xgetbv(0);
+                supp_xcr0 &= host_xcr0;
+            }
             eax &= supp_xcr0;
         } else if (idx == 1) {
             hv_vmx_read_capability(HV_VMX_CAP_PROCBASED2, &cap);
-- 
2.20.1 (Apple Git-117)



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

end of thread, other threads:[~2021-01-12 15:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-19  2:13 [PATCH] hvf: guard xgetbv call Hill Ma
2021-01-09  5:48 ` Roman Bolshakov
2021-01-09 11:42   ` Peter Maydell
2021-01-10  1:46     ` Roman Bolshakov
2021-01-10 18:34       ` Richard Henderson
2021-01-10 18:38         ` Richard Henderson
2021-01-11  4:31           ` Roman Bolshakov
2021-01-11 17:06             ` Richard Henderson
2021-01-12  7:49               ` Roman Bolshakov
2021-01-12 15:28                 ` Richard Henderson

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).