Skip to content

Commit b856a59

Browse files
committed
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 <[email protected]> Signed-off-by: Christoffer Dall <[email protected]>
1 parent 3ad8b3d commit b856a59

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed

arch/arm/include/asm/kvm_emulate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ void kvm_inject_undefined(struct kvm_vcpu *vcpu);
3333
void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr);
3434
void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr);
3535

36+
static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
37+
{
38+
vcpu->arch.hcr = HCR_GUEST_MASK;
39+
}
40+
3641
static inline bool vcpu_mode_is_32bit(struct kvm_vcpu *vcpu)
3742
{
3843
return 1;

arch/arm/kvm/arm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,8 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
658658
if (ret)
659659
return ret;
660660

661+
vcpu_reset_hcr(vcpu);
662+
661663
/*
662664
* Handle the "start in power-off" case by marking the VCPU as paused.
663665
*/

arch/arm/kvm/guest.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
3838

3939
int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
4040
{
41-
vcpu->arch.hcr = HCR_GUEST_MASK;
4241
return 0;
4342
}
4443

arch/arm64/include/asm/kvm_emulate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ void kvm_inject_undefined(struct kvm_vcpu *vcpu);
3838
void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr);
3939
void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr);
4040

41+
static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
42+
{
43+
vcpu->arch.hcr_el2 = HCR_GUEST_FLAGS;
44+
}
45+
4146
static inline unsigned long *vcpu_pc(const struct kvm_vcpu *vcpu)
4247
{
4348
return (unsigned long *)&vcpu_gp_regs(vcpu)->regs.pc;

arch/arm64/kvm/guest.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
3838

3939
int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
4040
{
41-
vcpu->arch.hcr_el2 = HCR_GUEST_FLAGS;
4241
return 0;
4342
}
4443

0 commit comments

Comments
 (0)