public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: Fix a stall when KVM_SET_MSRS is called on the pmu counters
@ 2022-10-28 13:00 Aaron Lewis
  2022-10-28 16:26 ` Sean Christopherson
  0 siblings, 1 reply; 9+ messages in thread
From: Aaron Lewis @ 2022-10-28 13:00 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, jmattson, seanjc, Aaron Lewis

When the host initiates a wrmsr through KVM_SET_MSRS don't print an
error if the PMU is disabled, doing so can cause a noticeable stall
while printing the error message.

The profile below was taken while calling KVM_SET_MSRS on the pmu
counters while the PMU was disabled in KVM.  Even though the print is
rate limited it still manages to consume by far the majority of the
time.

-   99.75%     0.00%  [.] __ioctl
   - __ioctl
      - 99.74% entry_SYSCALL_64_after_hwframe
           do_syscall_64
           sys_ioctl
         - do_vfs_ioctl
            - 92.48% kvm_vcpu_ioctl
               - kvm_arch_vcpu_ioctl
                  - 85.12% kvm_set_msr_ignored_check
                       svm_set_msr
                       kvm_set_msr_common
                       printk
                       vprintk_func
                       vprintk_default
                       vprintk_emit
                       console_unlock
                       call_console_drivers
                       univ8250_console_write
                       serial8250_console_write
                       uart_console_write

A stall in this situation could have an impact on live migration.  So,
to avoid that disable the print if the write is initiated by the host.

Fixes: 5753785fa977 ("KVM: do not #GP on perf MSR writes when vPMU is disabled")
Signed-off-by: Aaron Lewis <aaronlewis@google.com>
---
 arch/x86/kvm/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 9cf1ba865562..a3b842467bd2 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3778,7 +3778,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 
 	case MSR_K7_PERFCTR0 ... MSR_K7_PERFCTR3:
 	case MSR_P6_PERFCTR0 ... MSR_P6_PERFCTR1:
-		pr = true;
+		pr = !msr_info->host_initiated;
 		fallthrough;
 	case MSR_K7_EVNTSEL0 ... MSR_K7_EVNTSEL3:
 	case MSR_P6_EVNTSEL0 ... MSR_P6_EVNTSEL1:
-- 
2.38.1.273.g43a17bfeac-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-11-02 23:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-28 13:00 [PATCH] KVM: x86: Fix a stall when KVM_SET_MSRS is called on the pmu counters Aaron Lewis
2022-10-28 16:26 ` Sean Christopherson
2022-10-28 20:47   ` Aaron Lewis
2022-10-28 21:50     ` Sean Christopherson
2022-10-28 22:01       ` Jim Mattson
2022-10-28 22:43         ` Sean Christopherson
2022-11-02 17:55           ` Paolo Bonzini
2022-11-02 23:15             ` Aaron Lewis
2022-10-29  0:34       ` Aaron Lewis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox