Skip to content

Commit 1616ca6

Browse files
reijiw-kvmoupton
authored andcommitted
KVM: arm64: PMU: Introduce helpers to set the guest's PMU
Introduce new helper functions to set the guest's PMU (kvm->arch.arm_pmu) either to a default probed instance or to a caller requested one, and use it when the guest's PMU needs to be set. These helpers will make it easier for the following patches to modify the relevant code. No functional change intended. Reviewed-by: Sebastian Ott <[email protected]> Signed-off-by: Reiji Watanabe <[email protected]> Signed-off-by: Raghavendra Rao Ananta <[email protected]> Reviewed-by: Eric Auger <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 6465e26 commit 1616ca6

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

arch/arm64/kvm/pmu-emul.c

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,36 @@ static bool pmu_irq_is_valid(struct kvm *kvm, int irq)
874874
return true;
875875
}
876876

877+
static void kvm_arm_set_pmu(struct kvm *kvm, struct arm_pmu *arm_pmu)
878+
{
879+
lockdep_assert_held(&kvm->arch.config_lock);
880+
881+
kvm->arch.arm_pmu = arm_pmu;
882+
}
883+
884+
/**
885+
* kvm_arm_set_default_pmu - No PMU set, get the default one.
886+
* @kvm: The kvm pointer
887+
*
888+
* The observant among you will notice that the supported_cpus
889+
* mask does not get updated for the default PMU even though it
890+
* is quite possible the selected instance supports only a
891+
* subset of cores in the system. This is intentional, and
892+
* upholds the preexisting behavior on heterogeneous systems
893+
* where vCPUs can be scheduled on any core but the guest
894+
* counters could stop working.
895+
*/
896+
static int kvm_arm_set_default_pmu(struct kvm *kvm)
897+
{
898+
struct arm_pmu *arm_pmu = kvm_pmu_probe_armpmu();
899+
900+
if (!arm_pmu)
901+
return -ENODEV;
902+
903+
kvm_arm_set_pmu(kvm, arm_pmu);
904+
return 0;
905+
}
906+
877907
static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id)
878908
{
879909
struct kvm *kvm = vcpu->kvm;
@@ -893,7 +923,7 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id)
893923
break;
894924
}
895925

896-
kvm->arch.arm_pmu = arm_pmu;
926+
kvm_arm_set_pmu(kvm, arm_pmu);
897927
cpumask_copy(kvm->arch.supported_cpus, &arm_pmu->supported_cpus);
898928
ret = 0;
899929
break;
@@ -917,20 +947,10 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
917947
return -EBUSY;
918948

919949
if (!kvm->arch.arm_pmu) {
920-
/*
921-
* No PMU set, get the default one.
922-
*
923-
* The observant among you will notice that the supported_cpus
924-
* mask does not get updated for the default PMU even though it
925-
* is quite possible the selected instance supports only a
926-
* subset of cores in the system. This is intentional, and
927-
* upholds the preexisting behavior on heterogeneous systems
928-
* where vCPUs can be scheduled on any core but the guest
929-
* counters could stop working.
930-
*/
931-
kvm->arch.arm_pmu = kvm_pmu_probe_armpmu();
932-
if (!kvm->arch.arm_pmu)
933-
return -ENODEV;
950+
int ret = kvm_arm_set_default_pmu(kvm);
951+
952+
if (ret)
953+
return ret;
934954
}
935955

936956
switch (attr->attr) {

0 commit comments

Comments
 (0)