Bug 1628469

Summary: libvirt uses incorrect method to detect that KVM is working
Product: Red Hat Enterprise Linux 7 Reporter: Richard W.M. Jones <rjones>
Component: libvirtAssignee: Andrea Bolognani <abologna>
Status: CLOSED ERRATA QA Contact: yalzhang <yalzhang>
Severity: high Docs Contact:
Priority: unspecified    
Version: 7.7CC: abologna, bugproxy, dyuan, fjin, hannsj_uhl, jdenemar, jkachuck, lmen, xuzhang, yalzhang, yoguo
Target Milestone: rcKeywords: Patch
Target Release: 7.7   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-4.5.0-13.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1629862 (view as bug list) Environment:
Last Closed: 2019-08-06 13:13:56 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1628468    
Bug Blocks: 1598750, 1605071, 1619379, 1629862, 1707454    

Description Richard W.M. Jones 2018-09-13 07:44:18 UTC
Description of problem:

https://github.com/libvirt/libvirt/blob/e9e904b3b70533982954ab39ccb81122e8dad338/src/qemu/qemu_capabilities.c#L837

Just checking the existence of /dev/kvm is no good.  This
node always exists since:

$ cat /usr/lib/udev/rules.d/80-kvm.rules
KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"

It does not guarantee that KVM works.

I have filed https://bugzilla.redhat.com/show_bug.cgi?id=1628468
to get the KVM team to suggest or implement a reliable test.

Version-Release number of selected component (if applicable):

All recent libvirt.

Steps to Reproduce:

On a machine where KVM is broken:

  virsh capabilities

It will show KVM is available.

Comment 2 Andrea Bolognani 2018-09-14 08:37:11 UTC
Patches posted upstream.

  https://www.redhat.com/archives/libvir-list/2018-September/msg00651.html

Comment 3 Andrea Bolognani 2018-09-17 14:30:09 UTC
Fix merged upstream.

  commit 88983855d5496a74b97551860db737c2b17b100e
  Author: Andrea Bolognani <abologna>
  Date:   Thu Sep 13 17:40:51 2018 +0200

    qemu: Drop QEMU_CAPS_ENABLE_KVM
    
    It was already available in 1.5.0.
    
    Moreover, we're not even formatting it on the QEMU command
    line, ever: we just use it as part of some logic that decides
    whether KVM support should be advertised, and as it turns out
    that logic is actually buggy and dropping this capability
    fixes it.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1628469
    
    Signed-off-by: Andrea Bolognani <abologna>
    Reviewed-by: Jiri Denemark <jdenemar>

v4.7.0-141-g88983855d5

Comment 4 Joseph Kachuck 2018-10-17 19:14:36 UTC
Hello,
RHEL ALT 7.6 is the last release of RHEL ALT. There will be one final release of RHEL ALT 7.6.z.
Only critical bugs will be accepted for this release. If this bug is required for RHEL ALT 7.6 ALT. 
Please provide a justification why this is required for Z stream. Please confirm what a client would see in the field from this issue.

Thank You
Joe Kachuck

Comment 9 yalzhang@redhat.com 2019-06-11 09:32:44 UTC
Reproduce this bug on libvirt-4.5.0-11.el7.x86_64
1. prepare a host which KVM is broken, but /dev/kvm exists:
# modprobe -r kvm_intel
# modprobe -r kvm
# mknod /dev/kvm c 10 232

2. make sure /dev/kvm is there:
# ls /dev/kvm 
/dev/kvm

3. check virsh capabilities output:
# virsh capabilities
...
  <guest>
    <os_type>hvm</os_type>
    <arch name='x86_64'>
...
    <domain type='qemu'/>
      <domain type='kvm'>
        <emulator>/usr/libexec/qemu-kvm</emulator>
      </domain>
...
 </guest>

Update libvirt to libvirt-4.5.0-21.el7.x86_64, and check again:
1.
# yum update libvirt libvirt* -y
# systemctl restart libvirtd
# rpm -q libvirt
libvirt-4.5.0-21.el7.x86_64

2.
# virsh capabilities 
<capabilities>
...
 <guest>
    <os_type>hvm</os_type>
    <arch name='x86_64'>
...
  <domain type='qemu'/>
 </guest>

</capabilities>

There is no "<domain type='kvm'>" in the "# virsh capabilities" outputs any more.

3. Restore the settings and check again:
# rm -f /dev/kvm
# modprobe kvm_intel
# modprobe kvm
# virsh capabilities
<capabilities>
...
 <guest>
    <os_type>hvm</os_type>
    <arch name='i686'>
...
 <domain type='qemu'/>
      <domain type='kvm'>
        <emulator>/usr/libexec/qemu-kvm</emulator>
      </domain>
...
</guest>
<guest>
    <os_type>hvm</os_type>
    <arch name='x86_64'>
...
  <domain type='qemu'/>
      <domain type='kvm'>
        <emulator>/usr/libexec/qemu-kvm</emulator>
      </domain>
...
</guest>

The result is as expected, set the bug to be verified.

Comment 11 errata-xmlrpc 2019-08-06 13:13:56 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2019:2294