FAILED: patch "[PATCH] KVM: arm64: Remove VM-wide VNCR mapping counter" failed to apply to 6.18-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x c55bc773b6e814406658fae7dc5c15f639ed816e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090950-contact-impatient-f4fb@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From c55bc773b6e814406658fae7dc5c15f639ed816e Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Thu, 6 Aug 2026 10:10:19 +0100
Subject: [PATCH] KVM: arm64: Remove VM-wide VNCR mapping counter
The global VNCR mapping counter is used to decide whether an L1 provided VNCR page is mapped in L0 on any CPU at the point of dealing with a TLB invalidation. It is incremented when a mapping is made in the fixmap, and decremented when unmapped.
As it turns out, this tracking has several flaws:
- we are trying to invalidate TLBs, and the mapping is only an opportunistic consequence of the TLB. Checking this counter to decide whether a TLB needs to be invalidated may result in missed invalidations.
- an L1 vcpu invalidating its own TLB (a very likely case) will not succeed in invalidating the VNCR pseudo TLB because that page is not mapped in L0 at this stage.
Given that this tracking fails at delivering the minimum guarantees that are required and is only a performance optimisation, remove it completely.
arch/arm64/include/asm/kvm_host.h +0 -3
@@ -411,9 +411,6 @@ struct kvm_arch {/* Masks for VNCR-backed and general EL2 sysregs */ struct kvm_sysreg_masks *sysreg_masks; -/* Count the number of VNCR_EL2 currently mapped */ -atomic_t vncr_map_count; -/* * For an untrusted host VM, 'pkvm.handle' is used to lookup * the associated pKVM instance in the hypervisor.
arch/arm64/kvm/hyp/vhe/switch.c +1 -2
@@ -427,8 +427,7 @@ static bool kvm_hyp_handle_tlbi_el2(struct kvm_vcpu *vcpu, u64 *exit_code)* If we have to check for any VNCR mapping being invalidated, * go back to the slow path for further processing. */ -if (vcpu_el2_e2h_is_set (vcpu) &&vcpu_el2_tge_is_set (vcpu) && -atomic_read (&vcpu->kvm->arch.vncr_map_count)) +if (vcpu_el2_e2h_is_set (vcpu) &&vcpu_el2_tge_is_set (vcpu))return false;__kvm_skip_instr (vcpu);
arch/arm64/kvm/nested.c +0 -3
@@ -48,7 +48,6 @@ void kvm_init_nested(struct kvm *kvm) { kvm->arch.nested_mmus =NULL ; kvm->arch.nested_mmus_size =0 ; -atomic_set (&kvm->arch.vncr_map_count,0 ); }static int init_nested_s2_mmu (struct kvm *kvm,struct kvm_s2_mmu *mmu)
@@ -890,7 +889,6 @@ static void this_cpu_reset_vncr_fixmap(struct kvm_vcpu *vcpu)clear_fixmap (vncr_fixmap (vcpu->arch.vncr_tlb->cpu)); vcpu->arch.vncr_tlb->cpu =-1 ;host_data_clear_flag (L1_VNCR_MAPPED ); -atomic_dec (&vcpu->kvm->arch.vncr_map_count); }void kvm_vcpu_put_hw_mmu (struct kvm_vcpu *vcpu)
@@ -1592,7 +1590,6 @@ static void kvm_map_l1_vncr(struct kvm_vcpu *vcpu)if (pgprot_val (prot) !=pgprot_val (PAGE_NONE )) {__set_fixmap (vncr_fixmap (vt->cpu), vt->hpa, prot);host_data_set_flag (L1_VNCR_MAPPED ); -atomic_inc (&vcpu->kvm->arch.vncr_map_count); } }
Sasha Levin
maintainerPATCH 1/2 KVM: arm64: nv: Fully update VNCR fixmap state in kvm_translate_vncr()
From: Oliver Upton <[email protected]>
[ Upstream commit 5949004d7032767e8fde1e8c986a33f241b2a192 ]
kvm_translate_vncr() first invalidates the pseudo-TLB entry and corresponding fixmap in anticipation of installing a new translation.
While the fixmap invalidation does clear the mapping from host stage-1, it does not clear the L1_VNCR_MAPPED flag. Depending on the state of the VNCR TLB at vcpu_put(), this could potentially precipitate a BUG_ON() if vt->cpu is reset.
Share a helper with kvm_vcpu_put_hw_mmu(), ensuring that KVM's view of the VNCR fixmap is in sync with the state of the VNCR TLB. Give it a slightly verbose name to make it obvious that it is meant to be used local to a CPU, unlike other VNCR TLB maintenance.
Stable-dep-of: c55bc773b6e8 ("KVM: arm64: Remove VM-wide VNCR mapping counter")
--- arch/arm64/kvm/nested.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
arch/arm64/kvm/nested.c +17 -10
@@ -771,18 +771,24 @@ void kvm_vcpu_load_hw_mmu(struct kvm_vcpu *vcpu) } } +static void this_cpu_reset_vncr_fixmap (struct kvm_vcpu *vcpu) +{ +if (!host_data_test_flag (L1_VNCR_MAPPED )) +return ; + +BUG_ON (vcpu->arch.vncr_tlb->cpu !=smp_processor_id ()); +BUG_ON (is_hyp_ctxt (vcpu)); + +clear_fixmap (vncr_fixmap (vcpu->arch.vncr_tlb->cpu)); + vcpu->arch.vncr_tlb->cpu =-1 ; +host_data_clear_flag (L1_VNCR_MAPPED ); +atomic_dec (&vcpu->kvm->arch.vncr_map_count); +} +void kvm_vcpu_put_hw_mmu (struct kvm_vcpu *vcpu) {/* Unconditionally drop the VNCR mapping if we have one */ -if (host_data_test_flag (L1_VNCR_MAPPED )) { -BUG_ON (vcpu->arch.vncr_tlb->cpu !=smp_processor_id ()); -BUG_ON (is_hyp_ctxt (vcpu)); - -clear_fixmap (vncr_fixmap (vcpu->arch.vncr_tlb->cpu)); - vcpu->arch.vncr_tlb->cpu =-1 ; -host_data_clear_flag (L1_VNCR_MAPPED ); -atomic_dec (&vcpu->kvm->arch.vncr_map_count); - } +this_cpu_reset_vncr_fixmap (vcpu);/* * Keep a reference on the associated stage-2 MMU if the vCPU is
@@ -1244,7 +1250,8 @@ static int kvm_translate_vncr(struct kvm_vcpu *vcpu, bool *is_gmem)* We also prepare the next walk wilst we're at it. */ scoped_guard(write_lock, &vcpu->kvm->mmu_lock) { -invalidate_vncr (vt); +this_cpu_reset_vncr_fixmap (vcpu); + vt->valid = false; vt->wi = (struct s1_walk_info ) { .regime =TR_EL20 ,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 KVM: arm64: Remove VM-wide VNCR mapping counter
From: Marc Zyngier <[email protected]>
[ Upstream commit c55bc773b6e814406658fae7dc5c15f639ed816e ]
The global VNCR mapping counter is used to decide whether an L1 provided VNCR page is mapped in L0 on any CPU at the point of dealing with a TLB invalidation. It is incremented when a mapping is made in the fixmap, and decremented when unmapped.
As it turns out, this tracking has several flaws:
- we are trying to invalidate TLBs, and the mapping is only an opportunistic consequence of the TLB. Checking this counter to decide whether a TLB needs to be invalidated may result in missed invalidations.
- an L1 vcpu invalidating its own TLB (a very likely case) will not succeed in invalidating the VNCR pseudo TLB because that page is not mapped in L0 at this stage.
Given that this tracking fails at delivering the minimum guarantees that are required and is only a performance optimisation, remove it completely.
--- arch/arm64/include/asm/kvm_host.h | 3 --- arch/arm64/kvm/hyp/vhe/switch.c | 3 +-- arch/arm64/kvm/nested.c | 3 --- 3 files changed, 1 insertion(+), 8 deletions(-)
arch/arm64/include/asm/kvm_host.h +0 -3
@@ -397,9 +397,6 @@ struct kvm_arch {/* Masks for VNCR-backed and general EL2 sysregs */ struct kvm_sysreg_masks *sysreg_masks; -/* Count the number of VNCR_EL2 currently mapped */ -atomic_t vncr_map_count; -/* * For an untrusted host VM, 'pkvm.handle' is used to lookup * the associated pKVM instance in the hypervisor.
arch/arm64/kvm/hyp/vhe/switch.c +1 -2
@@ -427,8 +427,7 @@ static bool kvm_hyp_handle_tlbi_el2(struct kvm_vcpu *vcpu, u64 *exit_code)* If we have to check for any VNCR mapping being invalidated, * go back to the slow path for further processing. */ -if (vcpu_el2_e2h_is_set (vcpu) &&vcpu_el2_tge_is_set (vcpu) && -atomic_read (&vcpu->kvm->arch.vncr_map_count)) +if (vcpu_el2_e2h_is_set (vcpu) &&vcpu_el2_tge_is_set (vcpu))return false;__kvm_skip_instr (vcpu);
arch/arm64/kvm/nested.c +0 -3
@@ -48,7 +48,6 @@ void kvm_init_nested(struct kvm *kvm) { kvm->arch.nested_mmus =NULL ; kvm->arch.nested_mmus_size =0 ; -atomic_set (&kvm->arch.vncr_map_count,0 ); }static int init_nested_s2_mmu (struct kvm *kvm,struct kvm_s2_mmu *mmu)
@@ -782,7 +781,6 @@ static void this_cpu_reset_vncr_fixmap(struct kvm_vcpu *vcpu)clear_fixmap (vncr_fixmap (vcpu->arch.vncr_tlb->cpu)); vcpu->arch.vncr_tlb->cpu =-1 ;host_data_clear_flag (L1_VNCR_MAPPED ); -atomic_dec (&vcpu->kvm->arch.vncr_map_count); }void kvm_vcpu_put_hw_mmu (struct kvm_vcpu *vcpu)
@@ -1470,7 +1468,6 @@ static void kvm_map_l1_vncr(struct kvm_vcpu *vcpu)if (pgprot_val (prot) !=pgprot_val (PAGE_NONE )) {__set_fixmap (vncr_fixmap (vt->cpu), vt->hpa, prot);host_data_set_flag (L1_VNCR_MAPPED ); -atomic_inc (&vcpu->kvm->arch.vncr_map_count); } }
Signature · 1 line
2.53.0