mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nadav Amit <namit@cs.technion.ac.il>
To: gleb@kernel.org, pbonzini@redhat.com
Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
	x86@kernel.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Nadav Amit <namit@cs.technion.ac.il>
Subject: [PATCH 1/5] KVM: x86: Fix wrong/stuck PMU when guest does not use PMI
Date: Fri, 18 Apr 2014 03:35:08 +0300	[thread overview]
Message-ID: <1397781312-6885-1-git-send-email-namit@cs.technion.ac.il> (raw)
In-Reply-To: <1397777591-6147-1-git-send-email-namit@cs.technion.ac.il>

If a guest enables a performance counter but does not enable PMI, the
hypervisor currently does not reprogram the performance counter once it
overflows.  As a result the host performance counter is kept with the original
sampling period which was configured according to the value of the guest's
counter when the counter was enabled.

Such behaviour can cause very bad consequences. The most distrubing one can
cause the guest not to make any progress at all, and keep exiting due to host
PMI before any guest instructions is exeucted. This situation occurs when the
performance counter holds a very high value when the guest enables the
performance counter. As a result the host's sampling period is configured to be
very short. The host then never reconfigures the sampling period and get stuck
at entry->PMI->exit loop. We encountered such a scenario in our experiments.

The solution is to reprogram the counter even if the guest does not use PMI.

Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
---
:100644 100644 5c4f631... cbecaa9... M	arch/x86/kvm/pmu.c
 arch/x86/kvm/pmu.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index 5c4f631..cbecaa9 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -108,7 +108,10 @@ static void kvm_perf_overflow(struct perf_event *perf_event,
 {
 	struct kvm_pmc *pmc = perf_event->overflow_handler_context;
 	struct kvm_pmu *pmu = &pmc->vcpu->arch.pmu;
-	__set_bit(pmc->idx, (unsigned long *)&pmu->global_status);
+	if (!test_and_set_bit(pmc->idx, (unsigned long *)&pmu->reprogram_pmi)) {
+		__set_bit(pmc->idx, (unsigned long *)&pmu->global_status);
+		kvm_make_request(KVM_REQ_PMU, pmc->vcpu);
+	}
 }
 
 static void kvm_perf_overflow_intr(struct perf_event *perf_event,
@@ -117,7 +120,7 @@ static void kvm_perf_overflow_intr(struct perf_event *perf_event,
 	struct kvm_pmc *pmc = perf_event->overflow_handler_context;
 	struct kvm_pmu *pmu = &pmc->vcpu->arch.pmu;
 	if (!test_and_set_bit(pmc->idx, (unsigned long *)&pmu->reprogram_pmi)) {
-		kvm_perf_overflow(perf_event, data, regs);
+		__set_bit(pmc->idx, (unsigned long *)&pmu->global_status);
 		kvm_make_request(KVM_REQ_PMU, pmc->vcpu);
 		/*
 		 * Inject PMI. If vcpu was in a guest mode during NMI PMI
-- 
1.7.10.4


  reply	other threads:[~2014-04-18  0:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-17 23:33 [PATCH 0/5] KVM: x86: Fix KVM behavior that does not follow spec Nadav Amit
2014-04-18  0:35 ` Nadav Amit [this message]
2014-04-18  0:35   ` [PATCH 2/5] KVM: x86: Fix CR3 reserved bits Nadav Amit
2014-05-10  7:13     ` Jan Kiszka
2014-05-10  7:24       ` [PATCH] KVM: x86: Fix CR3 reserved bits check in long mode Jan Kiszka
2014-05-12 10:46         ` Paolo Bonzini
2014-04-18  0:35   ` [PATCH 3/5] KVM: x86: IN instruction emulation should ignore REP-prefix Nadav Amit
2014-04-18  4:11 ` [PATCH 4/5] KVM: x86: RSI/RDI/RCX are zero-extended when affected by string ops Nadav Amit
2014-04-18  4:11   ` [PATCH 5/5] KVM: x86: Processor mode may be determined incorrectly Nadav Amit
2014-04-20  9:26   ` [PATCH 4/5] KVM: x86: RSI/RDI/RCX are zero-extended when affected by string ops Gleb Natapov
2014-04-22  6:04     ` Nadav Amit
2014-04-23 19:58       ` Marcelo Tosatti
2014-04-23 20:11         ` Marcelo Tosatti
2014-04-23 20:53           ` Nadav Amit
2014-04-23 21:01             ` H. Peter Anvin
2014-04-23 20:47 ` [PATCH 0/5] KVM: x86: Fix KVM behavior that does not follow spec Marcelo Tosatti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1397781312-6885-1-git-send-email-namit@cs.technion.ac.il \
    --to=namit@cs.technion.ac.il \
    --cc=gleb@kernel.org \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®