Re: [PATCH v4 3/6] KVM: arm64: nv: Add nested revmap broken tracepoint
From: Oliver Upton
Date: Thu Jul 16 2026 - 02:45:22 EST
Hi Wei-Lin,
On Tue, Jul 14, 2026 at 12:59:22PM +0100, Wei-Lin Chang wrote:
> Add a tracepoint to track when a nested reverse map becomes broken. This
> makes it easier to detect NV performance degradation caused by full
> shadow stage-2 unmaps.
>
> Signed-off-by: Wei-Lin Chang <weilin.chang@xxxxxxx>
I'm not too excited about making a tracepoint out of this, especially
since a 'broken' reverse map is more of a KVM implementation detail
(that could change) than anything else.
BPF is quite popular at this point, do you think it's reasonable to
instead expect the curious KVM developer to attach a kprobe and inspect
the state of the nested MMU?
Thanks,
Oliver
> ---
> arch/arm64/kvm/nested.c | 7 ++++++-
> arch/arm64/kvm/trace_arm.h | 27 +++++++++++++++++++++++++++
> 2 files changed, 33 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
> index 065823e415ce..22f8a1daca93 100644
> --- a/arch/arm64/kvm/nested.c
> +++ b/arch/arm64/kvm/nested.c
> @@ -17,6 +17,7 @@
> #include <asm/sysreg.h>
>
> #include "sys_regs.h"
> +#include "trace.h"
>
> struct vncr_tlb {
> /* The guest's VNCR_EL2 */
> @@ -916,8 +917,12 @@ void kvm_record_nested_revmap(gpa_t canonical_ipa, struct kvm_s2_mmu *mmu,
>
> mas_set_range(&mas_rmap, canonical_ipa, canonical_ipa_end);
> if (mas_store_gfp(&mas_rmap, xa_mk_value(new_entry),
> - GFP_NOWAIT | __GFP_ACCOUNT))
> + GFP_NOWAIT | __GFP_ACCOUNT)) {
> + trace_kvm_nested_revmap_broken(mmu - mmu->arch->nested_mmus,
> + canonical_ipa, canonical_ipa_end,
> + nested_ipa, new_entry);
> mmu->nested_revmap_broken = true;
> + }
> unlock:
> mtree_unlock(revmap_mt);
> }
> diff --git a/arch/arm64/kvm/trace_arm.h b/arch/arm64/kvm/trace_arm.h
> index 9c60f6465c78..0db90068ff63 100644
> --- a/arch/arm64/kvm/trace_arm.h
> +++ b/arch/arm64/kvm/trace_arm.h
> @@ -415,6 +415,33 @@ TRACE_EVENT(kvm_forward_sysreg_trap,
> sys_reg_Op2(__entry->sysreg))
> );
>
> +TRACE_EVENT(kvm_nested_revmap_broken,
> + TP_PROTO(int mmu_idx, unsigned long canonical_ipa,
> + unsigned long canonical_ipa_end, unsigned long nested_ipa,
> + unsigned long revmap_entry),
> + TP_ARGS(mmu_idx, canonical_ipa, canonical_ipa_end, nested_ipa, revmap_entry),
> +
> + TP_STRUCT__entry(
> + __field(int, mmu_idx)
> + __field(unsigned long, canonical_ipa)
> + __field(unsigned long, nested_ipa)
> + __field(size_t, size)
> + __field(unsigned long, revmap_entry)
> + ),
> +
> + TP_fast_assign(
> + __entry->mmu_idx = mmu_idx;
> + __entry->canonical_ipa = canonical_ipa;
> + __entry->nested_ipa = nested_ipa;
> + __entry->size = canonical_ipa_end - canonical_ipa + 1;
> + __entry->revmap_entry = revmap_entry;
> + ),
> +
> + TP_printk("mmu idx: %d, cipa: 0x%016lx, nipa: 0x%016lx, size: 0x%016lx, entry: %016lx",
> + __entry->mmu_idx, __entry->canonical_ipa, __entry->nested_ipa,
> + __entry->size, __entry->revmap_entry)
> +);
> +
> #endif /* _TRACE_ARM_ARM64_KVM_H */
>
> #undef TRACE_INCLUDE_PATH
> --
> 2.43.0
>