Skip to contentSkip to conversation

vfio-pci: Fix KVM disabled path

PATCH In review Alex Williamson 2 participants 3 messages Nov 27, 2012 – Nov 30, 2012 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio-pci: Fix KVM disabled path

kvm_check_extension() explodes when KVM isn't enabled so we need to first test whether KVM is enabled. Use kvm_irqchip_in_kernel() for this since it matches the test we do before using this result.

---
 hw/vfio_pci.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Anthony, please include this for 1.3. Let me know if you prefer a pull request. Thanks,

Alex

hw/vfio_pci.c +2 -1
index 7c27834..2acc757 100644
@@ -438,7 +438,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_check_extension(kvm_state, KVM_CAP_IRQFD_RESAMPLE)) {
+    if (kvm_irqchip_in_kernel() &&
+        kvm_check_extension(kvm_state, KVM_CAP_IRQFD_RESAMPLE)) {
         vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev,
                                                         vdev->intx.pin);
     }
#1 lore raw
Quoted 7 lines · Alex Williamson

kvm_check_extension() explodes when KVM isn't enabled so we need to first test whether KVM is enabled. Use kvm_irqchip_in_kernel() for this since it matches the test we do before using this result.

hw/vfio_pci.c static int vfio_enable_intx(VFIODevice *vdev) · line 444

Quoted 8 lines
hw/vfio_pci.c +2 -1
@@ -438,7 +438,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_check_extension(kvm_state, KVM_CAP_IRQFD_RESAMPLE)) {
+    if (kvm_irqchip_in_kernel() &&
+        kvm_check_extension(kvm_state, KVM_CAP_IRQFD_RESAMPLE)) {
         vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev,
                                                         vdev->intx.pin);

vfio_pci is supposed to be architecture-independent code, right? kvm.h says you mustn't use kvm_irqchip_in_kernel() in such code (its semantics vary from arch to arch). I think kvm_enabled() is sufficient here since what we're actually guarding is just the kvm_check_extension call.

-- PMM

#2 lore raw
Quoted 15 lines · Peter Maydell
Quoted 14 lines · Alex Williamson

kvm_check_extension() explodes when KVM isn't enabled so we need to first test whether KVM is enabled. Use kvm_irqchip_in_kernel() for this since it matches the test we do before using this result.

hw/vfio_pci.c +2 -1
@@ -438,7 +438,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_check_extension(kvm_state, KVM_CAP_IRQFD_RESAMPLE)) {
+    if (kvm_irqchip_in_kernel() &&
+        kvm_check_extension(kvm_state, KVM_CAP_IRQFD_RESAMPLE)) {
         vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev,
Quoted 8 lines

hw/vfio_pci.c static int vfio_enable_intx(VFIODevice *vdev) · line 444

Quoted 1 line
hw/vfio_pci.c +0 -0
                                                         vdev->intx.pin);

vfio_pci is supposed to be architecture-independent code, right? kvm.h says you mustn't use kvm_irqchip_in_kernel() in such code (its semantics vary from arch to arch). I think kvm_enabled() is sufficient here since what we're actually guarding is just the kvm_check_extension call.

Here, yes. The other call spot we're matching is specifically looking for whether kvm is capable of using IRQFD_RESAMPLE and whether it should be used. I think kvm_irqfds_enabled() is probably the right way to go. Post 1.3 we might want to make kvm_intx_via_irqfd_enabled which encapsulates the IRQFD_RESAMPLE test. I'll do some testing and repost a kvm_irqfds_enabled() version. Thanks,

Alex