KVM: arm64: Reenable MTE on VHE guest exit
Marc Zyngier
maintainercover KVM: arm64: Reenable MTE on VHE guest exit
Upton taking an exception, the CPU sets PSTATE.TCO to ensure that no tag fault can be taken while handling the exception. It is SW's job to eventually clear it when it is safe to do so.
It appears that when MTE is enabled and that the kernel is running VHE, nothing eventually clears TCO when we come back from the guest, so things such as KASAN_HW_TAGS will not work until the next exit to userspace.
This series aims at fixing this. This is not a stable candidate, as KASAN is only a debug option.
Marc Zyngier (2):
arm64: Add return value to mte_disable_tco_entry()
KVM: arm64: Reenable MTE tag checking on exit from guest when running
VHE
arch/arm64/include/asm/mte.h | 10 +++++++--- arch/arm64/kvm/hyp/vhe/switch.c | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-)
Signature · 1 line
2.47.3
Marc Zyngier
maintainerPATCH 1/2 arm64: Add return value to mte_disable_tco_entry()
In order to provide adequate levels of synchronisation when clearing TCO, update mte_disable_tco_entry() to indicate whether it has actually done something.
--- arch/arm64/include/asm/mte.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
arch/arm64/include/asm/mte.h +7 -3
@@ -224,10 +224,10 @@ static inline bool folio_try_hugetlb_mte_tagging(struct folio *folio) }#endif -static inline void mte_disable_tco_entry (struct task_struct *task) +static inline bool mte_disable_tco_entry (struct task_struct *task) {if (!system_supports_mte ()) -return ; +return false;/* * Re-enable tag checking (TCO set on exception entry). This is only
@@ -240,8 +240,12 @@ static inline void mte_disable_tco_entry(struct task_struct *task)* expensive. */ if (kasan_hw_tags_enabled () || - (task->thread.sctlr_user & (1UL <<SCTLR_EL1_TCF0_SHIFT ))) + (task->thread.sctlr_user & (1UL <<SCTLR_EL1_TCF0_SHIFT ))) { asm volatile(SET_PSTATE_TCO(0)); +return true; + } + +return false; }#ifdef CONFIG_KASAN_HW_TAGS
Signature · 1 line
2.47.3
Marc Zyngier
maintainerPATCH 2/2 KVM: arm64: Reenable MTE tag checking on exit from guest when running VHE
In reply to Marc ZyngierOnce we're back from running a guest, it is important to set TCO to zero so that MTE is functional again.
--- arch/arm64/kvm/hyp/vhe/switch.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm64/kvm/hyp/vhe/switch.c +7 -0
@@ -193,6 +193,13 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu)if (!arm64_kernel_unmapped_at_el0 ()) host_vectors =__this_cpu_read (this_cpu_vector);write_sysreg (host_vectors, vbar_el1); + +/* +* We're now able to take MTE exceptions, make sure the VBAR_EL2 is +* set to the correct value. +*/ +if (mte_disable_tco_entry (current)) +isb (); }NOKPROBE_SYMBOL (__deactivate_traps);
Signature · 1 line
2.47.3
Hi Marc,
On Mon, 26 Oct 2026 08:23:03 +0000, Marc Zyngier <[email protected]> wrote:
[...]
Tested on QEMU with MTE, on a VHE host with KASAN_HW_TAGS: a debug print right after the guest run returns shows TCO set without the series and clear with it. Guests also boot on nVHE and pKVM hosts (as normal).
For the series:
Cheers,
/fuad
Quoted 12 lines · Marc Zyngier
Upton taking an exception, the CPU sets PSTATE.TCO to ensure that no tag fault can be taken while handling the exception. It is SW's job to eventually clear it when it is safe to do so.
It appears that when MTE is enabled and that the kernel is running VHE, nothing eventually clears TCO when we come back from the guest, so things such as
KASAN_HW_TAGSwill not work until the next exit to userspace.This series aims at fixing this. This is not a stable candidate, as KASAN is only a debug option.
Quoted 8 lines
Marc Zyngier (2):
arm64: Add return value tomte_disable_tco_entry()
KVM: arm64: Reenable MTE tag checking on exit from guest when running
VHEarch/arm64/include/asm/mte.h | 10 +++++++--- arch/arm64/kvm/hyp/vhe/switch.c | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-)
For both patches:
Quoted 10 lines · Marc Zyngier
Upton taking an exception, the CPU sets PSTATE.TCO to ensure that no tag fault can be taken while handling the exception. It is SW's job to eventually clear it when it is safe to do so.
It appears that when MTE is enabled and that the kernel is running VHE, nothing eventually clears TCO when we come back from the guest, so things such as
KASAN_HW_TAGSwill not work until the next exit to userspace.[...]
Applied to fixes, thanks!
[1/2] arm64: Add return value to mte_disable_tco_entry()
commit: 09436ffe8f1b396c6446eda12798e46f82fed48c
[2/2] KVM: arm64: Reenable MTE tag checking on exit from guest when running VHE
commit: 491fe17530d662a7e6c6b4d139d950dfa0e3a210Cheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.