Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3350946pxf; Sun, 28 Mar 2021 22:55:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIy7DF8tXdN01Y6gtTTKUEOOkKxDCNPk4sXypgzJm6K8taBSs+ZfeRzcbjN81WesTVebeN X-Received: by 2002:a05:6402:b2a:: with SMTP id bo10mr26404583edb.144.1616997309384; Sun, 28 Mar 2021 22:55:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616997309; cv=none; d=google.com; s=arc-20160816; b=a24gA/2H7dj+gWZ6MCgQplTdepGMPeYkMbjy2f2/bWe9tMrlv27Yj7PqnlqfuG7eei 12mheYmO4nfXQI5ez7egygB5OIPB+aOdEV2ocynV8VirdPVut3qiwnqHzBIgGWH6xMyO eE9jCDlL7k8IsIqdKNHbjzOUjD9QcmIZd8ip5eL6zLcqkH04k6FZpsir1vkRiEySLEHn qWBfJXOc/6S0Sxa2AgdtUXE0sE0pMe6ZqwO6ls24VYDEuOP+SkY9vvwDBprcRCJkSKMX hYqSWdIAaI0h72PaqEwrsXPTILhi72tLXoyJtG8vcEYcyoa4PFJto8ewk+PUu+BU+XB9 DK4A== 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=48U8YHDU51cY0pzIDMJ2z7hmsMeRfhSMLcnFYOV30D4=; b=s8VcU5fM/HwI06jhaGylWCBdBC5V1zObL719kKOT0cS0Y2fTNyg3kWjnT1qcJMiZtP Kb3mxH8ML/kdcpCkcfsI4tbhhLdPEwNMAKYI/eIoc1k2a8mqHlk2rXWCw9GbhuBof9gZ yzxMFeNTBqMPMjvnuA5jU7isiY2CQOheomLaUlX9SSetSIcT5fpXCSCF3iITRCgdMGId FouzEYog7pk8qcQnAzpJSr5vtljnoNXysCHtuvltJwSlaiFtUPCv9EEMgeS35J0cgXB/ +M2HTnm2H2WLLFAPrjje02ihLULlSrZb2nk9FdEacM8qJgdicPvqZIiHh95pqTydDM9J 8HuQ== 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 qh20si11560844ejb.749.2021.03.28.22.54.47; Sun, 28 Mar 2021 22:55:09 -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 S230329AbhC2Fuj (ORCPT + 99 others); Mon, 29 Mar 2021 01:50:39 -0400 Received: from mga07.intel.com ([134.134.136.100]:15632 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230437AbhC2FuD (ORCPT ); Mon, 29 Mar 2021 01:50:03 -0400 IronPort-SDR: 7kot5cITVil+oLS5yZaB9qcxL6OUg8fs9rfpySI4cifpAT6PJlIkOtFp58ual5+OPikwSNeHX9 ZOTwa07lnWow== X-IronPort-AV: E=McAfee;i="6000,8403,9937"; a="255478755" X-IronPort-AV: E=Sophos;i="5.81,285,1610438400"; d="scan'208";a="255478755" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2021 22:50:02 -0700 IronPort-SDR: NUtgFmNLl+JwLC3NArebTMTACnpXZPYhHns9wrCYsVaD7XQRZRk5iPF6jMDfIqDHoo27N4pLb0 i94Og2T+iOWw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,285,1610438400"; d="scan'208";a="417506874" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga008.jf.intel.com with ESMTP; 28 Mar 2021 22:49:59 -0700 From: Like Xu To: peterz@infradead.org, Sean Christopherson , Paolo Bonzini Cc: eranian@google.com, andi@firstfloor.org, kan.liang@linux.intel.com, wei.w.wang@intel.com, Wanpeng Li , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Like Xu Subject: [PATCH v4 10/16] KVM: x86: Set PEBS_UNAVAIL in IA32_MISC_ENABLE when PEBS is enabled Date: Mon, 29 Mar 2021 13:41:31 +0800 Message-Id: <20210329054137.120994-11-like.xu@linux.intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210329054137.120994-1-like.xu@linux.intel.com> References: <20210329054137.120994-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 7f18c760dbae..4dcf66e6c398 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; @@ -598,6 +599,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 536b64360b75..888f2c3cc288 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3126,6 +3126,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.29.2