Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3009374ybi; Mon, 17 Jun 2019 14:35:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwH3MuSN35UtKLCvjz4qpT8z1clhZ27meo1oPVt5WlACSWxBCPxd0YrIdVCjqGlXX8Krxz7 X-Received: by 2002:a62:4dc5:: with SMTP id a188mr117605843pfb.8.1560807346949; Mon, 17 Jun 2019 14:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560807346; cv=none; d=google.com; s=arc-20160816; b=Nui9Pt8qNoqa1BD+z6n+/3EtwqSXmZdKJmMEmO5esOZ9o9eVBymQ7jTDQDfg6i1Lxo G25O1GYqNGUsKtYbHbAeuOhurI0k2TsKhLibmMcpf8d/4XfRinO+h+L/KMGKSpnvPcCe zv0mb24xKOoRwNL/FH1KaAVefo9Z4zzsd97eCQtoIqBpDp3vUQ4xHh1U9EAUm6ggPN50 rJKVHc5TBHEQ3XDVFhrib6yxfsbj5cf6VZN3P4vAhwi6Fj/gJUwdtcUvDM7O41u0mHKh iFQNbZqGiW3f0dYlHatKYV6ykRnR1ipyh2nYwrJueqro3dCgBYI2/Os5u9KtU3eG1h1w mY0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lRrV73tt5bm7QchoG0rizKUH6cjqStEhczsCy054P4c=; b=cHCAn8riOzRyAXzYSPqgTFBt/3V1Luzgil2HvEmYWDSgUvFM2KeUUK1olLsWepnnT/ +eBABJywZ46s3p659N+1xCdUZuyXSWZm5zb5g26EatCXseVSw0KMNrWvcXrX3pPvwOiI EXczhrogiju3hZ/VVsPeSLK8GhWAsFxKjK/kdw6tCYs6n71+H6MRcZdYJXkaJJFTD3oH qYXAeaYCJ27bAUiVIQhylq0tqr6ZhHr4con8LLy9MAscG13uhvcgHu0WqAe6MuRkUzmN nj72K/QLU4HZkuVd9RtX6J/RcQVIxTXGvcCU4rTgeRXkcDKDjEeFLZSy5dyeaC75ZBqH SI8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WoecNCLq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10si11291616pgo.359.2019.06.17.14.35.32; Mon, 17 Jun 2019 14:35:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WoecNCLq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728691AbfFQVWw (ORCPT + 99 others); Mon, 17 Jun 2019 17:22:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:47634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729599AbfFQVWt (ORCPT ); Mon, 17 Jun 2019 17:22:49 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3D268206B7; Mon, 17 Jun 2019 21:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806568; bh=zvYzAelTsaiCdKRjDnzmqvkcpsP0V6Ofx+NoPmbZhFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WoecNCLqvi0kQG0WepWUT5/Ogu6LTpzav+ESBSVFjv7Kadg47NPeRuHd23GiZEJvr G94f9PADu+23oWyHMVuc9Xsr29QxCl8adZeLipmNU+lmp0zfE1FTynj57gsupi6QQ6 DFtiAYwknV/7VAwIsvWjtCmquQQI2zCHB6Az64w8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nadav Amit , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.1 090/115] KVM: x86/pmu: do not mask the value that is written to fixed PMUs Date: Mon, 17 Jun 2019 23:09:50 +0200 Message-Id: <20190617210804.539178058@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210759.929316339@linuxfoundation.org> References: <20190617210759.929316339@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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 Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/vmx/pmu_intel.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index ad7ea81fbfbf..c3f103e2b08e 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -240,11 +240,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