Skip to content

Commit cbf5d94

Browse files
committed
KVM: x86: Move kvm_irq_delivery_to_apic() from irq.c to lapic.c
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>
1 parent c266754 commit cbf5d94

4 files changed

Lines changed: 60 additions & 61 deletions

File tree

arch/x86/kvm/irq.c

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -195,63 +195,6 @@ bool kvm_arch_irqchip_in_kernel(struct kvm *kvm)
195195
return irqchip_in_kernel(kvm);
196196
}
197197

198-
int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
199-
struct kvm_lapic_irq *irq, struct dest_map *dest_map)
200-
{
201-
int r = -1;
202-
struct kvm_vcpu *vcpu, *lowest = NULL;
203-
unsigned long i, dest_vcpu_bitmap[BITS_TO_LONGS(KVM_MAX_VCPUS)];
204-
unsigned int dest_vcpus = 0;
205-
206-
if (kvm_irq_delivery_to_apic_fast(kvm, src, irq, &r, dest_map))
207-
return r;
208-
209-
if (irq->dest_mode == APIC_DEST_PHYSICAL &&
210-
irq->dest_id == 0xff && kvm_lowest_prio_delivery(irq)) {
211-
pr_info("apic: phys broadcast and lowest prio\n");
212-
irq->delivery_mode = APIC_DM_FIXED;
213-
}
214-
215-
memset(dest_vcpu_bitmap, 0, sizeof(dest_vcpu_bitmap));
216-
217-
kvm_for_each_vcpu(i, vcpu, kvm) {
218-
if (!kvm_apic_present(vcpu))
219-
continue;
220-
221-
if (!kvm_apic_match_dest(vcpu, src, irq->shorthand,
222-
irq->dest_id, irq->dest_mode))
223-
continue;
224-
225-
if (!kvm_lowest_prio_delivery(irq)) {
226-
if (r < 0)
227-
r = 0;
228-
r += kvm_apic_set_irq(vcpu, irq, dest_map);
229-
} else if (kvm_apic_sw_enabled(vcpu->arch.apic)) {
230-
if (!kvm_vector_hashing_enabled()) {
231-
if (!lowest)
232-
lowest = vcpu;
233-
else if (kvm_apic_compare_prio(vcpu, lowest) < 0)
234-
lowest = vcpu;
235-
} else {
236-
__set_bit(i, dest_vcpu_bitmap);
237-
dest_vcpus++;
238-
}
239-
}
240-
}
241-
242-
if (dest_vcpus != 0) {
243-
int idx = kvm_vector_to_index(irq->vector, dest_vcpus,
244-
dest_vcpu_bitmap, KVM_MAX_VCPUS);
245-
246-
lowest = kvm_get_vcpu(kvm, idx);
247-
}
248-
249-
if (lowest)
250-
r = kvm_apic_set_irq(lowest, irq, dest_map);
251-
252-
return r;
253-
}
254-
255198
static void kvm_msi_to_lapic_irq(struct kvm *kvm,
256199
struct kvm_kernel_irq_routing_entry *e,
257200
struct kvm_lapic_irq *irq)

arch/x86/kvm/irq.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,4 @@ void __kvm_migrate_timers(struct kvm_vcpu *vcpu);
121121

122122
int apic_has_pending_timer(struct kvm_vcpu *vcpu);
123123

124-
int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
125-
struct kvm_lapic_irq *irq,
126-
struct dest_map *dest_map);
127-
128124
#endif

arch/x86/kvm/lapic.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,63 @@ bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *irq,
12491249
return ret;
12501250
}
12511251

1252+
int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
1253+
struct kvm_lapic_irq *irq, struct dest_map *dest_map)
1254+
{
1255+
int r = -1;
1256+
struct kvm_vcpu *vcpu, *lowest = NULL;
1257+
unsigned long i, dest_vcpu_bitmap[BITS_TO_LONGS(KVM_MAX_VCPUS)];
1258+
unsigned int dest_vcpus = 0;
1259+
1260+
if (kvm_irq_delivery_to_apic_fast(kvm, src, irq, &r, dest_map))
1261+
return r;
1262+
1263+
if (irq->dest_mode == APIC_DEST_PHYSICAL &&
1264+
irq->dest_id == 0xff && kvm_lowest_prio_delivery(irq)) {
1265+
pr_info("apic: phys broadcast and lowest prio\n");
1266+
irq->delivery_mode = APIC_DM_FIXED;
1267+
}
1268+
1269+
memset(dest_vcpu_bitmap, 0, sizeof(dest_vcpu_bitmap));
1270+
1271+
kvm_for_each_vcpu(i, vcpu, kvm) {
1272+
if (!kvm_apic_present(vcpu))
1273+
continue;
1274+
1275+
if (!kvm_apic_match_dest(vcpu, src, irq->shorthand,
1276+
irq->dest_id, irq->dest_mode))
1277+
continue;
1278+
1279+
if (!kvm_lowest_prio_delivery(irq)) {
1280+
if (r < 0)
1281+
r = 0;
1282+
r += kvm_apic_set_irq(vcpu, irq, dest_map);
1283+
} else if (kvm_apic_sw_enabled(vcpu->arch.apic)) {
1284+
if (!kvm_vector_hashing_enabled()) {
1285+
if (!lowest)
1286+
lowest = vcpu;
1287+
else if (kvm_apic_compare_prio(vcpu, lowest) < 0)
1288+
lowest = vcpu;
1289+
} else {
1290+
__set_bit(i, dest_vcpu_bitmap);
1291+
dest_vcpus++;
1292+
}
1293+
}
1294+
}
1295+
1296+
if (dest_vcpus != 0) {
1297+
int idx = kvm_vector_to_index(irq->vector, dest_vcpus,
1298+
dest_vcpu_bitmap, KVM_MAX_VCPUS);
1299+
1300+
lowest = kvm_get_vcpu(kvm, idx);
1301+
}
1302+
1303+
if (lowest)
1304+
r = kvm_apic_set_irq(lowest, irq, dest_map);
1305+
1306+
return r;
1307+
}
1308+
12521309
/*
12531310
* Add a pending IRQ into lapic.
12541311
* Return 1 if successfully added and 0 if discarded.

arch/x86/kvm/lapic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ void kvm_inhibit_apic_access_page(struct kvm_vcpu *vcpu);
119119

120120
bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
121121
struct kvm_lapic_irq *irq, int *r, struct dest_map *dest_map);
122+
int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
123+
struct kvm_lapic_irq *irq,
124+
struct dest_map *dest_map);
122125
void kvm_apic_send_ipi(struct kvm_lapic *apic, u32 icr_low, u32 icr_high);
123126

124127
int kvm_apic_set_base(struct kvm_vcpu *vcpu, u64 value, bool host_initiated);

0 commit comments

Comments
 (0)