Skip to content

Commit 1de10b7

Browse files
committed
KVM: arm64: Get rid of vCPU-scoped feature bitmap
The vCPU-scoped feature bitmap was left in place a couple of releases ago in case the change to VM-scoped vCPU features broke anyone. Nobody has complained and the interop between VM and vCPU bitmaps is pretty gross. Throw it out. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 3d4b2a4 commit 1de10b7

File tree

8 files changed

+18
-22
lines changed

8 files changed

+18
-22
lines changed

arch/arm64/include/asm/kvm_emulate.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu);
5454
int kvm_inject_nested_sync(struct kvm_vcpu *vcpu, u64 esr_el2);
5555
int kvm_inject_nested_irq(struct kvm_vcpu *vcpu);
5656

57+
static inline bool vcpu_has_feature(const struct kvm_vcpu *vcpu, int feature)
58+
{
59+
return test_bit(feature, vcpu->kvm->arch.vcpu_features);
60+
}
61+
5762
#if defined(__KVM_VHE_HYPERVISOR__) || defined(__KVM_NVHE_HYPERVISOR__)
5863
static __always_inline bool vcpu_el1_is_32bit(struct kvm_vcpu *vcpu)
5964
{
@@ -62,7 +67,7 @@ static __always_inline bool vcpu_el1_is_32bit(struct kvm_vcpu *vcpu)
6267
#else
6368
static __always_inline bool vcpu_el1_is_32bit(struct kvm_vcpu *vcpu)
6469
{
65-
return test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features);
70+
return vcpu_has_feature(vcpu, KVM_ARM_VCPU_EL1_32BIT);
6671
}
6772
#endif
6873

@@ -565,12 +570,6 @@ static __always_inline void kvm_incr_pc(struct kvm_vcpu *vcpu)
565570
vcpu_set_flag((v), e); \
566571
} while (0)
567572

568-
569-
static inline bool vcpu_has_feature(struct kvm_vcpu *vcpu, int feature)
570-
{
571-
return test_bit(feature, vcpu->arch.features);
572-
}
573-
574573
static __always_inline void kvm_write_cptr_el2(u64 val)
575574
{
576575
if (has_vhe() || has_hvhe())

arch/arm64/include/asm/kvm_host.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,6 @@ struct kvm_vcpu_arch {
574574
/* Cache some mmu pages needed inside spinlock regions */
575575
struct kvm_mmu_memory_cache mmu_page_cache;
576576

577-
/* feature flags */
578-
DECLARE_BITMAP(features, KVM_VCPU_MAX_FEATURES);
579-
580577
/* Virtual SError ESR to restore when HCR_EL2.VSE is set */
581578
u64 vsesr_el2;
582579

arch/arm64/include/asm/kvm_nested.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
#ifndef __ARM64_KVM_NESTED_H
33
#define __ARM64_KVM_NESTED_H
44

5+
#include <asm/kvm_emulate.h>
56
#include <linux/kvm_host.h>
67

78
static inline bool vcpu_has_nv(const struct kvm_vcpu *vcpu)
89
{
910
return (!__is_defined(__KVM_NVHE_HYPERVISOR__) &&
1011
cpus_have_final_cap(ARM64_HAS_NESTED_VIRT) &&
11-
test_bit(KVM_ARM_VCPU_HAS_EL2, vcpu->arch.features));
12+
vcpu_has_feature(vcpu, KVM_ARM_VCPU_HAS_EL2));
1213
}
1314

1415
extern bool __check_nv_sr_forward(struct kvm_vcpu *vcpu);

arch/arm64/kvm/arm.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
367367

368368
/* Force users to call KVM_ARM_VCPU_INIT */
369369
vcpu_clear_flag(vcpu, VCPU_INITIALIZED);
370-
bitmap_zero(vcpu->arch.features, KVM_VCPU_MAX_FEATURES);
371370

372371
vcpu->arch.mmu_page_cache.gfp_zero = __GFP_ZERO;
373372

@@ -1263,7 +1262,8 @@ static bool kvm_vcpu_init_changed(struct kvm_vcpu *vcpu,
12631262
{
12641263
unsigned long features = init->features[0];
12651264

1266-
return !bitmap_equal(vcpu->arch.features, &features, KVM_VCPU_MAX_FEATURES);
1265+
return !bitmap_equal(vcpu->kvm->arch.vcpu_features, &features,
1266+
KVM_VCPU_MAX_FEATURES);
12671267
}
12681268

12691269
static int __kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
@@ -1276,15 +1276,14 @@ static int __kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
12761276
mutex_lock(&kvm->arch.config_lock);
12771277

12781278
if (test_bit(KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED, &kvm->arch.flags) &&
1279-
!bitmap_equal(kvm->arch.vcpu_features, &features, KVM_VCPU_MAX_FEATURES))
1279+
kvm_vcpu_init_changed(vcpu, init))
12801280
goto out_unlock;
12811281

1282-
bitmap_copy(vcpu->arch.features, &features, KVM_VCPU_MAX_FEATURES);
1282+
bitmap_copy(kvm->arch.vcpu_features, &features, KVM_VCPU_MAX_FEATURES);
12831283

12841284
/* Now we know what it is, we can reset it. */
12851285
kvm_reset_vcpu(vcpu);
12861286

1287-
bitmap_copy(kvm->arch.vcpu_features, &features, KVM_VCPU_MAX_FEATURES);
12881287
set_bit(KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED, &kvm->arch.flags);
12891288
vcpu_set_flag(vcpu, VCPU_INITIALIZED);
12901289
ret = 0;

arch/arm64/kvm/hypercalls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
554554
{
555555
bool wants_02;
556556

557-
wants_02 = test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features);
557+
wants_02 = vcpu_has_feature(vcpu, KVM_ARM_VCPU_PSCI_0_2);
558558

559559
switch (val) {
560560
case KVM_ARM_PSCI_0_1:

arch/arm64/kvm/reset.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
208208
kvm_arch_vcpu_put(vcpu);
209209

210210
if (!kvm_arm_vcpu_sve_finalized(vcpu)) {
211-
if (test_bit(KVM_ARM_VCPU_SVE, vcpu->arch.features))
211+
if (vcpu_has_feature(vcpu, KVM_ARM_VCPU_SVE))
212212
kvm_vcpu_enable_sve(vcpu);
213213
} else {
214214
kvm_vcpu_reset_sve(vcpu);
215215
}
216216

217-
if (test_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, vcpu->arch.features) ||
218-
test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, vcpu->arch.features))
217+
if (vcpu_has_feature(vcpu, KVM_ARM_VCPU_PTRAUTH_ADDRESS) ||
218+
vcpu_has_feature(vcpu, KVM_ARM_VCPU_PTRAUTH_GENERIC))
219219
kvm_vcpu_enable_ptrauth(vcpu);
220220

221221
if (vcpu_el1_is_32bit(vcpu))

include/kvm/arm_pmu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu);
7777
void kvm_vcpu_pmu_resync_el0(void);
7878

7979
#define kvm_vcpu_has_pmu(vcpu) \
80-
(test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features))
80+
(vcpu_has_feature(vcpu, KVM_ARM_VCPU_PMU_V3))
8181

8282
/*
8383
* Updates the vcpu's view of the pmu events for this cpu.

include/kvm/arm_psci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static inline int kvm_psci_version(struct kvm_vcpu *vcpu)
2626
* revisions. It is thus safe to return the latest, unless
2727
* userspace has instructed us otherwise.
2828
*/
29-
if (test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features)) {
29+
if (vcpu_has_feature(vcpu, KVM_ARM_VCPU_PSCI_0_2)) {
3030
if (vcpu->kvm->arch.psci_version)
3131
return vcpu->kvm->arch.psci_version;
3232

0 commit comments

Comments
 (0)