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.

Dependency Surface

Detected Declarations

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

Implementation Notes