]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86: Move kvm_irq_delivery_to_apic() from irq.c to lapic.c
authorSean Christopherson <seanjc@google.com>
Thu, 21 Aug 2025 21:42:07 +0000 (14:42 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 10 Sep 2025 19:05:09 +0000 (12:05 -0700)
Move kvm_irq_delivery_to_apic() to lapic.c as it is specific to local APIC
emulation.  This will allow burying more local APIC code in lapic.c, e.g.
the various "lowest priority" helpers.

No functional change intended.

Link: https://lore.kernel.org/r/20250821214209.3463350-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/irq.c
arch/x86/kvm/irq.h
arch/x86/kvm/lapic.c
arch/x86/kvm/lapic.h

index 16da892590116ef7c711a1181b890e5d68ca8abe..a6b122f732be690956678ca1e31966253283c2b8 100644 (file)
@@ -195,63 +195,6 @@ bool kvm_arch_irqchip_in_kernel(struct kvm *kvm)
        return irqchip_in_kernel(kvm);
 }
 
-int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
-                            struct kvm_lapic_irq *irq, struct dest_map *dest_map)
-{
-       int r = -1;
-       struct kvm_vcpu *vcpu, *lowest = NULL;
-       unsigned long i, dest_vcpu_bitmap[BITS_TO_LONGS(KVM_MAX_VCPUS)];
-       unsigned int dest_vcpus = 0;
-
-       if (kvm_irq_delivery_to_apic_fast(kvm, src, irq, &r, dest_map))
-               return r;
-
-       if (irq->dest_mode == APIC_DEST_PHYSICAL &&
-           irq->dest_id == 0xff && kvm_lowest_prio_delivery(irq)) {
-               pr_info("apic: phys broadcast and lowest prio\n");
-               irq->delivery_mode = APIC_DM_FIXED;
-       }
-
-       memset(dest_vcpu_bitmap, 0, sizeof(dest_vcpu_bitmap));
-
-       kvm_for_each_vcpu(i, vcpu, kvm) {
-               if (!kvm_apic_present(vcpu))
-                       continue;
-
-               if (!kvm_apic_match_dest(vcpu, src, irq->shorthand,
-                                       irq->dest_id, irq->dest_mode))
-                       continue;
-
-               if (!kvm_lowest_prio_delivery(irq)) {
-                       if (r < 0)
-                               r = 0;
-                       r += kvm_apic_set_irq(vcpu, irq, dest_map);
-               } else if (kvm_apic_sw_enabled(vcpu->arch.apic)) {
-                       if (!kvm_vector_hashing_enabled()) {
-                               if (!lowest)
-                                       lowest = vcpu;
-                               else if (kvm_apic_compare_prio(vcpu, lowest) < 0)
-                                       lowest = vcpu;
-                       } else {
-                               __set_bit(i, dest_vcpu_bitmap);
-                               dest_vcpus++;
-                       }
-               }
-       }
-
-       if (dest_vcpus != 0) {
-               int idx = kvm_vector_to_index(irq->vector, dest_vcpus,
-                                       dest_vcpu_bitmap, KVM_MAX_VCPUS);
-
-               lowest = kvm_get_vcpu(kvm, idx);
-       }
-
-       if (lowest)
-               r = kvm_apic_set_irq(lowest, irq, dest_map);
-
-       return r;
-}
-
 static void kvm_msi_to_lapic_irq(struct kvm *kvm,
                                 struct kvm_kernel_irq_routing_entry *e,
                                 struct kvm_lapic_irq *irq)
index 5e62c1f79ce655a7c7a5b148f07e1b571ea040ab..34f4a78a7a010e9a37bcf07443aa0870ccafb595 100644 (file)
@@ -121,8 +121,4 @@ void __kvm_migrate_timers(struct kvm_vcpu *vcpu);
 
 int apic_has_pending_timer(struct kvm_vcpu *vcpu);
 
-int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
-                            struct kvm_lapic_irq *irq,
-                            struct dest_map *dest_map);
-
 #endif
index 0c10b1e003c731ff53294b0913a4e2aac47abd29..66de69cbd57ca8cb2dd986614f9997f9a94fdd57 100644 (file)
@@ -1249,6 +1249,63 @@ bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *irq,
        return ret;
 }
 
+int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
+                            struct kvm_lapic_irq *irq, struct dest_map *dest_map)
+{
+       int r = -1;
+       struct kvm_vcpu *vcpu, *lowest = NULL;
+       unsigned long i, dest_vcpu_bitmap[BITS_TO_LONGS(KVM_MAX_VCPUS)];
+       unsigned int dest_vcpus = 0;
+
+       if (kvm_irq_delivery_to_apic_fast(kvm, src, irq, &r, dest_map))
+               return r;
+
+       if (irq->dest_mode == APIC_DEST_PHYSICAL &&
+           irq->dest_id == 0xff && kvm_lowest_prio_delivery(irq)) {
+               pr_info("apic: phys broadcast and lowest prio\n");
+               irq->delivery_mode = APIC_DM_FIXED;
+       }
+
+       memset(dest_vcpu_bitmap, 0, sizeof(dest_vcpu_bitmap));
+
+       kvm_for_each_vcpu(i, vcpu, kvm) {
+               if (!kvm_apic_present(vcpu))
+                       continue;
+
+               if (!kvm_apic_match_dest(vcpu, src, irq->shorthand,
+                                       irq->dest_id, irq->dest_mode))
+                       continue;
+
+               if (!kvm_lowest_prio_delivery(irq)) {
+                       if (r < 0)
+                               r = 0;
+                       r += kvm_apic_set_irq(vcpu, irq, dest_map);
+               } else if (kvm_apic_sw_enabled(vcpu->arch.apic)) {
+                       if (!kvm_vector_hashing_enabled()) {
+                               if (!lowest)
+                                       lowest = vcpu;
+                               else if (kvm_apic_compare_prio(vcpu, lowest) < 0)
+                                       lowest = vcpu;
+                       } else {
+                               __set_bit(i, dest_vcpu_bitmap);
+                               dest_vcpus++;
+                       }
+               }
+       }
+
+       if (dest_vcpus != 0) {
+               int idx = kvm_vector_to_index(irq->vector, dest_vcpus,
+                                       dest_vcpu_bitmap, KVM_MAX_VCPUS);
+
+               lowest = kvm_get_vcpu(kvm, idx);
+       }
+
+       if (lowest)
+               r = kvm_apic_set_irq(lowest, irq, dest_map);
+
+       return r;
+}
+
 /*
  * Add a pending IRQ into lapic.
  * Return 1 if successfully added and 0 if discarded.
index 8b00e29741de5d3aeafd4fcd916513ce86883764..edfed763cf8901a5209e60786d6c7b534e782cb5 100644 (file)
@@ -119,6 +119,9 @@ void kvm_inhibit_apic_access_page(struct kvm_vcpu *vcpu);
 
 bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
                struct kvm_lapic_irq *irq, int *r, struct dest_map *dest_map);
+int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
+                            struct kvm_lapic_irq *irq,
+                            struct dest_map *dest_map);
 void kvm_apic_send_ipi(struct kvm_lapic *apic, u32 icr_low, u32 icr_high);
 
 int kvm_apic_set_base(struct kvm_vcpu *vcpu, u64 value, bool host_initiated);