Re: [PATCH 1/2] KVM: vmx/pmu: Indicate available fixed function PMCs through a bitmap

Sean Christopherson
2023-05-25T22:35:25Z

On Thu, Apr 27, 2023, Anselm Busse wrote:
> This commit changes the tracking of available fixed function counters
> from a number to a bitmap.
>
> Starting with Intel PMU v5, the available fixed function counters cannot
> only be advertised through a number, but also through a bitmap in
> CPUID.0AH.ECX. However, the current KVM implementation determines if a
> fixed function PMC is available to a guest purely based on the number
> of exposed fixed function PMCs. This makes it impossible to use this
> new feature of the Intel PMU v5. Therefore, this change serves as a
> preparation to seamlessly enable the virtualization of Intel PMU v5 in
> the future.
>
> No functional change intended.
>
> Signed-off-by: Anselm Busse <abusse@amazon.com>
> ---
> arch/x86/include/asm/kvm_host.h | 2 +-
> arch/x86/kvm/pmu.h | 6 +++---
> arch/x86/kvm/svm/pmu.c | 2 +-
> arch/x86/kvm/vmx/pmu_intel.c | 33 ++++++++++++++++++---------------
> 4 files changed, 23 insertions(+), 20 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 808c292ad3f4..ea4859554678 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -516,7 +516,7 @@ struct kvm_pmc {
> #define KVM_AMD_PMC_MAX_GENERIC 6
> struct kvm_pmu {
> unsigned nr_arch_gp_counters;
> - unsigned nr_arch_fixed_counters;
> + DECLARE_BITMAP(mask_arch_fixed_counters, INTEL_PMC_MAX_FIXED);

Please see the feedback I gave to Like[*]. Unless I'm missing something, there's
no need for another bitmap.

[*] https://lore.kernel.org/kvm/ZB4oUhmIKPF2lAzN@google.com