summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Raghavan <arun@arunraghavan.net>2019-07-01 07:22:55 +0530
committerArun Raghavan <arun@arunraghavan.net>2019-07-04 07:13:51 +0000
commit2ed4f388de8171dcd1e3261baf3c7a45fb8f3f38 (patch)
treeae857eeb27ae38fb6697701f137459f812b5101f
parent4c6bab435316768974b94573e3f67ea17f56e221 (diff)
downloadpulseaudio-2ed4f388de8171dcd1e3261baf3c7a45fb8f3f38.tar.gz
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
-rw-r--r--src/pulsecore/core-util.c26
1 files changed, 6 insertions, 20 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index f2748aeb1..270acd8cb 100644
--- a/src/pulsecore/core-util.c
+++ b/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__) */