drivers/hv/mshv_root_main.c
Source file repositories/reference/linux-study-clean/drivers/hv/mshv_root_main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hv/mshv_root_main.c- Extension
.c- Size
- 62596 bytes
- Lines
- 2418
- Domain
- Driver Families
- Bucket
- drivers/hv
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/entry-virt.hlinux/kernel.hlinux/module.hlinux/fs.hlinux/miscdevice.hlinux/slab.hlinux/file.hlinux/anon_inodes.hlinux/mm.hlinux/io.hlinux/cpuhotplug.hlinux/random.hasm/mshyperv.hlinux/hyperv.hlinux/notifier.hlinux/reboot.hlinux/kexec.hlinux/page-flags.hlinux/crash_dump.hlinux/panic_notifier.hlinux/vmalloc.hlinux/rseq.hmshv_eventfd.hmshv.hmshv_root.h
Detected Declarations
function mshv_hvcall_is_asyncfunction mshv_passthru_hvcall_allowedfunction mshv_ioctl_passthru_hvcallfunction is_ghcb_mapping_availablefunction mshv_get_vp_registersfunction mshv_set_vp_registersfunction naturefunction orderfunction mshv_vp_dispatchfunction mshv_vp_clear_explicit_suspendfunction mshv_vp_interrupt_pendingfunction mshv_vp_interrupt_pendingfunction mshv_vp_dispatch_thread_blockedfunction mshv_vp_wait_for_hv_kickfunction mshv_run_vp_with_root_schedulerfunction mshv_partition_region_by_gfnfunction hlist_for_each_entryfunction mshv_partition_region_by_gfn_getfunction mshv_handle_gpa_interceptfunction mshv_vp_handle_interceptfunction mshv_vp_ioctl_run_vpfunction mshv_vp_ioctl_get_set_state_pfnfunction mshv_vp_ioctl_get_set_statefunction mshv_vp_ioctlfunction mshv_vp_faultfunction mshv_vp_mmapfunction mshv_vp_releasefunction mshv_vp_stats_unmapfunction mshv_vp_stats_mapfunction mshv_partition_ioctl_create_vpfunction mshv_init_async_handlerfunction mshv_async_hvcall_handlerfunction mshv_partition_create_regionfunction mshv_prepare_pinned_regionfunction vfio_pci_mmap_faultfunction mshv_unmap_user_memoryfunction mshv_partition_ioctl_set_memoryfunction mshv_partition_ioctl_ioeventfdfunction mshv_partition_ioctl_irqfdfunction mshv_partition_ioctl_get_gpap_access_bitmapfunction mshv_partition_ioctl_set_msi_routingfunction mshv_partition_ioctl_initializefunction mshv_partition_ioctlfunction disable_vp_dispatchfunction get_vp_signaled_countfunction drain_vp_signalsfunction drain_all_vpsfunction remove_partition
Annotated Snippet
static const struct file_operations mshv_vp_fops = {
.owner = THIS_MODULE,
.release = mshv_vp_release,
.unlocked_ioctl = mshv_vp_ioctl,
.llseek = noop_llseek,
.mmap = mshv_vp_mmap,
};
static const struct file_operations mshv_partition_fops = {
.owner = THIS_MODULE,
.release = mshv_partition_release,
.unlocked_ioctl = mshv_partition_ioctl,
.llseek = noop_llseek,
};
static const struct file_operations mshv_dev_fops = {
.owner = THIS_MODULE,
.open = mshv_dev_open,
.release = mshv_dev_release,
.unlocked_ioctl = mshv_dev_ioctl,
.llseek = noop_llseek,
};
static struct miscdevice mshv_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "mshv",
.fops = &mshv_dev_fops,
.mode = 0600,
};
/*
* Only allow hypercalls that have a u64 partition id as the first member of
* the input structure.
* These are sorted by value.
*/
static u16 mshv_passthru_hvcalls[] = {
HVCALL_GET_PARTITION_PROPERTY,
HVCALL_GET_PARTITION_PROPERTY_EX,
HVCALL_SET_PARTITION_PROPERTY,
HVCALL_INSTALL_INTERCEPT,
HVCALL_GET_VP_REGISTERS,
HVCALL_SET_VP_REGISTERS,
HVCALL_TRANSLATE_VIRTUAL_ADDRESS,
HVCALL_CLEAR_VIRTUAL_INTERRUPT,
HVCALL_REGISTER_INTERCEPT_RESULT,
HVCALL_ASSERT_VIRTUAL_INTERRUPT,
HVCALL_GET_GPA_PAGES_ACCESS_STATES,
HVCALL_SIGNAL_EVENT_DIRECT,
HVCALL_POST_MESSAGE_DIRECT,
HVCALL_GET_VP_CPUID_VALUES,
};
/*
* Only allow hypercalls that are safe to be called by the VMM with the host
* partition as target (i.e. HV_PARTITION_ID_SELF). Carefully audit that a
* hypercall cannot be misused by the VMM before adding it to this list.
*/
static u16 mshv_self_passthru_hvcalls[] = {
HVCALL_GET_PARTITION_PROPERTY,
HVCALL_GET_PARTITION_PROPERTY_EX,
};
static bool mshv_hvcall_is_async(u16 code)
{
switch (code) {
case HVCALL_SET_PARTITION_PROPERTY:
return true;
default:
break;
}
return false;
}
static bool mshv_passthru_hvcall_allowed(u16 code, u64 pt_id)
{
int i;
int n = ARRAY_SIZE(mshv_passthru_hvcalls);
u16 *allowed_hvcalls = mshv_passthru_hvcalls;
if (pt_id == HV_PARTITION_ID_SELF) {
n = ARRAY_SIZE(mshv_self_passthru_hvcalls);
allowed_hvcalls = mshv_self_passthru_hvcalls;
}
for (i = 0; i < n; ++i)
if (allowed_hvcalls[i] == code)
return true;
return false;
}
Annotation
- Immediate include surface: `linux/entry-virt.h`, `linux/kernel.h`, `linux/module.h`, `linux/fs.h`, `linux/miscdevice.h`, `linux/slab.h`, `linux/file.h`, `linux/anon_inodes.h`.
- Detected declarations: `function mshv_hvcall_is_async`, `function mshv_passthru_hvcall_allowed`, `function mshv_ioctl_passthru_hvcall`, `function is_ghcb_mapping_available`, `function mshv_get_vp_registers`, `function mshv_set_vp_registers`, `function nature`, `function order`, `function mshv_vp_dispatch`, `function mshv_vp_clear_explicit_suspend`.
- Atlas domain: Driver Families / drivers/hv.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.