diff options
author | James Hogan <james.hogan@imgtec.com> | 2016-11-28 17:45:04 -0500 |
---|---|---|
committer | James Hogan <james.hogan@imgtec.com> | 2017-02-03 10:21:08 -0500 |
commit | 4841e0dd4f53c127b11947bdbe4423b5e9014ebc (patch) | |
tree | 20404edba5267e5071f79ec98815430c6cd666a5 | |
parent | 06c158c96ed8909a1d8696d4f953ca8a9ef55574 (diff) |
KVM: MIPS: Update vcpu->mode and vcpu->cpu
Keep the vcpu->mode and vcpu->cpu variables up to date so that
kvm_make_all_cpus_request() has a chance of functioning correctly. This
will soon need to be used for kvm_flush_remote_tlbs().
We can easily update vcpu->cpu when the VCPU context is loaded or saved,
which will happen when accessing guest context and when the guest is
scheduled in and out.
We need to be a little careful with vcpu->mode though, as we will in
future be checking for outstanding VCPU requests, and this must be done
after the value of IN_GUEST_MODE in vcpu->mode is visible to other CPUs.
Otherwise the other CPU could fail to trigger an IPI to wait for
completion dispite the VCPU request not being seen.
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
-rw-r--r-- | arch/mips/kvm/mips.c | 18 | ||||
-rw-r--r-- | arch/mips/kvm/mmu.c | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c index 9b72e2c55a0c..ff5e34293227 100644 --- a/arch/mips/kvm/mips.c +++ b/arch/mips/kvm/mips.c | |||
@@ -365,6 +365,14 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) | |||
365 | guest_enter_irqoff(); | 365 | guest_enter_irqoff(); |
366 | trace_kvm_enter(vcpu); | 366 | trace_kvm_enter(vcpu); |
367 | 367 | ||
368 | /* | ||
369 | * Make sure the read of VCPU requests in vcpu_run() callback is not | ||
370 | * reordered ahead of the write to vcpu->mode, or we could miss a TLB | ||
371 | * flush request while the requester sees the VCPU as outside of guest | ||
372 | * mode and not needing an IPI. | ||
373 | */ | ||
374 | smp_store_mb(vcpu->mode, IN_GUEST_MODE); | ||
375 | |||
368 | r = kvm_mips_callbacks->vcpu_run(run, vcpu); | 376 | r = kvm_mips_callbacks->vcpu_run(run, vcpu); |
369 | 377 | ||
370 | trace_kvm_out(vcpu); | 378 | trace_kvm_out(vcpu); |
@@ -1326,6 +1334,8 @@ int kvm_mips_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu) | |||
1326 | u32 inst; | 1334 | u32 inst; |
1327 | int ret = RESUME_GUEST; | 1335 | int ret = RESUME_GUEST; |
1328 | 1336 | ||
1337 | vcpu->mode = OUTSIDE_GUEST_MODE; | ||
1338 | |||
1329 | /* re-enable HTW before enabling interrupts */ | 1339 | /* re-enable HTW before enabling interrupts */ |
1330 | htw_start(); | 1340 | htw_start(); |
1331 | 1341 | ||
@@ -1481,6 +1491,14 @@ skip_emul: | |||
1481 | if (ret == RESUME_GUEST) { | 1491 | if (ret == RESUME_GUEST) { |
1482 | trace_kvm_reenter(vcpu); | 1492 | trace_kvm_reenter(vcpu); |
1483 | 1493 | ||
1494 | /* | ||
1495 | * Make sure the read of VCPU requests in vcpu_reenter() | ||
1496 | * callback is not reordered ahead of the write to vcpu->mode, | ||
1497 | * or we could miss a TLB flush request while the requester sees | ||
1498 | * the VCPU as outside of guest mode and not needing an IPI. | ||
1499 | */ | ||
1500 | smp_store_mb(vcpu->mode, IN_GUEST_MODE); | ||
1501 | |||
1484 | kvm_mips_callbacks->vcpu_reenter(run, vcpu); | 1502 | kvm_mips_callbacks->vcpu_reenter(run, vcpu); |
1485 | 1503 | ||
1486 | /* | 1504 | /* |
diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c index 09f5da706d9a..e41ee36dd626 100644 --- a/arch/mips/kvm/mmu.c +++ b/arch/mips/kvm/mmu.c | |||
@@ -696,6 +696,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) | |||
696 | 696 | ||
697 | local_irq_save(flags); | 697 | local_irq_save(flags); |
698 | 698 | ||
699 | vcpu->cpu = cpu; | ||
699 | if (vcpu->arch.last_sched_cpu != cpu) { | 700 | if (vcpu->arch.last_sched_cpu != cpu) { |
700 | kvm_debug("[%d->%d]KVM VCPU[%d] switch\n", | 701 | kvm_debug("[%d->%d]KVM VCPU[%d] switch\n", |
701 | vcpu->arch.last_sched_cpu, cpu, vcpu->vcpu_id); | 702 | vcpu->arch.last_sched_cpu, cpu, vcpu->vcpu_id); |
@@ -723,6 +724,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) | |||
723 | 724 | ||
724 | cpu = smp_processor_id(); | 725 | cpu = smp_processor_id(); |
725 | vcpu->arch.last_sched_cpu = cpu; | 726 | vcpu->arch.last_sched_cpu = cpu; |
727 | vcpu->cpu = -1; | ||
726 | 728 | ||
727 | /* save guest state in registers */ | 729 | /* save guest state in registers */ |
728 | kvm_mips_callbacks->vcpu_put(vcpu, cpu); | 730 | kvm_mips_callbacks->vcpu_put(vcpu, cpu); |