Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3128372pxj; Mon, 10 May 2021 19:48:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfeOnXblSGiNiqHBzKI2fo8vEZ0P3eTO8Ra5Lt0gHx5bi0xzdufIbQiNTf1es+bIgCiaRa X-Received: by 2002:a05:6402:5a:: with SMTP id f26mr33247883edu.306.1620701284901; Mon, 10 May 2021 19:48:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620701284; cv=none; d=google.com; s=arc-20160816; b=mlnqRzxJU0/ekN4zkydctK3WXgl16oQTiY1E1xgQ5/fhhnoq/9D2l1uQ3M4CU/87CE DYWb2uf/l8FPVWP/5PSsN1bwckfdH1RxxigF8AcwxDe8o8uD0nfLku5KM+9AxmoxQfWA aBeUFvlXTNHNqwxq9jQv+33p6zxmt04xfJnfireQjg7FAypcIqEH9tPcHP/zCtAjHTE5 JnTEA0mRWrKchKG/tDZwB77phoM7vO8Dvc0qFo2yjpFSOjCnuMR76i/DeERh67nGwrI4 jpUFkcfYszZySUzzp7Kme0cPAbFRq5X5IJcJ0CmX5kni7dQNMV/j9nlOxL/v4W3i3e0a xgHQ== 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=uxUws3KEqKEoGDo+ukJztmv7VZk947Wjj6QXLN02ZDk=; b=atKsUt6pdFv01YM57CZZXMwFny1aMuP73ptuHMa31po87KWrl2M/jdss/AlQ8SbtCx O/q2CFHdlZBTvQ0IsHiXGC8WYnGODC0ImqKiQopODNdpiSAk1JoAmYT3l1clbNZg798M 6wSFCfLnDtSdjlbad4L+SLBA19F3RY2ZizR7JdilCerZE7vFwdZLMlZUR/DVUmcdmaIf vzI2vA/gg0j5sS6hUKEeYjhXhn2faOKI1mX6xMQ8CCQ6Rq0jLUiXgZBs1hIPLUMNfdoR Gu34DcdKWehmwINbMHlR15X8jqE/9BPnGr/mB6C28BoQ1U+2xSBu4ubV+N6Bjr/hWiuo qX6A== 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 da8si11598397edb.398.2021.05.10.19.47.41; Mon, 10 May 2021 19:48:04 -0700 (PDT) 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 S230343AbhEKCo4 (ORCPT + 99 others); Mon, 10 May 2021 22:44:56 -0400 Received: from mga11.intel.com ([192.55.52.93]:42043 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230349AbhEKCos (ORCPT ); Mon, 10 May 2021 22:44:48 -0400 IronPort-SDR: 3BNo/bEntLs4hgQfSFpHiEInEM2q/UtoXIibtNi7fiT9C+Yrskjg5vxWXxOFSfeUu4vdPhs3bm P9re20szB8gg== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="196246452" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="196246452" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2021 19:43:41 -0700 IronPort-SDR: fUqBrpl83XvSk/VkXe9e99ngAvg4xPlwe01KGRzp7Qr89IXnk60TRUHUCo8RghJszmn13zEUH7 wlqDYYkbDfhA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="468591908" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by fmsmga002.fm.intel.com with ESMTP; 10 May 2021 19:43:36 -0700 From: Like Xu To: Peter Zijlstra , Paolo Bonzini Cc: Borislav Petkov , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , weijiang.yang@intel.com, Kan Liang , ak@linux.intel.com, wei.w.wang@intel.com, eranian@google.com, liuxiangdong5@huawei.com, linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, Like Xu Subject: [PATCH v6 10/16] KVM: x86: Set PEBS_UNAVAIL in IA32_MISC_ENABLE when PEBS is enabled Date: Tue, 11 May 2021 10:42:08 +0800 Message-Id: <20210511024214.280733-11-like.xu@linux.intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511024214.280733-1-like.xu@linux.intel.com> References: <20210511024214.280733-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 58f32a55cc2e..296246bf253d 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -588,6 +588,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) bitmap_set(pmu->all_valid_pmc_idx, INTEL_PMC_IDX_FIXED_VLBR, 1); 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; @@ -601,6 +602,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) ~((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 abe3ea69078c..c1ab5bcf75cc 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3212,6 +3212,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.31.1