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 A67D82749C6; Wed, 14 May 2025 10:35:08 +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=1747218908; cv=none; b=GAZpdI6aVZSUT2ybVNJGKizUi7446ozn55fz6ogbfJD9ZxFRQEC+KP36urT7wlWhqzIqbVBdLCesaT43vRURxoHgjupqbQZVQemrcWT1xSX5NcItcHqYrt96sOFE3oNGmfdZZ3rZ/FF9ABwvW/Vsxga3iWA88mV6zLGjMN+2P4g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747218908; c=relaxed/simple; bh=ydvZE2fcKiHSXxy2PEWqOT/2J5DSfX2LWTaD8LM7MhU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VvBTGUITUM5l4cnKbqh/ZqUUbI+DIhQz2uuITpbjHUkU+1Ff9hGALfXYRPpwQnfDmUmYaSwMFSLEvU/zF6dGdgawviWUry9Ll750rOyVQybT2HMQvJ4GHnckadraTb/Asq2UZT4IRHhB+DyngbEEL1tMQPXUUGzZIHBKGmuWTzI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JtzEH0np; 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="JtzEH0np" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88A04C4CEE9; Wed, 14 May 2025 10:35:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747218908; bh=ydvZE2fcKiHSXxy2PEWqOT/2J5DSfX2LWTaD8LM7MhU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JtzEH0np12lNKx3ap5NwvUBksnYfYriQ4eBqES19F26xHcOUUnyXH7UvuioS2Azxz XQPa3085T8H4UARolu9fDyZcy4NrP2017E0qwYZ82MfckuuqersBKkcM2MHItU47ga URdfAXWzv94iqJqIf8Ywj3LawAYfNg7R4YT6QJ2EsQHZyT8qYW+I2fbM8rt52Vjeab iuNjdziwTcBDLIgoR9QcxOzrSp6wca5mwhr8BkbTlkmDEIjHZBibXxzJf6pSbitm0m QNF9ExUUnf67uC3i034bMxeiCe9XKn9qLGWmCZtmIg2llRGruWQ9KeT5fkc+rn1i5s n6zHr9kcpw6Cw== 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 1uF9S6-00Eos3-NZ; Wed, 14 May 2025 11:35:06 +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 v4 12/17] KVM: arm64: nv: Program host's VNCR_EL2 to the fixmap address Date: Wed, 14 May 2025 11:34:55 +0100 Message-Id: <20250514103501.2225951-13-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250514103501.2225951-1-maz@kernel.org> References: <20250514103501.2225951-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