Skip to content

Commit 5eba523

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Reload stage-2 for VMID change on VHE
Naturally, a change to the VMID for an MMU implies a new value for VTTBR. Reload on VMID change in anticipation of loading stage-2 on vcpu_load() instead of every guest entry. Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 4288ff7 commit 5eba523

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ int kvm_arm_pvtime_has_attr(struct kvm_vcpu *vcpu,
10251025
extern unsigned int __ro_after_init kvm_arm_vmid_bits;
10261026
int __init kvm_arm_vmid_alloc_init(void);
10271027
void __init kvm_arm_vmid_alloc_free(void);
1028-
void kvm_arm_vmid_update(struct kvm_vmid *kvm_vmid);
1028+
bool kvm_arm_vmid_update(struct kvm_vmid *kvm_vmid);
10291029
void kvm_arm_vmid_clear_active(void);
10301030

10311031
static inline void kvm_arm_pvtime_vcpu_init(struct kvm_vcpu_arch *vcpu_arch)

arch/arm64/kvm/arm.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,10 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
950950
* making a thread's VMID inactive. So we need to call
951951
* kvm_arm_vmid_update() in non-premptible context.
952952
*/
953-
kvm_arm_vmid_update(&vcpu->arch.hw_mmu->vmid);
953+
if (kvm_arm_vmid_update(&vcpu->arch.hw_mmu->vmid) &&
954+
has_vhe())
955+
__load_stage2(vcpu->arch.hw_mmu,
956+
vcpu->arch.hw_mmu->arch);
954957

955958
kvm_pmu_flush_hwstate(vcpu);
956959

arch/arm64/kvm/vmid.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ void kvm_arm_vmid_clear_active(void)
135135
atomic64_set(this_cpu_ptr(&active_vmids), VMID_ACTIVE_INVALID);
136136
}
137137

138-
void kvm_arm_vmid_update(struct kvm_vmid *kvm_vmid)
138+
bool kvm_arm_vmid_update(struct kvm_vmid *kvm_vmid)
139139
{
140140
unsigned long flags;
141141
u64 vmid, old_active_vmid;
142+
bool updated = false;
142143

143144
vmid = atomic64_read(&kvm_vmid->id);
144145

@@ -156,17 +157,21 @@ void kvm_arm_vmid_update(struct kvm_vmid *kvm_vmid)
156157
if (old_active_vmid != 0 && vmid_gen_match(vmid) &&
157158
0 != atomic64_cmpxchg_relaxed(this_cpu_ptr(&active_vmids),
158159
old_active_vmid, vmid))
159-
return;
160+
return false;
160161

161162
raw_spin_lock_irqsave(&cpu_vmid_lock, flags);
162163

163164
/* Check that our VMID belongs to the current generation. */
164165
vmid = atomic64_read(&kvm_vmid->id);
165-
if (!vmid_gen_match(vmid))
166+
if (!vmid_gen_match(vmid)) {
166167
vmid = new_vmid(kvm_vmid);
168+
updated = true;
169+
}
167170

168171
atomic64_set(this_cpu_ptr(&active_vmids), vmid);
169172
raw_spin_unlock_irqrestore(&cpu_vmid_lock, flags);
173+
174+
return updated;
170175
}
171176

172177
/*

0 commit comments

Comments
 (0)