Skip to contentSkip to conversation

perf/x86/lbr: Reset LBR_SELECT during vlbr reset

PATCH Applied Wanpeng Li 3 participants 3 messages Nov 5, 2021 – Nov 11, 2021

Subsystems (2)
lore
Share & tools
lore

Wanpeng Li

author
#0 lore raw

PATCH 1/1 perf/x86/lbr: Reset LBR_SELECT during vlbr reset

From: Wanpeng Li <[email protected]>

lbr_select in kvm guest has residual data even if kvm guest is poweroff. We can get residual data in the next boot. Because lbr_select is not reset during kvm vlbr release. Let's reset LBR_SELECT during vlbr reset.

---
 arch/x86/events/intel/lbr.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/events/intel/lbr.c +2 -0
index 9e6d6eaeb4cb..1076de93a2f5 100644
@@ -279,6 +279,8 @@ void intel_pmu_lbr_reset(void)
 
 	cpuc->last_task_ctx = NULL;
 	cpuc->last_log_id = 0;
+	if (!static_cpu_has(X86_FEATURE_ARCH_LBR) && cpuc->lbr_select)
+		wrmsrl(MSR_LBR_SELECT, 0);
 }
 
 /*
Signature · 1 line
2.25.1
#1 lore raw
Quoted 5 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

lbr_select in kvm guest has residual data even if kvm guest is poweroff. We can get residual data in the next boot. Because lbr_select is not reset during kvm vlbr release. Let's reset LBR_SELECT during vlbr reset.

This is because when a new vlbr event is first scheduled in the current CPU, the lbr_select is not reset, which causes the previous lbr_select value to be visible to the next vcpu.

Considering that the requested lbr_select will be reconfigured when the event is enabled. It is trivial, but a valid fix. Thanks.

Quoted 21 lines
---
  arch/x86/events/intel/lbr.c | 2 ++
  1 file changed, 2 insertions(+)
arch/x86/events/intel/lbr.c +2 -0
index 9e6d6eaeb4cb..1076de93a2f5 100644
@@ -279,6 +279,8 @@ void intel_pmu_lbr_reset(void)
 
  	cpuc->last_task_ctx = NULL;
  	cpuc->last_log_id = 0;
+	if (!static_cpu_has(X86_FEATURE_ARCH_LBR) && cpuc->lbr_select)
+		wrmsrl(MSR_LBR_SELECT, 0);
  }
 
  /*
merge bot Applied
#2 lore raw
In reply to Wanpeng Li
The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     0fe39a3929ac7af980347814d552a734b51adacf
Gitweb:        https://git.kernel.org/tip/0fe39a3929ac7af980347814d552a734b51adacf
Author:        Wanpeng Li <[email protected]>
AuthorDate:    Fri, 05 Nov 2021 00:20:51 -07:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Thu, 11 Nov 2021 13:09:34 +01:00

perf/x86/lbr: Reset LBR_SELECT during vlbr reset

lbr_select in kvm guest has residual data even if kvm guest is poweroff. We can get residual data in the next boot. Because lbr_select is not reset during kvm vlbr release. Let's reset LBR_SELECT during vlbr reset.

---
 arch/x86/events/intel/lbr.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/events/intel/lbr.c +2 -0
index 6b72e9b..8043213 100644
@@ -265,6 +265,8 @@ void intel_pmu_lbr_reset(void)
 
 	cpuc->last_task_ctx = NULL;
 	cpuc->last_log_id = 0;
+	if (!static_cpu_has(X86_FEATURE_ARCH_LBR) && cpuc->lbr_select)
+		wrmsrl(MSR_LBR_SELECT, 0);
 }
 
 /*