Skip to contentSkip to conversation

KVM: x86/pmu: Don't truncate the PerfEvtSeln MSR when creating a perf event

PATCH Applied Jim Mattson 3 participants 5 messages Feb 3, 2022 – Feb 14, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 KVM: x86/pmu: Don't truncate the PerfEvtSeln MSR when creating a perf event

AMD's event select is 3 nybbles, with the high nybble in bits 35:32 of a PerfEvtSeln MSR. Don't drop the high nybble when setting up the config field of a perf_event_attr structure for a call to perf_event_create_kernel_counter().

Fixes ca724305a2b0 ("KVM: x86/vPMU: Implement AMD vPMU code for KVM")
---
 arch/x86/kvm/pmu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/pmu.c +3 -2
index 2c98f3ee8df4..80f7e5bb6867 100644
@@ -95,7 +95,7 @@ static void kvm_perf_overflow(struct perf_event *perf_event,
 }
 
 static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type,
-				  unsigned config, bool exclude_user,
+				  u64 config, bool exclude_user,
 				  bool exclude_kernel, bool intr,
 				  bool in_tx, bool in_tx_cp)
 {
@@ -181,7 +181,8 @@ static int cmp_u64(const void *a, const void *b)
 
 void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
 {
-	unsigned config, type = PERF_TYPE_RAW;
+	u64 config;
+	u32 type = PERF_TYPE_RAW;
 	struct kvm *kvm = pmc->vcpu->kvm;
 	struct kvm_pmu_event_filter *filter;
 	bool allow_event = true;
Signature · 1 line
2.35.0.263.gb82422642f-goog
#1 lore raw

PATCH 2/2 KVM: x86/pmu: Use AMD64_RAW_EVENT_MASK for PERF_TYPE_RAW

AMD's event select is 3 nybbles, with the high nybble in bits 35:32 of a PerfEvtSeln MSR. Don't mask off the high nybble when configuring a RAW perf event.

Fixes ca724305a2b0 ("KVM: x86/vPMU: Implement AMD vPMU code for KVM")
---
 arch/x86/kvm/pmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/pmu.c +1 -1
index 80f7e5bb6867..06715a4f08ec 100644
@@ -221,7 +221,7 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
 	}
 
 	if (type == PERF_TYPE_RAW)
-		config = eventsel & X86_RAW_EVENT_MASK;
+		config = eventsel & AMD64_RAW_EVENT_MASK;
 
 	if (pmc->current_config == eventsel && pmc_resume_counter(pmc))
 		return;
Signature · 1 line
2.35.0.263.gb82422642f-goog
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] KVM: x86/pmu: Use AMD64_RAW_EVENT_MASK for PERF_TYPE_RAW

Quoted 4 lines · Jim Mattson

AMD's event select is 3 nybbles, with the high nybble in bits 35:32 of a PerfEvtSeln MSR. Don't mask off the high nybble when configuring a RAW perf event.

Reviewed-by on v1 1/2
#3 lore raw
In reply to Jim Mattson
Quoted 5 lines · Jim Mattson

AMD's event select is 3 nybbles, with the high nybble in bits 35:32 of a PerfEvtSeln MSR. Don't drop the high nybble when setting up the config field of a perf_event_attr structure for a call to perf_event_create_kernel_counter().

maintainer Applied
#4 lore raw
In reply to Jim Mattson
Quoted 26 lines · Jim Mattson

AMD's event select is 3 nybbles, with the high nybble in bits 35:32 of a PerfEvtSeln MSR. Don't drop the high nybble when setting up the config field of a perf_event_attr structure for a call to perf_event_create_kernel_counter().

Fixes ca724305a2b0 ("KVM: x86/vPMU: Implement AMD vPMU code for KVM")
---
  arch/x86/kvm/pmu.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/pmu.c +1 -1
index 2c98f3ee8df4..80f7e5bb6867 100644
@@ -95,7 +95,7 @@ static void kvm_perf_overflow(struct perf_event *perf_event,
  }
 
  static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type,
-				  unsigned config, bool exclude_user,
+				  u64 config, bool exclude_user,
  				  bool exclude_kernel, bool intr,
  				  bool in_tx, bool in_tx_cp)
  {

arch/x86/kvm/pmu.c static int cmp_u64(const void *a, const void *b) · line 188

Quoted 9 lines
arch/x86/kvm/pmu.c +2 -1
@@ -181,7 +181,8 @@ static int cmp_u64(const void *a, const void *b)
 
  void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
  {
-	unsigned config, type = PERF_TYPE_RAW;
+	u64 config;
+	u32 type = PERF_TYPE_RAW;
  	struct kvm *kvm = pmc->vcpu->kvm;
  	struct kvm_pmu_event_filter *filter;
  	bool allow_event = true;

Queued both, thanks.

Paolo