From patchwork Fri Oct 20 18:45:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Henrik Weinstock X-Patchwork-Id: 13431028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B8957C001DF for ; Fri, 20 Oct 2023 18:45:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:Subject: Message-ID:Date:From:MIME-Version:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=RMldteU5eHof1GkB+2aL5mARcwFMy39knLJKEMWRTR8=; b=3rZMZDudNPdboucs91tIMpIj9Q X8jTtnAdA0hr/KRexcrbLBE6rWk4mBs+r/9XcoSbE+Q43K6CNvv8e5ko80xSVW1FngI8pO4Euggyo w2VGOzVsMbQTbh0dGdOgbe+BnVCLzxJoyKMcdEC1fBBAB4lNApTCB34jbOzfY2pnhx+vtCvMjCxHL WEiHupq7sn9wQ/D0G9XBzjJWhMI72Kfcu1MX32r0uHuuUB4EvICUlj7utnJG41A9GKkFeUidXntzz 7xV3VUq8CvgtQc/h5aYuc0tqa0vOsDT79FA4es+/5C+Ey9/ItiWyGjYZnXSPl1KFXtxm1FhQZ5pxZ jMtS+ovg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtuUx-002sI3-2N; Fri, 20 Oct 2023 18:45:27 +0000 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtuUu-002sH1-3C for linux-arm-kernel@lists.infradead.org; Fri, 20 Oct 2023 18:45:26 +0000 Received: by mail-lf1-x144.google.com with SMTP id 2adb3069b0e04-507962561adso1602695e87.0 for ; Fri, 20 Oct 2023 11:45:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mwa.re; s=google; t=1697827517; x=1698432317; darn=lists.infradead.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=ZfFMOnzOWPDFZoMZUine3Kwx2BGR2wcwPk9fcWx+DPA=; b=in1mSZNIbuIiKSFFg64FnNmzMOF6E+1TKgn7oRbrSCRSV1yVDoILpnEg6qZxWJxp9O RoDU0CUb8EXsTa01AEbQJu3WkVs6LFSfwsJ5k7tBDCU5TlaVmy1a5D9RH00eXnxNfQO6 6sFUHcEqqBmRAoIvMFrBpRl1P6nt3pbr54v54Ajf/ZNhfDcoF8tH2S3T85cft3nWiFeK o/bGqV9coK/S1h/d1cXOQXck/u1oBeSncTcC7HjBcdzO+pCXYKMGr42/N2ufOaCgFogk aUxrlchkUJ3CCDQNPfDlG08N9AcEW6u3+DEmR0171c5jmwOUCzx2vWZ1YMUZu14sCQdK r/Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697827517; x=1698432317; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ZfFMOnzOWPDFZoMZUine3Kwx2BGR2wcwPk9fcWx+DPA=; b=qHRtzqAXdQ877k0m/02KJTuClzpCw3RqJXq8E1+MPtmEbwvRH3J+m85yxRhwysGs/m D3tD7Blww+qKf6Fa6AN/X7ImQYUxj6+6y6o9k/ACSxxovPVfgojKTyaMPO4NbVu9vLmv OO7fCkq91Sf1yMVW6fujOpxeorhWF+UcJD9X9NppP66bp1WBqOyOA6150ZNn1eBM8mWK 126jls5qCvqT0+xX+rO+2767WW6KPtXikN1oSOkc4nfyaucS5yh0zdHqP+sQ5x4MLqJe sYV18XnrmpAasPbEGvOoipP0bnjWTPiR0SpJkPCMACfNIzHhBpA09s9R057MYyjiZOYg yUjA== X-Gm-Message-State: AOJu0YwNaR4vpwjlN+U9zCfcprr+W8PsuF9Kkq699jlrzJ4xewFie6qH yNdfKZHUlDzBBV77KD7UHSVApIQAmogf+AKtnH2y+A== X-Google-Smtp-Source: AGHT+IE5hZ1sKzwYuMwdSBO+vIOGwPbVFEcae0zzTmXEQmtV9ubV2XfshfdeCHWwUQnmfz7pTCIGDGe4fITdr3PoS58= X-Received: by 2002:ac2:5a0a:0:b0:4fb:9f93:365f with SMTP id q10-20020ac25a0a000000b004fb9f93365fmr1881407lfn.38.1697827516928; Fri, 20 Oct 2023 11:45:16 -0700 (PDT) MIME-Version: 1.0 From: Jan Henrik Weinstock Date: Fri, 20 Oct 2023 20:45:05 +0200 Message-ID: Subject: KVM exit to userspace on WFI To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, =?utf-8?q?Lukas_J=C3=BCnger?= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231020_114525_037702_221A93BB X-CRM114-Status: GOOD ( 12.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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? 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