[libvirt] [PATCH] virt-host-validate: improve tests for arm/aarch64

ARM/Aarch64 /proc/cpuinfo has no virtualization related flags. Refactor the Qemu/KVM test a bit: 1) run the "for hardware virtualization" test only on plaforms with known cpuinfo flags (x86, s390) 2) test for /dev/kvm also on platforms where no cpu flags are set Finally Add a more generic error hint message for non-x86 plaforms when /dev/kvm is missing. Signed-off-by: Riku Voipio <riku.voipio@linaro.org> --- tools/virt-host-validate-qemu.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/tools/virt-host-validate-qemu.c b/tools/virt-host-validate-qemu.c index 56ec3c7..520c8ed 100644 --- a/tools/virt-host-validate-qemu.c +++ b/tools/virt-host-validate-qemu.c @@ -32,8 +32,9 @@ int virHostValidateQEMU(void) virBitmapPtr flags; int ret = 0; bool hasHwVirt = false; - - virHostMsgCheck("QEMU", "%s", _("for hardware virtualization")); + bool hasVirtFlag = false; + char *kvmhint = _("Check that CPU and firmware supports virtualization " + "and kvm module is loaded"); if (!(flags = virHostValidateGetCPUFlags())) return -1; @@ -41,12 +42,16 @@ int virHostValidateQEMU(void) switch (virArchFromHost()) { case VIR_ARCH_I686: case VIR_ARCH_X86_64: + hasVirtFlag = true; + kvmhint =_("Check that the 'kvm-intel' or 'kvm-amd' modules are " + "loaded & the BIOS has enabled virtualization"); if (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SVM) || virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_VMX)) hasHwVirt = true; break; case VIR_ARCH_S390: case VIR_ARCH_S390X: + hasVirtFlag = true; if (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SIE)) hasHwVirt = true; break; @@ -54,21 +59,27 @@ int virHostValidateQEMU(void) hasHwVirt = false; } - if (hasHwVirt) { - virHostMsgPass(); + if (hasVirtFlag) { + virHostMsgCheck("QEMU", "%s", _("for hardware virtualization")); + if (hasHwVirt) + virHostMsgPass(); + else { + virHostMsgFail(VIR_HOST_VALIDATE_FAIL, + _("Only emulated CPUs are available, performance will be significantly limited")); + ret = -1; + } + } + + if (hasHwVirt || !hasVirtFlag) { if (virHostValidateDeviceExists("QEMU", "/dev/kvm", VIR_HOST_VALIDATE_FAIL, - _("Check that the 'kvm-intel' or 'kvm-amd' modules are " - "loaded & the BIOS has enabled virtualization")) < 0) + kvmhint) <0) ret = -1; else if (virHostValidateDeviceAccessible("QEMU", "/dev/kvm", VIR_HOST_VALIDATE_FAIL, _("Check /dev/kvm is world writable or you are in " "a group that is allowed to access it")) < 0) ret = -1; - } else { - virHostMsgFail(VIR_HOST_VALIDATE_WARN, - _("Only emulated CPUs are available, performance will be significantly limited")); } virBitmapFree(flags); -- 2.1.4

