arch/powerpc/kernel/kvm.c
Source file repositories/reference/linux-study-clean/arch/powerpc/kernel/kvm.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/kernel/kvm.c- Extension
.c- Size
- 19024 bytes
- Lines
- 724
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kvm_host.hlinux/init.hlinux/export.hlinux/kmemleak.hlinux/kvm_para.hlinux/slab.hlinux/of.hlinux/pagemap.hasm/reg.hasm/sections.hasm/cacheflush.hasm/disassemble.hasm/ppc-opcode.hasm/epapr_hcalls.h
Detected Declarations
function kvm_patch_insfunction kvm_patch_ins_llfunction kvm_patch_ins_ldfunction kvm_patch_ins_lwzfunction kvm_patch_ins_stdfunction kvm_patch_ins_stwfunction kvm_patch_ins_nopfunction kvm_patch_ins_bfunction kvm_allocfunction kvm_patch_ins_mtmsrdfunction kvm_patch_ins_mtmsrfunction kvm_patch_ins_wrteefunction kvm_patch_ins_wrteei_0function kvm_patch_ins_mtsrinfunction kvm_map_magic_pagefunction kvm_check_insfunction kvm_use_magic_pagefunction kvm_guest_init
Annotated Snippet
switch (get_rt(rt)) {
case 30:
kvm_patch_ins_ll(&p[kvm_emulate_wrtee_reg_offs],
magic_var(scratch2), KVM_RT_30);
break;
case 31:
kvm_patch_ins_ll(&p[kvm_emulate_wrtee_reg_offs],
magic_var(scratch1), KVM_RT_30);
break;
default:
p[kvm_emulate_wrtee_reg_offs] |= rt;
break;
}
}
p[kvm_emulate_wrtee_orig_ins_offs] = *inst;
flush_icache_range((ulong)p, (ulong)p + kvm_emulate_wrtee_len * 4);
/* Patch the invocation */
kvm_patch_ins_b(inst, distance_start);
}
extern u32 kvm_emulate_wrteei_0_branch_offs;
extern u32 kvm_emulate_wrteei_0_len;
extern u32 kvm_emulate_wrteei_0[];
static void __init kvm_patch_ins_wrteei_0(u32 *inst)
{
u32 *p;
int distance_start;
int distance_end;
ulong next_inst;
p = kvm_alloc(kvm_emulate_wrteei_0_len * 4);
if (!p)
return;
/* Find out where we are and put everything there */
distance_start = (ulong)p - (ulong)inst;
next_inst = ((ulong)inst + 4);
distance_end = next_inst - (ulong)&p[kvm_emulate_wrteei_0_branch_offs];
/* Make sure we only write valid b instructions */
if (distance_start > KVM_INST_B_MAX) {
kvm_patching_worked = false;
return;
}
memcpy(p, kvm_emulate_wrteei_0, kvm_emulate_wrteei_0_len * 4);
p[kvm_emulate_wrteei_0_branch_offs] |= distance_end & KVM_INST_B_MASK;
flush_icache_range((ulong)p, (ulong)p + kvm_emulate_wrteei_0_len * 4);
/* Patch the invocation */
kvm_patch_ins_b(inst, distance_start);
}
#endif
#ifdef CONFIG_PPC_BOOK3S_32
extern u32 kvm_emulate_mtsrin_branch_offs;
extern u32 kvm_emulate_mtsrin_reg1_offs;
extern u32 kvm_emulate_mtsrin_reg2_offs;
extern u32 kvm_emulate_mtsrin_orig_ins_offs;
extern u32 kvm_emulate_mtsrin_len;
extern u32 kvm_emulate_mtsrin[];
static void __init kvm_patch_ins_mtsrin(u32 *inst, u32 rt, u32 rb)
{
u32 *p;
int distance_start;
int distance_end;
ulong next_inst;
p = kvm_alloc(kvm_emulate_mtsrin_len * 4);
if (!p)
return;
/* Find out where we are and put everything there */
distance_start = (ulong)p - (ulong)inst;
next_inst = ((ulong)inst + 4);
distance_end = next_inst - (ulong)&p[kvm_emulate_mtsrin_branch_offs];
/* Make sure we only write valid b instructions */
if (distance_start > KVM_INST_B_MAX) {
kvm_patching_worked = false;
return;
}
/* Modify the chunk to fit the invocation */
Annotation
- Immediate include surface: `linux/kvm_host.h`, `linux/init.h`, `linux/export.h`, `linux/kmemleak.h`, `linux/kvm_para.h`, `linux/slab.h`, `linux/of.h`, `linux/pagemap.h`.
- Detected declarations: `function kvm_patch_ins`, `function kvm_patch_ins_ll`, `function kvm_patch_ins_ld`, `function kvm_patch_ins_lwz`, `function kvm_patch_ins_std`, `function kvm_patch_ins_stw`, `function kvm_patch_ins_nop`, `function kvm_patch_ins_b`, `function kvm_alloc`, `function kvm_patch_ins_mtmsrd`.
- Atlas domain: Architecture Layer / arch/powerpc.
- Implementation status: integration implementation candidate.
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.