From mboxrd@z Thu Jan 1 00:00:00 1970 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 C3D6B29AAF4; Wed, 23 Apr 2025 15:15:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745421318; cv=none; b=VOfLPfB9hENlnaWl6spZaomxIHQk5YpRKsy0rU68U9GIZWS0KODFT0ZZb1dGn37LHTuskK+hed3FOdhe3A4pun1ZtiiZPssrbB28ENSb4PUnAjIupFLe6yPyVhL9/F5NoRfFypFclYiUCrvIJrjQCP96UqNLuow7VfPtnb9v+2g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745421318; c=relaxed/simple; bh=ydvZE2fcKiHSXxy2PEWqOT/2J5DSfX2LWTaD8LM7MhU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MIOLE7nfPPxW77wh+xQpRSnwGMG96PzsQivfOFaJQpu9Xc5wbmlZI7KA39WvGCKT5ECKHRivjYlUk2HDu+HjAgsFNufxN+vbcDfk2PSj2Xy7yCG4GwUr2uxkcZT6VwqNZfcP754auxlHtxP3NmJ1zJ953B3EO2Y6Hgn79luzPxM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W1QWVxbd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W1QWVxbd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41B6AC4CEE2; Wed, 23 Apr 2025 15:15:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745421318; bh=ydvZE2fcKiHSXxy2PEWqOT/2J5DSfX2LWTaD8LM7MhU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W1QWVxbdXqXKmZ/onqcAyuN43xhgVxBT1UFRYiqubMUdVOsOg7fGbZRrWYg71LwJV 95st50Li0G/ggd7UGV0HejKF6Wp/Oib4k/gJNN6Yx7toT1KTX/YhANkVzvMQ67HMC5 frCc2k0A5b1akKefhO9CPIE7424nxxQEdw7wqMbZdEEPaf5bsGLCx0aMT/x+quT6+0 wkhfDAHcwgIk7vDhmVpFdH1/2On6X9o+oMbQ6j8t+a+YWOAlaozjl1X+nv4HI1GJY7 hvehFnwVg/FLKLTvoruV9e2AZ5v+8B8eTsJS53D5V5qq4hbuCuTgklcuZoAdQ19dT7 Rd5JtyxtEZbdA== 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 1u7boi-0082xr-7G; Wed, 23 Apr 2025 16:15:16 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Joey Gouly , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Eric Auger , Ganapatrao Kulkarni Subject: [PATCH v3 12/17] KVM: arm64: nv: Program host's VNCR_EL2 to the fixmap address Date: Wed, 23 Apr 2025 16:15:03 +0100 Message-Id: <20250423151508.2961768-13-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250423151508.2961768-1-maz@kernel.org> References: <20250423151508.2961768-1-maz@kernel.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, joey.gouly@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, eric.auger@redhat.com, gankulkarni@os.amperecomputing.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Since we now have a way to map the guest's VNCR_EL2 on the host, we can point the host's VNCR_EL2 to it and go full circle! Note that we unconditionally assign the fixmap to VNCR_EL2, irrespective of the guest's version being mapped or not. We want to take a fault on first access, so the fixmap either contains something guranteed to be either invalid or a guest mapping. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/vhe/switch.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c index 220dee8a45e0d..5eaff1ae32b29 100644 --- a/arch/arm64/kvm/hyp/vhe/switch.c +++ b/arch/arm64/kvm/hyp/vhe/switch.c @@ -48,6 +48,7 @@ DEFINE_PER_CPU(unsigned long, kvm_hyp_vector); static u64 __compute_hcr(struct kvm_vcpu *vcpu) { + u64 guest_hcr = __vcpu_sys_reg(vcpu, HCR_EL2); u64 hcr = vcpu->arch.hcr_el2; if (!vcpu_has_nv(vcpu)) @@ -70,9 +71,23 @@ static u64 __compute_hcr(struct kvm_vcpu *vcpu) write_sysreg_s(vcpu->arch.ctxt.vncr_array, SYS_VNCR_EL2); } else { host_data_clear_flag(VCPU_IN_HYP_CONTEXT); + + if (guest_hcr & HCR_NV) { + u64 va = __fix_to_virt(vncr_fixmap(smp_processor_id())); + + /* Inherit the low bits from the actual register */ + va |= __vcpu_sys_reg(vcpu, VNCR_EL2) & GENMASK(PAGE_SHIFT - 1, 0); + write_sysreg_s(va, SYS_VNCR_EL2); + + /* Force NV2 in case the guest is forgetful... */ + guest_hcr |= HCR_NV2; + } } - return hcr | (__vcpu_sys_reg(vcpu, HCR_EL2) & ~NV_HCR_GUEST_EXCLUDE); + BUG_ON(host_data_test_flag(VCPU_IN_HYP_CONTEXT) && + host_data_test_flag(L1_VNCR_MAPPED)); + + return hcr | (guest_hcr & ~NV_HCR_GUEST_EXCLUDE); } static void __activate_cptr_traps(struct kvm_vcpu *vcpu) -- 2.39.2