On 3 June 2016 at 15:53, Riku Voipio <riku.voipio@linaro.org> wrote:
ARM/Aarch64 /proc/cpuinfo has no virtualization related flags. Refactor the Qemu/KVM test a bit:
1) run the "for hardware virtualization" test only on plaforms with known cpuinfo flags (x86, s390) 2) test for /dev/kvm also on platforms where no cpu flags are set
Finally Add a more generic error hint message for non-x86 plaforms when /dev/kvm is missing.
Ping? Can some please take a look?
Signed-off-by: Riku Voipio <riku.voipio@linaro.org> --- tools/virt-host-validate-qemu.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/tools/virt-host-validate-qemu.c b/tools/virt-host-validate-qemu.c index 56ec3c7..520c8ed 100644 --- a/tools/virt-host-validate-qemu.c +++ b/tools/virt-host-validate-qemu.c @@ -32,8 +32,9 @@ int virHostValidateQEMU(void) virBitmapPtr flags; int ret = 0; bool hasHwVirt = false; - - virHostMsgCheck("QEMU", "%s", _("for hardware virtualization")); + bool hasVirtFlag = false; + char *kvmhint = _("Check that CPU and firmware supports virtualization " + "and kvm module is loaded");
if (!(flags = virHostValidateGetCPUFlags())) return -1; @@ -41,12 +42,16 @@ int virHostValidateQEMU(void) switch (virArchFromHost()) { case VIR_ARCH_I686: case VIR_ARCH_X86_64: + hasVirtFlag = true; + kvmhint =_("Check that the 'kvm-intel' or 'kvm-amd' modules are " + "loaded & the BIOS has enabled virtualization"); if (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SVM) || virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_VMX)) hasHwVirt = true; break; case VIR_ARCH_S390: case VIR_ARCH_S390X: + hasVirtFlag = true; if (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SIE)) hasHwVirt = true; break; @@ -54,21 +59,27 @@ int virHostValidateQEMU(void) hasHwVirt = false; }
- if (hasHwVirt) { - virHostMsgPass(); + if (hasVirtFlag) { + virHostMsgCheck("QEMU", "%s", _("for hardware virtualization")); + if (hasHwVirt) + virHostMsgPass(); + else { + virHostMsgFail(VIR_HOST_VALIDATE_FAIL, + _("Only emulated CPUs are available, performance will be significantly limited")); + ret = -1; + } + } + + if (hasHwVirt || !hasVirtFlag) { if (virHostValidateDeviceExists("QEMU", "/dev/kvm", VIR_HOST_VALIDATE_FAIL, - _("Check that the 'kvm-intel' or 'kvm-amd' modules are " - "loaded & the BIOS has enabled virtualization")) < 0) + kvmhint) <0) ret = -1; else if (virHostValidateDeviceAccessible("QEMU", "/dev/kvm", VIR_HOST_VALIDATE_FAIL, _("Check /dev/kvm is world writable or you are in " "a group that is allowed to access it")) < 0) ret = -1; - } else { - virHostMsgFail(VIR_HOST_VALIDATE_WARN, - _("Only emulated CPUs are available, performance will be significantly limited")); }
virBitmapFree(flags); -- 2.1.4

On 03.06.2016 14:53, Riku Voipio wrote:
ARM/Aarch64 /proc/cpuinfo has no virtualization related flags. Refactor the Qemu/KVM test a bit:
1) run the "for hardware virtualization" test only on plaforms with known cpuinfo flags (x86, s390) 2) test for /dev/kvm also on platforms where no cpu flags are set
Finally Add a more generic error hint message for non-x86 plaforms when /dev/kvm is missing.
Signed-off-by: Riku Voipio <riku.voipio@linaro.org> --- tools/virt-host-validate-qemu.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/tools/virt-host-validate-qemu.c b/tools/virt-host-validate-qemu.c index 56ec3c7..520c8ed 100644 --- a/tools/virt-host-validate-qemu.c +++ b/tools/virt-host-validate-qemu.c @@ -32,8 +32,9 @@ int virHostValidateQEMU(void) virBitmapPtr flags; int ret = 0; bool hasHwVirt = false; - - virHostMsgCheck("QEMU", "%s", _("for hardware virtualization")); + bool hasVirtFlag = false; + char *kvmhint = _("Check that CPU and firmware supports virtualization " + "and kvm module is loaded");
if (!(flags = virHostValidateGetCPUFlags())) return -1; @@ -41,12 +42,16 @@ int virHostValidateQEMU(void) switch (virArchFromHost()) { case VIR_ARCH_I686: case VIR_ARCH_X86_64: + hasVirtFlag = true; + kvmhint =_("Check that the 'kvm-intel' or 'kvm-amd' modules are "
Missing space after '='.
+ "loaded & the BIOS has enabled virtualization"); if (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SVM) || virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_VMX)) hasHwVirt = true; break; case VIR_ARCH_S390: case VIR_ARCH_S390X: + hasVirtFlag = true; if (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SIE)) hasHwVirt = true; break; @@ -54,21 +59,27 @@ int virHostValidateQEMU(void) hasHwVirt = false; }
- if (hasHwVirt) { - virHostMsgPass(); + if (hasVirtFlag) { + virHostMsgCheck("QEMU", "%s", _("for hardware virtualization")); + if (hasHwVirt) + virHostMsgPass(); + else { + virHostMsgFail(VIR_HOST_VALIDATE_FAIL, + _("Only emulated CPUs are available, performance will be significantly limited")); + ret = -1; + }
Missing curly braces for the first body.
+ } + + if (hasHwVirt || !hasVirtFlag) { if (virHostValidateDeviceExists("QEMU", "/dev/kvm", VIR_HOST_VALIDATE_FAIL, - _("Check that the 'kvm-intel' or 'kvm-amd' modules are " - "loaded & the BIOS has enabled virtualization")) < 0) + kvmhint) <0) ret = -1; else if (virHostValidateDeviceAccessible("QEMU", "/dev/kvm", VIR_HOST_VALIDATE_FAIL, _("Check /dev/kvm is world writable or you are in " "a group that is allowed to access it")) < 0) ret = -1; - } else { - virHostMsgFail(VIR_HOST_VALIDATE_WARN, - _("Only emulated CPUs are available, performance will be significantly limited")); }
virBitmapFree(flags);
Okay, so IIUC this is just so that we don't produce an error on platforms such as arm where HW virt is not advertised in cpu flags. Firstly, it's shame it isn't advertised there. Secondly, what can we do other than adjust our code just like you're doing here? Fixed the small syntax nits, ACked and pushed. Congratulations on your first libvirt contribution! Michal

On Fri, 2016-06-03 at 15:53 +0300, Riku Voipio wrote:
ARM/Aarch64 /proc/cpuinfo has no virtualization related flags. Refactor the Qemu/KVM test a bit: 1) run the "for hardware virtualization" test only on plaforms with known cpuinfo flags (x86, s390) 2) test for /dev/kvm also on platforms where no cpu flags are set Finally Add a more generic error hint message for non-x86 plaforms when /dev/kvm is missing.
So, this has already been merged and it's definitely an improvement over the existing situation (thanks to both you and Michal, by the way!), but I was wondering whether removing the hardware check altogether is a good idea. There is a difference between KVM not being built properly / shipped / loaded and the host not supporting hardware virtualization at all. We capture that difference on x86 and s390, but not on aarch64 and ppc64. Is figuring out whether hardware virtualization support is present just not feasible on aarch64, eg. because each reports the information in a different way, or because the information is not exposed to userspace at all? -- Andrea Bolognani Software Engineer - Virtualization Team

On 13 June 2016 at 20:20, Andrea Bolognani <abologna@redhat.com> wrote:
So, this has already been merged and it's definitely an improvement over the existing situation (thanks to both you and Michal, by the way!), but I was wondering whether removing the hardware check altogether is a good idea.
I wondered too, but opted in keeping the existing checks. They might still save someones time.
There is a difference between KVM not being built properly / shipped / loaded and the host not supporting hardware virtualization at all. We capture that difference on x86 and s390, but not on aarch64 and ppc64.
Is figuring out whether hardware virtualization support is present just not feasible on aarch64, eg. because each reports the information in a different way, or because the information is not exposed to userspace at all?
The information isn't exposed to userspace. The closest thing we have is looking at kernel error messages when kvm is initialized. Lack of virtualization support on arm64 is usually a firmware issue. Riku

On Tue, 2016-06-14 at 16:34 +0300, Riku Voipio wrote:
There is a difference between KVM not being built properly / shipped / loaded and the host not supporting hardware virtualization at all. We capture that difference on x86 and s390, but not on aarch64 and ppc64.
Is figuring out whether hardware virtualization support is present just not feasible on aarch64, eg. because each reports the information in a different way, or because the information is not exposed to userspace at all?
The information isn't exposed to userspace. The closest thing we have is looking at kernel error messages when kvm is initialized. Lack of virtualization support on arm64 is usually a firmware issue.
I see. Let's leave it as it is then. -- Andrea Bolognani Software Engineer - Virtualization Team
participants (3)
-
Andrea Bolognani
-
Michal Privoznik
-
Riku Voipio