Skip to content

Commit 16e53ef

Browse files
committed
KVM: x86: Move kvm_intr_is_single_vcpu() to lapic.c
Move kvm_intr_is_single_vcpu() to lapic.c, drop its export, and make its "fast" helper local to lapic.c. kvm_intr_is_single_vcpu() is only usable if the local APIC is in-kernel, i.e. it most definitely belongs in the local APIC code. No functional change intended. Fixes: cf04ec3 ("KVM: x86: Dedup AVIC vs. PI code for identifying target vCPU") Link: https://lore.kernel.org/r/20250919003303.1355064-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent d66078b commit 16e53ef

File tree

4 files changed

+33
-35
lines changed

4 files changed

+33
-35
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,9 +2401,6 @@ void __user *__x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa,
24012401
bool kvm_vcpu_is_reset_bsp(struct kvm_vcpu *vcpu);
24022402
bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu);
24032403

2404-
bool kvm_intr_is_single_vcpu(struct kvm *kvm, struct kvm_lapic_irq *irq,
2405-
struct kvm_vcpu **dest_vcpu);
2406-
24072404
static inline bool kvm_irq_is_postable(struct kvm_lapic_irq *irq)
24082405
{
24092406
/* We can only post Fixed and LowPrio IRQs */

arch/x86/kvm/irq.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -354,34 +354,6 @@ int kvm_set_routing_entry(struct kvm *kvm,
354354
return 0;
355355
}
356356

357-
bool kvm_intr_is_single_vcpu(struct kvm *kvm, struct kvm_lapic_irq *irq,
358-
struct kvm_vcpu **dest_vcpu)
359-
{
360-
int r = 0;
361-
unsigned long i;
362-
struct kvm_vcpu *vcpu;
363-
364-
if (kvm_intr_is_single_vcpu_fast(kvm, irq, dest_vcpu))
365-
return true;
366-
367-
kvm_for_each_vcpu(i, vcpu, kvm) {
368-
if (!kvm_apic_present(vcpu))
369-
continue;
370-
371-
if (!kvm_apic_match_dest(vcpu, NULL, irq->shorthand,
372-
irq->dest_id, irq->dest_mode))
373-
continue;
374-
375-
if (++r == 2)
376-
return false;
377-
378-
*dest_vcpu = vcpu;
379-
}
380-
381-
return r == 1;
382-
}
383-
EXPORT_SYMBOL_GPL(kvm_intr_is_single_vcpu);
384-
385357
void kvm_scan_ioapic_irq(struct kvm_vcpu *vcpu, u32 dest_id, u16 dest_mode,
386358
u8 vector, unsigned long *ioapic_handled_vectors)
387359
{

arch/x86/kvm/lapic.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,8 +1235,9 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
12351235
* interrupt.
12361236
* - Otherwise, use remapped mode to inject the interrupt.
12371237
*/
1238-
bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *irq,
1239-
struct kvm_vcpu **dest_vcpu)
1238+
static bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm,
1239+
struct kvm_lapic_irq *irq,
1240+
struct kvm_vcpu **dest_vcpu)
12401241
{
12411242
struct kvm_apic_map *map;
12421243
unsigned long bitmap;
@@ -1263,6 +1264,34 @@ bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *irq,
12631264
return ret;
12641265
}
12651266

1267+
bool kvm_intr_is_single_vcpu(struct kvm *kvm, struct kvm_lapic_irq *irq,
1268+
struct kvm_vcpu **dest_vcpu)
1269+
{
1270+
int r = 0;
1271+
unsigned long i;
1272+
struct kvm_vcpu *vcpu;
1273+
1274+
if (kvm_intr_is_single_vcpu_fast(kvm, irq, dest_vcpu))
1275+
return true;
1276+
1277+
kvm_for_each_vcpu(i, vcpu, kvm) {
1278+
if (!kvm_apic_present(vcpu))
1279+
continue;
1280+
1281+
if (!kvm_apic_match_dest(vcpu, NULL, irq->shorthand,
1282+
irq->dest_id, irq->dest_mode))
1283+
continue;
1284+
1285+
if (++r == 2)
1286+
return false;
1287+
1288+
*dest_vcpu = vcpu;
1289+
}
1290+
1291+
return r == 1;
1292+
}
1293+
EXPORT_SYMBOL_GPL(kvm_intr_is_single_vcpu);
1294+
12661295
int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
12671296
struct kvm_lapic_irq *irq, struct dest_map *dest_map)
12681297
{

arch/x86/kvm/lapic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu);
236236
void kvm_bitmap_or_dest_vcpus(struct kvm *kvm, struct kvm_lapic_irq *irq,
237237
unsigned long *vcpu_bitmap);
238238

239-
bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *irq,
240-
struct kvm_vcpu **dest_vcpu);
239+
bool kvm_intr_is_single_vcpu(struct kvm *kvm, struct kvm_lapic_irq *irq,
240+
struct kvm_vcpu **dest_vcpu);
241241
void kvm_lapic_switch_to_sw_timer(struct kvm_vcpu *vcpu);
242242
void kvm_lapic_switch_to_hv_timer(struct kvm_vcpu *vcpu);
243243
void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu);

0 commit comments

Comments
 (0)