Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2901897pxb; Sun, 8 Nov 2020 18:22:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNYLmQWrP8Jch9kNQEePMtBjYfIrrPuErlLILRCDJQF+kTwOAKr2xRd95X8Eu64hj1FdJE X-Received: by 2002:a50:be8f:: with SMTP id b15mr12970593edk.180.1604888575215; Sun, 08 Nov 2020 18:22:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604888575; cv=none; d=google.com; s=arc-20160816; b=E0v4IcBNPoWlDvqs5yaaLAFO+Z1QsxIjqE6qkThNOJ17mDPoZ1MFcQLe7CaV6fSw2X 7tlppJOHks5eXZUj601tYQGmwfYmgnqvygulfnm1DQNeaQyNqxbLAJHMhRYl50jDNY1O urWpQKd+L6rvCB34kcGvhglPJmbqO8Ahvq/MPdr3WrC7D49SYBcE4oUvHnyI3yzRBcPS NiwL140emQTzDgQZlNLXmF40uQ3O3cFROTv2rIyK1Kb2HrD2TMRE0Air76w5FDtm6OM5 yCtVE2qDPcgrKnGbPlHnjGbEv/toW0OImZBMNYR8QOeumjXT+SMbE0UsC8GBXrJBL/WX id1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=yVqNZ5AAnYk29vaMCwQ1ay1NsjVuGUJj3NzZRkwYXOs=; b=GYU9Edx4SxYt+c01eD0oPU75l7hWW91ndnAGnS1cljKkEfAKOEAeUZ7V6qFKam0PcS vQol4hFNmnvTy7nsp20I4gHv75viPsZhBmzuG2cXGtz6VGlz+mOAQ5xOYswtOq6X3NTc qlIHe/KSFjWt80GcKh1Drm5s/iqhCEELNvhYzt7C7w5nXhz0q1x59myGZ3HWeDOByGLn OyAkx3EaZThWXCykSdWBhWjqgylIMSxAv9aNKlreC9qvtko6VoGG2QU8NoVaBkBI0FQ5 DOwqg1Nlmw5PrOfNI+Y8EPmsK05eY5rM0+25d/2c/t7hvI2yCxaQ35TPQDvsQ0x7cORj Rwvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z19si6198225edx.461.2020.11.08.18.22.32; Sun, 08 Nov 2020 18:22:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729362AbgKICS0 (ORCPT + 99 others); Sun, 8 Nov 2020 21:18:26 -0500 Received: from mga01.intel.com ([192.55.52.88]:64930 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729335AbgKICRZ (ORCPT ); Sun, 8 Nov 2020 21:17:25 -0500 IronPort-SDR: KR7920oyjXv7Edb0gItM/G8JQL/MZ1pAJne669SAj/PFah4FfxktYjjsaRLW/8rorSJ6EwBEi3 PMqIjynhZZZw== X-IronPort-AV: E=McAfee;i="6000,8403,9799"; a="187684622" X-IronPort-AV: E=Sophos;i="5.77,462,1596524400"; d="scan'208";a="187684622" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2020 18:17:25 -0800 IronPort-SDR: LmkJyZt+f2MPjQi+D6sXKFJ3ZrP+U9SPuvb10L3TG8DmJ9uVY0GVJTIA5DyAL5DRknOfynretj LJVtATB92sLg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,462,1596524400"; d="scan'208";a="540646221" Received: from e5-2699-v4-likexu.sh.intel.com ([10.239.48.39]) by orsmga005.jf.intel.com with ESMTP; 08 Nov 2020 18:17:21 -0800 From: Like Xu To: Peter Zijlstra , Paolo Bonzini , kvm@vger.kernel.org Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Kan Liang , luwei.kang@intel.com, Thomas Gleixner , wei.w.wang@intel.com, Tony Luck , Stephane Eranian , Mark Gross , Srinivas Pandruvada , linux-kernel@vger.kernel.org Subject: [PATCH v2 09/17] KVM: x86: Set PEBS_UNAVAIL in IA32_MISC_ENABLE when PEBS is enabled Date: Mon, 9 Nov 2020 10:12:46 +0800 Message-Id: <20201109021254.79755-10-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201109021254.79755-1-like.xu@linux.intel.com> References: <20201109021254.79755-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The bit 12 represents "Processor Event Based Sampling Unavailable (RO)" : 1 = PEBS is not supported. 0 = PEBS is supported. A write to this PEBS_UNAVL available bit will bring #GP(0) when guest PEBS is enabled. Some PEBS drivers in guest may care about this bit. Signed-off-by: Like Xu --- arch/x86/kvm/vmx/pmu_intel.c | 2 ++ arch/x86/kvm/x86.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index c04e12812797..99d9453e0176 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -426,6 +426,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) INTEL_PMC_MAX_GENERIC, pmu->nr_arch_fixed_counters); if (vcpu->arch.perf_capabilities & PERF_CAP_PEBS_FORMAT) { + vcpu->arch.ia32_misc_enable_msr &= ~MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL; if (vcpu->arch.perf_capabilities & PERF_CAP_PEBS_BASELINE) { pmu->pebs_enable_mask = ~pmu->global_ctrl; pmu->reserved_bits &= ~ICL_EVENTSEL_ADAPTIVE; @@ -436,6 +437,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) } else pmu->pebs_enable_mask = ~((1ull << pmu->nr_arch_gp_counters) - 1); } else { + vcpu->arch.ia32_misc_enable_msr |= MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL; vcpu->arch.perf_capabilities &= ~PERF_CAP_PEBS_MASK; } diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index e1280bb18152..b5963a36bf6b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3087,6 +3087,10 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) break; case MSR_IA32_MISC_ENABLE: data &= ~MSR_IA32_MISC_ENABLE_EMON; + if (!msr_info->host_initiated && + (vcpu->arch.perf_capabilities & PERF_CAP_PEBS_FORMAT) && + (data & MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL)) + return 1; if (!kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT) && ((vcpu->arch.ia32_misc_enable_msr ^ data) & MSR_IA32_MISC_ENABLE_MWAIT)) { if (!guest_cpuid_has(vcpu, X86_FEATURE_XMM3)) -- 2.21.3