Skip to contentSkip to conversation

vfio-pci: Add missing kvm_enabled() checks

PATCH In review Stefan Hajnoczi 3 participants 3 messages Dec 20, 2012 – Dec 21, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio-pci: Add missing kvm_enabled() checks

It's necessary to check kvm_enabled() since a QEMU binary can be compiled with KVM support but TCG can be used at run-time. kvm_check_extension() segfaults if kvm_state is NULL.

---
 hw/vfio_pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/vfio_pci.c +4 -2
index fbfe670..677dc48 100644
@@ -275,7 +275,8 @@ static void vfio_enable_intx_kvm(VFIODevice *vdev)
     int ret, argsz;
     int32_t *pfd;
 
-    if (!kvm_irqfds_enabled() ||
+    if (!kvm_enabled() ||
+        !kvm_irqfds_enabled() ||
         vdev->intx.route.mode != PCI_INTX_ENABLED ||
         !kvm_check_extension(kvm_state, KVM_CAP_IRQFD_RESAMPLE)) {
         return;
@@ -438,7 +439,8 @@ static int vfio_enable_intx(VFIODevice *vdev)
      * Only conditional to avoid generating error messages on platforms
      * where we won't actually use the result anyway.
      */
-    if (kvm_irqfds_enabled() &&
+    if (kvm_enabled() &&
+        kvm_irqfds_enabled() &&
         kvm_check_extension(kvm_state, KVM_CAP_IRQFD_RESAMPLE)) {
         vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev,
                                                         vdev->intx.pin);
Signature · 1 line
1.8.0.2
#1 lore raw
Quoted 3 lines · Stefan Hajnoczi

It's necessary to check kvm_enabled() since a QEMU binary can be compiled with KVM support but TCG can be used at run-time. kvm_check_extension() segfaults if kvm_state is NULL.

Ugh, this is exactly why we added kvm_irqfds_enabled() which doesn't call kvm_check_extension(). How is it possible to fall through to a kvm_check_extension() with that in place? Thanks,

Alex

Quoted 30 lines
---
 hw/vfio_pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/vfio_pci.c +4 -2
index fbfe670..677dc48 100644
@@ -275,7 +275,8 @@ static void vfio_enable_intx_kvm(VFIODevice *vdev)
     int ret, argsz;
     int32_t *pfd;
 
-    if (!kvm_irqfds_enabled() ||
+    if (!kvm_enabled() ||
+        !kvm_irqfds_enabled() ||
         vdev->intx.route.mode != PCI_INTX_ENABLED ||
         !kvm_check_extension(kvm_state, KVM_CAP_IRQFD_RESAMPLE)) {
         return;
@@ -438,7 +439,8 @@ static int vfio_enable_intx(VFIODevice *vdev)
      * Only conditional to avoid generating error messages on platforms
      * where we won't actually use the result anyway.
      */
-    if (kvm_irqfds_enabled() &&
+    if (kvm_enabled() &&
+        kvm_irqfds_enabled() &&
         kvm_check_extension(kvm_state, KVM_CAP_IRQFD_RESAMPLE)) {
         vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev,
                                                         vdev->intx.pin);
#2 lore raw
Quoted 8 lines · Alex Williamson
Quoted 3 lines · Stefan Hajnoczi

It's necessary to check kvm_enabled() since a QEMU binary can be compiled with KVM support but TCG can be used at run-time. kvm_check_extension() segfaults if kvm_state is NULL.

Ugh, this is exactly why we added kvm_irqfds_enabled() which doesn't call kvm_check_extension(). How is it possible to fall through to a kvm_check_extension() with that in place? Thanks,

Ah, this explains it: Joe was using QEMU 1.3.0 which does not contain the kvm_irqfds_enabled() fix.

My patch is unnecessary and can be dropped.

Stefan