kvm: x86: limit the maximum number of vPMU fixed counters to 3
PATCH 1/1 kvm: x86: limit the maximum number of vPMU fixed counters to 3
Some new Intel platforms (such as TGL) already have the fourth fixed counter TOPDOWN.SLOTS, but it has not been fully enabled on KVM and the host.
Therefore, we limit edx.split.num_counters_fixed to 3, so that it does not break the kvm-unit-tests PMU test case and bad-handled userspace.
--- arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/pmu.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
arch/x86/kvm/cpuid.c +1 -1
@@ -604,7 +604,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) eax.split.bit_width = cap.bit_width_gp; eax.split.mask_length = cap.events_mask_len; - edx.split.num_counters_fixed = cap.num_counters_fixed; + edx.split.num_counters_fixed =min (cap.num_counters_fixed,MAX_FIXED_COUNTERS ); edx.split.bit_width_fixed = cap.bit_width_fixed; edx.split.reserved =0 ;
arch/x86/kvm/pmu.h +2 -0
@@ -15,6 +15,8 @@#define VMWARE_BACKDOOR_PMC_REAL_TIME 0x10001#define VMWARE_BACKDOOR_PMC_APPARENT_TIME 0x10002 +#define MAX_FIXED_COUNTERS 3 +struct kvm_event_hw_type_mapping {u8 eventsel;u8 unit_mask;
Signature · 1 line
2.21.3
Kindly ping.
I think we may need this patch, as we limit the maximum vPMU version to 2:
eax.split.version_id = min(cap.version, 2);
Thanks,
Like Xu
Quoted 40 lines · Like Xu
Some new Intel platforms (such as TGL) already have the fourth fixed counter TOPDOWN.SLOTS, but it has not been fully enabled on KVM and the host.
Therefore, we limit edx.split.num_counters_fixed to 3, so that it does not break the kvm-unit-tests PMU test case and bad-handled userspace.
Signed-off-by Like Xu <[email protected]>--- arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/pmu.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)arch/x86/kvm/cpuid.c +1
-1@@ -604,7 +604,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) eax.split.bit_width = cap.bit_width_gp; eax.split.mask_length = cap.events_mask_len; - edx.split.num_counters_fixed = cap.num_counters_fixed; + edx.split.num_counters_fixed =min (cap.num_counters_fixed,MAX_FIXED_COUNTERS ); edx.split.bit_width_fixed = cap.bit_width_fixed; edx.split.reserved =0 ;arch/x86/kvm/pmu.h +2
-0@@ -15,6 +15,8 @@#define VMWARE_BACKDOOR_PMC_REAL_TIME 0x10001#define VMWARE_BACKDOOR_PMC_APPARENT_TIME 0x10002 +#define MAX_FIXED_COUNTERS 3 +struct kvm_event_hw_type_mapping {u8 eventsel;u8 unit_mask;
Paolo Bonzini
maintainerQuoted 4 lines · Like
Kindly ping.
I think we may need this patch, as we limit the maximum vPMU version to 2:
eax.split.version_id =min(cap.version, 2);
I don't think this is a problem. Are you planning to add support for the fourth counter?
Paolo
Quoted 7 lines · Paolo Bonzini
Quoted 4 lines · Like
Kindly ping.
I think we may need this patch, as we limit the maximum vPMU version to 2:
eax.split.version_id =min(cap.version, 2);I don't think this is a problem. Are you planning to add support for the fourth counter?
Yes, we plan to provide this support on the KVM after fully enabling the fourth counter (and an accompanying special counter) on the host perf side.
This may require one or two kernel cycles, so I have to prevent it from being exposed to non-linux guest with this fix. Thanks for your support.
Thanks,
Like Xu
Quoted 3 lines
Paolo
Quoted 33 lines · Like Xu
Some new Intel platforms (such as TGL) already have the fourth fixed counter TOPDOWN.SLOTS, but it has not been fully enabled on KVM and the host.
Therefore, we limit edx.split.num_counters_fixed to 3, so that it does not break the kvm-unit-tests PMU test case and bad-handled userspace.
Signed-off-by Like Xu <[email protected]>--- arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/pmu.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)arch/x86/kvm/cpuid.c +1
-1@@ -604,7 +604,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) eax.split.bit_width = cap.bit_width_gp; eax.split.mask_length = cap.events_mask_len; - edx.split.num_counters_fixed = cap.num_counters_fixed; + edx.split.num_counters_fixed =min (cap.num_counters_fixed,MAX_FIXED_COUNTERS ); edx.split.bit_width_fixed = cap.bit_width_fixed; edx.split.reserved =0 ;arch/x86/kvm/pmu.h +0
-0
arch/x86/kvm/pmu.h line 22
Quoted 8 lines
arch/x86/kvm/pmu.h +2
-0@@ -15,6 +15,8 @@#define VMWARE_BACKDOOR_PMC_REAL_TIME 0x10001#define VMWARE_BACKDOOR_PMC_APPARENT_TIME 0x10002 +#define MAX_FIXED_COUNTERS 3 +struct kvm_event_hw_type_mapping {u8 eventsel;u8 unit_mask;
Queued, thanks.
Paolo