From patchwork Mon Nov 20 13:10:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13461235 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D1461EA72; Mon, 20 Nov 2023 13:10:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JDcWY2Xs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5F9EC433C7; Mon, 20 Nov 2023 13:10:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700485858; bh=uQStS8OhF9bOiuYGBQwafNDcKEhaFD7FkZJn4m6F/3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JDcWY2XsT+wrP772GvzQKQviIKjoSo0yNiyntXdUgo2pEk7+4vMYduNWP3kFXraRt DTK+1X8zKXN9lk1P4NNl6oQ9u2qdjd0wmd8xizNKi+NDJ9Tzrc0efMih15QOcnsu7t N4OTDF4S4pwa6KX9ooL/I4C0RD4jnNMP6ymscOaeZS0jMT7UXD3TCJfMd1XHTVjFSA IOhSixITUNd1IdrYhilLCYTodpQJfDY/teL8zlNz6xJ0AvDyHA27QTWKihjUd+FENp fnMVIYmaCww/ZadPVXYGi0rhhXAgg03CWQx4K9T2vlOR9E14eiFSRRU2E4c8RJ8iBy Pn8O1OFZcfqzw== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1r543F-00EjnU-2c; Mon, 20 Nov 2023 13:10:57 +0000 From: Marc Zyngier To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Alexandru Elisei , Andre Przywara , Chase Conklin , Christoffer Dall , Ganapatrao Kulkarni , Darren Hart , Jintack Lim , Russell King , Miguel Luis , James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu Subject: [PATCH v11 31/43] KVM: arm64: nv: Don't block in WFI from nested state Date: Mon, 20 Nov 2023 13:10:15 +0000 Message-Id: <20231120131027.854038-32-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231120131027.854038-1-maz@kernel.org> References: <20231120131027.854038-1-maz@kernel.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, alexandru.elisei@arm.com, andre.przywara@arm.com, chase.conklin@arm.com, christoffer.dall@arm.com, gankulkarni@os.amperecomputing.com, darren@os.amperecomputing.com, jintack@cs.columbia.edu, rmk+kernel@armlinux.org.uk, miguel.luis@oracle.com, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false If trapping WFI from a L2 guest, and that L1 hasn't asked for such trap, it is very hard to decide when to unblock the vcpu, as we only have a very partial view on the guest's nested interrupt state (the L1 hypervisor knows about it, but L0 doesn't). In such a case, we're better off just returning to the L2 guest immediately. It isn't wrong from an architecture perspective. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/arm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 95760ed448bf..d684a2af3406 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -781,6 +781,15 @@ static void kvm_vcpu_sleep(struct kvm_vcpu *vcpu) */ void kvm_vcpu_wfi(struct kvm_vcpu *vcpu) { + /* + * If we're in nested state and the guest hypervisor does not trap + * WFI, we're in a bit of trouble, as we don't have a good handle + * on the interrupts that are pending for the guest yet. Revisit + * this at some point. + */ + if (vgic_state_is_nested(vcpu)) + return; + /* * Sync back the state of the GIC CPU interface so that we have * the latest PMR and group enables. This ensures that