Skip to content

Commit

Permalink
KVM: PPC: Book3S HV: Fix guest time accounting with VIRT_CPU_ACCOUNTI…
Browse files Browse the repository at this point in the history
…NG_GEN

Since commit 8b24e69 ("KVM: PPC: Book3S HV: Close race with testing
for signals on guest entry"), if CONFIG_VIRT_CPU_ACCOUNTING_GEN is set, the
guest time is not accounted to guest time and user time, but instead to
system time.

This is because guest_enter()/guest_exit() are called while interrupts
are disabled and the tick counter cannot be updated between them.

To fix that, move guest_exit() after local_irq_enable(), and as
guest_enter() is called with IRQ disabled, call guest_enter_irqoff()
instead.

Fixes: 8b24e69 ("KVM: PPC: Book3S HV: Close race with testing for signals on guest entry")
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
  • Loading branch information
Laurent Vivier authored and Paul Mackerras committed Mar 3, 2018
1 parent debd574 commit 61bd0f6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions arch/powerpc/kvm/book3s_hv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2885,16 +2885,14 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
*/
trace_hardirqs_on();

guest_enter();
guest_enter_irqoff();

srcu_idx = srcu_read_lock(&vc->kvm->srcu);

trap = __kvmppc_vcore_entry();

srcu_read_unlock(&vc->kvm->srcu, srcu_idx);

guest_exit();

trace_hardirqs_off();
set_irq_happened(trap);

Expand Down Expand Up @@ -2937,6 +2935,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
kvmppc_set_host_core(pcpu);

local_irq_enable();
guest_exit();

/* Let secondaries go back to the offline loop */
for (i = 0; i < controlled_threads; ++i) {
Expand Down

0 comments on commit 61bd0f6

Please sign in to comment.