drivers/xen/unpopulated-alloc.c
Source file repositories/reference/linux-study-clean/drivers/xen/unpopulated-alloc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/xen/unpopulated-alloc.c- Extension
.c- Size
- 5603 bytes
- Lines
- 252
- Domain
- Driver Families
- Bucket
- drivers/xen
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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/errno.hlinux/gfp.hlinux/kernel.hlinux/mm.hlinux/memremap.hlinux/slab.hasm/page.hxen/balloon.hxen/page.hxen/xen.h
Detected Declarations
function arch_xen_unpopulated_initfunction fill_listfunction xen_alloc_unpopulated_pagesfunction xen_free_unpopulated_pagesfunction unpopulated_initexport xen_alloc_unpopulated_pagesexport xen_free_unpopulated_pages
Annotated Snippet
if (!tmp_res) {
ret = -ENOMEM;
goto err_insert;
}
tmp_res->name = res->name;
tmp_res->start = res->start;
tmp_res->end = res->end;
tmp_res->flags = res->flags;
ret = request_resource(&iomem_resource, tmp_res);
if (ret < 0) {
pr_err("Cannot request resource %pR (%d)\n", tmp_res, ret);
kfree(tmp_res);
goto err_insert;
}
}
pgmap = kzalloc_obj(*pgmap);
if (!pgmap) {
ret = -ENOMEM;
goto err_pgmap;
}
pgmap->type = MEMORY_DEVICE_GENERIC;
pgmap->range = (struct range) {
.start = res->start,
.end = res->end,
};
pgmap->nr_range = 1;
pgmap->owner = res;
#ifdef CONFIG_XEN_HAVE_PVMMU
/*
* memremap will build page tables for the new memory so
* the p2m must contain invalid entries so the correct
* non-present PTEs will be written.
*
* If a failure occurs, the original (identity) p2m entries
* are not restored since this region is now known not to
* conflict with any devices.
*/
if (xen_pv_domain()) {
xen_pfn_t pfn = PFN_DOWN(res->start);
for (i = 0; i < alloc_pages; i++) {
if (!set_phys_to_machine(pfn + i, INVALID_P2M_ENTRY)) {
pr_warn("set_phys_to_machine() failed, no memory added\n");
ret = -ENOMEM;
goto err_memremap;
}
}
}
#endif
vaddr = memremap_pages(pgmap, NUMA_NO_NODE);
if (IS_ERR(vaddr)) {
pr_err("Cannot remap memory range\n");
ret = PTR_ERR(vaddr);
goto err_memremap;
}
for (i = 0; i < alloc_pages; i++) {
struct page *pg = virt_to_page(vaddr + PAGE_SIZE * i);
pg->zone_device_data = page_list;
page_list = pg;
list_count++;
}
return 0;
err_memremap:
kfree(pgmap);
err_pgmap:
if (tmp_res) {
release_resource(tmp_res);
kfree(tmp_res);
}
err_insert:
release_resource(res);
err_resource:
kfree(res);
return ret;
}
/**
* xen_alloc_unpopulated_pages - alloc unpopulated pages
* @nr_pages: Number of pages
* @pages: pages returned
Annotation
- Immediate include surface: `linux/errno.h`, `linux/gfp.h`, `linux/kernel.h`, `linux/mm.h`, `linux/memremap.h`, `linux/slab.h`, `asm/page.h`, `xen/balloon.h`.
- Detected declarations: `function arch_xen_unpopulated_init`, `function fill_list`, `function xen_alloc_unpopulated_pages`, `function xen_free_unpopulated_pages`, `function unpopulated_init`, `export xen_alloc_unpopulated_pages`, `export xen_free_unpopulated_pages`.
- Atlas domain: Driver Families / drivers/xen.
- 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.