hw/vfio/pci.c: eradicate CONFIG_KVM
We just need to add kvm_enabled() guard when calling concerned functions, but no need to extract those kvm functions since they are not using any kvm specific types that would not be visible at compilation time. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Reviewed-by: Cédric Le Goater <clg@redhat.com> Tested-by: Cédric Le Goater <clg@redhat.com> Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> Link: https://lore.kernel.org/qemu-devel/20260318174733.1717643-6-pierrick.bouvier@linaro.org Signed-off-by: Cédric Le Goater <clg@redhat.com>
Pierrick Bouvier committed
Mar 18, 2026 at 10:47 UTC
4e365e7d2a212580e7c17ee5a784db792b9d752d
1 file changed
+10
-18
hw/vfio/pci.c
+10
-18
@@ -152,7 +152,6 @@ void vfio_pci_intx_eoi(VFIODevice *vbasedev)
152
153
static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
154
{
155
-#ifdef CONFIG_KVM
155
PCIDevice *pdev = PCI_DEVICE(vdev);
156
int irq_fd = event_notifier_get_fd(&vdev->intx.interrupt);
157
@@ -206,14 +205,10 @@ fail:
205
qemu_set_fd_handler(irq_fd, vfio_intx_interrupt, NULL, vdev);
206
vfio_device_irq_unmask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
207
return false;
209
-#else
210
- return true;
211
-#endif
208
}
209
210
static bool vfio_cpr_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
211
{
216
-#ifdef CONFIG_KVM
212
if (vdev->no_kvm_intx || !kvm_irqfds_enabled() ||
213
vdev->intx.route.mode != PCI_INTX_ENABLED ||
214
!kvm_resamplefds_enabled()) {
@@ -236,14 +231,10 @@ static bool vfio_cpr_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
231
vdev->intx.kvm_accel = true;
232
trace_vfio_intx_enable_kvm(vdev->vbasedev.name);
233
return true;
239
-#else
240
- return true;
241
-#endif
234
}
235
236
static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
237
{
246
-#ifdef CONFIG_KVM
238
PCIDevice *pdev = PCI_DEVICE(vdev);
239
240
if (!vdev->intx.kvm_accel) {
@@ -277,7 +268,6 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
268
vfio_device_irq_unmask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
269
270
trace_vfio_intx_disable_kvm(vdev->vbasedev.name);
280
-#endif
271
}
272
273
static void vfio_intx_update(VFIOPCIDevice *vdev, PCIINTxRoute *route)
@@ -287,7 +277,9 @@ static void vfio_intx_update(VFIOPCIDevice *vdev, PCIINTxRoute *route)
277
trace_vfio_intx_update(vdev->vbasedev.name,
278
vdev->intx.route.irq, route->irq);
279
290
- vfio_intx_disable_kvm(vdev);
280
+ if (kvm_enabled()) {
281
+ vfio_intx_disable_kvm(vdev);
282
+ }
283
284
vdev->intx.route = *route;
285
@@ -295,7 +287,7 @@ static void vfio_intx_update(VFIOPCIDevice *vdev, PCIINTxRoute *route)
287
return;
288
}
289
298
- if (!vfio_intx_enable_kvm(vdev, &err)) {
290
+ if (kvm_enabled() && !vfio_intx_enable_kvm(vdev, &err)) {
291
warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
292
}
293
@@ -350,16 +342,14 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
342
vdev->intx.pin = pin - 1; /* Pin A (1) -> irq[0] */
343
pci_config_set_interrupt_pin(pdev->config, pin);
344
353
-#ifdef CONFIG_KVM
345
/*
346
* Only conditional to avoid generating error messages on platforms
347
* where we won't actually use the result anyway.
348
*/
358
- if (kvm_irqfds_enabled() && kvm_resamplefds_enabled()) {
349
+ if (kvm_enabled() && kvm_irqfds_enabled() && kvm_resamplefds_enabled()) {
350
vdev->intx.route = pci_device_route_intx_to_irq(pdev,
351
vdev->intx.pin);
352
}
362
-#endif
353
354
if (!vfio_notifier_init(vdev, &vdev->intx.interrupt, "intx-interrupt", 0,
355
errp)) {
@@ -370,7 +360,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
360
361
362
if (cpr_is_incoming()) {
373
- if (!vfio_cpr_intx_enable_kvm(vdev, &err)) {
363
+ if (kvm_enabled() && !vfio_cpr_intx_enable_kvm(vdev, &err)) {
364
warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
365
}
366
goto skip_signaling;
@@ -383,7 +373,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
373
return false;
374
}
375
386
- if (!vfio_intx_enable_kvm(vdev, &err)) {
376
+ if (kvm_enabled() && !vfio_intx_enable_kvm(vdev, &err)) {
377
warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
378
}
379
@@ -400,7 +390,9 @@ static void vfio_intx_disable(VFIOPCIDevice *vdev)
390
int fd;
391
392
timer_del(vdev->intx.mmap_timer);
403
- vfio_intx_disable_kvm(vdev);
393
+ if (kvm_enabled()) {
394
+ vfio_intx_disable_kvm(vdev);
395
+ }
396
vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
397
vdev->intx.pending = false;
398
pci_irq_deassert(pdev);