Skip to content

Commit 557abc4

Browse files
committed
KVM: remove kvm_vcpu_compatible
The new created_vcpus field makes it possible to avoid the race between irqchip and VCPU creation in a much nicer way; just check under kvm->lock whether a VCPU has already been created. We can then remove KVM_APIC_ARCHITECTURE too, because at this point the symbol is only governing the default definition of kvm_vcpu_compatible. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 6c7caeb commit 557abc4

5 files changed

Lines changed: 3 additions & 22 deletions

File tree

‎arch/x86/kvm/Kconfig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ config KVM
3232
select HAVE_KVM_IRQ_BYPASS
3333
select HAVE_KVM_IRQ_ROUTING
3434
select HAVE_KVM_EVENTFD
35-
select KVM_APIC_ARCHITECTURE
3635
select KVM_ASYNC_PF
3736
select USER_RETURN_NOTIFIER
3837
select KVM_MMIO

‎arch/x86/kvm/x86.c‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3774,7 +3774,7 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
37743774
r = -EEXIST;
37753775
if (irqchip_in_kernel(kvm))
37763776
goto split_irqchip_unlock;
3777-
if (atomic_read(&kvm->online_vcpus))
3777+
if (kvm->created_vcpus)
37783778
goto split_irqchip_unlock;
37793779
r = kvm_setup_empty_irq_routing(kvm);
37803780
if (r)
@@ -3839,7 +3839,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
38393839
if (kvm->arch.vpic)
38403840
goto create_irqchip_unlock;
38413841
r = -EINVAL;
3842-
if (atomic_read(&kvm->online_vcpus))
3842+
if (kvm->created_vcpus)
38433843
goto create_irqchip_unlock;
38443844
r = -ENOMEM;
38453845
vpic = kvm_create_pic(kvm);
@@ -3995,7 +3995,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
39953995
case KVM_SET_BOOT_CPU_ID:
39963996
r = 0;
39973997
mutex_lock(&kvm->lock);
3998-
if (atomic_read(&kvm->online_vcpus) != 0)
3998+
if (kvm->created_vcpus)
39993999
r = -EBUSY;
40004000
else
40014001
kvm->arch.bsp_vcpu_id = arg;
@@ -7639,11 +7639,6 @@ bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
76397639
return (vcpu->arch.apic_base & MSR_IA32_APICBASE_BSP) != 0;
76407640
}
76417641

7642-
bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu)
7643-
{
7644-
return irqchip_in_kernel(vcpu->kvm) == lapic_in_kernel(vcpu);
7645-
}
7646-
76477642
struct static_key kvm_no_apic_vcpu __read_mostly;
76487643
EXPORT_SYMBOL_GPL(kvm_no_apic_vcpu);
76497644

‎include/linux/kvm_host.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,12 +1105,6 @@ static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
11051105

11061106
#endif /* CONFIG_HAVE_KVM_EVENTFD */
11071107

1108-
#ifdef CONFIG_KVM_APIC_ARCHITECTURE
1109-
bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu);
1110-
#else
1111-
static inline bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu) { return true; }
1112-
#endif
1113-
11141108
static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu)
11151109
{
11161110
/*

‎virt/kvm/Kconfig‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ config HAVE_KVM_EVENTFD
1616
bool
1717
select EVENTFD
1818

19-
config KVM_APIC_ARCHITECTURE
20-
bool
21-
2219
config KVM_MMIO
2320
bool
2421

‎virt/kvm/kvm_main.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,10 +2368,6 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
23682368
goto vcpu_destroy;
23692369

23702370
mutex_lock(&kvm->lock);
2371-
if (!kvm_vcpu_compatible(vcpu)) {
2372-
r = -EINVAL;
2373-
goto unlock_vcpu_destroy;
2374-
}
23752371
if (kvm_get_vcpu_by_id(kvm, id)) {
23762372
r = -EEXIST;
23772373
goto unlock_vcpu_destroy;

0 commit comments

Comments
 (0)