Skip to content

Commit 7ae2f3d

Browse files
author
Marc Zyngier
committed
KVM: arm64: Flush the instruction cache if not unmapping the VM on reboot
On a system with FWB, we don't need to unmap Stage-2 on reboot, as even if userspace takes this opportunity to repaint the whole of memory, FWB ensures that the data side stays consistent even if the guest uses non-cacheable mappings. However, the I-side is not necessarily coherent with the D-side if CTR_EL0.DIC is 0. In this case, invalidate the i-cache to preserve coherency. Reported-by: Alexandru Elisei <[email protected]> Reviewed-by: Alexandru Elisei <[email protected]> Fixes: 892713e ("KVM: arm64: Sidestep stage2_unmap_vm() on vcpu reset when S2FWB is supported") Signed-off-by: Marc Zyngier <[email protected]>
1 parent 8f7f4fe commit 7ae2f3d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

arch/arm64/kvm/arm.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -989,11 +989,17 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
989989
* Ensure a rebooted VM will fault in RAM pages and detect if the
990990
* guest MMU is turned off and flush the caches as needed.
991991
*
992-
* S2FWB enforces all memory accesses to RAM being cacheable, we
993-
* ensure that the cache is always coherent.
992+
* S2FWB enforces all memory accesses to RAM being cacheable,
993+
* ensuring that the data side is always coherent. We still
994+
* need to invalidate the I-cache though, as FWB does *not*
995+
* imply CTR_EL0.DIC.
994996
*/
995-
if (vcpu->arch.has_run_once && !cpus_have_const_cap(ARM64_HAS_STAGE2_FWB))
996-
stage2_unmap_vm(vcpu->kvm);
997+
if (vcpu->arch.has_run_once) {
998+
if (!cpus_have_final_cap(ARM64_HAS_STAGE2_FWB))
999+
stage2_unmap_vm(vcpu->kvm);
1000+
else
1001+
__flush_icache_all();
1002+
}
9971003

9981004
vcpu_reset_hcr(vcpu);
9991005

0 commit comments

Comments
 (0)