diff mbox series

[kernel,v2] KVM: PPC: Make KVM_CAP_IRQFD_RESAMPLE support platform dependent

Message ID 20220920125143.28009-1-aik@ozlabs.ru
State New
Headers show
Series [kernel,v2] KVM: PPC: Make KVM_CAP_IRQFD_RESAMPLE support platform dependent | expand

Commit Message

Alexey Kardashevskiy Sept. 20, 2022, 12:51 p.m. UTC
When introduced, IRQFD resampling worked on POWER8 with XICS. However
KVM on POWER9 has never implemented it - the compatibility mode code
("XICS-on-XIVE") misses the kvm_notify_acked_irq() call and the native
XIVE mode does not handle INTx in KVM at all.

This moved the capability support advertising to platforms and stops
advertising it on XIVE, i.e. POWER9 and later.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Acked-by: Nicholas Piggin <npiggin@gmail.com>
[For KVM RISC-V]
Acked-by: Anup Patel <anup@brainfault.org>
---
Changes:
v2:
* removed ifdef for ARM64.
---
 arch/arm64/kvm/arm.c       | 1 +
 arch/mips/kvm/mips.c       | 3 +++
 arch/powerpc/kvm/powerpc.c | 6 ++++++
 arch/riscv/kvm/vm.c        | 3 +++
 arch/s390/kvm/kvm-s390.c   | 3 +++
 arch/x86/kvm/x86.c         | 3 +++
 virt/kvm/kvm_main.c        | 1 -
 7 files changed, 19 insertions(+), 1 deletion(-)

Comments

Marc Zyngier Sept. 20, 2022, 4:08 p.m. UTC | #1
On Tue, 20 Sep 2022 13:51:43 +0100,
Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
> 
> When introduced, IRQFD resampling worked on POWER8 with XICS. However
> KVM on POWER9 has never implemented it - the compatibility mode code
> ("XICS-on-XIVE") misses the kvm_notify_acked_irq() call and the native
> XIVE mode does not handle INTx in KVM at all.
> 
> This moved the capability support advertising to platforms and stops
> advertising it on XIVE, i.e. POWER9 and later.
> 
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> Acked-by: Nicholas Piggin <npiggin@gmail.com>
> [For KVM RISC-V]
> Acked-by: Anup Patel <anup@brainfault.org>
> ---
> Changes:
> v2:
> * removed ifdef for ARM64.

The same argument applies to both x86 and s390, which do select
HAVE_KVM_IRQFD from the KVM config option. Only power allows this
option to be selected depending on the underlying interrupt controller
emulation.

As for riscv and mips, they don't select HAVE_KVM_IRQFD, and this
isn't a user-selectable option. So why do they get patched at all?

My conclusion is that:

- only power needs the #ifdefery in the arch-specific code
- arm64, s390 and x86 can use KVM_CAP_IRQFD_RESAMPLE without a #ifdef
- mips and riscv should be left alone

Thanks,

	M.
Alexey Kardashevskiy Sept. 20, 2022, 9:46 p.m. UTC | #2
On 21/09/2022 02:08, Marc Zyngier wr
ote:
> On Tue, 20 Sep 2022 13:51:43 +0100,
> Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
>>
>> When introduced, IRQFD resampling worked on POWER8 with XICS. However
>> KVM on POWER9 has never implemented it - the compatibility mode code
>> ("XICS-on-XIVE") misses the kvm_notify_acked_irq() call and the native
>> XIVE mode does not handle INTx in KVM at all.
>>
>> This moved the capability support advertising to platforms and stops
>> advertising it on XIVE, i.e. POWER9 and later.
>>
>> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
>> Acked-by: Nicholas Piggin <npiggin@gmail.com>
>> [For KVM RISC-V]
>> Acked-by: Anup Patel <anup@brainfault.org>
>> ---
>> Changes:
>> v2:
>> * removed ifdef for ARM64.
> 
> The same argument applies to both x86 and s390, which do select
> HAVE_KVM_IRQFD from the KVM config option. Only power allows this
> option to be selected depending on the underlying interrupt controller
> emulation.
> 
> As for riscv and mips, they don't select HAVE_KVM_IRQFD, and this
> isn't a user-selectable option. So why do they get patched at all?

Before the patch, the capability was advertised on those, with your 
proposal it will stop. Which is a change in behavior which some may say 
requires a separate patch (like, one per platform). I am definitely 
overthinking it though and you are right.

> My conclusion is that:
> 
> - only power needs the #ifdefery in the arch-specific code
> - arm64, s390 and x86 can use KVM_CAP_IRQFD_RESAMPLE without a #ifdef
> - mips and riscv should be left alone

Fair enough, thanks for the review! I'll post v3 shortly.

