summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--man/systemd-detect-virt.xml4
-rw-r--r--src/basic/virt.c20
2 files changed, 15 insertions, 9 deletions
diff --git a/man/systemd-detect-virt.xml b/man/systemd-detect-virt.xml
index 996c2fa256..dc10b4dd43 100644
--- a/man/systemd-detect-virt.xml
+++ b/man/systemd-detect-virt.xml
@@ -91,12 +91,12 @@
<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>
diff --git a/src/basic/virt.c b/src/basic/virt.c
index 03ce71a728..0fbbdea602 100644
--- a/src/basic/virt.c
+++ b/src/basic/virt.c
@@ -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)