Skip to contentSkip to conversation

KVM: PPC: Book3S HV: Fix guest time accounting with VIRT_CPU_ACCOUNTING_GEN

PATCH Applied Laurent Vivier 3 participants 3 messages Mar 2, 2018 – Mar 4, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: PPC: Book3S HV: Fix guest time accounting with VIRT_CPU_ACCOUNTING_GEN

Since commit 8b24e69fc47e ("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, calls guest_enter_irqoff() instead.

Fixes 8b24e69fc47e

("KVM: PPC: Book3S HV: Close race with testing for signals on guest entry")

---
 arch/powerpc/kvm/book3s_hv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/powerpc/kvm/book3s_hv.c +2 -3
index 89707354c2ef..8274c2807202 100644
@@ -2885,7 +2885,7 @@ 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);
 
@@ -2893,8 +2893,6 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
 
 	srcu_read_unlock(&vc->kvm->srcu, srcu_idx);
 
-	guest_exit();
-
 	trace_hardirqs_off();
 	set_irq_happened(trap);
 
@@ -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) {
Signature · 1 line
2.14.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Laurent Vivier

Since commit 8b24e69fc47e ("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.

Quoted 7 lines

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

Fixes 8b24e69fc47e

("KVM: PPC: Book3S HV: Close race with testing for signals on guest entry")

Quoted 35 lines
---
 arch/powerpc/kvm/book3s_hv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/powerpc/kvm/book3s_hv.c +2 -3
index 89707354c2ef..8274c2807202 100644
@@ -2885,7 +2885,7 @@ 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);
 
@@ -2893,8 +2893,6 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
 
 	srcu_read_unlock(&vc->kvm->srcu, srcu_idx);
 
-	guest_exit();
-
 	trace_hardirqs_off();
 	set_irq_happened(trap);
 
@@ -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) {
#2 lore raw
In reply to Laurent Vivier
Quoted 8 lines · Laurent Vivier

Since commit 8b24e69fc47e ("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.

Quoted 7 lines

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

Fixes 8b24e69fc47e

("KVM: PPC: Book3S HV: Close race with testing for signals on guest entry")

Thanks, applied to my kvm-ppc-fixes branch.

Paul.