Commit 49776faf authored by Radim Krčmář's avatar Radim Krčmář

KVM: x86: decouple irqchip_in_kernel() and pic_irqchip()

irqchip_in_kernel() tried to save a bit by reusing pic_irqchip(), but it
just complicated the code.
Add a separate state for the irqchip mode.
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
[Used Paolo's version of condition in irqchip_in_kernel().]
Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
parent 35e6eaa3
...@@ -716,6 +716,12 @@ struct kvm_hv { ...@@ -716,6 +716,12 @@ struct kvm_hv {
HV_REFERENCE_TSC_PAGE tsc_ref; HV_REFERENCE_TSC_PAGE tsc_ref;
}; };
enum kvm_irqchip_mode {
KVM_IRQCHIP_NONE,
KVM_IRQCHIP_KERNEL, /* created with KVM_CREATE_IRQCHIP */
KVM_IRQCHIP_SPLIT, /* created with KVM_CAP_SPLIT_IRQCHIP */
};
struct kvm_arch { struct kvm_arch {
unsigned int n_used_mmu_pages; unsigned int n_used_mmu_pages;
unsigned int n_requested_mmu_pages; unsigned int n_requested_mmu_pages;
...@@ -788,7 +794,7 @@ struct kvm_arch { ...@@ -788,7 +794,7 @@ struct kvm_arch {
u64 disabled_quirks; u64 disabled_quirks;
bool irqchip_split; enum kvm_irqchip_mode irqchip_mode;
u8 nr_reserved_ioapic_pins; u8 nr_reserved_ioapic_pins;
bool disabled_lapic_found; bool disabled_lapic_found;
......
...@@ -93,18 +93,19 @@ static inline int pic_in_kernel(struct kvm *kvm) ...@@ -93,18 +93,19 @@ 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_split; return kvm->arch.irqchip_mode == KVM_IRQCHIP_SPLIT;
} }
static inline int irqchip_in_kernel(struct kvm *kvm) static inline int irqchip_kernel(struct kvm *kvm)
{ {
struct kvm_pic *vpic = pic_irqchip(kvm); return kvm->arch.irqchip_mode == KVM_IRQCHIP_KERNEL;
bool ret; }
ret = (vpic != NULL); static inline int irqchip_in_kernel(struct kvm *kvm)
ret |= irqchip_split(kvm); {
bool ret = kvm->arch.irqchip_mode != KVM_IRQCHIP_NONE;
/* Read vpic before kvm->irq_routing. */ /* Matches with wmb after initializing kvm->irq_routing. */
smp_rmb(); smp_rmb();
return ret; return ret;
} }
......
...@@ -3894,7 +3894,7 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm, ...@@ -3894,7 +3894,7 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
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_split = true; kvm->arch.irqchip_mode = KVM_IRQCHIP_SPLIT;
kvm->arch.nr_reserved_ioapic_pins = cap->args[0]; kvm->arch.nr_reserved_ioapic_pins = cap->args[0];
r = 0; r = 0;
split_irqchip_unlock: split_irqchip_unlock:
...@@ -3988,8 +3988,9 @@ long kvm_arch_vm_ioctl(struct file *filp, ...@@ -3988,8 +3988,9 @@ long kvm_arch_vm_ioctl(struct file *filp,
mutex_unlock(&kvm->slots_lock); mutex_unlock(&kvm->slots_lock);
goto create_irqchip_unlock; goto create_irqchip_unlock;
} }
/* Write kvm->irq_routing before kvm->arch.vpic. */ /* Write kvm->irq_routing before enabling irqchip_in_kernel. */
smp_wmb(); smp_wmb();
kvm->arch.irqchip_mode = KVM_IRQCHIP_KERNEL;
kvm->arch.vpic = vpic; kvm->arch.vpic = vpic;
create_irqchip_unlock: create_irqchip_unlock:
mutex_unlock(&kvm->lock); mutex_unlock(&kvm->lock);
......
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