arch/powerpc/mm/book3s64/mmu_context.c
Source file repositories/reference/linux-study-clean/arch/powerpc/mm/book3s64/mmu_context.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/mm/book3s64/mmu_context.c- Extension
.c- Size
- 8903 bytes
- Lines
- 346
- 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/sched.hlinux/kernel.hlinux/errno.hlinux/string.hlinux/types.hlinux/mm.hlinux/pkeys.hlinux/spinlock.hlinux/idr.hlinux/export.hlinux/gfp.hlinux/slab.hlinux/cpu.hasm/mmu_context.hasm/pgalloc.hinternal.h
Detected Declarations
function alloc_context_idfunction hash__reserve_context_idfunction hash__alloc_context_idfunction realloc_context_idsfunction hash__init_new_contextfunction init_new_contextfunction hash__setup_new_execfunction hash__init_new_contextfunction radix__init_new_contextfunction init_new_contextfunction __destroy_contextfunction destroy_contextsfunction pmd_frag_destroyfunction destroy_pagetable_cachefunction destroy_contextfunction arch_exit_mmapfunction radix__switch_mmu_contextfunction cleanup_cpu_mmu_contextexport hash__alloc_context_idexport __destroy_context
Annotated Snippet
if (i == 0 || ctx->extended_id[i]) {
id = hash__alloc_context_id();
if (id < 0)
goto error;
ctx->extended_id[i] = id;
}
}
/* The caller expects us to return id */
return ctx->id;
error:
for (i--; i >= 0; i--) {
if (ctx->extended_id[i])
ida_free(&mmu_context_ida, ctx->extended_id[i]);
}
return id;
}
static int hash__init_new_context(struct mm_struct *mm)
{
int index;
mm->context.hash_context = kmalloc_obj(struct hash_mm_context);
if (!mm->context.hash_context)
return -ENOMEM;
/*
* The old code would re-promote on fork, we don't do that when using
* slices as it could cause problem promoting slices that have been
* forced down to 4K.
*
* For book3s we have MMU_NO_CONTEXT set to be ~0. Hence check
* explicitly against context.id == 0. This ensures that we properly
* initialize context slice details for newly allocated mm's (which will
* have id == 0) and don't alter context slice inherited via fork (which
* will have id != 0).
*
* We should not be calling init_new_context() on init_mm. Hence a
* check against 0 is OK.
*/
if (mm->context.id == 0) {
memset(mm->context.hash_context, 0, sizeof(struct hash_mm_context));
slice_init_new_context_exec(mm);
} else {
/* This is fork. Copy hash_context details from current->mm */
memcpy(mm->context.hash_context, current->mm->context.hash_context, sizeof(struct hash_mm_context));
#ifdef CONFIG_PPC_SUBPAGE_PROT
/* inherit subpage prot details if we have one. */
if (current->mm->context.hash_context->spt) {
mm->context.hash_context->spt = kmalloc_obj(struct subpage_prot_table);
if (!mm->context.hash_context->spt) {
kfree(mm->context.hash_context);
return -ENOMEM;
}
}
#endif
}
index = realloc_context_ids(&mm->context);
if (index < 0) {
#ifdef CONFIG_PPC_SUBPAGE_PROT
kfree(mm->context.hash_context->spt);
#endif
kfree(mm->context.hash_context);
return index;
}
pkey_mm_init(mm);
return index;
}
void hash__setup_new_exec(void)
{
slice_setup_new_exec();
}
#else
static inline int hash__init_new_context(struct mm_struct *mm)
{
BUILD_BUG();
return 0;
}
#endif
static int radix__init_new_context(struct mm_struct *mm)
{
unsigned long rts_field;
int index, max_id;
Annotation
- Immediate include surface: `linux/sched.h`, `linux/kernel.h`, `linux/errno.h`, `linux/string.h`, `linux/types.h`, `linux/mm.h`, `linux/pkeys.h`, `linux/spinlock.h`.
- Detected declarations: `function alloc_context_id`, `function hash__reserve_context_id`, `function hash__alloc_context_id`, `function realloc_context_ids`, `function hash__init_new_context`, `function init_new_context`, `function hash__setup_new_exec`, `function hash__init_new_context`, `function radix__init_new_context`, `function init_new_context`.
- 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.