Skip to content

Commit ef98406

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: Replace vCPU target with a configuration flag
The value of kvm_vcpu_arch::target has been used to determine if a vCPU has actually been initialized. Storing this as an integer is needless at this point, as KVM doesn't do any microarch-specific emulation in the first place. Instead, all we care about is whether or not the vCPU has been initialized. Delete the field in favor of a vCPU configuration flag indicating if KVM_ARM_VCPU_INIT has completed for the vCPU. Reviewed-by: Zenghui Yu <yuzenghui@huawei.com> Signed-off-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20230710193140.1706399-4-oliver.upton@linux.dev
1 parent c8a6772 commit ef98406

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,7 @@ struct kvm_vcpu_arch {
567567
/* Cache some mmu pages needed inside spinlock regions */
568568
struct kvm_mmu_memory_cache mmu_page_cache;
569569

570-
/* Target CPU and feature flags */
571-
int target;
570+
/* feature flags */
572571
DECLARE_BITMAP(features, KVM_VCPU_MAX_FEATURES);
573572

574573
/* Virtual SError ESR to restore when HCR_EL2.VSE is set */
@@ -669,6 +668,8 @@ struct kvm_vcpu_arch {
669668
#define VCPU_SVE_FINALIZED __vcpu_single_flag(cflags, BIT(1))
670669
/* PTRAUTH exposed to guest */
671670
#define GUEST_HAS_PTRAUTH __vcpu_single_flag(cflags, BIT(2))
671+
/* KVM_ARM_VCPU_INIT completed */
672+
#define VCPU_INITIALIZED __vcpu_single_flag(cflags, BIT(3))
672673

673674
/* Exception pending */
674675
#define PENDING_EXCEPTION __vcpu_single_flag(iflags, BIT(0))

arch/arm64/kvm/arm.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
360360
#endif
361361

362362
/* Force users to call KVM_ARM_VCPU_INIT */
363-
vcpu->arch.target = -1;
363+
vcpu_clear_flag(vcpu, VCPU_INITIALIZED);
364364
bitmap_zero(vcpu->arch.features, KVM_VCPU_MAX_FEATURES);
365365

366366
vcpu->arch.mmu_page_cache.gfp_zero = __GFP_ZERO;
@@ -569,7 +569,7 @@ unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu)
569569

570570
static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu)
571571
{
572-
return vcpu->arch.target >= 0;
572+
return vcpu_get_flag(vcpu, VCPU_INITIALIZED);
573573
}
574574

575575
/*
@@ -1051,7 +1051,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
10511051
* invalid. The VMM can try and fix it by issuing a
10521052
* KVM_ARM_VCPU_INIT if it really wants to.
10531053
*/
1054-
vcpu->arch.target = -1;
1054+
vcpu_clear_flag(vcpu, VCPU_INITIALIZED);
10551055
ret = ARM_EXCEPTION_IL;
10561056
}
10571057

@@ -1228,20 +1228,18 @@ static int __kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
12281228
!bitmap_equal(kvm->arch.vcpu_features, &features, KVM_VCPU_MAX_FEATURES))
12291229
goto out_unlock;
12301230

1231-
vcpu->arch.target = init->target;
12321231
bitmap_copy(vcpu->arch.features, &features, KVM_VCPU_MAX_FEATURES);
12331232

12341233
/* Now we know what it is, we can reset it. */
12351234
ret = kvm_reset_vcpu(vcpu);
12361235
if (ret) {
1237-
vcpu->arch.target = -1;
12381236
bitmap_zero(vcpu->arch.features, KVM_VCPU_MAX_FEATURES);
12391237
goto out_unlock;
12401238
}
12411239

12421240
bitmap_copy(kvm->arch.vcpu_features, &features, KVM_VCPU_MAX_FEATURES);
12431241
set_bit(KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED, &kvm->arch.flags);
1244-
1242+
vcpu_set_flag(vcpu, VCPU_INITIALIZED);
12451243
out_unlock:
12461244
mutex_unlock(&kvm->arch.config_lock);
12471245
return ret;
@@ -1259,7 +1257,7 @@ static int kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
12591257
if (ret)
12601258
return ret;
12611259

1262-
if (vcpu->arch.target == -1)
1260+
if (!kvm_vcpu_initialized(vcpu))
12631261
return __kvm_vcpu_set_target(vcpu, init);
12641262

12651263
if (kvm_vcpu_init_changed(vcpu, init))

arch/arm64/kvm/hyp/nvhe/switch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static void early_exit_filter(struct kvm_vcpu *vcpu, u64 *exit_code)
236236
* KVM_ARM_VCPU_INIT, however, this is likely not possible for
237237
* protected VMs.
238238
*/
239-
vcpu->arch.target = -1;
239+
vcpu_clear_flag(vcpu, VCPU_INITIALIZED);
240240
*exit_code &= BIT(ARM_EXIT_WITH_SERROR_BIT);
241241
*exit_code |= ARM_EXCEPTION_IL;
242242
}

0 commit comments

Comments
 (0)