[PATCH v2 2/4] KVM: arm64: Trap TCR2_EL1 writes when S1PIE or S1POE is hidden

Marc Zyngier maz at kernel.org
Thu Nov 19 08:32:00 PST 2026


On Thu, 19 Nov 2026 13:25:35 +0000,
Dan Carpenter <dan at pereq.eu> wrote:
> 
> A VMM can offer FEAT_TCR2 to a guest but hide FEAT_S1PIE or FEAT_S1POE,
> for example this is done to keep the VM migratable.  KVM then stops
> loading the PIR_EL1, PIRE0_EL1 and POR_EL1 registers for that guest.  But
> the guest's writes to the TCR2_EL1 register don't trap, and the CPU still
> acts on its PIE, POE and E0POE bits.
> 
> If a guest turned these features on, it would run with the permission
> settings another VM left on the CPU.  Technically this is a kind of
> information leak and a guest could figure out another guests permission
> setting based on which accesses fault.
> 
> For these VMs, set the TCR_EL1 bit in HFGWTR_EL2 so that writes to
> TCR_EL1 and TCR2_EL1 trap, and clear the hidden bits in a new
> access_tcr2_el1() handler.
> 
> Fixes: 58627b722ee2 ("KVM: arm64: Make PIR{,E0}_EL1 UNDEF if S1PIE is not advertised to the guest")
> Fixes: b86c9bea6349 ("KVM: arm64: Save/restore POE registers")
> Cc: stable at vger.kernel.org
> Signed-off-by: Dan Carpenter <dan at pereq.eu>
> ---
> v2: This is a new patch
> 
> This is only a partial fix, I will update nested virtualization in the
> next patch and the !vcpu_has_nv(vcpu) condition in __compute_hfgwtr() will
> go away.

No, I really don't want to go down that road.

Trapping TCR_EL1 is an absolute performance sink, and at this point it
is not worth running VMs (it puts everyone at the level of AmpereOne).
It also puts the penalty on well behaved guests which should be able
to access TCR_EL1 as much as they want without penalties.

Yes, the architecture is terrible, and we have to work around it.  I
can see two ways to address this:

- load PIR/PIRE0/POR unconditionally so that they do not contain any
  state that logically belong to another guest, preferably with values
  that prevent any access (0 is a good candidate for the permissions).
  It means that if the guest plays with us, it will lose permission to
  its own memory accesses.

- Move TCR2_EL1 to the sanitised set, and make sure that these bits are
  never evaluated by KVM, and will be cleared on each entry (we
  already do this for TCR2_EL2).

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-arm-kernel mailing list