arch/powerpc/kvm/book3s_hv_rm_mmu.c
Source file repositories/reference/linux-study-clean/arch/powerpc/kvm/book3s_hv_rm_mmu.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/kvm/book3s_hv_rm_mmu.c- Extension
.c- Size
- 36276 bytes
- Lines
- 1301
- 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.
- 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/types.hlinux/string.hlinux/kvm.hlinux/kvm_host.hlinux/hugetlb.hlinux/module.hlinux/log2.hlinux/sizes.hasm/trace.hasm/kvm_ppc.hasm/kvm_book3s.hasm/book3s/64/mmu-hash.hasm/hvcall.hasm/synch.hasm/ppc-opcode.hasm/pte-walk.h
Detected Declarations
function global_invalidatesfunction kvmppc_add_revmap_chainfunction kvmppc_update_dirty_mapfunction kvmppc_set_dirty_from_hptefunction remove_revmap_chainfunction kvmppc_do_h_enterfunction compute_tlbie_rbfunction kvmppc_h_enterfunction is_mmio_hptefunction fixup_tlbie_lpidfunction do_tlbiesfunction kvmppc_do_h_removefunction kvmppc_h_removefunction kvmppc_h_bulk_removefunction kvmppc_h_protectfunction kvmppc_h_readfunction kvmppc_h_clear_reffunction kvmppc_h_clear_modfunction kvmppc_get_hpafunction kvmppc_do_h_page_init_zerofunction kvmppc_do_h_page_init_copyfunction kvmppc_rm_h_page_initfunction kvmppc_invalidate_hptefunction kvmppc_clear_ref_hptefunction next_mmio_cache_entryfunction preempt_disablefunction statusexport kvmppc_add_revmap_chainexport kvmppc_update_dirty_mapexport kvmppc_do_h_enterexport kvmppc_h_enterexport kvmppc_do_h_removeexport kvmppc_h_removeexport kvmppc_h_bulk_removeexport kvmppc_h_protectexport kvmppc_h_readexport kvmppc_h_clear_refexport kvmppc_h_clear_modexport kvmppc_invalidate_hpteexport kvmppc_clear_ref_hpteexport kvmppc_hv_find_lock_hpteexport kvmppc_hpte_hv_fault
Annotated Snippet
if (host_pte_size < psize) {
arch_spin_unlock(&kvm->mmu_lock.rlock.raw_lock);
return H_PARAMETER;
}
pte = kvmppc_read_update_linux_pte(ptep, writing);
if (pte_present(pte) && !pte_protnone(pte)) {
if (writing && !pte_write(pte))
/* make the actual HPTE be read-only */
ptel = hpte_make_readonly(ptel);
is_ci = pte_ci(pte);
pa = pte_pfn(pte) << PAGE_SHIFT;
pa |= hva & (host_pte_size - 1);
pa |= gpa & ~PAGE_MASK;
}
}
arch_spin_unlock(&kvm->mmu_lock.rlock.raw_lock);
ptel &= HPTE_R_KEY | HPTE_R_PP0 | (psize-1);
ptel |= pa;
if (pa)
pteh |= HPTE_V_VALID;
else {
pteh |= HPTE_V_ABSENT;
ptel &= ~(HPTE_R_KEY_HI | HPTE_R_KEY_LO);
}
/*If we had host pte mapping then Check WIMG */
if (ptep && !hpte_cache_flags_ok(ptel, is_ci)) {
if (is_ci)
return H_PARAMETER;
/*
* Allow guest to map emulated device memory as
* uncacheable, but actually make it cacheable.
*/
ptel &= ~(HPTE_R_W|HPTE_R_I|HPTE_R_G);
ptel |= HPTE_R_M;
}
/* Find and lock the HPTEG slot to use */
do_insert:
if (pte_index >= kvmppc_hpt_npte(&kvm->arch.hpt))
return H_PARAMETER;
if (likely((flags & H_EXACT) == 0)) {
pte_index &= ~7UL;
hpte = (__be64 *)(kvm->arch.hpt.virt + (pte_index << 4));
for (i = 0; i < 8; ++i) {
if ((be64_to_cpu(*hpte) & HPTE_V_VALID) == 0 &&
try_lock_hpte(hpte, HPTE_V_HVLOCK | HPTE_V_VALID |
HPTE_V_ABSENT))
break;
hpte += 2;
}
if (i == 8) {
/*
* Since try_lock_hpte doesn't retry (not even stdcx.
* failures), it could be that there is a free slot
* but we transiently failed to lock it. Try again,
* actually locking each slot and checking it.
*/
hpte -= 16;
for (i = 0; i < 8; ++i) {
u64 pte;
while (!try_lock_hpte(hpte, HPTE_V_HVLOCK))
cpu_relax();
pte = be64_to_cpu(hpte[0]);
if (!(pte & (HPTE_V_VALID | HPTE_V_ABSENT)))
break;
__unlock_hpte(hpte, pte);
hpte += 2;
}
if (i == 8)
return H_PTEG_FULL;
}
pte_index += i;
} else {
hpte = (__be64 *)(kvm->arch.hpt.virt + (pte_index << 4));
if (!try_lock_hpte(hpte, HPTE_V_HVLOCK | HPTE_V_VALID |
HPTE_V_ABSENT)) {
/* Lock the slot and check again */
u64 pte;
while (!try_lock_hpte(hpte, HPTE_V_HVLOCK))
cpu_relax();
pte = be64_to_cpu(hpte[0]);
if (pte & (HPTE_V_VALID | HPTE_V_ABSENT)) {
__unlock_hpte(hpte, pte);
return H_PTEG_FULL;
}
}
Annotation
- Immediate include surface: `linux/types.h`, `linux/string.h`, `linux/kvm.h`, `linux/kvm_host.h`, `linux/hugetlb.h`, `linux/module.h`, `linux/log2.h`, `linux/sizes.h`.
- Detected declarations: `function global_invalidates`, `function kvmppc_add_revmap_chain`, `function kvmppc_update_dirty_map`, `function kvmppc_set_dirty_from_hpte`, `function remove_revmap_chain`, `function kvmppc_do_h_enter`, `function compute_tlbie_rb`, `function kvmppc_h_enter`, `function is_mmio_hpte`, `function fixup_tlbie_lpid`.
- Atlas domain: Architecture Layer / arch/powerpc.
- Implementation status: integration implementation candidate.
- 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.