public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* KVM exit to userspace on WFI
@ 2023-10-20 18:45 Jan Henrik Weinstock
  2023-10-20 19:56 ` Marc Zyngier
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Henrik Weinstock @ 2023-10-20 18:45 UTC (permalink / raw)
  To: maz, oliver.upton, james.morse, suzuki.poulose, yuzenghui,
	catalin.marinas, will
  Cc: linux-arm-kernel, kvmarm, linux-kernel, Lukas Jünger

[-- Attachment #1: Type: text/plain, Size: 650 bytes --]

Hi all,

I am looking for a way to have KVM_RUN exit back to userspace once the
vcpu encounters a WFI. It seems the kvm_run->request_interrupt_window
flag is currently ignored by arm64. So my solution thus far is to
patch kvm_handle_wfx in arch/arm64/kvm/handle_exit.c and return to
userspace with KVM_EXIT_IRQ_WINDOW_OPEN - working example attached.
Any chance to get this (or something similar) mainline?

-- 
Dr.-Ing. Jan Henrik Weinstock
Managing Director

MachineWare GmbH | www.machineware.de
Hühnermarkt 19, 52062 Aachen, Germany
Amtsgericht Aachen HRB25734

Geschäftsführung
Lukas Jünger
Dr.-Ing. Jan Henrik Weinstock

[-- Attachment #2: kvm.patch --]
[-- Type: text/x-patch, Size: 1339 bytes --]

diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 54d26f13f..7be42e3f1 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -215,6 +215,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_SET_GUEST_DEBUG:
 	case KVM_CAP_VCPU_ATTRIBUTES:
 	case KVM_CAP_PTP_KVM:
+	case KVM_CAP_ARM_WFX_EXIT:
 		r = 1;
 		break;
 	case KVM_CAP_SET_GUEST_DEBUG2:
diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
index a5ab52150..d0386faeb 100644
--- a/arch/arm64/kvm/handle_exit.c
+++ b/arch/arm64/kvm/handle_exit.c
@@ -88,6 +88,11 @@ static int handle_no_fpsimd(struct kvm_vcpu *vcpu)
  */
 static int kvm_handle_wfx(struct kvm_vcpu *vcpu)
 {
+	if (vcpu->run->request_interrupt_window) {
+		vcpu->run->exit_reason = KVM_EXIT_IRQ_WINDOW_OPEN;
+		return 0;
+	}
+
 	if (kvm_vcpu_get_esr(vcpu) & ESR_ELx_WFx_ISS_WFE) {
 		trace_kvm_wfx_arm64(*vcpu_pc(vcpu), true);
 		vcpu->stat.wfe_exit_stat++;
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 83a2185d9..1073269f2 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -1124,6 +1124,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_SYS_ATTRIBUTES 209
 #define KVM_CAP_S390_MEM_OP_EXTENSION 211
 #define KVM_CAP_S390_ZPCI_OP 221
+#define KVM_CAP_ARM_WFX_EXIT 222
 
 #ifdef KVM_CAP_IRQ_ROUTING
 

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-11-08  9:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-20 18:45 KVM exit to userspace on WFI Jan Henrik Weinstock
2023-10-20 19:56 ` Marc Zyngier
2023-10-25 12:12   ` Jan Henrik Weinstock
2023-10-25 12:42     ` Marc Zyngier
2023-10-27 17:41       ` Jan Henrik Weinstock
2023-10-30 12:36         ` Marc Zyngier
2023-10-31 19:21           ` Jan Henrik Weinstock
2023-11-04 12:13             ` Marc Zyngier
2023-11-08  9:38               ` Jan Henrik Weinstock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox