arch/x86/xen/p2m.c
Source file repositories/reference/linux-study-clean/arch/x86/xen/p2m.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/xen/p2m.c- Extension
.c- Size
- 24197 bytes
- Lines
- 886
- Domain
- Architecture Layer
- Bucket
- arch/x86
- 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/init.hlinux/export.hlinux/list.hlinux/hash.hlinux/sched.hlinux/seq_file.hlinux/memblock.hlinux/slab.hlinux/vmalloc.hlinux/acpi.hasm/cache.hasm/setup.hlinux/uaccess.hasm/xen/page.hasm/xen/hypercall.hasm/xen/hypervisor.hxen/balloon.hxen/grant_table.hxen/hvc-console.hxen-ops.h
Detected Declarations
function p2m_top_indexfunction p2m_mid_indexfunction p2m_top_mfn_initfunction p2m_top_mfn_p_initfunction p2m_mid_mfn_initfunction p2m_initfunction p2m_init_identityfunction alloc_p2m_pagefunction free_p2m_pagefunction xen_build_mfn_list_listfunction xen_setup_mfn_list_listfunction xen_build_dynamic_phys_to_machinefunction xen_p2m_elem_typefunction xen_rebuild_p2m_listfunction xen_vmalloc_p2m_treefunction get_phys_to_machinefunction pmdfunction xen_alloc_p2m_entryfunction set_phys_range_identityfunction __set_phys_to_machinefunction set_phys_to_machinefunction set_foreign_p2m_mappingfunction clear_foreign_p2m_mappingfunction xen_do_remap_nonramfunction acpi_os_ioremapfunction xen_add_remap_nonramexport xen_p2m_addrexport xen_p2m_sizeexport xen_max_p2m_pfnexport get_phys_to_machineexport xen_alloc_p2m_entry
Annotated Snippet
if (ptep == p2m_missing_pte || ptep == p2m_identity_pte) {
BUG_ON(mididx);
BUG_ON(mid_mfn_p != p2m_mid_missing_mfn);
p2m_top_mfn[topidx] = virt_to_mfn(p2m_mid_missing_mfn);
pfn += (P2M_MID_PER_PAGE - 1) * P2M_PER_PAGE;
continue;
}
if (mid_mfn_p == p2m_mid_missing_mfn) {
mid_mfn_p = alloc_p2m_page();
p2m_mid_mfn_init(mid_mfn_p, p2m_missing);
p2m_top_mfn_p[topidx] = mid_mfn_p;
}
p2m_top_mfn[topidx] = virt_to_mfn(mid_mfn_p);
mid_mfn_p[mididx] = mfn;
}
}
void xen_setup_mfn_list_list(void)
{
BUG_ON(HYPERVISOR_shared_info == &xen_dummy_shared_info);
if (xen_start_info->flags & SIF_VIRT_P2M_4TOOLS)
HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = ~0UL;
else
HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =
virt_to_mfn(p2m_top_mfn);
HYPERVISOR_shared_info->arch.max_pfn = xen_p2m_last_pfn;
HYPERVISOR_shared_info->arch.p2m_generation = 0;
HYPERVISOR_shared_info->arch.p2m_vaddr = (unsigned long)xen_p2m_addr;
HYPERVISOR_shared_info->arch.p2m_cr3 =
xen_pfn_to_cr3(virt_to_mfn(swapper_pg_dir));
}
/* Set up p2m_top to point to the domain-builder provided p2m pages */
void __init xen_build_dynamic_phys_to_machine(void)
{
unsigned long pfn;
xen_p2m_addr = (unsigned long *)xen_start_info->mfn_list;
xen_p2m_size = ALIGN(xen_start_info->nr_pages, P2M_PER_PAGE);
for (pfn = xen_start_info->nr_pages; pfn < xen_p2m_size; pfn++)
xen_p2m_addr[pfn] = INVALID_P2M_ENTRY;
xen_max_p2m_pfn = xen_p2m_size;
}
#define P2M_TYPE_IDENTITY 0
#define P2M_TYPE_MISSING 1
#define P2M_TYPE_PFN 2
#define P2M_TYPE_UNKNOWN 3
static int xen_p2m_elem_type(unsigned long pfn)
{
unsigned long mfn;
if (pfn >= xen_p2m_size)
return P2M_TYPE_IDENTITY;
mfn = xen_p2m_addr[pfn];
if (mfn == INVALID_P2M_ENTRY)
return P2M_TYPE_MISSING;
if (mfn & IDENTITY_FRAME_BIT)
return P2M_TYPE_IDENTITY;
return P2M_TYPE_PFN;
}
static void __init xen_rebuild_p2m_list(unsigned long *p2m)
{
unsigned int i, chunk;
unsigned long pfn;
unsigned long *mfns;
pte_t *ptep;
pmd_t *pmdp;
int type;
p2m_missing = alloc_p2m_page();
p2m_init(p2m_missing);
p2m_identity = alloc_p2m_page();
p2m_init(p2m_identity);
p2m_missing_pte = alloc_p2m_page();
paravirt_alloc_pte(&init_mm, __pa(p2m_missing_pte) >> PAGE_SHIFT);
p2m_identity_pte = alloc_p2m_page();
Annotation
- Immediate include surface: `linux/init.h`, `linux/export.h`, `linux/list.h`, `linux/hash.h`, `linux/sched.h`, `linux/seq_file.h`, `linux/memblock.h`, `linux/slab.h`.
- Detected declarations: `function p2m_top_index`, `function p2m_mid_index`, `function p2m_top_mfn_init`, `function p2m_top_mfn_p_init`, `function p2m_mid_mfn_init`, `function p2m_init`, `function p2m_init_identity`, `function alloc_p2m_page`, `function free_p2m_page`, `function xen_build_mfn_list_list`.
- Atlas domain: Architecture Layer / arch/x86.
- 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.