From: sashiko-bot@kernel.org
To: "Dan Carpenter" <dan@pereq.eu>
Cc: kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>,
"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH 1/2] KVM: arm64: nv: Fix AT emulation for TCR2_EL1
Date: Mon, 16 Nov 2026 06:27:41 +0000 [thread overview]
Message-ID: <sashiko-outbox-216278@kernel.org> (raw)
In-Reply-To: <eec50693a12e1ba34d60458ae8fe605ac198a79c.1794808373.git.dan@pereq.eu>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: arm64: nv: unmasked PIE/POE in SYS_TCR2 in
__kvm_at_s1e01_fast() and __kvm_at_s1e2()
--
commit ba7c962c50af660f734650ef98aa65969755bc0a
Author: Dan Carpenter <dan@pereq.eu>
KVM: arm64: nv: Fix AT emulation for TCR2_EL1
This commit sanitizes hardware SYS_TCR2 during nested AT instruction
emulation by masking out unsupported PIE and POE bits and clearing
SYS_TCR2 when the guest VM does not support FEAT_TCR2.
> diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c
> index 30d8f062b2c29..06765881a4c81 100644
> --- a/arch/arm64/kvm/at.c
> +++ b/arch/arm64/kvm/at.c
> @@ -1438,7 +1438,13 @@ static u64 __kvm_at_s1e01_fast(struct kvm_vcpu *vcpu, u32 op, u64 vaddr)
> write_sysreg_el1(vcpu_read_sys_reg(vcpu, TCR_EL1), SYS_TCR);
> write_sysreg_el1(vcpu_read_sys_reg(vcpu, MAIR_EL1), SYS_MAIR);
> if (kvm_has_tcr2(vcpu->kvm)) {
> - write_sysreg_el1(vcpu_read_sys_reg(vcpu, TCR2_EL1), SYS_TCR2);
> + u64 tcr2 = effective_tcr2(vcpu, TR_EL10);
> +
> + if (!kvm_has_s1pie(vcpu->kvm))
> + tcr2 &= ~TCR2_EL1_PIE;
> + if (!kvm_has_s1poe(vcpu->kvm))
> + tcr2 &= ~(TCR2_EL1_POE | TCR2_EL1_E0POE);
> + write_sysreg_el1(tcr2, SYS_TCR2);
> if (kvm_has_s1pie(vcpu->kvm)) {
> write_sysreg_el1(vcpu_read_sys_reg(vcpu, PIR_EL1), SYS_PIR);
> write_sysreg_el1(vcpu_read_sys_reg(vcpu, PIRE0_EL1), SYS_PIRE0);
> @@ -1452,6 +1458,9 @@ static u64 __kvm_at_s1e01_fast(struct kvm_vcpu *vcpu, u32 op, u64 vaddr)
> __load_stage2(mmu);
>
> skip_mmu_switch:
> + if (cpus_have_final_cap(ARM64_HAS_TCR2) && !kvm_has_tcr2(vcpu->kvm))
> + write_sysreg_el1(0, SYS_TCR2);
> +
> /* Temporarily switch back to guest context */
> write_sysreg_hcr(vcpu->arch.hcr_el2);
> isb();
> @@ -1554,6 +1563,9 @@ int __kvm_at_s1e2(struct kvm_vcpu *vcpu, u32 op, u64 vaddr)
> if (!vcpu_el2_e2h_is_set(vcpu))
> val |= HCR_EL2_NV | HCR_EL2_NV1;
>
> + if (cpus_have_final_cap(ARM64_HAS_TCR2) && !kvm_has_tcr2(vcpu->kvm))
> + write_sysreg_el1(0, SYS_TCR2);
[Severity: Medium]
Does hardware SYS_TCR2 still retain unmasked PIE, POE, and E0POE bits in
__kvm_at_s1e2() and on the !mmu_cs path of __kvm_at_s1e01_fast() when
kvm_has_tcr2(vcpu->kvm) is true?
When the guest runs at vEL2 with HCR_EL2.E2H == 1, HCRX_EL2_TCR2En is set
and the guest writes its TCR2_EL2 directly into hardware SYS_TCR2 without
trapping. The RES0 masks in tcr2_el2_feat_map are only applied in
software by vcpu_read_sys_reg(vcpu, TCR2_EL2), so on a guest exit for an
AT trap, hardware SYS_TCR2 still holds any raw PIE, POE, or E0POE bits
written by vEL2.
If the VM has FEAT_TCR2 enabled but FEAT_S1PIE or FEAT_S1POE disabled,
KVM does not load PIR_EL1, PIRE0_EL1, or POR_EL1 for the guest, so both
paths will evaluate Stage-1 permissions against stale PIR/POR values from
another VM or the host VMM's POR_EL0. Writing vcpu_read_sys_reg(vcpu,
TCR2_EL2) to SYS_TCR2 (and restoring the raw guest value afterwards) when
kvm_has_tcr2(vcpu->kvm) is true would apply the configured RES0 masks.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1794808373.git.dan@pereq.eu?part=1
next prev parent reply other threads:[~2026-11-16 6:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 6:00 [PATCH 0/2] KVM: arm64: nv: fix a couple bugs in AT emulation Dan Carpenter
2026-11-16 6:00 ` [PATCH 2/2] KVM: arm64: nv: Update the shadow MMU's VMID for " Dan Carpenter
2026-11-16 6:00 ` [PATCH 1/2] KVM: arm64: nv: Fix AT emulation for TCR2_EL1 Dan Carpenter
2026-11-16 6:27 ` sashiko-bot [this message]
2026-11-16 9:22 ` Dan Carpenter
2026-11-16 16:01 ` Marc Zyngier
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=sashiko-outbox-216278@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dan@pereq.eu \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.