summaryrefslogtreecommitdiff
path: root/src/basic/virt.c
diff options
context:
space:
mode:
authorChristian Hesse <mail@eworm.de>2017-02-14 14:51:12 +0100
committerSven Eden <yamakuzure@gmx.net>2017-07-17 17:58:36 +0200
commitdfa83c1e0c059b5030b8927bbbc9afcc48486c17 (patch)
tree9b8dace12799f0c76a598703d5035e83f80e4a78 /src/basic/virt.c
parentb9c87201dcff2c33985880bdd0f0666eaed6c5a3 (diff)
virt: detect qemu/kvm as 'kvm'
In commit 050e65a we swapped order of detect_vm_{cpuid,dmi}(). That fixed Virtualbox but broke qemu with kvm, which is expected to return 'kvm'. So check for qemu/kvm first, then DMI, CPUID last. This fixes #5318. Signed-off-by: Christian Hesse <mail@eworm.de>
Diffstat (limited to 'src/basic/virt.c')
-rw-r--r--src/basic/virt.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/basic/virt.c b/src/basic/virt.c
index 20effaf4c..e25a274e8 100644
--- a/src/basic/virt.c
+++ b/src/basic/virt.c
@@ -315,25 +315,31 @@ static int detect_vm_zvm(void) {
/* Returns a short identifier for the various VM implementations */
int detect_vm(void) {
static thread_local int cached_found = _VIRTUALIZATION_INVALID;
- int r;
+ int r, cpuid;
if (cached_found >= 0)
return cached_found;
/* We have to use the correct order here:
- * Some virtualization technologies do use KVM hypervisor but are
- * expected to be detected as something else. So detect DMI first.
*
- * An example is Virtualbox since version 5.0, which uses KVM backend.
- * Detection via DMI works corretly, the CPU ID would find KVM
- * only. */
+ * -> First try to detect qemu/kvm and return 'kvm'.
+ * -> Some virtualization technologies do use KVM hypervisor but are
+ * expected to be detected as something else. Virtualbox since
+ * version 5.0 is an example. So detect DMI next.
+ * -> Get infos from CPUID third. */
+
+ cpuid = detect_vm_cpuid();
r = detect_vm_dmi();
+
+ if (r == VIRTUALIZATION_QEMU && cpuid == VIRTUALIZATION_KVM)
+ return cpuid;
+
if (r < 0)
return r;
if (r != VIRTUALIZATION_NONE)
goto finish;
- r = detect_vm_cpuid();
+ r = cpuid;
if (r < 0)
return r;
if (r != VIRTUALIZATION_NONE)