> 
> Thanks,
> 
> 	M.
>
Marc Zyngier Sept. 21, 2022, 5:04 p.m. UTC | #3
On Tue, 20 Sep 2022 22:46:21 +0100,
Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
> 
> 
> 
> On 21/09/2022 02:08, Marc Zyngier wr
> ote:
> > On Tue, 20 Sep 2022 13:51:43 +0100,
> > Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
> >> 
> >> When introduced, IRQFD resampling worked on POWER8 with XICS. However
> >> KVM on POWER9 has never implemented it - the compatibility mode code
> >> ("XICS-on-XIVE") misses the kvm_notify_acked_irq() call and the native
> >> XIVE mode does not handle INTx in KVM at all.
> >> 
> >> This moved the capability support advertising to platforms and stops
> >> advertising it on XIVE, i.e. POWER9 and later.
> >> 
> >> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> >> Acked-by: Nicholas Piggin <npiggin@gmail.com>
> >> [For KVM RISC-V]
> >> Acked-by: Anup Patel <anup@brainfault.org>
> >> ---
> >> Changes:
> >> v2:
> >> * removed ifdef for ARM64.
> > 
> > The same argument applies to both x86 and s390, which do select
> > HAVE_KVM_IRQFD from the KVM config option. Only power allows this
> > option to be selected depending on the underlying interrupt controller
> > emulation.
> > 
> > As for riscv and mips, they don't select HAVE_KVM_IRQFD, and this
> > isn't a user-selectable option. So why do they get patched at all?
> 
> Before the patch, the capability was advertised on those, with your
> proposal it will stop.

No, they were never advertised, since none of these architectures
select CONFIG_HAVE_KVM_IRQFD, and this option is not selectable by the
user.

> Which is a change in behavior which some may
> say requires a separate patch (like, one per platform). I am
> definitely overthinking it though and you are right.

Well, either there is no change in behaviour (and therefore I am
right), or there is one (and I am wrong).

	M.
diff mbox series

Patch

diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 2ff0ef62abad..d2daa4d375b5 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -218,6 +218,7 @@  int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_VCPU_ATTRIBUTES:
 	case KVM_CAP_PTP_KVM:
 	case KVM_CAP_ARM_SYSTEM_SUSPEND:
+	case KVM_CAP_IRQFD_RESAMPLE:
 		r = 1;
 		break;
 	case KVM_CAP_SET_GUEST_DEBUG2:
diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index a25e0b73ee70..0f3de470a73e 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -1071,6 +1071,9 @@  int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_READONLY_MEM:
 	case KVM_CAP_SYNC_MMU:
 	case KVM_CAP_IMMEDIATE_EXIT:
+#ifdef CONFIG_HAVE_KVM_IRQFD
+	case KVM_CAP_IRQFD_RESAMPLE:
+#endif
 		r = 1;
 		break;
 	case KVM_CAP_NR_VCPUS:
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index fb1490761c87..908ce8bd91c9 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -593,6 +593,12 @@  int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 		break;
 #endif
 
+#ifdef CONFIG_HAVE_KVM_IRQFD
+	case KVM_CAP_IRQFD_RESAMPLE:
+		r = !xive_enabled();
+		break;
+#endif
+
 	case KVM_CAP_PPC_ALLOC_HTAB:
 		r = hv_enabled;
 		break;
diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c
index 65a964d7e70d..0ef7a6168018 100644
--- a/arch/riscv/kvm/vm.c
+++ b/arch/riscv/kvm/vm.c
@@ -65,6 +65,9 @@  int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_READONLY_MEM:
 	case KVM_CAP_MP_STATE:
 	case KVM_CAP_IMMEDIATE_EXIT:
+#ifdef CONFIG_HAVE_KVM_IRQFD
+	case KVM_CAP_IRQFD_RESAMPLE:
+#endif
 		r = 1;
 		break;
 	case KVM_CAP_NR_VCPUS:
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index edfd4bbd0cba..03037b0d1cc8 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -577,6 +577,9 @@  int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_SET_GUEST_DEBUG:
 	case KVM_CAP_S390_DIAG318:
 	case KVM_CAP_S390_MEM_OP_EXTENSION:
+#ifdef CONFIG_HAVE_KVM_IRQFD
+	case KVM_CAP_IRQFD_RESAMPLE:
+#endif
 		r = 1;
 		break;
 	case KVM_CAP_SET_GUEST_DEBUG2:
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 43a6a7efc6ec..efcc02230226 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4395,6 +4395,9 @@  int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_VAPIC:
 	case KVM_CAP_ENABLE_CAP:
 	case KVM_CAP_VM_DISABLE_NX_HUGE_PAGES:
+#ifdef CONFIG_HAVE_KVM_IRQFD
+	case KVM_CAP_IRQFD_RESAMPLE:
+#endif
 		r = 1;
 		break;
 	case KVM_CAP_EXIT_HYPERCALL:
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 584a5bab3af3..05cf94013f02 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -4447,7 +4447,6 @@  static long kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
 #endif
 #ifdef CONFIG_HAVE_KVM_IRQFD
 	case KVM_CAP_IRQFD:
-	case KVM_CAP_IRQFD_RESAMPLE:
 #endif
 	case KVM_CAP_IOEVENTFD_ANY_LENGTH:
 	case KVM_CAP_CHECK_EXTENSION_VM: