Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm/arm64: KVM: Reset the HCR on each vcpu when resetting the vcpu

When userspace resets the vcpu using KVM_ARM_VCPU_INIT, we should also
reset the HCR, because we now modify the HCR dynamically to
enable/disable trapping of guest accesses to the VM registers.

This is crucial for reboot of VMs working since otherwise we will not be
doing the necessary cache maintenance operations when faulting in pages
with the guest MMU off.

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>

+12 -2
+5
arch/arm/include/asm/kvm_emulate.h
··· 33 33 void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr); 34 34 void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr); 35 35 36 + static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu) 37 + { 38 + vcpu->arch.hcr = HCR_GUEST_MASK; 39 + } 40 + 36 41 static inline bool vcpu_mode_is_32bit(struct kvm_vcpu *vcpu) 37 42 { 38 43 return 1;
+2
arch/arm/kvm/arm.c
··· 658 658 if (ret) 659 659 return ret; 660 660 661 + vcpu_reset_hcr(vcpu); 662 + 661 663 /* 662 664 * Handle the "start in power-off" case by marking the VCPU as paused. 663 665 */
-1
arch/arm/kvm/guest.c
··· 38 38 39 39 int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) 40 40 { 41 - vcpu->arch.hcr = HCR_GUEST_MASK; 42 41 return 0; 43 42 } 44 43
+5
arch/arm64/include/asm/kvm_emulate.h
··· 38 38 void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr); 39 39 void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr); 40 40 41 + static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu) 42 + { 43 + vcpu->arch.hcr_el2 = HCR_GUEST_FLAGS; 44 + } 45 + 41 46 static inline unsigned long *vcpu_pc(const struct kvm_vcpu *vcpu) 42 47 { 43 48 return (unsigned long *)&vcpu_gp_regs(vcpu)->regs.pc;
-1
arch/arm64/kvm/guest.c
··· 38 38 39 39 int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) 40 40 { 41 - vcpu->arch.hcr_el2 = HCR_GUEST_FLAGS; 42 41 return 0; 43 42 } 44 43