int bit, loops;
        u64 status;
        int handled;
+       int pmu_enabled;
 
        cpuc = this_cpu_ptr(&cpu_hw_events);
 
+       /*
+        * Save the PMU state.
+        * It needs to be restored when leaving the handler.
+        */
+       pmu_enabled = cpuc->enabled;
        /*
         * No known reason to not always do late ACK,
         * but just in case do it opt-in.
        if (!x86_pmu.late_ack)
                apic_write(APIC_LVTPC, APIC_DM_NMI);
        intel_bts_disable_local();
+       cpuc->enabled = 0;
        __intel_pmu_disable_all();
        handled = intel_pmu_drain_bts_buffer();
        handled += intel_bts_interrupt();
 
 done:
        /* Only restore PMU state when it's active. See x86_pmu_disable(). */
-       if (cpuc->enabled)
+       cpuc->enabled = pmu_enabled;
+       if (pmu_enabled)
                __intel_pmu_enable_all(0, true);
        intel_bts_enable_local();