arch/powerpc/kvm/book3s_xive.c
Source file repositories/reference/linux-study-clean/arch/powerpc/kvm/book3s_xive.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/kvm/book3s_xive.c- Extension
.c- Size
- 77630 bytes
- Lines
- 2977
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/kvm_host.hlinux/err.hlinux/gfp.hlinux/spinlock.hlinux/delay.hlinux/percpu.hlinux/cpumask.hlinux/uaccess.hlinux/irqdomain.hasm/kvm_book3s.hasm/kvm_ppc.hasm/hvcall.hasm/xics.hasm/xive.hasm/xive-regs.hasm/debug.hasm/time.hasm/opal.hlinux/debugfs.hlinux/seq_file.hbook3s_xive.h
Detected Declarations
function xive_vm_ack_pendingfunction xive_vm_esb_loadfunction xive_vm_source_eoifunction xive_vm_scan_interruptsfunction favoredfunction xive_vm_h_xirrfunction xive_vm_h_ipollfunction xive_vm_push_pending_to_hwfunction xive_vm_scan_for_rerouted_irqsfunction xive_vm_h_cpprfunction xive_vm_h_eoifunction xive_vm_h_ipifunction kvmppc_xive_vcpu_has_save_restorefunction kvmppc_xive_check_save_restorefunction modefunction modefunction kvmppc_xive_rearm_escalationfunction xive_irq_triggerfunction xive_esc_irqfunction kvmppc_xive_attach_escalationfunction xive_provision_queuefunction xive_check_provisioningfunction xive_inc_q_pendingfunction xive_try_pick_queuefunction kvmppc_xive_select_targetfunction xive_lock_and_maskfunction xive_lock_for_unmaskfunction xive_finish_unmaskfunction xive_target_interruptfunction Otherwisefunction kvmppc_xive_get_xivefunction kvmppc_xive_int_onfunction kvmppc_xive_int_offfunction xive_restore_pending_irqfunction kvmppc_xive_get_icpfunction kvmppc_xive_set_icpfunction xive_set_sourcefunction kvmppc_xive_set_mappedfunction kvmppc_xive_clr_mappedfunction kvmppc_xive_disable_vcpu_interruptsfunction stale_pfunction kvmppc_xive_cleanup_vcpufunction kvmppc_xive_vcpu_id_validfunction kvmppc_xive_compute_vp_idfunction kvmppc_xive_connect_vcpufunction xive_pre_save_set_queuedfunction xive_pre_save_mask_irqfunction xive_pre_save_unmask_irq
Annotated Snippet
else if (xd->flags & XIVE_IRQ_FLAG_LSI) {
/*
* For LSIs the HW EOI cycle is used rather than PQ bits,
* as they are automatically re-triggred in HW when still
* pending.
*/
__raw_readq(__x_eoi_page(xd) + XIVE_ESB_LOAD_EOI);
} else {
uint64_t eoi_val;
/*
* Otherwise for EOI, we use the special MMIO that does
* a clear of both P and Q and returns the old Q,
* except for LSIs where we use the "EOI cycle" special
* load.
*
* This allows us to then do a re-trigger if Q was set
* rather than synthetizing an interrupt in software
*/
eoi_val = xive_vm_esb_load(xd, XIVE_ESB_SET_PQ_00);
/* Re-trigger if needed */
if ((eoi_val & 1) && __x_trig_page(xd))
__raw_writeq(0, __x_trig_page(xd));
}
}
enum {
scan_fetch,
scan_poll,
scan_eoi,
};
static u32 xive_vm_scan_interrupts(struct kvmppc_xive_vcpu *xc,
u8 pending, int scan_type)
{
u32 hirq = 0;
u8 prio = 0xff;
/* Find highest pending priority */
while ((xc->mfrr != 0xff || pending != 0) && hirq == 0) {
struct xive_q *q;
u32 idx, toggle;
__be32 *qpage;
/*
* If pending is 0 this will return 0xff which is what
* we want
*/
prio = ffs(pending) - 1;
/* Don't scan past the guest cppr */
if (prio >= xc->cppr || prio > 7) {
if (xc->mfrr < xc->cppr) {
prio = xc->mfrr;
hirq = XICS_IPI;
}
break;
}
/* Grab queue and pointers */
q = &xc->queues[prio];
idx = q->idx;
toggle = q->toggle;
/*
* Snapshot the queue page. The test further down for EOI
* must use the same "copy" that was used by __xive_read_eq
* since qpage can be set concurrently and we don't want
* to miss an EOI.
*/
qpage = READ_ONCE(q->qpage);
skip_ipi:
/*
* Try to fetch from the queue. Will return 0 for a
* non-queueing priority (ie, qpage = 0).
*/
hirq = __xive_read_eq(qpage, q->msk, &idx, &toggle);
/*
* If this was a signal for an MFFR change done by
* H_IPI we skip it. Additionally, if we were fetching
* we EOI it now, thus re-enabling reception of a new
* such signal.
*
* We also need to do that if prio is 0 and we had no
* page for the queue. In this case, we have non-queued
* IPI that needs to be EOId.
*
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/kvm_host.h`, `linux/err.h`, `linux/gfp.h`, `linux/spinlock.h`, `linux/delay.h`, `linux/percpu.h`, `linux/cpumask.h`.
- Detected declarations: `function xive_vm_ack_pending`, `function xive_vm_esb_load`, `function xive_vm_source_eoi`, `function xive_vm_scan_interrupts`, `function favored`, `function xive_vm_h_xirr`, `function xive_vm_h_ipoll`, `function xive_vm_push_pending_to_hw`, `function xive_vm_scan_for_rerouted_irqs`, `function xive_vm_h_cppr`.
- Atlas domain: Architecture Layer / arch/powerpc.
- 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.