[PATCH v6 02/11] KVM: arm64: PMU: Set the default PMU for the guest on vCPU reset

Oliver Upton oliver.upton at linux.dev
Wed Sep 27 01:02:40 PDT 2023


Hi Raghu,

On Tue, Sep 26, 2023 at 11:39:59PM +0000, Raghavendra Rao Ananta wrote:
> From: Reiji Watanabe <reijiw at google.com>
> 
> The following patches will use the number of counters information
> from the arm_pmu and use this to set the PMCR.N for the guest
> during vCPU reset. However, since the guest is not associated
> with any arm_pmu until userspace configures the vPMU device
> attributes, and a reset can happen before this event, call
> kvm_arm_support_pmu_v3() just before doing the reset.
> 
> No functional change intended.

I would argue there still is a functional change here, as PMU
initialization failure now shows up on a completely different ioctl for
userspace.

> @@ -216,6 +217,18 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
>  	vcpu->arch.reset_state.reset = false;
>  	spin_unlock(&vcpu->arch.mp_state_lock);
>  
> +	if (kvm_vcpu_has_pmu(vcpu)) {
> +		if (!kvm_arm_support_pmu_v3())
> +			return -EINVAL;
> +
> +		/*
> +		 * When the vCPU has a PMU, but no PMU is set for the guest
> +		 * yet, set the default one.
> +		 */
> +		if (unlikely(!kvm->arch.arm_pmu) && kvm_arm_set_default_pmu(kvm))
> +			return -EINVAL;
> +	}
> +

Ah, this probably will not mix well with my recent change to get rid of
the return value altogether from kvm_reset_vcpu() [*]. I see two ways to
handle this:

 - Add a separate helper responsible for one-time setup of the vCPU
   called from KVM_ARM_VCPU_INIT which may fail.

 - Add a check for !kvm->arch.arm_pmu to kvm_arm_pmu_v3_init().

No strong preference, though.

[*]: https://lore.kernel.org/r/20230920195036.1169791-8-oliver.upton@linux.dev

-- 
Thanks,
Oliver



More information about the linux-arm-kernel mailing list