drivers/hv/mshv_regions.c
Source file repositories/reference/linux-study-clean/drivers/hv/mshv_regions.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hv/mshv_regions.c- Extension
.c- Size
- 16935 bytes
- Lines
- 588
- Domain
- Driver Families
- Bucket
- drivers/hv
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/hmm.hlinux/hyperv.hlinux/kref.hlinux/mm.hlinux/vmalloc.hasm/mshyperv.hmshv_root.h
Detected Declarations
function mshv_chunk_stridefunction sizefunction mshv_region_process_rangefunction mshv_region_chunk_sharefunction mshv_region_sharefunction mshv_region_chunk_unsharefunction mshv_region_unsharefunction mshv_region_chunk_remapfunction mshv_region_remap_pagesfunction mshv_region_mapfunction mshv_region_invalidate_pagesfunction mshv_region_invalidatefunction mshv_region_pinfunction mshv_region_chunk_unmapfunction mshv_region_unmapfunction mshv_region_destroyfunction mshv_region_putfunction mshv_region_getfunction hmm_range_faultfunction mshv_region_range_faultfunction mshv_region_handle_gfn_faultfunction mshv_region_interval_invalidatefunction mshv_region_movable_finifunction mshv_region_movable_init
Annotated Snippet
if (!region->mreg_pages[page_offset]) {
page_offset++;
page_count--;
continue;
}
ret = mshv_region_process_chunk(region, flags,
page_offset,
page_count,
handler);
if (ret < 0)
return ret;
page_offset += ret;
page_count -= ret;
}
return 0;
}
struct mshv_mem_region *mshv_region_create(u64 guest_pfn, u64 nr_pages,
u64 uaddr, u32 flags)
{
struct mshv_mem_region *region;
region = vzalloc(sizeof(*region) + sizeof(struct page *) * nr_pages);
if (!region)
return ERR_PTR(-ENOMEM);
region->nr_pages = nr_pages;
region->start_gfn = guest_pfn;
region->start_uaddr = uaddr;
region->hv_map_flags = HV_MAP_GPA_READABLE | HV_MAP_GPA_ADJUSTABLE;
if (flags & BIT(MSHV_SET_MEM_BIT_WRITABLE))
region->hv_map_flags |= HV_MAP_GPA_WRITABLE;
if (flags & BIT(MSHV_SET_MEM_BIT_EXECUTABLE))
region->hv_map_flags |= HV_MAP_GPA_EXECUTABLE;
kref_init(®ion->mreg_refcount);
return region;
}
static int mshv_region_chunk_share(struct mshv_mem_region *region,
u32 flags,
u64 page_offset, u64 page_count,
bool huge_page)
{
if (huge_page)
flags |= HV_MODIFY_SPA_PAGE_HOST_ACCESS_LARGE_PAGE;
return hv_call_modify_spa_host_access(region->partition->pt_id,
region->mreg_pages + page_offset,
page_count,
HV_MAP_GPA_READABLE |
HV_MAP_GPA_WRITABLE,
flags, true);
}
int mshv_region_share(struct mshv_mem_region *region)
{
u32 flags = HV_MODIFY_SPA_PAGE_HOST_ACCESS_MAKE_SHARED;
return mshv_region_process_range(region, flags,
0, region->nr_pages,
mshv_region_chunk_share);
}
static int mshv_region_chunk_unshare(struct mshv_mem_region *region,
u32 flags,
u64 page_offset, u64 page_count,
bool huge_page)
{
if (huge_page)
flags |= HV_MODIFY_SPA_PAGE_HOST_ACCESS_LARGE_PAGE;
return hv_call_modify_spa_host_access(region->partition->pt_id,
region->mreg_pages + page_offset,
page_count, 0,
flags, false);
}
int mshv_region_unshare(struct mshv_mem_region *region)
{
u32 flags = HV_MODIFY_SPA_PAGE_HOST_ACCESS_MAKE_EXCLUSIVE;
return mshv_region_process_range(region, flags,
0, region->nr_pages,
mshv_region_chunk_unshare);
}
Annotation
- Immediate include surface: `linux/hmm.h`, `linux/hyperv.h`, `linux/kref.h`, `linux/mm.h`, `linux/vmalloc.h`, `asm/mshyperv.h`, `mshv_root.h`.
- Detected declarations: `function mshv_chunk_stride`, `function size`, `function mshv_region_process_range`, `function mshv_region_chunk_share`, `function mshv_region_share`, `function mshv_region_chunk_unshare`, `function mshv_region_unshare`, `function mshv_region_chunk_remap`, `function mshv_region_remap_pages`, `function mshv_region_map`.
- Atlas domain: Driver Families / drivers/hv.
- 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.