Skip to content

Commit de40bb8

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: Add a helper to check if a VM has ran once
The test_bit(...) pattern is quite a lot of keystrokes. Replace existing callsites with a helper. No functional change intended. Signed-off-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20230404154050.2270077-3-oliver.upton@linux.dev
1 parent e65733b commit de40bb8

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

arch/arm64/include/asm/kvm_host.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,9 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu);
10611061
(system_supports_32bit_el0() && \
10621062
!static_branch_unlikely(&arm64_mismatched_32bit_el0))
10631063

1064+
#define kvm_vm_has_ran_once(kvm) \
1065+
(test_bit(KVM_ARCH_FLAG_HAS_RAN_ONCE, &(kvm)->arch.flags))
1066+
10641067
int kvm_trng_call(struct kvm_vcpu *vcpu);
10651068
#ifdef CONFIG_KVM
10661069
extern phys_addr_t hyp_mem_base;

arch/arm64/kvm/hypercalls.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,7 @@ static int kvm_arm_set_fw_reg_bmap(struct kvm_vcpu *vcpu, u64 reg_id, u64 val)
379379

380380
mutex_lock(&kvm->lock);
381381

382-
if (test_bit(KVM_ARCH_FLAG_HAS_RAN_ONCE, &kvm->arch.flags) &&
383-
val != *fw_reg_bmap) {
382+
if (kvm_vm_has_ran_once(kvm) && val != *fw_reg_bmap) {
384383
ret = -EBUSY;
385384
goto out;
386385
}

arch/arm64/kvm/pmu-emul.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id)
880880
list_for_each_entry(entry, &arm_pmus, entry) {
881881
arm_pmu = entry->arm_pmu;
882882
if (arm_pmu->pmu.type == pmu_id) {
883-
if (test_bit(KVM_ARCH_FLAG_HAS_RAN_ONCE, &kvm->arch.flags) ||
883+
if (kvm_vm_has_ran_once(kvm) ||
884884
(kvm->arch.pmu_filter && kvm->arch.arm_pmu != arm_pmu)) {
885885
ret = -EBUSY;
886886
break;
@@ -963,7 +963,7 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
963963

964964
mutex_lock(&kvm->lock);
965965

966-
if (test_bit(KVM_ARCH_FLAG_HAS_RAN_ONCE, &kvm->arch.flags)) {
966+
if (kvm_vm_has_ran_once(kvm)) {
967967
mutex_unlock(&kvm->lock);
968968
return -EBUSY;
969969
}

0 commit comments

Comments
 (0)