Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp433369pxb; Wed, 14 Apr 2021 20:23:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsX9B4URbLhbFCoMQgw+OceuqOjrqs06MIFjp68q4tH0dxhORweQLMaFWjoovIenHqZFl6 X-Received: by 2002:a17:906:b104:: with SMTP id u4mr1191277ejy.211.1618457009002; Wed, 14 Apr 2021 20:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618457008; cv=none; d=google.com; s=arc-20160816; b=gwgonVqi+suLPYTHBqfBQIZimf8C1YXOP8nQn1oeAP6MJJCotkS7a9MIyvD3HV0c5D 1F/tDsgexFQTrf3a6aNrBduVJXkYcmlw8xI3Ljq8R+CwxmP+xdkQRMizNhGUzg/cYS0k txUWDW/YXeboODRcQ3S/XYP0QUoNkYCixXfBPUEAK3pn4pQAZSmW/wAAugOeFP66Y+7S JXxLyy8k95kRYpAU1om5w5nG97jNbbSmRR5T7h9JJL55G7K9+rP8IltUS5DNKjCdVGwe SIQ5/snv1k10w11T73IdbgIn5CIOgsQe3HkxEmhAsgI9vpI2NfWapKK/zQak4DESgw7q T7HQ== 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=V52+ahfghrh5m9zM0XBWNWvd/Gm6qQzUtA3lzb7FPec=; b=YRvQob9IjK+FziLiH/HuET3uawpboYWah4jSVTIBS8ztkORpqA2P8MVH69o3sHQ5rn fhyU7zxUy05+qr2Wdhj8XmWEY8pIS09PDHpwAmsJPUVuXR1Vr7zCAWsuB7Y+bElDG9mr 8xDQr3y33c9bsi3XnBRNKncFELiLVfWKUyifdF2N9EGz+VK1gNepFNF/uzv2F75zq+q5 9CUz2+zax/oH+Dy4H3SnlRPHCAPBJsMpwsRSA66Y6PBE0ZKguNuxiuVOtEkjsn3RngS6 XNa+fyehr1d5tQo6dAgPvszw9nVpYHECwPLNnsIxi2DXnM12sBKENrdjr/NxNsiF/oFh kdMg== 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 kl9si1030124ejc.271.2021.04.14.20.23.06; Wed, 14 Apr 2021 20:23:28 -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 S230097AbhDODVh (ORCPT + 99 others); Wed, 14 Apr 2021 23:21:37 -0400 Received: from mga01.intel.com ([192.55.52.88]:10590 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230023AbhDODVa (ORCPT ); Wed, 14 Apr 2021 23:21:30 -0400 IronPort-SDR: Lmg4q4qpWnM5rX0EsvYGpIylfMLtmaqjVG/SwkN7l4gKdDAPmm4WkRDt5bzrMoeb81qRrA7oCp naeiw/ZvwyBg== X-IronPort-AV: E=McAfee;i="6200,9189,9954"; a="215281573" X-IronPort-AV: E=Sophos;i="5.82,223,1613462400"; d="scan'208";a="215281573" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2021 20:21:08 -0700 IronPort-SDR: 961zQWue4/RwxgW/9FPxzaO/OOhXO39JbejTexb1K23s115QbuocFNquUBkweee2bZV1u+iXKh QS8YdScasLBw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,223,1613462400"; d="scan'208";a="425014069" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga008.jf.intel.com with ESMTP; 14 Apr 2021 20:21:04 -0700 From: Like Xu To: peterz@infradead.org, Paolo Bonzini , Sean Christopherson Cc: andi@firstfloor.org, kan.liang@linux.intel.com, wei.w.wang@intel.com, eranian@google.com, liuxiangdong5@huawei.com, Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Like Xu Subject: [PATCH v5 11/16] KVM: x86/pmu: Adjust precise_ip to emulate Ice Lake guest PDIR counter Date: Thu, 15 Apr 2021 11:20:11 +0800 Message-Id: <20210415032016.166201-12-like.xu@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210415032016.166201-1-like.xu@linux.intel.com> References: <20210415032016.166201-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 0f86c1142f17..d3f746877d1b 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -149,6 +149,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.30.2