Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp296250ima; Wed, 24 Oct 2018 01:08:11 -0700 (PDT) X-Google-Smtp-Source: AJdET5f8iJZtq84tKm8kXnDsj7fl9FOcPYAVhIvcvZJapE9M9gaToY2T73I2VXOGYU+tC3QmElRQ X-Received: by 2002:a63:da57:: with SMTP id l23-v6mr1608919pgj.179.1540368491191; Wed, 24 Oct 2018 01:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540368491; cv=none; d=google.com; s=arc-20160816; b=SBeKkkji37jjkrz2ky5NNxRWWE1g4MZy8RMt1sGDYVpTHGOy9rILJZwFM2ABIH+W3b hqJ+sr4eQX7XtuwXrtoE6SHZjbF+ZtDsDvzt8pCNT+Zk5fSmag69aTlUbwx2VwB7MLLL ZhzNSKTCBkcM30rSi8P72Ou7FepLW4ADB1wD+bjZei2NDp+N3Jz81bGCVGfhjk1Vy0/L WzglFlp9TfNjqTBx5Sh31o1XOIuI3iZy5L9MBYvGPFyPNmJYQqmB2ue8cLaozSyNwkD9 sNUj8twD0pCuZUZSsW+mX7TrsRHzEx5LqveJYvQXydChHTpSwYZuM8cFRCmc888ENNZ4 tZig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=2UhBBPmvdzUCLyErJvOFnq0zdF6oEeB4ugZzYLXYspQ=; b=IZfryC7T5WuodLNeQYOlpuSPCxa6wKrGHttMuoV99NU2JPjtKeFbCbmRNekjoJRhdR rnQ2sbFOVQRtDxHZh7/i0M+ST+RFwZ1fKpm0S8dKZu5dpT7G80IjZds9oZ8p4PzFEb1a OlyVQ8uTJsbiSIrUoQ2LzY4Y3uALrL1VjGfJmRN10f8VbquJap2Arbw/oh1wUk/0sMLl 6ImSJQNGZ2YyNMWxnmxbjRMPZFaQyiR3p5Fzmy4ykzpmLuGUtxe7EkylbJBqPZbUDHUx 3ZYbkGsJZMOCbzDDgOTO9v9MQYDQ7FWpNpAJc29UF5oEXeKbaPEiX94NxIb1iDURJXfE hUfQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id u14-v6si3762882plq.268.2018.10.24.01.07.55; Wed, 24 Oct 2018 01:08:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727713AbeJXQeV (ORCPT + 99 others); Wed, 24 Oct 2018 12:34:21 -0400 Received: from mga18.intel.com ([134.134.136.126]:4505 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727441AbeJXQeV (ORCPT ); Wed, 24 Oct 2018 12:34:21 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Oct 2018 01:07:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,419,1534834800"; d="scan'208";a="273987277" Received: from skx-d.bj.intel.com ([10.238.135.53]) by fmsmga005.fm.intel.com with ESMTP; 24 Oct 2018 01:07:14 -0700 From: Luwei Kang To: kvm@vger.kernel.org, x86@kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, pbonzini@redhat.com, rkrcmar@redhat.com, joro@8bytes.org, songliubraving@fb.com, peterz@infradead.org, alexander.shishkin@linux.intel.com, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, thomas.lendacky@amd.com, konrad.wilk@oracle.com, mattst88@gmail.com, Janakarajan.Natarajan@amd.com, dwmw@amazon.co.uk, jpoimboe@redhat.com, marcorr@google.com, ubizjak@gmail.com, sean.j.christopherson@intel.com, jmattson@google.com, linux-kernel@vger.kernel.org, Luwei Kang Subject: [PATCH v13 03/12] perf/x86/intel/pt: Introduce intel_pt_validate_cap() Date: Wed, 24 Oct 2018 16:05:07 +0800 Message-Id: <1540368316-12998-4-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1540368316-12998-1-git-send-email-luwei.kang@intel.com> References: <1540368316-12998-1-git-send-email-luwei.kang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org intel_pt_validate_hw_cap() validates whether a given PT capability is supported by the hardware. It checks the PT capability array which reflects the capabilities of the hardware on which the code is executed. For setting up PT for KVM guests this is not correct as the capability array for the guest can be different from the host array. Provide a new function to check against a given capability array. Acked-by: Song Liu Signed-off-by: Luwei Kang --- arch/x86/events/intel/pt.c | 12 +++++++++--- arch/x86/include/asm/intel_pt.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c index 309bb1d..53e481a 100644 --- a/arch/x86/events/intel/pt.c +++ b/arch/x86/events/intel/pt.c @@ -75,14 +75,20 @@ PT_CAP(psb_periods, 1, CPUID_EBX, 0xffff0000), }; -u32 intel_pt_validate_hw_cap(enum pt_capabilities cap) +u32 intel_pt_validate_cap(u32 *caps, enum pt_capabilities capability) { - struct pt_cap_desc *cd = &pt_caps[cap]; - u32 c = pt_pmu.caps[cd->leaf * PT_CPUID_REGS_NUM + cd->reg]; + struct pt_cap_desc *cd = &pt_caps[capability]; + u32 c = caps[cd->leaf * PT_CPUID_REGS_NUM + cd->reg]; unsigned int shift = __ffs(cd->mask); return (c & cd->mask) >> shift; } +EXPORT_SYMBOL_GPL(intel_pt_validate_cap); + +u32 intel_pt_validate_hw_cap(enum pt_capabilities cap) +{ + return intel_pt_validate_cap(pt_pmu.caps, cap); +} EXPORT_SYMBOL_GPL(intel_pt_validate_hw_cap); static ssize_t pt_cap_show(struct device *cdev, diff --git a/arch/x86/include/asm/intel_pt.h b/arch/x86/include/asm/intel_pt.h index fa4b4fd..00f4afb 100644 --- a/arch/x86/include/asm/intel_pt.h +++ b/arch/x86/include/asm/intel_pt.h @@ -26,9 +26,11 @@ enum pt_capabilities { #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL) void cpu_emergency_stop_pt(void); extern u32 intel_pt_validate_hw_cap(enum pt_capabilities cap); +extern u32 intel_pt_validate_cap(u32 *caps, enum pt_capabilities cap); #else static inline void cpu_emergency_stop_pt(void) {} static inline u32 intel_pt_validate_hw_cap(enum pt_capabilities cap) { return 0; } +static inline u32 intel_pt_validate_cap(u32 *caps, enum pt_capabilities capability) { return 0; } #endif #endif /* _ASM_X86_INTEL_PT_H */ -- 1.8.3.1