Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3350967pxf; Sun, 28 Mar 2021 22:55:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcvVQZ7ZyLWfo5GgsXursoHgEhEkbQjKUu4+MHg1XPbaM51bhTFj82qE7K/Pm5f5thE1iB X-Received: by 2002:a17:906:ecb8:: with SMTP id qh24mr27775158ejb.162.1616997312634; Sun, 28 Mar 2021 22:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616997312; cv=none; d=google.com; s=arc-20160816; b=l2ZlpqjsauzShFts3rKgccPn2zMhLypo7VxyCnzw3R030VjAVLEWiKAigQyDqptLd2 k5ktfh2/OaMNSx2RiupDLYKrDglI71PQ6E89a39a6Tn1mWBzaEMeL2UgbFSg++Tq3aK2 YuBfwwqcfJWTCEV7TQ3B4j31TWEmlJHIJ2j6hXfgsYqUA/+yLSW6DPFkq2/ex/wi7ZmL 1FYT1emBwtwD7HTyUXaVEI/wE8zT0Or05z6PHbiVY/hAzlyyt78xtXcAn1EZOxm1J5YS IuO+CI5rdKCko/oEPW5KHWeN69IpLRyPDvuLJTfnt5nBHEQ46PQXja3lcL2R5GNFgjFN bxDg== 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=FXCpAna7fs+U52Brb2uMMN8ZR27r+wyq9MnBhPpDh0k=; b=QbcK4qQ2Jv3XT1v+UaWsMU7GXvTP4EsMvweJ5vewAyBb8jR+PaKUmMEXdBXj9mSfxc TzQ5ZFuEYX9ENyVc19yn1cSQ/ZRhOkFxxqgawQB3ChkL4TB65VsEGoj04kL9j3lZtqcU TEgkKwUX2zyhydxCqZM8ymUU0UjnrO3a/n5XLxgMswbFD95+QCfd/ACf614JZ1Ie3iaz 7Ag/SsBQiInptK5GFpUUEEkKyiUNPwwR5vbTKWUx9Iw7DdkI4xSvRH7S3GijeXJCCyUn v0mw4mKmHggZtrSzaGNp6zu4jxsCnKEn5ttfk+2aYk6pZW3ZG2ulswN7d/fUQrVXNuiS Uz5g== 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 f11si12145539edw.236.2021.03.28.22.54.50; Sun, 28 Mar 2021 22:55:12 -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 S231480AbhC2Ful (ORCPT + 99 others); Mon, 29 Mar 2021 01:50:41 -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 S230522AbhC2FuG (ORCPT ); Mon, 29 Mar 2021 01:50:06 -0400 IronPort-SDR: VFRkGN2E0suGtzof6y9h9r7GTdGODCQhi47yemyjwZpmWfqW7psghgzS07RX8xNGuJPeckvVwB rhnPjWCx2qsw== X-IronPort-AV: E=McAfee;i="6000,8403,9937"; a="255478757" X-IronPort-AV: E=Sophos;i="5.81,285,1610438400"; d="scan'208";a="255478757" 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:06 -0700 IronPort-SDR: j1F+LCI3vQmSIm7SXbk31Qpxu17AJcwsRL0SPPI2qVkBzNw6GQ6a+FYHAuIxBesxTCD/HuzwnG vYCyX89EpTtQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,285,1610438400"; d="scan'208";a="417506944" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga008.jf.intel.com with ESMTP; 28 Mar 2021 22:50:03 -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 11/16] KVM: x86/pmu: Adjust precise_ip to emulate Ice Lake guest PDIR counter Date: Mon, 29 Mar 2021 13:41:32 +0800 Message-Id: <20210329054137.120994-12-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 PEBS-PDIR facility on Ice Lake server is supported on IA31_FIXED0 only. If the guest configures counter 32 and PEBS is enabled, the PEBS-PDIR facility is supposed to be used, in which case KVM adjusts attr.precise_ip to 3 and request host perf to assign the exactly requested counter or fail. The cpu model check is also required since some platforms may place the PEBS-PDIR facility in another counter index. Signed-off-by: Like Xu --- arch/x86/kvm/pmu.c | 2 ++ arch/x86/kvm/pmu.h | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index 3509b18478b9..8d2873cfec69 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -148,6 +148,8 @@ static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type, * in the PEBS record is calibrated on the guest side. */ attr.precise_ip = 1; + if (x86_match_cpu(vmx_icl_pebs_cpu) && pmc->idx == 32) + attr.precise_ip = 3; } event = perf_event_create_kernel_counter(&attr, -1, current, diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h index 7b30bc967af3..d9157128e6eb 100644 --- a/arch/x86/kvm/pmu.h +++ b/arch/x86/kvm/pmu.h @@ -4,6 +4,8 @@ #include +#include + #define vcpu_to_pmu(vcpu) (&(vcpu)->arch.pmu) #define pmu_to_vcpu(pmu) (container_of((pmu), struct kvm_vcpu, arch.pmu)) #define pmc_to_pmu(pmc) (&(pmc)->vcpu->arch.pmu) @@ -16,6 +18,11 @@ #define VMWARE_BACKDOOR_PMC_APPARENT_TIME 0x10002 #define MAX_FIXED_COUNTERS 3 +static const struct x86_cpu_id vmx_icl_pebs_cpu[] = { + X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, NULL), + X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, NULL), + {} +}; struct kvm_event_hw_type_mapping { u8 eventsel; -- 2.29.2