arch/powerpc/kvm/book3s_hv.c
Source file repositories/reference/linux-study-clean/arch/powerpc/kvm/book3s_hv.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/kvm/book3s_hv.c- Extension
.c- Size
- 176861 bytes
- Lines
- 6704
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- Inferred role
- Architecture Layer: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/kvm_host.hlinux/kernel.hlinux/err.hlinux/slab.hlinux/preempt.hlinux/sched/signal.hlinux/sched/stat.hlinux/delay.hlinux/export.hlinux/fs.hlinux/anon_inodes.hlinux/cpu.hlinux/cpumask.hlinux/spinlock.hlinux/page-flags.hlinux/srcu.hlinux/miscdevice.hlinux/debugfs.hlinux/gfp.hlinux/vmalloc.hlinux/highmem.hlinux/kvm_irqfd.hlinux/irqbypass.hlinux/module.hlinux/compiler.hlinux/of.hlinux/irqdomain.hlinux/smp.hasm/ftrace.hasm/reg.hasm/ppc-opcode.hasm/asm-prototypes.h
Detected Declarations
struct reg_vpastruct debugfs_timings_statestruct preempted_vcore_liststruct core_infofunction kvmppc_ipi_threadfunction kvmppc_fast_vcpu_kick_hvfunction kvmppc_core_start_stolenfunction kvmppc_core_end_stolenfunction kvmppc_core_vcpu_load_hvfunction kvmppc_core_vcpu_put_hvfunction kvmppc_set_pvr_hvfunction map_pcr_to_capfunction kvmppc_set_arch_compatfunction kvmppc_dump_regsfunction init_vpafunction set_vpafunction vpa_is_registeredfunction do_h_register_vpafunction kvmppc_update_vpafunction kvmppc_update_vpasfunction vcore_stolen_timefunction __kvmppc_create_dtl_entryfunction kvmppc_update_vpa_dispatchfunction kvmppc_update_vpa_dispatch_p9function kvmppc_doorbell_pendingfunction kvmppc_power8_compatiblefunction kvmppc_h_set_modefunction kvmppc_copy_guestfunction kvmppc_h_page_initfunction kvm_arch_vcpu_yield_tofunction kvmppc_get_yield_countfunction kvmppc_nested_h_rpt_invalidatefunction kvmppc_h_rpt_invalidatefunction kvmppc_pseries_do_hcallfunction kvmppc_run_single_vcpufunction kvmppc_hcall_impl_hvfunction kvmppc_emulate_debug_instfunction do_nothingfunction kvmppc_emulate_doorbell_instrfunction kvmppc_pmu_unavailablefunction kvmppc_ebb_unavailablefunction kvmppc_tm_unavailablefunction kvmppc_handle_exit_hvfunction exitfunction kvmppc_handle_nested_exitfunction exitfunction kvm_arch_vcpu_ioctl_get_sregs_hvfunction kvm_arch_vcpu_ioctl_set_sregs_hv
Annotated Snippet
static const struct file_operations debugfs_timings_ops = {
.owner = THIS_MODULE,
.open = debugfs_timings_open,
.release = debugfs_timings_release,
.read = debugfs_timings_read,
.write = debugfs_timings_write,
.llseek = generic_file_llseek,
};
/* Create a debugfs directory for the vcpu */
static int kvmppc_arch_create_vcpu_debugfs_hv(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
{
if (cpu_has_feature(CPU_FTR_ARCH_300) == IS_ENABLED(CONFIG_KVM_BOOK3S_HV_P9_TIMING))
debugfs_create_file("timings", 0444, debugfs_dentry, vcpu,
&debugfs_timings_ops);
return 0;
}
#else /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
static int kvmppc_arch_create_vcpu_debugfs_hv(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
{
return 0;
}
#endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
static int kvmppc_core_vcpu_create_hv(struct kvm_vcpu *vcpu)
{
int err;
int core;
struct kvmppc_vcore *vcore;
struct kvm *kvm;
unsigned int id;
kvm = vcpu->kvm;
id = vcpu->vcpu_id;
vcpu->arch.shared = &vcpu->arch.shregs;
#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
/*
* The shared struct is never shared on HV,
* so we can always use host endianness
*/
#ifdef __BIG_ENDIAN__
vcpu->arch.shared_big_endian = true;
#else
vcpu->arch.shared_big_endian = false;
#endif
#endif
if (kvmhv_is_nestedv2()) {
err = kvmhv_nestedv2_vcpu_create(vcpu, &vcpu->arch.nestedv2_io);
if (err < 0)
return err;
}
kvmppc_set_mmcr_hv(vcpu, 0, MMCR0_FC);
if (cpu_has_feature(CPU_FTR_ARCH_31)) {
kvmppc_set_mmcr_hv(vcpu, 0, kvmppc_get_mmcr_hv(vcpu, 0) | MMCR0_PMCCEXT);
kvmppc_set_mmcra_hv(vcpu, MMCRA_BHRB_DISABLE);
}
kvmppc_set_ctrl_hv(vcpu, CTRL_RUNLATCH);
/* default to host PVR, since we can't spoof it */
kvmppc_set_pvr_hv(vcpu, mfspr(SPRN_PVR));
spin_lock_init(&vcpu->arch.vpa_update_lock);
spin_lock_init(&vcpu->arch.tbacct_lock);
vcpu->arch.busy_preempt = TB_NIL;
__kvmppc_set_msr_hv(vcpu, MSR_ME);
vcpu->arch.intr_msr = MSR_SF | MSR_ME;
/*
* Set the default HFSCR for the guest from the host value.
* This value is only used on POWER9 and later.
* On >= POWER9, we want to virtualize the doorbell facility, so we
* don't set the HFSCR_MSGP bit, and that causes those instructions
* to trap and then we emulate them.
*/
kvmppc_set_hfscr_hv(vcpu, HFSCR_TAR | HFSCR_EBB | HFSCR_PM | HFSCR_BHRB |
HFSCR_DSCR | HFSCR_VECVSX | HFSCR_FP);
/* On POWER10 and later, allow prefixed instructions */
if (cpu_has_feature(CPU_FTR_ARCH_31))
kvmppc_set_hfscr_hv(vcpu, kvmppc_get_hfscr_hv(vcpu) | HFSCR_PREFIX);
if (cpu_has_feature(CPU_FTR_HVMODE)) {
kvmppc_set_hfscr_hv(vcpu, kvmppc_get_hfscr_hv(vcpu) & mfspr(SPRN_HFSCR));
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
if (cpu_has_feature(CPU_FTR_P9_TM_HV_ASSIST))
kvmppc_set_hfscr_hv(vcpu, kvmppc_get_hfscr_hv(vcpu) | HFSCR_TM);
Annotation
- Immediate include surface: `linux/kvm_host.h`, `linux/kernel.h`, `linux/err.h`, `linux/slab.h`, `linux/preempt.h`, `linux/sched/signal.h`, `linux/sched/stat.h`, `linux/delay.h`.
- Detected declarations: `struct reg_vpa`, `struct debugfs_timings_state`, `struct preempted_vcore_list`, `struct core_info`, `function kvmppc_ipi_thread`, `function kvmppc_fast_vcpu_kick_hv`, `function kvmppc_core_start_stolen`, `function kvmppc_core_end_stolen`, `function kvmppc_core_vcpu_load_hv`, `function kvmppc_core_vcpu_put_hv`.
- Atlas domain: Architecture Layer / arch/powerpc.
- Implementation status: pattern 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.