arch/powerpc/kvm/book3s_32_mmu.c
Source file repositories/reference/linux-study-clean/arch/powerpc/kvm/book3s_32_mmu.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/kvm/book3s_32_mmu.c- Extension
.c- Size
- 9541 bytes
- Lines
- 416
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/string.hlinux/kvm.hlinux/kvm_host.hlinux/highmem.hasm/kvm_ppc.hasm/kvm_book3s.h
Detected Declarations
function check_debug_ipfunction sr_vsidfunction sr_validfunction sr_ksfunction sr_kpfunction find_srfunction kvmppc_mmu_book3s_32_ea_to_vpfunction kvmppc_mmu_book3s_32_get_ptegfunction kvmppc_mmu_book3s_32_get_ptemfunction kvmppc_mmu_book3s_32_xlate_batfunction kvmppc_mmu_book3s_32_xlate_ptefunction kvmppc_mmu_book3s_32_xlatefunction unlikelyfunction kvmppc_mmu_book3s_32_mfsrinfunction kvmppc_mmu_book3s_32_mtsrinfunction kvmppc_mmu_book3s_32_tlbiefunction kvmppc_mmu_book3s_32_esid_to_vsidfunction kvmppc_mmu_book3s_32_is_dcbz32function kvmppc_mmu_book3s_32_init
Annotated Snippet
if (kvmppc_get_msr(vcpu) & MSR_PR) {
if (!bat->vp)
continue;
} else {
if (!bat->vs)
continue;
}
if (check_debug_ip(vcpu))
{
dprintk_pte("%cBAT %02d: 0x%lx - 0x%x (0x%x)\n",
data ? 'd' : 'i', i, eaddr, bat->bepi,
bat->bepi_mask);
}
if ((eaddr & bat->bepi_mask) == bat->bepi) {
u64 vsid;
kvmppc_mmu_book3s_32_esid_to_vsid(vcpu,
eaddr >> SID_SHIFT, &vsid);
vsid <<= 16;
pte->vpage = (((u64)eaddr >> 12) & 0xffff) | vsid;
pte->raddr = bat->brpn | (eaddr & ~bat->bepi_mask);
pte->may_read = bat->pp;
pte->may_write = bat->pp > 1;
pte->may_execute = true;
if (!pte->may_read) {
printk(KERN_INFO "BAT is not readable!\n");
continue;
}
if (iswrite && !pte->may_write) {
dprintk_pte("BAT is read-only!\n");
continue;
}
return 0;
}
}
return -ENOENT;
}
static int kvmppc_mmu_book3s_32_xlate_pte(struct kvm_vcpu *vcpu, gva_t eaddr,
struct kvmppc_pte *pte, bool data,
bool iswrite, bool primary)
{
u32 sre;
hva_t ptegp;
u32 pteg[16];
u32 pte0, pte1;
u32 ptem = 0;
int i;
int found = 0;
sre = find_sr(vcpu, eaddr);
dprintk_pte("SR 0x%lx: vsid=0x%x, raw=0x%x\n", eaddr >> 28,
sr_vsid(sre), sre);
pte->vpage = kvmppc_mmu_book3s_32_ea_to_vp(vcpu, eaddr, data);
ptegp = kvmppc_mmu_book3s_32_get_pteg(vcpu, sre, eaddr, primary);
if (kvm_is_error_hva(ptegp)) {
printk(KERN_INFO "KVM: Invalid PTEG!\n");
goto no_page_found;
}
ptem = kvmppc_mmu_book3s_32_get_ptem(sre, eaddr, primary);
if(copy_from_user(pteg, (void __user *)ptegp, sizeof(pteg))) {
printk_ratelimited(KERN_ERR
"KVM: Can't copy data from 0x%lx!\n", ptegp);
goto no_page_found;
}
for (i=0; i<16; i+=2) {
pte0 = be32_to_cpu(pteg[i]);
pte1 = be32_to_cpu(pteg[i + 1]);
if (ptem == pte0) {
u8 pp;
pte->raddr = (pte1 & ~(0xFFFULL)) | (eaddr & 0xFFF);
pp = pte1 & 3;
if ((sr_kp(sre) && (kvmppc_get_msr(vcpu) & MSR_PR)) ||
(sr_ks(sre) && !(kvmppc_get_msr(vcpu) & MSR_PR)))
pp |= 4;
pte->may_write = false;
pte->may_read = false;
pte->may_execute = true;
Annotation
- Immediate include surface: `linux/types.h`, `linux/string.h`, `linux/kvm.h`, `linux/kvm_host.h`, `linux/highmem.h`, `asm/kvm_ppc.h`, `asm/kvm_book3s.h`.
- Detected declarations: `function check_debug_ip`, `function sr_vsid`, `function sr_valid`, `function sr_ks`, `function sr_kp`, `function find_sr`, `function kvmppc_mmu_book3s_32_ea_to_vp`, `function kvmppc_mmu_book3s_32_get_pteg`, `function kvmppc_mmu_book3s_32_get_ptem`, `function kvmppc_mmu_book3s_32_xlate_bat`.
- 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.
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.