[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] core-util: Fix detection when running in a VM

Georg Chini gitlab at gitlab.freedesktop.org
Thu Jul 4 07:43:36 UTC 2019



Georg Chini pushed to branch master at PulseAudio / pulseaudio


Commits:
2ed4f388 by Arun Raghavan at 2019-07-04T07:13:51Z
core-util: Fix detection when running in a VM

The original code that was written was trying to detect what hypervisor
we were running under, rather than testing the presence bit first. We
don't really need the former, so let's use the more comprehensive latter
instead.

Fixes: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/684

- - - - -


1 changed file:

- src/pulsecore/core-util.c


Changes:

=====================================
src/pulsecore/core-util.c
=====================================
@@ -3518,11 +3518,7 @@ bool pa_running_in_vm(void) {
     /* Both CPUID and DMI are x86 specific interfaces... */
 
 #ifdef HAVE_CPUID_H
-    uint32_t eax;
-    union {
-        uint32_t sig32[3];
-        char text[13];
-    } sig;
+    unsigned int eax, ebx, ecx, edx;
 #endif
 
 #ifdef __linux__
@@ -3559,24 +3555,14 @@ bool pa_running_in_vm(void) {
 
 #ifdef HAVE_CPUID_H
 
-    /* Hypervisors provide their signature on the 0x40000000 cpuid leaf.
-     * http://lwn.net/Articles/301888/
-     *
-     * XXX: Why are we checking a list of signatures instead of the
-     * "hypervisor present bit"? According to the LWN article, the "hypervisor
-     * present bit" would be available on bit 31 of ECX on leaf 0x1, and that
-     * bit would tell us directly whether we're in a virtual machine or not. */
-    pa_zero(sig);
-    if (__get_cpuid(0x40000000, &eax, &sig.sig32[0], &sig.sig32[1], &sig.sig32[2]) == 0)
+    /* Hypervisors provide presence on 0x1 cpuid leaf.
+     * http://lwn.net/Articles/301888/ */
+    if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) == 0)
         return false;
 
-    if (pa_streq(sig.text, "XenVMMXenVMM") ||
-        pa_streq(sig.text, "KVMKVMKVM") ||
-        /* http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1009458 */
-        pa_streq(sig.text, "VMwareVMware") ||
-        /* http://msdn.microsoft.com/en-us/library/bb969719.aspx */
-        pa_streq(sig.text, "Microsoft Hv"))
+    if (ecx & 0x80000000)
         return true;
+
 #endif /* HAVE_CPUID_H */
 
 #endif /* defined(__i386__) || defined(__x86_64__) */



View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/commit/2ed4f388de8171dcd1e3261baf3c7a45fb8f3f38

-- 
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/commit/2ed4f388de8171dcd1e3261baf3c7a45fb8f3f38
You're receiving this email because of your account on gitlab.freedesktop.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20190704/85b72f8f/attachment-0001.html>


More information about the pulseaudio-commits mailing list