Drivers: hv: Introduce new driver - mshv_vtl
Subsystems (2)
v7 cover Drivers: hv: Introduce new driver - mshv_vtl
Introduce a new mshv_vtl driver to provide an interface for Virtual Machine Monitor like OpenVMM and its use as OpenHCL paravisor to control VTL0 (Virtual trust Level).
Expose devices and support IOCTLs for features like VTL creation, VTL0 memory management, context switch, making hypercalls, mapping VTL0 address space to VTL2 userspace, getting new VMBus messages and channel events in VTL2 etc.
OpenVMM : https://openvmm.dev/guide/
Changes since v6:
https://lore.kernel.org/all/[email protected]/
Addressed Michael's comments:
* Corrected MAX_BITMAP_SIZE size - finally
* Added missing __packed to hv_synic_overlay_page_msr
* Fixed typo in comment, added CPU hotplug info in comments
* Reverted to mutex_lock/unlock in mshv_vtl_ioctl_set_poll_file
* Unified mshv_vtl_set_reg and mshv_vtl_get_reg
* Dynamic to static allocation of reg in mshv_vtl_ioctl_(get|set)_regs
* Fixed error handling in mshv_vtl_sint_ioctl_signal_event()
Changes since v5:
https://lore.kernel.org/all/[email protected]/
Addressed Michael Kelley's suggestions:
* Added "depends on HYPERV_VTL_MODE", removed "depends on HYPERV" in Kconfig
* Removed unused macro MAX_GUEST_MEM_SIZE
* Made macro dependency explicit: MSHV_PG_OFF_CPU_MASK and MSHV_REAL_OFF_SHIFT
* Refactored and corrected how allow_bitmap is used and defined. Removed PAGE_SIZE dependency.
* Added __packed for structure definitions wherever it was missing.
* Moved hv_register_vsm_* union definitions to hvgdk_mini.h, kept mshv_synic_overlay_page_msr in the driver, renamed it and added a comment. (Nuno)
* Introduced global variables input_vtl_zero and input_vtl_normal and used them everywhere these were defined locally
* s/"page_to_phys(reg_page) >> HV_HYP_PAGE_SHIFT"/"page_to_hvpfn(reg_page)" in mshv_vtl_configure_reg_page
* Refactored mshv_vtl_vmbus_isr() to reduce complexity in finding and resetting bits similar to how vmbus_chan_sched is implemented.
* Used __get_free_page() instead in mshv_vtl_alloc_context()
* Added fallback hv_setup_vmbus_handler(vmbus_isr) in hv_vtl_setup_synic() and in hv_vtl_remove_synic().
* Maintained symmetry of functions in hv_vtl_remove_synic
* Added a note for explanation of excluding last PFN in the range provided in mshv_vtl_ioctl_add_vtl0_mem()
* Added comments for hotplug being not supported, wherever cpu_online() was used to check if CPU is online or not.
* Added a check for input.cpu to make sure it's less than nr_cpu_ids in mshv_vtl_ioctl_set_poll_file()
* Removed switch-case and implemented static tables in mshv_vtl_(get|set)_reg for reducing LOC
* Simplified mshv_vtl_ioctl_(get|set)_regs to process one register at a time, and fixed earlier bug with array of registers processing.
* Used hv_result_to_errno() in mshv_vtl_sint_ioctl_signal_event()
* Added a READ_ONCE() while reading old_eventfd in mshv_vtl_sint_ioctl_set_eventfd()
* Renamed mshv_vtl_hvcall and mshv_vtl_hvcall_setup to remove ambiguity
* Took care of latest mm patches regarding PFN_DEV, pfn_t deprecation
* Few other minor changes while reorganizing code.
Addressed Markus Elfring's suggestions:
* Used guard(mutex) for better mutex handling.
Changes since v4:
https://lore.kernel.org/all/[email protected]/
* Fixed warnings from kernel test robot for missing export.h when the kernel is compiled with W=1 option.
Some recent changes in kernel flags these warnings and that's why it was not seen in previous runs. Warnings in other Hyper-V drivers will be fixed separately.
* No functional changes
Changes since v3:
https://lore.kernel.org/all/[email protected]/
Addressed Stanislav's, Nuno's comments.
* Change data types for different variables, excluding the ones in uapi headers
* Added comment for the need of HUGEPAGES config in Kconfig.
* generalized new IOCTL names by removing VTL in their name.
* Rebased and added Saurabh's Reviewed-by tag
Changes since v2:
https://lore.kernel.org/all/[email protected]/
* Removed CONFIG_OF dependency (addressed Saurabh's comments)
* Fixed typo in "allow_map_intialized" variable name
Changes since v1:
https://lore.kernel.org/all/[email protected]/
Addressed Saurabh's comments:
* Split the patch in 2 to keep export symbols separate
* Make MSHV_VTL module tristate and fixed compilation warning that would come when HYPERV is compiled as a module.
* Remove the use of ref_count
* Split functionality of mshv_vtl_ioctl_get_set_regs to different functions mshv_vtl_ioctl_(get|set)_regs as it actually make things simpler
* Fixed use of copy_from_user in atomic context in mshv_vtl_hvcall_call. Added ToDo comment for info.
* Added extra code to free memory for vtl in error scenarios in mshv_ioctl_create_vtl()
Addressed Alok's comments regarding:
* Additional conditional checks
* corrected typo in HV_X64_REGISTER_MSR_MTRR_PHYS_MASKB case
* empty lines before return statement
* Added/edited comments, variable names, structure field names as suggested to improve documentation - no functional change here.
Naman Jain (2):
Drivers: hv: Export some symbols for mshv_vtl
Drivers: hv: Introduce mshv_vtl driver
drivers/hv/Kconfig | 22 + drivers/hv/Makefile | 7 +- drivers/hv/hv.c | 3 + drivers/hv/hyperv_vmbus.h | 1 + drivers/hv/mshv_vtl.h | 52 ++ drivers/hv/mshv_vtl_main.c | 1468 +++++++++++++++++++++++++++++++++++ drivers/hv/vmbus_drv.c | 4 +- include/hyperv/hvgdk_mini.h | 106 +++ include/uapi/linux/mshv.h | 80 ++ 9 files changed, 1741 insertions(+), 2 deletions(-) create mode 100644 drivers/hv/mshv_vtl.h create mode 100644 drivers/hv/mshv_vtl_main.c
base-commit: a933d3dc1968fcfb0ab72879ec304b1971ed1b9a
Signature · 1 line
2.34.1
PATCH v7 1/2 Drivers: hv: Export some symbols for mshv_vtl
MSHV_VTL driver is going to be introduced, which is supposed to provide interface for Virtual Machine Monitors (VMMs) to control Virtual Trust Level (VTL). Export the symbols needed to make it work (vmbus_isr, hv_context and hv_post_message).
--- drivers/hv/hv.c | 3 +++ drivers/hv/hyperv_vmbus.h | 1 + drivers/hv/vmbus_drv.c | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-)
drivers/hv/hv.c +3 -0
@@ -18,6 +18,7 @@#include <linux/clockchips.h> #include <linux/delay.h> #include <linux/interrupt.h> +#include <linux/export.h> #include <clocksource/hyperv_timer.h> #include <asm/mshyperv.h> #include <linux/set_memory.h>
@@ -25,6 +26,7 @@/* The one and only */ struct hv_context hv_context; +EXPORT_SYMBOL_GPL (hv_context);/* * hv_init - Main initialization routine.
@@ -95,6 +97,7 @@ int hv_post_message(union hv_connection_id connection_id,return hv_result (status); } +EXPORT_SYMBOL_GPL (hv_post_message);int hv_synic_alloc (void ) {
drivers/hv/hyperv_vmbus.h +1 -0
@@ -32,6 +32,7 @@*/ #define HV_UTIL_NEGO_TIMEOUT 55 +void vmbus_isr (void );/* Definitions for the monitored notification facility */ union hv_monitor_trigger_group {
drivers/hv/vmbus_drv.c +3 -1
@@ -36,6 +36,7 @@#include <linux/syscore_ops.h> #include <linux/dma-map-ops.h> #include <linux/pci.h> +#include <linux/export.h> #include <clocksource/hyperv_timer.h> #include <asm/mshyperv.h> #include "hyperv_vmbus.h"
@@ -1306,7 +1307,7 @@ static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu) } } -static void vmbus_isr (void ) +void vmbus_isr (void ) {struct hv_per_cpu_context *hv_cpu =this_cpu_ptr (hv_context.cpu_context);
@@ -1329,6 +1330,7 @@ static void vmbus_isr(void)add_interrupt_randomness (vmbus_interrupt); } +EXPORT_SYMBOL_GPL (vmbus_isr);static irqreturn_t vmbus_percpu_isr (int irq,void *dev_id) {
Signature · 1 line
2.34.1
RE: [PATCH v7 1/2] Drivers: hv: Export some symbols for mshv_vtl
From: Naman Jain <[email protected]> Sent: Monday, July 28, 2025 10:15 PM
Quoted 15 lines
MSHV_VTLdriver is going to be introduced, which is supposed to provide interface for Virtual Machine Monitors (VMMs) to control Virtual Trust Level (VTL). Export the symbols needed to make it work (vmbus_isr,hv_contextandhv_post_message).Co-developed-by Roman Kisel <[email protected]>Signed-off-by Roman Kisel <[email protected]>Co-developed-by Saurabh Sengar <[email protected]>Signed-off-by Saurabh Sengar <[email protected]>Reviewed-by Roman Kisel <[email protected]>Reviewed-by Saurabh Sengar <[email protected]>Reported-by kernel test robot <[email protected]>Signed-off-by Naman Jain <[email protected]>
Quoted 6 lines
--- drivers/hv/hv.c | 3 +++ drivers/hv/hyperv_vmbus.h | 1 + drivers/hv/vmbus_drv.c | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-)
Re: [PATCH v7 1/2] Drivers: hv: Export some symbols for mshv_vtl
In reply to Naman JainQuoted 91 lines · Naman Jain
MSHV_VTLdriver is going to be introduced, which is supposed to provide interface for Virtual Machine Monitors (VMMs) to control Virtual Trust Level (VTL). Export the symbols needed to make it work (vmbus_isr,hv_contextandhv_post_message).Co-developed-by Roman Kisel <[email protected]>Signed-off-by Roman Kisel <[email protected]>Co-developed-by Saurabh Sengar <[email protected]>Signed-off-by Saurabh Sengar <[email protected]>Reviewed-by Roman Kisel <[email protected]>Reviewed-by Saurabh Sengar <[email protected]>Reported-by kernel test robot <[email protected]>Signed-off-by Naman Jain <[email protected]>--- drivers/hv/hv.c | 3 +++ drivers/hv/hyperv_vmbus.h | 1 + drivers/hv/vmbus_drv.c | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-)drivers/hv/hv.c +3
-0@@ -18,6 +18,7 @@#include <linux/clockchips.h> #include <linux/delay.h> #include <linux/interrupt.h> +#include <linux/export.h> #include <clocksource/hyperv_timer.h> #include <asm/mshyperv.h> #include <linux/set_memory.h> @@ -25,6 +26,7 @@/* The one and only */ struct hv_context hv_context; +EXPORT_SYMBOL_GPL (hv_context);/* * hv_init - Main initialization routine. @@ -95,6 +97,7 @@ int hv_post_message(union hv_connection_id connection_id,return hv_result (status); } +EXPORT_SYMBOL_GPL (hv_post_message);int hv_synic_alloc (void ) {drivers/hv/hyperv_vmbus.h +1
-0@@ -32,6 +32,7 @@*/ #define HV_UTIL_NEGO_TIMEOUT 55 +void vmbus_isr (void );/* Definitions for the monitored notification facility */ union hv_monitor_trigger_group {drivers/hv/vmbus_drv.c +3
-2@@ -36,6 +36,7 @@#include <linux/syscore_ops.h> #include <linux/dma-map-ops.h> #include <linux/pci.h> +#include <linux/export.h> #include <clocksource/hyperv_timer.h> #include <asm/mshyperv.h> #include "hyperv_vmbus.h" @@ -1306,7 +1307,7 @@ static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu) } } -static void vmbus_isr (void ) +void vmbus_isr (void ) {struct hv_per_cpu_context *hv_cpu =this_cpu_ptr (hv_context.cpu_context);@@ -1329,6 +1330,7 @@ static void vmbus_isr(void)add_interrupt_randomness (vmbus_interrupt); } +EXPORT_SYMBOL_GPL (vmbus_isr);static irqreturn_t vmbus_percpu_isr (int irq,void *dev_id) { --
Quoted 3 lines
2.34.1
Signature · 2 lines
Thanks Tianyu Lan
PATCH v7 2/2 Drivers: hv: Introduce mshv_vtl driver
In reply to Naman JainProvide an interface for Virtual Machine Monitor like OpenVMM and its use as OpenHCL paravisor to control VTL0 (Virtual trust Level). Expose devices and support IOCTLs for features like VTL creation, VTL0 memory management, context switch, making hypercalls, mapping VTL0 address space to VTL2 userspace, getting new VMBus messages and channel events in VTL2 etc.
--- drivers/hv/Kconfig | 22 + drivers/hv/Makefile | 7 +- drivers/hv/mshv_vtl.h | 52 ++ drivers/hv/mshv_vtl_main.c | 1468 +++++++++++++++++++++++++++++++++++ include/hyperv/hvgdk_mini.h | 106 +++ include/uapi/linux/mshv.h | 80 ++ 6 files changed, 1734 insertions(+), 1 deletion(-) create mode 100644 drivers/hv/mshv_vtl.h create mode 100644 drivers/hv/mshv_vtl_main.c
drivers/hv/Kconfig +22 -0
@@ -73,4 +73,26 @@ config MSHV_ROOT If unsure, say N. +config MSHV_VTL + tristate "Microsoft Hyper-V VTL driver" + depends on X86_64 && HYPERV_VTL_MODE + # Mapping VTL0 memory to a userspace process in VTL2 is supported in OpenHCL. + # VTL2 for OpenHCL makes use of Huge Pages to improve performance on VMs, + # specially with large memory requirements. + depends on TRANSPARENT_HUGEPAGE + # MTRRs are controlled by VTL0, and are not specific to individual VTLs. + # Therefore, do not attempt to access or modify MTRRs here. + depends on !MTRR + select CPUMASK_OFFSTACK + default n + help + Select this option to enable Hyper-V VTL driver support. + This driver provides interfaces for Virtual Machine Manager (VMM) running in VTL2 + userspace to create VTLs and partitions, setup and manage VTL0 memory and + allow userspace to make direct hypercalls. This also allows to map VTL0's address + space to a usermode process in VTL2 and supports getting new VMBus messages and channel + events in VTL2. + + If unsure, say N. + endmenu
drivers/hv/Makefile +6 -1
@@ -3,6 +3,7 @@ obj-$(CONFIG_HYPERV) += hv_vmbus.o obj-$(CONFIG_HYPERV_UTILS) += hv_utils.o obj-$(CONFIG_HYPERV_BALLOON) += hv_balloon.o obj-$(CONFIG_MSHV_ROOT) += mshv_root.o +obj-$(CONFIG_MSHV_VTL) += mshv_vtl.o CFLAGS_hv_trace.o = -I$(src) CFLAGS_hv_balloon.o = -I$(src)
@@ -14,7 +15,11 @@ hv_vmbus-$(CONFIG_HYPERV_TESTING) += hv_debugfs.o hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_utils_transport.o mshv_root-y := mshv_root_main.o mshv_synic.o mshv_eventfd.o mshv_irq.o \ mshv_root_hv_call.o mshv_portid_table.o +mshv_vtl-y := mshv_vtl_main.o # Code that must be built-in obj-$(subst m,y,$(CONFIG_HYPERV)) += hv_common.o -obj-$(subst m,y,$(CONFIG_MSHV_ROOT)) += hv_proc.o mshv_common.o +obj-$(subst m,y,$(CONFIG_MSHV_ROOT)) += hv_proc.o +ifneq ($(CONFIG_MSHV_ROOT) $(CONFIG_MSHV_VTL),) + obj-y += mshv_common.o +endif
drivers/hv/mshv_vtl.h new file +52 -0
52 lines not on this page · raw message
drivers/hv/mshv_vtl_main.c new file +1468 -0
1,468 lines not on this page · raw message
include/hyperv/hvgdk_mini.h +106 -0
118 lines not on this page · raw message
include/uapi/linux/mshv.h +80 -0
84 lines not on this page · raw message
Signature · 1 line
2.34.1
RE: [PATCH v7 2/2] Drivers: hv: Introduce mshv_vtl driver
From: Naman Jain <[email protected]> Sent: Monday, July 28, 2025 10:15 PM
Quoted 17 lines
Provide an interface for Virtual Machine Monitor like OpenVMM and its use as OpenHCL paravisor to control VTL0 (Virtual trust Level). Expose devices and support IOCTLs for features like VTL creation, VTL0 memory management, context switch, making hypercalls, mapping VTL0 address space to VTL2 userspace, getting new VMBus messages and channel events in VTL2 etc.
Co-developed-by Roman Kisel <[email protected]>Signed-off-by Roman Kisel <[email protected]>Co-developed-by Saurabh Sengar <[email protected]>Signed-off-by Saurabh Sengar <[email protected]>Reviewed-by Roman Kisel <[email protected]>Reviewed-by Alok Tiwari <[email protected]>Reviewed-by Saurabh Sengar <[email protected]>Reviewed-by Nuno Das Neves <[email protected]>Signed-off-by Naman Jain <[email protected]>
Quoted 11 lines
--- drivers/hv/Kconfig | 22 + drivers/hv/Makefile | 7 +- drivers/hv/mshv_vtl.h | 52 ++ drivers/hv/mshv_vtl_main.c | 1468 +++++++++++++++++++++++++++++++++++ include/hyperv/hvgdk_mini.h | 106 +++ include/uapi/linux/mshv.h | 80 ++ 6 files changed, 1734 insertions(+), 1 deletion(-) create mode 100644 drivers/hv/mshv_vtl.h create mode 100644 drivers/hv/mshv_vtl_main.c
Looks good!
On Tue, Jul 29, 2025 at 10:44:34AM +0530, Naman Jain wrote:
[...]
Quoted 4 lines
Naman Jain (2):
Drivers: hv: Export some symbols formshv_vtl
Drivers: hv: Introducemshv_vtldriver
Queued for hyperv-next, thanks!