Commit 637e3f86 authored by David Hildenbrand's avatar David Hildenbrand Committed by Radim Krčmář

KVM: x86: new irqchip mode KVM_IRQCHIP_INIT_IN_PROGRESS

Let's add a new mode and set it while we create the irqchip via
KVM_CREATE_IRQCHIP and KVM_CAP_SPLIT_IRQCHIP.

This mode will be used later to test if adding routes
(in kvm_set_routing_entry()) is already allowed.
Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
parent 1df6dded
...@@ -726,6 +726,7 @@ struct kvm_hv { ...@@ -726,6 +726,7 @@ struct kvm_hv {
enum kvm_irqchip_mode { enum kvm_irqchip_mode {
KVM_IRQCHIP_NONE, KVM_IRQCHIP_NONE,
KVM_IRQCHIP_INIT_IN_PROGRESS, /* temporarily set during creation */
KVM_IRQCHIP_KERNEL, /* created with KVM_CREATE_IRQCHIP */ KVM_IRQCHIP_KERNEL, /* created with KVM_CREATE_IRQCHIP */
KVM_IRQCHIP_SPLIT, /* created with KVM_CAP_SPLIT_IRQCHIP */ KVM_IRQCHIP_SPLIT, /* created with KVM_CAP_SPLIT_IRQCHIP */
}; };
......
...@@ -93,21 +93,29 @@ static inline int pic_in_kernel(struct kvm *kvm) ...@@ -93,21 +93,29 @@ static inline int pic_in_kernel(struct kvm *kvm)
static inline int irqchip_split(struct kvm *kvm) static inline int irqchip_split(struct kvm *kvm)
{ {
return kvm->arch.irqchip_mode == KVM_IRQCHIP_SPLIT; int mode = kvm->arch.irqchip_mode;
/* Matches smp_wmb() when setting irqchip_mode */
smp_rmb();
return mode == KVM_IRQCHIP_SPLIT;
} }
static inline int irqchip_kernel(struct kvm *kvm) static inline int irqchip_kernel(struct kvm *kvm)
{ {
return kvm->arch.irqchip_mode == KVM_IRQCHIP_KERNEL; int mode = kvm->arch.irqchip_mode;
/* Matches smp_wmb() when setting irqchip_mode */
smp_rmb();
return mode == KVM_IRQCHIP_KERNEL;
} }
static inline int irqchip_in_kernel(struct kvm *kvm) static inline int irqchip_in_kernel(struct kvm *kvm)
{ {
bool ret = kvm->arch.irqchip_mode != KVM_IRQCHIP_NONE; int mode = kvm->arch.irqchip_mode;
/* Matches with wmb after initializing kvm->irq_routing. */ /* Matches smp_wmb() when setting irqchip_mode */
smp_rmb(); smp_rmb();
return ret; return mode > KVM_IRQCHIP_INIT_IN_PROGRESS;
} }
void kvm_pic_reset(struct kvm_kpic_state *s); void kvm_pic_reset(struct kvm_kpic_state *s);
......
...@@ -3928,9 +3928,14 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm, ...@@ -3928,9 +3928,14 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
goto split_irqchip_unlock; goto split_irqchip_unlock;
if (kvm->created_vcpus) if (kvm->created_vcpus)
goto split_irqchip_unlock; goto split_irqchip_unlock;
kvm->arch.irqchip_mode = KVM_IRQCHIP_INIT_IN_PROGRESS;
r = kvm_setup_empty_irq_routing(kvm); r = kvm_setup_empty_irq_routing(kvm);
if (r) if (r) {
kvm->arch.irqchip_mode = KVM_IRQCHIP_NONE;
/* Pairs with smp_rmb() when reading irqchip_mode */
smp_wmb();
goto split_irqchip_unlock; goto split_irqchip_unlock;
}
/* Pairs with irqchip_in_kernel. */ /* Pairs with irqchip_in_kernel. */
smp_wmb(); smp_wmb();
kvm->arch.irqchip_mode = KVM_IRQCHIP_SPLIT; kvm->arch.irqchip_mode = KVM_IRQCHIP_SPLIT;
...@@ -4018,8 +4023,12 @@ long kvm_arch_vm_ioctl(struct file *filp, ...@@ -4018,8 +4023,12 @@ long kvm_arch_vm_ioctl(struct file *filp,
goto create_irqchip_unlock; goto create_irqchip_unlock;
} }
kvm->arch.irqchip_mode = KVM_IRQCHIP_INIT_IN_PROGRESS;
r = kvm_setup_default_irq_routing(kvm); r = kvm_setup_default_irq_routing(kvm);
if (r) { if (r) {
kvm->arch.irqchip_mode = KVM_IRQCHIP_NONE;
/* Pairs with smp_rmb() when reading irqchip_mode */
smp_wmb();
mutex_lock(&kvm->slots_lock); mutex_lock(&kvm->slots_lock);
mutex_lock(&kvm->irq_lock); mutex_lock(&kvm->irq_lock);
kvm_ioapic_destroy(kvm); kvm_ioapic_destroy(kvm);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment