All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Nadav Amit <nadav.amit@gmail.com>,
	Sasha Levin <sashal@kernel.org>,
	kvm@vger.kernel.org
Subject: [PATCH AUTOSEL 4.9 16/17] KVM: x86/pmu: do not mask the value that is written to fixed PMUs
Date: Tue,  4 Jun 2019 19:24:57 -0400	[thread overview]
Message-ID: <20190604232459.7745-16-sashal@kernel.org> (raw)
In-Reply-To: <20190604232459.7745-1-sashal@kernel.org>

From: Paolo Bonzini <pbonzini@redhat.com>

[ Upstream commit 2924b52117b2812e9633d5ea337333299166d373 ]

According to the SDM, for MSR_IA32_PERFCTR0/1 "the lower-order 32 bits of
each MSR may be written with any value, and the high-order 8 bits are
sign-extended according to the value of bit 31", but the fixed counters
in real hardware are limited to the width of the fixed counters ("bits
beyond the width of the fixed-function counter are reserved and must be
written as zeros").  Fix KVM to do the same.

Reported-by: Nadav Amit <nadav.amit@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 arch/x86/kvm/pmu_intel.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/pmu_intel.c b/arch/x86/kvm/pmu_intel.c
index 5ab4a364348e..2729131fe9bf 100644
--- a/arch/x86/kvm/pmu_intel.c
+++ b/arch/x86/kvm/pmu_intel.c
@@ -235,11 +235,14 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 		}
 		break;
 	default:
-		if ((pmc = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0)) ||
-		    (pmc = get_fixed_pmc(pmu, msr))) {
-			if (!msr_info->host_initiated)
-				data = (s64)(s32)data;
-			pmc->counter += data - pmc_read_counter(pmc);
+		if ((pmc = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0))) {
+			if (msr_info->host_initiated)
+				pmc->counter = data;
+			else
+				pmc->counter = (s32)data;
+			return 0;
+		} else if ((pmc = get_fixed_pmc(pmu, msr))) {
+			pmc->counter = data;
 			return 0;
 		} else if ((pmc = get_gp_pmc(pmu, msr, MSR_P6_EVNTSEL0))) {
 			if (data == pmc->eventsel)
-- 
2.20.1


  parent reply	other threads:[~2019-06-04 23:26 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-04 23:24 [PATCH AUTOSEL 4.9 01/17] x86/uaccess, kcov: Disable stack protector Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 02/17] ALSA: seq: Protect in-kernel ioctl calls with mutex Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 03/17] ALSA: seq: Fix race of get-subscription call vs port-delete ioctls Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 04/17] Revert "ALSA: seq: Protect in-kernel ioctl calls with mutex" Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 05/17] ALSA: seq: Cover unsubscribe_port() in list_mutex Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 06/17] driver core: platform: Fix the usage of platform device name(pdev->name) Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 07/17] Drivers: misc: fix out-of-bounds access in function param_set_kgdbts_var Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 08/17] configfs: fix possible use-after-free in configfs_register_group Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 09/17] ipc: prevent lockup on alloc_msg and free_msg Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 10/17] scsi: lpfc: add check for loss of ndlp when sending RRQ Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 11/17] arm64/mm: Inhibit huge-vmap with ptdump Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 12/17] scsi: bnx2fc: fix incorrect cast to u64 on shift operation Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 13/17] selftests/timers: Add missing fflush(stdout) calls sashal
2019-06-04 23:24   ` Sasha Levin
2019-06-04 23:24   ` Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 14/17] usbnet: ipheth: fix racing condition Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 15/17] usbnet: fix kernel crash after disconnect Sasha Levin
2019-06-04 23:24 ` Sasha Levin [this message]
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 17/17] KVM: s390: fix memory slot handling for KVM_SET_USER_MEMORY_REGION Sasha Levin

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=20190604232459.7745-16-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nadav.amit@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=stable@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.