From: Oliver Upton <oupton@kernel.org>
To: kvmarm@lists.linux.dev
Cc: Marc Zyngier <maz@kernel.org>, Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Wei-Lin Chang <weilin.chang@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Fuad Tabba <fuad.tabba@linux.dev>,
Oliver Upton <oupton@kernel.org>,
stable@vger.kernel.org
Subject: [PATCH v3 5/5] KVM: arm64: nv: Correctly compute the effective TCR_EL1 for nVHE TCR_EL2
Date: Thu, 29 Oct 2026 15:37:32 -0700 [thread overview]
Message-ID: <20261029223732.103785-6-oupton@kernel.org> (raw)
In-Reply-To: <20261029223732.103785-1-oupton@kernel.org>
It would appear that nVHE hypervisor support has a few warts which
shouldn't come as a surprise. Several fields in TCR_EL2 for features
supported in the VM (TCR_EL2.HA for example) are not correctly
propagated to the effective value of TCR_EL1.
Forward fields in bulk from nVHE TCR_EL2 to the effective TCR_EL1,
relying on config-based sanitisation to enforce the RESx behavior of
unsupported features. Deal with the slightly annoying case where the
E2H==0 bitfield names are not annotated by TTBR like they are in E2H==1.
Cc: stable@vger.kernel.org # v6.18+
Fixes: d5bbb76f4474 ("KVM: arm64: nv: Expose hardware access flag management to NV guests")
Fixes: 3606e0b2e462 ("KVM: arm64: nv: Add non-VHE-EL2->EL1 translation helpers")
Signed-off-by: Oliver Upton <oupton@kernel.org>
---
arch/arm64/include/asm/kvm_nested.h | 38 ++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 9 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/kvm_nested.h
index 0f899addafa8..27ec73da02c6 100644
--- a/arch/arm64/include/asm/kvm_nested.h
+++ b/arch/arm64/include/asm/kvm_nested.h
@@ -20,16 +20,36 @@ static inline u64 tcr_el2_ps_to_tcr_el1_ips(u64 tcr_el2)
return (u64)FIELD_GET(TCR_EL2_PS_MASK, tcr_el2) << TCR_IPS_SHIFT;
}
-static inline u64 translate_tcr_el2_to_tcr_el1(u64 tcr)
+#define __xlate_tcr_nvhe_to_vhe(nfld, vfld, nvhe, vhe) \
+ FIELD_MODIFY(VHE_TCR_EL2_##vfld, vhe, FIELD_GET(TCR_EL2_##nfld, *(nvhe)))
+
+#define __xlate_tcr_nvhe_to_vhe_field(fld, nvhe, vhe) \
+ __xlate_tcr_nvhe_to_vhe(fld, fld, nvhe, vhe)
+
+static inline u64 translate_tcr_el2_to_tcr_el1(u64 nvhe)
{
- return TCR_EPD1_MASK | /* disable TTBR1_EL1 */
- ((tcr & TCR_EL2_DS) ? TCR_DS : 0) |
- ((tcr & TCR_EL2_TBI) ? TCR_TBI0 : 0) |
- tcr_el2_ps_to_tcr_el1_ips(tcr) |
- (tcr & TCR_EL2_TG0_MASK) |
- (tcr & TCR_EL2_ORGN0_MASK) |
- (tcr & TCR_EL2_IRGN0_MASK) |
- (tcr & TCR_EL2_T0SZ_MASK);
+ u64 vhe = VHE_TCR_EL2_EPD1 | /* disable TTBR1_EL1 */
+ tcr_el2_ps_to_tcr_el1_ips(nvhe);
+
+ __xlate_tcr_nvhe_to_vhe(MTX, MTX0, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe(TCMA, TCMA0, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe(TBID, TBID0, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe(HWU62, HWU062, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe(HWU61, HWU061, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe(HWU60, HWU060, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe(HWU59, HWU059, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe(HPD, HPD0, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe(TBI, TBI0, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe_field( DS, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe_field( HA, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe_field( HD, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe_field( TG0, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe_field( SH0, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe_field( ORGN0, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe_field( IRGN0, &nvhe, &vhe);
+ __xlate_tcr_nvhe_to_vhe_field( T0SZ, &nvhe, &vhe);
+
+ return vhe;
}
static inline u64 translate_cptr_el2_to_cpacr_el1(u64 cptr_el2)
--
2.47.3
next prev parent reply other threads:[~2026-10-29 22:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 22:37 [PATCH v3 0/5] KVM: arm64: TCR_EL2 fixes, FEAT_LPA2=NI for NV Oliver Upton
2026-10-29 22:37 ` [PATCH v3 1/5] KVM: arm64: nv: Don't advertise FEAT_LPA2 for guest stage-1 Oliver Upton
2026-10-29 22:37 ` [PATCH v3 2/5] arm64: sysreg: Add TCR_EL2 to sysreg infrastructure Oliver Upton
2026-10-29 22:37 ` [PATCH v3 3/5] KVM: arm64: Reset TCR_EL2 according to guest's E2H mode Oliver Upton
2026-10-29 22:37 ` [PATCH v3 4/5] KVM: arm64: Convert TCR_EL2 to config-driven sanitisation Oliver Upton
2026-10-30 1:26 ` Wei-Lin Chang
2026-10-29 22:37 ` Oliver Upton [this message]
2026-10-30 1:13 ` [PATCH v3 5/5] KVM: arm64: nv: Correctly compute the effective TCR_EL1 for nVHE TCR_EL2 Wei-Lin Chang
2026-10-30 11:03 ` [PATCH v3 0/5] KVM: arm64: TCR_EL2 fixes, FEAT_LPA2=NI for NV Fuad Tabba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261029223732.103785-6-oupton@kernel.org \
--to=oupton@kernel.org \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=seiden@linux.ibm.com \
--cc=stable@vger.kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=weilin.chang@arm.com \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox