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: 13461276 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 D93E0C54FB9 for ; Mon, 20 Nov 2023 13:15:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jxRpEPPdO2OzkCuYTK4zaPnhawcfp4D1Xv1zEgLcZRw=; b=rMQVdv+PBuOqxZ AbT8wmQB4JmwjFkeoTJjInARoS7vFRoaRtXp2c8JzJeocQKx4L4VcAXFxt62U+us/SX4+2vWrFNUN nGrhx/hYpHN2Zcqn8vOZ1UIkM4s2h2b1jbckPxFn2LqNDDtED7eMcX0Kgh/OEnk0pIHdpxwkqcHPj EV9iWmHNmvldebLl3QvrGXU4dra2MOq3s4IR8iWYCdq81H3gteJ3a4DakCVV8GM3jGcLFThzll7nX 5rE7nYpZY6uRg38cH5DJx1678txmpz8uK7c6K6Opy6tybnpFFgz5dgt8BDGSv4F3zVtClkDrh78UW fO3+rIvkCZ3qhAdebpNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r547X-00C6Z3-2V; Mon, 20 Nov 2023 13:15:23 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r543O-00C4jG-2v for linux-arm-kernel@bombadil.infradead.org; Mon, 20 Nov 2023 13:11:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=5e4XuhJ6bmvnLX8VY4oJmabjAcRNmGlLfwvaOSDqNig=; b=A8VAPqRJkjPAJji50tL4zKdJqT 7tv1h+mhfwUajhZMrCZnUo96GP1jTYuk16oSQuIWHvKJwTwRn1K3LC7lnEu1GdFIbvOb+K3ItdlEP SvaLksRmQT44dW+J4SGLBxPzx+lnAn798W78nl0wixghGE+nNu15dKPZEWUT24gBxRbyIDjqOEM1f slp9aI89cKP0ME1oaU5w2xRgoz95n37Pjj9xui1bg8VSKkIX0H9wn0jUbUc4x+ZkdmRDc8LC1spNL YlwpiOkXwpjDu5C1EKLJM6n9qTXlDt5MHRDbAqfCFpAum/CnbGtejKBcSWhXR7tWW7NNIc0jjJFBu coJ4x7vg==; Received: from dfw.source.kernel.org ([139.178.84.217]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r543K-00AyDI-0h for linux-arm-kernel@lists.infradead.org; Mon, 20 Nov 2023 13:11:05 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C11AF60E8B; Mon, 20 Nov 2023 13:10:59 +0000 (UTC) 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> 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231120_131102_450538_4E3EFBAE X-CRM114-Status: GOOD ( 12.97 ) 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 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