Skip to contentSkip to conversation

perf/x86/intel/pt: Test CPU vendor before loading

PATCH In review Borislav Petkov 2 participants 2 messages Nov 12, 2015

Subsystems (2)
lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

PATCH 1/1 perf/x86/intel/pt: Test CPU vendor before loading

From: Borislav Petkov <[email protected]>

This keeps poking at MSR 0x570 when loading, i.e. MSR_IA32_RTIT_CTL, which is most likely not present on other vendors. It is using the _safe variant but there's no need to try it at all, really. Besides, it causes unhandled rdmsr warnings when booting in a guest:

kvm [4414]: vcpu0 unhandled rdmsr: 0x570

So check CPU vendor before doing anything else.

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Paul Gortmaker <[email protected]>
Cc "Peter Zijlstra (Intel)" <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/cpu/perf_event_intel_pt.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kernel/cpu/perf_event_intel_pt.c +3 -0
index 42169283448b..fa1262b025e7 100644
@@ -1129,6 +1129,9 @@ static __init int pt_init(void)
 {
 	int ret, cpu, prior_warn = 0;
 
+	if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
+		return 0;
+
 	BUILD_BUG_ON(sizeof(struct topa) > PAGE_SIZE);
 	get_online_cpus();
 	for_each_online_cpu(cpu) {
Signature · 1 line
2.3.5
maintainer Reviewed-by Alexander Shishkin on v1 1/1
#1 lore raw

arch/x86/kernel/cpu/perf_event_intel_pt.c static __init int pt_init(void) · line 1134

Quoted 11 lines · Borislav Petkov
arch/x86/kernel/cpu/perf_event_intel_pt.c +3 -0
index 42169283448b..fa1262b025e7 100644
@@ -1129,6 +1129,9 @@ static __init int pt_init(void)
 {
 	int ret, cpu, prior_warn = 0;
 
+	if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
+		return 0;
+

Does not apply; conflicts with:

commit 73fdeb66592ee80dffb16fb8a9b7378a00c1a826

Author: Huaitong Han <[email protected]>
Date:   Mon Aug 31 16:21:02 2015 +0800

perf/x86/intel/pt: Fix KVM warning due to doing rdmsr() before the CPUID test

If KVM does not support INTEL_PT, guest MSR_IA32_RTIT_CTL reading will produce host warning like "kvm [2469]: vcpu0 unhandled rdmsr: 0x570".

Guest can determine whether the CPU supports Intel_PT according to CPUID, so test_cpu_cap function is added before rdmsr,and it is more in line with the code style.

arch/x86/kernel/cpu/perf_event_intel_pt.c +4 -3
index 42169283448b..868e1194337f 100644
@@ -139,9 +139,6 @@ static int __init pt_pmu_hw_init(void)
 	long i;
 
 	attrs = NULL;
-	ret = -ENODEV;
-	if (!test_cpu_cap(&boot_cpu_data, X86_FEATURE_INTEL_PT))
-		goto fail;
 
 	for (i = 0; i < PT_CPUID_LEAVES; i++) {
 		cpuid_count(20, i,
@@ -1130,6 +1127,10 @@ static __init int pt_init(void)
 	int ret, cpu, prior_warn = 0;
 
 	BUILD_BUG_ON(sizeof(struct topa) > PAGE_SIZE);
+
+	if (!test_cpu_cap(&boot_cpu_data, X86_FEATURE_INTEL_PT))
+		return -ENODEV;
+
 	get_online_cpus();
 	for_each_online_cpu(cpu) {
 		u64 ctl;