Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3940463ybl; Mon, 27 Jan 2020 13:24:09 -0800 (PST) X-Google-Smtp-Source: APXvYqw1Nf2m6KpY2bdeybm3PmXyFzHwkU8WVkPUBEmTYMQlDnU3LS5dtnuvuhq7pBXb2kJE3kl2 X-Received: by 2002:a05:6808:1c6:: with SMTP id x6mr773979oic.49.1580160249360; Mon, 27 Jan 2020 13:24:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580160249; cv=none; d=google.com; s=arc-20160816; b=Isdy1euwCnPW2T5HInGK3KceOp63Nr35AWPPsePm+JCsGilOYkYoZBkUqjUZFAjuaD qT02qIDumhXlGddyCSCtfBqDhrIDIsSJJNV59HLu//HbHa8b7WDwNph/CJAyJP1mYBZV WnYatuow3YPoOi+VrTkQE5CMYZx0LfbF9+A0orHPtlU8ZcSsoGjClDS1+BprjXyU1xb6 duo5b4fsAYCOVew3eps7ybDi9vlKuxNXVISFNJ+9rE2uFVCmYZuociM9P6lXiG+lFD61 POQ8R9P5TDeqb/s1dN8M6qxl9yMDqWRo0A+tCqMwn85n6G15ApIzrAk5sZBF5CLrRh6y /VWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=M7uDook8T4JuFhQPKzSHd/4CKNgbM46H4EUNpVdKl20=; b=qk8Pyw/nDlVfPr6qYpVBFxJUn55WsOl1use+26XNiYM4KAI8G52X3i5sFc9Ynz4ket +i/cc8GxZUCyoqs5fTTB8HdgqeJVa0Eb3TJ4iptfCpfeLFTNTBbXH/xFlgSMZvFiG8Bq FTJrt8xQjDVwejFG0sppHC8z5AZ+/6srxq5+HU1Ig2O5sohAEeZ3tQCZJqPFJ7YQXAVW O9JQowY2VAIvAo5BlrwxIl1A8rFNBdjfDJo2OU+ixaKfazws0eyf8+ohhlswX5yPP42s Guvx3PQEgu3wS5zcxaGzeFfwLJ6PLTWsq6DDBQd6TQmBmmI8oceEg1MVUZVXlAWLwNXI ZaCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nQCoMeg5; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y12si4070889oti.162.2020.01.27.13.23.56; Mon, 27 Jan 2020 13:24:09 -0800 (PST) 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=@google.com header.s=20161025 header.b=nQCoMeg5; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726267AbgA0VXB (ORCPT + 99 others); Mon, 27 Jan 2020 16:23:01 -0500 Received: from mail-pl1-f201.google.com ([209.85.214.201]:54457 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbgA0VXB (ORCPT ); Mon, 27 Jan 2020 16:23:01 -0500 Received: by mail-pl1-f201.google.com with SMTP id f10so4444803plr.21 for ; Mon, 27 Jan 2020 13:23:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=M7uDook8T4JuFhQPKzSHd/4CKNgbM46H4EUNpVdKl20=; b=nQCoMeg5/E+KDXBiPl89mZrX/Kg1XuVS5rl428w6rs8LyHFj8aVDYpYacV9NcKKeEg I5vAbvKzZSe21rKyTDluGc9cKcpMpZvjlp/lhl0vvJ6wENBCcWLDosQ0+D9vhuClnUOI upl33DmT7LzNNtkcaKyNxk3VTMVFyXpPXQkWxaHFDPqJj+kFbmmzDcjMseirRMpI0gfK ah5uQV/ilEnZmwn2oOiwRRuVjHhWnzXvrDjF4LSsOr9bKaZP3HayadlgPM/BAdgn4TI6 R00A86ey46B9XNod6zeVEXD6N7ebi95rOqgYc410VknfnRFkZ80cF8yTiUZu9KFYK4zV wX5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=M7uDook8T4JuFhQPKzSHd/4CKNgbM46H4EUNpVdKl20=; b=VsV0y79rgv+MhXPxGMQJtwktrqRihtncLXQExtFZUX+Nhq3tagKEiFkEMWqPif9hlX SO0JfruS7EMpL2ix5HjpVa/s+Qbg3q6Q8hH9lJNCOCrhuonR5Trpj4GWqHDX+jWgNmJJ Wjxrmq7/mUQLYXEuCjKqw/BIHFsNdJRPTG//RHeaeh2yv3o5mlzHh8z/njQIfut3ZROi ExeIYOLKKIy4cf+tnZ+iODxmIRPSMG/jsuIeiyWuvSWMsEC1CZpR2LtXR2EqFCzabdWY 1H/Nlmtxg4SQ1xvG2pWmbLEqR8ckvSTSluEQSi1igLHPl5q1jNQZBChyqgakZmS3bAnX GQUQ== X-Gm-Message-State: APjAAAXersdYchgZUUrTHFan+zmYavxeBjctm1VhWQAXIzpxhZzMr5A6 XcqMR0z+dgVZaHQikzy1mXsmW/+ff8pR3Gc= X-Received: by 2002:a63:1756:: with SMTP id 22mr21988920pgx.109.1580160180456; Mon, 27 Jan 2020 13:23:00 -0800 (PST) Date: Mon, 27 Jan 2020 13:22:56 -0800 Message-Id: <20200127212256.194310-1-ehankland@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH] KVM: x86: Fix perfctr WRMSR for running counters From: Eric Hankland To: Paolo Bonzini , Jim Mattson , Peter Shier Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Eric Hankland Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Correct the logic in intel_pmu_set_msr() for fixed and general purpose counters. This was recently changed to set pmc->counter without taking in to account the value of pmc_read_counter() which will be incorrect if the counter is currently running and non-zero; this changes back to the old logic which accounted for the value of currently running counters. Signed-off-by: Eric Hankland --- arch/x86/kvm/vmx/pmu_intel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index 34a3a17bb6d7..9bdbe05b599c 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -264,9 +264,10 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) pmc->counter = data; else pmc->counter = (s32)data; + pmc->counter += pmc->counter - pmc_read_counter(pmc); return 0; } else if ((pmc = get_fixed_pmc(pmu, msr))) { - pmc->counter = data; + pmc->counter += data - pmc_read_counter(pmc); return 0; } else if ((pmc = get_gp_pmc(pmu, msr, MSR_P6_EVNTSEL0))) { if (data == pmc->eventsel)