Drivers: hv: Add ARM64 support in mshv_vtl
Subsystems (6)
cover Drivers: hv: Add ARM64 support in mshv_vtl
The series intends to add support for ARM64 to mshv_vtl driver. For this, common Hyper-V code is refactored, necessary support is added, mshv_vtl_main.c is refactored and then finally support is added in Kconfig.
Based on commit 1f318b96cc84 ("Linux 7.0-rc3")
Naman Jain (11):
arch: arm64: Export arch_smp_send_reschedule for mshv_vtl module
Drivers: hv: Move hv_vp_assist_page to common files
Drivers: hv: Add support to setup percpu vmbus handler
Drivers: hv: Refactor mshv_vtl for ARM64 support to be added
drivers: hv: Export vmbus_interrupt for mshv_vtl module
Drivers: hv: Make sint vector architecture neutral in MSHV_VTL
arch: arm64: Add support for mshv_vtl_return_call
Drivers: hv: mshv_vtl: Move register page config to arch-specific
files
Drivers: hv: mshv_vtl: Let userspace do VSM configuration
Drivers: hv: Add support for arm64 in MSHV_VTL
Drivers: hv: Kconfig: Add ARM64 support for MSHV_VTL
arch/arm64/hyperv/Makefile | 1 + arch/arm64/hyperv/hv_vtl.c | 152 ++++++++++++++++++++++ arch/arm64/hyperv/mshyperv.c | 13 ++ arch/arm64/include/asm/mshyperv.h | 28 ++++ arch/arm64/kernel/smp.c | 1 + arch/x86/hyperv/hv_init.c | 88 +------------ arch/x86/hyperv/hv_vtl.c | 130 +++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 8 +- drivers/hv/Kconfig | 2 +- drivers/hv/hv_common.c | 99 +++++++++++++++ drivers/hv/mshv.h | 8 -- drivers/hv/mshv_vtl_main.c | 205 ++++-------------------------- drivers/hv/vmbus_drv.c | 8 +- include/asm-generic/mshyperv.h | 49 +++++++ include/hyperv/hvgdk_mini.h | 2 + 15 files changed, 505 insertions(+), 289 deletions(-) create mode 100644 arch/arm64/hyperv/hv_vtl.c
base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
prerequisite-patch-id: 24022ec1fb63bc20de8114eedf03c81bb1086e0e
prerequisite-patch-id: 801f2588d5c6db4ceb9a6705a09e4649fab411b1
prerequisite-patch-id: 581c834aa268f0c54120c6efbc1393fbd9893f49
prerequisite-patch-id: b0b153807bab40860502c52e4a59297258ade0db
prerequisite-patch-id: 2bff6accea80e7976c58d80d847cd33f260a3cb9
prerequisite-patch-id: 296ffbc4f119a5b249bc9c840f84129f5c151139
prerequisite-patch-id: 3b54d121145e743ac5184518df33a1812280ec96
prerequisite-patch-id: 06fc5b37b23ee3f91a2c8c9b9c126fde290834f2
prerequisite-patch-id: 6e8afed988309b03485f5538815ea29c8fa5b0a9
prerequisite-patch-id: 4f1fb1b7e9cfa8a3b1c02fafecdbb432b74ee367
prerequisite-patch-id: 49944347e0b2d93e72911a153979c567ebb7e66b
prerequisite-patch-id: 6dec75498eeae6365d15ac12b5d0a3bd32e9f91c
Signature · 1 line
2.43.0
PATCH 1/11 arch: arm64: Export arch_smp_send_reschedule for mshv_vtl module
mshv_vtl_main.c calls smp_send_reschedule() which expands to arch_smp_send_reschedule(). When CONFIG_MSHV_VTL=m, the module cannot access this symbol since it is not exported on arm64.
smp_send_reschedule() is used in mshv_vtl_cancel() to interrupt a vCPU thread running on another CPU. When a vCPU is looping in mshv_vtl_ioctl_return_to_lower_vtl(), it checks a per-CPU cancel flag before each VTL0 entry. Setting cancel=1 alone is not enough if the target CPU thread is sleeping - the IPI from smp_send_reschedule() kicks the remote CPU out of idle/sleep so it re-checks the cancel flag and exits the loop promptly.
Other architectures (riscv, loongarch, powerpc) already export this symbol. Add the same EXPORT_SYMBOL_GPL for arm64. This is required for adding arm64 support in MSHV_VTL.
--- arch/arm64/kernel/smp.c | 1 + 1 file changed, 1 insertion(+)
arch/arm64/kernel/smp.c +1 -0
@@ -1152,6 +1152,7 @@ void arch_smp_send_reschedule(int cpu) {smp_cross_call (cpumask_of (cpu),IPI_RESCHEDULE ); } +EXPORT_SYMBOL_GPL (arch_smp_send_reschedule);#ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL void arch_send_wakeup_ipi (unsigned int cpu)
Signature · 1 line
2.43.0
PATCH 2/11 Drivers: hv: Move hv_vp_assist_page to common files
In reply to Naman JainMove the logic to initialize and export hv_vp_assist_page from x86 architecture code to Hyper-V common code to allow it to be used for upcoming arm64 support in MSHV_VTL driver.
Note: This change also improves error handling - if VP assist page allocation fails, hyperv_init() now returns early instead of continuing with partial initialization.
--- arch/x86/hyperv/hv_init.c | 88 +--------------------------------- drivers/hv/hv_common.c | 88 ++++++++++++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 4 ++ include/hyperv/hvgdk_mini.h | 2 + 4 files changed, 95 insertions(+), 87 deletions(-)
arch/x86/hyperv/hv_init.c +1 -87
@@ -81,9 +81,6 @@ union hv_ghcb * __percpu *hv_ghcb_pg;/* Storage to save the hypercall page temporarily for hibernation */ static void *hv_hypercall_pg_saved; -struct hv_vp_assist_page **hv_vp_assist_page; -EXPORT_SYMBOL_GPL (hv_vp_assist_page); -static int hyperv_init_ghcb (void ) {u64 ghcb_gpa;
@@ -117,59 +114,12 @@ static int hyperv_init_ghcb(void)static int hv_cpu_init (unsigned int cpu) { -union hv_vp_assist_msr_contents msr = {0 }; -struct hv_vp_assist_page **hvp;int ret; ret =hv_common_cpu_init (cpu);if (ret)return ret; -if (!hv_vp_assist_page) -return 0 ; - - hvp = &hv_vp_assist_page[cpu]; -if (hv_root_partition ()) { -/* -* For root partition we get the hypervisor provided VP assist -* page, instead of allocating a new page. -*/ -rdmsrq (HV_X64_MSR_VP_ASSIST_PAGE , msr.as_uint64); - *hvp =memremap (msr.pfn <<HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT , -PAGE_SIZE ,MEMREMAP_WB ); - }else { -/* -* The VP assist page is an "overlay" page (see Hyper-V TLFS's -* Section 5.2.1 "GPA Overlay Pages"). Here it must be zeroed -* out to make sure we always write the EOI MSR in -* hv_apic_eoi_write() *after* the EOI optimization is disabled -* in hv_cpu_die(), otherwise a CPU may not be stopped in the -* case of CPU offlining and the VM will hang. -*/ -if (!*hvp) { - *hvp =__vmalloc (PAGE_SIZE ,GFP_KERNEL | __GFP_ZERO); - -/* -* Hyper-V should never specify a VM that is a Confidential -* VM and also running in the root partition. Root partition -* is blocked to run in Confidential VM. So only decrypt assist -* page in non-root partition here. -*/ -if (*hvp && !ms_hyperv.paravisor_present &&hv_isolation_type_snp ()) { -WARN_ON_ONCE (set_memory_decrypted ((unsigned long )(*hvp),1 )); -memset (*hvp,0 ,PAGE_SIZE ); - } - } - -if (*hvp) - msr.pfn =vmalloc_to_pfn (*hvp); - - } -if (!WARN_ON (!(*hvp))) { - msr.enable =1 ; -wrmsrq (HV_X64_MSR_VP_ASSIST_PAGE , msr.as_uint64); - } -/* Allow Hyper-V stimer vector to be injected from Hypervisor. */ if (ms_hyperv.misc_features &HV_STIMER_DIRECT_MODE_AVAILABLE )apic_update_vector (cpu,HYPERV_STIMER0_VECTOR , true);
@@ -286,23 +236,6 @@ static int hv_cpu_die(unsigned int cpu)hv_common_cpu_die (cpu); -if (hv_vp_assist_page && hv_vp_assist_page[cpu]) { -union hv_vp_assist_msr_contents msr = {0 }; -if (hv_root_partition ()) { -/* -* For root partition the VP assist page is mapped to -* hypervisor provided page, and thus we unmap the -* page here and nullify it, so that in future we have -* correct page address mapped in hv_cpu_init. -*/ -memunmap (hv_vp_assist_page[cpu]); - hv_vp_assist_page[cpu] =NULL ; -rdmsrq (HV_X64_MSR_VP_ASSIST_PAGE , msr.as_uint64); - msr.enable =0 ; - } -wrmsrq (HV_X64_MSR_VP_ASSIST_PAGE , msr.as_uint64); - } -if (hv_reenlightenment_cb ==NULL )return 0 ;
@@ -460,21 +393,6 @@ void __init hyperv_init(void)if (hv_common_init ())return ; -/* -* The VP assist page is useless to a TDX guest: the only use we -* would have for it is lazy EOI, which can not be used with TDX. -*/ -if (hv_isolation_type_tdx ()) - hv_vp_assist_page =NULL ; -else - hv_vp_assist_page =kzalloc_objs (*hv_vp_assist_page, nr_cpu_ids); -if (!hv_vp_assist_page) { - ms_hyperv.hints &= ~HV_X64_ENLIGHTENED_VMCS_RECOMMENDED ; - -if (!hv_isolation_type_tdx ()) - goto common_free; - } -if (ms_hyperv.paravisor_present &&hv_isolation_type_snp ()) {/* Negotiate GHCB Version. */ if (!hv_ghcb_negotiate_protocol ())
@@ -483,7 +401,7 @@ void __init hyperv_init(void) hv_ghcb_pg = alloc_percpu(union hv_ghcb *);if (!hv_ghcb_pg) - goto free_vp_assist_page; + goto free_ghcb_page; } cpuhp = cpuhp_setup_state(CPUHP_AP_HYPERV_ONLINE, "x86/hyperv_init:online",
@@ -613,10 +531,6 @@ void __init hyperv_init(void)cpuhp_remove_state (CPUHP_AP_HYPERV_ONLINE ); free_ghcb_page:free_percpu (hv_ghcb_pg); -free_vp_assist_page: -kfree (hv_vp_assist_page); - hv_vp_assist_page =NULL ; -common_free:hv_common_free (); }
drivers/hv/hv_common.c +88 -0
131 lines not on this page · raw message
include/asm-generic/mshyperv.h +4 -0
@@ -25,6 +25,7 @@#include <linux/nmi.h> #include <asm/ptrace.h> #include <hyperv/hvhdk.h> +#include <hyperv/hvgdk.h> #define VTPM_BASE_ADDRESS 0xfed40000
@@ -299,6 +300,8 @@ do { \#define hv_status_debug (status, fmt, ...) \ hv_status_printk(debug, status, fmt, ##__VA_ARGS__) +extern struct hv_vp_assist_page **hv_vp_assist_page; +const char *hv_result_to_string (u64 hv_status);int hv_result_to_errno (u64 status);void hyperv_report_panic (struct pt_regs *regs,long err,bool in_die);
@@ -377,6 +380,7 @@ static inline int hv_deposit_memory(u64 partition_id, u64 status)return hv_deposit_memory_node (NUMA_NO_NODE , partition_id, status); } +#define HV_VP_ASSIST_PAGE_ADDRESS_SHIFT 12#if IS_ENABLED (CONFIG_HYPERV_VTL_MODE )u8 __init get_vtl (void );#else
include/hyperv/hvgdk_mini.h +2 -0
@@ -149,6 +149,7 @@ struct hv_u128 {#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT 12#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_MASK \ (~((1ull << HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT) - 1)) +#define HV_SYN_REG_VP_ASSIST_PAGE (HV_X64_MSR_VP_ASSIST_PAGE)/* Hyper-V Enlightened VMCS version mask in nested features CPUID */ #define HV_X64_ENLIGHTENED_VMCS_VERSION 0xff
@@ -1185,6 +1186,7 @@ enum hv_register_name {#define HV_MSR_STIMER0_CONFIG (HV_REGISTER_STIMER0_CONFIG)#define HV_MSR_STIMER0_COUNT (HV_REGISTER_STIMER0_COUNT) +#define HV_SYN_REG_VP_ASSIST_PAGE (HV_REGISTER_VP_ASSIST_PAGE)#endif /* CONFIG_ARM64 */
Signature · 1 line
2.43.0
PATCH 3/11 Drivers: hv: Add support to setup percpu vmbus handler
In reply to Naman JainAdd a wrapper function - hv_setup_percpu_vmbus_handler(), similar to hv_setup_vmbus_handler() to allow setting up custom per-cpu VMBus interrupt handler. This is required for arm64 support, to be added in MSHV_VTL driver, where per-cpu VMBus interrupt handler will be set to mshv_vtl_vmbus_isr() for VTL2 (Virtual Trust Level 2).
--- arch/arm64/hyperv/mshyperv.c | 13 +++++++++++++ drivers/hv/hv_common.c | 11 +++++++++++ drivers/hv/vmbus_drv.c | 7 +------ include/asm-generic/mshyperv.h | 3 +++ 4 files changed, 28 insertions(+), 6 deletions(-)
arch/arm64/hyperv/mshyperv.c +13 -0
@@ -134,3 +134,16 @@ bool hv_is_hyperv_initialized(void)return hyperv_initialized; }EXPORT_SYMBOL_GPL (hv_is_hyperv_initialized); + +static void (*vmbus_percpu_handler)(void ); +void hv_setup_percpu_vmbus_handler (void (*handler)(void )) +{ + vmbus_percpu_handler = handler; +} + +irqreturn_t vmbus_percpu_isr (int irq,void *dev_id) +{ +if (vmbus_percpu_handler) +vmbus_percpu_handler (); +return IRQ_HANDLED ; +}
drivers/hv/hv_common.c +11 -0
@@ -759,6 +759,17 @@ void __weak hv_setup_vmbus_handler(void (*handler)(void)) }EXPORT_SYMBOL_GPL (hv_setup_vmbus_handler); +irqreturn_t __weak vmbus_percpu_isr (int irq,void *dev_id) +{ +return IRQ_HANDLED ; +} +EXPORT_SYMBOL_GPL (vmbus_percpu_isr); + +void __weak hv_setup_percpu_vmbus_handler (void (*handler)(void )) +{ +} +EXPORT_SYMBOL_GPL (hv_setup_percpu_vmbus_handler); +void __weak hv_remove_vmbus_handler (void ) { }
drivers/hv/vmbus_drv.c +1 -6
@@ -1413,12 +1413,6 @@ void vmbus_isr(void) }EXPORT_SYMBOL_FOR_MODULES (vmbus_isr,"mshv_vtl" ); -static irqreturn_t vmbus_percpu_isr (int irq,void *dev_id) -{ -vmbus_isr (); -return IRQ_HANDLED ; -} -static void vmbus_percpu_work (struct work_struct *work) {unsigned int cpu =smp_processor_id ();
@@ -1520,6 +1514,7 @@ static int vmbus_bus_init(void)if (vmbus_irq ==-1 ) {hv_setup_vmbus_handler (vmbus_isr); }else { +hv_setup_percpu_vmbus_handler (vmbus_isr); ret =request_percpu_irq (vmbus_irq, vmbus_percpu_isr,"Hyper-V VMbus" , &vmbus_evt);if (ret) {
include/asm-generic/mshyperv.h +3 -0
@@ -22,6 +22,7 @@#include <linux/bitops.h> #include <acpi/acpi_numa.h> #include <linux/cpumask.h> +#include <linux/interrupt.h> #include <linux/nmi.h> #include <asm/ptrace.h> #include <hyperv/hvhdk.h>
@@ -179,6 +180,8 @@ static inline u64 hv_generate_guest_id(u64 kernel_version)int hv_get_hypervisor_version (union hv_hypervisor_version_info *info); +irqreturn_t vmbus_percpu_isr (int irq,void *dev_id); +void hv_setup_percpu_vmbus_handler (void (*handler)(void ));void hv_setup_vmbus_handler (void (*handler)(void ));void hv_remove_vmbus_handler (void );void hv_setup_stimer0_handler (void (*handler)(void ));
Signature · 1 line
2.43.0
PATCH 4/11 Drivers: hv: Refactor mshv_vtl for ARM64 support to be added
In reply to Naman JainRefactor MSHV_VTL driver to move some of the x86 specific code to arch specific files, and add corresponding functions for arm64.
--- arch/arm64/include/asm/mshyperv.h | 10 +++ arch/x86/hyperv/hv_vtl.c | 98 ++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 1 + drivers/hv/mshv_vtl_main.c | 102 +----------------------------- 4 files changed, 111 insertions(+), 100 deletions(-)
arch/arm64/include/asm/mshyperv.h +10 -0
@@ -60,6 +60,16 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg) ARM_SMCCC_SMC_64, \ ARM_SMCCC_OWNER_VENDOR_HYP, \ HV_SMCCC_FUNC_NUMBER) +#ifdef CONFIG_HYPERV_VTL_MODE +/* +* Get/Set the register. If the function returns `1`, that must be done via +* a hypercall. Returning `0` means success. +*/ +static inline int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared) +{ +return 1 ; +} +#endif #include <asm-generic/mshyperv.h>
arch/x86/hyperv/hv_vtl.c +98 -0
107 lines not on this page · raw message
arch/x86/include/asm/mshyperv.h +1 -0
@@ -304,6 +304,7 @@ void mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0);void mshv_vtl_return_call_init (u64 vtl_return_offset);void mshv_vtl_return_hypercall (void );void __mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0); +int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared);#else static inline void __init hv_vtl_init_platform (void ) {}static inline int __init hv_vtl_early_init (void ) {return 0 ; }
drivers/hv/mshv_vtl_main.c +2 -100
128 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 5/11 drivers: hv: Export vmbus_interrupt for mshv_vtl module
In reply to Naman Jainvmbus_interrupt is used in mshv_vtl_main.c to set the SINT vector. When CONFIG_MSHV_VTL=m and CONFIG_HYPERV_VMBUS=y (built-in), the module cannot access vmbus_interrupt at load time since it is not exported.
Export it using EXPORT_SYMBOL_FOR_MODULES consistent with the existing pattern used for vmbus_isr.
--- drivers/hv/vmbus_drv.c | 1 + 1 file changed, 1 insertion(+)
drivers/hv/vmbus_drv.c +1 -0
@@ -57,6 +57,7 @@ static DEFINE_PER_CPU(long, vmbus_evt);/* Values parsed from ACPI DSDT */ int vmbus_irq;int vmbus_interrupt; +EXPORT_SYMBOL_FOR_MODULES (vmbus_interrupt,"mshv_vtl" );/* * If the Confidential VMBus is used, the data on the "wire" is not
Signature · 1 line
2.43.0
PATCH 6/11 Drivers: hv: Make sint vector architecture neutral in MSHV_VTL
In reply to Naman JainGeneralize Synthetic interrupt source vector (sint) to use vmbus_interrupt variable instead, which automatically takes care of architectures where HYPERVISOR_CALLBACK_VECTOR is not present (arm64).
--- drivers/hv/mshv_vtl_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hv/mshv_vtl_main.c +2 -2
@@ -234,7 +234,7 @@ static void mshv_vtl_synic_enable_regs(unsigned int cpu)union hv_synic_sint sint; sint.as_uint64 =0 ; - sint.vector =HYPERVISOR_CALLBACK_VECTOR ; + sint.vector = vmbus_interrupt; sint.masked = false; sint.auto_eoi =hv_recommend_using_aeoi ();
@@ -753,7 +753,7 @@ static void mshv_vtl_synic_mask_vmbus_sint(void *info)const u8 *mask = info; sint.as_uint64 =0 ; - sint.vector =HYPERVISOR_CALLBACK_VECTOR ; + sint.vector = vmbus_interrupt; sint.masked = (*mask !=0 ); sint.auto_eoi =hv_recommend_using_aeoi ();
Signature · 1 line
2.43.0
PATCH 7/11 arch: arm64: Add support for mshv_vtl_return_call
In reply to Naman JainAdd support for arm64 specific variant of mshv_vtl_return_call function to be able to add support for arm64 in MSHV_VTL driver. This would help enable the transition between Virtual Trust Levels (VTL) in MSHV_VTL when the kernel acts as a paravisor.
--- arch/arm64/hyperv/Makefile | 1 + arch/arm64/hyperv/hv_vtl.c | 144 ++++++++++++++++++++++++++++++ arch/arm64/include/asm/mshyperv.h | 13 +++ 3 files changed, 158 insertions(+) create mode 100644 arch/arm64/hyperv/hv_vtl.c
arch/arm64/hyperv/Makefile +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 obj-y := hv_core.o mshyperv.o +obj-$(CONFIG_HYPERV_VTL_MODE) += hv_vtl.o
arch/arm64/hyperv/hv_vtl.c new file +144 -0
144 lines not on this page · raw message
arch/arm64/include/asm/mshyperv.h +13 -0
@@ -60,6 +60,17 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg) ARM_SMCCC_SMC_64, \ ARM_SMCCC_OWNER_VENDOR_HYP, \ HV_SMCCC_FUNC_NUMBER) + +struct mshv_vtl_cpu_context { +/* +* NOTE: x18 is managed by the hypervisor. It won't be reloaded from this array. +* It is included here for convenience in the common case. +*/ +__u64 x[31 ]; +__u64 rsvd; +__uint128_t q[32 ]; +}; +#ifdef CONFIG_HYPERV_VTL_MODE /* * Get/Set the register. If the function returns `1`, that must be done via
@@ -69,6 +80,8 @@ static inline int hv_vtl_get_set_reg(struct hv_register_assoc *regs, bool set, u {return 1 ; } + +void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0);#endif #include <asm-generic/mshyperv.h>
Signature · 1 line
2.43.0
PATCH 8/11 Drivers: hv: mshv_vtl: Move register page config to arch-specific files
In reply to Naman JainMove mshv_vtl_configure_reg_page() implementation from drivers/hv/mshv_vtl_main.c to arch-specific files:
- arch/x86/hyperv/hv_vtl.c: full implementation with register page setup
- arch/arm64/hyperv/hv_vtl.c: stub implementation (unsupported)
Move common type definitions to include/asm-generic/mshyperv.h:
- struct mshv_vtl_per_cpu
- union hv_synic_overlay_page_msr
Move hv_call_get_vp_registers() and hv_call_set_vp_registers() declarations to include/asm-generic/mshyperv.h since these functions are used by multiple modules.
While at it, remove the unnecessary stub implementations in #else case for mshv_vtl_return* functions in arch/x86/include/asm/mshyperv.h.
This is essential for adding support for ARM64 in MSHV_VTL.
--- arch/arm64/hyperv/hv_vtl.c | 8 +++++ arch/arm64/include/asm/mshyperv.h | 3 ++ arch/x86/hyperv/hv_vtl.c | 32 ++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 7 ++--- drivers/hv/mshv.h | 8 ----- drivers/hv/mshv_vtl_main.c | 49 +++---------------------------- include/asm-generic/mshyperv.h | 42 ++++++++++++++++++++++++++ 7 files changed, 92 insertions(+), 57 deletions(-)
arch/arm64/hyperv/hv_vtl.c +8 -0
@@ -10,6 +10,7 @@#include <asm/boot.h> #include <asm/mshyperv.h> #include <asm/cpu_ops.h> +#include <linux/export.h> void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) {
@@ -142,3 +143,10 @@ void mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0) "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"); }EXPORT_SYMBOL (mshv_vtl_return_call); + +bool hv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu) +{ +pr_debug ("Register page not supported on ARM64\n" ); +return false; +} +EXPORT_SYMBOL_GPL (hv_vtl_configure_reg_page);
arch/arm64/include/asm/mshyperv.h +3 -0
@@ -61,6 +61,8 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg) ARM_SMCCC_OWNER_VENDOR_HYP, \ HV_SMCCC_FUNC_NUMBER) +struct mshv_vtl_per_cpu ; + struct mshv_vtl_cpu_context {/* * NOTE: x18 is managed by the hypervisor. It won't be reloaded from this array.
@@ -82,6 +84,7 @@ static inline int hv_vtl_get_set_reg(struct hv_register_assoc *regs, bool set, u }void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0); +bool hv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu);#endif #include <asm-generic/mshyperv.h>
arch/x86/hyperv/hv_vtl.c +32 -0
@@ -20,6 +20,7 @@#include <uapi/asm/mtrr.h> #include <asm/debugreg.h> #include <linux/export.h> +#include <linux/hyperv.h> #include <../kernel/smpboot.h> #include "../../kernel/fpu/legacy.h"
@@ -259,6 +260,37 @@ int __init hv_vtl_early_init(void)return 0 ; } +static const union hv_input_vtl input_vtl_zero; + +bool hv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu) +{ +struct hv_register_assoc reg_assoc = {}; +union hv_synic_overlay_page_msr overlay = {}; +struct page *reg_page; + + reg_page =alloc_page (GFP_KERNEL | __GFP_ZERO | __GFP_RETRY_MAYFAIL); +if (!reg_page) { +WARN (1 ,"failed to allocate register page\n" ); +return false; + } + + overlay.enabled =1 ; + overlay.pfn =page_to_hvpfn (reg_page); + reg_assoc.name =HV_X64_REGISTER_REG_PAGE ; + reg_assoc.value.reg64 = overlay.as_uint64; + +if (hv_call_set_vp_registers (HV_VP_INDEX_SELF ,HV_PARTITION_ID_SELF , +1 , input_vtl_zero, ®_assoc)) { +WARN (1 ,"failed to setup register page\n" ); +__free_page (reg_page); +return false; + } + + per_cpu->reg_page = reg_page; +return true; +} +EXPORT_SYMBOL_GPL (hv_vtl_configure_reg_page); + DEFINE_STATIC_CALL_NULL(__mshv_vtl_return_hypercall, void (*)(void));void mshv_vtl_return_call_init (u64 vtl_return_offset)
arch/x86/include/asm/mshyperv.h +3 -4
@@ -271,6 +271,8 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg) { return 0; }static inline int hv_apicid_to_vp_index (u32 apic_id) {return -EINVAL ; }#endif /* CONFIG_HYPERV */ +struct mshv_vtl_per_cpu ; + struct mshv_vtl_cpu_context { union { struct {
@@ -305,13 +307,10 @@ void mshv_vtl_return_call_init(u64 vtl_return_offset);void mshv_vtl_return_hypercall (void );void __mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0);int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared); +bool hv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu);#else static inline void __init hv_vtl_init_platform (void ) {}static inline int __init hv_vtl_early_init (void ) {return 0 ; } -static inline void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) {} -static inline void mshv_vtl_return_call_init (u64 vtl_return_offset) {} -static inline void mshv_vtl_return_hypercall (void ) {} -static inline void __mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) {}#endif #include <asm-generic/mshyperv.h>
drivers/hv/mshv.h +0 -8
@@ -14,14 +14,6 @@memchr_inv (&((STRUCT ).MEMBER), \ 0, sizeof_field(typeof(STRUCT), MEMBER)) -int hv_call_get_vp_registers (u32 vp_index,u64 partition_id,u16 count, -union hv_input_vtl input_vtl, -struct hv_register_assoc *registers); - -int hv_call_set_vp_registers (u32 vp_index,u64 partition_id,u16 count, -union hv_input_vtl input_vtl, -struct hv_register_assoc *registers); -int hv_call_get_partition_property (u64 partition_id,u64 property_code,u64 *property_value);
drivers/hv/mshv_vtl_main.c +4 -45
67 lines not on this page · raw message
include/asm-generic/mshyperv.h +42 -0
50 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 9/11 Drivers: hv: mshv_vtl: Let userspace do VSM configuration
In reply to Naman JainThe kernel currently sets the VSM configuration register, thereby imposing certain VSM configuration on the userspace (OpenVMM).
The userspace (OpenVMM) has the capability to configure this register, and it is already doing it using the generic hypercall interface. The configuration can vary based on the use case or architectures, so let userspace take care of configuring it and remove this logic in the kernel driver.
--- drivers/hv/mshv_vtl_main.c | 29 ----------------------------- 1 file changed, 29 deletions(-)
drivers/hv/mshv_vtl_main.c +0 -29
@@ -222,30 +222,6 @@ static int mshv_vtl_get_vsm_regs(void)return ret; } -static int mshv_vtl_configure_vsm_partition (struct device *dev) -{ -union hv_register_vsm_partition_config config; -struct hv_register_assoc reg_assoc; - - config.as_uint64 =0 ; - config.default_vtl_protection_mask =HV_MAP_GPA_PERMISSIONS_MASK ; - config.enable_vtl_protection =1 ; - config.zero_memory_on_reset =1 ; - config.intercept_vp_startup =1 ; - config.intercept_cpuid_unimplemented =1 ; - -if (mshv_vsm_capabilities.intercept_page_available) { -dev_dbg (dev,"using intercept page\n" ); - config.intercept_page =1 ; - } - - reg_assoc.name =HV_REGISTER_VSM_PARTITION_CONFIG ; - reg_assoc.value.reg64 = config.as_uint64; - -return hv_call_set_vp_registers (HV_VP_INDEX_SELF ,HV_PARTITION_ID_SELF , -1 , input_vtl_zero, ®_assoc); -} -static void mshv_vtl_vmbus_isr (void ) {struct hv_per_cpu_context *per_cpu;
@@ -1168,11 +1144,6 @@ static int __init mshv_vtl_init(void) ret = -ENODEV ; goto free_dev; } -if (mshv_vtl_configure_vsm_partition (dev)) { -dev_emerg (dev,"VSM configuration failed !!\n" ); - ret = -ENODEV ; - goto free_dev; - }mshv_vtl_return_call_init (mshv_vsm_page_offsets.vtl_return_offset); ret =hv_vtl_setup_synic ();
Signature · 1 line
2.43.0
PATCH 10/11 Drivers: hv: Add support for arm64 in MSHV_VTL
In reply to Naman JainAdd necessary support to make MSHV_VTL work for arm64 architecture.
* Add stub implementation for mshv_vtl_return_call_init(): not required for arm64
* Remove fpu/legacy.h header inclusion, as this is not required
* handle HV_REGISTER_VSM_CODE_PAGE_OFFSETS register: not supported in arm64
* Configure custom percpu_vmbus_handler by using hv_setup_percpu_vmbus_handler()
* Handle hugepage functions by config checks
--- arch/arm64/include/asm/mshyperv.h | 2 ++ drivers/hv/mshv_vtl_main.c | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-)
arch/arm64/include/asm/mshyperv.h +2 -0
@@ -83,6 +83,8 @@ static inline int hv_vtl_get_set_reg(struct hv_register_assoc *regs, bool set, u return 1; } +static inline void mshv_vtl_return_call_init (u64 vtl_return_offset) {} +void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0);bool hv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu);#endif
drivers/hv/mshv_vtl_main.c +14 -7
@@ -23,8 +23,6 @@#include <trace/events/ipi.h> #include <uapi/linux/mshv.h> #include <hyperv/hvhdk.h> - -#include "../../kernel/fpu/legacy.h" #include "mshv.h" #include "mshv_vtl.h" #include "hyperv_vmbus.h"
@@ -206,18 +204,21 @@ static void mshv_vtl_synic_enable_regs(unsigned int cpu)static int mshv_vtl_get_vsm_regs (void ) {struct hv_register_assoc registers[2 ]; -int ret, count =2 ; +int ret, count =0 ; - registers[0 ].name =HV_REGISTER_VSM_CODE_PAGE_OFFSETS ; - registers[1 ].name =HV_REGISTER_VSM_CAPABILITIES ; + registers[count++].name =HV_REGISTER_VSM_CAPABILITIES ; +/* Code page offset register is not supported on ARM */ +if (IS_ENABLED (CONFIG_X86_64 )) + registers[count++].name =HV_REGISTER_VSM_CODE_PAGE_OFFSETS ; ret =hv_call_get_vp_registers (HV_VP_INDEX_SELF ,HV_PARTITION_ID_SELF , count, input_vtl_zero, registers);if (ret)return ret; - mshv_vsm_page_offsets.as_uint64 = registers[0 ].value.reg64; - mshv_vsm_capabilities.as_uint64 = registers[1 ].value.reg64; + mshv_vsm_capabilities.as_uint64 = registers[0 ].value.reg64; +if (IS_ENABLED (CONFIG_X86_64 )) + mshv_vsm_page_offsets.as_uint64 = registers[1 ].value.reg64;return ret; }
@@ -280,10 +281,13 @@ static int hv_vtl_setup_synic(void)/* Use our isr to first filter out packets destined for userspace */ hv_setup_vmbus_handler (mshv_vtl_vmbus_isr); +/* hv_setup_vmbus_handler() is stubbed for ARM64, add per-cpu VMBus handlers instead */ +hv_setup_percpu_vmbus_handler (mshv_vtl_vmbus_isr); ret =cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"hyperv/vtl:online" , mshv_vtl_alloc_context,NULL );if (ret <0 ) { +hv_setup_percpu_vmbus_handler (vmbus_isr);hv_setup_vmbus_handler (vmbus_isr);return ret; }
@@ -296,6 +300,7 @@ static int hv_vtl_setup_synic(void)static void hv_vtl_remove_synic (void ) {cpuhp_remove_state (mshv_vtl_cpuhp_online); +hv_setup_percpu_vmbus_handler (vmbus_isr);hv_setup_vmbus_handler (vmbus_isr); }
@@ -1080,10 +1085,12 @@ static vm_fault_t mshv_vtl_low_huge_fault(struct vm_fault *vmf, unsigned int ord ret =vmf_insert_pfn_pmd (vmf, pfn, vmf->flags &FAULT_FLAG_WRITE );return ret; +#if defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD )case PUD_ORDER :if (can_fault (vmf,PUD_SIZE , &pfn)) ret =vmf_insert_pfn_pud (vmf, pfn, vmf->flags &FAULT_FLAG_WRITE );return ret; +#endif default :return VM_FAULT_SIGBUS ;
Signature · 1 line
2.43.0
PATCH 11/11 Drivers: hv: Kconfig: Add ARM64 support for MSHV_VTL
In reply to Naman JainEnable ARM64 support in MSHV_VTL Kconfig now that all the necessary support is present.
--- drivers/hv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hv/Kconfig +1 -1
@@ -87,7 +87,7 @@ config MSHV_ROOT config MSHV_VTL tristate "Microsoft Hyper-V VTL driver" - depends on X86_64 && HYPERV_VTL_MODE + depends on (X86_64 || ARM64) && HYPERV_VTL_MODE depends on HYPERV_VMBUS # 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,
Signature · 1 line
2.43.0
Quoted 8 lines · Naman Jain
The series intends to add support for ARM64 to
mshv_vtldriver. For this, common Hyper-V code is refactored, necessary support is added,mshv_vtl_main.cis refactored and then finally support is added inKconfig.
Hi Naman, Saurabh,
So awesome to see the ARM64 support for the VSM being upstreamed!!
Few of the patches carry my old Microsoft "Signed-off-by" tag, and I really appreciate you folks very much kindly adding it although the code appears to be a far more evolved and crisper version of what it was back then!
Do feel free to drop my SOB from these few patches so the below SRB doesn't look weird or as a conflict of interest - that is if you see adding my below SRB to these few patches as a good option. It's been 2 years, and after 2 years who can really remember their code :D
For the series,
Quoted 51 lines
Based on commit
1f318b96cc84("Linux 7.0-rc3")Naman Jain (11):
arch: arm64: Exportarch_smp_send_rescheduleformshv_vtlmodule
Drivers: hv: Movehv_vp_assist_pageto common files
Drivers: hv: Add support to setup percpu vmbus handler
Drivers: hv: Refactormshv_vtlfor ARM64 support to be added
drivers: hv: Exportvmbus_interruptformshv_vtlmodule
Drivers: hv: Make sint vector architecture neutral inMSHV_VTL
arch: arm64: Add support formshv_vtl_return_call
Drivers: hv:mshv_vtl: Move register page config to arch-specific
files
Drivers: hv:mshv_vtl: Let userspace do VSM configuration
Drivers: hv: Add support for arm64 inMSHV_VTL
Drivers: hv:Kconfig: Add ARM64 support forMSHV_VTLarch/arm64/hyperv/Makefile | 1 + arch/arm64/hyperv/hv_vtl.c | 152 ++++++++++++++++++++++ arch/arm64/hyperv/mshyperv.c | 13 ++ arch/arm64/include/asm/mshyperv.h | 28 ++++ arch/arm64/kernel/smp.c | 1 + arch/x86/hyperv/hv_init.c | 88 +------------ arch/x86/hyperv/hv_vtl.c | 130 +++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 8 +- drivers/hv/Kconfig | 2 +- drivers/hv/hv_common.c | 99 +++++++++++++++ drivers/hv/mshv.h | 8 -- drivers/hv/mshv_vtl_main.c | 205 ++++-------------------------- drivers/hv/vmbus_drv.c | 8 +- include/asm-generic/mshyperv.h | 49 +++++++ include/hyperv/hvgdk_mini.h | 2 + 15 files changed, 505 insertions(+), 289 deletions(-) create mode 100644 arch/arm64/hyperv/hv_vtl.cbase-commit:
1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
prerequisite-patch-id:24022ec1fb63bc20de8114eedf03c81bb1086e0e
prerequisite-patch-id:801f2588d5c6db4ceb9a6705a09e4649fab411b1
prerequisite-patch-id:581c834aa268f0c54120c6efbc1393fbd9893f49
prerequisite-patch-id:b0b153807bab40860502c52e4a59297258ade0db
prerequisite-patch-id:2bff6accea80e7976c58d80d847cd33f260a3cb9
prerequisite-patch-id:296ffbc4f119a5b249bc9c840f84129f5c151139
prerequisite-patch-id:3b54d121145e743ac5184518df33a1812280ec96
prerequisite-patch-id:06fc5b37b23ee3f91a2c8c9b9c126fde290834f2
prerequisite-patch-id:6e8afed988309b03485f5538815ea29c8fa5b0a9
prerequisite-patch-id:4f1fb1b7e9cfa8a3b1c02fafecdbb432b74ee367
prerequisite-patch-id:49944347e0b2d93e72911a153979c567ebb7e66b
prerequisite-patch-id:6dec75498eeae6365d15ac12b5d0a3bd32e9f91cSignature · 1 line
2.43.0
Quoted 18 lines · On 3/17/2026 9:04 AM, [email protected] wrote:
Quoted 8 lines · Naman Jain
The series intends to add support for ARM64 to
mshv_vtldriver. For this, common Hyper-V code is refactored, necessary support is added,mshv_vtl_main.cis refactored and then finally support is added inKconfig.Hi Naman, Saurabh,
So awesome to see the ARM64 support for the VSM being upstreamed!!
Few of the patches carry my old Microsoft "Signed-off-by" tag, and I really appreciate you folks very much kindly adding it although the code appears to be a far more evolved and crisper version of what it was back then!
Quoted 7 lines
Do feel free to drop my SOB from these few patches so the below SRB doesn't look weird or as a conflict of interest - that is if you see adding my below SRB to these few patches as a good option. It's been 2 years, and after 2 years who can really remember their code :D
For the series,
Reviewed-by Roman Kisel <[email protected]>
Thank you so much Roman for reviewing the changes. I think we can retain both the tags from you. I'll let the maintainers decide.
Regards,
Naman
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 7 lines
The series intends to add support for ARM64 to
mshv_vtldriver. For this, common Hyper-V code is refactored, necessary support is added,mshv_vtl_main.cis refactored and then finally support is added inKconfig.Based on commit
1f318b96cc84("Linux 7.0-rc3")
There's now an online LLM-based tool that is automatically reviewing kernel patches. For this patch set, the results are here:
https://sashiko.dev/#/patchset/20260316121241.910764-1-namjain%40linux.microsoft.com
It has flagged several things that are worth checking, but I haven't reviewed them to see if they are actually valid.
FWIW, the announcement about sashiko.dev is here:
https://lore.kernel.org/lkml/[email protected]/
Michael
Quoted 50 lines
Naman Jain (11):
arch: arm64: Exportarch_smp_send_rescheduleformshv_vtlmodule
Drivers: hv: Movehv_vp_assist_pageto common files
Drivers: hv: Add support to setup percpu vmbus handler
Drivers: hv: Refactormshv_vtlfor ARM64 support to be added
drivers: hv: Exportvmbus_interruptformshv_vtlmodule
Drivers: hv: Make sint vector architecture neutral inMSHV_VTL
arch: arm64: Add support formshv_vtl_return_call
Drivers: hv:mshv_vtl: Move register page config to arch-specific
files
Drivers: hv:mshv_vtl: Let userspace do VSM configuration
Drivers: hv: Add support for arm64 inMSHV_VTL
Drivers: hv:Kconfig: Add ARM64 support forMSHV_VTLarch/arm64/hyperv/Makefile | 1 + arch/arm64/hyperv/hv_vtl.c | 152 ++++++++++++++++++++++ arch/arm64/hyperv/mshyperv.c | 13 ++ arch/arm64/include/asm/mshyperv.h | 28 ++++ arch/arm64/kernel/smp.c | 1 + arch/x86/hyperv/hv_init.c | 88 +------------ arch/x86/hyperv/hv_vtl.c | 130 +++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 8 +- drivers/hv/Kconfig | 2 +- drivers/hv/hv_common.c | 99 +++++++++++++++ drivers/hv/mshv.h | 8 -- drivers/hv/mshv_vtl_main.c | 205 ++++-------------------------- drivers/hv/vmbus_drv.c | 8 +- include/asm-generic/mshyperv.h | 49 +++++++ include/hyperv/hvgdk_mini.h | 2 + 15 files changed, 505 insertions(+), 289 deletions(-) create mode 100644 arch/arm64/hyperv/hv_vtl.cbase-commit:
1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
prerequisite-patch-id:24022ec1fb63bc20de8114eedf03c81bb1086e0e
prerequisite-patch-id:801f2588d5c6db4ceb9a6705a09e4649fab411b1
prerequisite-patch-id:581c834aa268f0c54120c6efbc1393fbd9893f49
prerequisite-patch-id:b0b153807bab40860502c52e4a59297258ade0db
prerequisite-patch-id:2bff6accea80e7976c58d80d847cd33f260a3cb9
prerequisite-patch-id:296ffbc4f119a5b249bc9c840f84129f5c151139
prerequisite-patch-id:3b54d121145e743ac5184518df33a1812280ec96
prerequisite-patch-id:06fc5b37b23ee3f91a2c8c9b9c126fde290834f2
prerequisite-patch-id:6e8afed988309b03485f5538815ea29c8fa5b0a9
prerequisite-patch-id:4f1fb1b7e9cfa8a3b1c02fafecdbb432b74ee367
prerequisite-patch-id:49944347e0b2d93e72911a153979c567ebb7e66b
prerequisite-patch-id:6dec75498eeae6365d15ac12b5d0a3bd32e9f91c--
2.43.0
Quoted 14 lines · Michael Kelley
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 7 lines
The series intends to add support for ARM64 to
mshv_vtldriver. For this, common Hyper-V code is refactored, necessary support is added,mshv_vtl_main.cis refactored and then finally support is added inKconfig.Based on commit
1f318b96cc84("Linux 7.0-rc3")There's now an online LLM-based tool that is automatically reviewing kernel patches. For this patch set, the results are here:
https://sashiko.dev/#/patchset/20260316121241.910764-1-namjain%40linux.microsoft.com
Quoted 8 lines
It has flagged several things that are worth checking, but I haven't reviewed them to see if they are actually valid.
FWIW, the announcement about sashiko.dev is here:
https://lore.kernel.org/lkml/[email protected]/
Michael
Thanks for sharing Michael,
I'll check it out and do the needful.
Regards,
Naman
From: Naman Jain <[email protected]> Sent: Tuesday, March 17, 2026 9:23 PM
Quoted 5 lines · Michael Kelley
Quoted 3 lines
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 2 lines
The series intends to add support for ARM64 to
mshv_vtldriver.
No need to be tentative. :-) Just write as:
"The series adds support for ARM64 to the mshv_vtl driver."
Quoted 16 lines
Quoted 16 lines
Quoted 5 lines
For this, common Hyper-V code is refactored, necessary support is added,
mshv_vtl_main.cis refactored and then finally support is added inKconfig.Based on commit
1f318b96cc84("Linux 7.0-rc3")There's now an online LLM-based tool that is automatically reviewing kernel patches. For this patch set, the results are here:
https://sashiko.dev/#/patchset/20260316121241.910764-1-namjain%40linux.microsoft.com
It has flagged several things that are worth checking, but I haven't reviewed them to see if they are actually valid.
FWIW, the announcement about sashiko.dev is here:
Quoted 8 lines
Quoted 3 lines
https://lore.kernel.org/lkml/[email protected]/
Michael
Thanks for sharing Michael,
I'll check it out and do the needful.
I've done a full review of this patch set and provided comments in the individual patches. Some of my comments reference the Sashiko AI comments, but there are still some Sashiko AI comments to consider that I haven't referenced.
FWIW, the Sashiko AI comments are quite good -- it found some things here that I missed on my own, and in my earlier reviews of the original VTL code. :-(
Michael
RE: [PATCH 01/11] arch: arm64: Export arch_smp_send_reschedule for mshv_vtl module
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 1 line
Nit: For the patch "Subject", the most common prefix for the file arch/arm64/kernel/smp.c is "arm64: smp:". I'd suggest using that prefix for historical consistency.
Quoted 34 lines
mshv_vtl_main.ccallssmp_send_reschedule()which expands toarch_smp_send_reschedule(). WhenCONFIG_MSHV_VTL=m, the module cannot access this symbol since it is not exported on arm64.
smp_send_reschedule()is used inmshv_vtl_cancel()to interrupt a vCPU thread running on another CPU. When a vCPU is looping inmshv_vtl_ioctl_return_to_lower_vtl(), it checks a per-CPU cancel flag before each VTL0 entry. Setting cancel=1 alone is not enough if the target CPU thread is sleeping - the IPI fromsmp_send_reschedule()kicks the remote CPU out of idle/sleep so it re-checks the cancel flag and exits the loop promptly.Other architectures (riscv, loongarch, powerpc) already export this symbol. Add the same
EXPORT_SYMBOL_GPLfor arm64. This is required for adding arm64 support inMSHV_VTL.Signed-off-by Naman Jain <[email protected]>--- arch/arm64/kernel/smp.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/kernel/smp.c +1
-1@@ -1152,6 +1152,7 @@ void arch_smp_send_reschedule(int cpu) {smp_cross_call (cpumask_of (cpu),IPI_RESCHEDULE ); } +EXPORT_SYMBOL_GPL (arch_smp_send_reschedule);#ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL void arch_send_wakeup_ipi (unsigned int cpu) --
Quoted 2 lines
2.43.0
The "Subject" nit notwithstanding,
RE: [PATCH 02/11] Drivers: hv: Move hv_vp_assist_page to common files
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 162 lines
Move the logic to initialize and export
hv_vp_assist_pagefrom x86 architecture code to Hyper-V common code to allow it to be used for upcoming arm64 support inMSHV_VTLdriver.
Note: This change also improves error handling - if VP assist page allocation fails,hyperv_init()now returns early instead of continuing with partial initialization.Signed-off-by Roman Kisel <[email protected]>Signed-off-by Naman Jain <[email protected]>--- arch/x86/hyperv/hv_init.c | 88 +--------------------------------- drivers/hv/hv_common.c | 88 ++++++++++++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 4 ++ include/hyperv/hvgdk_mini.h | 2 + 4 files changed, 95 insertions(+), 87 deletions(-)arch/x86/hyperv/hv_init.c +1
-87@@ -81,9 +81,6 @@ union hv_ghcb * __percpu *hv_ghcb_pg;/* Storage to save the hypercall page temporarily for hibernation */ static void *hv_hypercall_pg_saved; -struct hv_vp_assist_page **hv_vp_assist_page; -EXPORT_SYMBOL_GPL (hv_vp_assist_page); -static int hyperv_init_ghcb (void ) {u64 ghcb_gpa;@@ -117,59 +114,12 @@ static int hyperv_init_ghcb(void)static int hv_cpu_init (unsigned int cpu) { -union hv_vp_assist_msr_contents msr = {0 }; -struct hv_vp_assist_page **hvp;int ret; ret =hv_common_cpu_init (cpu);if (ret)return ret; -if (!hv_vp_assist_page) -return 0 ; - - hvp = &hv_vp_assist_page[cpu]; -if (hv_root_partition ()) { -/* -* For root partition we get the hypervisor provided VP assist -* page, instead of allocating a new page. -*/ -rdmsrq (HV_X64_MSR_VP_ASSIST_PAGE , msr.as_uint64); - *hvp =memremap (msr.pfn <<HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT , -PAGE_SIZE ,MEMREMAP_WB ); - }else { -/* -* The VP assist page is an "overlay" page (see Hyper-V TLFS's -* Section 5.2.1 "GPA Overlay Pages"). Here it must be zeroed -* out to make sure we always write the EOI MSR in -* hv_apic_eoi_write() *after* the EOI optimization is disabled -* in hv_cpu_die(), otherwise a CPU may not be stopped in the -* case of CPU offlining and the VM will hang. -*/ -if (!*hvp) { - *hvp =__vmalloc (PAGE_SIZE ,GFP_KERNEL | __GFP_ZERO); - -/* -* Hyper-V should never specify a VM that is a Confidential -* VM and also running in the root partition. Root partition -* is blocked to run in Confidential VM. So only decrypt assist -* page in non-root partition here. -*/ -if (*hvp && !ms_hyperv.paravisor_present &&hv_isolation_type_snp ()) { -WARN_ON_ONCE (set_memory_decrypted ((unsigned long )(*hvp),1 )); -memset (*hvp,0 ,PAGE_SIZE ); - } - } - -if (*hvp) - msr.pfn =vmalloc_to_pfn (*hvp); - - } -if (!WARN_ON (!(*hvp))) { - msr.enable =1 ; -wrmsrq (HV_X64_MSR_VP_ASSIST_PAGE , msr.as_uint64); - } -/* Allow Hyper-V stimer vector to be injected from Hypervisor. */ if (ms_hyperv.misc_features &HV_STIMER_DIRECT_MODE_AVAILABLE )apic_update_vector (cpu,HYPERV_STIMER0_VECTOR , true);@@ -286,23 +236,6 @@ static int hv_cpu_die(unsigned int cpu)hv_common_cpu_die (cpu); -if (hv_vp_assist_page && hv_vp_assist_page[cpu]) { -union hv_vp_assist_msr_contents msr = {0 }; -if (hv_root_partition ()) { -/* -* For root partition the VP assist page is mapped to -* hypervisor provided page, and thus we unmap the -* page here and nullify it, so that in future we have -* correct page address mapped in hv_cpu_init. -*/ -memunmap (hv_vp_assist_page[cpu]); - hv_vp_assist_page[cpu] =NULL ; -rdmsrq (HV_X64_MSR_VP_ASSIST_PAGE , msr.as_uint64); - msr.enable =0 ; - } -wrmsrq (HV_X64_MSR_VP_ASSIST_PAGE , msr.as_uint64); - } -if (hv_reenlightenment_cb ==NULL )return 0 ;@@ -460,21 +393,6 @@ void __init hyperv_init(void)if (hv_common_init ())return ; -/* -* The VP assist page is useless to a TDX guest: the only use we -* would have for it is lazy EOI, which can not be used with TDX. -*/ -if (hv_isolation_type_tdx ()) - hv_vp_assist_page =NULL ; -else - hv_vp_assist_page =kzalloc_objs (*hv_vp_assist_page, nr_cpu_ids); -if (!hv_vp_assist_page) { - ms_hyperv.hints &= ~HV_X64_ENLIGHTENED_VMCS_RECOMMENDED ; - -if (!hv_isolation_type_tdx ()) - goto common_free; - } -if (ms_hyperv.paravisor_present &&hv_isolation_type_snp ()) {/* Negotiate GHCB Version. */ if (!hv_ghcb_negotiate_protocol ())@@ -483,7 +401,7 @@ void __init hyperv_init(void) hv_ghcb_pg = alloc_percpu(union hv_ghcb *);if (!hv_ghcb_pg) - goto free_vp_assist_page; + goto free_ghcb_page; } cpuhp = cpuhp_setup_state(CPUHP_AP_HYPERV_ONLINE, "x86/hyperv_init:online",@@ -613,10 +531,6 @@ void __init hyperv_init(void)cpuhp_remove_state (CPUHP_AP_HYPERV_ONLINE ); free_ghcb_page:free_percpu (hv_ghcb_pg); -free_vp_assist_page: -kfree (hv_vp_assist_page); - hv_vp_assist_page =NULL ; -common_free:hv_common_free (); }drivers/hv/hv_common.c +0
-0
drivers/hv/hv_common.c line 34
Quoted 7 lines
drivers/hv/hv_common.c +2
-0@@ -28,7 +28,9 @@#include <linux/slab.h> #include <linux/dma-map-ops.h> #include <linux/set_memory.h> +#include <linux/vmalloc.h> #include <hyperv/hvhdk.h> +#include <hyperv/hvgdk.h> #include <asm/mshyperv.h>
Need to add
#include <linux/io.h>
because of the memremap() and related calls that have been added. io.h is probably being #include'd indirectly, but it is better to #include it directly.
Quoted 29 lines
drivers/hv/hv_common.c +9
-0u64 hv_current_partition_id =HV_PARTITION_ID_SELF ;@@ -78,6 +80,8 @@ static struct ctl_table_header *hv_ctl_table_hdr;u8 *__percpu *hv_synic_eventring_tail;EXPORT_SYMBOL_GPL (hv_synic_eventring_tail); +struct hv_vp_assist_page **hv_vp_assist_page; +EXPORT_SYMBOL_GPL (hv_vp_assist_page);/* * Hyper-V specific initialization and shutdown code that is * common across all architectures. Called from architecture @@ -92,6 +96,9 @@ void __init hv_common_free(void)if (ms_hyperv.misc_features &HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE )hv_kmsg_dump_unregister (); +kfree (hv_vp_assist_page); + hv_vp_assist_page =NULL ; +kfree (hv_vp_index); hv_vp_index =NULL ;@@ -394,6 +401,23 @@ int __init hv_common_init(void)for (i =0 ; i < nr_cpu_ids; i++) hv_vp_index[i] =VP_INVAL ; +/* +* The VP assist page is useless to a TDX guest: the only use we +* would have for it is lazy EOI, which can not be used with TDX. +*/
drivers/hv/hv_common.c int __init hv_common_init(void) · line 417
Quoted 10 lines
drivers/hv/hv_common.c +10
-0+if (hv_isolation_type_tdx ()) { + hv_vp_assist_page =NULL ; + }else { + hv_vp_assist_page =kzalloc_objs (*hv_vp_assist_page, nr_cpu_ids); +if (!hv_vp_assist_page) { +#ifdef CONFIG_X86_64 + ms_hyperv.hints &= ~HV_X64_ENLIGHTENED_VMCS_RECOMMENDED ; +#endif +hv_common_free (); +return -ENOMEM ;
Given that "failure to allocate memory" now returns an error that is essentially fatal to hyperv_init(), is it still necessary to clear the flag in ms_hyperv.hints? I'd love to see that #ifdef go away. It's the only #ifdef in hv_common.c, and I had worked hard in the past to avoid such #ifdef's. :-)
Quoted 16 lines
drivers/hv/hv_common.c +5
-0+ } + } +return 0 ; }@@ -471,6 +495,8 @@ void __init ms_hyperv_late_init(void)int hv_common_cpu_init (unsigned int cpu) { +union hv_vp_assist_msr_contents msr = {0 }; +struct hv_vp_assist_page **hvp;void **inputarg, **outputarg;u8 **synic_eventring_tail;u64 msr_vp_index;
drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 568
Quoted 1 line
drivers/hv/hv_common.c +0
-0@@ -542,6 +568,50 @@ int hv_common_cpu_init(unsigned int cpu) ret = -ENOMEM ;
The Sashiko AI comment here about a bug when ret is set to -ENOMEM seems valid to me.
Quoted 4 lines
drivers/hv/hv_common.c +2
-0} +if (!hv_vp_assist_page) +return ret;
drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 582
Quoted 10 lines
drivers/hv/hv_common.c +10
-0+ + hvp = &hv_vp_assist_page[cpu]; +if (hv_root_partition ()) { +/* +* For root partition we get the hypervisor provided VP assist +* page, instead of allocating a new page. +*/ + msr.as_uint64 =hv_get_msr (HV_SYN_REG_VP_ASSIST_PAGE ); + *hvp =memremap (msr.pfn <<HV_VP_ASSIST_PAGE_ADDRESS_SHIFT , +PAGE_SIZE ,MEMREMAP_WB );
The Sashiko AI comment about potentially memremap'ing 64K instead of 4K can be ignored. We know that the root partition can only run with a 4K page size, and that is enforced in drivers/hv/Kconfig.
HV_VP_ASSIST_PAGE_ADDRESS_SHIFT is defined in asm-generic/mshyperv.h. But there is also HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT in hvgdk_mini.h. Is there a clean way to eliminate the duplication?
drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 591
Quoted 9 lines
drivers/hv/hv_common.c +9
-0+ }else { +/* +* The VP assist page is an "overlay" page (see Hyper-V TLFS's +* Section 5.2.1 "GPA Overlay Pages"). Here it must be zeroed +* out to make sure we always write the EOI MSR in +* hv_apic_eoi_write() *after* the EOI optimization is disabled +* in hv_cpu_die(), otherwise a CPU may not be stopped in the +* case of CPU offlining and the VM will hang. +*/
Somewhere in the comment above, I'd suggest adding a short "on x86/x64" qualifier, as the comment doesn't apply on arm64 since it doesn't support the AutoEOI optimization. Maybe "Here it must be zeroed out to make sure that on x86/x64 we always write the EOI MSR in ....".
drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 593
Quoted 2 lines
drivers/hv/hv_common.c +2
-0+if (!*hvp) { + *hvp =__vmalloc (PAGE_SIZE ,GFP_KERNEL | __GFP_ZERO);
The Sashiko AI comment about using "flags" instead of GFP_KERNEL seems valid.
Quoted 5 lines
drivers/hv/hv_common.c +5
-0+ +/* +* Hyper-V should never specify a VM that is a Confidential +* VM and also running in the root partition. Root partition +* is blocked to run in Confidential VM. So only decrypt assist
drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 608
Quoted 10 lines
drivers/hv/hv_common.c +10
-0+* page in non-root partition here. +*/ +if (*hvp && !ms_hyperv.paravisor_present &&hv_isolation_type_snp ()) { +WARN_ON_ONCE (set_memory_decrypted ((unsigned long )(*hvp),1 )); +memset (*hvp,0 ,PAGE_SIZE ); + } + } + +if (*hvp) + msr.pfn =vmalloc_to_pfn (*hvp);
The Sashiko AI comment about page size here seems valid. But what are the rules about arm64 page sizes that are supported for VTL2, and how does they relate to VTL0 allowing 4K, 16K, and 64K page size? What combinations are allowed? For example, can a VTL2 built with 4K page size run with a VTL0 built with 64K page size? It would be nice to have the rules recorded somewhere in a code comment, but I'm not sure of the best place.
But regardless of the rules, I'd suggest future-proofing by using "page_to_hvpfn(vmalloc_to_page(*hvp))" so that the PFN generated is always in terms of 4K page size as the Hyper-V host expects.
Quoted 47 lines
drivers/hv/hv_common.c +24
-0+ } +if (!WARN_ON (!(*hvp))) { + msr.enable =1 ; +hv_set_msr (HV_SYN_REG_VP_ASSIST_PAGE , msr.as_uint64); + } +return ret; }@@ -566,6 +636,24 @@ int hv_common_cpu_die(unsigned int cpu) *synic_eventring_tail =NULL ; } +if (hv_vp_assist_page && hv_vp_assist_page[cpu]) { +union hv_vp_assist_msr_contents msr = {0 }; + +if (hv_root_partition ()) { +/* +* For root partition the VP assist page is mapped to +* hypervisor provided page, and thus we unmap the +* page here and nullify it, so that in future we have +* correct page address mapped in hv_cpu_init. +*/ +memunmap (hv_vp_assist_page[cpu]); + hv_vp_assist_page[cpu] =NULL ; + msr.as_uint64 =hv_get_msr (HV_SYN_REG_VP_ASSIST_PAGE ); + msr.enable =0 ; + } +hv_set_msr (HV_SYN_REG_VP_ASSIST_PAGE , msr.as_uint64); + } +return 0 ; }include/asm-generic/mshyperv.h +1
-0@@ -25,6 +25,7 @@#include <linux/nmi.h> #include <asm/ptrace.h> #include <hyperv/hvhdk.h> +#include <hyperv/hvgdk.h> #define VTPM_BASE_ADDRESS 0xfed40000
include/asm-generic/mshyperv.h do { \ · line 303
Quoted 4 lines
include/asm-generic/mshyperv.h +1
-0@@ -299,6 +300,8 @@ do { \#define hv_status_debug (status, fmt, ...) \ hv_status_printk(debug, status, fmt, ##__VA_ARGS__) +extern struct hv_vp_assist_page **hv_vp_assist_page;
This "extern" statement is added here so it is visible to both x86/x64 and arm64. And that's correct.
But there is still some VP assist page stuff that has been left in the arch/x86 version of mshyperv.h. That other stuff, including the inline function hv_get_vp_assist_page(), should also be moved to asm-generic/mshyperv.h. Given that the VP assist page support is now fully generic and not x86/x64 specific, it shouldn't occur anywhere in the arch/x86 version of mshyperv.h.
Quoted 25 lines
include/asm-generic/mshyperv.h +2
-0+const char *hv_result_to_string (u64 hv_status);int hv_result_to_errno (u64 status);void hyperv_report_panic (struct pt_regs *regs,long err,bool in_die);@@ -377,6 +380,7 @@ static inline int hv_deposit_memory(u64 partition_id, u64 status)return hv_deposit_memory_node (NUMA_NO_NODE , partition_id, status); } +#define HV_VP_ASSIST_PAGE_ADDRESS_SHIFT 12#if IS_ENABLED (CONFIG_HYPERV_VTL_MODE )u8 __init get_vtl (void );#else include/hyperv/hvgdk_mini.h +1
-0@@ -149,6 +149,7 @@ struct hv_u128 {#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT 12#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_MASK \ (~((1ull << HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT) - 1)) +#define HV_SYN_REG_VP_ASSIST_PAGE (HV_X64_MSR_VP_ASSIST_PAGE)/* Hyper-V Enlightened VMCS version mask in nested features CPUID */ #define HV_X64_ENLIGHTENED_VMCS_VERSION 0xff
include/hyperv/hvgdk_mini.h enum hv_register_name { · line 1189
Quoted 4 lines
include/hyperv/hvgdk_mini.h +1
-0@@ -1185,6 +1186,7 @@ enum hv_register_name {#define HV_MSR_STIMER0_CONFIG (HV_REGISTER_STIMER0_CONFIG)#define HV_MSR_STIMER0_COUNT (HV_REGISTER_STIMER0_COUNT) +#define HV_SYN_REG_VP_ASSIST_PAGE (HV_REGISTER_VP_ASSIST_PAGE)
This defines a new register name prefix "HV_SYN_REG_" that isn't used anywhere else. The prefixes for Hyper-V register names are already complex to account to x86/x64 and arm64 differences, and the fact the x86/x64 has synthetic MSRs, while arm64 does not. So introducing another prefix is undesirable. Couldn't this just be HV_MSR_VP_ASSIST_PAGE using the same structure as HV_MSR_STIMER0_COUNT (for example)?
Quoted 6 lines
include/hyperv/hvgdk_mini.h +0
-1#endif /* CONFIG_ARM64 */ --2.43.0
RE: [PATCH 03/11] Drivers: hv: Add support to setup percpu vmbus handler
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 6 lines
Add a wrapper function -
hv_setup_percpu_vmbus_handler(), similar tohv_setup_vmbus_handler()to allow setting up custom per-cpu VMBus interrupt handler. This is required for arm64 support, to be added inMSHV_VTLdriver, where per-cpu VMBus interrupt handler will be set tomshv_vtl_vmbus_isr()for VTL2 (Virtual Trust Level 2).
Needing both hv_setup_vmbus_handler() and hv_setup_percpu_vmbus_handler() seems unfortunate. Here's an alternate approach to consider:
1. I think the x86 VMBus sysvec handler and the vmbus_percpu_isr() functions could both use the same vmbus_handler global variable. Looking at your changes in this patch set, hv_setup_vmbus_handler() and hv_setup_percpu_vmbus_handler() are used together and always set the same value.
2. So move the global variable vmbus_handler out from arch/x86 and into hv_common.c, and export it. The x86 sysvec handler can still reference it, and vmbus_percpu_isr() in vmbus_drv.c can also reference it. No need to have vmbus_percpu_isr() under arch/arm64 or have a stub in hv_common.c.
3. hv_setup_vmbus_handler() and hv_remove_vmbus_handler() also move to hv_common.c. The __weak stubs go away.
With these changes, only hv_setup_vmbus_handler() needs to be called, and it works for both x86 with the sysvec handler and for arm64 with vmbus_percpu_isr().
I haven't coded this up, so maybe there's some problematic detail, but the idea seems like it would work. If it does work, some of my comments below are no longer applicable.
Quoted 39 lines
Signed-off-by Saurabh Sengar <[email protected]>Signed-off-by Naman Jain <[email protected]>--- arch/arm64/hyperv/mshyperv.c | 13 +++++++++++++ drivers/hv/hv_common.c | 11 +++++++++++ drivers/hv/vmbus_drv.c | 7 +------ include/asm-generic/mshyperv.h | 3 +++ 4 files changed, 28 insertions(+), 6 deletions(-)arch/arm64/hyperv/mshyperv.c +13
-0@@ -134,3 +134,16 @@ bool hv_is_hyperv_initialized(void)return hyperv_initialized; }EXPORT_SYMBOL_GPL (hv_is_hyperv_initialized); + +static void (*vmbus_percpu_handler)(void ); +void hv_setup_percpu_vmbus_handler (void (*handler)(void )) +{ + vmbus_percpu_handler = handler; +} + +irqreturn_t vmbus_percpu_isr (int irq,void *dev_id) +{ +if (vmbus_percpu_handler) +vmbus_percpu_handler (); +return IRQ_HANDLED ; +}drivers/hv/hv_common.c +0
-0@@ -759,6 +759,17 @@ void __weak hv_setup_vmbus_handler(void (*handler)(void)) }EXPORT_SYMBOL_GPL (hv_setup_vmbus_handler);
drivers/hv/hv_common.c void __weak hv_setup_vmbus_handler(void (*handler)(void)) · line 771
Quoted 10 lines
drivers/hv/hv_common.c +10
-0+irqreturn_t __weak vmbus_percpu_isr (int irq,void *dev_id) +{ +return IRQ_HANDLED ; +} +EXPORT_SYMBOL_GPL (vmbus_percpu_isr); + +void __weak hv_setup_percpu_vmbus_handler (void (*handler)(void )) +{ +} +EXPORT_SYMBOL_GPL (hv_setup_percpu_vmbus_handler);
You've implemented hv_setup_percpu_vmbus_handler() following the pattern of hv_setup_vmbus_handler(), which is reasonable. But that turns out to be unnecessarily complicated. The existing hv_setup_vmbus_handler() has a portion in arch/x86/kernel/cpu/mshyperv.c as a special case because it uses a hard-coded interrupt vector on x86/x64, and has its own custom sysvec code. And there's a need for a __weak stub in hv_common.c so that vmbus_drv.c will compile on arm64.
But hv_setup_percpu_vmbus_handler() does not have the same requirements. It could be implemented entirely in vmbus_drv.c, with no code under arch/x86 or arch/arm64, and no __weak stub in hv_common.c. vmbus_drv.c would just need to EXPORT_SYMBOL_FOR_MODULES, like it already does with vmbus_isr. I didn't code it up, but I think that approach would be simpler with fewer piece-parts scattered all over. If so, it would be worth breaking the symmetry with hv_setup_vmbus_handler().
Quoted 53 lines
drivers/hv/hv_common.c +1
-0+void __weak hv_remove_vmbus_handler (void ) { }drivers/hv/vmbus_drv.c +1
-6@@ -1413,12 +1413,6 @@ void vmbus_isr(void) }EXPORT_SYMBOL_FOR_MODULES (vmbus_isr,"mshv_vtl" ); -static irqreturn_t vmbus_percpu_isr (int irq,void *dev_id) -{ -vmbus_isr (); -return IRQ_HANDLED ; -} -static void vmbus_percpu_work (struct work_struct *work) {unsigned int cpu =smp_processor_id ();@@ -1520,6 +1514,7 @@ static int vmbus_bus_init(void)if (vmbus_irq ==-1 ) {hv_setup_vmbus_handler (vmbus_isr); }else { +hv_setup_percpu_vmbus_handler (vmbus_isr); ret =request_percpu_irq (vmbus_irq, vmbus_percpu_isr,"Hyper-V VMbus" , &vmbus_evt);if (ret) {include/asm-generic/mshyperv.h +3
-1@@ -22,6 +22,7 @@#include <linux/bitops.h> #include <acpi/acpi_numa.h> #include <linux/cpumask.h> +#include <linux/interrupt.h> #include <linux/nmi.h> #include <asm/ptrace.h> #include <hyperv/hvhdk.h> @@ -179,6 +180,8 @@ static inline u64 hv_generate_guest_id(u64 kernel_version)int hv_get_hypervisor_version (union hv_hypervisor_version_info *info); +irqreturn_t vmbus_percpu_isr (int irq,void *dev_id); +void hv_setup_percpu_vmbus_handler (void (*handler)(void ));void hv_setup_vmbus_handler (void (*handler)(void ));void hv_remove_vmbus_handler (void );void hv_setup_stimer0_handler (void (*handler)(void )); --2.43.0
RE: [PATCH 04/11] Drivers: hv: Refactor mshv_vtl for ARM64 support to be added
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 153 lines
Refactor
MSHV_VTLdriver to move some of the x86 specific code to arch specific files, and add corresponding functions for arm64.Signed-off-by Roman Kisel <[email protected]>Signed-off-by Naman Jain <[email protected]>--- arch/arm64/include/asm/mshyperv.h | 10 +++ arch/x86/hyperv/hv_vtl.c | 98 ++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 1 + drivers/hv/mshv_vtl_main.c | 102 +----------------------------- 4 files changed, 111 insertions(+), 100 deletions(-)arch/arm64/include/asm/mshyperv.h +10
-0@@ -60,6 +60,16 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg) ARM_SMCCC_SMC_64, \ ARM_SMCCC_OWNER_VENDOR_HYP, \ HV_SMCCC_FUNC_NUMBER) +#ifdef CONFIG_HYPERV_VTL_MODE +/* +* Get/Set the register. If the function returns `1`, that must be done via +* a hypercall. Returning `0` means success. +*/ +static inline int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared) +{ +return 1 ; +} +#endif #include <asm-generic/mshyperv.h> arch/x86/hyperv/hv_vtl.c +98
-0@@ -17,6 +17,8 @@#include <asm/realmode.h> #include <asm/reboot.h> #include <asm/smap.h> +#include <uapi/asm/mtrr.h> +#include <asm/debugreg.h> #include <linux/export.h> #include <../kernel/smpboot.h> #include "../../kernel/fpu/legacy.h" @@ -281,3 +283,99 @@ void mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0)kernel_fpu_end (); }EXPORT_SYMBOL (mshv_vtl_return_call); + +/* Static table mapping register names to their corresponding actions */ +static const struct { +enum hv_register_name reg_name; +int debug_reg_num;/* -1 if not a debug register */ +u32 msr_addr;/* 0 if not an MSR */ +} reg_table[] = { +/* Debug registers */ + {HV_X64_REGISTER_DR0 ,0 ,0 }, + {HV_X64_REGISTER_DR1 ,1 ,0 }, + {HV_X64_REGISTER_DR2 ,2 ,0 }, + {HV_X64_REGISTER_DR3 ,3 ,0 }, + {HV_X64_REGISTER_DR6 ,6 ,0 }, +/* MTRR MSRs */ + {HV_X64_REGISTER_MSR_MTRR_CAP ,-1 , MSR_MTRRcap}, + {HV_X64_REGISTER_MSR_MTRR_DEF_TYPE ,-1 , MSR_MTRRdefType}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE0 ,-1 ,MTRRphysBase_MSR (0 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE1 ,-1 ,MTRRphysBase_MSR (1 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE2 ,-1 ,MTRRphysBase_MSR (2 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE3 ,-1 ,MTRRphysBase_MSR (3 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE4 ,-1 ,MTRRphysBase_MSR (4 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE5 ,-1 ,MTRRphysBase_MSR (5 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE6 ,-1 ,MTRRphysBase_MSR (6 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE7 ,-1 ,MTRRphysBase_MSR (7 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE8 ,-1 ,MTRRphysBase_MSR (8 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE9 ,-1 ,MTRRphysBase_MSR (9 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEA ,-1 ,MTRRphysBase_MSR (0xa )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEB ,-1 ,MTRRphysBase_MSR (0xb )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEC ,-1 ,MTRRphysBase_MSR (0xc )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASED ,-1 ,MTRRphysBase_MSR (0xd )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEE ,-1 ,MTRRphysBase_MSR (0xe )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEF ,-1 ,MTRRphysBase_MSR (0xf )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK0 ,-1 ,MTRRphysMask_MSR (0 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK1 ,-1 ,MTRRphysMask_MSR (1 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK2 ,-1 ,MTRRphysMask_MSR (2 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK3 ,-1 ,MTRRphysMask_MSR (3 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK4 ,-1 ,MTRRphysMask_MSR (4 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK5 ,-1 ,MTRRphysMask_MSR (5 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK6 ,-1 ,MTRRphysMask_MSR (6 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK7 ,-1 ,MTRRphysMask_MSR (7 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK8 ,-1 ,MTRRphysMask_MSR (8 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK9 ,-1 ,MTRRphysMask_MSR (9 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKA ,-1 ,MTRRphysMask_MSR (0xa )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKB ,-1 ,MTRRphysMask_MSR (0xb )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKC ,-1 ,MTRRphysMask_MSR (0xc )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKD ,-1 ,MTRRphysMask_MSR (0xd )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKE ,-1 ,MTRRphysMask_MSR (0xe )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKF ,-1 ,MTRRphysMask_MSR (0xf )}, + {HV_X64_REGISTER_MSR_MTRR_FIX64K00000 ,-1 , MSR_MTRRfix64K_00000}, + {HV_X64_REGISTER_MSR_MTRR_FIX16K80000 ,-1 , MSR_MTRRfix16K_80000}, + {HV_X64_REGISTER_MSR_MTRR_FIX16KA0000 ,-1 , MSR_MTRRfix16K_A0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KC0000 ,-1 , MSR_MTRRfix4K_C0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KC8000 ,-1 , MSR_MTRRfix4K_C8000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KD0000 ,-1 , MSR_MTRRfix4K_D0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KD8000 ,-1 , MSR_MTRRfix4K_D8000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KE0000 ,-1 , MSR_MTRRfix4K_E0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KE8000 ,-1 , MSR_MTRRfix4K_E8000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KF0000 ,-1 , MSR_MTRRfix4K_F0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KF8000 ,-1 , MSR_MTRRfix4K_F8000}, +}; + +int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared) +{ +u64 *reg64; +enum hv_register_name gpr_name; +int i; + + gpr_name = regs->name; + reg64 = ®s->value.reg64; + +/* Search for the register in the table */ +for (i =0 ; i <ARRAY_SIZE (reg_table); i++) { +if (reg_table[i].reg_name != gpr_name) +continue ; +if (reg_table[i].debug_reg_num !=-1 ) { +/* Handle debug registers */ +if (gpr_name ==HV_X64_REGISTER_DR6 && !shared) + goto hypercall; +if (set) +native_set_debugreg (reg_table[i].debug_reg_num, *reg64); +else + *reg64 =native_get_debugreg (reg_table[i].debug_reg_num); + }else { +/* Handle MSRs */ +if (set) +wrmsrl (reg_table[i].msr_addr, *reg64); +else +rdmsrl (reg_table[i].msr_addr, *reg64); + } +return 0 ; + } + +hypercall: +return 1 ; +} +EXPORT_SYMBOL (hv_vtl_get_set_reg);arch/x86/include/asm/mshyperv.h +0
-0
arch/x86/include/asm/mshyperv.h void mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0); · line 307
Quoted 4 lines
arch/x86/include/asm/mshyperv.h +1
-0@@ -304,6 +304,7 @@ void mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0);void mshv_vtl_return_call_init (u64 vtl_return_offset);void mshv_vtl_return_hypercall (void );void __mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0); +int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared);
Can this move to asm-generic/mshyperv.h? The function is no longer specific to x86/x64, so one would want to not declare it in the arch/x86 version of mshyperv.h. But maybe moving it to asm-generic/mshyperv.h breaks compilation on arm64 because there's also the static inline stub there.
Quoted 142 lines
arch/x86/include/asm/mshyperv.h +0
-0#else static inline void __init hv_vtl_init_platform (void ) {}static inline int __init hv_vtl_early_init (void ) {return 0 ; }drivers/hv/mshv_vtl_main.c +2
-101@@ -19,10 +19,8 @@#include <linux/poll.h> #include <linux/file.h> #include <linux/vmalloc.h> -#include <asm/debugreg.h> #include <asm/mshyperv.h> #include <trace/events/ipi.h> -#include <uapi/asm/mtrr.h> #include <uapi/linux/mshv.h> #include <hyperv/hvhdk.h> @@ -505,102 +503,6 @@ static int mshv_vtl_ioctl_set_poll_file(struct mshv_vtl_set_poll_file __user *usreturn 0 ; } -/* Static table mapping register names to their corresponding actions */ -static const struct { -enum hv_register_name reg_name; -int debug_reg_num;/* -1 if not a debug register */ -u32 msr_addr;/* 0 if not an MSR */ -} reg_table[] = { -/* Debug registers */ - {HV_X64_REGISTER_DR0 ,0 ,0 }, - {HV_X64_REGISTER_DR1 ,1 ,0 }, - {HV_X64_REGISTER_DR2 ,2 ,0 }, - {HV_X64_REGISTER_DR3 ,3 ,0 }, - {HV_X64_REGISTER_DR6 ,6 ,0 }, -/* MTRR MSRs */ - {HV_X64_REGISTER_MSR_MTRR_CAP ,-1 , MSR_MTRRcap}, - {HV_X64_REGISTER_MSR_MTRR_DEF_TYPE ,-1 , MSR_MTRRdefType}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE0 ,-1 ,MTRRphysBase_MSR (0 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE1 ,-1 ,MTRRphysBase_MSR (1 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE2 ,-1 ,MTRRphysBase_MSR (2 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE3 ,-1 ,MTRRphysBase_MSR (3 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE4 ,-1 ,MTRRphysBase_MSR (4 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE5 ,-1 ,MTRRphysBase_MSR (5 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE6 ,-1 ,MTRRphysBase_MSR (6 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE7 ,-1 ,MTRRphysBase_MSR (7 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE8 ,-1 ,MTRRphysBase_MSR (8 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE9 ,-1 ,MTRRphysBase_MSR (9 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEA ,-1 ,MTRRphysBase_MSR (0xa )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEB ,-1 ,MTRRphysBase_MSR (0xb )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEC ,-1 ,MTRRphysBase_MSR (0xc )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASED ,-1 ,MTRRphysBase_MSR (0xd )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEE ,-1 ,MTRRphysBase_MSR (0xe )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEF ,-1 ,MTRRphysBase_MSR (0xf )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK0 ,-1 ,MTRRphysMask_MSR (0 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK1 ,-1 ,MTRRphysMask_MSR (1 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK2 ,-1 ,MTRRphysMask_MSR (2 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK3 ,-1 ,MTRRphysMask_MSR (3 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK4 ,-1 ,MTRRphysMask_MSR (4 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK5 ,-1 ,MTRRphysMask_MSR (5 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK6 ,-1 ,MTRRphysMask_MSR (6 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK7 ,-1 ,MTRRphysMask_MSR (7 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK8 ,-1 ,MTRRphysMask_MSR (8 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK9 ,-1 ,MTRRphysMask_MSR (9 )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKA ,-1 ,MTRRphysMask_MSR (0xa )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKB ,-1 ,MTRRphysMask_MSR (0xb )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKC ,-1 ,MTRRphysMask_MSR (0xc )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKD ,-1 ,MTRRphysMask_MSR (0xd )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKE ,-1 ,MTRRphysMask_MSR (0xe )}, - {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKF ,-1 ,MTRRphysMask_MSR (0xf )}, - {HV_X64_REGISTER_MSR_MTRR_FIX64K00000 ,-1 , MSR_MTRRfix64K_00000}, - {HV_X64_REGISTER_MSR_MTRR_FIX16K80000 ,-1 , MSR_MTRRfix16K_80000}, - {HV_X64_REGISTER_MSR_MTRR_FIX16KA0000 ,-1 , MSR_MTRRfix16K_A0000}, - {HV_X64_REGISTER_MSR_MTRR_FIX4KC0000 ,-1 , MSR_MTRRfix4K_C0000}, - {HV_X64_REGISTER_MSR_MTRR_FIX4KC8000 ,-1 , MSR_MTRRfix4K_C8000}, - {HV_X64_REGISTER_MSR_MTRR_FIX4KD0000 ,-1 , MSR_MTRRfix4K_D0000}, - {HV_X64_REGISTER_MSR_MTRR_FIX4KD8000 ,-1 , MSR_MTRRfix4K_D8000}, - {HV_X64_REGISTER_MSR_MTRR_FIX4KE0000 ,-1 , MSR_MTRRfix4K_E0000}, - {HV_X64_REGISTER_MSR_MTRR_FIX4KE8000 ,-1 , MSR_MTRRfix4K_E8000}, - {HV_X64_REGISTER_MSR_MTRR_FIX4KF0000 ,-1 , MSR_MTRRfix4K_F0000}, - {HV_X64_REGISTER_MSR_MTRR_FIX4KF8000 ,-1 , MSR_MTRRfix4K_F8000}, -}; - -static int mshv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set) -{ -u64 *reg64; -enum hv_register_name gpr_name; -int i; - - gpr_name = regs->name; - reg64 = ®s->value.reg64; - -/* Search for the register in the table */ -for (i =0 ; i <ARRAY_SIZE (reg_table); i++) { -if (reg_table[i].reg_name != gpr_name) -continue ; -if (reg_table[i].debug_reg_num !=-1 ) { -/* Handle debug registers */ -if (gpr_name ==HV_X64_REGISTER_DR6 && - !mshv_vsm_capabilities.dr6_shared) - goto hypercall; -if (set) -native_set_debugreg (reg_table[i].debug_reg_num, *reg64); -else - *reg64 =native_get_debugreg (reg_table[i].debug_reg_num); - }else { -/* Handle MSRs */ -if (set) -wrmsrl (reg_table[i].msr_addr, *reg64); -else -rdmsrl (reg_table[i].msr_addr, *reg64); - } -return 0 ; - } - -hypercall: -return 1 ; -} -static void mshv_vtl_return (struct mshv_vtl_cpu_context *vtl0) {struct hv_vp_assist_page *hvp;@@ -720,7 +622,7 @@ mshv_vtl_ioctl_get_regs(void __user *user_args) sizeof(reg)))return -EFAULT ; - ret =mshv_vtl_get_set_reg (®, false); + ret =hv_vtl_get_set_reg (®, false, mshv_vsm_capabilities.dr6_shared);if (!ret) goto copy_args;/* No need of hypercall */ ret =vtl_get_vp_register (®);@@ -751,7 +653,7 @@ mshv_vtl_ioctl_set_regs(void __user *user_args)if (copy_from_user (®, (void __user *)args.regs_ptr,sizeof (reg)))return -EFAULT ; - ret =mshv_vtl_get_set_reg (®, true); + ret =hv_vtl_get_set_reg (®, true, mshv_vsm_capabilities.dr6_shared);if (!ret)return ret;/* No need of hypercall */ ret =vtl_set_vp_register (®); --2.43.0
RE: [PATCH 05/11] drivers: hv: Export vmbus_interrupt for mshv_vtl module
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 1 line
Nit: For the patch Subject, capitalize "Drivers:" in the prefix.
Quoted 25 lines
vmbus_interruptis used inmshv_vtl_main.cto set the SINT vector. WhenCONFIG_MSHV_VTL=mandCONFIG_HYPERV_VMBUS=y(built-in), the module cannot accessvmbus_interruptat load time since it is not exported.Export it using
EXPORT_SYMBOL_FOR_MODULESconsistent with the existing pattern used forvmbus_isr.Signed-off-by Naman Jain <[email protected]>--- drivers/hv/vmbus_drv.c | 1 + 1 file changed, 1 insertion(+)drivers/hv/vmbus_drv.c +1
-1@@ -57,6 +57,7 @@ static DEFINE_PER_CPU(long, vmbus_evt);/* Values parsed from ACPI DSDT */ int vmbus_irq;int vmbus_interrupt; +EXPORT_SYMBOL_FOR_MODULES (vmbus_interrupt,"mshv_vtl" );/* * If the Confidential VMBus is used, the data on the "wire" is not --
Quoted 2 lines
2.43.0
RE: [PATCH 06/11] Drivers: hv: Make sint vector architecture neutral in MSHV_VTL
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 4 lines
Generalize Synthetic interrupt source vector (sint) to use
vmbus_interruptvariable instead, which automatically takes care of architectures whereHYPERVISOR_CALLBACK_VECTORis not present (arm64).
Sashiko AI raised an interesting question about the startup timing -- whether the vmbus_platform_driver_probe() is guaranteed to have set vmbus_interrupt before the VTL functions below run and use it. What causes the mshv_vtl.ko module to be loaded, and hence run mshv_vtl_init()?
Quoted 30 lines
Signed-off-by Roman Kisel <[email protected]>Signed-off-by Naman Jain <[email protected]>--- drivers/hv/mshv_vtl_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/hv/mshv_vtl_main.c +2
-3@@ -234,7 +234,7 @@ static void mshv_vtl_synic_enable_regs(unsigned int cpu)union hv_synic_sint sint; sint.as_uint64 =0 ; - sint.vector =HYPERVISOR_CALLBACK_VECTOR ; + sint.vector = vmbus_interrupt; sint.masked = false; sint.auto_eoi =hv_recommend_using_aeoi ();@@ -753,7 +753,7 @@ static void mshv_vtl_synic_mask_vmbus_sint(void *info)const u8 *mask = info; sint.as_uint64 =0 ; - sint.vector =HYPERVISOR_CALLBACK_VECTOR ; + sint.vector = vmbus_interrupt; sint.masked = (*mask !=0 ); sint.auto_eoi =hv_recommend_using_aeoi (); --
Quoted 2 lines
2.43.0
Assuming there's no timing problem vs. the VMBus driver,
RE: [PATCH 07/11] arch: arm64: Add support for mshv_vtl_return_call
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 1 line
Nit: For historical consistency, use "arm64: hyperv:" as the prefix in the patch Subject.
Quoted 4 lines
Add support for arm64 specific variant of
mshv_vtl_return_callfunction to be able to add support for arm64 inMSHV_VTLdriver. This would help enable the transition between Virtual Trust Levels (VTL) inMSHV_VTLwhen the kernel acts as a paravisor.
This commit message has a fair number of "filler" words. Suggest simplifying to:
Add the arm64 variant of mshv_vtl_return_call() to support the MSHV_VTL driver on arm64. This function enables the transition between Virtual Trust Levels (VTLs) in MSHV_VTL when the kernel acts as a paravisor.
Quoted 45 lines
Signed-off-by Roman Kisel <[email protected]>Signed-off-by Naman Jain <[email protected]>--- arch/arm64/hyperv/Makefile | 1 + arch/arm64/hyperv/hv_vtl.c | 144 ++++++++++++++++++++++++++++++ arch/arm64/include/asm/mshyperv.h | 13 +++ 3 files changed, 158 insertions(+) create mode 100644 arch/arm64/hyperv/hv_vtl.carch/arm64/hyperv/Makefile +1
-0@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 obj-y := hv_core.o mshyperv.o +obj-$(CONFIG_HYPERV_VTL_MODE) += hv_vtl.oarch/arm64/hyperv/hv_vtl.c new file +21
-0@@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2026, Microsoft, Inc. +* +* Authors: +* Roman Kisel <[email protected]> +* Naman Jain <[email protected]> +*/ + +#include <asm/boot.h> +#include <asm/mshyperv.h> +#include <asm/cpu_ops.h> + +void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) +{ +u64 base_ptr = (u64 )vtl0->x; + +/* +* VTL switch for ARM64 platform - managing VTL0's CPU context. +* We explicitly use the stack to save the base pointer, and use x16 +* as our working register for accessing the context structure.
arch/arm64/hyperv/hv_vtl.c line 31
Quoted 10 lines
arch/arm64/hyperv/hv_vtl.c new file +10
-0+* +* Register Handling: +* - X0-X17: Saved/restored (general-purpose, shared for VTL communication) +* - X18: NOT touched - hypervisor-managed per-VTL (platform register) +* - X19-X30: Saved/restored (part of VTL0's execution context) +* - Q0-Q31: Saved/restored (128-bit NEON/floating-point registers, shared) +* - SP: Not in structure, hypervisor-managed per-VTL +* +* Note: X29 (FP) and X30 (LR) are in the structure and must be saved/restored +* as part of VTL0's complete execution state.
Could drop "Note:". That's what comments are. :-)
arch/arm64/hyperv/hv_vtl.c line 39
Quoted 8 lines
arch/arm64/hyperv/hv_vtl.c new file +8
-0+*/ + asm __volatile__ ( +/* Save base pointer to stack explicitly, then load into x16 */ +"str %0, [sp, #-16]!\n\t" /* Push base pointer onto stack */ +"mov x16, %0\n\t" /* Load base pointer into x16 */ +/* Volatile registers (Windows ARM64 ABI: x0-x15) */ +"ldp x0, x1, [x16]\n\t" + "ldp x2, x3, [x16, #(2*8)]\n\t"
On the x86 side, there's machinery to generate a series of constants that are the offsets of the individual fields in struct mshv_vtl_cpu_context. The x86 asm code then uses these constants. Here on the arm64 side, you've calculated the offsets directly in the asm code. Any reason for the difference? I can see it's fairly easy to eyeball the offsets here and compare against the registers that are being loaded, where it's not so easy the way registers are named on x86. So maybe the additional machinery that's helpful on the x86 side is less necessary here. Just wondering ....
Quoted 111 lines
arch/arm64/hyperv/hv_vtl.c new file +105
-0+"ldp x4, x5, [x16, #(4*8)]\n\t" +"ldp x6, x7, [x16, #(6*8)]\n\t" +"ldp x8, x9, [x16, #(8*8)]\n\t" +"ldp x10, x11, [x16, #(10*8)]\n\t" +"ldp x12, x13, [x16, #(12*8)]\n\t" +"ldp x14, x15, [x16, #(14*8)]\n\t" +/* x16 will be loaded last, after saving base pointer */ +"ldr x17, [x16, #(17*8)]\n\t" +/* x18 is hypervisor-managed per-VTL - DO NOT LOAD */ + +/* General-purpose registers: x19-x30 */ +"ldp x19, x20, [x16, #(19*8)]\n\t" +"ldp x21, x22, [x16, #(21*8)]\n\t" +"ldp x23, x24, [x16, #(23*8)]\n\t" +"ldp x25, x26, [x16, #(25*8)]\n\t" +"ldp x27, x28, [x16, #(27*8)]\n\t" + +/* Frame pointer and link register */ +"ldp x29, x30, [x16, #(29*8)]\n\t" + +/* Shared NEON/FP registers: Q0-Q31 (128-bit) */ +"ldp q0, q1, [x16, #(32*8)]\n\t" +"ldp q2, q3, [x16, #(32*8 + 2*16)]\n\t" +"ldp q4, q5, [x16, #(32*8 + 4*16)]\n\t" +"ldp q6, q7, [x16, #(32*8 + 6*16)]\n\t" +"ldp q8, q9, [x16, #(32*8 + 8*16)]\n\t" +"ldp q10, q11, [x16, #(32*8 + 10*16)]\n\t" +"ldp q12, q13, [x16, #(32*8 + 12*16)]\n\t" +"ldp q14, q15, [x16, #(32*8 + 14*16)]\n\t" +"ldp q16, q17, [x16, #(32*8 + 16*16)]\n\t" +"ldp q18, q19, [x16, #(32*8 + 18*16)]\n\t" +"ldp q20, q21, [x16, #(32*8 + 20*16)]\n\t" +"ldp q22, q23, [x16, #(32*8 + 22*16)]\n\t" +"ldp q24, q25, [x16, #(32*8 + 24*16)]\n\t" +"ldp q26, q27, [x16, #(32*8 + 26*16)]\n\t" +"ldp q28, q29, [x16, #(32*8 + 28*16)]\n\t" +"ldp q30, q31, [x16, #(32*8 + 30*16)]\n\t" + +/* Now load x16 itself */ +"ldr x16, [x16, #(16*8)]\n\t" + +/* Return to the lower VTL */ +"hvc #3\n\t" + +/* Save context after return - reload base pointer from stack */ +"stp x16, x17, [sp, #-16]!\n\t" /* Save x16, x17 temporarily */ +"ldr x16, [sp, #16]\n\t" /* Reload base pointer (skip saved x16,x17) */ + +/* Volatile registers */ +"stp x0, x1, [x16]\n\t" +"stp x2, x3, [x16, #(2*8)]\n\t" +"stp x4, x5, [x16, #(4*8)]\n\t" +"stp x6, x7, [x16, #(6*8)]\n\t" +"stp x8, x9, [x16, #(8*8)]\n\t" +"stp x10, x11, [x16, #(10*8)]\n\t" +"stp x12, x13, [x16, #(12*8)]\n\t" +"stp x14, x15, [x16, #(14*8)]\n\t" +"ldp x0, x1, [sp], #16\n\t" /* Recover saved x16, x17 */ +"stp x0, x1, [x16, #(16*8)]\n\t" +/* x18 is hypervisor-managed - DO NOT SAVE */ + +/* General-purpose registers: x19-x30 */ +"stp x19, x20, [x16, #(19*8)]\n\t" +"stp x21, x22, [x16, #(21*8)]\n\t" +"stp x23, x24, [x16, #(23*8)]\n\t" +"stp x25, x26, [x16, #(25*8)]\n\t" +"stp x27, x28, [x16, #(27*8)]\n\t" +"stp x29, x30, [x16, #(29*8)]\n\t" /* Frame pointer and link register */ + +/* Shared NEON/FP registers: Q0-Q31 (128-bit) */ +"stp q0, q1, [x16, #(32*8)]\n\t" +"stp q2, q3, [x16, #(32*8 + 2*16)]\n\t" +"stp q4, q5, [x16, #(32*8 + 4*16)]\n\t" +"stp q6, q7, [x16, #(32*8 + 6*16)]\n\t" +"stp q8, q9, [x16, #(32*8 + 8*16)]\n\t" +"stp q10, q11, [x16, #(32*8 + 10*16)]\n\t" +"stp q12, q13, [x16, #(32*8 + 12*16)]\n\t" +"stp q14, q15, [x16, #(32*8 + 14*16)]\n\t" +"stp q16, q17, [x16, #(32*8 + 16*16)]\n\t" +"stp q18, q19, [x16, #(32*8 + 18*16)]\n\t" +"stp q20, q21, [x16, #(32*8 + 20*16)]\n\t" +"stp q22, q23, [x16, #(32*8 + 22*16)]\n\t" +"stp q24, q25, [x16, #(32*8 + 24*16)]\n\t" +"stp q26, q27, [x16, #(32*8 + 26*16)]\n\t" +"stp q28, q29, [x16, #(32*8 + 28*16)]\n\t" +"stp q30, q31, [x16, #(32*8 + 30*16)]\n\t" + +/* Clean up stack - pop base pointer */ +"add sp, sp, #16\n\t" + + : /* No outputs */ + : /* Input */ "r"(base_ptr) + : /* Clobber list - x16 used as base, x18 is hypervisor-managed (not touched) */ + "memory", "cc", +"x0" ,"x1" ,"x2" ,"x3" ,"x4" ,"x5" , +"x6" ,"x7" ,"x8" ,"x9" ,"x10" ,"x11" ,"x12" ,"x13" , +"x14" ,"x15" ,"x16" ,"x17" ,"x19" ,"x20" ,"x21" , +"x22" ,"x23" ,"x24" ,"x25" ,"x26" ,"x27" ,"x28" , +"x29" ,"x30" , +"v0" ,"v1" ,"v2" ,"v3" ,"v4" ,"v5" ,"v6" ,"v7" , +"v8" ,"v9" ,"v10" ,"v11" ,"v12" ,"v13" ,"v14" ,"v15" , +"v16" ,"v17" ,"v18" ,"v19" ,"v20" ,"v21" ,"v22" ,"v23" , + "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"); +} +EXPORT_SYMBOL (mshv_vtl_return_call);arch/arm64/include/asm/mshyperv.h +0
-0
arch/arm64/include/asm/mshyperv.h static inline u64 hv_get_non_nested_msr(unsigned int reg) · line 67
Quoted 8 lines
arch/arm64/include/asm/mshyperv.h +5
-0@@ -60,6 +60,17 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg) ARM_SMCCC_SMC_64, \ ARM_SMCCC_OWNER_VENDOR_HYP, \ HV_SMCCC_FUNC_NUMBER) + +struct mshv_vtl_cpu_context { +/* +* NOTE: x18 is managed by the hypervisor. It won't be reloaded from this array. +* It is included here for convenience in the common case.
I'm not getting your point in this last sentence. What is the "common case"?
You could also drop the "NOTE: " prefix.
arch/arm64/include/asm/mshyperv.h static inline u64 hv_get_non_nested_msr(unsigned int reg) · line 72
Quoted 5 lines
arch/arm64/include/asm/mshyperv.h +5
-0+*/ +__u64 x[31 ]; +__u64 rsvd; +__uint128_t q[32 ]; +};
struct mshv_vtl_run reserves 1024 bytes for cpu_context. It would be nice to have a compile-time check that the size of struct mshv_vtl_cpu_context fits in that 1024 bytes. That check might be better added where struct mshv_vtl_run is defined so that it works for both x86 and arm64.
arch/arm64/include/asm/mshyperv.h static inline int hv_vtl_get_set_reg(struct hv_register_assoc *regs, bool set, u · line 84
Quoted 10 lines
arch/arm64/include/asm/mshyperv.h +3
-0+#ifdef CONFIG_HYPERV_VTL_MODE /* * Get/Set the register. If the function returns `1`, that must be done via @@ -69,6 +80,8 @@ static inline int hv_vtl_get_set_reg(struct hv_register_assoc *regs, bool set, u {return 1 ; } + +void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0);
This declaration now duplicated in mshyperv.h under arch/arm64 and under arch/x86. Instead, it should be added to asm-generic/mshyperv.h, and removed from the arch/x86 mshyperv.h, so that there's only a single instance of the declaration.
Quoted 6 lines
arch/arm64/include/asm/mshyperv.h +0
-1#endif #include <asm-generic/mshyperv.h> --2.43.0
RE: [PATCH 08/11] Drivers: hv: mshv_vtl: Move register page config to arch-specific files
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 10 lines
Move
mshv_vtl_configure_reg_page()implementation fromdrivers/hv/mshv_vtl_main.cto arch-specific files:
-arch/x86/hyperv/hv_vtl.c: full implementation with register page setup
-arch/arm64/hyperv/hv_vtl.c: stub implementation (unsupported)Move common type definitions to
include/asm-generic/mshyperv.h:
- structmshv_vtl_per_cpu
- unionhv_synic_overlay_page_msr
Quoted 6 lines
Move
hv_call_get_vp_registers()andhv_call_set_vp_registers()declarations toinclude/asm-generic/mshyperv.hsince these functions are used by multiple modules.While at it, remove the unnecessary stub implementations in #else case for mshv_vtl_return* functions in
arch/x86/include/asm/mshyperv.h.
Seems like this patch is doing multiple things. The reg page configuration changes are more substantial and should probably be in a patch by themselves. The other changes are more trivial and maybe are OK grouped into a single patch, but you could also consider breaking them out.
Quoted 55 lines
This is essential for adding support for ARM64 in
MSHV_VTL.Signed-off-by Naman Jain <[email protected]>--- arch/arm64/hyperv/hv_vtl.c | 8 +++++ arch/arm64/include/asm/mshyperv.h | 3 ++ arch/x86/hyperv/hv_vtl.c | 32 ++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 7 ++--- drivers/hv/mshv.h | 8 ----- drivers/hv/mshv_vtl_main.c | 49 +++---------------------------- include/asm-generic/mshyperv.h | 42 ++++++++++++++++++++++++++ 7 files changed, 92 insertions(+), 57 deletions(-)arch/arm64/hyperv/hv_vtl.c +8
-0@@ -10,6 +10,7 @@#include <asm/boot.h> #include <asm/mshyperv.h> #include <asm/cpu_ops.h> +#include <linux/export.h> void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) {@@ -142,3 +143,10 @@ void mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0) "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"); }EXPORT_SYMBOL (mshv_vtl_return_call); + +bool hv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu) +{ +pr_debug ("Register page not supported on ARM64\n" ); +return false; +} +EXPORT_SYMBOL_GPL (hv_vtl_configure_reg_page);arch/arm64/include/asm/mshyperv.h +2
-0@@ -61,6 +61,8 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg) ARM_SMCCC_OWNER_VENDOR_HYP, \ HV_SMCCC_FUNC_NUMBER) +struct mshv_vtl_per_cpu ; + struct mshv_vtl_cpu_context {/* * NOTE: x18 is managed by the hypervisor. It won't be reloaded from this array. @@ -82,6 +84,7 @@ static inline int hv_vtl_get_set_reg(struct hv_register_assoc *regs,bool set, u
}
Quoted 2 lines
void
mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0);
+boolhv_vtl_configure_reg_page(struct mshv_vtl_per_cpu *per_cpu);
I think this declaration could be added in asm-generic/mshyperv.h so that it is shared by x86 and arm64. That also obviates the need for the forward ref to struct mshv_vtl_per_cpu that you've added here.
Quoted 37 lines
#endif
#include <
asm-generic/mshyperv.h>arch/x86/hyperv/hv_vtl.c +19
-0@@ -20,6 +20,7 @@#include <uapi/asm/mtrr.h> #include <asm/debugreg.h> #include <linux/export.h> +#include <linux/hyperv.h> #include <../kernel/smpboot.h> #include "../../kernel/fpu/legacy.h" @@ -259,6 +260,37 @@ int __init hv_vtl_early_init(void)return 0 ; } +static const union hv_input_vtl input_vtl_zero; + +bool hv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu) +{ +struct hv_register_assoc reg_assoc = {}; +union hv_synic_overlay_page_msr overlay = {}; +struct page *reg_page; + + reg_page =alloc_page (GFP_KERNEL | __GFP_ZERO | __GFP_RETRY_MAYFAIL); +if (!reg_page) { +WARN (1 ,"failed to allocate register page\n" ); +return false; + } + + overlay.enabled =1 ; + overlay.pfn =page_to_hvpfn (reg_page); + reg_assoc.name =HV_X64_REGISTER_REG_PAGE ; + reg_assoc.value.reg64 = overlay.as_uint64;
arch/x86/hyperv/hv_vtl.c int __init hv_vtl_early_init(void) · line 290
Quoted 10 lines
arch/x86/hyperv/hv_vtl.c +10
-0+ +if (hv_call_set_vp_registers (HV_VP_INDEX_SELF ,HV_PARTITION_ID_SELF , +1 , input_vtl_zero, ®_assoc)) { +WARN (1 ,"failed to setup register page\n" ); +__free_page (reg_page); +return false; + } + + per_cpu->reg_page = reg_page; +return true;
As Sashiko AI noted, the memory allocated for the reg_page never gets freed.
Quoted 21 lines
arch/x86/hyperv/hv_vtl.c +3
-0+} +EXPORT_SYMBOL_GPL (hv_vtl_configure_reg_page); + DEFINE_STATIC_CALL_NULL(__mshv_vtl_return_hypercall, void (*)(void));void mshv_vtl_return_call_init (u64 vtl_return_offset)arch/x86/include/asm/mshyperv.h +2
-0@@ -271,6 +271,8 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg) { return 0; }static inline int hv_apicid_to_vp_index (u32 apic_id) {return -EINVAL ; }#endif /* CONFIG_HYPERV */ +struct mshv_vtl_per_cpu ; + struct mshv_vtl_cpu_context { union {arch/x86/include/asm/mshyperv.h +0
-0struct {
arch/x86/include/asm/mshyperv.h void mshv_vtl_return_call_init(u64 vtl_return_offset); · line 310
Quoted 4 lines
arch/x86/include/asm/mshyperv.h +1
-0@@ -305,13 +307,10 @@ void mshv_vtl_return_call_init(u64 vtl_return_offset);void mshv_vtl_return_hypercall (void );void __mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0);int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared); +bool hv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu);
Same as for arm64. Add a shared declaration in asm-generic/mshyperv.h.
Quoted 91 lines
arch/x86/include/asm/mshyperv.h +0
-4#else static inline void __init hv_vtl_init_platform (void ) {}static inline int __init hv_vtl_early_init (void ) {return 0 ; } -static inline void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) {} -static inline void mshv_vtl_return_call_init (u64 vtl_return_offset) {} -static inline void mshv_vtl_return_hypercall (void ) {} -static inline void __mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) {}#endif #include <asm-generic/mshyperv.h> drivers/hv/mshv.h +0
-8@@ -14,14 +14,6 @@memchr_inv (&((STRUCT ).MEMBER), \ 0, sizeof_field(typeof(STRUCT), MEMBER)) -int hv_call_get_vp_registers (u32 vp_index,u64 partition_id,u16 count, -union hv_input_vtl input_vtl, -struct hv_register_assoc *registers); - -int hv_call_set_vp_registers (u32 vp_index,u64 partition_id,u16 count, -union hv_input_vtl input_vtl, -struct hv_register_assoc *registers); -int hv_call_get_partition_property (u64 partition_id,u64 property_code,u64 *property_value);drivers/hv/mshv_vtl_main.c +0
-43@@ -78,21 +78,6 @@ struct mshv_vtl {u64 id; }; -struct mshv_vtl_per_cpu { -struct mshv_vtl_run *run; -struct page *reg_page; -}; - -/* SYNIC_OVERLAY_PAGE_MSR - internal, identical to hv_synic_simp */ -union hv_synic_overlay_page_msr { -u64 as_uint64; -struct { -u64 enabled:1 ; -u64 reserved:11 ; -u64 pfn:52 ; - } __packed; -}; -static struct mutex mshv_vtl_poll_file_lock;static union hv_register_vsm_page_offsets mshv_vsm_page_offsets;static union hv_register_vsm_capabilities mshv_vsm_capabilities;@@ -201,34 +186,6 @@ static struct page *mshv_vtl_cpu_reg_page(int cpu)return *per_cpu_ptr (&mshv_vtl_per_cpu.reg_page, cpu); } -static void mshv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu) -{ -struct hv_register_assoc reg_assoc = {}; -union hv_synic_overlay_page_msr overlay = {}; -struct page *reg_page; - - reg_page =alloc_page (GFP_KERNEL | __GFP_ZERO | __GFP_RETRY_MAYFAIL); -if (!reg_page) { -WARN (1 ,"failed to allocate register page\n" ); -return ; - } - - overlay.enabled =1 ; - overlay.pfn =page_to_hvpfn (reg_page); - reg_assoc.name =HV_X64_REGISTER_REG_PAGE ; - reg_assoc.value.reg64 = overlay.as_uint64; - -if (hv_call_set_vp_registers (HV_VP_INDEX_SELF ,HV_PARTITION_ID_SELF , -1 , input_vtl_zero, ®_assoc)) { -WARN (1 ,"failed to setup register page\n" ); -__free_page (reg_page); -return ; - } - - per_cpu->reg_page = reg_page; - mshv_has_reg_page = true; -} -static void mshv_vtl_synic_enable_regs (unsigned int cpu) {union hv_synic_sint sint;
drivers/hv/mshv_vtl_main.c static int mshv_vtl_alloc_context(unsigned int cpu) · line 291
Quoted 8 lines
drivers/hv/mshv_vtl_main.c +3
-2@@ -329,8 +286,10 @@ static int mshv_vtl_alloc_context(unsigned int cpu)if (!per_cpu->run)return -ENOMEM ; -if (mshv_vsm_capabilities.intercept_page_available) -mshv_vtl_configure_reg_page (per_cpu); +if (mshv_vsm_capabilities.intercept_page_available) { +if (hv_vtl_configure_reg_page (per_cpu)) + mshv_has_reg_page = true;
As Sashiko AI noted, it doesn't work to use the global mshv_has_reg_page to indicate the success of configuring the reg page, which is a per-cpu operation. But this bug existed before this patch set, so maybe it should be fixed as a preliminary patch.
Quoted 60 lines
drivers/hv/mshv_vtl_main.c +1
-0+ }mshv_vtl_synic_enable_regs (cpu);include/asm-generic/mshyperv.h +42
-1@@ -383,8 +383,50 @@ static inline int hv_deposit_memory(u64 partition_id, u64 status)return hv_deposit_memory_node (NUMA_NO_NODE , partition_id, status); } +#if IS_ENABLED (CONFIG_MSHV_ROOT ) ||IS_ENABLED (CONFIG_MSHV_VTL ) +int hv_call_get_vp_registers (u32 vp_index,u64 partition_id,u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers); + +int hv_call_set_vp_registers (u32 vp_index,u64 partition_id,u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers); +#else +static inline int hv_call_get_vp_registers (u32 vp_index,u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers) +{ +return -EOPNOTSUPP ; +} + +static inline int hv_call_set_vp_registers (u32 vp_index,u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers) +{ +return -EOPNOTSUPP ; +} +#endif /* CONFIG_MSHV_ROOT || CONFIG_MSHV_VTL */ +#define HV_VP_ASSIST_PAGE_ADDRESS_SHIFT 12 +#if IS_ENABLED (CONFIG_HYPERV_VTL_MODE ) +struct mshv_vtl_per_cpu { +struct mshv_vtl_run *run; +struct page *reg_page; +}; + +/* SYNIC_OVERLAY_PAGE_MSR - internal, identical to hv_synic_simp */ +union hv_synic_overlay_page_msr { +u64 as_uint64; +struct { +u64 enabled:1 ; +u64 reserved:11 ; +u64 pfn:52 ; + } __packed; +}; +u8 __init get_vtl (void );#else static inline u8 get_vtl (void ) {return 0 ; } --
Quoted 2 lines
2.43.0
Sashiko AI noted another existing bug in mshv_vtl_init(), which is that the error path does kfree(mem_dev) when it should do put_device(mem_dev). See the comment in the header of device_initialize().
RE: [PATCH 09/11] Drivers: hv: mshv_vtl: Let userspace do VSM configuration
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 64 lines
The kernel currently sets the VSM configuration register, thereby imposing certain VSM configuration on the userspace (OpenVMM).
The userspace (OpenVMM) has the capability to configure this register, and it is already doing it using the generic hypercall interface. The configuration can vary based on the use case or architectures, so let userspace take care of configuring it and remove this logic in the kernel driver.
Signed-off-by Roman Kisel <[email protected]>Signed-off-by Naman Jain <[email protected]>--- drivers/hv/mshv_vtl_main.c | 29 ----------------------------- 1 file changed, 29 deletions(-)drivers/hv/mshv_vtl_main.c +0
-30@@ -222,30 +222,6 @@ static int mshv_vtl_get_vsm_regs(void)return ret; } -static int mshv_vtl_configure_vsm_partition (struct device *dev) -{ -union hv_register_vsm_partition_config config; -struct hv_register_assoc reg_assoc; - - config.as_uint64 =0 ; - config.default_vtl_protection_mask =HV_MAP_GPA_PERMISSIONS_MASK ; - config.enable_vtl_protection =1 ; - config.zero_memory_on_reset =1 ; - config.intercept_vp_startup =1 ; - config.intercept_cpuid_unimplemented =1 ; - -if (mshv_vsm_capabilities.intercept_page_available) { -dev_dbg (dev,"using intercept page\n" ); - config.intercept_page =1 ; - } - - reg_assoc.name =HV_REGISTER_VSM_PARTITION_CONFIG ; - reg_assoc.value.reg64 = config.as_uint64; - -return hv_call_set_vp_registers (HV_VP_INDEX_SELF ,HV_PARTITION_ID_SELF , -1 , input_vtl_zero, ®_assoc); -} -static void mshv_vtl_vmbus_isr (void ) {struct hv_per_cpu_context *per_cpu;@@ -1168,11 +1144,6 @@ static int __init mshv_vtl_init(void) ret = -ENODEV ; goto free_dev; } -if (mshv_vtl_configure_vsm_partition (dev)) { -dev_emerg (dev,"VSM configuration failed !!\n" ); - ret = -ENODEV ; - goto free_dev; - }mshv_vtl_return_call_init (mshv_vsm_page_offsets.vtl_return_offset); ret =hv_vtl_setup_synic (); --
Quoted 2 lines
2.43.0
RE: [PATCH 10/11] Drivers: hv: Add support for arm64 in MSHV_VTL
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 37 lines
Add necessary support to make
MSHV_VTLwork for arm64 architecture.
* Add stub implementation formshv_vtl_return_call_init(): not required for arm64
* Removefpu/legacy.hheader inclusion, as this is not required
* handleHV_REGISTER_VSM_CODE_PAGE_OFFSETSregister: not supported in arm64
* Configure custompercpu_vmbus_handlerby usinghv_setup_percpu_vmbus_handler()
* Handle hugepage functions by config checksSigned-off-by Roman Kisel <[email protected]>Signed-off-by Naman Jain <[email protected]>--- arch/arm64/include/asm/mshyperv.h | 2 ++ drivers/hv/mshv_vtl_main.c | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-)arch/arm64/include/asm/mshyperv.h +2
-0@@ -83,6 +83,8 @@ static inline int hv_vtl_get_set_reg(struct hv_register_assoc *regs, bool set, u return 1; } +static inline void mshv_vtl_return_call_init (u64 vtl_return_offset) {} +void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0);bool hv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu);#endif drivers/hv/mshv_vtl_main.c +0
-0
drivers/hv/mshv_vtl_main.c line 27
Quoted 5 lines
drivers/hv/mshv_vtl_main.c +0
-2@@ -23,8 +23,6 @@#include <trace/events/ipi.h> #include <uapi/linux/mshv.h> #include <hyperv/hvhdk.h> - -#include "../../kernel/fpu/legacy.h"
Was there a particular code change that made this unnecessary? Or was it unnecessary from the start of this source code file? Just curious ....
Quoted 20 lines
drivers/hv/mshv_vtl_main.c +5
-3#include "mshv.h" #include "mshv_vtl.h" #include "hyperv_vmbus.h" @@ -206,18 +204,21 @@ static void mshv_vtl_synic_enable_regs(unsigned int cpu)static int mshv_vtl_get_vsm_regs (void ) {struct hv_register_assoc registers[2 ]; -int ret, count =2 ; +int ret, count =0 ; - registers[0 ].name =HV_REGISTER_VSM_CODE_PAGE_OFFSETS ; - registers[1 ].name =HV_REGISTER_VSM_CAPABILITIES ; + registers[count++].name =HV_REGISTER_VSM_CAPABILITIES ; +/* Code page offset register is not supported on ARM */ +if (IS_ENABLED (CONFIG_X86_64 )) + registers[count++].name =HV_REGISTER_VSM_CODE_PAGE_OFFSETS ; ret =hv_call_get_vp_registers (HV_VP_INDEX_SELF ,HV_PARTITION_ID_SELF , count, input_vtl_zero, registers);if (ret)
drivers/hv/mshv_vtl_main.c static void mshv_vtl_synic_enable_regs(unsigned int cpu) · line 224
Quoted 10 lines
drivers/hv/mshv_vtl_main.c +3
-2return ret; - mshv_vsm_page_offsets.as_uint64 = registers[0 ].value.reg64; - mshv_vsm_capabilities.as_uint64 = registers[1 ].value.reg64; + mshv_vsm_capabilities.as_uint64 = registers[0 ].value.reg64; +if (IS_ENABLED (CONFIG_X86_64 )) + mshv_vsm_page_offsets.as_uint64 = registers[1 ].value.reg64;return ret; }
This function has gotten somewhat messy to handle the x86 and arm64 differences. Let me suggest a different approach. Have this function only get the VSM capabilities register, as that is generic across x86 and arm64. Then, update x86 mshv_vtl_return_call_init() to get the PAGE_OFFSETS register and then immediately use the value to update the static call. The global variable mshv_vms_page_offsets is no longer necessary.
My suggestion might be little more code because hv_call_get_vp_registers() is invoked in two different places. But it cleanly separates the two use cases, and keeps the x86 hackery under arch/x86.
Quoted 38 lines
drivers/hv/mshv_vtl_main.c +6
-1@@ -280,10 +281,13 @@ static int hv_vtl_setup_synic(void)/* Use our isr to first filter out packets destined for userspace */ hv_setup_vmbus_handler (mshv_vtl_vmbus_isr); +/* hv_setup_vmbus_handler() is stubbed for ARM64, add per-cpu VMBus handlers instead */ +hv_setup_percpu_vmbus_handler (mshv_vtl_vmbus_isr); ret =cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"hyperv/vtl:online" , mshv_vtl_alloc_context,NULL );if (ret <0 ) { +hv_setup_percpu_vmbus_handler (vmbus_isr);hv_setup_vmbus_handler (vmbus_isr);return ret; }@@ -296,6 +300,7 @@ static int hv_vtl_setup_synic(void)static void hv_vtl_remove_synic (void ) {cpuhp_remove_state (mshv_vtl_cpuhp_online); +hv_setup_percpu_vmbus_handler (vmbus_isr);hv_setup_vmbus_handler (vmbus_isr); }@@ -1080,10 +1085,12 @@ static vm_fault_t mshv_vtl_low_huge_fault(struct vm_fault *vmf, unsigned int ord ret =vmf_insert_pfn_pmd (vmf, pfn, vmf->flags &FAULT_FLAG_WRITE );return ret; +#if defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD )case PUD_ORDER :if (can_fault (vmf,PUD_SIZE , &pfn)) ret =vmf_insert_pfn_pud (vmf, pfn, vmf->flags &FAULT_FLAG_WRITE );return ret; +#endif default :return VM_FAULT_SIGBUS ; --2.43.0
RE: [PATCH 11/11] Drivers: hv: Kconfig: Add ARM64 support for MSHV_VTL
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 1 line
Nit: In keeping with past practice, the "Subject" prefix for this patch could just be "Drivers: hv:"
Quoted 23 lines
Enable ARM64 support in
MSHV_VTLKconfignow that all the necessary support is present.Signed-off-by Roman Kisel <[email protected]>Signed-off-by Naman Jain <[email protected]>--- drivers/hv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hv/Kconfig +1
-2@@ -87,7 +87,7 @@ config MSHV_ROOT config MSHV_VTL tristate "Microsoft Hyper-V VTL driver" - depends on X86_64 && HYPERV_VTL_MODE + depends on (X86_64 || ARM64) && HYPERV_VTL_MODE depends on HYPERV_VMBUS # 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, --
Quoted 2 lines
2.43.0
The nit notwithstanding,
Quoted 41 lines · Michael Kelley
From: Naman Jain <[email protected]> Sent: Tuesday, March 17, 2026 9:23 PM
Quoted 5 lines · Michael Kelley
Quoted 3 lines
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 2 lines
The series intends to add support for ARM64 to
mshv_vtldriver.No need to be tentative. :-) Just write as:
"The series adds support for ARM64 to the
mshv_vtldriver."Quoted 16 lines
Quoted 16 lines
Quoted 5 lines
For this, common Hyper-V code is refactored, necessary support is added,
mshv_vtl_main.cis refactored and then finally support is added inKconfig.Based on commit
1f318b96cc84("Linux 7.0-rc3")There's now an online LLM-based tool that is automatically reviewing kernel patches. For this patch set, the results are here:
https://sashiko.dev/#/patchset/20260316121241.910764-1-namjain%40linux.microsoft.com
It has flagged several things that are worth checking, but I haven't reviewed them to see if they are actually valid.
FWIW, the announcement about sashiko.dev is here:
Quoted 8 lines
Quoted 3 lines
https://lore.kernel.org/lkml/[email protected]/
Michael
Thanks for sharing Michael,
I'll check it out and do the needful.I've done a full review of this patch set and provided comments in the individual patches. Some of my comments reference the Sashiko AI comments, but there are still some Sashiko AI comments to consider that I haven't referenced.
Quoted 5 lines
FWIW, the Sashiko AI comments are quite good -- it found some things here that I missed on my own, and in my earlier reviews of the original VTL code. :-(
Michael
Thank you so much Michael for reviewing these. I was also trying to address review comments from Sashiko, and noticed some of them were false positives in the sense that these were existing issues and not introduced by arm64 changes. I thought of keeping them separate from the scope of this series for future.
I'll review your comments and address them.
Regards,
Naman
Re: [PATCH 01/11] arch: arm64: Export arch_smp_send_reschedule for mshv_vtl module
In reply to Michael KelleyQuoted 6 lines · Michael Kelley
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 1 line
Nit: For the patch "Subject", the most common prefix for the file
arch/arm64/kernel/smp.cis "arm64: smp:". I'd suggest using that prefix for historical consistency.
Acked. Will change in v2.
Quoted 40 lines
Quoted 35 lines
mshv_vtl_main.ccallssmp_send_reschedule()which expands toarch_smp_send_reschedule(). WhenCONFIG_MSHV_VTL=m, the module cannot access this symbol since it is not exported on arm64.
smp_send_reschedule()is used inmshv_vtl_cancel()to interrupt a vCPU thread running on another CPU. When a vCPU is looping inmshv_vtl_ioctl_return_to_lower_vtl(), it checks a per-CPU cancel flag before each VTL0 entry. Setting cancel=1 alone is not enough if the target CPU thread is sleeping - the IPI fromsmp_send_reschedule()kicks the remote CPU out of idle/sleep so it re-checks the cancel flag and exits the loop promptly.Other architectures (riscv, loongarch, powerpc) already export this symbol. Add the same
EXPORT_SYMBOL_GPLfor arm64. This is required for adding arm64 support inMSHV_VTL.Signed-off-by Naman Jain <[email protected]>--- arch/arm64/kernel/smp.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/kernel/smp.c +1
-1@@ -1152,6 +1152,7 @@ void arch_smp_send_reschedule(int cpu) {smp_cross_call (cpumask_of (cpu),IPI_RESCHEDULE ); } +EXPORT_SYMBOL_GPL (arch_smp_send_reschedule);#ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL void arch_send_wakeup_ipi (unsigned int cpu) --Quoted 2 lines
2.43.0
The "Subject" nit notwithstanding,
Quoted 1 line
Reviewed-by Michael Kelley <[email protected]>
Thanks,
Naman
Re: [PATCH 03/11] Drivers: hv: Add support to setup percpu vmbus handler
In reply to Michael KelleyQuoted 27 lines · Michael Kelley
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 6 lines
Add a wrapper function -
hv_setup_percpu_vmbus_handler(), similar tohv_setup_vmbus_handler()to allow setting up custom per-cpu VMBus interrupt handler. This is required for arm64 support, to be added inMSHV_VTLdriver, where per-cpu VMBus interrupt handler will be set tomshv_vtl_vmbus_isr()for VTL2 (Virtual Trust Level 2).Needing both
hv_setup_vmbus_handler()andhv_setup_percpu_vmbus_handler()seems unfortunate. Here's an alternate approach to consider:1. I think the x86 VMBus sysvec handler and the
vmbus_percpu_isr()functions could both use the samevmbus_handlerglobal variable. Looking at your changes in this patch set,hv_setup_vmbus_handler()andhv_setup_percpu_vmbus_handler()are used together and always set the same value.2. So move the global variable
vmbus_handlerout fromarch/x86and intohv_common.c, and export it. The x86 sysvec handler can still reference it, andvmbus_percpu_isr()invmbus_drv.ccan also reference it. No need to havevmbus_percpu_isr()underarch/arm64or have a stub inhv_common.c.3.
hv_setup_vmbus_handler()andhv_remove_vmbus_handler()also move tohv_common.c. The__weakstubs go away.
Quoted 8 lines
With these changes, only
hv_setup_vmbus_handler()needs to be called, and it works for both x86 with the sysvec handler and for arm64 withvmbus_percpu_isr().I haven't coded this up, so maybe there's some problematic detail, but the idea seems like it would work. If it does work, some of my comments below are no longer applicable.
This is a great suggestion. Current implementation looked complex in design and it was becoming more complex with the changes I was making while addressing Sashiko's AI review comments. However your suggestion looks much better. I'll implement it. Thanks for suggesting.
Quoted 59 lines
Quoted 39 lines
Signed-off-by Saurabh Sengar <[email protected]>Signed-off-by Naman Jain <[email protected]>--- arch/arm64/hyperv/mshyperv.c | 13 +++++++++++++ drivers/hv/hv_common.c | 11 +++++++++++ drivers/hv/vmbus_drv.c | 7 +------ include/asm-generic/mshyperv.h | 3 +++ 4 files changed, 28 insertions(+), 6 deletions(-)arch/arm64/hyperv/mshyperv.c +13
-0@@ -134,3 +134,16 @@ bool hv_is_hyperv_initialized(void)return hyperv_initialized; }EXPORT_SYMBOL_GPL (hv_is_hyperv_initialized); + +static void (*vmbus_percpu_handler)(void ); +void hv_setup_percpu_vmbus_handler (void (*handler)(void )) +{ + vmbus_percpu_handler = handler; +} + +irqreturn_t vmbus_percpu_isr (int irq,void *dev_id) +{ +if (vmbus_percpu_handler) +vmbus_percpu_handler (); +return IRQ_HANDLED ; +}drivers/hv/hv_common.c +0
-0@@ -759,6 +759,17 @@ void __weak hv_setup_vmbus_handler(void (*handler)(void)) }EXPORT_SYMBOL_GPL (hv_setup_vmbus_handler);drivers/hv/hv_common.c void __weak hv_setup_vmbus_handler(void (*handler)(void)) · line 771
Quoted 10 lines
drivers/hv/hv_common.c +10
-0+irqreturn_t __weak vmbus_percpu_isr (int irq,void *dev_id) +{ +return IRQ_HANDLED ; +} +EXPORT_SYMBOL_GPL (vmbus_percpu_isr); + +void __weak hv_setup_percpu_vmbus_handler (void (*handler)(void )) +{ +} +EXPORT_SYMBOL_GPL (hv_setup_percpu_vmbus_handler);You've implemented
hv_setup_percpu_vmbus_handler()following the pattern ofhv_setup_vmbus_handler(), which is reasonable. But that turns out to be unnecessarily complicated. The existinghv_setup_vmbus_handler()has a portion inarch/x86/kernel/cpu/mshyperv.cas a special case because it uses a hard-coded interrupt vector on x86/x64, and has its own custom sysvec code. And there's a need for a__weakstub inhv_common.cso thatvmbus_drv.cwill compile on arm64.
Quoted 9 lines
But
hv_setup_percpu_vmbus_handler()does not have the same requirements. It could be implemented entirely invmbus_drv.c, with no code underarch/x86orarch/arm64, and no__weakstub inhv_common.c.vmbus_drv.cwould just need toEXPORT_SYMBOL_FOR_MODULES, like it already does withvmbus_isr. I didn't code it up, but I think that approach would be simpler with fewer piece-parts scattered all over. If so, it would be worth breaking the symmetry withhv_setup_vmbus_handler().
No longer applicable.
Regards,
Naman
Re: [PATCH 04/11] Drivers: hv: Refactor mshv_vtl for ARM64 support to be added
In reply to Michael KelleyQuoted 155 lines · Michael Kelley
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 154 lines
Refactor
MSHV_VTLdriver to move some of the x86 specific code to arch specific files, and add corresponding functions for arm64.Signed-off-by Roman Kisel <[email protected]>Signed-off-by Naman Jain <[email protected]>--- arch/arm64/include/asm/mshyperv.h | 10 +++ arch/x86/hyperv/hv_vtl.c | 98 ++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 1 + drivers/hv/mshv_vtl_main.c | 102 +----------------------------- 4 files changed, 111 insertions(+), 100 deletions(-)arch/arm64/include/asm/mshyperv.h +10
-0@@ -60,6 +60,16 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg) ARM_SMCCC_SMC_64, \ ARM_SMCCC_OWNER_VENDOR_HYP, \ HV_SMCCC_FUNC_NUMBER) +#ifdef CONFIG_HYPERV_VTL_MODE +/* +* Get/Set the register. If the function returns `1`, that must be done via +* a hypercall. Returning `0` means success. +*/ +static inline int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared) +{ +return 1 ; +} +#endif #include <asm-generic/mshyperv.h> arch/x86/hyperv/hv_vtl.c +98
-0@@ -17,6 +17,8 @@#include <asm/realmode.h> #include <asm/reboot.h> #include <asm/smap.h> +#include <uapi/asm/mtrr.h> +#include <asm/debugreg.h> #include <linux/export.h> #include <../kernel/smpboot.h> #include "../../kernel/fpu/legacy.h" @@ -281,3 +283,99 @@ void mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0)kernel_fpu_end (); }EXPORT_SYMBOL (mshv_vtl_return_call); + +/* Static table mapping register names to their corresponding actions */ +static const struct { +enum hv_register_name reg_name; +int debug_reg_num;/* -1 if not a debug register */ +u32 msr_addr;/* 0 if not an MSR */ +} reg_table[] = { +/* Debug registers */ + {HV_X64_REGISTER_DR0 ,0 ,0 }, + {HV_X64_REGISTER_DR1 ,1 ,0 }, + {HV_X64_REGISTER_DR2 ,2 ,0 }, + {HV_X64_REGISTER_DR3 ,3 ,0 }, + {HV_X64_REGISTER_DR6 ,6 ,0 }, +/* MTRR MSRs */ + {HV_X64_REGISTER_MSR_MTRR_CAP ,-1 , MSR_MTRRcap}, + {HV_X64_REGISTER_MSR_MTRR_DEF_TYPE ,-1 , MSR_MTRRdefType}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE0 ,-1 ,MTRRphysBase_MSR (0 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE1 ,-1 ,MTRRphysBase_MSR (1 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE2 ,-1 ,MTRRphysBase_MSR (2 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE3 ,-1 ,MTRRphysBase_MSR (3 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE4 ,-1 ,MTRRphysBase_MSR (4 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE5 ,-1 ,MTRRphysBase_MSR (5 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE6 ,-1 ,MTRRphysBase_MSR (6 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE7 ,-1 ,MTRRphysBase_MSR (7 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE8 ,-1 ,MTRRphysBase_MSR (8 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE9 ,-1 ,MTRRphysBase_MSR (9 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEA ,-1 ,MTRRphysBase_MSR (0xa )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEB ,-1 ,MTRRphysBase_MSR (0xb )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEC ,-1 ,MTRRphysBase_MSR (0xc )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASED ,-1 ,MTRRphysBase_MSR (0xd )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEE ,-1 ,MTRRphysBase_MSR (0xe )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEF ,-1 ,MTRRphysBase_MSR (0xf )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK0 ,-1 ,MTRRphysMask_MSR (0 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK1 ,-1 ,MTRRphysMask_MSR (1 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK2 ,-1 ,MTRRphysMask_MSR (2 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK3 ,-1 ,MTRRphysMask_MSR (3 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK4 ,-1 ,MTRRphysMask_MSR (4 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK5 ,-1 ,MTRRphysMask_MSR (5 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK6 ,-1 ,MTRRphysMask_MSR (6 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK7 ,-1 ,MTRRphysMask_MSR (7 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK8 ,-1 ,MTRRphysMask_MSR (8 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK9 ,-1 ,MTRRphysMask_MSR (9 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKA ,-1 ,MTRRphysMask_MSR (0xa )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKB ,-1 ,MTRRphysMask_MSR (0xb )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKC ,-1 ,MTRRphysMask_MSR (0xc )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKD ,-1 ,MTRRphysMask_MSR (0xd )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKE ,-1 ,MTRRphysMask_MSR (0xe )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKF ,-1 ,MTRRphysMask_MSR (0xf )}, + {HV_X64_REGISTER_MSR_MTRR_FIX64K00000 ,-1 , MSR_MTRRfix64K_00000}, + {HV_X64_REGISTER_MSR_MTRR_FIX16K80000 ,-1 , MSR_MTRRfix16K_80000}, + {HV_X64_REGISTER_MSR_MTRR_FIX16KA0000 ,-1 , MSR_MTRRfix16K_A0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KC0000 ,-1 , MSR_MTRRfix4K_C0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KC8000 ,-1 , MSR_MTRRfix4K_C8000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KD0000 ,-1 , MSR_MTRRfix4K_D0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KD8000 ,-1 , MSR_MTRRfix4K_D8000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KE0000 ,-1 , MSR_MTRRfix4K_E0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KE8000 ,-1 , MSR_MTRRfix4K_E8000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KF0000 ,-1 , MSR_MTRRfix4K_F0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KF8000 ,-1 , MSR_MTRRfix4K_F8000}, +}; + +int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared) +{ +u64 *reg64; +enum hv_register_name gpr_name; +int i; + + gpr_name = regs->name; + reg64 = ®s->value.reg64; + +/* Search for the register in the table */ +for (i =0 ; i <ARRAY_SIZE (reg_table); i++) { +if (reg_table[i].reg_name != gpr_name) +continue ; +if (reg_table[i].debug_reg_num !=-1 ) { +/* Handle debug registers */ +if (gpr_name ==HV_X64_REGISTER_DR6 && !shared) + goto hypercall; +if (set) +native_set_debugreg (reg_table[i].debug_reg_num, *reg64); +else + *reg64 =native_get_debugreg (reg_table[i].debug_reg_num); + }else { +/* Handle MSRs */ +if (set) +wrmsrl (reg_table[i].msr_addr, *reg64); +else +rdmsrl (reg_table[i].msr_addr, *reg64); + } +return 0 ; + } + +hypercall: +return 1 ; +} +EXPORT_SYMBOL (hv_vtl_get_set_reg);arch/x86/include/asm/mshyperv.h +0
-0@@ -304,6 +304,7 @@ void mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0);void mshv_vtl_return_call_init (u64 vtl_return_offset);
Quoted 8 lines
arch/x86/include/asm/mshyperv.h void mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0); · line 307
Quoted 3 lines
arch/x86/include/asm/mshyperv.h +1
-0void mshv_vtl_return_hypercall (void );void __mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0); +int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared);Can this move to
asm-generic/mshyperv.h? The function is no longer specific to x86/x64, so one would want to not declare it in thearch/x86version ofmshyperv.h. But maybe moving it toasm-generic/mshyperv.hbreaks compilation on arm64 because there's also the static inline stub there.
This is still arch specific (x86 to be precise). For ARM64, we always want to return 1, which is to tell the client to use hypercall as a fallback option. Moving this x86 specific implementation (X64 registers, MTRR etc) to a common code, would not be right. One thing that could be done here was to move the "return 1" stub code from arm64 to asm-generic mshyperv.h, but that would not provide much benefit.
I am currently not planning to make any changes here. If I misunderstood your comment, please let me know.
Regards,
Naman
Re: [PATCH 05/11] drivers: hv: Export vmbus_interrupt for mshv_vtl module
In reply to Michael KelleyQuoted 4 lines · Michael Kelley
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 1 line
Nit: For the patch Subject, capitalize "Drivers:" in the prefix.
Acked.
Thanks,
Naman
Quoted 30 lines
Quoted 26 lines
vmbus_interruptis used inmshv_vtl_main.cto set the SINT vector. WhenCONFIG_MSHV_VTL=mandCONFIG_HYPERV_VMBUS=y(built-in), the module cannot accessvmbus_interruptat load time since it is not exported.Export it using
EXPORT_SYMBOL_FOR_MODULESconsistent with the existing pattern used forvmbus_isr.Signed-off-by Naman Jain <[email protected]>--- drivers/hv/vmbus_drv.c | 1 + 1 file changed, 1 insertion(+)drivers/hv/vmbus_drv.c +1
-1@@ -57,6 +57,7 @@ static DEFINE_PER_CPU(long, vmbus_evt);/* Values parsed from ACPI DSDT */ int vmbus_irq;int vmbus_interrupt; +EXPORT_SYMBOL_FOR_MODULES (vmbus_interrupt,"mshv_vtl" );/* * If the Confidential VMBus is used, the data on the "wire" is not -- Quoted 2 lines
2.43.0
Reviewed-by Michael Kelley <[email protected]>
Re: [PATCH 06/11] Drivers: hv: Make sint vector architecture neutral in MSHV_VTL
In reply to Michael KelleyQuoted 11 lines · Michael Kelley
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 4 lines
Generalize Synthetic interrupt source vector (sint) to use
vmbus_interruptvariable instead, which automatically takes care of architectures whereHYPERVISOR_CALLBACK_VECTORis not present (arm64).Sashiko AI raised an interesting question about the startup timing -- whether the
vmbus_platform_driver_probe()is guaranteed to have setvmbus_interruptbefore the VTL functions below run and use it. What causes the mshv_vtl.ko module to be loaded, and hence runmshv_vtl_init()?
There is no race condition here. The init ordering guarantees that vmbus_interrupt is always set before mshv_vtl_synic_enable_regs() reads it.
The call chain for setting vmbus_interrupt:
subsys_initcall(hv_acpi_init) [level 4]
-> platform_driver_register(&vmbus_platform_driver) and so on.
The call chain for reading vmbus_interrupt:
module_init(mshv_vtl_init) [level 6]
-> hv_vtl_setup_synic()
-> cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, ...,
mshv_vtl_alloc_context, ...)
-> mshv_vtl_alloc_context()
-> mshv_vtl_synic_enable_regs()
-> sint.vector = vmbus_interruptdo_initcalls() processes sections in order 0 through 7, so hv_acpi_init() (level 4) is guaranteed to complete before mshv_vtl_init() (level 6) runs.
Regarding memory leak on cpu offline/online or module load/unload- it is beyond the scope of this series, I will fix it separately.
I may need some more time in addressing comments on rest of the patches. Please bear with me.
Regards,
Naman
Quoted 37 lines
Quoted 31 lines
Signed-off-by Roman Kisel <[email protected]>Signed-off-by Naman Jain <[email protected]>--- drivers/hv/mshv_vtl_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/hv/mshv_vtl_main.c +2
-3@@ -234,7 +234,7 @@ static void mshv_vtl_synic_enable_regs(unsigned int cpu)union hv_synic_sint sint; sint.as_uint64 =0 ; - sint.vector =HYPERVISOR_CALLBACK_VECTOR ; + sint.vector = vmbus_interrupt; sint.masked = false; sint.auto_eoi =hv_recommend_using_aeoi ();@@ -753,7 +753,7 @@ static void mshv_vtl_synic_mask_vmbus_sint(void *info)const u8 *mask = info; sint.as_uint64 =0 ; - sint.vector =HYPERVISOR_CALLBACK_VECTOR ; + sint.vector = vmbus_interrupt; sint.masked = (*mask !=0 ); sint.auto_eoi =hv_recommend_using_aeoi (); --Quoted 2 lines
2.43.0
Assuming there's no timing problem vs. the VMBus driver,
Reviewed-by Michael Kelley <[email protected]>
RE: [PATCH 04/11] Drivers: hv: Refactor mshv_vtl for ARM64 support to be added
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, April 13, 2026 4:46 AM
Quoted 175 lines · Michael Kelley
Quoted 1 line
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026
5:13 AM
Quoted 145 lines
Quoted 145 lines
Refactor
MSHV_VTLdriver to move some of the x86 specific code to arch specific files, and add corresponding functions for arm64.Signed-off-by Roman Kisel <[email protected]>Signed-off-by Naman Jain <[email protected]>--- arch/arm64/include/asm/mshyperv.h | 10 +++ arch/x86/hyperv/hv_vtl.c | 98 ++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 1 + drivers/hv/mshv_vtl_main.c | 102 +----------------------------- 4 files changed, 111 insertions(+), 100 deletions(-)arch/arm64/include/asm/mshyperv.h +10
-0@@ -60,6 +60,16 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg) ARM_SMCCC_SMC_64, \ ARM_SMCCC_OWNER_VENDOR_HYP, \ HV_SMCCC_FUNC_NUMBER) +#ifdef CONFIG_HYPERV_VTL_MODE +/* +* Get/Set the register. If the function returns `1`, that must be done via +* a hypercall. Returning `0` means success. +*/ +static inline int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared) +{ +return 1 ; +} +#endif #include <asm-generic/mshyperv.h> arch/x86/hyperv/hv_vtl.c +95
-0@@ -17,6 +17,8 @@#include <asm/realmode.h> #include <asm/reboot.h> #include <asm/smap.h> +#include <uapi/asm/mtrr.h> +#include <asm/debugreg.h> #include <linux/export.h> #include <../kernel/smpboot.h> #include "../../kernel/fpu/legacy.h" @@ -281,3 +283,99 @@ void mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0)kernel_fpu_end (); }EXPORT_SYMBOL (mshv_vtl_return_call); + +/* Static table mapping register names to their corresponding actions */ +static const struct { +enum hv_register_name reg_name; +int debug_reg_num;/* -1 if not a debug register */ +u32 msr_addr;/* 0 if not an MSR */ +} reg_table[] = { +/* Debug registers */ + {HV_X64_REGISTER_DR0 ,0 ,0 }, + {HV_X64_REGISTER_DR1 ,1 ,0 }, + {HV_X64_REGISTER_DR2 ,2 ,0 }, + {HV_X64_REGISTER_DR3 ,3 ,0 }, + {HV_X64_REGISTER_DR6 ,6 ,0 }, +/* MTRR MSRs */ + {HV_X64_REGISTER_MSR_MTRR_CAP ,-1 , MSR_MTRRcap}, + {HV_X64_REGISTER_MSR_MTRR_DEF_TYPE ,-1 , MSR_MTRRdefType}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE0 ,-1 ,MTRRphysBase_MSR (0 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE1 ,-1 ,MTRRphysBase_MSR (1 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE2 ,-1 ,MTRRphysBase_MSR (2 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE3 ,-1 ,MTRRphysBase_MSR (3 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE4 ,-1 ,MTRRphysBase_MSR (4 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE5 ,-1 ,MTRRphysBase_MSR (5 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE6 ,-1 ,MTRRphysBase_MSR (6 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE7 ,-1 ,MTRRphysBase_MSR (7 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE8 ,-1 ,MTRRphysBase_MSR (8 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASE9 ,-1 ,MTRRphysBase_MSR (9 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEA ,-1 ,MTRRphysBase_MSR (0xa )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEB ,-1 ,MTRRphysBase_MSR (0xb )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEC ,-1 ,MTRRphysBase_MSR (0xc )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASED ,-1 ,MTRRphysBase_MSR (0xd )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEE ,-1 ,MTRRphysBase_MSR (0xe )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_BASEF ,-1 ,MTRRphysBase_MSR (0xf )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK0 ,-1 ,MTRRphysMask_MSR (0 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK1 ,-1 ,MTRRphysMask_MSR (1 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK2 ,-1 ,MTRRphysMask_MSR (2 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK3 ,-1 ,MTRRphysMask_MSR (3 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK4 ,-1 ,MTRRphysMask_MSR (4 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK5 ,-1 ,MTRRphysMask_MSR (5 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK6 ,-1 ,MTRRphysMask_MSR (6 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK7 ,-1 ,MTRRphysMask_MSR (7 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK8 ,-1 ,MTRRphysMask_MSR (8 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASK9 ,-1 ,MTRRphysMask_MSR (9 )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKA ,-1 ,MTRRphysMask_MSR (0xa )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKB ,-1 ,MTRRphysMask_MSR (0xb )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKC ,-1 ,MTRRphysMask_MSR (0xc )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKD ,-1 ,MTRRphysMask_MSR (0xd )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKE ,-1 ,MTRRphysMask_MSR (0xe )}, + {HV_X64_REGISTER_MSR_MTRR_PHYS_MASKF ,-1 ,MTRRphysMask_MSR (0xf )}, + {HV_X64_REGISTER_MSR_MTRR_FIX64K00000 ,-1 , MSR_MTRRfix64K_00000}, + {HV_X64_REGISTER_MSR_MTRR_FIX16K80000 ,-1 , MSR_MTRRfix16K_80000}, + {HV_X64_REGISTER_MSR_MTRR_FIX16KA0000 ,-1 , MSR_MTRRfix16K_A0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KC0000 ,-1 , MSR_MTRRfix4K_C0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KC8000 ,-1 , MSR_MTRRfix4K_C8000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KD0000 ,-1 , MSR_MTRRfix4K_D0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KD8000 ,-1 , MSR_MTRRfix4K_D8000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KE0000 ,-1 , MSR_MTRRfix4K_E0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KE8000 ,-1 , MSR_MTRRfix4K_E8000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KF0000 ,-1 , MSR_MTRRfix4K_F0000}, + {HV_X64_REGISTER_MSR_MTRR_FIX4KF8000 ,-1 , MSR_MTRRfix4K_F8000}, +}; + +int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared) +{ +u64 *reg64; +enum hv_register_name gpr_name; +int i; + + gpr_name = regs->name; + reg64 = ®s->value.reg64; + +/* Search for the register in the table */ +for (i =0 ; i <ARRAY_SIZE (reg_table); i++) { +if (reg_table[i].reg_name != gpr_name) +continue ; +if (reg_table[i].debug_reg_num !=-1 ) { +/* Handle debug registers */ +if (gpr_name ==HV_X64_REGISTER_DR6 && !shared) + goto hypercall; +if (set) +native_set_debugreg (reg_table[i].debug_reg_num, *reg64); +else + *reg64 =native_get_debugreg (reg_table[i].debug_reg_num); + }else { +/* Handle MSRs */ +if (set) +wrmsrl (reg_table[i].msr_addr, *reg64); +else +rdmsrl (reg_table[i].msr_addr, *reg64); + } +return 0 ; + } + +hypercall:Quoted 8 lines
arch/x86/include/asm/mshyperv.h void mshv_vtl_return_call(struct mshv_vtl_cpu_context
Quoted 8 lines
arch/x86/hyperv/hv_vtl.c +3
-0+return 1 ; +} +EXPORT_SYMBOL (hv_vtl_get_set_reg);arch/x86/include/asm/mshyperv.h +0
-0@@ -304,6 +304,7 @@ void mshv_vtl_return_call(struct mshv_vtl_cpu_context*vtl0);
Quoted 9 lines
arch/x86/include/asm/mshyperv.h void mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0); · line 307
Quoted 4 lines
arch/x86/include/asm/mshyperv.h +1
-0void mshv_vtl_return_call_init (u64 vtl_return_offset);void mshv_vtl_return_hypercall (void );void __mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0); +int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared);Can this move to
asm-generic/mshyperv.h? The function is no longer specific to x86/x64, so one would want to not declare it in thearch/x86version ofmshyperv.h. But maybe moving it toasm-generic/mshyperv.hbreaks compilation on arm64 because there's also the static inline stub there.This is still arch specific (x86 to be precise). For ARM64, we always want to return 1, which is to tell the client to use hypercall as a fallback option. Moving this x86 specific implementation (X64 registers, MTRR etc) to a common code, would not be right. One thing that could be done here was to move the "return 1" stub code from arm64 to asm-generic
mshyperv.h, but that would not provide much benefit.
Quoted 3 lines
I am currently not planning to make any changes here. If I misunderstood your comment, please let me know.
Yes, the implementation of hv_vtl_get_set_reg() is arch-specific. But the one-line declaration is not. If there was a full implementation on arm64 like with x86, then the declaration could move to asm-generic/mshyperv.h. But the arm64 side is a "static inline" function, and I'm pretty sure the above declaration would cause a compiler conflict. So not making any changes is appropriate. If the arm64 side should ever change to a full implementation that isn't static inline, then the one-line declaration should move to asm-generic/mshyperv.h.
I probably should have omitted my comment entirely as it was just musing about a situation that doesn't actually exist at the moment. :-(
Michael
RE: [PATCH 06/11] Drivers: hv: Make sint vector architecture neutral in MSHV_VTL
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, April 13, 2026 4:48 AM
Quoted 33 lines · Michael Kelley
Quoted 11 lines
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 4 lines
Generalize Synthetic interrupt source vector (sint) to use
vmbus_interruptvariable instead, which automatically takes care of architectures whereHYPERVISOR_CALLBACK_VECTORis not present (arm64).Sashiko AI raised an interesting question about the startup timing -- whether the
vmbus_platform_driver_probe()is guaranteed to have setvmbus_interruptbefore the VTL functions below run and use it. What causes the mshv_vtl.ko module to be loaded, and hence runmshv_vtl_init()?There is no race condition here. The init ordering guarantees that
vmbus_interruptis always set beforemshv_vtl_synic_enable_regs()reads it.The call chain for setting
vmbus_interrupt:
subsys_initcall(hv_acpi_init)[level 4]-> platform_driver_register(&vmbus_platform_driver) and so on.The call chain for reading
vmbus_interrupt:module_init(mshv_vtl_init) [level 6] -> hv_vtl_setup_synic() -> cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, ..., mshv_vtl_alloc_context, ...) -> mshv_vtl_alloc_context() -> mshv_vtl_synic_enable_regs() -> sint.vector = vmbus_interrupt
Quoted 4 lines
do_initcalls()processes sections in order 0 through 7, sohv_acpi_init()(level 4) is guaranteed to complete beforemshv_vtl_init()(level 6) runs.
I think the situation is more complex than what you describe, depending on whether the VMBus driver and/or MSHV_VTL are built as modules vs. being built-in to the kernel image. In include/linux/module.h, see the comment for module_init() and how subsys_initcall() is mapped to module_init() when built as a module.
If both are built-in, then what you describe is correct. But if either or both are modules, then the respective init functions (hv_acpi_init and mshv_vtl_init) get called at the time the module is loaded, and not by do_initcalls(). I think hv_vmbus.ko gets loaded when an attempt is first made to access a disk, but I would need to look more closely to be sure. I don't have any understanding of what causes mshv_vtl.ko to be loaded. And what is the ordering if MSHV_VTL is built-in while VMBus is built as a module, or vice versa?
Michael
Re: [PATCH 06/11] Drivers: hv: Make sint vector architecture neutral in MSHV_VTL
Quoted 54 lines · Michael Kelley
From: Naman Jain <[email protected]> Sent: Monday, April 13, 2026 4:48 AM
Quoted 33 lines · Michael Kelley
Quoted 11 lines
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 4 lines
Generalize Synthetic interrupt source vector (sint) to use
vmbus_interruptvariable instead, which automatically takes care of architectures whereHYPERVISOR_CALLBACK_VECTORis not present (arm64).Sashiko AI raised an interesting question about the startup timing -- whether the
vmbus_platform_driver_probe()is guaranteed to have setvmbus_interruptbefore the VTL functions below run and use it. What causes the mshv_vtl.ko module to be loaded, and hence runmshv_vtl_init()?There is no race condition here. The init ordering guarantees that
vmbus_interruptis always set beforemshv_vtl_synic_enable_regs()reads it.The call chain for setting
vmbus_interrupt:
subsys_initcall(hv_acpi_init)[level 4]
->platform_driver_register(&vmbus_platform_driver)and so on.The call chain for reading
vmbus_interrupt:module_init(mshv_vtl_init) [level 6] -> hv_vtl_setup_synic() -> cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, ..., mshv_vtl_alloc_context, ...) -> mshv_vtl_alloc_context() -> mshv_vtl_synic_enable_regs() -> sint.vector = vmbus_interruptQuoted 4 lines
do_initcalls()processes sections in order 0 through 7, sohv_acpi_init()(level 4) is guaranteed to complete beforemshv_vtl_init()(level 6) runs.I think the situation is more complex than what you describe, depending on whether the VMBus driver and/or
MSHV_VTLare built as modules vs. being built-in to the kernel image. Ininclude/linux/module.h, see the comment formodule_init()and howsubsys_initcall()is mapped tomodule_init()when built as a module.If both are built-in, then what you describe is correct. But if either or both are modules, then the respective init functions (
hv_acpi_initandmshv_vtl_init) get called at the time the module is loaded, and not bydo_initcalls(). I think hv_vmbus.ko gets loaded when an attempt is first made to access a disk, but I would need to look more closely to be sure. I don't have any understanding of what causes mshv_vtl.ko to be loaded. And what is the ordering ifMSHV_VTLis built-in while VMBus is built as a module, or vice versa?
Quoted 2 lines
Michael
Based on this, I still feel that this race is not possible.
hv_vmbus mshv_vtl
y y -> different initcall levels, no issues y m -> use without initialization is not possible m y -> config dependencies take care of this, and mshv_vtl
is forced to compile as a module in this case.
m m -> config and symbol dependencies should take care of
it. mshv_vtl has symbol and config dependencies on hv_vmbus, and it won't allow loading mshv_vtl if hv_vmbus module is not loaded.
Relevant code here: kernel/module/main.c
Regards,
Naman
Re: [PATCH 07/11] arch: arm64: Add support for mshv_vtl_return_call
In reply to Michael KelleyQuoted 4 lines · Michael Kelley
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 1 line
Nit: For historical consistency, use "arm64: hyperv:" as the prefix in the patch Subject.
Acked.
Quoted 6 lines
Quoted 5 lines
Add support for arm64 specific variant of
mshv_vtl_return_callfunction to be able to add support for arm64 inMSHV_VTLdriver. This would help enable the transition between Virtual Trust Levels (VTL) inMSHV_VTLwhen the kernel acts as a paravisor.
Quoted 6 lines
This commit message has a fair number of "filler" words. Suggest simplifying to:
Add the arm64 variant of
mshv_vtl_return_call()to support theMSHV_VTLdriver on arm64. This function enables the transition between Virtual Trust Levels (VTLs) inMSHV_VTLwhen the kernel acts as a paravisor.
I can see the difference clearly :-) Will use this in commit message.
Quoted 49 lines
Quoted 49 lines
Signed-off-by Roman Kisel <[email protected]>Signed-off-by Naman Jain <[email protected]>--- arch/arm64/hyperv/Makefile | 1 + arch/arm64/hyperv/hv_vtl.c | 144 ++++++++++++++++++++++++++++++ arch/arm64/include/asm/mshyperv.h | 13 +++ 3 files changed, 158 insertions(+)create mode 100644
arch/arm64/hyperv/hv_vtl.carch/arm64/hyperv/Makefile +1
-0@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 obj-y := hv_core.o mshyperv.o +obj-$(CONFIG_HYPERV_VTL_MODE) += hv_vtl.oarch/arm64/hyperv/hv_vtl.c new file +25
-0@@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2026, Microsoft, Inc. +* +* Authors: +* Roman Kisel <[email protected]> +* Naman Jain <[email protected]> +*/ + +#include <asm/boot.h> +#include <asm/mshyperv.h> +#include <asm/cpu_ops.h> + +void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) +{ +u64 base_ptr = (u64 )vtl0->x; + +/* +* VTL switch for ARM64 platform - managing VTL0's CPU context. +* We explicitly use the stack to save the base pointer, and use x16 +* as our working register for accessing the context structure. +* +* Register Handling: +* - X0-X17: Saved/restored (general-purpose, shared for VTL communication) +* - X18: NOT touched - hypervisor-managed per-VTL (platform register)
Quoted 8 lines
arch/arm64/hyperv/hv_vtl.c line 31
Quoted 6 lines
arch/arm64/hyperv/hv_vtl.c new file +6
-0+* - X19-X30: Saved/restored (part of VTL0's execution context) +* - Q0-Q31: Saved/restored (128-bit NEON/floating-point registers, shared) +* - SP: Not in structure, hypervisor-managed per-VTL +* +* Note: X29 (FP) and X30 (LR) are in the structure and must be saved/restored +* as part of VTL0's complete execution state. Could drop "Note:". That's what comments are. :-)
Acked.
Quoted 11 lines
arch/arm64/hyperv/hv_vtl.c line 39
Quoted 10 lines
arch/arm64/hyperv/hv_vtl.c new file +8
-0+*/ + asm __volatile__ ( +/* Save base pointer to stack explicitly, then load into x16 */ +"str %0, [sp, #-16]!\n\t" /* Push base pointer onto stack */ +"mov x16, %0\n\t" /* Load base pointer into x16 */ +/* Volatile registers (Windows ARM64 ABI: x0-x15) */ +"ldp x0, x1, [x16]\n\t" + "ldp x2, x3, [x16, #(2*8)]\n\t"
Quoted 8 lines
On the x86 side, there's machinery to generate a series of constants that are the offsets of the individual fields in struct
mshv_vtl_cpu_context. The x86 asm code then uses these constants. Here on the arm64 side, you've calculated the offsets directly in the asm code. Any reason for the difference? I can see it's fairly easy to eyeball the offsets here and compare against the registers that are being loaded, where it's not so easy the way registers are named on x86. So maybe the additional machinery that's helpful on the x86 side is less necessary here. Just wondering ....
There were complexities around static call etc. in x86 which led to that redesign. Here things are much simpler and the offsets we see are 1-1 mapped to registers. But I still tried to prototype it, and it looked more complex than it has to be. I think we can keep it in current form.
Quoted 114 lines
Quoted 114 lines
arch/arm64/hyperv/hv_vtl.c new file +105
-0+"ldp x4, x5, [x16, #(4*8)]\n\t" +"ldp x6, x7, [x16, #(6*8)]\n\t" +"ldp x8, x9, [x16, #(8*8)]\n\t" +"ldp x10, x11, [x16, #(10*8)]\n\t" +"ldp x12, x13, [x16, #(12*8)]\n\t" +"ldp x14, x15, [x16, #(14*8)]\n\t" +/* x16 will be loaded last, after saving base pointer */ +"ldr x17, [x16, #(17*8)]\n\t" +/* x18 is hypervisor-managed per-VTL - DO NOT LOAD */ + +/* General-purpose registers: x19-x30 */ +"ldp x19, x20, [x16, #(19*8)]\n\t" +"ldp x21, x22, [x16, #(21*8)]\n\t" +"ldp x23, x24, [x16, #(23*8)]\n\t" +"ldp x25, x26, [x16, #(25*8)]\n\t" +"ldp x27, x28, [x16, #(27*8)]\n\t" + +/* Frame pointer and link register */ +"ldp x29, x30, [x16, #(29*8)]\n\t" + +/* Shared NEON/FP registers: Q0-Q31 (128-bit) */ +"ldp q0, q1, [x16, #(32*8)]\n\t" +"ldp q2, q3, [x16, #(32*8 + 2*16)]\n\t" +"ldp q4, q5, [x16, #(32*8 + 4*16)]\n\t" +"ldp q6, q7, [x16, #(32*8 + 6*16)]\n\t" +"ldp q8, q9, [x16, #(32*8 + 8*16)]\n\t" +"ldp q10, q11, [x16, #(32*8 + 10*16)]\n\t" +"ldp q12, q13, [x16, #(32*8 + 12*16)]\n\t" +"ldp q14, q15, [x16, #(32*8 + 14*16)]\n\t" +"ldp q16, q17, [x16, #(32*8 + 16*16)]\n\t" +"ldp q18, q19, [x16, #(32*8 + 18*16)]\n\t" +"ldp q20, q21, [x16, #(32*8 + 20*16)]\n\t" +"ldp q22, q23, [x16, #(32*8 + 22*16)]\n\t" +"ldp q24, q25, [x16, #(32*8 + 24*16)]\n\t" +"ldp q26, q27, [x16, #(32*8 + 26*16)]\n\t" +"ldp q28, q29, [x16, #(32*8 + 28*16)]\n\t" +"ldp q30, q31, [x16, #(32*8 + 30*16)]\n\t" + +/* Now load x16 itself */ +"ldr x16, [x16, #(16*8)]\n\t" + +/* Return to the lower VTL */ +"hvc #3\n\t" + +/* Save context after return - reload base pointer from stack */ +"stp x16, x17, [sp, #-16]!\n\t" /* Save x16, x17 temporarily */ +"ldr x16, [sp, #16]\n\t" /* Reload base pointer (skip saved x16,x17) */ + +/* Volatile registers */ +"stp x0, x1, [x16]\n\t" +"stp x2, x3, [x16, #(2*8)]\n\t" +"stp x4, x5, [x16, #(4*8)]\n\t" +"stp x6, x7, [x16, #(6*8)]\n\t" +"stp x8, x9, [x16, #(8*8)]\n\t" +"stp x10, x11, [x16, #(10*8)]\n\t" +"stp x12, x13, [x16, #(12*8)]\n\t" +"stp x14, x15, [x16, #(14*8)]\n\t" +"ldp x0, x1, [sp], #16\n\t" /* Recover saved x16, x17 */ +"stp x0, x1, [x16, #(16*8)]\n\t" +/* x18 is hypervisor-managed - DO NOT SAVE */ + +/* General-purpose registers: x19-x30 */ +"stp x19, x20, [x16, #(19*8)]\n\t" +"stp x21, x22, [x16, #(21*8)]\n\t" +"stp x23, x24, [x16, #(23*8)]\n\t" +"stp x25, x26, [x16, #(25*8)]\n\t" +"stp x27, x28, [x16, #(27*8)]\n\t" +"stp x29, x30, [x16, #(29*8)]\n\t" /* Frame pointer and link register */ + +/* Shared NEON/FP registers: Q0-Q31 (128-bit) */ +"stp q0, q1, [x16, #(32*8)]\n\t" +"stp q2, q3, [x16, #(32*8 + 2*16)]\n\t" +"stp q4, q5, [x16, #(32*8 + 4*16)]\n\t" +"stp q6, q7, [x16, #(32*8 + 6*16)]\n\t" +"stp q8, q9, [x16, #(32*8 + 8*16)]\n\t" +"stp q10, q11, [x16, #(32*8 + 10*16)]\n\t" +"stp q12, q13, [x16, #(32*8 + 12*16)]\n\t" +"stp q14, q15, [x16, #(32*8 + 14*16)]\n\t" +"stp q16, q17, [x16, #(32*8 + 16*16)]\n\t" +"stp q18, q19, [x16, #(32*8 + 18*16)]\n\t" +"stp q20, q21, [x16, #(32*8 + 20*16)]\n\t" +"stp q22, q23, [x16, #(32*8 + 22*16)]\n\t" +"stp q24, q25, [x16, #(32*8 + 24*16)]\n\t" +"stp q26, q27, [x16, #(32*8 + 26*16)]\n\t" +"stp q28, q29, [x16, #(32*8 + 28*16)]\n\t" +"stp q30, q31, [x16, #(32*8 + 30*16)]\n\t" + +/* Clean up stack - pop base pointer */ +"add sp, sp, #16\n\t" + + : /* No outputs */ + : /* Input */ "r"(base_ptr) + : /* Clobber list - x16 used as base, x18 is hypervisor-managed (not touched) */ + "memory", "cc", +"x0" ,"x1" ,"x2" ,"x3" ,"x4" ,"x5" , +"x6" ,"x7" ,"x8" ,"x9" ,"x10" ,"x11" ,"x12" ,"x13" , +"x14" ,"x15" ,"x16" ,"x17" ,"x19" ,"x20" ,"x21" , +"x22" ,"x23" ,"x24" ,"x25" ,"x26" ,"x27" ,"x28" , +"x29" ,"x30" , +"v0" ,"v1" ,"v2" ,"v3" ,"v4" ,"v5" ,"v6" ,"v7" , +"v8" ,"v9" ,"v10" ,"v11" ,"v12" ,"v13" ,"v14" ,"v15" , +"v16" ,"v17" ,"v18" ,"v19" ,"v20" ,"v21" ,"v22" ,"v23" , + "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"); +} +EXPORT_SYMBOL (mshv_vtl_return_call);arch/arm64/include/asm/mshyperv.h +0
-0@@ -60,6 +60,17 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg)ARM_SMCCC_SMC_64 , \ ARM_SMCCC_OWNER_VENDOR_HYP, \
Quoted 9 lines
arch/arm64/include/asm/mshyperv.h static inline u64 hv_get_non_nested_msr(unsigned int reg) · line 67
Quoted 6 lines
arch/arm64/include/asm/mshyperv.h +5
-0HV_SMCCC_FUNC_NUMBER) + +struct mshv_vtl_cpu_context { +/* +* NOTE: x18 is managed by the hypervisor. It won't be reloaded from this array. +* It is included here for convenience in the common case. I'm not getting your point in this last sentence. What is the "common case"?
This was really odd :-) I should have spotted it. I'll change it to:
It is included here for convenience in array indexing.
Quoted 1 line
You could also drop the "NOTE: " prefix.
Acked.
Quoted 11 lines
arch/arm64/include/asm/mshyperv.h static inline u64 hv_get_non_nested_msr(unsigned int reg) · line 72
Quoted 6 lines
arch/arm64/include/asm/mshyperv.h +5
-0+*/ +__u64 x[31 ]; +__u64 rsvd; +__uint128_t q[32 ]; +};struct
mshv_vtl_runreserves 1024 bytes forcpu_context. It would be nice to have a compile-time check that the size of structmshv_vtl_cpu_contextfits in that 1024 bytes. That check might be better added where structmshv_vtl_runis defined so that it works for both x86 and arm64.
Acked, will add it.
Quoted 16 lines
arch/arm64/include/asm/mshyperv.h static inline int hv_vtl_get_set_reg(struct hv_register_assoc *regs, bool set, u · line 84
Quoted 11 lines
arch/arm64/include/asm/mshyperv.h +3
-0+#ifdef CONFIG_HYPERV_VTL_MODE /* * Get/Set the register. If the function returns `1`, that must be done via @@ -69,6 +80,8 @@ static inline int hv_vtl_get_set_reg(struct hv_register_assoc *regs, bool set, u {return 1 ; } + +void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0);This declaration now duplicated in
mshyperv.hunderarch/arm64and underarch/x86. Instead, it should be added toasm-generic/mshyperv.h, and removed from thearch/x86mshyperv.h, so that there's only a single instance of the declaration.
Acked.
Quoted 7 lines
Quoted 7 lines
arch/arm64/include/asm/mshyperv.h +0
-1#endif #include <asm-generic/mshyperv.h> --2.43.0
Regards,
Naman
RE: [PATCH 06/11] Drivers: hv: Make sint vector architecture neutral in MSHV_VTL
In reply to Naman JainFrom: Naman Jain <[email protected]> Sent: Monday, April 13, 2026 9:52 AM
Quoted 57 lines
Quoted 46 lines
Quoted 26 lines
Quoted 6 lines
Sashiko AI raised an interesting question about the startup timing -- whether the
vmbus_platform_driver_probe()is guaranteed to have setvmbus_interruptbefore the VTL functions below run and use it. What causes the mshv_vtl.ko module to be loaded, and hence runmshv_vtl_init()?There is no race condition here. The init ordering guarantees that
vmbus_interruptis always set beforemshv_vtl_synic_enable_regs()reads it.The call chain for setting
vmbus_interrupt:
subsys_initcall(hv_acpi_init)[level 4]
->platform_driver_register(&vmbus_platform_driver)and so on.The call chain for reading
vmbus_interrupt:module_init(mshv_vtl_init) [level 6] -> hv_vtl_setup_synic() -> cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, ..., mshv_vtl_alloc_context, ...) -> mshv_vtl_alloc_context() -> mshv_vtl_synic_enable_regs() -> sint.vector = vmbus_interruptQuoted 4 lines
do_initcalls()processes sections in order 0 through 7, sohv_acpi_init()(level 4) is guaranteed to complete beforemshv_vtl_init()(level 6) runs.I think the situation is more complex than what you describe, depending on whether the VMBus driver and/or
MSHV_VTLare built as modules vs. being built-in to the kernel image. Ininclude/linux/module.h, see the comment formodule_init()and howsubsys_initcall()is mapped tomodule_init()when built as a module.If both are built-in, then what you describe is correct. But if either or both are modules, then the respective init functions (
hv_acpi_initandmshv_vtl_init) get called at the time the module is loaded, and not bydo_initcalls(). I think hv_vmbus.ko gets loaded when an attempt is first made to access a disk, but I would need to look more closely to be sure. I don't have any understanding of what causes mshv_vtl.ko to be loaded. And what is the ordering ifMSHV_VTLis built-in while VMBus is built as a module, or vice versa?Quoted 2 lines
Michael
Based on this, I still feel that this race is not possible.
hv_vmbusmshv_vtly y -> different initcall levels, no issues y m -> use without initialization is not possible m y -> config dependencies take care of this, and mshv_vtl is forced to compile as a module in this case. m m -> config and symbol dependencies should take care of
Quoted 5 lines
it.
mshv_vtlhas symbol and config dependencies onhv_vmbus, and it won't allow loadingmshv_vtlifhv_vmbusmodule is not loaded.Relevant code here:
kernel/module/main.c
Makes sense. I'm convinced! :-)
Michael
Re: [PATCH 02/11] Drivers: hv: Move hv_vp_assist_page to common files
In reply to Michael KelleyQuoted 173 lines · Michael Kelley
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 162 lines
Move the logic to initialize and export
hv_vp_assist_pagefrom x86 architecture code to Hyper-V common code to allow it to be used for upcoming arm64 support inMSHV_VTLdriver.
Note: This change also improves error handling - if VP assist page allocation fails,hyperv_init()now returns early instead of continuing with partial initialization.Signed-off-by Roman Kisel <[email protected]>Signed-off-by Naman Jain <[email protected]>--- arch/x86/hyperv/hv_init.c | 88 +--------------------------------- drivers/hv/hv_common.c | 88 ++++++++++++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 4 ++ include/hyperv/hvgdk_mini.h | 2 + 4 files changed, 95 insertions(+), 87 deletions(-)arch/x86/hyperv/hv_init.c +1
-87@@ -81,9 +81,6 @@ union hv_ghcb * __percpu *hv_ghcb_pg;/* Storage to save the hypercall page temporarily for hibernation */ static void *hv_hypercall_pg_saved; -struct hv_vp_assist_page **hv_vp_assist_page; -EXPORT_SYMBOL_GPL (hv_vp_assist_page); -static int hyperv_init_ghcb (void ) {u64 ghcb_gpa;@@ -117,59 +114,12 @@ static int hyperv_init_ghcb(void)static int hv_cpu_init (unsigned int cpu) { -union hv_vp_assist_msr_contents msr = {0 }; -struct hv_vp_assist_page **hvp;int ret; ret =hv_common_cpu_init (cpu);if (ret)return ret; -if (!hv_vp_assist_page) -return 0 ; - - hvp = &hv_vp_assist_page[cpu]; -if (hv_root_partition ()) { -/* -* For root partition we get the hypervisor provided VP assist -* page, instead of allocating a new page. -*/ -rdmsrq (HV_X64_MSR_VP_ASSIST_PAGE , msr.as_uint64); - *hvp =memremap (msr.pfn <<HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT , -PAGE_SIZE ,MEMREMAP_WB ); - }else { -/* -* The VP assist page is an "overlay" page (see Hyper-V TLFS's -* Section 5.2.1 "GPA Overlay Pages"). Here it must be zeroed -* out to make sure we always write the EOI MSR in -* hv_apic_eoi_write() *after* the EOI optimization is disabled -* in hv_cpu_die(), otherwise a CPU may not be stopped in the -* case of CPU offlining and the VM will hang. -*/ -if (!*hvp) { - *hvp =__vmalloc (PAGE_SIZE ,GFP_KERNEL | __GFP_ZERO); - -/* -* Hyper-V should never specify a VM that is a Confidential -* VM and also running in the root partition. Root partition -* is blocked to run in Confidential VM. So only decrypt assist -* page in non-root partition here. -*/ -if (*hvp && !ms_hyperv.paravisor_present &&hv_isolation_type_snp ()) { -WARN_ON_ONCE (set_memory_decrypted ((unsigned long )(*hvp),1 )); -memset (*hvp,0 ,PAGE_SIZE ); - } - } - -if (*hvp) - msr.pfn =vmalloc_to_pfn (*hvp); - - } -if (!WARN_ON (!(*hvp))) { - msr.enable =1 ; -wrmsrq (HV_X64_MSR_VP_ASSIST_PAGE , msr.as_uint64); - } -/* Allow Hyper-V stimer vector to be injected from Hypervisor. */ if (ms_hyperv.misc_features &HV_STIMER_DIRECT_MODE_AVAILABLE )apic_update_vector (cpu,HYPERV_STIMER0_VECTOR , true);@@ -286,23 +236,6 @@ static int hv_cpu_die(unsigned int cpu)hv_common_cpu_die (cpu); -if (hv_vp_assist_page && hv_vp_assist_page[cpu]) { -union hv_vp_assist_msr_contents msr = {0 }; -if (hv_root_partition ()) { -/* -* For root partition the VP assist page is mapped to -* hypervisor provided page, and thus we unmap the -* page here and nullify it, so that in future we have -* correct page address mapped in hv_cpu_init. -*/ -memunmap (hv_vp_assist_page[cpu]); - hv_vp_assist_page[cpu] =NULL ; -rdmsrq (HV_X64_MSR_VP_ASSIST_PAGE , msr.as_uint64); - msr.enable =0 ; - } -wrmsrq (HV_X64_MSR_VP_ASSIST_PAGE , msr.as_uint64); - } -if (hv_reenlightenment_cb ==NULL )return 0 ;@@ -460,21 +393,6 @@ void __init hyperv_init(void)if (hv_common_init ())return ; -/* -* The VP assist page is useless to a TDX guest: the only use we -* would have for it is lazy EOI, which can not be used with TDX. -*/ -if (hv_isolation_type_tdx ()) - hv_vp_assist_page =NULL ; -else - hv_vp_assist_page =kzalloc_objs (*hv_vp_assist_page, nr_cpu_ids); -if (!hv_vp_assist_page) { - ms_hyperv.hints &= ~HV_X64_ENLIGHTENED_VMCS_RECOMMENDED ; - -if (!hv_isolation_type_tdx ()) - goto common_free; - } -if (ms_hyperv.paravisor_present &&hv_isolation_type_snp ()) {/* Negotiate GHCB Version. */ if (!hv_ghcb_negotiate_protocol ())@@ -483,7 +401,7 @@ void __init hyperv_init(void) hv_ghcb_pg = alloc_percpu(union hv_ghcb *);if (!hv_ghcb_pg) - goto free_vp_assist_page; + goto free_ghcb_page; } cpuhp = cpuhp_setup_state(CPUHP_AP_HYPERV_ONLINE, "x86/hyperv_init:online",@@ -613,10 +531,6 @@ void __init hyperv_init(void)cpuhp_remove_state (CPUHP_AP_HYPERV_ONLINE ); free_ghcb_page:free_percpu (hv_ghcb_pg); -free_vp_assist_page: -kfree (hv_vp_assist_page); - hv_vp_assist_page =NULL ; -common_free:hv_common_free (); }drivers/hv/hv_common.c +0
-0drivers/hv/hv_common.c line 34
Quoted 7 lines
drivers/hv/hv_common.c +2
-0@@ -28,7 +28,9 @@#include <linux/slab.h> #include <linux/dma-map-ops.h> #include <linux/set_memory.h> +#include <linux/vmalloc.h> #include <hyperv/hvhdk.h> +#include <hyperv/hvgdk.h> #include <asm/mshyperv.h> Need to add
Quoted 6 lines
#include <
linux/io.h>because of the
memremap()and related calls that have been added.io.his probably being #include'd indirectly, but it is better to #include it directly.
Acked.
Quoted 37 lines
Quoted 37 lines
drivers/hv/hv_common.c +17
-0u64 hv_current_partition_id =HV_PARTITION_ID_SELF ;@@ -78,6 +80,8 @@ static struct ctl_table_header *hv_ctl_table_hdr;u8 *__percpu *hv_synic_eventring_tail;EXPORT_SYMBOL_GPL (hv_synic_eventring_tail); +struct hv_vp_assist_page **hv_vp_assist_page; +EXPORT_SYMBOL_GPL (hv_vp_assist_page);/* * Hyper-V specific initialization and shutdown code that is * common across all architectures. Called from architecture @@ -92,6 +96,9 @@ void __init hv_common_free(void)if (ms_hyperv.misc_features &HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE )hv_kmsg_dump_unregister (); +kfree (hv_vp_assist_page); + hv_vp_assist_page =NULL ; +kfree (hv_vp_index); hv_vp_index =NULL ;@@ -394,6 +401,23 @@ int __init hv_common_init(void)for (i =0 ; i < nr_cpu_ids; i++) hv_vp_index[i] =VP_INVAL ; +/* +* The VP assist page is useless to a TDX guest: the only use we +* would have for it is lazy EOI, which can not be used with TDX. +*/ +if (hv_isolation_type_tdx ()) { + hv_vp_assist_page =NULL ; + }else { + hv_vp_assist_page =kzalloc_objs (*hv_vp_assist_page, nr_cpu_ids); +if (!hv_vp_assist_page) { +#ifdef CONFIG_X86_64 + ms_hyperv.hints &= ~HV_X64_ENLIGHTENED_VMCS_RECOMMENDED ; +#endif
Quoted 8 lines
drivers/hv/hv_common.c int __init hv_common_init(void) · line 417
Quoted 2 lines
drivers/hv/hv_common.c +2
-0+hv_common_free (); +return -ENOMEM ;Given that "failure to allocate memory" now returns an error that is essentially fatal to
hyperv_init(), is it still necessary to clear the flag in ms_hyperv.hints? I'd love to see that #ifdef go away. It's the only #ifdef inhv_common.c, and I had worked hard in the past to avoid such #ifdef's. :-)
Yes, this particular block can be removed, and I will remove it in v2.
The other thing pointed out in Sashiko's AI review was having this if-def block in tdx case after setting hv_vp_assist_page to NULL. This is to maintain parity with existing code. That's the reason, I will need to add it back there.
Quoted 9 lines
Quoted 9 lines
drivers/hv/hv_common.c +3
-0+ } + } +return 0 ; }@@ -471,6 +495,8 @@ void __init ms_hyperv_late_init(void)
Quoted 13 lines
drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 568
Quoted 9 lines
drivers/hv/hv_common.c +2
-0int hv_common_cpu_init (unsigned int cpu) { +union hv_vp_assist_msr_contents msr = {0 }; +struct hv_vp_assist_page **hvp;void **inputarg, **outputarg;u8 **synic_eventring_tail;u64 msr_vp_index;@@ -542,6 +568,50 @@ int hv_common_cpu_init(unsigned int cpu) ret = -ENOMEM ;The Sashiko AI comment here about a bug when ret is set to
-ENOMEMseems valid to me.
I'm planning to simply "return -ENOMEM" here.
Quoted 19 lines
Quoted 4 lines
drivers/hv/hv_common.c +2
-0} +if (!hv_vp_assist_page) +return ret;drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 582
Quoted 10 lines
drivers/hv/hv_common.c +10
-0+ + hvp = &hv_vp_assist_page[cpu]; +if (hv_root_partition ()) { +/* +* For root partition we get the hypervisor provided VP assist +* page, instead of allocating a new page. +*/ + msr.as_uint64 =hv_get_msr (HV_SYN_REG_VP_ASSIST_PAGE ); + *hvp =memremap (msr.pfn <<HV_VP_ASSIST_PAGE_ADDRESS_SHIFT , +PAGE_SIZE ,MEMREMAP_WB );The Sashiko AI comment about potentially memremap'ing 64K instead of 4K can be ignored. We know that the root partition can only run with a 4K page size, and that is enforced in
drivers/hv/Kconfig.
I am thinking of adding this config dependency (PAGE_SIZE_4KB) in the Kconfig patch in this series, to MSHV_VTL as well. We are also using only 4KB as page size. This should prevent all of PAGE_SIZE Sachiko issues. I am also replacing PAGE_SIZE with HV_HYP_PAGE_SIZE in all places. Hope that is fine?
Quoted 3 lines
HV_VP_ASSIST_PAGE_ADDRESS_SHIFTis defined inasm-generic/mshyperv.h. But there is alsoHV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFTinhvgdk_mini.h. Is there a clean way to eliminate the duplication?
Although both these architectures are using same value - 12, I was hesitant to use x64 register for ARM64. I will move arch based definition of HV_VP_ASSIST_PAGE_ADDRESS_SHIFT to hvgdk_mini.h and remove it from asm-generic/mshyperv.h.
Quoted 15 lines
drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 591
Quoted 10 lines
drivers/hv/hv_common.c +9
-0+ }else { +/* +* The VP assist page is an "overlay" page (see Hyper-V TLFS's +* Section 5.2.1 "GPA Overlay Pages"). Here it must be zeroed +* out to make sure we always write the EOI MSR in +* hv_apic_eoi_write() *after* the EOI optimization is disabled +* in hv_cpu_die(), otherwise a CPU may not be stopped in the +* case of CPU offlining and the VM will hang. +*/ Somewhere in the comment above, I'd suggest adding a short "on x86/x64" qualifier, as the comment doesn't apply on arm64 since it doesn't support the AutoEOI optimization. Maybe "Here it must be zeroed out to make sure that on x86/x64 we always write the EOI MSR in ....".
Acked. I will add it.
Quoted 5 lines
drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 593
Quoted 3 lines
drivers/hv/hv_common.c +2
-0+if (!*hvp) { + *hvp =__vmalloc (PAGE_SIZE ,GFP_KERNEL | __GFP_ZERO);The Sashiko AI comment about using "flags" instead of
GFP_KERNELseems valid.
Acked.
Quoted 15 lines
Quoted 15 lines
drivers/hv/hv_common.c +14
-0+ +/* +* Hyper-V should never specify a VM that is a Confidential +* VM and also running in the root partition. Root partition +* is blocked to run in Confidential VM. So only decrypt assist +* page in non-root partition here. +*/ +if (*hvp && !ms_hyperv.paravisor_present &&hv_isolation_type_snp ()) { +WARN_ON_ONCE (set_memory_decrypted ((unsigned long )(*hvp),1 )); +memset (*hvp,0 ,PAGE_SIZE ); + } + } + +if (*hvp)
Quoted 9 lines
drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 608
Quoted 1 line
drivers/hv/hv_common.c +1
-0+ msr.pfn =vmalloc_to_pfn (*hvp);The Sashiko AI comment about page size here seems valid. But what are the rules about arm64 page sizes that are supported for VTL2, and how does they relate to VTL0 allowing 4K, 16K, and 64K page size? What combinations are allowed? For example, can a VTL2 built with 4K page size run with a VTL0 built with 64K page size? It would be nice to have the rules recorded somewhere in a code comment, but I'm not sure of the best place.
VTL2 uses 4k page size only. This can be enforced with a Kconfig change in next version. As and when other page size support is added in ARM64 for MSHV_VTL, this change can be removed.
Regarding support of VTL0 kernel page sizes, page size in VTL2 is of no impact to it.
Quoted 3 lines
But regardless of the rules, I'd suggest future-proofing by using "page_to_hvpfn(vmalloc_to_page(*hvp))" so that the PFN generated is always in terms of 4K page size as the Hyper-V host expects.
Acked. Will try this and make the changes.
Quoted 56 lines
Quoted 48 lines
drivers/hv/hv_common.c +24
-0+ } +if (!WARN_ON (!(*hvp))) { + msr.enable =1 ; +hv_set_msr (HV_SYN_REG_VP_ASSIST_PAGE , msr.as_uint64); + } +return ret; }@@ -566,6 +636,24 @@ int hv_common_cpu_die(unsigned int cpu) *synic_eventring_tail =NULL ; } +if (hv_vp_assist_page && hv_vp_assist_page[cpu]) { +union hv_vp_assist_msr_contents msr = {0 }; + +if (hv_root_partition ()) { +/* +* For root partition the VP assist page is mapped to +* hypervisor provided page, and thus we unmap the +* page here and nullify it, so that in future we have +* correct page address mapped in hv_cpu_init. +*/ +memunmap (hv_vp_assist_page[cpu]); + hv_vp_assist_page[cpu] =NULL ; + msr.as_uint64 =hv_get_msr (HV_SYN_REG_VP_ASSIST_PAGE ); + msr.enable =0 ; + } +hv_set_msr (HV_SYN_REG_VP_ASSIST_PAGE , msr.as_uint64); + } +return 0 ; }include/asm-generic/mshyperv.h +1
-0@@ -25,6 +25,7 @@#include <linux/nmi.h> #include <asm/ptrace.h> #include <hyperv/hvhdk.h> +#include <hyperv/hvgdk.h> #define VTPM_BASE_ADDRESS 0xfed40000include/asm-generic/mshyperv.h do { \ · line 303
Quoted 4 lines
include/asm-generic/mshyperv.h +1
-0@@ -299,6 +300,8 @@ do { \#define hv_status_debug (status, fmt, ...) \ hv_status_printk(debug, status, fmt, ##__VA_ARGS__) +extern struct hv_vp_assist_page **hv_vp_assist_page;This "extern" statement is added here so it is visible to both x86/x64 and arm64. And that's correct.
Quoted 5 lines
But there is still some VP assist page stuff that has been left in the
arch/x86version ofmshyperv.h. That other stuff, including the inline functionhv_get_vp_assist_page(), should also be moved toasm-generic/mshyperv.h. Given that the VP assist page support is now fully generic and not x86/x64 specific, it shouldn't occur anywhere in thearch/x86version ofmshyperv.h.
Will move the remaining code.
Quoted 27 lines
Quoted 27 lines
include/asm-generic/mshyperv.h +2
-0+const char *hv_result_to_string (u64 hv_status);int hv_result_to_errno (u64 status);void hyperv_report_panic (struct pt_regs *regs,long err,bool in_die);@@ -377,6 +380,7 @@ static inline int hv_deposit_memory(u64 partition_id, u64 status)return hv_deposit_memory_node (NUMA_NO_NODE , partition_id, status); } +#define HV_VP_ASSIST_PAGE_ADDRESS_SHIFT 12#if IS_ENABLED (CONFIG_HYPERV_VTL_MODE )u8 __init get_vtl (void );#else include/hyperv/hvgdk_mini.h +1
-0@@ -149,6 +149,7 @@ struct hv_u128 {#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT 12#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_MASK \ (~((1ull << HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT) - 1)) +#define HV_SYN_REG_VP_ASSIST_PAGE (HV_X64_MSR_VP_ASSIST_PAGE)/* Hyper-V Enlightened VMCS version mask in nested features CPUID */ #define HV_X64_ENLIGHTENED_VMCS_VERSION 0xff@@ -1185,6 +1186,7 @@ enum hv_register_name {
Quoted 11 lines
include/hyperv/hvgdk_mini.h enum hv_register_name { · line 1189
Quoted 3 lines
include/hyperv/hvgdk_mini.h +1
-0#define HV_MSR_STIMER0_CONFIG (HV_REGISTER_STIMER0_CONFIG)#define HV_MSR_STIMER0_COUNT (HV_REGISTER_STIMER0_COUNT) +#define HV_SYN_REG_VP_ASSIST_PAGE (HV_REGISTER_VP_ASSIST_PAGE)This defines a new register name prefix "
HV_SYN_REG_" that isn't used anywhere else. The prefixes for Hyper-V register names are already complex to account to x86/x64 and arm64 differences, and the fact the x86/x64 has synthetic MSRs, while arm64 does not. So introducing another prefix is undesirable. Couldn't this just beHV_MSR_VP_ASSIST_PAGEusing the same structure asHV_MSR_STIMER0_COUNT(for example)?
Will rename it to HV_MSR_VP_ASSIST_PAGE in all places.
Quoted 6 lines
Quoted 6 lines
include/hyperv/hvgdk_mini.h +0
-1#endif /* CONFIG_ARM64 */ --2.43.0
Thank you so much for thoroughly reviwing this Michael.
Regards,
Naman
Re: [PATCH 08/11] Drivers: hv: mshv_vtl: Move register page config to arch-specific files
In reply to Michael KelleyQuoted 15 lines · Michael Kelley
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 14 lines
Move
mshv_vtl_configure_reg_page()implementation fromdrivers/hv/mshv_vtl_main.cto arch-specific files:
-arch/x86/hyperv/hv_vtl.c: full implementation with register page setup
-arch/arm64/hyperv/hv_vtl.c: stub implementation (unsupported)Move common type definitions to
include/asm-generic/mshyperv.h:
- structmshv_vtl_per_cpu
- unionhv_synic_overlay_page_msrMove
hv_call_get_vp_registers()andhv_call_set_vp_registers()declarations toinclude/asm-generic/mshyperv.hsince these functions are used by multiple modules.
Quoted 8 lines
Quoted 2 lines
While at it, remove the unnecessary stub implementations in #else case for mshv_vtl_return* functions in
arch/x86/include/asm/mshyperv.h.Seems like this patch is doing multiple things. The reg page configuration changes are more substantial and should probably be in a patch by themselves. The other changes are more trivial and maybe are OK grouped into a single patch, but you could also consider breaking them out.
I will split this patch into 3 patches.
Quoted 56 lines
Quoted 56 lines
This is essential for adding support for ARM64 in
MSHV_VTL.Signed-off-by Naman Jain <[email protected]>--- arch/arm64/hyperv/hv_vtl.c | 8 +++++ arch/arm64/include/asm/mshyperv.h | 3 ++ arch/x86/hyperv/hv_vtl.c | 32 ++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 7 ++--- drivers/hv/mshv.h | 8 ----- drivers/hv/mshv_vtl_main.c | 49 +++---------------------------- include/asm-generic/mshyperv.h | 42 ++++++++++++++++++++++++++ 7 files changed, 92 insertions(+), 57 deletions(-)arch/arm64/hyperv/hv_vtl.c +8
-0@@ -10,6 +10,7 @@#include <asm/boot.h> #include <asm/mshyperv.h> #include <asm/cpu_ops.h> +#include <linux/export.h> void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) {@@ -142,3 +143,10 @@ void mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0) "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"); }EXPORT_SYMBOL (mshv_vtl_return_call); + +bool hv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu) +{ +pr_debug ("Register page not supported on ARM64\n" ); +return false; +} +EXPORT_SYMBOL_GPL (hv_vtl_configure_reg_page);arch/arm64/include/asm/mshyperv.h +2
-0@@ -61,6 +61,8 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg) ARM_SMCCC_OWNER_VENDOR_HYP, \ HV_SMCCC_FUNC_NUMBER) +struct mshv_vtl_per_cpu ; + struct mshv_vtl_cpu_context {/* * NOTE: x18 is managed by the hypervisor. It won't be reloaded from this array. @@ -82,6 +84,7 @@ static inline int hv_vtl_get_set_reg(struct hv_register_assoc *regs,bool set, u
}
Quoted 6 lines
Quoted 2 lines
void
mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0);
+boolhv_vtl_configure_reg_page(struct mshv_vtl_per_cpu *per_cpu);I think this declaration could be added in
asm-generic/mshyperv.hso that it is shared by x86 and arm64. That also obviates the need for the forward ref to structmshv_vtl_per_cputhat you've added here.
Acked.
Quoted 42 lines
Quoted 42 lines
#endif #include <asm-generic/mshyperv.h>arch/x86/hyperv/hv_vtl.c +23
-0@@ -20,6 +20,7 @@#include <uapi/asm/mtrr.h> #include <asm/debugreg.h> #include <linux/export.h> +#include <linux/hyperv.h> #include <../kernel/smpboot.h> #include "../../kernel/fpu/legacy.h" @@ -259,6 +260,37 @@ int __init hv_vtl_early_init(void)return 0 ; } +static const union hv_input_vtl input_vtl_zero; + +bool hv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu) +{ +struct hv_register_assoc reg_assoc = {}; +union hv_synic_overlay_page_msr overlay = {}; +struct page *reg_page; + + reg_page =alloc_page (GFP_KERNEL | __GFP_ZERO | __GFP_RETRY_MAYFAIL); +if (!reg_page) { +WARN (1 ,"failed to allocate register page\n" ); +return false; + } + + overlay.enabled =1 ; + overlay.pfn =page_to_hvpfn (reg_page); + reg_assoc.name =HV_X64_REGISTER_REG_PAGE ; + reg_assoc.value.reg64 = overlay.as_uint64; + +if (hv_call_set_vp_registers (HV_VP_INDEX_SELF ,HV_PARTITION_ID_SELF , +1 , input_vtl_zero, ®_assoc)) { +WARN (1 ,"failed to setup register page\n" );
Quoted 8 lines
arch/x86/hyperv/hv_vtl.c int __init hv_vtl_early_init(void) · line 290
Quoted 6 lines
arch/x86/hyperv/hv_vtl.c +6
-0+__free_page (reg_page); +return false; + } + + per_cpu->reg_page = reg_page; +return true;As Sashiko AI noted, the memory allocated for the
reg_pagenever gets freed.
These are present in existing code, I'll address them in a separate series.
Quoted 16 lines
Quoted 16 lines
arch/x86/hyperv/hv_vtl.c +3
-0+} +EXPORT_SYMBOL_GPL (hv_vtl_configure_reg_page); + DEFINE_STATIC_CALL_NULL(__mshv_vtl_return_hypercall, void (*)(void));void mshv_vtl_return_call_init (u64 vtl_return_offset)arch/x86/include/asm/mshyperv.h +0
-0@@ -271,6 +271,8 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg) { return 0; }static inline int hv_apicid_to_vp_index (u32 apic_id) {return -EINVAL ; }#endif /* CONFIG_HYPERV */
Quoted 12 lines
arch/x86/include/asm/mshyperv.h void mshv_vtl_return_call_init(u64 vtl_return_offset); · line 310
Quoted 10 lines
arch/x86/include/asm/mshyperv.h +2
-0+struct mshv_vtl_per_cpu ; + struct mshv_vtl_cpu_context { union {struct {arch/x86/include/asm/mshyperv.h +1
-0@@ -305,13 +307,10 @@ void mshv_vtl_return_call_init(u64 vtl_return_offset);void mshv_vtl_return_hypercall (void );void __mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0);int hv_vtl_get_set_reg (struct hv_register_assoc *regs,bool set,u64 shared); +bool hv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu);Same as for arm64. Add a shared declaration in
asm-generic/mshyperv.h.
Ditto.
Quoted 95 lines
Quoted 95 lines
arch/x86/include/asm/mshyperv.h +0
-4#else static inline void __init hv_vtl_init_platform (void ) {}static inline int __init hv_vtl_early_init (void ) {return 0 ; } -static inline void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) {} -static inline void mshv_vtl_return_call_init (u64 vtl_return_offset) {} -static inline void mshv_vtl_return_hypercall (void ) {} -static inline void __mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) {}#endif #include <asm-generic/mshyperv.h> drivers/hv/mshv.h +0
-8@@ -14,14 +14,6 @@memchr_inv (&((STRUCT ).MEMBER), \ 0, sizeof_field(typeof(STRUCT), MEMBER)) -int hv_call_get_vp_registers (u32 vp_index,u64 partition_id,u16 count, -union hv_input_vtl input_vtl, -struct hv_register_assoc *registers); - -int hv_call_set_vp_registers (u32 vp_index,u64 partition_id,u16 count, -union hv_input_vtl input_vtl, -struct hv_register_assoc *registers); -int hv_call_get_partition_property (u64 partition_id,u64 property_code,u64 *property_value);drivers/hv/mshv_vtl_main.c +0
-43@@ -78,21 +78,6 @@ struct mshv_vtl {u64 id; }; -struct mshv_vtl_per_cpu { -struct mshv_vtl_run *run; -struct page *reg_page; -}; - -/* SYNIC_OVERLAY_PAGE_MSR - internal, identical to hv_synic_simp */ -union hv_synic_overlay_page_msr { -u64 as_uint64; -struct { -u64 enabled:1 ; -u64 reserved:11 ; -u64 pfn:52 ; - } __packed; -}; -static struct mutex mshv_vtl_poll_file_lock;static union hv_register_vsm_page_offsets mshv_vsm_page_offsets;static union hv_register_vsm_capabilities mshv_vsm_capabilities;@@ -201,34 +186,6 @@ static struct page *mshv_vtl_cpu_reg_page(int cpu)return *per_cpu_ptr (&mshv_vtl_per_cpu.reg_page, cpu); } -static void mshv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu) -{ -struct hv_register_assoc reg_assoc = {}; -union hv_synic_overlay_page_msr overlay = {}; -struct page *reg_page; - - reg_page =alloc_page (GFP_KERNEL | __GFP_ZERO | __GFP_RETRY_MAYFAIL); -if (!reg_page) { -WARN (1 ,"failed to allocate register page\n" ); -return ; - } - - overlay.enabled =1 ; - overlay.pfn =page_to_hvpfn (reg_page); - reg_assoc.name =HV_X64_REGISTER_REG_PAGE ; - reg_assoc.value.reg64 = overlay.as_uint64; - -if (hv_call_set_vp_registers (HV_VP_INDEX_SELF ,HV_PARTITION_ID_SELF , -1 , input_vtl_zero, ®_assoc)) { -WARN (1 ,"failed to setup register page\n" ); -__free_page (reg_page); -return ; - } - - per_cpu->reg_page = reg_page; - mshv_has_reg_page = true; -} -static void mshv_vtl_synic_enable_regs (unsigned int cpu) {union hv_synic_sint sint;@@ -329,8 +286,10 @@ static int mshv_vtl_alloc_context(unsigned int cpu)if (!per_cpu->run)return -ENOMEM ;
Quoted 10 lines
drivers/hv/mshv_vtl_main.c static int mshv_vtl_alloc_context(unsigned int cpu) · line 291
Quoted 5 lines
drivers/hv/mshv_vtl_main.c +3
-2-if (mshv_vsm_capabilities.intercept_page_available) -mshv_vtl_configure_reg_page (per_cpu); +if (mshv_vsm_capabilities.intercept_page_available) { +if (hv_vtl_configure_reg_page (per_cpu)) + mshv_has_reg_page = true;As Sashiko AI noted, it doesn't work to use the global
mshv_has_reg_pageto indicate the success of configuring the reg page, which is a per-cpu operation. But this bug existed before this patch set, so maybe it should be fixed as a preliminary patch.
Acked. Will address them in a separate series.
Quoted 60 lines
Quoted 60 lines
drivers/hv/mshv_vtl_main.c +1
-0+ }mshv_vtl_synic_enable_regs (cpu);include/asm-generic/mshyperv.h +42
-0@@ -383,8 +383,50 @@ static inline int hv_deposit_memory(u64 partition_id, u64 status)return hv_deposit_memory_node (NUMA_NO_NODE , partition_id, status); } +#if IS_ENABLED (CONFIG_MSHV_ROOT ) ||IS_ENABLED (CONFIG_MSHV_VTL ) +int hv_call_get_vp_registers (u32 vp_index,u64 partition_id,u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers); + +int hv_call_set_vp_registers (u32 vp_index,u64 partition_id,u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers); +#else +static inline int hv_call_get_vp_registers (u32 vp_index,u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers) +{ +return -EOPNOTSUPP ; +} + +static inline int hv_call_set_vp_registers (u32 vp_index,u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers) +{ +return -EOPNOTSUPP ; +} +#endif /* CONFIG_MSHV_ROOT || CONFIG_MSHV_VTL */ +#define HV_VP_ASSIST_PAGE_ADDRESS_SHIFT 12 +#if IS_ENABLED (CONFIG_HYPERV_VTL_MODE ) +struct mshv_vtl_per_cpu { +struct mshv_vtl_run *run; +struct page *reg_page; +}; + +/* SYNIC_OVERLAY_PAGE_MSR - internal, identical to hv_synic_simp */ +union hv_synic_overlay_page_msr { +u64 as_uint64; +struct { +u64 enabled:1 ; +u64 reserved:11 ; +u64 pfn:52 ; + } __packed; +}; +u8 __init get_vtl (void );#else static inline u8 get_vtl (void ) {return 0 ; }
Quoted 8 lines
Quoted 3 lines
--
2.43.0Sashiko AI noted another existing bug in
mshv_vtl_init(), which is that the error path doeskfree(mem_dev)when it should doput_device(mem_dev). See the comment in the header ofdevice_initialize().
To avoid this series bloating up, I am thinking of taking up these fixes in a separate series.
Regards,
Naman
Re: [PATCH 10/11] Drivers: hv: Add support for arm64 in MSHV_VTL
In reply to Michael KelleyQuoted 38 lines · Michael Kelley
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 37 lines
Add necessary support to make
MSHV_VTLwork for arm64 architecture.
* Add stub implementation formshv_vtl_return_call_init(): not required for arm64
* Removefpu/legacy.hheader inclusion, as this is not required
* handleHV_REGISTER_VSM_CODE_PAGE_OFFSETSregister: not supported in arm64
* Configure custompercpu_vmbus_handlerby usinghv_setup_percpu_vmbus_handler()
* Handle hugepage functions by config checksSigned-off-by Roman Kisel <[email protected]>Signed-off-by Naman Jain <[email protected]>--- arch/arm64/include/asm/mshyperv.h | 2 ++ drivers/hv/mshv_vtl_main.c | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-)arch/arm64/include/asm/mshyperv.h +2
-0@@ -83,6 +83,8 @@ static inline int hv_vtl_get_set_reg(struct hv_register_assoc *regs, bool set, u return 1; } +static inline void mshv_vtl_return_call_init (u64 vtl_return_offset) {} +void mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0);bool hv_vtl_configure_reg_page (struct mshv_vtl_per_cpu *per_cpu);#endif drivers/hv/mshv_vtl_main.c +0
-0@@ -23,8 +23,6 @@
Quoted 8 lines
drivers/hv/mshv_vtl_main.c line 27
Quoted 5 lines
drivers/hv/mshv_vtl_main.c +0
-2#include <trace/events/ipi.h> #include <uapi/linux/mshv.h> #include <hyperv/hvhdk.h> - -#include "../../kernel/fpu/legacy.h" Was there a particular code change that made this unnecessary? Or was it unnecessary from the start of this source code file? Just curious ....
This was present in initial driver changes when the assembly code was part of this driver. Then it moved to arch files and this was left here. Just cleaning it up.
Quoted 40 lines
Quoted 21 lines
drivers/hv/mshv_vtl_main.c +5
-3#include "mshv.h" #include "mshv_vtl.h" #include "hyperv_vmbus.h" @@ -206,18 +204,21 @@ static void mshv_vtl_synic_enable_regs(unsigned int cpu)static int mshv_vtl_get_vsm_regs (void ) {struct hv_register_assoc registers[2 ]; -int ret, count =2 ; +int ret, count =0 ; - registers[0 ].name =HV_REGISTER_VSM_CODE_PAGE_OFFSETS ; - registers[1 ].name =HV_REGISTER_VSM_CAPABILITIES ; + registers[count++].name =HV_REGISTER_VSM_CAPABILITIES ; +/* Code page offset register is not supported on ARM */ +if (IS_ENABLED (CONFIG_X86_64 )) + registers[count++].name =HV_REGISTER_VSM_CODE_PAGE_OFFSETS ; ret =hv_call_get_vp_registers (HV_VP_INDEX_SELF ,HV_PARTITION_ID_SELF , count, input_vtl_zero, registers);if (ret)drivers/hv/mshv_vtl_main.c static void mshv_vtl_synic_enable_regs(unsigned int cpu) · line 224
Quoted 10 lines
drivers/hv/mshv_vtl_main.c +3
-2return ret; - mshv_vsm_page_offsets.as_uint64 = registers[0 ].value.reg64; - mshv_vsm_capabilities.as_uint64 = registers[1 ].value.reg64; + mshv_vsm_capabilities.as_uint64 = registers[0 ].value.reg64; +if (IS_ENABLED (CONFIG_X86_64 )) + mshv_vsm_page_offsets.as_uint64 = registers[1 ].value.reg64;return ret; }This function has gotten somewhat messy to handle the x86 and arm64 differences. Let me suggest a different approach. Have this function only get the VSM capabilities register, as that is generic across x86 and arm64. Then, update x86
mshv_vtl_return_call_init()to get thePAGE_OFFSETSregister and then immediately use the value to update the static call. The global variablemshv_vms_page_offsetsis no longer necessary.
Quoted 4 lines
My suggestion might be little more code because
hv_call_get_vp_registers()is invoked in two different places. But it cleanly separates the two use cases, and keeps the x86 hackery underarch/x86.
I implemented this in my dev branch, and it works fine. Thanks for the suggestion.
Quoted 7 lines
Quoted 7 lines
drivers/hv/mshv_vtl_main.c +2
-0@@ -280,10 +281,13 @@ static int hv_vtl_setup_synic(void)/* Use our isr to first filter out packets destined for userspace */ hv_setup_vmbus_handler (mshv_vtl_vmbus_isr); +/* hv_setup_vmbus_handler() is stubbed for ARM64, add per-cpu VMBus handlers instead */ +hv_setup_percpu_vmbus_handler (mshv_vtl_vmbus_isr);
Quoted 12 lines
drivers/hv/mshv_vtl_main.c static int hv_vtl_setup_synic(void) · line 303
Quoted 12 lines
drivers/hv/mshv_vtl_main.c +2
-0ret =cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"hyperv/vtl:online" , mshv_vtl_alloc_context,NULL );if (ret <0 ) { +hv_setup_percpu_vmbus_handler (vmbus_isr);hv_setup_vmbus_handler (vmbus_isr);return ret; }@@ -296,6 +300,7 @@ static int hv_vtl_setup_synic(void)static void hv_vtl_remove_synic (void ) {cpuhp_remove_state (mshv_vtl_cpuhp_online); +hv_setup_percpu_vmbus_handler (vmbus_isr);
hv_setup_percpu_vmbus_handler() calls will also be removed with the redesign.
Regards,
Naman
Re: [PATCH 11/11] Drivers: hv: Kconfig: Add ARM64 support for MSHV_VTL
In reply to Michael KelleyQuoted 5 lines · Michael Kelley
From: Naman Jain <[email protected]> Sent: Monday, March 16, 2026 5:13 AM
Quoted 1 line
Nit: In keeping with past practice, the "Subject" prefix for this patch could just be "Drivers: hv:"
Acked.
I am also planning to change other subject line prefixes, based on your earlier suggestion:
mshv_vtl_main changes - "mshv_vtl: "arch/arm64 Hyper-V changes - "arm64: hyperv: "arch/x86 Hyper-V changes - "x86/hyperv: "
Thank you so much for doing such a thorough review. I really appreciate all the help and guidance.
Regards,
Naman