arch/powerpc/kvm/e500_mmu_host.c
Source file repositories/reference/linux-study-clean/arch/powerpc/kvm/e500_mmu_host.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/kvm/e500_mmu_host.c- Extension
.c- Size
- 20536 bytes
- Lines
- 757
- 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.
- 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/types.hlinux/slab.hlinux/string.hlinux/kvm.hlinux/kvm_host.hlinux/highmem.hlinux/log2.hlinux/uaccess.hlinux/sched/mm.hlinux/rwsem.hlinux/vmalloc.hlinux/hugetlb.hasm/kvm_ppc.hasm/pte-walk.he500.htiming.he500_mmu_host.htrace_booke.h
Detected Declarations
function tlb1_max_shadow_sizefunction e500_shadow_mas3_attribfunction __write_host_tlbefunction get_host_mas0function write_host_tlbefunction write_stlbefunction kvmppc_map_magicfunction inval_gtlbe_on_hostfunction tlbe_is_writablefunction kvmppc_e500_tlbe_setupfunction kvmppc_e500_tlbe_releasefunction clear_tlb1_bitmapfunction clear_tlb_privsfunction kvmppc_core_flush_tlbfunction kvmppc_e500_setup_stlbefunction kvmppc_e500_shadow_mapfunction kvmppc_e500_tlb0_mapfunction kvmppc_e500_tlb1_map_tlb1function kvmppc_e500_tlb1_mapfunction kvmppc_mmu_mapfunction kvmppc_load_last_instfunction unlikelyfunction kvmppc_load_last_instfunction kvm_e500_mmu_unmap_gfnfunction kvm_unmap_gfn_rangefunction kvm_age_gfnfunction kvm_test_age_gfnfunction e500_mmu_host_initfunction e500_mmu_host_uninit
Annotated Snippet
while (tmp) {
hw_tlb_indx = __ilog2_u64(tmp & -tmp);
mtspr(SPRN_MAS0,
MAS0_TLBSEL(1) |
MAS0_ESEL(to_htlb1_esel(hw_tlb_indx)));
mtspr(SPRN_MAS1, 0);
asm volatile("tlbwe");
vcpu_e500->h2g_tlb1_rmap[hw_tlb_indx] = 0;
tmp &= tmp - 1;
}
mb();
vcpu_e500->g2h_tlb1_map[esel] = 0;
tlbe->flags &= ~(E500_TLB_BITMAP | E500_TLB_VALID);
local_irq_restore(flags);
}
if (tlbsel == 1 && tlbe->flags & E500_TLB_TLB0) {
/*
* TLB1 entry is backed by 4k pages. This should happen
* rarely and is not worth optimizing. Invalidate everything.
*/
kvmppc_e500_tlbil_all(vcpu_e500);
tlbe->flags &= ~(E500_TLB_TLB0 | E500_TLB_VALID);
}
/*
* If TLB entry is still valid then it's a TLB0 entry, and thus
* backed by at most one host tlbe per shadow pid
*/
if (tlbe->flags & E500_TLB_VALID)
kvmppc_e500_tlbil_one(vcpu_e500, gtlbe);
/* Mark the TLB as not backed by the host anymore */
tlbe->flags = 0;
}
static inline int tlbe_is_writable(struct kvm_book3e_206_tlb_entry *tlbe)
{
return tlbe->mas7_3 & (MAS3_SW|MAS3_UW);
}
static inline void kvmppc_e500_tlbe_setup(struct tlbe_priv *tlbe,
struct kvm_book3e_206_tlb_entry *gtlbe,
kvm_pfn_t pfn, unsigned int wimg,
bool writable)
{
tlbe->pfn = pfn;
tlbe->flags = E500_TLB_VALID;
if (writable)
tlbe->flags |= E500_TLB_WRITABLE;
/* Use guest supplied MAS2_G and MAS2_E */
tlbe->flags |= (gtlbe->mas2 & MAS2_ATTRIB_MASK) | wimg;
}
static inline void kvmppc_e500_tlbe_release(struct tlbe_priv *tlbe)
{
if (tlbe->flags & E500_TLB_VALID) {
/* FIXME: don't log bogus pfn for TLB1 */
trace_kvm_booke206_ref_release(tlbe->pfn, tlbe->flags);
tlbe->flags = 0;
}
}
static void clear_tlb1_bitmap(struct kvmppc_vcpu_e500 *vcpu_e500)
{
if (vcpu_e500->g2h_tlb1_map)
memset(vcpu_e500->g2h_tlb1_map, 0,
sizeof(u64) * vcpu_e500->gtlb_params[1].entries);
if (vcpu_e500->h2g_tlb1_rmap)
memset(vcpu_e500->h2g_tlb1_rmap, 0,
sizeof(unsigned int) * host_tlb_params[1].entries);
}
static void clear_tlb_privs(struct kvmppc_vcpu_e500 *vcpu_e500)
{
int tlbsel;
int i;
for (tlbsel = 0; tlbsel <= 1; tlbsel++) {
for (i = 0; i < vcpu_e500->gtlb_params[tlbsel].entries; i++)
kvmppc_e500_tlbe_release(&vcpu_e500->gtlb_priv[tlbsel][i]);
}
}
void kvmppc_core_flush_tlb(struct kvm_vcpu *vcpu)
{
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
kvmppc_e500_tlbil_all(vcpu_e500);
clear_tlb_privs(vcpu_e500);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `linux/slab.h`, `linux/string.h`, `linux/kvm.h`, `linux/kvm_host.h`, `linux/highmem.h`, `linux/log2.h`.
- Detected declarations: `function tlb1_max_shadow_size`, `function e500_shadow_mas3_attrib`, `function __write_host_tlbe`, `function get_host_mas0`, `function write_host_tlbe`, `function write_stlbe`, `function kvmppc_map_magic`, `function inval_gtlbe_on_host`, `function tlbe_is_writable`, `function kvmppc_e500_tlbe_setup`.
- Atlas domain: Architecture Layer / arch/powerpc.
- Implementation status: source 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.