Introduce /dev/mshv drivers
Subsystems (8)
PATCH 3/15 mshyperv: Introduce numa_node_to_proximity_domain_info
In reply to Nuno Das NevesFactor out logic for converting numa node to proximity domain info into a helper function, and export it.
--- arch/x86/hyperv/hv_proc.c | 8 ++------ drivers/acpi/numa/srat.c | 1 + include/asm-generic/mshyperv.h | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-)
arch/x86/hyperv/hv_proc.c +2 -6
@@ -121,7 +121,6 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)u64 status;unsigned long flags;int ret =HV_STATUS_SUCCESS ; -int pxm =node_to_pxm (node);/* * When adding a logical processor, the hypervisor may return
@@ -137,11 +136,8 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id) input->lp_index = lp_index; input->apic_id = apic_id; - input->flags =0 ; - input->proximity_domain_info.domain_id = pxm; - input->proximity_domain_info.flags.reserved =0 ; - input->proximity_domain_info.flags.proximity_info_valid =1 ; - input->proximity_domain_info.flags.proximity_preferred =1 ; + input->proximity_domain_info = +numa_node_to_proximity_domain_info (node); status =hv_do_hypercall (HVCALL_ADD_LOGICAL_PROCESSOR , input, output);local_irq_restore (flags);
drivers/acpi/numa/srat.c +1 -0
@@ -48,6 +48,7 @@ int node_to_pxm(int node)return PXM_INVAL ;return node_to_pxm_map[node]; } +EXPORT_SYMBOL (node_to_pxm);static void __acpi_map_pxm_to_node (int pxm,int node) {
include/asm-generic/mshyperv.h +18 -0
@@ -21,6 +21,7 @@#include <linux/types.h> #include <linux/atomic.h> #include <linux/bitops.h> +#include <acpi/acpi_numa.h> #include <linux/cpumask.h> #include <linux/nmi.h> #include <asm/ptrace.h>
@@ -28,6 +29,23 @@#define VTPM_BASE_ADDRESS 0xfed40000 +static inline union hv_proximity_domain_info +numa_node_to_proximity_domain_info (int node) +{ +union hv_proximity_domain_info proximity_domain_info; + +if (node !=NUMA_NO_NODE ) { + proximity_domain_info.domain_id =node_to_pxm (node); + proximity_domain_info.flags.reserved =0 ; + proximity_domain_info.flags.proximity_info_valid =1 ; + proximity_domain_info.flags.proximity_preferred =1 ; + }else { + proximity_domain_info.as_uint64 =0 ; + } + +return proximity_domain_info; +} +struct ms_hyperv_info {u32 features;u32 priv_high;
Signature · 1 line
2.25.1
PATCH 4/15 asm-generic/mshyperv: Introduce hv_recommend_using_aeoi()
In reply to Nuno Das NevesFactor out logic for determining if we should set the auto eoi flag in SINT register.
--- drivers/hv/hv.c | 12 +----------- include/asm-generic/mshyperv.h | 13 +++++++++++++ 2 files changed, 14 insertions(+), 11 deletions(-)
drivers/hv/hv.c +1 -11
@@ -217,17 +217,7 @@ void hv_synic_enable_regs(unsigned int cpu) shared_sint.vector = vmbus_interrupt; shared_sint.masked = false; - -/* -* On architectures where Hyper-V doesn't support AEOI (e.g., ARM64), -* it doesn't provide a recommendation flag and AEOI must be disabled. -*/ -#ifdef HV_DEPRECATING_AEOI_RECOMMENDED - shared_sint.auto_eoi = - !(ms_hyperv.hints &HV_DEPRECATING_AEOI_RECOMMENDED ); -#else - shared_sint.auto_eoi =0 ; -#endif + shared_sint.auto_eoi =hv_recommend_using_aeoi ();hv_set_register (HV_MSR_SINT0 +VMBUS_MESSAGE_SINT , shared_sint.as_uint64);
include/asm-generic/mshyperv.h +13 -0
@@ -77,6 +77,19 @@ extern u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr);extern u64 hv_do_fast_hypercall8 (u16 control,u64 input8);extern bool hv_isolation_type_snp (void ); +/* +* On architectures where Hyper-V doesn't support AEOI (e.g., ARM64), +* it doesn't provide a recommendation flag and AEOI must be disabled. +*/ +static inline bool hv_recommend_using_aeoi (void ) +{ +#ifdef HV_DEPRECATING_AEOI_RECOMMENDED +return !(ms_hyperv.hints &HV_DEPRECATING_AEOI_RECOMMENDED ); +#else +return false; +#endif +} +/* Helper functions that provide a consistent pattern for checking Hyper-V hypercall status. */ static inline int hv_result (u64 status) {
Signature · 1 line
2.25.1
PATCH 1/15 hyperv-tlfs: Change shared HV_REGISTER_* defines to HV_MSR_*
In reply to Nuno Das NevesIn x86 hyperv-tlfs, HV_REGISTER_ prefix is used to indicate MSRs accessed via rdmsrl/wrmsrl. But in ARM64, HV_REGISTER_ instead indicates VP registers accessed via get/set vp registers hypercall.
This is due to HV_REGISTER_* names being used by hv_set/get_register, with the arch-specific version delegating to the appropriate mechanism.
The problem is, using prefix HV_REGISTER_ for MSRs will conflict with VP registers when they are introduced for x86 in future.
This patch solves the issue by:
1. Defining all the x86 MSRs with a consistent prefix: HV_X64_MSR_. This is so HV_REGISTER_ can be reserved for VP registers.
2. Change the non-arch-specific alias used by hv_set/get_register to HV_MSR_. This is also happens to be the same name HyperV uses for this purpose.
--- arch/arm64/include/asm/hyperv-tlfs.h | 25 +++++ arch/x86/include/asm/hyperv-tlfs.h | 137 +++++++++++++-------------- arch/x86/include/asm/mshyperv.h | 8 +- arch/x86/kernel/cpu/mshyperv.c | 22 ++--- drivers/clocksource/hyperv_timer.c | 24 ++--- drivers/hv/hv.c | 32 +++---- drivers/hv/hv_common.c | 18 ++-- include/asm-generic/mshyperv.h | 2 +- 8 files changed, 146 insertions(+), 122 deletions(-)
arch/arm64/include/asm/hyperv-tlfs.h +25 -0
@@ -64,6 +64,31 @@#define HV_REGISTER_STIMER0_CONFIG 0x000B0000#define HV_REGISTER_STIMER0_COUNT 0x000B0001 +/* +* To support non-arch-specific code calling hv_set/get_register: +* - On x86, HV_MSR_ indicates an MSR accessed via rdmsrl/wrmsrl +* - On ARM, HV_MSR_ indicates a VP register accessed via hypercall +*/ +#define HV_MSR_VP_INDEX (HV_REGISTER_VP_INDEX) +#define HV_MSR_TIME_REF_COUNT (HV_REGISTER_TIME_REF_COUNT) +#define HV_MSR_REFERENCE_TS (HV_REGISTER_REFERENCE_TSC) + +#define HV_MSR_STIMER0_CONFIG (HV_REGISTER_STIMER0_CONFIG) +#define HV_MSR_STIMER0_COUNT (HV_REGISTER_STIMER0_COUNT) + +#define HV_MSR_SCONTROL (HV_REGISTER_SCONTROL) +#define HV_MSR_SIEFP (HV_REGISTER_SIEFP) +#define HV_MSR_SIMP (HV_REGISTER_SIMP) +#define HV_MSR_EOM (HV_REGISTER_EOM) +#define HV_MSR_SINT0 (HV_REGISTER_SINT0) + +#define HV_MSR_CRASH_P0 (HV_REGISTER_CRASH_P0) +#define HV_MSR_CRASH_P1 (HV_REGISTER_CRASH_P1) +#define HV_MSR_CRASH_P2 (HV_REGISTER_CRASH_P2) +#define HV_MSR_CRASH_P3 (HV_REGISTER_CRASH_P3) +#define HV_MSR_CRASH_P4 (HV_REGISTER_CRASH_P4) +#define HV_MSR_CRASH_CTL (HV_REGISTER_CRASH_CTL) +union hv_msi_entry {u64 as_uint64[2 ];struct {
arch/x86/include/asm/hyperv-tlfs.h +68 -69
177 lines not on this page · raw message
arch/x86/include/asm/mshyperv.h +4 -4
@@ -242,14 +242,14 @@ extern bool hv_isolation_type_snp(void);static inline bool hv_is_synic_reg (unsigned int reg) { -return (reg >=HV_REGISTER_SCONTROL ) && - (reg <=HV_REGISTER_SINT15 ); +return (reg >=HV_X64_MSR_SCONTROL ) && + (reg <=HV_X64_MSR_SINT15 ); }static inline bool hv_is_sint_reg (unsigned int reg) { -return (reg >=HV_REGISTER_SINT0 ) && - (reg <=HV_REGISTER_SINT15 ); +return (reg >=HV_X64_MSR_SINT0 ) && + (reg <=HV_X64_MSR_SINT15 ); }u64 hv_get_register (unsigned int reg);
arch/x86/kernel/cpu/mshyperv.c +11 -11
@@ -43,19 +43,19 @@ struct ms_hyperv_info ms_hyperv;static inline unsigned int hv_get_nested_reg (unsigned int reg) {if (hv_is_sint_reg (reg)) -return reg -HV_REGISTER_SINT0 +HV_REGISTER_NESTED_SINT0 ; +return reg -HV_X64_MSR_SINT0 +HV_X64_MSR_NESTED_SINT0 ;switch (reg) { -case HV_REGISTER_SIMP : -return HV_REGISTER_NESTED_SIMP ; -case HV_REGISTER_SIEFP : -return HV_REGISTER_NESTED_SIEFP ; -case HV_REGISTER_SVERSION : -return HV_REGISTER_NESTED_SVERSION ; -case HV_REGISTER_SCONTROL : -return HV_REGISTER_NESTED_SCONTROL ; -case HV_REGISTER_EOM : -return HV_REGISTER_NESTED_EOM ; +case HV_X64_MSR_SIMP : +return HV_X64_MSR_NESTED_SIMP ; +case HV_X64_MSR_SIEFP : +return HV_X64_MSR_NESTED_SIEFP ; +case HV_X64_MSR_SVERSION : +return HV_X64_MSR_NESTED_SVERSION ; +case HV_X64_MSR_SCONTROL : +return HV_X64_MSR_NESTED_SCONTROL ; +case HV_X64_MSR_EOM : +return HV_X64_MSR_NESTED_EOM ;default :return reg; }
drivers/clocksource/hyperv_timer.c +12 -12
@@ -81,14 +81,14 @@ static int hv_ce_set_next_event(unsigned long delta, current_tick =hv_read_reference_counter (); current_tick += delta; -hv_set_register (HV_REGISTER_STIMER0_COUNT , current_tick); +hv_set_register (HV_MSR_STIMER0_COUNT , current_tick);return 0 ; }static int hv_ce_shutdown (struct clock_event_device *evt) { -hv_set_register (HV_REGISTER_STIMER0_COUNT ,0 ); -hv_set_register (HV_REGISTER_STIMER0_CONFIG ,0 ); +hv_set_register (HV_MSR_STIMER0_COUNT ,0 ); +hv_set_register (HV_MSR_STIMER0_CONFIG ,0 );if (direct_mode_enabled && stimer0_irq >=0 )disable_percpu_irq (stimer0_irq);
@@ -119,7 +119,7 @@ static int hv_ce_set_oneshot(struct clock_event_device *evt) timer_cfg.direct_mode =0 ; timer_cfg.sintx = stimer0_message_sint; } -hv_set_register (HV_REGISTER_STIMER0_CONFIG , timer_cfg.as_uint64); +hv_set_register (HV_MSR_STIMER0_CONFIG , timer_cfg.as_uint64);return 0 ; }
@@ -398,7 +398,7 @@ static u64 notrace read_hv_clock_tsc(void)u64 current_tick =hv_read_tsc_page (hv_get_tsc_page ());if (current_tick ==U64_MAX ) - current_tick =hv_get_register (HV_REGISTER_TIME_REF_COUNT ); + current_tick =hv_get_register (HV_MSR_TIME_REF_COUNT );return current_tick; }
@@ -419,9 +419,9 @@ static void suspend_hv_clock_tsc(struct clocksource *arg)union hv_reference_tsc_msr tsc_msr;/* Disable the TSC page */ - tsc_msr.as_uint64 =hv_get_register (HV_REGISTER_REFERENCE_TSC ); + tsc_msr.as_uint64 =hv_get_register (HV_MSR_REFERENCE_TSC ); tsc_msr.enable =0 ; -hv_set_register (HV_REGISTER_REFERENCE_TSC , tsc_msr.as_uint64); +hv_set_register (HV_MSR_REFERENCE_TSC , tsc_msr.as_uint64); }
@@ -430,10 +430,10 @@ static void resume_hv_clock_tsc(struct clocksource *arg)union hv_reference_tsc_msr tsc_msr;/* Re-enable the TSC page */ - tsc_msr.as_uint64 =hv_get_register (HV_REGISTER_REFERENCE_TSC ); + tsc_msr.as_uint64 =hv_get_register (HV_MSR_REFERENCE_TSC ); tsc_msr.enable =1 ; tsc_msr.pfn = tsc_pfn; -hv_set_register (HV_REGISTER_REFERENCE_TSC , tsc_msr.as_uint64); +hv_set_register (HV_MSR_REFERENCE_TSC , tsc_msr.as_uint64); }#ifdef HAVE_VDSO_CLOCKMODE_HVCLOCK
@@ -467,7 +467,7 @@ static u64 notrace read_hv_clock_msr(void)* is set to 0 when the partition is created and is incremented in * 100 nanosecond units. */ -return hv_get_register (HV_REGISTER_TIME_REF_COUNT ); +return hv_get_register (HV_MSR_TIME_REF_COUNT ); } static u64 notrace read_hv_clock_msr_cs(struct clocksource *arg)
@@ -554,14 +554,14 @@ static bool __init hv_init_tsc_clocksource(void)* thus TSC clocksource will work even without the real TSC page * mapped. */ - tsc_msr.as_uint64 =hv_get_register (HV_REGISTER_REFERENCE_TSC ); + tsc_msr.as_uint64 =hv_get_register (HV_MSR_REFERENCE_TSC );if (hv_root_partition) tsc_pfn = tsc_msr.pfn;else tsc_pfn =HVPFN_DOWN (virt_to_phys (tsc_page)); tsc_msr.enable =1 ; tsc_msr.pfn = tsc_pfn; -hv_set_register (HV_REGISTER_REFERENCE_TSC , tsc_msr.as_uint64); +hv_set_register (HV_MSR_REFERENCE_TSC , tsc_msr.as_uint64);clocksource_register_hz (&hyperv_cs_tsc,NSEC_PER_SEC /100 );
drivers/hv/hv.c +16 -16
@@ -172,7 +172,7 @@ void hv_synic_enable_regs(unsigned int cpu)union hv_synic_scontrol sctrl;/* Setup the Synic's message page */ - simp.as_uint64 =hv_get_register (HV_REGISTER_SIMP ); + simp.as_uint64 =hv_get_register (HV_MSR_SIMP ); simp.simp_enabled =1 ;if (hv_isolation_type_snp () || hv_root_partition) {
@@ -188,10 +188,10 @@ void hv_synic_enable_regs(unsigned int cpu) >> HV_HYP_PAGE_SHIFT; } -hv_set_register (HV_REGISTER_SIMP , simp.as_uint64); +hv_set_register (HV_MSR_SIMP , simp.as_uint64);/* Setup the Synic's event page */ - siefp.as_uint64 =hv_get_register (HV_REGISTER_SIEFP ); + siefp.as_uint64 =hv_get_register (HV_MSR_SIEFP ); siefp.siefp_enabled =1 ;if (hv_isolation_type_snp () || hv_root_partition) {
@@ -207,12 +207,12 @@ void hv_synic_enable_regs(unsigned int cpu) >> HV_HYP_PAGE_SHIFT; } -hv_set_register (HV_REGISTER_SIEFP , siefp.as_uint64); +hv_set_register (HV_MSR_SIEFP , siefp.as_uint64);/* Setup the shared SINT. */ if (vmbus_irq !=-1 )enable_percpu_irq (vmbus_irq,0 ); - shared_sint.as_uint64 =hv_get_register (HV_REGISTER_SINT0 + + shared_sint.as_uint64 =hv_get_register (HV_MSR_SINT0 +VMBUS_MESSAGE_SINT ); shared_sint.vector = vmbus_interrupt;
@@ -228,14 +228,14 @@ void hv_synic_enable_regs(unsigned int cpu)#else shared_sint.auto_eoi =0 ;#endif -hv_set_register (HV_REGISTER_SINT0 +VMBUS_MESSAGE_SINT , +hv_set_register (HV_MSR_SINT0 +VMBUS_MESSAGE_SINT , shared_sint.as_uint64);/* Enable the global synic bit */ - sctrl.as_uint64 =hv_get_register (HV_REGISTER_SCONTROL ); + sctrl.as_uint64 =hv_get_register (HV_MSR_SCONTROL ); sctrl.enable =1 ; -hv_set_register (HV_REGISTER_SCONTROL , sctrl.as_uint64); +hv_set_register (HV_MSR_SCONTROL , sctrl.as_uint64); }int hv_synic_init (unsigned int cpu)
@@ -259,17 +259,17 @@ void hv_synic_disable_regs(unsigned int cpu)union hv_synic_siefp siefp;union hv_synic_scontrol sctrl; - shared_sint.as_uint64 =hv_get_register (HV_REGISTER_SINT0 + + shared_sint.as_uint64 =hv_get_register (HV_MSR_SINT0 +VMBUS_MESSAGE_SINT ); shared_sint.masked =1 ;/* Need to correctly cleanup in the case of SMP!!! */ /* Disable the interrupt */ -hv_set_register (HV_REGISTER_SINT0 +VMBUS_MESSAGE_SINT , +hv_set_register (HV_MSR_SINT0 +VMBUS_MESSAGE_SINT , shared_sint.as_uint64); - simp.as_uint64 =hv_get_register (HV_REGISTER_SIMP ); + simp.as_uint64 =hv_get_register (HV_MSR_SIMP );/* * In Isolation VM, sim and sief pages are allocated by * paravisor. These pages also will be used by kdump
@@ -284,9 +284,9 @@ void hv_synic_disable_regs(unsigned int cpu) simp.base_simp_gpa =0 ; } -hv_set_register (HV_REGISTER_SIMP , simp.as_uint64); +hv_set_register (HV_MSR_SIMP , simp.as_uint64); - siefp.as_uint64 =hv_get_register (HV_REGISTER_SIEFP ); + siefp.as_uint64 =hv_get_register (HV_MSR_SIEFP ); siefp.siefp_enabled =0 ;if (hv_isolation_type_snp () || hv_root_partition) {
@@ -296,12 +296,12 @@ void hv_synic_disable_regs(unsigned int cpu) siefp.base_siefp_gpa =0 ; } -hv_set_register (HV_REGISTER_SIEFP , siefp.as_uint64); +hv_set_register (HV_MSR_SIEFP , siefp.as_uint64);/* Disable the global synic bit */ - sctrl.as_uint64 =hv_get_register (HV_REGISTER_SCONTROL ); + sctrl.as_uint64 =hv_get_register (HV_MSR_SCONTROL ); sctrl.enable =0 ; -hv_set_register (HV_REGISTER_SCONTROL , sctrl.as_uint64); +hv_set_register (HV_MSR_SCONTROL , sctrl.as_uint64);if (vmbus_irq !=-1 )disable_percpu_irq (vmbus_irq);
drivers/hv/hv_common.c +9 -9
@@ -227,17 +227,17 @@ static void hv_kmsg_dump(struct kmsg_dumper *dumper,* contain the size of the panic data in that page. Rest of the * registers are no-op when the NOTIFY_MSG flag is set. */ -hv_set_register (HV_REGISTER_CRASH_P0 ,0 ); -hv_set_register (HV_REGISTER_CRASH_P1 ,0 ); -hv_set_register (HV_REGISTER_CRASH_P2 ,0 ); -hv_set_register (HV_REGISTER_CRASH_P3 ,virt_to_phys (hv_panic_page)); -hv_set_register (HV_REGISTER_CRASH_P4 , bytes_written); +hv_set_register (HV_MSR_CRASH_P0 ,0 ); +hv_set_register (HV_MSR_CRASH_P1 ,0 ); +hv_set_register (HV_MSR_CRASH_P2 ,0 ); +hv_set_register (HV_MSR_CRASH_P3 ,virt_to_phys (hv_panic_page)); +hv_set_register (HV_MSR_CRASH_P4 , bytes_written);/* * Let Hyper-V know there is crash data available along with * the panic message. */ -hv_set_register (HV_REGISTER_CRASH_CTL , +hv_set_register (HV_MSR_CRASH_CTL , (HV_CRASH_CTL_CRASH_NOTIFY |HV_CRASH_CTL_CRASH_NOTIFY_MSG )); }
@@ -310,7 +310,7 @@ int __init hv_common_init(void)* Register for panic kmsg callback only if the right * capability is supported by the hypervisor. */ - hyperv_crash_ctl =hv_get_register (HV_REGISTER_CRASH_CTL ); + hyperv_crash_ctl =hv_get_register (HV_MSR_CRASH_CTL );if (hyperv_crash_ctl &HV_CRASH_CTL_CRASH_NOTIFY_MSG )hv_kmsg_dump_register ();
@@ -373,7 +373,7 @@ int hv_common_cpu_init(unsigned int cpu) *outputarg = (char *)(*inputarg) +HV_HYP_PAGE_SIZE ; } - msr_vp_index =hv_get_register (HV_REGISTER_VP_INDEX ); + msr_vp_index =hv_get_register (HV_MSR_VP_INDEX ); hv_vp_index[cpu] = msr_vp_index;
@@ -477,7 +477,7 @@ EXPORT_SYMBOL_GPL(hv_is_hibernation_supported);*/ static u64 __hv_read_ref_counter (void ) { -return hv_get_register (HV_REGISTER_TIME_REF_COUNT ); +return hv_get_register (HV_MSR_TIME_REF_COUNT ); }u64 (*hv_read_reference_counter)(void) = __hv_read_ref_counter;
include/asm-generic/mshyperv.h +1 -1
@@ -149,7 +149,7 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)* possibly deliver another msg from the * hypervisor */ -hv_set_register (HV_REGISTER_EOM ,0 ); +hv_set_register (HV_MSR_EOM ,0 ); } }
Signature · 1 line
2.25.1
PATCH 5/15 hyperv: Move hv_connection_id to hyperv-tlfs
In reply to Nuno Das NevesThis structure should be in hyperv-tlfs.h anyway, since it is part of the TLFS document.
The definition conflicts with one added in hvgdk.h as part of the mshv driver so must be moved to hyperv-tlfs.h.
--- include/asm-generic/hyperv-tlfs.h | 9 +++++++++ include/linux/hyperv.h | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-)
include/asm-generic/hyperv-tlfs.h +9 -0
@@ -845,4 +845,13 @@ struct hv_mmio_write_input { u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH]; } __packed; +/* Define connection identifier type. */ +union hv_connection_id { +u32 asu32; +struct { +u32 id:24 ; +u32 reserved:8 ; + } u; +}; +#endif
include/linux/hyperv.h +0 -9
@@ -748,15 +748,6 @@ struct vmbus_close_msg {struct vmbus_channel_close_channel msg; }; -/* Define connection identifier type. */ -union hv_connection_id { -u32 asu32; -struct { -u32 id:24 ; -u32 reserved:8 ; - } u; -}; -enum vmbus_device_type {HV_IDE =0 ,HV_SCSI ,
Signature · 1 line
2.25.1
PATCH 6/15 hyperv-tlfs: Introduce hv_status_to_string and hv_status_to_errno
In reply to Nuno Das Neveshv_status_to_errno translates hyperv statuses to linux error codes. This is useful for returning something linux-friendly from a hypercall helper function.hv_status_to_string improves clarity of error messages.
--- arch/x86/hyperv/hv_init.c | 2 +- arch/x86/hyperv/hv_proc.c | 6 ++--- include/asm-generic/hyperv-tlfs.h | 45 ++++++++++++++++++++++--------- include/asm-generic/mshyperv.h | 33 +++++++++++++++++++++++ 4 files changed, 70 insertions(+), 16 deletions(-)
arch/x86/hyperv/hv_init.c +1 -1
@@ -371,7 +371,7 @@ static void __init hv_get_partition_id(void) status =hv_do_hypercall (HVCALL_GET_PARTITION_ID ,NULL , output_page);if (!hv_result_success (status)) {/* No point in proceeding if this failed */ -pr_err ("Failed to get partition ID: %lld\n" , status); +pr_err ("Failed to get partition ID: %s\n" ,hv_status_to_string (status));BUG (); } hv_current_partition_id = output_page->partition_id;
arch/x86/hyperv/hv_proc.c +3 -3
@@ -144,9 +144,9 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)if (hv_result (status) !=HV_STATUS_INSUFFICIENT_MEMORY ) {if (!hv_result_success (status)) { -pr_err ("%s: cpu %u apic ID %u, %lld\n" , __func__, - lp_index, apic_id, status); - ret =hv_result (status); +pr_err ("%s: cpu %u apic ID %u, %s\n" , __func__, + lp_index, apic_id,hv_status_to_string (status)); + ret =hv_status_to_errno (status); }break ; }
include/asm-generic/hyperv-tlfs.h +33 -12
51 lines not on this page · raw message
include/asm-generic/mshyperv.h +33 -0
@@ -300,6 +300,39 @@ static inline int cpumask_to_vpset_skip(struct hv_vpset *vpset,return __cpumask_to_vpset (vpset, cpus, func); } + +static inline int hv_status_to_errno (u64 hv_status) +{ +switch (hv_result (hv_status)) { +case HV_STATUS_SUCCESS : +return 0 ; +case HV_STATUS_INVALID_PARAMETER : +case HV_STATUS_UNKNOWN_PROPERTY : +case HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE : +case HV_STATUS_INVALID_VP_INDEX : +case HV_STATUS_INVALID_REGISTER_VALUE : +case HV_STATUS_INVALID_LP_INDEX : +case HV_STATUS_PROCESSOR_FEATURE_NOT_SUPPORTED : +return -EINVAL ; +case HV_STATUS_ACCESS_DENIED : +case HV_STATUS_OPERATION_DENIED : +return -EACCES ; +case HV_STATUS_NOT_ACKNOWLEDGED : +case HV_STATUS_INVALID_VP_STATE : +case HV_STATUS_INVALID_PARTITION_STATE : +return -EBADFD ; + } +return -ENOTRECOVERABLE ; +} + +static inline const char *hv_status_to_string (u64 hv_status) +{ +switch (hv_result (hv_status)) { + __HV_STATUS_DEF(__HV_MAKE_HV_STATUS_CASE) + default : return "Unknown"; + } +} +void hyperv_report_panic (struct pt_regs *regs,long err,bool in_die);bool hv_is_hyperv_initialized (void );bool hv_is_hibernation_supported (void );
Signature · 1 line
2.25.1
cover Introduce /dev/mshv drivers
This series introduces support for creating and running guest machines while running on the Microsoft Hypervisor. [0]
This is done via an IOCTL interface accessed through /dev/mshv, similar to /dev/kvm. Another series introducing this support was previously posted.
[1]
These interfaces support VMMs running in:
1. The root patition - provided in the mshv_root module, and
2. VTL 2 - provided in the mshv_vtl module [2]
Patches breakdown
-----------------
The first 7 patches are refactoring and adding some helper functions. They provide some benefit on their own and could be applied independently as cleanup patches.
The following 5 patches just set things up for the driver code to come. These are very small. They are separated so that the remaining patches are more self-contained.
The final 3 patches are the meat of the series:
- Patch 13 contains new header files used by the driver.
These are designed to mirror the ABI headers exported by Hyper-V. This is done to avoid polluting hyperv-tlfs.h and help track changes to the ABIs that are still unstable. (See FAQ below).
- Patch 14 conditionally includes these new header files into mshyperv.h and linux/hyperv.h, in order to be able to use these files in the new drivers while remaining independent from hyperv-tlfs.h.
- Patch 15 contains the new driver code located in drivers/hv. This is a large amount of code and new files, but it is mostly self-contained and all within drivers/hv - apart from the IOCTL interface itself in uapi.
FAQ on include/uapi/hyperv/*.h
------------------------------
Q:
Why not just add these definitions to hyperv-tlfs.h?
A:
The intention of hyperv-tlfs.h is to contain stable definitions documented in the public TLFS document. These new definitions don't fit that criteria, so they should be separate.
Q:
Why are these files named hvgdk.h, hvgdk_mini.h, hvhdk.h and hvhdk_mini.h? A:
The precise meaning of the names reflects conventions used internally at Microsoft.
Naming them this way makes it easy to find where particular Hyper-V definitions come from, and check their correctness.
It also facilitates the future work of automatically generating these files.
Q:
Why are they in uapi?
A:
In short, to keep things simple. There are many definitions needed in both the kernel and the VMM in userspace. Separating them doesn't serve much purpose, and makes it more laborious to import definitions from Hyper-V code.
Q:
The new headers redefine many things that are already in hyperv-tlfs.h - why? A:
Some definitions are extended compared to what is documented in the TLFS. In order to avoid adding undocumented or unstable definitions to hyperv-tlfs.h, the new headers must compile independently.
Therefore, the new headers must redefine many things in hyperv-tlfs.h in order to compile.
--------------------------
[0] "Hyper-V" is more well-known, but it really refers to the whole stack including the hypervisor and other components that run in Windows kernel and userspace.
[1] Previous /dev/mshv patch series and discussion:
https://lore.kernel.org/linux-hyperv/1632853875-20261-1-git-send-email-nunodasneves@linux.microsoft.com/
[2] Virtual Secure Mode (VSM) and Virtual Trust Levels (VTL):
https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/vsm
Nuno Das Neves (15):
hyperv-tlfs: Change shared HV_REGISTER_* defines to HV_MSR_*
mshyperv: Introduce hv_get_hypervisor_version
mshyperv: Introduce numa_node_to_proximity_domain_info asm-generic/mshyperv: Introduce hv_recommend_using_aeoi()
hyperv: Move hv_connection_id to hyperv-tlfs
hyperv-tlfs: Introduce hv_status_to_string and hv_status_to_errno
Drivers: hv: Move hv_call_deposit_pages and hv_call_create_vp to
common code
Drivers: hv: Introduce per-cpu event ring tail
Drivers: hv: Introduce hv_output_arg_exists in hv_common
x86: hyperv: Add mshv_handler irq handler and setup function
Drivers: hv: export vmbus_isr, hv_context and hv_post_message
Documentation: Reserve ioctl number for mshv driver
uapi: hyperv: Add mshv driver headers hvhdk.h, hvhdk_mini.h, hvgdk.h,
hvgdk_mini.h
asm-generic: hyperv: Use mshv headers conditionally. Add
asm-generic/hyperv-defs.h
Drivers: hv: Add modules to expose /dev/mshv to VMMs running on
Hyper-V
.../userspace-api/ioctl/ioctl-number.rst | 2 + arch/arm64/hyperv/mshyperv.c | 23 +- arch/arm64/include/asm/hyperv-tlfs.h | 25 + arch/arm64/include/asm/mshyperv.h | 2 +- arch/x86/hyperv/hv_init.c | 2 +- arch/x86/hyperv/hv_proc.c | 166 +- arch/x86/include/asm/hyperv-tlfs.h | 137 +- arch/x86/include/asm/mshyperv.h | 13 +- arch/x86/kernel/cpu/mshyperv.c | 71 +- drivers/acpi/numa/srat.c | 1 + drivers/clocksource/hyperv_timer.c | 24 +- drivers/hv/Kconfig | 54 + drivers/hv/Makefile | 21 + drivers/hv/hv.c | 46 +- drivers/hv/hv_call.c | 119 + drivers/hv/hv_common.c | 225 +- drivers/hv/hyperv_vmbus.h | 2 +- drivers/hv/mshv.h | 156 ++ drivers/hv/mshv_eventfd.c | 758 +++++++ drivers/hv/mshv_eventfd.h | 80 + drivers/hv/mshv_main.c | 208 ++ drivers/hv/mshv_msi.c | 129 ++ drivers/hv/mshv_portid_table.c | 84 + drivers/hv/mshv_root.h | 194 ++ drivers/hv/mshv_root_hv_call.c | 1064 +++++++++ drivers/hv/mshv_root_main.c | 1964 +++++++++++++++++ drivers/hv/mshv_synic.c | 689 ++++++ drivers/hv/mshv_vtl.h | 52 + drivers/hv/mshv_vtl_main.c | 1541 +++++++++++++ drivers/hv/vmbus_drv.c | 3 +- drivers/hv/xfer_to_guest.c | 28 + include/asm-generic/hyperv-defs.h | 26 + include/asm-generic/hyperv-tlfs.h | 77 +- include/asm-generic/mshyperv.h | 76 +- include/linux/hyperv.h | 11 +- include/uapi/hyperv/hvgdk.h | 41 + include/uapi/hyperv/hvgdk_mini.h | 1077 +++++++++ include/uapi/hyperv/hvhdk.h | 1352 ++++++++++++ include/uapi/hyperv/hvhdk_mini.h | 164 ++ include/uapi/linux/mshv.h | 298 +++ 40 files changed, 10653 insertions(+), 352 deletions(-) create mode 100644 drivers/hv/hv_call.c create mode 100644 drivers/hv/mshv.h create mode 100644 drivers/hv/mshv_eventfd.c create mode 100644 drivers/hv/mshv_eventfd.h create mode 100644 drivers/hv/mshv_main.c create mode 100644 drivers/hv/mshv_msi.c create mode 100644 drivers/hv/mshv_portid_table.c create mode 100644 drivers/hv/mshv_root.h create mode 100644 drivers/hv/mshv_root_hv_call.c create mode 100644 drivers/hv/mshv_root_main.c create mode 100644 drivers/hv/mshv_synic.c create mode 100644 drivers/hv/mshv_vtl.h create mode 100644 drivers/hv/mshv_vtl_main.c create mode 100644 drivers/hv/xfer_to_guest.c create mode 100644 include/asm-generic/hyperv-defs.h create mode 100644 include/uapi/hyperv/hvgdk.h create mode 100644 include/uapi/hyperv/hvgdk_mini.h create mode 100644 include/uapi/hyperv/hvhdk.h create mode 100644 include/uapi/hyperv/hvhdk_mini.h create mode 100644 include/uapi/linux/mshv.h
Signature · 1 line
2.25.1
PATCH 7/15 Drivers: hv: Move hv_call_deposit_pages and hv_call_create_vp to common code
These hypercalls are not arch-specific.
Move them to common code.
--- arch/x86/hyperv/hv_proc.c | 152 -------------------------------- arch/x86/include/asm/mshyperv.h | 2 - drivers/hv/hv_common.c | 147 ++++++++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 2 + 4 files changed, 149 insertions(+), 154 deletions(-)
arch/x86/hyperv/hv_proc.c +0 -152
@@ -3,7 +3,6 @@#include <linux/vmalloc.h> #include <linux/mm.h> #include <linux/clockchips.h> -#include <linux/acpi.h> #include <linux/hyperv.h> #include <linux/slab.h> #include <linux/cpuhotplug.h>
@@ -14,106 +13,6 @@#include <asm/trace/hyperv.h> -/* -* See struct hv_deposit_memory. The first u64 is partition ID, the rest -* are GPAs. -*/ -#define HV_DEPOSIT_MAX (HV_HYP_PAGE_SIZE / sizeof(u64) - 1) - -/* Deposits exact number of pages. Must be called with interrupts enabled. */ -int hv_call_deposit_pages (int node,u64 partition_id,u32 num_pages) -{ -struct page **pages, *page; -int *counts; -int num_allocations; -int i, j, page_count; -int order; -u64 status; -int ret; -u64 base_pfn; -struct hv_deposit_memory *input_page; -unsigned long flags; - -if (num_pages >HV_DEPOSIT_MAX ) -return -E2BIG ; -if (!num_pages) -return 0 ; - -/* One buffer for page pointers and counts */ - page =alloc_page (GFP_KERNEL ); -if (!page) -return -ENOMEM ; - pages =page_address (page); - - counts =kcalloc (HV_DEPOSIT_MAX ,sizeof (int ),GFP_KERNEL ); -if (!counts) { -free_page ((unsigned long )pages); -return -ENOMEM ; - } - -/* Allocate all the pages before disabling interrupts */ - i =0 ; - -while (num_pages) { -/* Find highest order we can actually allocate */ - order =31 -__builtin_clz (num_pages); - -while (1 ) { - pages[i] =alloc_pages_node (node,GFP_KERNEL , order); -if (pages[i]) -break ; -if (!order) { - ret = -ENOMEM ; - num_allocations = i; - goto err_free_allocations; - } - --order; - } - -split_page (pages[i], order); - counts[i] =1 << order; - num_pages -= counts[i]; - i++; - } - num_allocations = i; - -local_irq_save (flags); - - input_page = *this_cpu_ptr (hyperv_pcpu_input_arg); - - input_page->partition_id = partition_id; - -/* Populate gpa_page_list - these will fit on the input page */ -for (i =0 , page_count =0 ; i < num_allocations; ++i) { - base_pfn =page_to_pfn (pages[i]); -for (j =0 ; j < counts[i]; ++j, ++page_count) - input_page->gpa_page_list[page_count] = base_pfn + j; - } - status =hv_do_rep_hypercall (HVCALL_DEPOSIT_MEMORY , - page_count,0 , input_page,NULL ); -local_irq_restore (flags); -if (!hv_result_success (status)) { -pr_err ("Failed to deposit pages: %lld\n" , status); - ret =hv_result (status); - goto err_free_allocations; - } - - ret =0 ; - goto free_buf; - -err_free_allocations: -for (i =0 ; i < num_allocations; ++i) { - base_pfn =page_to_pfn (pages[i]); -for (j =0 ; j < counts[i]; ++j) -__free_page (pfn_to_page (base_pfn + j)); - } - -free_buf: -free_page ((unsigned long )pages); -kfree (counts); -return ret; -} -int hv_call_add_logical_proc (int node,u32 lp_index,u32 apic_id) {struct hv_add_logical_processor_in *input;
@@ -156,54 +55,3 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)return ret; } -int hv_call_create_vp (int node,u64 partition_id,u32 vp_index,u32 flags) -{ -struct hv_create_vp *input; -u64 status; -unsigned long irq_flags; -int ret =HV_STATUS_SUCCESS ; -int pxm =node_to_pxm (node); - -/* Root VPs don't seem to need pages deposited */ -if (partition_id != hv_current_partition_id) { -/* The value 90 is empirically determined. It may change. */ - ret =hv_call_deposit_pages (node, partition_id,90 ); -if (ret) -return ret; - } - -do { -local_irq_save (irq_flags); - - input = *this_cpu_ptr (hyperv_pcpu_input_arg); - - input->partition_id = partition_id; - input->vp_index = vp_index; - input->flags = flags; - input->subnode_type = HvSubnodeAny; -if (node !=NUMA_NO_NODE ) { - input->proximity_domain_info.domain_id = pxm; - input->proximity_domain_info.flags.reserved =0 ; - input->proximity_domain_info.flags.proximity_info_valid =1 ; - input->proximity_domain_info.flags.proximity_preferred =1 ; - }else { - input->proximity_domain_info.as_uint64 =0 ; - } - status =hv_do_hypercall (HVCALL_CREATE_VP , input,NULL ); -local_irq_restore (irq_flags); - -if (hv_result (status) !=HV_STATUS_INSUFFICIENT_MEMORY ) { -if (!hv_result_success (status)) { -pr_err ("%s: vcpu %u, lp %u, %lld\n" , __func__, - vp_index, flags, status); - ret =hv_result (status); - } -break ; - } - ret =hv_call_deposit_pages (node, partition_id,1 ); - - }while (!ret); - -return ret; -} -
arch/x86/include/asm/mshyperv.h +0 -2
@@ -47,9 +47,7 @@ extern u64 hv_current_partition_id;extern union hv_ghcb *__percpu *hv_ghcb_pg; -int hv_call_deposit_pages (int node,u64 partition_id,u32 num_pages);int hv_call_add_logical_proc (int node,u32 lp_index,u32 acpi_id); -int hv_call_create_vp (int node,u64 partition_id,u32 vp_index,u32 flags);static inline u64 hv_do_hypercall (u64 control,void *input,void *output) {
drivers/hv/hv_common.c +147 -0
150 lines not on this page · raw message
include/asm-generic/mshyperv.h +2 -0
@@ -343,6 +343,8 @@ u64 hv_ghcb_hypercall(u64 control, void *input, void *output, u32 input_size);void hyperv_cleanup (void );bool hv_query_ext_cap (u64 cap_query);void hv_setup_dma_ops (struct device *dev,bool coherent); +int hv_call_create_vp (int node,u64 partition_id,u32 vp_index,u32 flags); +int hv_call_deposit_pages (int node,u64 partition_id,u32 num_pages);#else /* CONFIG_HYPERV */ static inline bool hv_is_hyperv_initialized (void ) {return false; }static inline bool hv_is_hibernation_supported (void ) {return false; }
Signature · 1 line
2.25.1
PATCH 8/15 Drivers: hv: Introduce per-cpu event ring tail
In reply to Nuno Das NevesAdd a pointer hv_synic_eventring_tail to track the tail pointer for the SynIC event ring buffer for each SINT.
This will be used by the mshv driver, but must be tracked independently since the driver module could be removed and re-inserted.
--- drivers/hv/hv_common.c | 25 +++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 2 ++ 2 files changed, 27 insertions(+)
drivers/hv/hv_common.c +25 -0
@@ -61,6 +61,16 @@ static void hv_kmsg_dump_unregister(void);static struct ctl_table_header *hv_ctl_table_hdr; +/* +* Per-cpu array holding the tail pointer for the SynIC event ring buffer +* for each SINT. +* +* We cannot maintain this in mshv driver because the tail pointer should +* persist even if the mshv driver is unloaded. +*/ +u8 __percpu **hv_synic_eventring_tail; +EXPORT_SYMBOL_GPL (hv_synic_eventring_tail); +/* * Hyper-V specific initialization and shutdown code that is * common across all architectures. Called from architecture
@@ -332,6 +342,8 @@ int __init hv_common_init(void)if (hv_root_partition) { hyperv_pcpu_output_arg = alloc_percpu(void *);BUG_ON (!hyperv_pcpu_output_arg); + hv_synic_eventring_tail = alloc_percpu(u8 *); +BUG_ON (hv_synic_eventring_tail ==NULL ); } hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index),
@@ -356,6 +368,7 @@ int __init hv_common_init(void)int hv_common_cpu_init (unsigned int cpu) {void **inputarg, **outputarg; +u8 **synic_eventring_tail;u64 msr_vp_index;gfp_t flags;int pgcount = hv_root_partition ?2 :1 ;
@@ -371,6 +384,14 @@ int hv_common_cpu_init(unsigned int cpu)if (hv_root_partition) { outputarg = (void **)this_cpu_ptr (hyperv_pcpu_output_arg); *outputarg = (char *)(*inputarg) +HV_HYP_PAGE_SIZE ; + synic_eventring_tail = (u8 **)this_cpu_ptr (hv_synic_eventring_tail); + *synic_eventring_tail =kcalloc (HV_SYNIC_SINT_COUNT ,sizeof (u8), + flags); + +if (unlikely (!*synic_eventring_tail)) { +kfree (*inputarg); +return -ENOMEM ; + } } msr_vp_index =hv_get_register (HV_MSR_VP_INDEX );
@@ -387,6 +408,7 @@ int hv_common_cpu_die(unsigned int cpu) {unsigned long flags;void **inputarg, **outputarg; +u8 **synic_eventring_tail;void *mem;local_irq_save (flags);
@@ -398,6 +420,9 @@ int hv_common_cpu_die(unsigned int cpu)if (hv_root_partition) { outputarg = (void **)this_cpu_ptr (hyperv_pcpu_output_arg); *outputarg =NULL ; + synic_eventring_tail = (u8 **)this_cpu_ptr (hv_synic_eventring_tail); +kfree (*synic_eventring_tail); + *synic_eventring_tail =NULL ; }local_irq_restore (flags);
include/asm-generic/mshyperv.h +2 -0
@@ -73,6 +73,8 @@ extern bool hv_nested;extern void *__percpu *hyperv_pcpu_input_arg;extern void *__percpu *hyperv_pcpu_output_arg; +extern u8 __percpu **hv_synic_eventring_tail; +extern u64 hv_do_hypercall (u64 control,void *inputaddr,void *outputaddr);extern u64 hv_do_fast_hypercall8 (u16 control,u64 input8);extern bool hv_isolation_type_snp (void );
Signature · 1 line
2.25.1
PATCH 9/15 Drivers: hv: Introduce hv_output_arg_exists in hv_common
In reply to Nuno Das NevesThis is a more flexible approach for determining whether to allocate the output page.
This will be used in both mshv_vtl and root partition.
--- drivers/hv/hv_common.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
drivers/hv/hv_common.c +25 -5
@@ -57,6 +57,18 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg);void *__percpu *hyperv_pcpu_output_arg;EXPORT_SYMBOL_GPL (hyperv_pcpu_output_arg); +/* +* Determine whether output arg is in use, for allocation/deallocation +*/ +static bool hv_output_arg_exists (void ) +{ +bool ret = hv_root_partition ? true : false; +#ifdef CONFIG_MSHV_VTL + ret = true; +#endif +return ret; +} +static void hv_kmsg_dump_unregister (void );static struct ctl_table_header *hv_ctl_table_hdr;
@@ -338,10 +350,12 @@ int __init hv_common_init(void) hyperv_pcpu_input_arg = alloc_percpu(void *);BUG_ON (!hyperv_pcpu_input_arg); -/* Allocate the per-CPU state for output arg for root */ -if (hv_root_partition) { +if (hv_output_arg_exists ()) { hyperv_pcpu_output_arg = alloc_percpu(void *);BUG_ON (!hyperv_pcpu_output_arg); + } + +if (hv_root_partition) { hv_synic_eventring_tail = alloc_percpu(u8 *);BUG_ON (hv_synic_eventring_tail ==NULL ); }
@@ -371,7 +385,7 @@ int hv_common_cpu_init(unsigned int cpu)u8 **synic_eventring_tail;u64 msr_vp_index;gfp_t flags; -int pgcount = hv_root_partition ?2 :1 ; +int pgcount =hv_output_arg_exists () ?2 :1 ;/* hv_cpu_init() can be called with IRQs disabled from hv_resume() */ flags =irqs_disabled () ?GFP_ATOMIC :GFP_KERNEL ;
@@ -381,9 +395,12 @@ int hv_common_cpu_init(unsigned int cpu)if (!(*inputarg))return -ENOMEM ; -if (hv_root_partition) { +if (hv_output_arg_exists ()) { outputarg = (void **)this_cpu_ptr (hyperv_pcpu_output_arg); *outputarg = (char *)(*inputarg) +HV_HYP_PAGE_SIZE ; + } + +if (hv_root_partition) { synic_eventring_tail = (u8 **)this_cpu_ptr (hv_synic_eventring_tail); *synic_eventring_tail =kcalloc (HV_SYNIC_SINT_COUNT ,sizeof (u8), flags);
@@ -417,9 +434,12 @@ int hv_common_cpu_die(unsigned int cpu) mem = *inputarg; *inputarg =NULL ; -if (hv_root_partition) { +if (hv_output_arg_exists ()) { outputarg = (void **)this_cpu_ptr (hyperv_pcpu_output_arg); *outputarg =NULL ; + } + +if (hv_root_partition) { synic_eventring_tail = (u8 **)this_cpu_ptr (hv_synic_eventring_tail);kfree (*synic_eventring_tail); *synic_eventring_tail =NULL ;
Signature · 1 line
2.25.1
PATCH 10/15 x86: hyperv: Add mshv_handler irq handler and setup function
In reply to Nuno Das NevesThis will handle SYNIC interrupts such as intercepts, doorbells, and scheduling messages intended for the mshv driver.
--- arch/x86/kernel/cpu/mshyperv.c | 9 +++++++++ drivers/hv/hv_common.c | 5 +++++ include/asm-generic/mshyperv.h | 2 ++ 3 files changed, 16 insertions(+)
arch/x86/kernel/cpu/mshyperv.c +9 -0
@@ -105,6 +105,7 @@ void hv_set_register(unsigned int reg, u64 value) }EXPORT_SYMBOL_GPL (hv_set_register); +static void (*mshv_handler)(void );static void (*vmbus_handler)(void );static void (*hv_stimer0_handler)(void );static void (*hv_kexec_handler)(void );
@@ -115,6 +116,9 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_hyperv_callback)struct pt_regs *old_regs =set_irq_regs (regs);inc_irq_stat (irq_hv_callback_count); +if (mshv_handler) +mshv_handler (); +if (vmbus_handler)vmbus_handler ();
@@ -139,6 +143,11 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_hyperv_nested_vmbus_intr)set_irq_regs (old_regs); } +void hv_setup_mshv_irq (void (*handler)(void )) +{ + mshv_handler = handler; +} +void hv_setup_vmbus_handler (void (*handler)(void )) { vmbus_handler = handler;
drivers/hv/hv_common.c +5 -0
@@ -557,6 +557,11 @@ void __weak hv_remove_vmbus_handler(void) }EXPORT_SYMBOL_GPL (hv_remove_vmbus_handler); +void __weak hv_setup_mshv_irq (void (*handler)(void )) +{ +} +EXPORT_SYMBOL_GPL (hv_setup_mshv_irq); +void __weak hv_setup_kexec_handler (void (*handler)(void )) { }
include/asm-generic/mshyperv.h +2 -0
@@ -193,6 +193,8 @@ void hv_remove_vmbus_handler(void);void hv_setup_stimer0_handler (void (*handler)(void ));void hv_remove_stimer0_handler (void ); +void hv_setup_mshv_irq (void (*handler)(void )); +void hv_setup_kexec_handler (void (*handler)(void ));void hv_remove_kexec_handler (void );void hv_setup_crash_handler (void (*handler)(struct pt_regs *regs));
Signature · 1 line
2.25.1
PATCH 12/15 Documentation: Reserve ioctl number for mshv driver
In reply to Nuno Das Neves--- Documentation/userspace-api/ioctl/ioctl-number.rst | 2 ++ 1 file changed, 2 insertions(+)
Documentation/userspace-api/ioctl/ioctl-number.rst +2 -0
@@ -355,6 +355,8 @@ Code Seq# Include File Comments 0xB6 all linux/fpga-dfl.h 0xB7 all uapi/linux/remoteproc_cdev.h <mailto:[email protected]> 0xB7 all uapi/linux/nsfs.h <mailto:Andrei Vagin <[email protected]>> +0xB8 all uapi/linux/mshv.h Microsoft Hypervisor VM management APIs + <mailto:[email protected]> 0xC0 00-0F linux/usb/iowarrior.h 0xCA 00-0F uapi/misc/cxl.h 0xCA 10-2F uapi/misc/ocxl.h
Signature · 1 line
2.25.1
PATCH 14/15 asm-generic: hyperv: Use mshv headers conditionally. Add asm-generic/hyperv-defs.h
In reply to Nuno Das NevesIn order to keep unstable hyper-v interfaces independent of hyperv-tlfs.h, hvhdk.h must replace hyperv-tlfs.h eveywhere it will be used in the mshv driver.
Add hyperv-defs.h to replace some inclusions of hyperv-tlfs.h. It includes hyperv-tlfs.h or hvhdk.h depending on a compile-time constant HV_HYPERV_DEFS which will be defined in the mshv driver.
--- arch/arm64/include/asm/mshyperv.h | 2 +- arch/x86/include/asm/mshyperv.h | 3 +-- drivers/hv/hyperv_vmbus.h | 1 - include/asm-generic/hyperv-defs.h | 26 ++++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 2 +- include/linux/hyperv.h | 2 +- 6 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 include/asm-generic/hyperv-defs.h
arch/arm64/include/asm/mshyperv.h +1 -1
@@ -20,7 +20,7 @@#include <linux/types.h> #include <linux/arm-smccc.h> -#include <asm/hyperv-tlfs.h> +#include <asm-generic/hyperv-defs.h> /* * Declare calls to get and set Hyper-V VP register values on ARM64, which
arch/x86/include/asm/mshyperv.h +1 -2
@@ -6,10 +6,9 @@#include <linux/nmi.h> #include <linux/msi.h> #include <asm/io.h> -#include <asm/hyperv-tlfs.h> #include <asm/nospec-branch.h> #include <asm/paravirt.h> -#include <asm/mshyperv.h> +#include <asm-generic/hyperv-defs.h> /* * Hyper-V always provides a single IO-APIC at this MMIO address.
drivers/hv/hyperv_vmbus.h +0 -1
@@ -15,7 +15,6 @@#include <linux/list.h> #include <linux/bitops.h> #include <asm/sync_bitops.h> -#include <asm/hyperv-tlfs.h> #include <linux/atomic.h> #include <linux/hyperv.h> #include <linux/interrupt.h>
include/asm-generic/hyperv-defs.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_HYPERV_DEFS_H +#define _ASM_GENERIC_HYPERV_DEFS_H + +/* +* There are cases where Microsoft Hypervisor ABIs are needed which may not be +* stable or present in the Hyper-V TLFS document. E.g. the mshv_root driver. +* +* As these interfaces are unstable and may differ from hyperv-tlfs.h, they +* must be kept separate and independent. +* +* However, code from files that depend on hyperv-tlfs.h (such as mshyperv.h) +* is still needed, so work around the issue by conditionally including the +* correct definitions. +* +* Note: Since they are independent of each other, there are many definitions +* duplicated in both hyperv-tlfs.h and uapi/hyperv/hv*.h files. +*/ +#ifdef HV_HYPERV_DEFS +#include <uapi/hyperv/hvhdk.h> +#else +#include <asm/hyperv-tlfs.h> +#endif + +#endif /* _ASM_GENERIC_HYPERV_DEFS_H */ +
include/asm-generic/mshyperv.h +1 -1
@@ -25,7 +25,7 @@#include <linux/cpumask.h> #include <linux/nmi.h> #include <asm/ptrace.h> -#include <asm/hyperv-tlfs.h> +#include <asm-generic/hyperv-defs.h> #define VTPM_BASE_ADDRESS 0xfed40000
include/linux/hyperv.h +1 -1
@@ -24,7 +24,7 @@#include <linux/mod_devicetable.h> #include <linux/interrupt.h> #include <linux/reciprocal_div.h> -#include <asm/hyperv-tlfs.h> +#include <asm-generic/hyperv-defs.h> #define MAX_PAGE_BUFFER_COUNT 32#define MAX_MULTIPAGE_BUFFER_COUNT 32/* 128K */
Signature · 1 line
2.25.1
PATCH 11/15 Drivers: hv: export vmbus_isr, hv_context and hv_post_message
In reply to Nuno Das NevesThese will be used by the mshv_vtl driver.
--- drivers/hv/hv.c | 2 ++ drivers/hv/hyperv_vmbus.h | 1 + drivers/hv/vmbus_drv.c | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-)
drivers/hv/hv.c +2 -0
@@ -24,6 +24,7 @@/* The one and only */ struct hv_context hv_context; +EXPORT_SYMBOL_GPL (hv_context);/* * hv_init - Main initialization routine.
@@ -80,6 +81,7 @@ int hv_post_message(union hv_connection_id connection_id,return hv_result (status); } +EXPORT_SYMBOL_GPL (hv_post_message);int hv_synic_alloc (void ) {
drivers/hv/hyperv_vmbus.h +1 -0
@@ -32,6 +32,7 @@*/ #define HV_UTIL_NEGO_TIMEOUT 55 +void vmbus_isr (void );/* Definitions for the monitored notification facility */ union hv_monitor_trigger_group {
drivers/hv/vmbus_drv.c +2 -1
@@ -1286,7 +1286,7 @@ static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu) } } -static void vmbus_isr (void ) +void vmbus_isr (void ) {struct hv_per_cpu_context *hv_cpu =this_cpu_ptr (hv_context.cpu_context);
@@ -1309,6 +1309,7 @@ static void vmbus_isr(void)add_interrupt_randomness (vmbus_interrupt); } +EXPORT_SYMBOL_GPL (vmbus_isr);static irqreturn_t vmbus_percpu_isr (int irq,void *dev_id) {
Signature · 1 line
2.25.1
PATCH 2/15 mshyperv: Introduce hv_get_hypervisor_version
In reply to Nuno Das Nevesx86_64 and arm64 implementations to get the hypervisor version information.
Also introduce hv_hypervisor_version_info structure to simplify parsing the fields.
Replace the existing parsing when printing the version numbers.
--- arch/arm64/hyperv/mshyperv.c | 23 +++++++++++------- arch/x86/kernel/cpu/mshyperv.c | 40 ++++++++++++++++++++----------- include/asm-generic/hyperv-tlfs.h | 23 ++++++++++++++++++ include/asm-generic/mshyperv.h | 2 ++ 4 files changed, 66 insertions(+), 22 deletions(-)
arch/arm64/hyperv/mshyperv.c +15 -8
@@ -19,10 +19,19 @@static bool hyperv_initialized; +int hv_get_hypervisor_version (union hv_hypervisor_version_info *info) +{ +hv_get_vpreg_128 (HV_REGISTER_HYPERVISOR_VERSION , + (struct hv_get_vp_registers_output *)info); + +return 0 ; +} +EXPORT_SYMBOL_GPL (hv_get_hypervisor_version); +static int __init hyperv_init (void ) { -struct hv_get_vp_registers_output result; -u32 a, b, c, d; +struct hv_get_vp_registers_output result; +union hv_hypervisor_version_info version;u64 guest_id;int ret;
@@ -55,13 +64,11 @@ static int __init hyperv_init(void) ms_hyperv.misc_features);/* Get information about the Hyper-V host version */ -hv_get_vpreg_128 (HV_REGISTER_HYPERVISOR_VERSION , &result); - a = result.as32.a; - b = result.as32.b; - c = result.as32.c; - d = result.as32.d; +hv_get_hypervisor_version (&version);pr_info ("Hyper-V: Host Build %d.%d.%d.%d-%d-%d\n" , - b >>16 , b &0xFFFF , a, d &0xFFFFFF , c, d >>24 ); + version.major_version, version.minor_version, + version.build_number, version.service_number, + version.service_pack, version.service_branch); ret =hv_common_init ();if (ret)
arch/x86/kernel/cpu/mshyperv.c +26 -14
@@ -328,13 +328,30 @@ static void __init hv_smp_prepare_cpus(unsigned int max_cpus) }#endif +int hv_get_hypervisor_version (union hv_hypervisor_version_info *info) +{ +unsigned int hv_max_functions; + + hv_max_functions =cpuid_eax (HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS ); +if (hv_max_functions <HYPERV_CPUID_VERSION ) { +pr_err ("%s: Could not detect Hyper-V version\n" , + __func__); +return -ENODEV ; + } + + info->eax =cpuid_eax (HYPERV_CPUID_VERSION ); + info->ebx =cpuid_ebx (HYPERV_CPUID_VERSION ); + info->ecx =cpuid_ecx (HYPERV_CPUID_VERSION ); + info->edx =cpuid_edx (HYPERV_CPUID_VERSION ); + +return 0 ; +} +EXPORT_SYMBOL_GPL (hv_get_hypervisor_version); +static void __init ms_hyperv_init_platform (void ) {int hv_max_functions_eax; -int hv_host_info_eax; -int hv_host_info_ebx; -int hv_host_info_ecx; -int hv_host_info_edx; +union hv_hypervisor_version_info version;#ifdef CONFIG_PARAVIRT pv_info.name ="Hyper-V" ;
@@ -388,16 +405,11 @@ static void __init ms_hyperv_init_platform(void)/* * Extract host information. */ -if (hv_max_functions_eax >=HYPERV_CPUID_VERSION ) { - hv_host_info_eax =cpuid_eax (HYPERV_CPUID_VERSION ); - hv_host_info_ebx =cpuid_ebx (HYPERV_CPUID_VERSION ); - hv_host_info_ecx =cpuid_ecx (HYPERV_CPUID_VERSION ); - hv_host_info_edx =cpuid_edx (HYPERV_CPUID_VERSION ); - -pr_info ("Hyper-V: Host Build %d.%d.%d.%d-%d-%d\n" , - hv_host_info_ebx >>16 , hv_host_info_ebx &0xFFFF , - hv_host_info_eax, hv_host_info_edx &0xFFFFFF , - hv_host_info_ecx, hv_host_info_edx >>24 ); +if (hv_get_hypervisor_version (&version) ==0 ) { +pr_info ("Hyper-V Host Build:%d-%d.%d-%d-%d.%d\n" , + version.build_number, version.major_version, + version.minor_version, version.service_pack, + version.service_branch, version.service_number); } if (ms_hyperv.features & HV_ACCESS_FREQUENCY_MSRS &&
include/asm-generic/hyperv-tlfs.h +23 -0
@@ -786,6 +786,29 @@ struct hv_input_unmap_device_interrupt {#define HV_SOURCE_SHADOW_NONE 0x0#define HV_SOURCE_SHADOW_BRIDGE_BUS_RANGE 0x1 +/* +* Version info reported by hypervisor +*/ +union hv_hypervisor_version_info { +struct { +u32 build_number; + +u32 minor_version :16 ; +u32 major_version :16 ; + +u32 service_pack; + +u32 service_number :24 ; +u32 service_branch :8 ; + }; +struct { +u32 eax; +u32 ebx; +u32 ecx; +u32 edx; + }; +}; +/* * The whole argument should fit in a page to be able to pass to the hypervisor * in one hypercall.
include/asm-generic/mshyperv.h +2 -0
@@ -153,6 +153,8 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type) } } +int hv_get_hypervisor_version (union hv_hypervisor_version_info *info); +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.25.1
PATCH 13/15 uapi: hyperv: Add mshv driver headers hvhdk.h, hvhdk_mini.h, hvgdk.h, hvgdk_mini.h
In reply to Nuno Das NevesContaining hypervisor ABI definitions to use in mshv driver.
Version numbers for each file:hvhdk.h 25212hvhdk_mini.h 25294hvgdk.h 25125hvgdk_mini.h 25294
These are unstable interfaces and as such must be compiled independently from published interfaces found in hyperv-tlfs.h.
These are in uapi because they will be used in the mshv ioctl API.
--- include/uapi/hyperv/hvgdk.h | 41 + include/uapi/hyperv/hvgdk_mini.h | 1077 ++++++++++++++++++++++++ include/uapi/hyperv/hvhdk.h | 1352 ++++++++++++++++++++++++++++++ include/uapi/hyperv/hvhdk_mini.h | 164 ++++ 4 files changed, 2634 insertions(+) create mode 100644 include/uapi/hyperv/hvgdk.h create mode 100644 include/uapi/hyperv/hvgdk_mini.h create mode 100644 include/uapi/hyperv/hvhdk.h create mode 100644 include/uapi/hyperv/hvhdk_mini.h
include/uapi/hyperv/hvgdk.h new file +41 -0
@@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright (c) 2023, Microsoft Corporation. +* +* These files (hvhdk.h, hvhdk_mini.h, hvgdk.h, hvgdk_mini.h) define APIs for +* communicating with the Microsoft Hypervisor. +* +* These definitions are subject to change across hypervisor versions, and as +* such are separate and independent from hyperv-tlfs.h. +* +* The naming of these headers reflects conventions used in the Microsoft +* Hypervisor. +*/ +#ifndef _UAPI_HV_HVGDK_H +#define _UAPI_HV_HVGDK_H + +#include "hvgdk_mini.h" + +enum hv_unimplemented_msr_action { +HV_UNIMPLEMENTED_MSR_ACTION_FAULT =0 , +HV_UNIMPLEMENTED_MSR_ACTION_IGNORE_WRITE_READ_ZERO =1 , +HV_UNIMPLEMENTED_MSR_ACTION_COUNT =2 , +}; + +/* Define connection identifier type. */ +union hv_connection_id { +__u32 asu32; +struct { +__u32 id:24 ; +__u32 reserved:8 ; + } __packed u; +}; + +struct hv_input_unmap_gpa_pages { +__u64 target_partition_id; +__u64 target_gpa_base; +__u32 unmap_flags; +__u32 padding; +} __packed; + +#endif /* #ifndef _UAPI_HV_HVGDK_H */
include/uapi/hyperv/hvgdk_mini.h new file +1077 -0
1,077 lines not on this page · raw message
include/uapi/hyperv/hvhdk.h new file +1352 -0
1,352 lines not on this page · raw message
include/uapi/hyperv/hvhdk_mini.h new file +164 -0
164 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 15/15 Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
In reply to Nuno Das NevesAdd mshv, mshv_root, and mshv_vtl modules.
- mshv provides /dev/mshv and common code, and is the parent module
- mshv_root provides APIs for creating and managing child partitions
- mshv_vtl provides VTL (Virtual Trust Level) support for VMMs
--- drivers/hv/Kconfig | 54 + drivers/hv/Makefile | 21 + drivers/hv/hv_call.c | 119 ++ drivers/hv/mshv.h | 156 +++ drivers/hv/mshv_eventfd.c | 758 ++++++++++++ drivers/hv/mshv_eventfd.h | 80 ++ drivers/hv/mshv_main.c | 208 ++++ drivers/hv/mshv_msi.c | 129 +++ drivers/hv/mshv_portid_table.c | 84 ++ drivers/hv/mshv_root.h | 194 ++++ drivers/hv/mshv_root_hv_call.c | 1064 +++++++++++++++++ drivers/hv/mshv_root_main.c | 1964 ++++++++++++++++++++++++++++++++ drivers/hv/mshv_synic.c | 689 +++++++++++ drivers/hv/mshv_vtl.h | 52 + drivers/hv/mshv_vtl_main.c | 1541 +++++++++++++++++++++++++ drivers/hv/xfer_to_guest.c | 28 + include/uapi/linux/mshv.h | 298 +++++ 17 files changed, 7439 insertions(+) create mode 100644 drivers/hv/hv_call.c create mode 100644 drivers/hv/mshv.h create mode 100644 drivers/hv/mshv_eventfd.c create mode 100644 drivers/hv/mshv_eventfd.h create mode 100644 drivers/hv/mshv_main.c create mode 100644 drivers/hv/mshv_msi.c create mode 100644 drivers/hv/mshv_portid_table.c create mode 100644 drivers/hv/mshv_root.h create mode 100644 drivers/hv/mshv_root_hv_call.c create mode 100644 drivers/hv/mshv_root_main.c create mode 100644 drivers/hv/mshv_synic.c create mode 100644 drivers/hv/mshv_vtl.h create mode 100644 drivers/hv/mshv_vtl_main.c create mode 100644 drivers/hv/xfer_to_guest.c create mode 100644 include/uapi/linux/mshv.h
drivers/hv/Kconfig +54 -0
@@ -54,4 +54,58 @@ config HYPERV_BALLOON help Select this option to enable Hyper-V Balloon driver. +config MSHV + tristate "Microsoft Hypervisor root partition interfaces: /dev/mshv" + depends on X86_64 && HYPERV + select EVENTFD + select MSHV_VFIO + select MSHV_XFER_TO_GUEST_WORK + help + Select this option to enable core functionality for managing guest + virtual machines running under the Microsoft Hypervisor. + + The interfaces are provided via a device named /dev/mshv. + + To compile this as a module, choose M here. + + If unsure, say N. + +config MSHV_ROOT + tristate "Microsoft Hyper-V root partition APIs driver" + depends on MSHV + help + Select this option to provide /dev/mshv interfaces specific to + running as the root partition on Microsoft Hypervisor. + + To compile this as a module, choose M here. + + If unsure, say N. + +config MSHV_VTL + tristate "Microsoft Hyper-V VTL driver" + depends on MSHV + select HYPERV_VTL_MODE + select TRANSPARENT_HUGEPAGE + help + Select this option to enable Hyper-V VTL driver. + Virtual Secure Mode (VSM) is a set of hypervisor capabilities and + enlightenments offered to host and guest partitions which enables + the creation and management of new security boundaries within + operating system software. + + VSM achieves and maintains isolation through Virtual Trust Levels + (VTLs). Virtual Trust Levels are hierarchical, with higher levels + being more privileged than lower levels. VTL0 is the least privileged + level, and currently only other level supported is VTL2. + + To compile this as a module, choose M here. + + If unsure, say N. + +config MSHV_VFIO + bool + +config MSHV_XFER_TO_GUEST_WORK + bool + endmenu
drivers/hv/Makefile +21 -0
@@ -2,10 +2,31 @@ obj-$(CONFIG_HYPERV) += hv_vmbus.o obj-$(CONFIG_HYPERV_UTILS) += hv_utils.o obj-$(CONFIG_HYPERV_BALLOON) += hv_balloon.o +obj-$(CONFIG_DXGKRNL) += dxgkrnl/ +obj-$(CONFIG_MSHV) += mshv.o +obj-$(CONFIG_MSHV_VTL) += mshv_vtl.o +obj-$(CONFIG_MSHV_ROOT) += mshv_root.o CFLAGS_hv_trace.o = -I$(src) CFLAGS_hv_balloon.o = -I$(src) +CFLAGS_mshv_main.o = -DHV_HYPERV_DEFS +CFLAGS_hv_call.o = -DHV_HYPERV_DEFS +CFLAGS_mshv_root_main.o = -DHV_HYPERV_DEFS +CFLAGS_mshv_root_hv_call.o = -DHV_HYPERV_DEFS +CFLAGS_mshv_synic.o = -DHV_HYPERV_DEFS +CFLAGS_mshv_portid_table.o = -DHV_HYPERV_DEFS +CFLAGS_mshv_eventfd.o = -DHV_HYPERV_DEFS +CFLAGS_mshv_msi.o = -DHV_HYPERV_DEFS +CFLAGS_mshv_vtl_main.o = -DHV_HYPERV_DEFS + +mshv-y += mshv_main.o +mshv_root-y := mshv_root_main.o mshv_synic.o mshv_portid_table.o \ + mshv_eventfd.o mshv_msi.o mshv_root_hv_call.o hv_call.o +mshv_vtl-y := mshv_vtl_main.o hv_call.o + +obj-$(CONFIG_MSHV_XFER_TO_GUEST_WORK) += xfer_to_guest.o + hv_vmbus-y := vmbus_drv.o \ hv.o connection.o channel.o \ channel_mgmt.o ring_buffer.o hv_trace.o
drivers/hv/hv_call.c new file +119 -0
119 lines not on this page · raw message
drivers/hv/mshv.h new file +156 -0
156 lines not on this page · raw message
drivers/hv/mshv_eventfd.c new file +758 -0
758 lines not on this page · raw message
drivers/hv/mshv_eventfd.h new file +80 -0
80 lines not on this page · raw message
drivers/hv/mshv_main.c new file +208 -0
208 lines not on this page · raw message
drivers/hv/mshv_msi.c new file +129 -0
129 lines not on this page · raw message
drivers/hv/mshv_portid_table.c new file +84 -0
84 lines not on this page · raw message
drivers/hv/mshv_root.h new file +194 -0
194 lines not on this page · raw message
drivers/hv/mshv_root_hv_call.c new file +1064 -0
1,064 lines not on this page · raw message
drivers/hv/mshv_root_main.c new file +1964 -0
119 lines not on this page · raw message
drivers/hv/mshv_synic.c new file +689 -0
689 lines not on this page · raw message
drivers/hv/mshv_vtl.h new file +52 -0
52 lines not on this page · raw message
drivers/hv/mshv_vtl_main.c new file +1541 -0
1,541 lines not on this page · raw message
include/uapi/linux/mshv.h new file +298 -0
298 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.25.1
Part of the diff is not shown here. View the raw message.
Apologies, it seems patch 15 bouncing from some mailing lists. As a workaround, here is a link to the patch on github while we figure out a solution:
https://github.com/NunoDasNeves/linux/commit/54329d18d68b0cbff4f1e0aeba00bc6dd9a21288
Quoted 159 lines · Nuno Das Neves
This series introduces support for creating and running guest machines while running on the Microsoft Hypervisor. [0]
This is done via an IOCTL interface accessed through/dev/mshv, similar to/dev/kvm. Another series introducing this support was previously posted.
[1]These interfaces support VMMs running in:
1. The root patition - provided in themshv_rootmodule, and
2. VTL 2 - provided in themshv_vtlmodule [2]Patches breakdown
-----------------
The first 7 patches are refactoring and adding some helper functions. They provide some benefit on their own and could be applied independently as cleanup patches.The following 5 patches just set things up for the driver code to come. These are very small. They are separated so that the remaining patches are more self-contained.
The final 3 patches are the meat of the series:
- Patch 13 contains new header files used by the driver.
These are designed to mirror the ABI headers exported by Hyper-V. This is done to avoid pollutinghyperv-tlfs.hand help track changes to the ABIs that are still unstable. (See FAQ below).
- Patch 14 conditionally includes these new header files intomshyperv.handlinux/hyperv.h, in order to be able to use these files in the new drivers while remaining independent fromhyperv-tlfs.h.
- Patch 15 contains the new driver code located indrivers/hv. This is a large amount of code and new files, but it is mostly self-contained and all withindrivers/hv- apart from the IOCTL interface itself in uapi.FAQ on
include/uapi/hyperv/*.h
------------------------------
Q:
Why not just add these definitions tohyperv-tlfs.h?
A:
The intention ofhyperv-tlfs.his to contain stable definitions documented in the public TLFS document. These new definitions don't fit that criteria, so they should be separate.Q:
Why are these files namedhvgdk.h,hvgdk_mini.h,hvhdk.handhvhdk_mini.h? A:
The precise meaning of the names reflects conventions used internally at Microsoft.
Naming them this way makes it easy to find where particular Hyper-V definitions come from, and check their correctness.
It also facilitates the future work of automatically generating these files.Q:
Why are they in uapi?
A:
In short, to keep things simple. There are many definitions needed in both the kernel and the VMM in userspace. Separating them doesn't serve much purpose, and makes it more laborious to import definitions from Hyper-V code.Q:
The new headers redefine many things that are already inhyperv-tlfs.h- why? A:
Some definitions are extended compared to what is documented in the TLFS. In order to avoid adding undocumented or unstable definitions tohyperv-tlfs.h, the new headers must compile independently.
Therefore, the new headers must redefine many things inhyperv-tlfs.hin order to compile.--------------------------
[0] "Hyper-V" is more well-known, but it really refers to the whole stack including the hypervisor and other components that run in Windows kernel and userspace.
[1] Previous/dev/mshvpatch series and discussion:https://lore.kernel.org/linux-hyperv/1632853875-20261-1-git-send-email-nunodasneves@linux.microsoft.com/[2] Virtual Secure Mode (VSM) and Virtual Trust Levels (VTL):
https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/vsmNuno Das Neves (15):
hyperv-tlfs: Change shared HV_REGISTER_* defines to HV_MSR_*
mshyperv: Introducehv_get_hypervisor_version
mshyperv: Introducenuma_node_to_proximity_domain_infoasm-generic/mshyperv: Introducehv_recommend_using_aeoi()
hyperv: Movehv_connection_idto hyperv-tlfs
hyperv-tlfs: Introducehv_status_to_stringandhv_status_to_errno
Drivers: hv: Movehv_call_deposit_pagesandhv_call_create_vpto
common code
Drivers: hv: Introduce per-cpu event ring tail
Drivers: hv: Introducehv_output_arg_existsinhv_common
x86: hyperv: Addmshv_handlerirq handler and setup function
Drivers: hv: exportvmbus_isr,hv_contextandhv_post_message
Documentation: Reserve ioctl number for mshv driver
uapi: hyperv: Add mshv driver headershvhdk.h,hvhdk_mini.h,hvgdk.h,
hvgdk_mini.h
asm-generic: hyperv: Use mshv headers conditionally. Add
asm-generic/hyperv-defs.h
Drivers: hv: Add modules to expose/dev/mshvto VMMs running on
Hyper-V.../userspace-api/ioctl/ioctl-number.rst | 2 + arch/arm64/hyperv/mshyperv.c | 23 +- arch/arm64/include/asm/hyperv-tlfs.h | 25 + arch/arm64/include/asm/mshyperv.h | 2 +- arch/x86/hyperv/hv_init.c | 2 +- arch/x86/hyperv/hv_proc.c | 166 +- arch/x86/include/asm/hyperv-tlfs.h | 137 +- arch/x86/include/asm/mshyperv.h | 13 +- arch/x86/kernel/cpu/mshyperv.c | 71 +- drivers/acpi/numa/srat.c | 1 + drivers/clocksource/hyperv_timer.c | 24 +- drivers/hv/Kconfig | 54 + drivers/hv/Makefile | 21 + drivers/hv/hv.c | 46 +- drivers/hv/hv_call.c | 119 + drivers/hv/hv_common.c | 225 +- drivers/hv/hyperv_vmbus.h | 2 +- drivers/hv/mshv.h | 156 ++ drivers/hv/mshv_eventfd.c | 758 +++++++ drivers/hv/mshv_eventfd.h | 80 + drivers/hv/mshv_main.c | 208 ++ drivers/hv/mshv_msi.c | 129 ++ drivers/hv/mshv_portid_table.c | 84 + drivers/hv/mshv_root.h | 194 ++ drivers/hv/mshv_root_hv_call.c | 1064 +++++++++ drivers/hv/mshv_root_main.c | 1964 +++++++++++++++++ drivers/hv/mshv_synic.c | 689 ++++++ drivers/hv/mshv_vtl.h | 52 + drivers/hv/mshv_vtl_main.c | 1541 +++++++++++++ drivers/hv/vmbus_drv.c | 3 +- drivers/hv/xfer_to_guest.c | 28 + include/asm-generic/hyperv-defs.h | 26 + include/asm-generic/hyperv-tlfs.h | 77 +- include/asm-generic/mshyperv.h | 76 +- include/linux/hyperv.h | 11 +- include/uapi/hyperv/hvgdk.h | 41 + include/uapi/hyperv/hvgdk_mini.h | 1077 +++++++++ include/uapi/hyperv/hvhdk.h | 1352 ++++++++++++ include/uapi/hyperv/hvhdk_mini.h | 164 ++ include/uapi/linux/mshv.h | 298 +++ 40 files changed, 10653 insertions(+), 352 deletions(-) create mode 100644 drivers/hv/hv_call.c create mode 100644 drivers/hv/mshv.h create mode 100644 drivers/hv/mshv_eventfd.c create mode 100644 drivers/hv/mshv_eventfd.h create mode 100644 drivers/hv/mshv_main.c create mode 100644 drivers/hv/mshv_msi.c create mode 100644 drivers/hv/mshv_portid_table.c create mode 100644 drivers/hv/mshv_root.h create mode 100644 drivers/hv/mshv_root_hv_call.c create mode 100644 drivers/hv/mshv_root_main.c create mode 100644 drivers/hv/mshv_synic.c create mode 100644 drivers/hv/mshv_vtl.h create mode 100644 drivers/hv/mshv_vtl_main.c create mode 100644 drivers/hv/xfer_to_guest.c create mode 100644 include/asm-generic/hyperv-defs.h create mode 100644 include/uapi/hyperv/hvgdk.h create mode 100644 include/uapi/hyperv/hvgdk_mini.h create mode 100644 include/uapi/hyperv/hvhdk.h create mode 100644 include/uapi/hyperv/hvhdk_mini.h create mode 100644 include/uapi/linux/mshv.h
Wei Liu
maintainerRe: [PATCH 02/15] mshyperv: Introduce hv_get_hypervisor_version
In reply to Nuno Das NevesQuoted 5 lines · Nuno Das Neves
x86_64and arm64 implementations to get the hypervisor version information.
Also introducehv_hypervisor_version_infostructure to simplify parsing the fields.
Replace the existing parsing when printing the version numbers.
The line wrapping looks odd. When you resend, please fix it. If you meant to use multiple paragraphs, please insert a blank line between them.
x86 and ARM maintainers, I don't think there is anything particularly interesting to you, but I guess you're CC'ed because some of the files fall under the respective directories. Feel free to ignore this patch.
The code looks fine to me -- it is mostly just refactoring.
Thanks,
Wei.
Quoted 164 lines
Signed-off-by Nuno Das Neves <[email protected]>--- arch/arm64/hyperv/mshyperv.c | 23 +++++++++++------- arch/x86/kernel/cpu/mshyperv.c | 40 ++++++++++++++++++++----------- include/asm-generic/hyperv-tlfs.h | 23 ++++++++++++++++++ include/asm-generic/mshyperv.h | 2 ++ 4 files changed, 66 insertions(+), 22 deletions(-)arch/arm64/hyperv/mshyperv.c +15
-8@@ -19,10 +19,19 @@static bool hyperv_initialized; +int hv_get_hypervisor_version (union hv_hypervisor_version_info *info) +{ +hv_get_vpreg_128 (HV_REGISTER_HYPERVISOR_VERSION , + (struct hv_get_vp_registers_output *)info); + +return 0 ; +} +EXPORT_SYMBOL_GPL (hv_get_hypervisor_version); +static int __init hyperv_init (void ) { -struct hv_get_vp_registers_output result; -u32 a, b, c, d; +struct hv_get_vp_registers_output result; +union hv_hypervisor_version_info version;u64 guest_id;int ret;@@ -55,13 +64,11 @@ static int __init hyperv_init(void) ms_hyperv.misc_features);/* Get information about the Hyper-V host version */ -hv_get_vpreg_128 (HV_REGISTER_HYPERVISOR_VERSION , &result); - a = result.as32.a; - b = result.as32.b; - c = result.as32.c; - d = result.as32.d; +hv_get_hypervisor_version (&version);pr_info ("Hyper-V: Host Build %d.%d.%d.%d-%d-%d\n" , - b >>16 , b &0xFFFF , a, d &0xFFFFFF , c, d >>24 ); + version.major_version, version.minor_version, + version.build_number, version.service_number, + version.service_pack, version.service_branch); ret =hv_common_init ();if (ret)arch/x86/kernel/cpu/mshyperv.c +26
-14@@ -328,13 +328,30 @@ static void __init hv_smp_prepare_cpus(unsigned int max_cpus) }#endif +int hv_get_hypervisor_version (union hv_hypervisor_version_info *info) +{ +unsigned int hv_max_functions; + + hv_max_functions =cpuid_eax (HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS ); +if (hv_max_functions <HYPERV_CPUID_VERSION ) { +pr_err ("%s: Could not detect Hyper-V version\n" , + __func__); +return -ENODEV ; + } + + info->eax =cpuid_eax (HYPERV_CPUID_VERSION ); + info->ebx =cpuid_ebx (HYPERV_CPUID_VERSION ); + info->ecx =cpuid_ecx (HYPERV_CPUID_VERSION ); + info->edx =cpuid_edx (HYPERV_CPUID_VERSION ); + +return 0 ; +} +EXPORT_SYMBOL_GPL (hv_get_hypervisor_version); +static void __init ms_hyperv_init_platform (void ) {int hv_max_functions_eax; -int hv_host_info_eax; -int hv_host_info_ebx; -int hv_host_info_ecx; -int hv_host_info_edx; +union hv_hypervisor_version_info version;#ifdef CONFIG_PARAVIRT pv_info.name ="Hyper-V" ;@@ -388,16 +405,11 @@ static void __init ms_hyperv_init_platform(void)/* * Extract host information. */ -if (hv_max_functions_eax >=HYPERV_CPUID_VERSION ) { - hv_host_info_eax =cpuid_eax (HYPERV_CPUID_VERSION ); - hv_host_info_ebx =cpuid_ebx (HYPERV_CPUID_VERSION ); - hv_host_info_ecx =cpuid_ecx (HYPERV_CPUID_VERSION ); - hv_host_info_edx =cpuid_edx (HYPERV_CPUID_VERSION ); - -pr_info ("Hyper-V: Host Build %d.%d.%d.%d-%d-%d\n" , - hv_host_info_ebx >>16 , hv_host_info_ebx &0xFFFF , - hv_host_info_eax, hv_host_info_edx &0xFFFFFF , - hv_host_info_ecx, hv_host_info_edx >>24 ); +if (hv_get_hypervisor_version (&version) ==0 ) { +pr_info ("Hyper-V Host Build:%d-%d.%d-%d-%d.%d\n" , + version.build_number, version.major_version, + version.minor_version, version.service_pack, + version.service_branch, version.service_number); } if (ms_hyperv.features & HV_ACCESS_FREQUENCY_MSRS &&include/asm-generic/hyperv-tlfs.h +23
-0@@ -786,6 +786,29 @@ struct hv_input_unmap_device_interrupt {#define HV_SOURCE_SHADOW_NONE 0x0#define HV_SOURCE_SHADOW_BRIDGE_BUS_RANGE 0x1 +/* +* Version info reported by hypervisor +*/ +union hv_hypervisor_version_info { +struct { +u32 build_number; + +u32 minor_version :16 ; +u32 major_version :16 ; + +u32 service_pack; + +u32 service_number :24 ; +u32 service_branch :8 ; + }; +struct { +u32 eax; +u32 ebx; +u32 ecx; +u32 edx; + }; +}; +/* * The whole argument should fit in a page to be able to pass to the hypervisor * in one hypercall. include/asm-generic/mshyperv.h +2
-0@@ -153,6 +153,8 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type) } } +int hv_get_hypervisor_version (union hv_hypervisor_version_info *info); +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.25.1
Re: [PATCH 03/15] mshyperv: Introduce numa_node_to_proximity_domain_info
In reply to Nuno Das NevesQuoted 4 lines · Nuno Das Neves
Factor out logic for converting numa node to proximity domain info into a helper function, and export it.
Signed-off-by Nuno Das Neves <[email protected]>
Quoted 6 lines
--- arch/x86/hyperv/hv_proc.c | 8 ++------ drivers/acpi/numa/srat.c | 1 + include/asm-generic/mshyperv.h | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-)
[...]
drivers/acpi/numa/srat.c int node_to_pxm(int node) · line 51
Quoted 9 lines
drivers/acpi/numa/srat.c +1
-0@@ -48,6 +48,7 @@ int node_to_pxm(int node)return PXM_INVAL ;return node_to_pxm_map[node]; } +EXPORT_SYMBOL (node_to_pxm);
Rafael and Len, I would like to get an ACK from you on this one line change. I see a lot of other functions in that file are already exported, so I hope this is okay, too.
It's user is the function below numa_node_to_proximity_domain_info.
Thanks,
Wei.
Quoted 42 lines
drivers/acpi/numa/srat.c +0
-0static void __acpi_map_pxm_to_node (int pxm,int node) {include/asm-generic/mshyperv.h +18
-0@@ -21,6 +21,7 @@#include <linux/types.h> #include <linux/atomic.h> #include <linux/bitops.h> +#include <acpi/acpi_numa.h> #include <linux/cpumask.h> #include <linux/nmi.h> #include <asm/ptrace.h> @@ -28,6 +29,23 @@#define VTPM_BASE_ADDRESS 0xfed40000 +static inline union hv_proximity_domain_info +numa_node_to_proximity_domain_info (int node) +{ +union hv_proximity_domain_info proximity_domain_info; + +if (node !=NUMA_NO_NODE ) { + proximity_domain_info.domain_id =node_to_pxm (node); + proximity_domain_info.flags.reserved =0 ; + proximity_domain_info.flags.proximity_info_valid =1 ; + proximity_domain_info.flags.proximity_preferred =1 ; + }else { + proximity_domain_info.as_uint64 =0 ; + } + +return proximity_domain_info; +} +struct ms_hyperv_info {u32 features;u32 priv_high;Signature · 1 line
2.25.1
Re: [PATCH 04/15] asm-generic/mshyperv: Introduce hv_recommend_using_aeoi()
In reply to Nuno Das NevesQuoted 4 lines · Nuno Das Neves
Factor out logic for determining if we should set the auto eoi flag in SINT register.
Signed-off-by Nuno Das Neves <[email protected]>
Wei Liu
maintainerRe: [PATCH 05/15] hyperv: Move hv_connection_id to hyperv-tlfs
In reply to Nuno Das NevesQuoted 2 lines · Nuno Das Neves
This structure should be in
hyperv-tlfs.hanyway, since it is part of the TLFS document.
Missing blank line here.
Quoted 16 lines
The definition conflicts with one added in
hvgdk.has part of the mshv driver so must be moved tohyperv-tlfs.h.Signed-off-by Nuno Das Neves <[email protected]>--- include/asm-generic/hyperv-tlfs.h | 9 +++++++++ include/linux/hyperv.h | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-)include/asm-generic/hyperv-tlfs.h +0
-0@@ -845,4 +845,13 @@ struct hv_mmio_write_input {u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH ]; } __packed;
include/asm-generic/hyperv-tlfs.h struct hv_mmio_write_input { · line 856
Quoted 10 lines
include/asm-generic/hyperv-tlfs.h +9
-0+/* Define connection identifier type. */ +union hv_connection_id { +u32 asu32; +struct { +u32 id:24 ; +u32 reserved:8 ; + } u; +}; +
Missing __packed here, but since this is already aligned it probably doesn't matter much.
Quoted 24 lines
include/asm-generic/hyperv-tlfs.h +0
-0#endif include/linux/hyperv.h +0
-9@@ -748,15 +748,6 @@ struct vmbus_close_msg {struct vmbus_channel_close_channel msg; }; -/* Define connection identifier type. */ -union hv_connection_id { -u32 asu32; -struct { -u32 id:24 ; -u32 reserved:8 ; - } u; -}; -enum vmbus_device_type {HV_IDE =0 ,HV_SCSI ,Signature · 1 line
2.25.1
Re: [PATCH 07/15] Drivers: hv: Move hv_call_deposit_pages and hv_call_create_vp to common code
In reply to Nuno Das NevesQuoted 1 line · Nuno Das Neves
These hypercalls are not arch-specific.
...
Quoted 3 lines
Move them to common code.
Signed-off-by Nuno Das Neves <[email protected]>
Pure code movement so:
Wei Liu
maintainerRe: [PATCH 08/15] Drivers: hv: Introduce per-cpu event ring tail
In reply to Nuno Das NevesQuoted 6 lines · Nuno Das Neves
Add a pointer
hv_synic_eventring_tailto track the tail pointer for the SynIC event ring buffer for each SINT.
This will be used by the mshv driver, but must be tracked independently since the driver module could be removed and re-inserted.Signed-off-by Nuno Das Neves <[email protected]>
I understand the general idea, but see below.
Quoted 67 lines
--- drivers/hv/hv_common.c | 25 +++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 2 ++ 2 files changed, 27 insertions(+)drivers/hv/hv_common.c +22
-0@@ -61,6 +61,16 @@ static void hv_kmsg_dump_unregister(void);static struct ctl_table_header *hv_ctl_table_hdr; +/* +* Per-cpu array holding the tail pointer for the SynIC event ring buffer +* for each SINT. +* +* We cannot maintain this in mshv driver because the tail pointer should +* persist even if the mshv driver is unloaded. +*/ +u8 __percpu **hv_synic_eventring_tail; +EXPORT_SYMBOL_GPL (hv_synic_eventring_tail); +/* * Hyper-V specific initialization and shutdown code that is * common across all architectures. Called from architecture @@ -332,6 +342,8 @@ int __init hv_common_init(void)if (hv_root_partition) { hyperv_pcpu_output_arg = alloc_percpu(void *);BUG_ON (!hyperv_pcpu_output_arg); + hv_synic_eventring_tail = alloc_percpu(u8 *); +BUG_ON (hv_synic_eventring_tail ==NULL ); } hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index),@@ -356,6 +368,7 @@ int __init hv_common_init(void)int hv_common_cpu_init (unsigned int cpu) {void **inputarg, **outputarg; +u8 **synic_eventring_tail;u64 msr_vp_index;gfp_t flags;int pgcount = hv_root_partition ?2 :1 ;@@ -371,6 +384,14 @@ int hv_common_cpu_init(unsigned int cpu)if (hv_root_partition) { outputarg = (void **)this_cpu_ptr (hyperv_pcpu_output_arg); *outputarg = (char *)(*inputarg) +HV_HYP_PAGE_SIZE ; + synic_eventring_tail = (u8 **)this_cpu_ptr (hv_synic_eventring_tail); + *synic_eventring_tail =kcalloc (HV_SYNIC_SINT_COUNT ,sizeof (u8), + flags); + +if (unlikely (!*synic_eventring_tail)) { +kfree (*inputarg); +return -ENOMEM ; + } } msr_vp_index =hv_get_register (HV_MSR_VP_INDEX );@@ -387,6 +408,7 @@ int hv_common_cpu_die(unsigned int cpu) {unsigned long flags;void **inputarg, **outputarg; +u8 **synic_eventring_tail;void *mem;local_irq_save (flags);
drivers/hv/hv_common.c int hv_common_cpu_die(unsigned int cpu) · line 425
Quoted 6 lines
drivers/hv/hv_common.c +3
-0@@ -398,6 +420,9 @@ int hv_common_cpu_die(unsigned int cpu)if (hv_root_partition) { outputarg = (void **)this_cpu_ptr (hyperv_pcpu_output_arg); *outputarg =NULL ; + synic_eventring_tail = (u8 **)this_cpu_ptr (hv_synic_eventring_tail); +kfree (*synic_eventring_tail); + *synic_eventring_tail =NULL ;
The upstream code looks different now. See 9636be85cc.
Quoted 19 lines
drivers/hv/hv_common.c +0
-0}local_irq_restore (flags);include/asm-generic/mshyperv.h +2
-0@@ -73,6 +73,8 @@ extern bool hv_nested;extern void *__percpu *hyperv_pcpu_input_arg;extern void *__percpu *hyperv_pcpu_output_arg; +extern u8 __percpu **hv_synic_eventring_tail; +extern u64 hv_do_hypercall (u64 control,void *inputaddr,void *outputaddr);extern u64 hv_do_fast_hypercall8 (u16 control,u64 input8);extern bool hv_isolation_type_snp (void );Signature · 1 line
2.25.1
Wei Liu
maintainerRe: [PATCH 09/15] Drivers: hv: Introduce hv_output_arg_exists in hv_common
In reply to Nuno Das NevesQuoted 17 lines · Nuno Das Neves
This is a more flexible approach for determining whether to allocate the output page.
This will be used in both
mshv_vtland root partition.Signed-off-by Nuno Das Neves <[email protected]>--- drivers/hv/hv_common.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)drivers/hv/hv_common.c +0
-0@@ -57,6 +57,18 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg);void *__percpu *hyperv_pcpu_output_arg;EXPORT_SYMBOL_GPL (hyperv_pcpu_output_arg);
drivers/hv/hv_common.c EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg); · line 68
Quoted 10 lines
drivers/hv/hv_common.c +9
-0+/* +* Determine whether output arg is in use, for allocation/deallocation +*/ +static bool hv_output_arg_exists (void ) +{ +bool ret = hv_root_partition ? true : false; +#ifdef CONFIG_MSHV_VTL + ret = true; +#endif
This should not be here. As far as I can tell, CONFIG_MSHV_VTL is introduced in a later patch.
The rest looks okay.
Thanks,
Wei.
Re: [PATCH 10/15] x86: hyperv: Add mshv_handler irq handler and setup function
In reply to Nuno Das NevesQuoted 4 lines · Nuno Das Neves
This will handle SYNIC interrupts such as intercepts, doorbells, and scheduling messages intended for the mshv driver.
Signed-off-by Nuno Das Neves <[email protected]>
Re: [PATCH 11/15] Drivers: hv: export vmbus_isr, hv_context and hv_post_message
In reply to Nuno Das NevesQuoted 3 lines · Nuno Das Neves
These will be used by the
mshv_vtldriver.Signed-off-by Nuno Das Neves <[email protected]>
Wei Liu
maintainerRe: [PATCH 12/15] Documentation: Reserve ioctl number for mshv driver
In reply to Nuno Das NevesThis needs an ack from Jonathan.
Quoted 21 lines · Nuno Das Neves
Signed-off-by Nuno Das Neves <[email protected]>--- Documentation/userspace-api/ioctl/ioctl-number.rst | 2 ++ 1 file changed, 2 insertions(+)Documentation/userspace-api/ioctl/ioctl-number.rst +2
-0@@ -355,6 +355,8 @@ Code Seq# Include File Comments 0xB6 all linux/fpga-dfl.h 0xB7 all uapi/linux/remoteproc_cdev.h <mailto:[email protected]> 0xB7 all uapi/linux/nsfs.h <mailto:Andrei Vagin <[email protected]>> +0xB8 all uapi/linux/mshv.h Microsoft Hypervisor VM management APIs + <mailto:[email protected]> 0xC0 00-0F linux/usb/iowarrior.h 0xCA 00-0F uapi/misc/cxl.h 0xCA 10-2F uapi/misc/ocxl.hSignature · 1 line
2.25.1
Re: [PATCH 13/15] uapi: hyperv: Add mshv driver headers hvhdk.h, hvhdk_mini.h, hvgdk.h, hvgdk_mini.h
In reply to Nuno Das NevesQuoted 8 lines · Nuno Das Neves
Containing hypervisor ABI definitions to use in mshv driver.
Version numbers for each file:
hvhdk.h25212hvhdk_mini.h25294hvgdk.h25125hvgdk_mini.h25294
Quoted 6 lines
These are unstable interfaces and as such must be compiled independently from published interfaces found in
hyperv-tlfs.h.These are in uapi because they will be used in the mshv ioctl API.
Signed-off-by Nuno Das Neves <[email protected]>
Wei Liu
maintainerRe: [PATCH 14/15] asm-generic: hyperv: Use mshv headers conditionally. Add asm-generic/hyperv-defs.h
In reply to Nuno Das NevesQuoted 3 lines · Nuno Das Neves
In order to keep unstable hyper-v interfaces independent of
hyperv-tlfs.h,hvhdk.hmust replacehyperv-tlfs.heveywhere it will be used in the mshv driver.
Please properly capitalize "Hyper-V" when it is used as a term.
Quoted 15 lines
Add
hyperv-defs.hto replace some inclusions ofhyperv-tlfs.h. It includeshyperv-tlfs.horhvhdk.hdepending on a compile-time constantHV_HYPERV_DEFSwhich will be defined in the mshv driver.Signed-off-by Nuno Das Neves <[email protected]>--- arch/arm64/include/asm/mshyperv.h | 2 +- arch/x86/include/asm/mshyperv.h | 3 +-- drivers/hv/hyperv_vmbus.h | 1 - include/asm-generic/hyperv-defs.h | 26 ++++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 2 +- include/linux/hyperv.h | 2 +- 6 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 include/asm-generic/hyperv-defs.h
[...]
Quoted 14 lines
include/asm-generic/hyperv-defs.h new file +8
-0@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_HYPERV_DEFS_H +#define _ASM_GENERIC_HYPERV_DEFS_H + +/* +* There are cases where Microsoft Hypervisor ABIs are needed which may not be +* stable or present in the Hyper-V TLFS document. E.g. the mshv_root driver. +*
include/asm-generic/hyperv-defs.h line 18
Quoted 10 lines
include/asm-generic/hyperv-defs.h new file +10
-0+* As these interfaces are unstable and may differ from hyperv-tlfs.h, they +* must be kept separate and independent. +* +* However, code from files that depend on hyperv-tlfs.h (such as mshyperv.h) +* is still needed, so work around the issue by conditionally including the +* correct definitions. +* +* Note: Since they are independent of each other, there are many definitions +* duplicated in both hyperv-tlfs.h and uapi/hyperv/hv*.h files. +*/
Is this because we accidentally introduced some host only, unstable interfaces to hyperv-tlfs.h? Is the long term plan to drop those from hyperv-tlfs.h and further separate the helper functions?
Thanks,
Wei.
Quoted 37 lines
include/asm-generic/hyperv-defs.h new file +8
-0+#ifdef HV_HYPERV_DEFS +#include <uapi/hyperv/hvhdk.h> +#else +#include <asm/hyperv-tlfs.h> +#endif + +#endif /* _ASM_GENERIC_HYPERV_DEFS_H */ +include/asm-generic/mshyperv.h +1
-1@@ -25,7 +25,7 @@#include <linux/cpumask.h> #include <linux/nmi.h> #include <asm/ptrace.h> -#include <asm/hyperv-tlfs.h> +#include <asm-generic/hyperv-defs.h> #define VTPM_BASE_ADDRESS 0xfed40000include/linux/hyperv.h +1
-1@@ -24,7 +24,7 @@#include <linux/mod_devicetable.h> #include <linux/interrupt.h> #include <linux/reciprocal_div.h> -#include <asm/hyperv-tlfs.h> +#include <asm-generic/hyperv-defs.h> #define MAX_PAGE_BUFFER_COUNT 32#define MAX_MULTIPAGE_BUFFER_COUNT 32/* 128K */ Signature · 1 line
2.25.1
Wei Liu
maintainerRe: [PATCH 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
In reply to Nuno Das NevesQuoted 4 lines · Nuno Das Neves
Add mshv,
mshv_root, andmshv_vtlmodules.
- mshv provides/dev/mshvand common code, and is the parent module
-mshv_rootprovides APIs for creating and managing child partitions
-mshv_vtlprovides VTL (Virtual Trust Level) support for VMMs
Please provide a slightly more detailed description of what these modules do. This is huge patch after all. People doing code archaeology will appreciate a better commit message.
For example (please correct if I'm wrong):
Module mshv provides /dev/mshv and common code, and is the parent module to the other two modules. At its core, it implements an eventfd frame work, and defines some helper functions for the other modules.
Module mshv_root provides APIs for creating and managing child partitions. It defines abstractions for vcpus, partitions and other things related to running a guest inside the kernel. It also exposes user space interfaces for the VMMs.
Module mshv_vtl provides VTL (Virtual Trust Level) support for VMMs. It allows the VMM to run in a higher trust level than the guest but still within the same context as the guest. This is a useful feature for in guest emulation for better isolation and performance.
Quoted 42 lines
Signed-off-by Nuno Das Neves <[email protected]>--- drivers/hv/Kconfig | 54 + drivers/hv/Makefile | 21 + drivers/hv/hv_call.c | 119 ++ drivers/hv/mshv.h | 156 +++ drivers/hv/mshv_eventfd.c | 758 ++++++++++++ drivers/hv/mshv_eventfd.h | 80 ++ drivers/hv/mshv_main.c | 208 ++++ drivers/hv/mshv_msi.c | 129 +++ drivers/hv/mshv_portid_table.c | 84 ++ drivers/hv/mshv_root.h | 194 ++++ drivers/hv/mshv_root_hv_call.c | 1064 +++++++++++++++++ drivers/hv/mshv_root_main.c | 1964 ++++++++++++++++++++++++++++++++ drivers/hv/mshv_synic.c | 689 +++++++++++ drivers/hv/mshv_vtl.h | 52 + drivers/hv/mshv_vtl_main.c | 1541 +++++++++++++++++++++++++ drivers/hv/xfer_to_guest.c | 28 + include/uapi/linux/mshv.h | 298 +++++ 17 files changed, 7439 insertions(+) create mode 100644 drivers/hv/hv_call.c create mode 100644 drivers/hv/mshv.h create mode 100644 drivers/hv/mshv_eventfd.c create mode 100644 drivers/hv/mshv_eventfd.h create mode 100644 drivers/hv/mshv_main.c create mode 100644 drivers/hv/mshv_msi.c create mode 100644 drivers/hv/mshv_portid_table.c create mode 100644 drivers/hv/mshv_root.h create mode 100644 drivers/hv/mshv_root_hv_call.c create mode 100644 drivers/hv/mshv_root_main.c create mode 100644 drivers/hv/mshv_synic.c create mode 100644 drivers/hv/mshv_vtl.h create mode 100644 drivers/hv/mshv_vtl_main.c create mode 100644 drivers/hv/xfer_to_guest.c create mode 100644 include/uapi/linux/mshv.hdrivers/hv/Kconfig +0
-0
drivers/hv/Kconfig config HYPERV_BALLOON · line 61
Quoted 8 lines
drivers/hv/Kconfig +5
-0@@ -54,4 +54,58 @@ config HYPERV_BALLOON help Select this option to enable Hyper-V Balloon driver. +config MSHV + tristate "Microsoft Hypervisor root partition interfaces: /dev/mshv" + depends on X86_64 && HYPERV + select EVENTFD + select MSHV_VFIO
This is not needed yet, right? I think this is just dead code right now.
It can be introduced when we start upstreaming the VFIO bits.
Quoted 32 lines
drivers/hv/Kconfig +32
-0+ select MSHV_XFER_TO_GUEST_WORK + help + Select this option to enable core functionality for managing guest + virtual machines running under the Microsoft Hypervisor. + + The interfaces are provided via a device named /dev/mshv. + + To compile this as a module, choose M here. + + If unsure, say N. + +config MSHV_ROOT + tristate "Microsoft Hyper-V root partition APIs driver" + depends on MSHV + help + Select this option to provide /dev/mshv interfaces specific to + running as the root partition on Microsoft Hypervisor. + + To compile this as a module, choose M here. + + If unsure, say N. + +config MSHV_VTL + tristate "Microsoft Hyper-V VTL driver" + depends on MSHV + select HYPERV_VTL_MODE + select TRANSPARENT_HUGEPAGE + help + Select this option to enable Hyper-V VTL driver. + Virtual Secure Mode (VSM) is a set of hypervisor capabilities and + enlightenments offered to host and guest partitions which enables + the creation and management of new security boundaries within
drivers/hv/Kconfig config HYPERV_BALLOON · line 103
Quoted 10 lines
drivers/hv/Kconfig +10
-0+ operating system software. + + VSM achieves and maintains isolation through Virtual Trust Levels + (VTLs). Virtual Trust Levels are hierarchical, with higher levels + being more privileged than lower levels. VTL0 is the least privileged + level, and currently only other level supported is VTL2. + + To compile this as a module, choose M here. + + If unsure, say N.
The changes to the function which indicates if output pages are needed should be in this patch.
Quoted 13 lines
drivers/hv/Kconfig +7
-0+ +config MSHV_VFIO + bool + +config MSHV_XFER_TO_GUEST_WORK + bool + endmenudrivers/hv/Makefile +0
-0
drivers/hv/Makefile line 5
Quoted 4 lines
drivers/hv/Makefile +1
-0@@ -2,10 +2,31 @@ obj-$(CONFIG_HYPERV) += hv_vmbus.o obj-$(CONFIG_HYPERV_UTILS) += hv_utils.o obj-$(CONFIG_HYPERV_BALLOON) += hv_balloon.o +obj-$(CONFIG_DXGKRNL) += dxgkrnl/
This is not yet upstreamed. It shouldn't be here. Does this not break the build for you?
The rest is basically a copy of what was posted many moons before plus some VTL stuff, and new code for the root scheduler and async hypercall support. I've probably gone through some versions of this code already, so I only skim the code.
Since this is a Microsoft only driver, I don't expect to get much review from the community -- the last few rounds were quiet. I will however let this patch series float for a while before taking any further actions just in case.
If people are interested in specific bits of the code in the driver, please let Nuno and I know.
Thanks,
Wei.
Re: [PATCH 01/15] hyperv-tlfs: Change shared HV_REGISTER_* defines to HV_MSR_*
In reply to Nuno Das NevesQuoted 12 lines · Nuno Das Neves
In x86 hyperv-tlfs,
HV_REGISTER_prefix is used to indicate MSRs accessed via rdmsrl/wrmsrl. But in ARM64,HV_REGISTER_instead indicates VP registers accessed via get/set vp registers hypercall.This is due to HV_REGISTER_* names being used by hv_set/get_register, with the arch-specific version delegating to the appropriate mechanism.
The problem is, using prefix
HV_REGISTER_for MSRs will conflict with VP registers when they are introduced for x86 in future.This patch solves the issue by:
Quoted 8 lines
1. Defining all the x86 MSRs with a consistent prefix:
HV_X64_MSR_. This is soHV_REGISTER_can be reserved for VP registers.2. Change the non-arch-specific alias used by hv_set/get_register to
HV_MSR_. This is also happens to be the same name HyperV uses for this purpose.Signed-off-by Nuno Das Neves <[email protected]>
Assuming the prior (private?) discussion with Michael led to this patch:
Re: [PATCH 12/15] Documentation: Reserve ioctl number for mshv driver
In reply to Wei LiuQuoted 1 line · Wei Liu
This needs an ack from Jonathan.
From me? If every docs change needed an ack from me we'd be in rather worse shape than we are now. You can certainly have one:
...but I don't control ioctl() numbers and don't need to gate-keep a change like this.
Thanks,
jon
Quoted 22 lines · Nuno Das Neves
Quoted 21 lines
Signed-off-by Nuno Das Neves <[email protected]>--- Documentation/userspace-api/ioctl/ioctl-number.rst | 2 ++ 1 file changed, 2 insertions(+)Documentation/userspace-api/ioctl/ioctl-number.rst +2
-0@@ -355,6 +355,8 @@ Code Seq# Include File Comments 0xB6 all linux/fpga-dfl.h 0xB7 all uapi/linux/remoteproc_cdev.h <mailto:[email protected]> 0xB7 all uapi/linux/nsfs.h <mailto:Andrei Vagin <[email protected]>> +0xB8 all uapi/linux/mshv.h Microsoft Hypervisor VM management APIs + <mailto:[email protected]> 0xC0 00-0F linux/usb/iowarrior.h 0xCA 00-0F uapi/misc/cxl.h 0xCA 10-2F uapi/misc/ocxl.hSignature · 1 line
2.25.1
Wei Liu
maintainerRe: [PATCH 12/15] Documentation: Reserve ioctl number for mshv driver
Quoted 11 lines · Jonathan Corbet
Quoted 1 line · Wei Liu
This needs an ack from Jonathan.
From me? If every docs change needed an ack from me we'd be in rather worse shape than we are now. You can certainly have one:
Acked-by Jonathan Corbet <[email protected]>...but I don't control
ioctl()numbers and don't need to gate-keep a change like this.
Thanks Jonathan.
MAINTAINERS says you're the maintainer for Documentation, and I couldn't find who owns userspace-api or who controls the allocation of ioctl numbers.
Thanks,
Wei.
Quoted 27 lines
Thanks,
jon
Quoted 22 lines · Nuno Das Neves
Quoted 21 lines
Signed-off-by Nuno Das Neves <[email protected]>--- Documentation/userspace-api/ioctl/ioctl-number.rst | 2 ++ 1 file changed, 2 insertions(+)Documentation/userspace-api/ioctl/ioctl-number.rst +2
-0@@ -355,6 +355,8 @@ Code Seq# Include File Comments 0xB6 all linux/fpga-dfl.h 0xB7 all uapi/linux/remoteproc_cdev.h <mailto:[email protected]> 0xB7 all uapi/linux/nsfs.h <mailto:Andrei Vagin <[email protected]>> +0xB8 all uapi/linux/mshv.h Microsoft Hypervisor VM management APIs + <mailto:[email protected]> 0xC0 00-0F linux/usb/iowarrior.h 0xCA 00-0F uapi/misc/cxl.h 0xCA 10-2F uapi/misc/ocxl.hSignature · 1 line
2.25.1
Re: [PATCH 02/15] mshyperv: Introduce hv_get_hypervisor_version
In reply to Wei LiuQuoted 11 lines · Wei Liu
Quoted 5 lines · Nuno Das Neves
x86_64and arm64 implementations to get the hypervisor version information.
Also introducehv_hypervisor_version_infostructure to simplify parsing the fields.
Replace the existing parsing when printing the version numbers.The line wrapping looks odd. When you resend, please fix it. If you meant to use multiple paragraphs, please insert a blank line between them.
Thanks, I'll fix it.
Re: [PATCH 05/15] hyperv: Move hv_connection_id to hyperv-tlfs
In reply to Wei LiuQuoted 6 lines · Wei Liu
Quoted 2 lines · Nuno Das Neves
This structure should be in
hyperv-tlfs.hanyway, since it is part of the TLFS document.Missing blank line here.
Thanks, will fix.
Quoted 40 lines
Quoted 16 lines
The definition conflicts with one added in
hvgdk.has part of the mshv driver so must be moved tohyperv-tlfs.h.Signed-off-by Nuno Das Neves <[email protected]>--- include/asm-generic/hyperv-tlfs.h | 9 +++++++++ include/linux/hyperv.h | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-)include/asm-generic/hyperv-tlfs.h +0
-0@@ -845,4 +845,13 @@ struct hv_mmio_write_input {u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH ]; } __packed;include/asm-generic/hyperv-tlfs.h struct hv_mmio_write_input { · line 856
Quoted 10 lines
include/asm-generic/hyperv-tlfs.h +9
-0+/* Define connection identifier type. */ +union hv_connection_id { +u32 asu32; +struct { +u32 id:24 ; +u32 reserved:8 ; + } u; +}; +Missing
__packedhere, but since this is already aligned it probably doesn't matter much.
Yes, it should be fine without__packed.Quoted 9 lines
include/asm-generic/hyperv-tlfs.h +0
-0#endif include/linux/hyperv.h +0
-0@@ -748,15 +748,6 @@ struct vmbus_close_msg {struct vmbus_channel_close_channel msg; };
Quoted 15 lines
Quoted 15 lines
include/linux/hyperv.h +0
-9-/* Define connection identifier type. */ -union hv_connection_id { -u32 asu32; -struct { -u32 id:24 ; -u32 reserved:8 ; - } u; -}; -enum vmbus_device_type {HV_IDE =0 ,HV_SCSI ,Signature · 1 line
2.25.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 08/15] Drivers: hv: Introduce per-cpu event ring tail
In reply to Wei LiuQuoted 52 lines
Quoted 52 lines
drivers/hv/hv_common.c +22
-0+/* +* Per-cpu array holding the tail pointer for the SynIC event ring buffer +* for each SINT. +* +* We cannot maintain this in mshv driver because the tail pointer should +* persist even if the mshv driver is unloaded. +*/ +u8 __percpu **hv_synic_eventring_tail; +EXPORT_SYMBOL_GPL (hv_synic_eventring_tail); +/* * Hyper-V specific initialization and shutdown code that is * common across all architectures. Called from architecture @@ -332,6 +342,8 @@ int __init hv_common_init(void)if (hv_root_partition) { hyperv_pcpu_output_arg = alloc_percpu(void *);BUG_ON (!hyperv_pcpu_output_arg); + hv_synic_eventring_tail = alloc_percpu(u8 *); +BUG_ON (hv_synic_eventring_tail ==NULL ); } hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index),@@ -356,6 +368,7 @@ int __init hv_common_init(void)int hv_common_cpu_init (unsigned int cpu) {void **inputarg, **outputarg; +u8 **synic_eventring_tail;u64 msr_vp_index;gfp_t flags;int pgcount = hv_root_partition ?2 :1 ;@@ -371,6 +384,14 @@ int hv_common_cpu_init(unsigned int cpu)if (hv_root_partition) { outputarg = (void **)this_cpu_ptr (hyperv_pcpu_output_arg); *outputarg = (char *)(*inputarg) +HV_HYP_PAGE_SIZE ; + synic_eventring_tail = (u8 **)this_cpu_ptr (hv_synic_eventring_tail); + *synic_eventring_tail =kcalloc (HV_SYNIC_SINT_COUNT ,sizeof (u8), + flags); + +if (unlikely (!*synic_eventring_tail)) { +kfree (*inputarg); +return -ENOMEM ; + } } msr_vp_index =hv_get_register (HV_MSR_VP_INDEX );@@ -387,6 +408,7 @@ int hv_common_cpu_die(unsigned int cpu) {unsigned long flags;void **inputarg, **outputarg; +u8 **synic_eventring_tail;void *mem;
Quoted 11 lines
drivers/hv/hv_common.c int hv_common_cpu_die(unsigned int cpu) · line 425
Quoted 8 lines
drivers/hv/hv_common.c +3
-0local_irq_save (flags);@@ -398,6 +420,9 @@ int hv_common_cpu_die(unsigned int cpu)if (hv_root_partition) { outputarg = (void **)this_cpu_ptr (hyperv_pcpu_output_arg); *outputarg =NULL ; + synic_eventring_tail = (u8 **)this_cpu_ptr (hv_synic_eventring_tail); +kfree (*synic_eventring_tail); + *synic_eventring_tail =NULL ;The upstream code looks different now. See
9636be85cc.
Thanks, I have rebased for v2, and fixed this.
Quoted 11 lines
Quoted 11 lines
drivers/hv/hv_common.c +0
-0}local_irq_restore (flags);include/asm-generic/mshyperv.h +0
-0@@ -73,6 +73,8 @@ extern bool hv_nested;extern void *__percpu *hyperv_pcpu_input_arg;extern void *__percpu *hyperv_pcpu_output_arg;
Quoted 8 lines
Quoted 8 lines
include/asm-generic/mshyperv.h +2
-0+extern u8 __percpu **hv_synic_eventring_tail; +extern u64 hv_do_hypercall (u64 control,void *inputaddr,void *outputaddr);extern u64 hv_do_fast_hypercall8 (u16 control,u64 input8);extern bool hv_isolation_type_snp (void );Signature · 1 line
2.25.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 09/15] Drivers: hv: Introduce hv_output_arg_exists in hv_common
In reply to Wei LiuQuoted 19 lines · Wei Liu
Quoted 18 lines · Nuno Das Neves
This is a more flexible approach for determining whether to allocate the output page.
This will be used in both
mshv_vtland root partition.Signed-off-by Nuno Das Neves <[email protected]>--- drivers/hv/hv_common.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)drivers/hv/hv_common.c +0
-0@@ -57,6 +57,18 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg);void *__percpu *hyperv_pcpu_output_arg;EXPORT_SYMBOL_GPL (hyperv_pcpu_output_arg);
Quoted 13 lines
drivers/hv/hv_common.c EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg); · line 68
Quoted 9 lines
drivers/hv/hv_common.c +9
-0+/* +* Determine whether output arg is in use, for allocation/deallocation +*/ +static bool hv_output_arg_exists (void ) +{ +bool ret = hv_root_partition ? true : false; +#ifdef CONFIG_MSHV_VTL + ret = true; +#endif This should not be here. As far as I can tell,
CONFIG_MSHV_VTLis introduced in a later patch.
Ok, I will introduce this #ifdef with the mshv_vtl module.
Quoted 4 lines
The rest looks okay.
Thanks,
Wei.
Re: [PATCH 14/15] asm-generic: hyperv: Use mshv headers conditionally. Add asm-generic/hyperv-defs.h
In reply to Wei LiuQuoted 7 lines · Wei Liu
Quoted 3 lines · Nuno Das Neves
In order to keep unstable hyper-v interfaces independent of
hyperv-tlfs.h,hvhdk.hmust replacehyperv-tlfs.heveywhere it will be used in the mshv driver.Please properly capitalize "Hyper-V" when it is used as a term.
Will fix, thanks.
Quoted 45 lines
Quoted 15 lines
Add
hyperv-defs.hto replace some inclusions ofhyperv-tlfs.h. It includeshyperv-tlfs.horhvhdk.hdepending on a compile-time constantHV_HYPERV_DEFSwhich will be defined in the mshv driver.Signed-off-by Nuno Das Neves <[email protected]>--- arch/arm64/include/asm/mshyperv.h | 2 +- arch/x86/include/asm/mshyperv.h | 3 +-- drivers/hv/hyperv_vmbus.h | 1 - include/asm-generic/hyperv-defs.h | 26 ++++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 2 +- include/linux/hyperv.h | 2 +- 6 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 include/asm-generic/hyperv-defs.h[...]
Quoted 14 lines
include/asm-generic/hyperv-defs.h new file +8
-0@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_HYPERV_DEFS_H +#define _ASM_GENERIC_HYPERV_DEFS_H + +/* +* There are cases where Microsoft Hypervisor ABIs are needed which may not be +* stable or present in the Hyper-V TLFS document. E.g. the mshv_root driver. +* include/asm-generic/hyperv-defs.h line 18
Quoted 10 lines
include/asm-generic/hyperv-defs.h new file +10
-0+* As these interfaces are unstable and may differ from hyperv-tlfs.h, they +* must be kept separate and independent. +* +* However, code from files that depend on hyperv-tlfs.h (such as mshyperv.h) +* is still needed, so work around the issue by conditionally including the +* correct definitions. +* +* Note: Since they are independent of each other, there are many definitions +* duplicated in both hyperv-tlfs.h and uapi/hyperv/hv*.h files. +*/ Is this because we accidentally introduced some host only, unstable interfaces to
hyperv-tlfs.h? Is the long term plan to drop those fromhyperv-tlfs.hand further separate the helper functions?
Quoted 3 lines
Thanks,
Wei.
We do have some host-only interfaces in hyperv-tlfs.h that should not be there. E.g. the create LP/VP hypercall inputs. We should drop them.
However, even if we fix that problem, the new headers still have conflicting definitions, so need to be independent.
E.g. enum hv_message_type has many more members in the new headers.
We don't want to put anything not in the TLFS doc into hyperv-tlfs.h, even if it can be ignored by the guest code.
Quoted 32 lines
Quoted 32 lines
include/asm-generic/hyperv-defs.h new file +8
-0+#ifdef HV_HYPERV_DEFS +#include <uapi/hyperv/hvhdk.h> +#else +#include <asm/hyperv-tlfs.h> +#endif + +#endif /* _ASM_GENERIC_HYPERV_DEFS_H */ +include/asm-generic/mshyperv.h +1
-1@@ -25,7 +25,7 @@#include <linux/cpumask.h> #include <linux/nmi.h> #include <asm/ptrace.h> -#include <asm/hyperv-tlfs.h> +#include <asm-generic/hyperv-defs.h> #define VTPM_BASE_ADDRESS 0xfed40000include/linux/hyperv.h +1
-1@@ -24,7 +24,7 @@#include <linux/mod_devicetable.h> #include <linux/interrupt.h> #include <linux/reciprocal_div.h> -#include <asm/hyperv-tlfs.h> +#include <asm-generic/hyperv-defs.h>
Quoted 5 lines
Quoted 5 lines
include/linux/hyperv.h +0
-0#define MAX_PAGE_BUFFER_COUNT 32#define MAX_MULTIPAGE_BUFFER_COUNT 32/* 128K */ Signature · 1 line
2.25.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
In reply to Wei LiuQuoted 21 lines · Wei Liu
Quoted 4 lines · Nuno Das Neves
Add mshv,
mshv_root, andmshv_vtlmodules.
- mshv provides/dev/mshvand common code, and is the parent module
-mshv_rootprovides APIs for creating and managing child partitions
-mshv_vtlprovides VTL (Virtual Trust Level) support for VMMsPlease provide a slightly more detailed description of what these modules do. This is huge patch after all. People doing code archaeology will appreciate a better commit message.
For example (please correct if I'm wrong):
Module mshv provides
/dev/mshvand common code, and is the parent module to the other two modules. At its core, it implements an eventfd frame work, and defines some helper functions for the other modules.Module
mshv_rootprovides APIs for creating and managing child partitions. It defines abstractions for vcpus, partitions and other things related to running a guest inside the kernel. It also exposes user space interfaces for the VMMs.
Quoted 5 lines
Module
mshv_vtlprovides VTL (Virtual Trust Level) support for VMMs. It allows the VMM to run in a higher trust level than the guest but still within the same context as the guest. This is a useful feature for in guest emulation for better isolation and performance.
Thanks - I will provide some more detail, including what you described.
I will make a couple of changes - the eventfd framework is in mshv_root, not mshv. I will amend the mshv_vtl part a little for clarity.
Quoted 53 lines
Quoted 42 lines
Signed-off-by Nuno Das Neves <[email protected]>--- drivers/hv/Kconfig | 54 + drivers/hv/Makefile | 21 + drivers/hv/hv_call.c | 119 ++ drivers/hv/mshv.h | 156 +++ drivers/hv/mshv_eventfd.c | 758 ++++++++++++ drivers/hv/mshv_eventfd.h | 80 ++ drivers/hv/mshv_main.c | 208 ++++ drivers/hv/mshv_msi.c | 129 +++ drivers/hv/mshv_portid_table.c | 84 ++ drivers/hv/mshv_root.h | 194 ++++ drivers/hv/mshv_root_hv_call.c | 1064 +++++++++++++++++ drivers/hv/mshv_root_main.c | 1964 ++++++++++++++++++++++++++++++++ drivers/hv/mshv_synic.c | 689 +++++++++++ drivers/hv/mshv_vtl.h | 52 + drivers/hv/mshv_vtl_main.c | 1541 +++++++++++++++++++++++++ drivers/hv/xfer_to_guest.c | 28 + include/uapi/linux/mshv.h | 298 +++++ 17 files changed, 7439 insertions(+) create mode 100644 drivers/hv/hv_call.c create mode 100644 drivers/hv/mshv.h create mode 100644 drivers/hv/mshv_eventfd.c create mode 100644 drivers/hv/mshv_eventfd.h create mode 100644 drivers/hv/mshv_main.c create mode 100644 drivers/hv/mshv_msi.c create mode 100644 drivers/hv/mshv_portid_table.c create mode 100644 drivers/hv/mshv_root.h create mode 100644 drivers/hv/mshv_root_hv_call.c create mode 100644 drivers/hv/mshv_root_main.c create mode 100644 drivers/hv/mshv_synic.c create mode 100644 drivers/hv/mshv_vtl.h create mode 100644 drivers/hv/mshv_vtl_main.c create mode 100644 drivers/hv/xfer_to_guest.c create mode 100644 include/uapi/linux/mshv.hdrivers/hv/Kconfig +0
-0drivers/hv/Kconfig config HYPERV_BALLOON · line 61
Quoted 8 lines
drivers/hv/Kconfig +5
-0@@ -54,4 +54,58 @@ config HYPERV_BALLOON help Select this option to enable Hyper-V Balloon driver. +config MSHV + tristate "Microsoft Hypervisor root partition interfaces: /dev/mshv" + depends on X86_64 && HYPERV + select EVENTFD + select MSHV_VFIOThis is not needed yet, right? I think this is just dead code right now.
Quoted 2 lines
It can be introduced when we start upstreaming the VFIO bits.
Right. Removed, along with config MSHV_VFIO below.
Quoted 37 lines
Quoted 37 lines
drivers/hv/Kconfig +37
-0+ select MSHV_XFER_TO_GUEST_WORK + help + Select this option to enable core functionality for managing guest + virtual machines running under the Microsoft Hypervisor. + + The interfaces are provided via a device named /dev/mshv. + + To compile this as a module, choose M here. + + If unsure, say N. + +config MSHV_ROOT + tristate "Microsoft Hyper-V root partition APIs driver" + depends on MSHV + help + Select this option to provide /dev/mshv interfaces specific to + running as the root partition on Microsoft Hypervisor. + + To compile this as a module, choose M here. + + If unsure, say N. + +config MSHV_VTL + tristate "Microsoft Hyper-V VTL driver" + depends on MSHV + select HYPERV_VTL_MODE + select TRANSPARENT_HUGEPAGE + help + Select this option to enable Hyper-V VTL driver. + Virtual Secure Mode (VSM) is a set of hypervisor capabilities and + enlightenments offered to host and guest partitions which enables + the creation and management of new security boundaries within + operating system software. + + VSM achieves and maintains isolation through Virtual Trust Levels + (VTLs). Virtual Trust Levels are hierarchical, with higher levels + being more privileged than lower levels. VTL0 is the least privileged
Quoted 9 lines
drivers/hv/Kconfig config HYPERV_BALLOON · line 103
Quoted 5 lines
drivers/hv/Kconfig +5
-0+ level, and currently only other level supported is VTL2. + + To compile this as a module, choose M here. + + If unsure, say N.The changes to the function which indicates if output pages are needed should be in this patch.
Yes - I will add it in this patch.
Quoted 12 lines
Quoted 12 lines
drivers/hv/Kconfig +7
-0+ +config MSHV_VFIO + bool + +config MSHV_XFER_TO_GUEST_WORK + bool + endmenudrivers/hv/Makefile +0
-0
Quoted 9 lines
drivers/hv/Makefile line 5
Quoted 5 lines
drivers/hv/Makefile +1
-0@@ -2,10 +2,31 @@ obj-$(CONFIG_HYPERV) += hv_vmbus.o obj-$(CONFIG_HYPERV_UTILS) += hv_utils.o obj-$(CONFIG_HYPERV_BALLOON) += hv_balloon.o +obj-$(CONFIG_DXGKRNL) += dxgkrnl/This is not yet upstreamed. It shouldn't be here. Does this not break the build for you?
Oops! Nope, it doesn't seem to break the build... Anyway, removed.
Quoted 10 lines
The rest is basically a copy of what was posted many moons before plus some VTL stuff, and new code for the root scheduler and async hypercall support. I've probably gone through some versions of this code already, so I only skim the code.
Since this is a Microsoft only driver, I don't expect to get much review from the community -- the last few rounds were quiet. I will however let this patch series float for a while before taking any further actions just in case.
Quoted 5 lines
If people are interested in specific bits of the code in the driver, please let Nuno and I know.
Thanks,
Wei.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel