actual checks of KVM_CAP_IRQFD and KVM_CAP_IRQFD_RESAMPLE
v2 cover actual checks of KVM_CAP_IRQFD and KVM_CAP_IRQFD_RESAMPLE
This patch serie replaces direct settings of kvm_irqfds_allowed by actual checks of the KVM_CAP_IRQFD extension. Also A new kvm_resamplefds_enabled() enables to check KVM_CAP_IRQFD_RESAMPLE.
in the second patch file the vfio device is the first user of kvm_resamplefds_enabled().
Eric Auger (2):
KVM_CAP_IRQFD and KVM_CAP_IRQFD_RESAMPLE checks
vfio: use kvm_resamplefds_enabled()
hw/intc/openpic_kvm.c | 1 - hw/intc/xics_kvm.c | 1 - hw/misc/vfio.c | 5 ++--- include/sysemu/kvm.h | 10 ++++++++++ kvm-all.c | 7 +++++++ target-i386/kvm.c | 1 - target-s390x/kvm.c | 1 - 7 files changed, 19 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.3.2
PATCH v2 1/2 KVM_CAP_IRQFD and KVM_CAP_IRQFD_RESAMPLE checks
Compute kvm_irqfds_allowed by checking the KVM_CAP_IRQFD extension. Remove direct settings in architecture specific files.
Add a new kvm_resamplefds_allowed variable, initialized by checking the KVM_CAP_IRQFD_RESAMPLE extension. Add a corresponding kvm_resamplefds_enabled() function.
---
in practice KVM_CAP_IRQFD_RESAMPLE seems to be always enabled as soon as kernel has HAVE_KVM_IRQFD so the resamplefd check may be unnecessary.
--- hw/intc/openpic_kvm.c | 1 - hw/intc/xics_kvm.c | 1 - include/sysemu/kvm.h | 10 ++++++++++ kvm-all.c | 7 +++++++ target-i386/kvm.c | 1 - target-s390x/kvm.c | 1 - 6 files changed, 17 insertions(+), 4 deletions(-)
hw/intc/openpic_kvm.c +0 -1
@@ -229,7 +229,6 @@ static void kvm_openpic_realize(DeviceState *dev, Error **errp)kvm_irqchip_add_irq_route (kvm_state, i,0 , i); } - kvm_irqfds_allowed = true; kvm_msi_via_irqfd_allowed = true; kvm_gsi_routing_allowed = true;
hw/intc/xics_kvm.c +0 -1
@@ -448,7 +448,6 @@ static void xics_kvm_realize(DeviceState *dev, Error **errp) } kvm_kernel_irqchip = true; - kvm_irqfds_allowed = true; kvm_msi_via_irqfd_allowed = true; kvm_gsi_direct_mapping = true;
include/sysemu/kvm.h +10 -0
@@ -45,6 +45,7 @@ extern bool kvm_async_interrupts_allowed;extern bool kvm_halt_in_kernel_allowed;extern bool kvm_eventfds_allowed;extern bool kvm_irqfds_allowed; +extern bool kvm_resamplefds_allowed;extern bool kvm_msi_via_irqfd_allowed;extern bool kvm_gsi_routing_allowed;extern bool kvm_gsi_direct_mapping;
@@ -102,6 +103,15 @@ extern bool kvm_readonly_mem_allowed;#define kvm_irqfds_enabled () (kvm_irqfds_allowed)/** +* kvm_resamplefds_enabled: +* +* Returns: true if we can use resamplefds to inject interrupts into +* a KVM CPU (ie the kernel supports resamplefds and we are running +* with a configuration where it is meaningful to use them). +*/ +#define kvm_resamplefds_enabled () (kvm_resamplefds_allowed) + +/** * kvm_msi_via_irqfd_enabled: * * Returns: true if we can route a PCI MSI (Message Signaled Interrupt)
kvm-all.c +7 -0
@@ -116,6 +116,7 @@ bool kvm_async_interrupts_allowed;bool kvm_halt_in_kernel_allowed;bool kvm_eventfds_allowed;bool kvm_irqfds_allowed; +bool kvm_resamplefds_allowed;bool kvm_msi_via_irqfd_allowed;bool kvm_gsi_routing_allowed;bool kvm_gsi_direct_mapping;
@@ -1548,6 +1549,12 @@ int kvm_init(MachineClass *mc) kvm_eventfds_allowed = (kvm_check_extension (s,KVM_CAP_IOEVENTFD ) >0 ); + kvm_irqfds_allowed = + (kvm_check_extension (s,KVM_CAP_IRQFD ) >0 ); + + kvm_resamplefds_allowed = + (kvm_check_extension (s,KVM_CAP_IRQFD_RESAMPLE ) >0 ); + ret =kvm_arch_init (s);if (ret <0 ) { goto err;
target-i386/kvm.c +0 -1
@@ -2544,7 +2544,6 @@ void kvm_arch_init_irq_routing(KVMState *s)* irqchip, so we can use irqfds, and on x86 we know * we can use msi via irqfd and GSI routing. */ - kvm_irqfds_allowed = true; kvm_msi_via_irqfd_allowed = true; kvm_gsi_routing_allowed = true; }
target-s390x/kvm.c +0 -1
@@ -1290,7 +1290,6 @@ void kvm_arch_init_irq_routing(KVMState *s)* have to override the common code kvm_halt_in_kernel_allowed setting. */ if (kvm_check_extension (s,KVM_CAP_IRQ_ROUTING )) { - kvm_irqfds_allowed = true; kvm_gsi_routing_allowed = true; kvm_halt_in_kernel_allowed = false; }
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH v2 1/2] KVM_CAP_IRQFD and KVM_CAP_IRQFD_RESAMPLE checks
On 03/09/14 11:54, Eric Auger wrote:
[...]
Quoted 2 lines
kvm-all.c +0
-0
[...]
kvm-all.c int kvm_init(MachineClass *mc) · line 1553
Quoted 6 lines
kvm-all.c +2
-0@@ -1548,6 +1549,12 @@ int kvm_init(MachineClass *mc) kvm_eventfds_allowed = (kvm_check_extension (s,KVM_CAP_IOEVENTFD ) >0 ); + kvm_irqfds_allowed = + (kvm_check_extension (s,KVM_CAP_IRQFD ) >0 );
^^^^^^^^^^^^^
Quoted 4 lines
kvm-all.c +4
-0+ + kvm_resamplefds_allowed = + (kvm_check_extension (s,KVM_CAP_IRQFD_RESAMPLE ) >0 ); +
[...]
target-s390x/kvm.c void kvm_arch_init_irq_routing(KVMState *s) · line 1292
Quoted 8 lines
target-s390x/kvm.c +0
-0@@ -1290,7 +1290,6 @@ void kvm_arch_init_irq_routing(KVMState *s)* have to override the common code kvm_halt_in_kernel_allowed setting. */ if (kvm_check_extension (s,KVM_CAP_IRQ_ROUTING )) {
^^^^^^^^^^^^^^^^^^^
target-s390x/kvm.c void kvm_arch_init_irq_routing(KVMState *s) · line 1295
Quoted 4 lines
target-s390x/kvm.c +0
-1- kvm_irqfds_allowed = true; kvm_gsi_routing_allowed = true; kvm_halt_in_kernel_allowed = false; }
I first thought that this is wrong, because on s390 we forgot to announce IRQFD when we introduced it. As you can see in both hunks, we check for KVM_CAP_IRQ_ROUTING and not for CAP_IRQFD
Luckily, the kernel got fixed with commit ebc3226202d5956a5963185222982d435378b899 ("KVM: s390: announce irqfd capability") and the capability was introduced with commit 84223598778ba08041f4297fda485df83414d57e ("KVM: s390: irq routing for adapter interrupts"). Looks that both patches first appear with 3.15, so there should be no kernel version that is affected by this change. You might want to add that to your changelog to help distros that 84223598778ba08041f4297fda485df83414d57e also needs ebc3226202d5956a5963185222982d435378b899.
Christian
Re: [Qemu-devel] [PATCH v2 1/2] KVM_CAP_IRQFD and KVM_CAP_IRQFD_RESAMPLE checks
Quoted 37 lines · Christian Borntraeger
On 03/09/14 11:54, Eric Auger wrote:
[...]Quoted 2 lines
kvm-all.c +0
-0[...]
kvm-all.c int kvm_init(MachineClass *mc) · line 1553
Quoted 6 lines
kvm-all.c +2
-0@@ -1548,6 +1549,12 @@ int kvm_init(MachineClass *mc) kvm_eventfds_allowed = (kvm_check_extension (s,KVM_CAP_IOEVENTFD ) >0 ); + kvm_irqfds_allowed = + (kvm_check_extension (s,KVM_CAP_IRQFD ) >0 );^^^^^^^^^^^^^Quoted 4 lines
kvm-all.c +4
-0+ + kvm_resamplefds_allowed = + (kvm_check_extension (s,KVM_CAP_IRQFD_RESAMPLE ) >0 ); +[...]
target-s390x/kvm.c void kvm_arch_init_irq_routing(KVMState *s) · line 1292
Quoted 8 lines
target-s390x/kvm.c +0
-0@@ -1290,7 +1290,6 @@ void kvm_arch_init_irq_routing(KVMState *s)* have to override the common code kvm_halt_in_kernel_allowed setting. */ if (kvm_check_extension (s,KVM_CAP_IRQ_ROUTING )) {^^^^^^^^^^^^^^^^^^^target-s390x/kvm.c void kvm_arch_init_irq_routing(KVMState *s) · line 1295
Quoted 4 lines
target-s390x/kvm.c +0
-1- kvm_irqfds_allowed = true; kvm_gsi_routing_allowed = true; kvm_halt_in_kernel_allowed = false; }I first thought that this is wrong, because on s390 we forgot to announce IRQFD when we introduced it. As you can see in both hunks, we check for
KVM_CAP_IRQ_ROUTINGand not forCAP_IRQFD
Quoted 6 lines
Luckily, the kernel got fixed with commit
ebc3226202d5956a5963185222982d435378b899("KVM: s390: announce irqfd capability") and the capability was introduced with commit84223598778ba08041f4297fda485df83414d57e("KVM: s390: irq routing for adapter interrupts"). Looks that both patches first appear with 3.15, so there should be no kernel version that is affected by this change. You might want to add that to your changelog to help distros that84223598778ba08041f4297fda485df83414d57ealso needsebc3226202d5956a5963185222982d435378b899.
Hi Christian,
I will add this information to the changelog. I effectively checked the cap was advertised in s390 arch but I was not aware of the history.
Thanks
Best Regards
Eric
Quoted 5 lines
Christian
PATCH v2 2/2 vfio: use kvm_resamplefds_enabled()
In reply to Eric AugerUse the kvm_resamplefds_enabled function
--- hw/misc/vfio.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/misc/vfio.c +2 -3
@@ -406,7 +406,7 @@ static void vfio_enable_intx_kvm(VFIODevice *vdev)if (!VFIO_ALLOW_KVM_INTX || !kvm_irqfds_enabled () || vdev->intx.route.mode !=PCI_INTX_ENABLED || - !kvm_check_extension (kvm_state,KVM_CAP_IRQFD_RESAMPLE )) { + !kvm_resamplefds_enabled ()) {return ; }
@@ -568,8 +568,7 @@ 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 () && -kvm_check_extension (kvm_state,KVM_CAP_IRQFD_RESAMPLE )) { +if (kvm_irqfds_enabled () &&kvm_resamplefds_enabled ()) { vdev->intx.route =pci_device_route_intx_to_irq (&vdev->pdev, vdev->intx.pin); }
Signature · 1 line
1.8.3.2