diff mbox series

[SRU,Artful,Bionic,1/1] KVM: PPC: Book3S HV: Fix guest time accounting with VIRT_CPU_ACCOUNTING_GEN

Message ID 4192d04a830ee542c5d6c4e6dbe2f66a7f444c23.1521142210.git.joseph.salisbury@canonical.com
State New
Headers show
Series KVM: PPC: Book3S HV: Fix guest time accounting with VIRT_CPU_ACCOUNTING_GEN | expand

Commit Message

Joseph Salisbury March 23, 2018, 8:03 p.m. UTC
From: Laurent Vivier <lvivier@redhat.com>

BugLink: http://bugs.launchpad.net/bugs/1755979

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, call guest_enter_irqoff()
instead.

Fixes: 8b24e69fc47e ("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>
(cherry picked from commit 61bd0f66ff92d5ce765ff9850fd3cbfec773c560)
Signed-off-by: Joseph Salisbury <joseph.salisbury@canonical.com>
---
 arch/powerpc/kvm/book3s_hv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Thadeu Lima de Souza Cascardo March 27, 2018, 5:27 p.m. UTC | #1
Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>

Applied to bionic master-next branches.

Thanks.
Cascardo.

Applied-to: bionic/master-next
Stefan Bader March 28, 2018, 12:27 p.m. UTC | #2
On 23.03.2018 21:03, Joseph Salisbury wrote:
> From: Laurent Vivier <lvivier@redhat.com>
> 
> BugLink: http://bugs.launchpad.net/bugs/1755979
> 
> 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, call guest_enter_irqoff()
> instead.
> 
> Fixes: 8b24e69fc47e ("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>
> (cherry picked from commit 61bd0f66ff92d5ce765ff9850fd3cbfec773c560)
> Signed-off-by: Joseph Salisbury <joseph.salisbury@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>

> ---
>  arch/powerpc/kvm/book3s_hv.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 6c402f6..a532743 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -2875,7 +2875,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);
>  
> @@ -2883,8 +2883,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);
>  
> @@ -2927,6 +2925,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) {
>
diff mbox series

Patch

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 6c402f6..a532743 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2875,7 +2875,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);
 
@@ -2883,8 +2883,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);
 
@@ -2927,6 +2925,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) {