From patchwork Tue Aug 27 15:25:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13779710 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 AE944C54731 for ; Tue, 27 Aug 2024 15:30:35 +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-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=lpvRqejwa3hfiGC0/NywBIc7ZlsRtuhgFN6LeJml/mI=; b=didxbJ4spRj4dNOxus9fH572Zh MmbKOV4gK/wkUJ+7sHd7mpgAeXWPx/IqqYP/GBDWP7d/N9GmfJzcVhYpBjPOxboYS2tqp5LURW2Eq qX9F9VcNls/uEBtd+ZyxjbLqq62yfFn4zo2v4OJIzjKlUIVGx7s+EWewSN9FrZ3Lf57GE+LbQomZW vEDIg/uIj3mWGprxUepYJw/9g7x8i4KqPb0QJ+LaOE1zG8YhHKH94ColXJNwbSF5wmdrBlDQj8wwc 2w7PZ354KH1nuAnHh4/QomT6GQxjGRD/bD9en7QqGOmj1k8zB6CkBuPpQkcTEYN9ZZwJIkjgNR+un emqVBj4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1siy9K-0000000Bt6j-1mBv; Tue, 27 Aug 2024 15:30:26 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1siy4Z-0000000BrWm-3LJy for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 15:25:34 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 2CC7BCE1333; Tue, 27 Aug 2024 15:25:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B20D2C6107C; Tue, 27 Aug 2024 15:25:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724772329; bh=c4iroNXWrqCbK3brxthl10TjLRTGDzGLQjuWGBMJdks=; h=From:To:Cc:Subject:Date:From; b=bPPcKj53eti0OzWLdfp3YFPYYpqaF53L79ZhIhlj6uaroKk8f8YE5KxscReXmMD56 lYOnVv7NnT6xD9MfUXihm41ezWpB3w4HrmrOnFFPhQr3rDcP0+KcwM+UXZVlNyfYOG wAHTpfFs0d/U+d0HF4kLs76PXa3HoIfqDM9ytnDidu3sRjfKK82jJK+2rosJ/iNe21 iqr7JZFJ5C9l/GDmt426B2dpqB6U4CxJWG48tcRf/lTOenUsITvg59G6AeLsMyy4m+ 36DTZ+D+f6cnTn09Rur3XdPMI3ZVXKWbDIykS/Pl7lNiOFjX9sea6mbcyGZnAdYQX1 uKie9zM7ZWL1A== 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 1siy4V-007HOs-Cg; Tue, 27 Aug 2024 16:25:27 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Alexander Potapenko Subject: [PATCH v2 00/11] KVM: arm64: Handle the lack of GICv3 exposed to a guest Date: Tue, 27 Aug 2024 16:25:06 +0100 Message-Id: <20240827152517.3909653-1-maz@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, glider@google.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-20240827_082532_222424_6B200025 X-CRM114-Status: GOOD ( 20.34 ) 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 It recently appeared that, when running on a GICv3-equipped platform (which is what non-ancient arm64 HW has), *not* configuring a GICv3 for the guest could result in less than desirable outcomes. We have multiple issues to fix: - for registers that *always* trap (the SGI registers) or that *may* trap (the SRE register), we need to check whether a GICv3 has been instantiated before acting upon the trap. - for registers that only conditionally trap, we must actively trap them even in the absence of a GICv3 being instantiated, and handle those traps accordingly. - finally, ID registers must reflect the absence of a GICv3, so that we are consistent. This series goes through all these requirements. The main complexity here is to apply a GICv3 configuration on the host in the absence of a GICv3 in the guest. This is pretty hackish, but I don't have a much better solution so far. As part of making wider use of of the trap bits, we fully define the trap routing as per the architecture, something that we eventually need for NV anyway. Finally, I have added two additional changes: - a file-wide cleanup of sys_regs.c, unifying the way we inject an UNDEF from the trap handling array - a selftest that checks for the implemented trapping behaviour (yes, I actually wrote a test -- hated every minute of it). Note that the effects of this series when a GICv2 is configured on a GICv3 host capable of emulation are imperfect: For some of the registers, the guest may take a system register trap at EL1 (EC=0x18), and there is nothing that KVM can do about it (this is a consequence of ICC_SRE_EL1.SRE being 0, which GICv2 requires). But at least that's a guest problem, not the host's. Patches on top of v6.11-rc5, tested on the usual lot of terrible HW: Synquacer, TX1 and M1. * From v1 [1]: - Drop the first patch of the series, as Oliver picked it up and ferried it into 6.11-rc5. - Fixed a number of comments involving GICv2 - Rewrote kvm_has_gicv3() to look at the ID registers instead of the internal condition soup. - Hacked more of the selftest so that we check that even when ICC_SRE_EL1 doesn't trap, it is still RAO/WI. [1] https://lore.kernel.org/r/20240820100349.3544850-1-maz@kernel.org Marc Zyngier (11): KVM: arm64: Move GICv3 trap configuration to kvm_calculate_traps() KVM: arm64: Force SRE traps when SRE access is not enabled KVM: arm64: Force GICv3 trap activation when no irqchip is configured on VHE KVM: arm64: Add helper for last ditch idreg adjustments KVM: arm64: Zero ID_AA64PFR0_EL1.GIC when no GICv3 is presented to the guest KVM: arm64: Add ICH_HCR_EL2 to the vcpu state KVM: arm64: Add trap routing information for ICH_HCR_EL2 KVM: arm64: Honor guest requested traps in GICv3 emulation KVM: arm64: Make most GICv3 accesses UNDEF if they trap KVM: arm64: Unify UNDEF injection helpers KVM: arm64: Add selftest checking how the absence of GICv3 is handled arch/arm64/include/asm/kvm_host.h | 2 + arch/arm64/kvm/arm.c | 14 +- arch/arm64/kvm/emulate-nested.c | 71 +++++- arch/arm64/kvm/hyp/vgic-v3-sr.c | 97 ++++++- arch/arm64/kvm/nested.c | 15 +- arch/arm64/kvm/sys_regs.c | 240 ++++++++++-------- arch/arm64/kvm/sys_regs.h | 9 + arch/arm64/kvm/vgic/vgic-v3.c | 12 + arch/arm64/kvm/vgic/vgic.c | 14 +- arch/arm64/kvm/vgic/vgic.h | 6 +- tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/aarch64/no-vgic-v3.c | 175 +++++++++++++ 12 files changed, 521 insertions(+), 135 deletions(-) create mode 100644 tools/testing/selftests/kvm/aarch64/no-vgic-v3.c Reviewed-by: Oliver Upton