Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1570247

[PATCH] KVM: x86: never specify a sample period for virtualized in_tx_cp counters

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From Robert O'Callahan <robert@ocallahan.org>
Newsgroups linux.kernel
Subject [PATCH] KVM: x86: never specify a sample period for virtualized in_tx_cp counters
Date Tue, 31 Jan 2017 03:00:01 +0100
Message-ID <t5vTH-2Xq-1@gated-at.bofh.it> (permalink)
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=abAauH0s7Kx4RSo2v2FYQwzd0nLCs4M2Zwix9mfLBkY=; b=QEZcBnEUo1jrUc6Y2kCqaVhYtZ09ZF2AT1Uh40hr2oBRAPEkjJvKDadA9qbEAKq6aU Z7dLrkKcJhjQCoVxkc8bXopGAYqCkt6wu7T7/YAYgmEewY4txzxxRcGsrpYfW1GZMPpW lNhxqaa5+zhoYXs33wxEmERFohNNXawzve2+Cjy6ci78WzCDI5GPN8chMgVyLG/+9NJZ LJkUGdHMzCGng6yRWMTFvuGBceAl+9DTGs8JPEYGm095RYnjYIE07xRlbpXa6oWXRMPP IlQskj/OZwTmrs/8MoyZVAR428NrSj4aa0gd804Yo0qg1atBH4L1NoDCed2nNLrTWyYQ kAQA==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=abAauH0s7Kx4RSo2v2FYQwzd0nLCs4M2Zwix9mfLBkY=; b=MkbufwOc9e6EoPKdTfe805yFHxk1snM8uot7M0y6gH1JpTfm7R/LWPaiyo0Bwha6ge pRa5cKN2o98LCOAhOJtZxQjYDKduK2XMIddI4Ewo27f2ounlqoaDJeRdAxYZiH9wpp5W YhRNXBGKM62g2xPiS903s1iXNFRc7akLcpERJoxuVgoJIcShMTcca1MfQNUxOSqg8aDo +XWcCk5sYaAQfX5lxlNaE4LGqYZWtlT7Op1+A3DEPLIZOiNgdIwKmVKHdWQWCIYjuK4X 48OlPSUd3RU9nwADDilFgvwRKlQsxCKjs+COVuTaA3yqa8qSqTWbf8FDe6H2fZNwQ+YM gAug==
X-Gm-Message-State AIkVDXK/x8NxlTRPh8QvIHlQwG6KORywIKSSNJJ6UdcEHO1z2jWjO/tcLDuOSnrTOlanGg==
X-Received by 10.84.177.129 with SMTP id x1mr35449309plb.75.1485827309332; Mon, 30 Jan 2017 17:48:29 -0800 (PST)
X-Mailer git-send-email 2.9.3
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 48
Organization linux.* mail to news gateway
X-Original-Cc Paolo Bonzini <pbonzini@redhat.com>, Radim Krčmář <rkrcmar@redhat.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>, x86@kernel.org, linux-kernel@vger.kernel.org, Robert O'Callahan <robert@ocallahan.org>
X-Original-Date Tue, 31 Jan 2017 14:48:13 +1300
X-Original-Message-ID <20170131014813.15220-1-robert@ocallahan.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1570247

Show key headers only | View raw


pmc_reprogram_counter() always sets a sample period based on the value of
pmc->counter. However, hsw_hw_config() rejects sample periods less than
2^31 - 1. So for example, a KVM guest doing
  perf stat -e r2005101c4 sleep 0
will count some conditional branch events, deschedule the task, reschedule
the task, try to restore the guest PMU state for the task, in the host
reach pmc_reprogram_counter() with nonzero pmc->count, trigger EOPNOTSUPP
in hsw_hw_config(), print "kvm_pmu: event creation failed" in
pmc_reprogram_counter(), and silently (from the guest's point of view) stop
counting events.

We fix event counting by forcing attr.sample_period to always be zero for
in_tx_cp counters. Sampling doesn't work, but it already didn't work and
can't be fixed without major changes to the approach in hsw_hw_config().

Signed-off-by: Robert O'Callahan <robert@ocallahan.org>
---
 arch/x86/kvm/pmu.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index 06ce377..af993d7 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -113,12 +113,18 @@ static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type,
 		.config = config,
 	};
 
+	attr.sample_period = (-pmc->counter) & pmc_bitmask(pmc);
+
 	if (in_tx)
 		attr.config |= HSW_IN_TX;
-	if (in_tx_cp)
+	if (in_tx_cp) {
+		/* HSW_IN_TX_CHECKPOINTED is not supported with nonzero
+		 * period. Just clear the sample period so at least
+		 * allocating the counter doesn't fail.
+		 */
+		attr.sample_period = 0;
 		attr.config |= HSW_IN_TX_CHECKPOINTED;
-
-	attr.sample_period = (-pmc->counter) & pmc_bitmask(pmc);
+	}
 
 	event = perf_event_create_kernel_counter(&attr, -1, current,
 						 intr ? kvm_perf_overflow_intr :
-- 
2.9.3

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

[PATCH] KVM: x86: never specify a sample period for virtualized in_tx_cp counters Robert O'Callahan <robert@ocallahan.org> - 2017-01-31 03:00 +0100
  Re: [PATCH] KVM: x86: never specify a sample period for virtualized  in_tx_cp counters Ingo Molnar <mingo@kernel.org> - 2017-01-31 08:40 +0100

csiph-web