]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: PPC: Book3S HV: Update guest state entry/exit accounting to new API
authorNicholas Piggin <npiggin@gmail.com>
Thu, 8 Sep 2022 13:25:43 +0000 (23:25 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 27 Sep 2022 15:07:19 +0000 (01:07 +1000)
Update the guest state and timing entry/exit accounting to use the new
API, which was introduced following issues found[1]. KVM HV does
possibly call instrumented code inside the guest context, and it does
call srcu inside the guest context which is fragile at best.

Switch to the new API, moving the guest context inside the
srcu_read_lock/unlock region.

[1] https://lore.kernel.org/lkml/20220201132926.3301912-1-mark.rutland@arm.com/

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220908132545.4085849-3-npiggin@gmail.com
arch/powerpc/kvm/book3s_hv.c

index 0f8dee6573364134a02ea793d6b4c77305ba08b0..23bcda3585fe0cd69b5e9546fcd47e25383d93f3 100644 (file)
@@ -3854,23 +3854,17 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
        for (sub = 0; sub < core_info.n_subcores; ++sub)
                spin_unlock(&core_info.vc[sub]->lock);
 
-       guest_enter_irqoff();
+       guest_timing_enter_irqoff();
 
        srcu_idx = srcu_read_lock(&vc->kvm->srcu);
 
+       guest_state_enter_irqoff();
        this_cpu_disable_ftrace();
 
-       /*
-        * Interrupts will be enabled once we get into the guest,
-        * so tell lockdep that we're about to enable interrupts.
-        */
-       trace_hardirqs_on();
-
        trap = __kvmppc_vcore_entry();
 
-       trace_hardirqs_off();
-
        this_cpu_enable_ftrace();
+       guest_state_exit_irqoff();
 
        srcu_read_unlock(&vc->kvm->srcu, srcu_idx);
 
@@ -3905,11 +3899,10 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
 
        kvmppc_set_host_core(pcpu);
 
-       context_tracking_guest_exit();
        if (!vtime_accounting_enabled_this_cpu()) {
                local_irq_enable();
                /*
-                * Service IRQs here before vtime_account_guest_exit() so any
+                * Service IRQs here before guest_timing_exit_irqoff() so any
                 * ticks that occurred while running the guest are accounted to
                 * the guest. If vtime accounting is enabled, accounting uses
                 * TB rather than ticks, so it can be done without enabling
@@ -3918,7 +3911,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
                 */
                local_irq_disable();
        }
-       vtime_account_guest_exit();
+       guest_timing_exit_irqoff();
 
        local_irq_enable();
 
@@ -4609,21 +4602,18 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,
 
        trace_kvm_guest_enter(vcpu);
 
-       guest_enter_irqoff();
+       guest_timing_enter_irqoff();
 
        srcu_idx = srcu_read_lock(&kvm->srcu);
 
+       guest_state_enter_irqoff();
        this_cpu_disable_ftrace();
 
-       /* Tell lockdep that we're about to enable interrupts */
-       trace_hardirqs_on();
-
        trap = kvmhv_p9_guest_entry(vcpu, time_limit, lpcr, &tb);
        vcpu->arch.trap = trap;
 
-       trace_hardirqs_off();
-
        this_cpu_enable_ftrace();
+       guest_state_exit_irqoff();
 
        srcu_read_unlock(&kvm->srcu, srcu_idx);
 
@@ -4632,11 +4622,10 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,
        vcpu->cpu = -1;
        vcpu->arch.thread_cpu = -1;
 
-       context_tracking_guest_exit();
        if (!vtime_accounting_enabled_this_cpu()) {
                powerpc_local_irq_pmu_restore(flags);
                /*
-                * Service IRQs here before vtime_account_guest_exit() so any
+                * Service IRQs here before guest_timing_exit_irqoff() so any
                 * ticks that occurred while running the guest are accounted to
                 * the guest. If vtime accounting is enabled, accounting uses
                 * TB rather than ticks, so it can be done without enabling
@@ -4645,7 +4634,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,
                 */
                powerpc_local_irq_pmu_save(flags);
        }
-       vtime_account_guest_exit();
+       guest_timing_exit_irqoff();
 
        powerpc_local_irq_pmu_restore(flags);