drivers/xen/xlate_mmu.c
Source file repositories/reference/linux-study-clean/drivers/xen/xlate_mmu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/xen/xlate_mmu.c- Extension
.c- Size
- 7924 bytes
- Lines
- 296
- 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.
- 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/mm.hlinux/slab.hlinux/vmalloc.hasm/xen/hypercall.hasm/xen/hypervisor.hxen/xen.hxen/xen-ops.hxen/page.hxen/interface/xen.hxen/interface/memory.hxen/balloon.h
Detected Declarations
struct remap_datastruct map_balloon_pagesstruct remap_pfnfunction xen_for_each_gfnfunction setup_hparamsfunction remap_pte_fnfunction xen_xlate_remap_gfn_arrayfunction unmap_gfnfunction xen_xlate_unmap_gfn_rangefunction setup_balloon_gfnfunction xen_xlate_map_ballooned_pagesfunction remap_pfn_fnfunction xen_remap_vma_rangeexport xen_xlate_remap_gfn_arrayexport xen_xlate_unmap_gfn_rangeexport xen_remap_vma_range
Annotated Snippet
struct remap_data {
xen_pfn_t *fgfn; /* foreign domain's gfn */
int nr_fgfn; /* Number of foreign gfn left to map */
pgprot_t prot;
domid_t domid;
struct vm_area_struct *vma;
int index;
struct page **pages;
struct xen_remap_gfn_info *info;
int *err_ptr;
int mapped;
/* Hypercall parameters */
int h_errs[XEN_PFN_PER_PAGE];
xen_ulong_t h_idxs[XEN_PFN_PER_PAGE];
xen_pfn_t h_gpfns[XEN_PFN_PER_PAGE];
int h_iter; /* Iterator */
};
static void setup_hparams(unsigned long gfn, void *data)
{
struct remap_data *info = data;
info->h_idxs[info->h_iter] = *info->fgfn;
info->h_gpfns[info->h_iter] = gfn;
info->h_errs[info->h_iter] = 0;
info->h_iter++;
info->fgfn++;
}
static int remap_pte_fn(pte_t *ptep, unsigned long addr, void *data)
{
struct remap_data *info = data;
struct page *page = info->pages[info->index++];
pte_t pte = pte_mkspecial(pfn_pte(page_to_pfn(page), info->prot));
int rc, nr_gfn;
uint32_t i;
struct xen_add_to_physmap_range xatp = {
.domid = DOMID_SELF,
.foreign_domid = info->domid,
.space = XENMAPSPACE_gmfn_foreign,
};
nr_gfn = min_t(typeof(info->nr_fgfn), XEN_PFN_PER_PAGE, info->nr_fgfn);
info->nr_fgfn -= nr_gfn;
info->h_iter = 0;
xen_for_each_gfn(&page, nr_gfn, setup_hparams, info);
BUG_ON(info->h_iter != nr_gfn);
set_xen_guest_handle(xatp.idxs, info->h_idxs);
set_xen_guest_handle(xatp.gpfns, info->h_gpfns);
set_xen_guest_handle(xatp.errs, info->h_errs);
xatp.size = nr_gfn;
rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap_range, &xatp);
/* info->err_ptr expect to have one error status per Xen PFN */
for (i = 0; i < nr_gfn; i++) {
int err = (rc < 0) ? rc : info->h_errs[i];
*(info->err_ptr++) = err;
if (!err)
info->mapped++;
}
/*
* Note: The hypercall will return 0 in most of the case if even if
* all the fgmfn are not mapped. We still have to update the pte
* as the userspace may decide to continue.
*/
if (!rc)
set_pte_at(info->vma->vm_mm, addr, ptep, pte);
return 0;
}
int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
unsigned long addr,
xen_pfn_t *gfn, int nr,
int *err_ptr, pgprot_t prot,
unsigned domid,
struct page **pages)
{
int err;
struct remap_data data;
unsigned long range = DIV_ROUND_UP(nr, XEN_PFN_PER_PAGE) << PAGE_SHIFT;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/mm.h`, `linux/slab.h`, `linux/vmalloc.h`, `asm/xen/hypercall.h`, `asm/xen/hypervisor.h`, `xen/xen.h`, `xen/xen-ops.h`.
- Detected declarations: `struct remap_data`, `struct map_balloon_pages`, `struct remap_pfn`, `function xen_for_each_gfn`, `function setup_hparams`, `function remap_pte_fn`, `function xen_xlate_remap_gfn_array`, `function unmap_gfn`, `function xen_xlate_unmap_gfn_range`, `function setup_balloon_gfn`.
- Atlas domain: Driver Families / drivers/xen.
- Implementation status: integration implementation candidate.
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.