Skip to content

Commit ceab52b

Browse files
James Hogangregkh
authored andcommitted
KVM: MIPS: Disable HTW while in guest
commit c4c6f2c upstream. Ensure any hardware page table walker (HTW) is disabled while in KVM guest mode, as KVM doesn't yet set up hardware page table walking for guest mappings so the wrong mappings would get loaded, resulting in the guest hanging or crashing once it reaches userland. The HTW is disabled and re-enabled around the call to __kvm_mips_vcpu_run() which does the initial switch into guest mode and the final switch out of guest context. Additionally it is enabled for the duration of guest exits (i.e. kvm_mips_handle_exit()), getting disabled again before returning back to guest or host. In all cases the HTW is only disabled in normal kernel mode while interrupts are disabled, so that the HTW doesn't get left disabled if the process is preempted. Signed-off-by: James Hogan <james.hogan@imgtec.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Markos Chandras <markos.chandras@imgtec.com> Cc: Gleb Natapov <gleb@kernel.org> Cc: kvm@vger.kernel.org Cc: linux-mips@linux-mips.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4a73309 commit ceab52b

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎arch/mips/kvm/mips.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <asm/page.h>
1919
#include <asm/cacheflush.h>
2020
#include <asm/mmu_context.h>
21+
#include <asm/pgtable.h>
2122

2223
#include <linux/kvm_host.h>
2324

@@ -385,8 +386,14 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
385386

386387
kvm_guest_enter();
387388

389+
/* Disable hardware page table walking while in guest */
390+
htw_stop();
391+
388392
r = __kvm_mips_vcpu_run(run, vcpu);
389393

394+
/* Re-enable HTW before enabling interrupts */
395+
htw_start();
396+
390397
kvm_guest_exit();
391398
local_irq_enable();
392399

@@ -1002,6 +1009,9 @@ int kvm_mips_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
10021009
enum emulation_result er = EMULATE_DONE;
10031010
int ret = RESUME_GUEST;
10041011

1012+
/* re-enable HTW before enabling interrupts */
1013+
htw_start();
1014+
10051015
/* Set a default exit reason */
10061016
run->exit_reason = KVM_EXIT_UNKNOWN;
10071017
run->ready_for_interrupt_injection = 1;
@@ -1136,6 +1146,9 @@ int kvm_mips_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
11361146
}
11371147
}
11381148

1149+
/* Disable HTW before returning to guest or host */
1150+
htw_stop();
1151+
11391152
return ret;
11401153
}
11411154

0 commit comments

Comments
 (0)