Re: [RFC PATCH v3 19/58] KVM: x86/pmu: Plumb through pass-through PMU to vcpu for Intel CPUs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/21/2024 12:45 AM, Sean Christopherson wrote:
> On Wed, Nov 20, 2024, Dapeng Mi wrote:
>> On 11/19/2024 10:54 PM, Sean Christopherson wrote:
>>> On Thu, Aug 01, 2024, Mingwei Zhang wrote:
>>>> Plumb through pass-through PMU setting from kvm->arch into kvm_pmu on each
>>>> vcpu created. Note that enabling PMU is decided by VMM when it sets the
>>>> CPUID bits exposed to guest VM. So plumb through the enabling for each pmu
>>>> in intel_pmu_refresh().
>>> Why?  As with the per-VM snapshot, I see zero reason for this to exist, it's
>>> simply:
>>>
>>>   kvm->arch.enable_pmu && enable_mediated_pmu && pmu->version;
>>>
>>> And in literally every correct usage of pmu->passthrough, kvm->arch.enable_pmu
>>> and pmu->version have been checked (though implicitly), i.e. KVM can check
>>> enable_mediated_pmu and nothing else.
>> Ok, too many passthrough_pmu flags indeed confuse readers. Besides these
>> dependencies, mediated vPMU also depends on lapic_in_kernel(). We need to
>> set enable_mediated_pmu to false as well if lapic_in_kernel() returns false.
> No, just kill the entire vPMU.
>
> Also, the need for an in-kernel APIC isn't unique to the mediated PMU.  KVM simply
> drops PMIs if there's no APIC.
>
> If we're feeling lucky, we could try a breaking change like so:
>
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index fcd188cc389a..bb08155f6198 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -817,7 +817,7 @@ void kvm_pmu_refresh(struct kvm_vcpu *vcpu)
>         pmu->pebs_data_cfg_mask = ~0ull;
>         bitmap_zero(pmu->all_valid_pmc_idx, X86_PMC_IDX_MAX);
>  
> -       if (!vcpu->kvm->arch.enable_pmu)
> +       if (!vcpu->kvm->arch.enable_pmu || !lapic_in_kernel(vcpu))
>                 return;
>  
>         static_call(kvm_x86_pmu_refresh)(vcpu);
>
>
> If we don't want to risk breaking weird setups, we could restrict the behavior
> to the mediated PMU being enabled:
>
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index fcd188cc389a..bc9673190574 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -817,7 +817,8 @@ void kvm_pmu_refresh(struct kvm_vcpu *vcpu)
>         pmu->pebs_data_cfg_mask = ~0ull;
>         bitmap_zero(pmu->all_valid_pmc_idx, X86_PMC_IDX_MAX);
>  
> -       if (!vcpu->kvm->arch.enable_pmu)
> +       if (!vcpu->kvm->arch.enable_pmu ||
> +           (!lapic_in_kernel(vcpu) && enable_mediated_pmu))
>                 return;
>  
>         static_call(kvm_x86_pmu_refresh)(vcpu);

Sure. would adopt the latter one for safe. :)






[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux