Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3152821pxb; Tue, 20 Apr 2021 01:34:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfNm7EyuPmLJB8yBfdz6I03LpuNDZ+evA6hkKm+Jswp4Gp73WFZTNzfAdV0hFv5eafr1zN X-Received: by 2002:a17:906:37c9:: with SMTP id o9mr25925398ejc.285.1618907690927; Tue, 20 Apr 2021 01:34:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618907690; cv=none; d=google.com; s=arc-20160816; b=TB12iJ0CcS/I7hqe0khdOIsW31uixig8MDUwwiGcnROJvf2xbft8/igRyWVx0oaO/0 8XJngiSJ/dCv7DXmKZdPq/YefezR9PNc+PLXC/7VkOcANgbvv4dUifaHPibSSgJArajT 2Kz6rSA254RHjrUq8kyuBTaleHEujmpN278KdnOSdS9EkawnyZGv9wake8jnqpZVtyRW D3b4qAD+oyLdX/+S7l8BhWPuw5xX8BVxMm4thhkG2SSE9lh9RM5ngYsrmMLbl4OML5qC fR1GP+NDvzv0I9EPZq7p0aBBX5/bNKeRl0vVsbn9k4AWMThGmL9UnKYfcye5wtJPHnUv /27A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=MnqGWxD1Pi+yaMaN/dQzajduLxmUQ5gbXcXcds2gU1E=; b=ozNtb0rCF1MNv7cI+wJPX27hnbD9f1IImIbnixAoUIksBdTJ0kJuHhf78C+SuVfbiI x8PEn/ghVHZ2J7TdFUWlm1MrcDRgXDra2aqTWcfIVNlijewE7dS1LFRLeBdcor1omuIA 0TAbUPmjrtG6f4TzPQLSyRDNcVJpKkiB6c18VU1SuIYzHcDWTZDkUx/s5wSEn4pxl1sS fvJi5HTjgK5OWP4MzRNIe9kWVcJ9fxG780+no0z3GY0eVRMWuUWQ1RQuHN+IDEz4jUQh fZ/gsodJWiQzrTmhpnnwc9U0XDS/KDL4gTdhiHFm/n9TY6kHPm6h7lZlHXmD0gQ3f9or Zn9Q== 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=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gx23si5910127ejb.463.2021.04.20.01.34.27; Tue, 20 Apr 2021 01:34:50 -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=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230507AbhDTIaz (ORCPT + 99 others); Tue, 20 Apr 2021 04:30:55 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:3342 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230495AbhDTIaz (ORCPT ); Tue, 20 Apr 2021 04:30:55 -0400 Received: from DGGEML402-HUB.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4FPcGg3sCZz14JV1; Tue, 20 Apr 2021 16:26:35 +0800 (CST) Received: from dggpeml500013.china.huawei.com (7.185.36.41) by DGGEML402-HUB.china.huawei.com (10.3.17.38) with Microsoft SMTP Server (TLS) id 14.3.498.0; Tue, 20 Apr 2021 16:30:21 +0800 Received: from [10.174.187.161] (10.174.187.161) by dggpeml500013.china.huawei.com (7.185.36.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Tue, 20 Apr 2021 16:30:20 +0800 Subject: Re: [PATCH v5 10/16] KVM: x86: Set PEBS_UNAVAIL in IA32_MISC_ENABLE when PEBS is enabled To: Like Xu , , Paolo Bonzini , Sean Christopherson References: <20210415032016.166201-1-like.xu@linux.intel.com> <20210415032016.166201-11-like.xu@linux.intel.com> CC: , , , , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , , , , "Fangyi (Eric)" , Xiexiangyou From: Liuxiangdong Message-ID: <607E911C.4090706@huawei.com> Date: Tue, 20 Apr 2021 16:30:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <20210415032016.166201-11-like.xu@linux.intel.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.187.161] X-ClientProxiedBy: dggeme712-chm.china.huawei.com (10.1.199.108) To dggpeml500013.china.huawei.com (7.185.36.41) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/4/15 11:20, Like Xu wrote: > 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..c846d3eef7a7 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; > @@ -597,6 +598,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) > } > pmu->pebs_data_cfg_mask = ~0xff00000full; > } else { > + vcpu->arch.ia32_misc_enable_msr |= MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL; > pmu->pebs_enable_mask = > ~((1ull << pmu->nr_arch_gp_counters) - 1); > } I guess what we want is 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; for (i = 0; i < pmu->nr_arch_fixed_counters; i++) { pmu->fixed_ctr_ctrl_mask &= ~(1ULL << (INTEL_PMC_IDX_FIXED + i * 4)); } pmu->pebs_data_cfg_mask = ~0xff00000full; } 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; } But here is 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; for (i = 0; i < pmu->nr_arch_fixed_counters; i++) { pmu->fixed_ctr_ctrl_mask &= ~(1ULL << (INTEL_PMC_IDX_FIXED + i * 4)); } pmu->pebs_data_cfg_mask = ~0xff00000full; } else { vcpu->arch.ia32_misc_enable_msr |= MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL; pmu->pebs_enable_mask = ~((1ull << pmu->nr_arch_gp_counters) - 1); } } else { vcpu->arch.perf_capabilities &= ~PERF_CAP_PEBS_MASK; } Wrong else branch? > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 1a64e816e06d..ed38f1dada63 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))