virt: swap order of cpuid and dmi again, but properly detect oracle (#5355)

This breaks again, this time for setups where Qemu is not reported via DMI for whatever
reason. So swap order of cpuid and dmi again, but properly detect oracle.

See issue #5318.
This commit is contained in:
Christian Hesse 2017-02-15 23:51:31 +01:00 committed by Zbigniew Jędrzejewski-Szmek
parent cda3d0c240
commit 28b1a3eac2
2 changed files with 14 additions and 14 deletions

View file

@ -96,7 +96,8 @@
<row> <row>
<entry><varname>kvm</varname></entry> <entry><varname>kvm</varname></entry>
<entry>Linux KVM kernel virtual machine, from within QEMU</entry> <entry>Linux KVM kernel virtual machine, with whatever software, except
Oracle Virtualbox</entry>
</row> </row>
<row> <row>
@ -116,7 +117,8 @@
<row> <row>
<entry><varname>oracle</varname></entry> <entry><varname>oracle</varname></entry>
<entry>Oracle VM VirtualBox (historically marketed by innotek and Sun Microsystems)</entry> <entry>Oracle VM VirtualBox (historically marketed by innotek and Sun Microsystems),
for legacy and KVM hypervisor</entry>
</row> </row>
<row> <row>

View file

@ -316,31 +316,29 @@ static int detect_vm_zvm(void) {
/* Returns a short identifier for the various VM implementations */ /* Returns a short identifier for the various VM implementations */
int detect_vm(void) { int detect_vm(void) {
static thread_local int cached_found = _VIRTUALIZATION_INVALID; static thread_local int cached_found = _VIRTUALIZATION_INVALID;
int r, cpuid; int r, dmi;
if (cached_found >= 0) if (cached_found >= 0)
return cached_found; return cached_found;
/* We have to use the correct order here: /* We have to use the correct order here:
* *
* -> First try to detect qemu/kvm and return 'kvm'. * -> First try to detect Oracle Virtualbox, even if it uses KVM.
* -> Some virtualization technologies do use KVM hypervisor but are * -> Second try to detect from cpuid, this will report KVM for
* expected to be detected as something else. Virtualbox since * whatever software is used even if info in dmi is overwritten.
* version 5.0 is an example. So detect DMI next. * -> Third try to detect from dmi. */
* -> Get infos from CPUID third. */
cpuid = detect_vm_cpuid(); dmi = detect_vm_dmi();
r = detect_vm_dmi(); if (dmi == VIRTUALIZATION_ORACLE)
return dmi;
if (r == VIRTUALIZATION_QEMU && cpuid == VIRTUALIZATION_KVM)
return cpuid;
r = detect_vm_cpuid();
if (r < 0) if (r < 0)
return r; return r;
if (r != VIRTUALIZATION_NONE) if (r != VIRTUALIZATION_NONE)
goto finish; goto finish;
r = cpuid; r = dmi;
if (r < 0) if (r < 0)
return r; return r;
if (r != VIRTUALIZATION_NONE) if (r != VIRTUALIZATION_NONE)