Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4547066pxj; Tue, 22 Jun 2021 02:46:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVsA4l1O80L7y/xIy0uAFBi/TiuiuVw+HeRkDjQZtBt70oxv9bPOBJXVTOW6DfhKjlmXOc X-Received: by 2002:a17:906:509:: with SMTP id j9mr3028523eja.109.1624355194631; Tue, 22 Jun 2021 02:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624355194; cv=none; d=google.com; s=arc-20160816; b=dEuei6t9rh/lfnTe5lzICsOaEZOF7Ap6FAhssWmtuPSwqjLKDXRM9zGLmFjiPDcmjO GkwhLjCI5/fG5MkNx/t1FfHejnOizzgfP9Kte1UtfWWG5La+2gh+hPdhOooSgXdXNw2h pMvNxJOQYZjam2Mt2FAEJ22w+TNaIBv6b08bx9r7VzzqoMal6TRVMFLHkLDtNJ7oU7xe 400xBeaxTuizSeW5X3WGdOGBsmhgOQJlKKF8Sn7QQMLp3oTCIPGSBulUmSWO4wZIHb9B NVwcTZzRxBYPbOWPTJ2WP6L7rhkAPC+wXAazBv6hz5fDS58MzIA1916zbULJEfz42WYX DZzA== 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=oEJFDlIYI6p9ydwHHOEaGm9roSWGqx+KSSO4EJrT9Cc=; b=BT2kpUKgjJI694S9KUWMPt/wi3pvNI7rGVjs/ePmpMGiWn8dLZkKONmO8u3apVY+Cl 2QlfDfq6f5sWuRryb7J7RvgtLTrxxjnq/ocK5dxR5VjBR76kMcv2FX6YZtLuSMR+VrER dlGyp3ZPj4yPvB8KlYxtmuNqxwKytbiS664WFis6skdb4b1yXNzCqpwLJxNIVSDzp0bj 9FJp0W6NA81br0//3hzQ9k0/CQ+88f65Z2DILCkZhKfOlppZ9DJCdK8/EnfW9V6eLZAC ppgSLZNrM6wlA2CuFUE6OzmmhtIXA4VMEwVeWH8w5QNo/wpeLU1OmvvfyTkjjcUzqmzX e/+Q== 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 eb9si12562198edb.139.2021.06.22.02.46.10; Tue, 22 Jun 2021 02:46:34 -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 S230403AbhFVJqt (ORCPT + 99 others); Tue, 22 Jun 2021 05:46:49 -0400 Received: from mga18.intel.com ([134.134.136.126]:20229 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230083AbhFVJq0 (ORCPT ); Tue, 22 Jun 2021 05:46:26 -0400 IronPort-SDR: 5hNk4FX5JqagLOLL+f18VZ914uSGraWgmHYycsczab+ax1PHR0RyemlXnl7DAnJIP3BdVNH6tM UmnJaV2bjCQQ== X-IronPort-AV: E=McAfee;i="6200,9189,10022"; a="194331004" X-IronPort-AV: E=Sophos;i="5.83,291,1616482800"; d="scan'208";a="194331004" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 02:44:03 -0700 IronPort-SDR: Fpyh1Z2Cb8sxx3pgdBnSzyIIjbQ9eIN7V3nDGDwjr7dH0regVmxgM2+5pPNTriPG0F16tTNzdl DqYbDrmIzqgg== X-IronPort-AV: E=Sophos;i="5.83,291,1616482800"; d="scan'208";a="641600236" Received: from vmm_a4_icx.sh.intel.com (HELO localhost.localdomain) ([10.239.53.245]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 02:43:58 -0700 From: Zhu Lingshan To: peterz@infradead.org, pbonzini@redhat.com Cc: bp@alien8.de, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, weijiang.yang@intel.com, kan.liang@linux.intel.com, 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.linux@gmail.com, Like Xu , Zhu Lingshan Subject: [PATCH V7 10/18] KVM: x86/pmu: Adjust precise_ip to emulate Ice Lake guest PDIR counter Date: Tue, 22 Jun 2021 17:42:58 +0800 Message-Id: <20210622094306.8336-11-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210622094306.8336-1-lingshan.zhu@intel.com> References: <20210622094306.8336-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Like Xu 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 Signed-off-by: Zhu Lingshan --- 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 d76b0a5d80d7..b907aba35ff3 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -153,6 +153,8 @@ static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type, * could possibly care here is unsupported and needs changes. */ attr.precise_ip = 1; + if (x86_match_cpu(vmx_icl_pebs_cpu) && pmc->idx == 32) + attr.precise_ip = 3; } if (pebs || intr) ovf = kvm_perf_overflow_intr; diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h index 67e753edfa22..1af86ae1d3f2 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.27.0