arch/x86/kvm/irq.c
Source file repositories/reference/linux-study-clean/arch/x86/kvm/irq.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kvm/irq.c- Extension
.c- Size
- 16655 bytes
- Lines
- 639
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/kvm_host.hlinux/kvm_irqfd.hhyperv.hioapic.hirq.htrace.hx86.hxen.h
Detected Declarations
function Copyrightfunction pending_userspace_extintfunction get_userspace_extintfunction kvm_cpu_has_extintfunction kvm_cpu_has_injectable_intrfunction kvm_cpu_has_interruptfunction interruptfunction kvm_cpu_get_interruptfunction kvm_inject_pending_timer_irqsfunction __kvm_migrate_timersfunction kvm_arch_irqfd_allowedfunction kvm_arch_irqchip_in_kernelfunction kvm_msi_to_lapic_irqfunction kvm_msi_route_invalidfunction kvm_set_msifunction kvm_arch_set_irq_inatomicfunction kvm_vm_ioctl_irq_linefunction kvm_arch_can_set_irq_routingfunction kvm_set_routing_entryfunction kvm_scan_ioapic_irqfunction kvm_scan_ioapic_routesfunction hlist_for_each_entryfunction kvm_arch_irq_routing_updatefunction kvm_pi_update_irtefunction kvm_arch_irq_bypass_add_producerfunction kvm_arch_irq_bypass_del_producerfunction kvm_arch_update_irqfd_routingfunction kvm_setup_default_ioapic_and_pic_routingfunction kvm_vm_ioctl_get_irqchipfunction kvm_vm_ioctl_set_irqchip
Annotated Snippet
switch (ue->u.irqchip.irqchip) {
case KVM_IRQCHIP_PIC_SLAVE:
e->irqchip.pin += PIC_NUM_PINS / 2;
fallthrough;
case KVM_IRQCHIP_PIC_MASTER:
if (ue->u.irqchip.pin >= PIC_NUM_PINS / 2)
return -EINVAL;
e->set = kvm_pic_set_irq;
break;
case KVM_IRQCHIP_IOAPIC:
if (ue->u.irqchip.pin >= KVM_IOAPIC_NUM_PINS)
return -EINVAL;
e->set = kvm_ioapic_set_irq;
break;
default:
return -EINVAL;
}
e->irqchip.irqchip = ue->u.irqchip.irqchip;
break;
#endif
case KVM_IRQ_ROUTING_MSI:
e->set = kvm_set_msi;
e->msi.address_lo = ue->u.msi.address_lo;
e->msi.address_hi = ue->u.msi.address_hi;
e->msi.data = ue->u.msi.data;
if (kvm_msi_route_invalid(kvm, e))
return -EINVAL;
break;
#ifdef CONFIG_KVM_HYPERV
case KVM_IRQ_ROUTING_HV_SINT:
e->set = kvm_hv_synic_set_irq;
e->hv_sint.vcpu = ue->u.hv_sint.vcpu;
e->hv_sint.sint = ue->u.hv_sint.sint;
break;
#endif
#ifdef CONFIG_KVM_XEN
case KVM_IRQ_ROUTING_XEN_EVTCHN:
return kvm_xen_setup_evtchn(kvm, e, ue);
#endif
default:
return -EINVAL;
}
return 0;
}
void kvm_scan_ioapic_irq(struct kvm_vcpu *vcpu, u32 dest_id, u16 dest_mode,
u8 vector, unsigned long *ioapic_handled_vectors)
{
/*
* Intercept EOI if the vCPU is the target of the new IRQ routing, or
* the vCPU has a pending IRQ from the old routing, i.e. if the vCPU
* may receive a level-triggered IRQ in the future, or already received
* level-triggered IRQ. The EOI needs to be intercepted and forwarded
* to I/O APIC emulation so that the IRQ can be de-asserted.
*/
if (kvm_apic_match_dest(vcpu, NULL, APIC_DEST_NOSHORT, dest_id, dest_mode)) {
__set_bit(vector, ioapic_handled_vectors);
} else if (kvm_apic_pending_eoi(vcpu, vector)) {
__set_bit(vector, ioapic_handled_vectors);
/*
* Track the highest pending EOI for which the vCPU is NOT the
* target in the new routing. Only the EOI for the IRQ that is
* in-flight (for the old routing) needs to be intercepted, any
* future IRQs that arrive on this vCPU will be coincidental to
* the level-triggered routing and don't need to be intercepted.
*/
if ((int)vector > vcpu->arch.highest_stale_pending_ioapic_eoi)
vcpu->arch.highest_stale_pending_ioapic_eoi = vector;
}
}
void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu,
ulong *ioapic_handled_vectors)
{
struct kvm *kvm = vcpu->kvm;
struct kvm_kernel_irq_routing_entry *entry;
struct kvm_irq_routing_table *table;
u32 i, nr_ioapic_pins;
int idx;
idx = srcu_read_lock(&kvm->irq_srcu);
table = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu);
nr_ioapic_pins = min_t(u32, table->nr_rt_entries,
kvm->arch.nr_reserved_ioapic_pins);
for (i = 0; i < nr_ioapic_pins; ++i) {
hlist_for_each_entry(entry, &table->map[i], link) {
struct kvm_lapic_irq irq;
Annotation
- Immediate include surface: `linux/export.h`, `linux/kvm_host.h`, `linux/kvm_irqfd.h`, `hyperv.h`, `ioapic.h`, `irq.h`, `trace.h`, `x86.h`.
- Detected declarations: `function Copyright`, `function pending_userspace_extint`, `function get_userspace_extint`, `function kvm_cpu_has_extint`, `function kvm_cpu_has_injectable_intr`, `function kvm_cpu_has_interrupt`, `function interrupt`, `function kvm_cpu_get_interrupt`, `function kvm_inject_pending_timer_irqs`, `function __kvm_migrate_timers`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.