]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
virt: detect qemu/kvm as 'kvm' 5343/head
authorChristian Hesse <mail@eworm.de>
Tue, 14 Feb 2017 13:51:12 +0000 (14:51 +0100)
committerChristian Hesse <mail@eworm.de>
Tue, 14 Feb 2017 14:52:53 +0000 (15:52 +0100)
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>
man/systemd-detect-virt.xml
src/basic/virt.c

index 996c2fa256e099277a1088267d61ecefd1ad7783..dc10b4dd430320e40e36b0e44cee104a03166a9a 100644 (file)
           <row>
             <entry valign="top" morerows="10">VM</entry>
             <entry><varname>qemu</varname></entry>
-            <entry>QEMU software virtualization</entry>
+            <entry>QEMU software virtualization, without KVM</entry>
           </row>
 
           <row>
             <entry><varname>kvm</varname></entry>
-            <entry>Linux KVM kernel virtual machine</entry>
+            <entry>Linux KVM kernel virtual machine, from within QEMU</entry>
           </row>
 
           <row>
index 03ce71a7288522fd5c1158ddd2d11bdb0afed58a..0fbbdea6029c7cf39a34eecc675e897a51340ae3 100644 (file)
@@ -316,25 +316,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)