[systemd-devel] [PATCH 1/2] detect-virt: detect in best-heuristic order

Andrew Jones drjones at redhat.com
Wed Nov 4 06:18:56 PST 2015


On Wed, Nov 04, 2015 at 03:54:45PM +0300, Andrei Borzenkov wrote:
> 04.11.2015 00:04, Andrew Jones пишет:
> >afaict, this will fix a regression caused by commit 75f86906c5.
> >Where we used to report "kvm" before that patch, without this patch,
> >we would only report "qemu".
> 
> Are you sure it is regression? QEMU is a program (platform) while KVM is
> technology. Modern VirtualBox can use KVM as PV interface but it still
> remains VirtualBox. QEMU may use KVM as PV interface but it still remains
> QEMU.

Sounds like VirtualBox should override the hypervisor cpuid leaf with
it's own signature, like kvmtool does.

> 
> Where does it matter? Is anything broken because of this change?

It's true that programs shouldn't change their behavior when detecting
"kvm" vs. "qemu", as "kvm" just means accelerated "qemu", but "shouldn't"
isn't something we should count on. Changing a behavior that some users
may now expect is a regression.

Thanks,
drew

> 
> >The reason is because cpuid detection
> >must come before dmi detection. Also, both can safely come before
> >other xen heuristics.
> >---
> >  src/basic/virt.c | 16 +++++++++-------
> >  1 file changed, 9 insertions(+), 7 deletions(-)
> >
> >diff --git a/src/basic/virt.c b/src/basic/virt.c
> >index fb181e5b55ee5..1e10fc755f201 100644
> >--- a/src/basic/virt.c
> >+++ b/src/basic/virt.c
> >@@ -267,12 +267,7 @@ int detect_vm(void) {
> >          if (cached_found >= 0)
> >                  return cached_found;
> >
> >-        /* Try xen capabilities file first, if not found try
> >-         * high-level hypervisor sysfs file:
> >-         *
> >-         * https://bugs.freedesktop.org/show_bug.cgi?id=77271 */
> >-
> >-        r = detect_vm_xen();
> >+        r = detect_vm_cpuid();
> >          if (r < 0)
> >                  return r;
> >          if (r != VIRTUALIZATION_NONE)
> >@@ -284,7 +279,14 @@ int detect_vm(void) {
> >          if (r != VIRTUALIZATION_NONE)
> >                  goto finish;
> >
> >-        r = detect_vm_cpuid();
> >+        /* x86 xen will most likely be detected by cpuid. If not (most likely
> >+         * because we're not an x86 guest), then we should try the xen capabilities
> >+         * file next. If that's not found, then we check for the high-level
> >+         * hypervisor sysfs file:
> >+         *
> >+         * https://bugs.freedesktop.org/show_bug.cgi?id=77271 */
> >+
> >+        r = detect_vm_xen();
> >          if (r < 0)
> >                  return r;
> >          if (r != VIRTUALIZATION_NONE)
> >
> 


More information about the systemd-devel mailing list