arch/powerpc/kvm/book3s_xive_native.c
Source file repositories/reference/linux-study-clean/arch/powerpc/kvm/book3s_xive_native.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/kvm/book3s_xive_native.c- Extension
.c- Size
- 31453 bytes
- Lines
- 1285
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- Inferred role
- Architecture Layer: implementation source
- Status
- source 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.
- 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.
- 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/file.hlinux/irqdomain.hasm/uaccess.hasm/kvm_book3s.hasm/kvm_ppc.hasm/hvcall.hasm/xive.hasm/xive-regs.hasm/debug.hasm/opal.hlinux/debugfs.hlinux/seq_file.hbook3s_xive.h
Detected Declarations
function Copyrightfunction kvmppc_xive_native_cleanup_queuefunction kvmppc_xive_native_configure_queuefunction kvmppc_xive_native_cleanup_vcpufunction kvmppc_xive_native_connect_vcpufunction kvmppc_xive_native_reset_mappedfunction xive_native_esb_faultfunction xive_native_tima_faultfunction kvmppc_xive_native_mmapfunction kvmppc_xive_native_set_sourcefunction kvmppc_xive_native_update_source_configfunction kvmppc_xive_native_set_source_configfunction kvmppc_xive_native_sync_sourcefunction xive_native_validate_queue_sizefunction kvmppc_xive_native_set_queue_configfunction kvmppc_xive_native_get_queue_configfunction kvmppc_xive_reset_sourcesfunction kvmppc_xive_resetfunction kvm_for_each_vcpufunction kvmppc_xive_native_sync_sourcesfunction kvmppc_xive_native_vcpu_eq_syncfunction kvmppc_xive_native_eq_syncfunction kvm_for_each_vcpufunction kvmppc_xive_native_set_attrfunction kvmppc_xive_native_get_attrfunction kvmppc_xive_native_has_attrfunction kvmppc_xive_native_releasefunction kvmppc_xive_native_createfunction Bufferfunction kvmppc_xive_native_set_vpfunction kvmppc_xive_native_supportedfunction xive_native_debug_showfunction kvm_for_each_vcpufunction xive_native_debugfs_initfunction kvmppc_xive_native_init
Annotated Snippet
if (xc->esc_virq[i]) {
if (kvmppc_xive_has_single_escalation(xc->xive))
xive_cleanup_single_escalation(vcpu, xc->esc_virq[i]);
free_irq(xc->esc_virq[i], vcpu);
irq_dispose_mapping(xc->esc_virq[i]);
kfree(xc->esc_virq_names[i]);
xc->esc_virq[i] = 0;
}
}
/* Disable the VP */
xive_native_disable_vp(xc->vp_id);
/* Clear the cam word so guest entry won't try to push context */
vcpu->arch.xive_cam_word = 0;
/* Free the queues */
for (i = 0; i < KVMPPC_XIVE_Q_COUNT; i++) {
kvmppc_xive_native_cleanup_queue(vcpu, i);
}
/* Free the VP */
kfree(xc);
/* Cleanup the vcpu */
vcpu->arch.irq_type = KVMPPC_IRQ_DEFAULT;
vcpu->arch.xive_vcpu = NULL;
}
int kvmppc_xive_native_connect_vcpu(struct kvm_device *dev,
struct kvm_vcpu *vcpu, u32 server_num)
{
struct kvmppc_xive *xive = dev->private;
struct kvmppc_xive_vcpu *xc = NULL;
int rc;
u32 vp_id;
pr_devel("native_connect_vcpu(server=%d)\n", server_num);
if (dev->ops != &kvm_xive_native_ops) {
pr_devel("Wrong ops !\n");
return -EPERM;
}
if (xive->kvm != vcpu->kvm)
return -EPERM;
if (vcpu->arch.irq_type != KVMPPC_IRQ_DEFAULT)
return -EBUSY;
mutex_lock(&xive->lock);
rc = kvmppc_xive_compute_vp_id(xive, server_num, &vp_id);
if (rc)
goto bail;
xc = kzalloc_obj(*xc);
if (!xc) {
rc = -ENOMEM;
goto bail;
}
vcpu->arch.xive_vcpu = xc;
xc->xive = xive;
xc->vcpu = vcpu;
xc->server_num = server_num;
xc->vp_id = vp_id;
xc->valid = true;
vcpu->arch.irq_type = KVMPPC_IRQ_XIVE;
rc = xive_native_get_vp_info(xc->vp_id, &xc->vp_cam, &xc->vp_chip_id);
if (rc) {
pr_err("Failed to get VP info from OPAL: %d\n", rc);
goto bail;
}
if (!kvmppc_xive_check_save_restore(vcpu)) {
pr_err("inconsistent save-restore setup for VCPU %d\n", server_num);
rc = -EIO;
goto bail;
}
/*
* Enable the VP first as the single escalation mode will
* affect escalation interrupts numbering
*/
rc = xive_native_enable_vp(xc->vp_id, kvmppc_xive_has_single_escalation(xive));
if (rc) {
pr_err("Failed to enable VP in OPAL: %d\n", rc);
goto bail;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/kvm_host.h`, `linux/err.h`, `linux/gfp.h`, `linux/spinlock.h`, `linux/delay.h`, `linux/file.h`, `linux/irqdomain.h`.
- Detected declarations: `function Copyright`, `function kvmppc_xive_native_cleanup_queue`, `function kvmppc_xive_native_configure_queue`, `function kvmppc_xive_native_cleanup_vcpu`, `function kvmppc_xive_native_connect_vcpu`, `function kvmppc_xive_native_reset_mapped`, `function xive_native_esb_fault`, `function xive_native_tima_fault`, `function kvmppc_xive_native_mmap`, `function kvmppc_xive_native_set_source`.
- Atlas domain: Architecture Layer / arch/powerpc.
- Implementation status: source 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.
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.