Introduce /dev/mshv drivers
Subsystems (8)
v2 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.
Patches 8-12 just set things up for the driver code to come. These are very small. They come first 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.
Patch 15 is rather big and has bounced back from some mailing lists. If you did not get a copy in your inbox, you can view it here instead:
https://github.com/NunoDasNeves/linux/commit/4dd436f13d95a6a0daecd75da012a2caa6c57c8c
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
--------------------------
Changes since v1:
* Clean up formatting, capitalization in commit messages
* Add detail to commit message for patch 15
* Remove errant lines in Makefile and Kconfig in patch 15
* Move a reference to CONFIG_MSHV_VTL from patch 9 to 15
Nuno Das Neves (15):
hyperv-tlfs: Change shared HV_REGISTER_* defines to HV_MSR_*
mshyperv: Introduce hv_get_hypervisor_version function
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.c
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 | 50 + drivers/hv/Makefile | 20 + drivers/hv/hv.c | 46 +- drivers/hv/hv_call.c | 119 + drivers/hv/hv_common.c | 222 +- 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 | 1542 +++++++++++++ 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, 10645 insertions(+), 353 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 v2 1/15 hyperv-tlfs: Change shared HV_REGISTER_* defines to HV_MSR_*
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:
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 ; }
@@ -373,10 +373,10 @@ static __always_inline u64 read_hv_clock_msr(void)* nanosecond units. * * Use hv_raw_get_register() because this function is used from -* noinstr. Notable; while HV_REGISTER_TIME_REF_COUNT is a synthetic +* noinstr. Notable; while HV_MSR_TIME_REF_COUNT is a synthetic * register it doesn't need the GHCB path. */ -return hv_raw_get_register (HV_REGISTER_TIME_REF_COUNT ); +return hv_raw_get_register (HV_MSR_TIME_REF_COUNT ); }/*
@@ -439,9 +439,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); }
@@ -450,10 +450,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
@@ -555,14 +555,14 @@ static void __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
@@ -167,7 +167,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) {
@@ -183,10 +183,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) {
@@ -202,12 +202,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;
@@ -223,14 +223,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)
@@ -254,17 +254,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
@@ -279,9 +279,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) {
@@ -291,12 +291,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 ();
@@ -380,7 +380,7 @@ int hv_common_cpu_init(unsigned int cpu) } } - 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
Wei Liu
maintainerRe: [PATCH v2 01/15] hyperv-tlfs: Change shared HV_REGISTER_* defines to HV_MSR_*
Hi Michael, Long and Haiyang
Quoted 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]>
I think this patch contains mostly mechanical changes, so I'm hoping it's not too controversial.
Can you give an ack or nack on this patch?
Thanks,
Wei.
Quoted 555 lines
--- 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@@ -181,7 +181,7 @@ enum hv_isolation_type {#define HV_X64_MSR_HYPERCALL 0x40000001/* MSR used to provide vcpu index */ -#define HV_REGISTER_VP_INDEX 0x40000002 +#define HV_X64_MSR_VP_INDEX 0x40000002/* MSR used to reset the guest OS. */ #define HV_X64_MSR_RESET 0x40000003@@ -190,10 +190,10 @@ enum hv_isolation_type {#define HV_X64_MSR_VP_RUNTIME 0x40000010/* MSR used to read the per-partition time reference counter */ -#define HV_REGISTER_TIME_REF_COUNT 0x40000020 +#define HV_X64_MSR_TIME_REF_COUNT 0x40000020/* A partition's reference time stamp counter (TSC) page */ -#define HV_REGISTER_REFERENCE_TSC 0x40000021 +#define HV_X64_MSR_REFERENCE_TSC 0x40000021/* MSR used to retrieve the TSC frequency */ #define HV_X64_MSR_TSC_FREQUENCY 0x40000022@@ -208,61 +208,61 @@ enum hv_isolation_type {#define HV_X64_MSR_VP_ASSIST_PAGE 0x40000073/* Define synthetic interrupt controller model specific registers. */ -#define HV_REGISTER_SCONTROL 0x40000080 -#define HV_REGISTER_SVERSION 0x40000081 -#define HV_REGISTER_SIEFP 0x40000082 -#define HV_REGISTER_SIMP 0x40000083 -#define HV_REGISTER_EOM 0x40000084 -#define HV_REGISTER_SINT0 0x40000090 -#define HV_REGISTER_SINT1 0x40000091 -#define HV_REGISTER_SINT2 0x40000092 -#define HV_REGISTER_SINT3 0x40000093 -#define HV_REGISTER_SINT4 0x40000094 -#define HV_REGISTER_SINT5 0x40000095 -#define HV_REGISTER_SINT6 0x40000096 -#define HV_REGISTER_SINT7 0x40000097 -#define HV_REGISTER_SINT8 0x40000098 -#define HV_REGISTER_SINT9 0x40000099 -#define HV_REGISTER_SINT10 0x4000009A -#define HV_REGISTER_SINT11 0x4000009B -#define HV_REGISTER_SINT12 0x4000009C -#define HV_REGISTER_SINT13 0x4000009D -#define HV_REGISTER_SINT14 0x4000009E -#define HV_REGISTER_SINT15 0x4000009F +#define HV_X64_MSR_SCONTROL 0x40000080 +#define HV_X64_MSR_SVERSION 0x40000081 +#define HV_X64_MSR_SIEFP 0x40000082 +#define HV_X64_MSR_SIMP 0x40000083 +#define HV_X64_MSR_EOM 0x40000084 +#define HV_X64_MSR_SINT0 0x40000090 +#define HV_X64_MSR_SINT1 0x40000091 +#define HV_X64_MSR_SINT2 0x40000092 +#define HV_X64_MSR_SINT3 0x40000093 +#define HV_X64_MSR_SINT4 0x40000094 +#define HV_X64_MSR_SINT5 0x40000095 +#define HV_X64_MSR_SINT6 0x40000096 +#define HV_X64_MSR_SINT7 0x40000097 +#define HV_X64_MSR_SINT8 0x40000098 +#define HV_X64_MSR_SINT9 0x40000099 +#define HV_X64_MSR_SINT10 0x4000009A +#define HV_X64_MSR_SINT11 0x4000009B +#define HV_X64_MSR_SINT12 0x4000009C +#define HV_X64_MSR_SINT13 0x4000009D +#define HV_X64_MSR_SINT14 0x4000009E +#define HV_X64_MSR_SINT15 0x4000009F/* * Define synthetic interrupt controller model specific registers for * nested hypervisor. */ -#define HV_REGISTER_NESTED_SCONTROL 0x40001080 -#define HV_REGISTER_NESTED_SVERSION 0x40001081 -#define HV_REGISTER_NESTED_SIEFP 0x40001082 -#define HV_REGISTER_NESTED_SIMP 0x40001083 -#define HV_REGISTER_NESTED_EOM 0x40001084 -#define HV_REGISTER_NESTED_SINT0 0x40001090 +#define HV_X64_MSR_NESTED_SCONTROL 0x40001080 +#define HV_X64_MSR_NESTED_SVERSION 0x40001081 +#define HV_X64_MSR_NESTED_SIEFP 0x40001082 +#define HV_X64_MSR_NESTED_SIMP 0x40001083 +#define HV_X64_MSR_NESTED_EOM 0x40001084 +#define HV_X64_MSR_NESTED_SINT0 0x40001090/* * Synthetic Timer MSRs. Four timers per vcpu. */ -#define HV_REGISTER_STIMER0_CONFIG 0x400000B0 -#define HV_REGISTER_STIMER0_COUNT 0x400000B1 -#define HV_REGISTER_STIMER1_CONFIG 0x400000B2 -#define HV_REGISTER_STIMER1_COUNT 0x400000B3 -#define HV_REGISTER_STIMER2_CONFIG 0x400000B4 -#define HV_REGISTER_STIMER2_COUNT 0x400000B5 -#define HV_REGISTER_STIMER3_CONFIG 0x400000B6 -#define HV_REGISTER_STIMER3_COUNT 0x400000B7 +#define HV_X64_MSR_STIMER0_CONFIG 0x400000B0 +#define HV_X64_MSR_STIMER0_COUNT 0x400000B1 +#define HV_X64_MSR_STIMER1_CONFIG 0x400000B2 +#define HV_X64_MSR_STIMER1_COUNT 0x400000B3 +#define HV_X64_MSR_STIMER2_CONFIG 0x400000B4 +#define HV_X64_MSR_STIMER2_COUNT 0x400000B5 +#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6 +#define HV_X64_MSR_STIMER3_COUNT 0x400000B7/* Hyper-V guest idle MSR */ #define HV_X64_MSR_GUEST_IDLE 0x400000F0/* Hyper-V guest crash notification MSR's */ -#define HV_REGISTER_CRASH_P0 0x40000100 -#define HV_REGISTER_CRASH_P1 0x40000101 -#define HV_REGISTER_CRASH_P2 0x40000102 -#define HV_REGISTER_CRASH_P3 0x40000103 -#define HV_REGISTER_CRASH_P4 0x40000104 -#define HV_REGISTER_CRASH_CTL 0x40000105 +#define HV_X64_MSR_CRASH_P0 0x40000100 +#define HV_X64_MSR_CRASH_P1 0x40000101 +#define HV_X64_MSR_CRASH_P2 0x40000102 +#define HV_X64_MSR_CRASH_P3 0x40000103 +#define HV_X64_MSR_CRASH_P4 0x40000104 +#define HV_X64_MSR_CRASH_CTL 0x40000105/* TSC emulation after migration */ #define HV_X64_MSR_REENLIGHTENMENT_CONTROL 0x40000106@@ -275,31 +275,30 @@ enum hv_isolation_type {/* HV_X64_MSR_TSC_INVARIANT_CONTROL bits */ #define HV_EXPOSE_INVARIANT_TSC BIT_ULL(0) -/* Register name aliases for temporary compatibility */ -#define HV_X64_MSR_STIMER0_COUNT HV_REGISTER_STIMER0_COUNT -#define HV_X64_MSR_STIMER0_CONFIG HV_REGISTER_STIMER0_CONFIG -#define HV_X64_MSR_STIMER1_COUNT HV_REGISTER_STIMER1_COUNT -#define HV_X64_MSR_STIMER1_CONFIG HV_REGISTER_STIMER1_CONFIG -#define HV_X64_MSR_STIMER2_COUNT HV_REGISTER_STIMER2_COUNT -#define HV_X64_MSR_STIMER2_CONFIG HV_REGISTER_STIMER2_CONFIG -#define HV_X64_MSR_STIMER3_COUNT HV_REGISTER_STIMER3_COUNT -#define HV_X64_MSR_STIMER3_CONFIG HV_REGISTER_STIMER3_CONFIG -#define HV_X64_MSR_SCONTROL HV_REGISTER_SCONTROL -#define HV_X64_MSR_SVERSION HV_REGISTER_SVERSION -#define HV_X64_MSR_SIMP HV_REGISTER_SIMP -#define HV_X64_MSR_SIEFP HV_REGISTER_SIEFP -#define HV_X64_MSR_VP_INDEX HV_REGISTER_VP_INDEX -#define HV_X64_MSR_EOM HV_REGISTER_EOM -#define HV_X64_MSR_SINT0 HV_REGISTER_SINT0 -#define HV_X64_MSR_SINT15 HV_REGISTER_SINT15 -#define HV_X64_MSR_CRASH_P0 HV_REGISTER_CRASH_P0 -#define HV_X64_MSR_CRASH_P1 HV_REGISTER_CRASH_P1 -#define HV_X64_MSR_CRASH_P2 HV_REGISTER_CRASH_P2 -#define HV_X64_MSR_CRASH_P3 HV_REGISTER_CRASH_P3 -#define HV_X64_MSR_CRASH_P4 HV_REGISTER_CRASH_P4 -#define HV_X64_MSR_CRASH_CTL HV_REGISTER_CRASH_CTL -#define HV_X64_MSR_TIME_REF_COUNT HV_REGISTER_TIME_REF_COUNT -#define HV_X64_MSR_REFERENCE_TSC HV_REGISTER_REFERENCE_TSC +/* +* 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_X64_MSR_VP_INDEX) +#define HV_MSR_TIME_REF_COUNT (HV_X64_MSR_TIME_REF_COUNT) +#define HV_MSR_REFERENCE_TSC (HV_X64_MSR_REFERENCE_TSC) + +#define HV_MSR_STIMER0_CONFIG (HV_X64_MSR_STIMER0_CONFIG) +#define HV_MSR_STIMER0_COUNT (HV_X64_MSR_STIMER0_COUNT) + +#define HV_MSR_SCONTROL (HV_X64_MSR_SCONTROL) +#define HV_MSR_SIEFP (HV_X64_MSR_SIEFP) +#define HV_MSR_SIMP (HV_X64_MSR_SIMP) +#define HV_MSR_EOM (HV_X64_MSR_EOM) +#define HV_MSR_SINT0 (HV_X64_MSR_SINT0) + +#define HV_MSR_CRASH_P0 (HV_X64_MSR_CRASH_P0) +#define HV_MSR_CRASH_P1 (HV_X64_MSR_CRASH_P1) +#define HV_MSR_CRASH_P2 (HV_X64_MSR_CRASH_P2) +#define HV_MSR_CRASH_P3 (HV_X64_MSR_CRASH_P3) +#define HV_MSR_CRASH_P4 (HV_X64_MSR_CRASH_P4) +#define HV_MSR_CRASH_CTL (HV_X64_MSR_CRASH_CTL)/* Hyper-V memory host visibility */ enum hv_mem_host_visibility {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 ; }@@ -373,10 +373,10 @@ static __always_inline u64 read_hv_clock_msr(void)* nanosecond units. * * Use hv_raw_get_register() because this function is used from -* noinstr. Notable; while HV_REGISTER_TIME_REF_COUNT is a synthetic +* noinstr. Notable; while HV_MSR_TIME_REF_COUNT is a synthetic * register it doesn't need the GHCB path. */ -return hv_raw_get_register (HV_REGISTER_TIME_REF_COUNT ); +return hv_raw_get_register (HV_MSR_TIME_REF_COUNT ); }/* @@ -439,9 +439,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); }@@ -450,10 +450,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 @@ -555,14 +555,14 @@ static void __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@@ -167,7 +167,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) {@@ -183,10 +183,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) {@@ -202,12 +202,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;@@ -223,14 +223,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)@@ -254,17 +254,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 @@ -279,9 +279,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) {@@ -291,12 +291,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 ();@@ -380,7 +380,7 @@ int hv_common_cpu_init(unsigned int cpu) } } - 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 v2 2/15 mshyperv: Introduce hv_get_hypervisor_version function
In reply to Nuno Das Nevesx86_64 and arm64 implementations to get the hypervisor version information. Store these in hv_hypervisor_version_info structure to simplify parsing the fields.
Replace the existing parsing when printing the version numbers at boot.
--- 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
@@ -313,13 +313,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" ;
@@ -373,16 +390,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 v2 02/15] mshyperv: Introduce hv_get_hypervisor_version function
Quoted 7 lines · Nuno Das Neves
arch/arm64/hyperv/mshyperv.c +7
-0+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 ; +}
...
Quoted 8 lines
arch/x86/kernel/cpu/mshyperv.c +8
-0+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__);
arch/x86/kernel/cpu/mshyperv.c static void __init hv_smp_prepare_cpus(unsigned int max_cpus) · line 333
Quoted 10 lines
arch/x86/kernel/cpu/mshyperv.c +10
-0+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 ; +}
I can't help but notice that the ARM version does *one* call to the hardware while the x86 version does CPUID four different times, once to get *EACH* register and throwing away the other three registers each time. Also recall that CPUID is a big, fat architecturally serializing instruction. This isn't a fast path, but CPUID is about as slow as you get.
Is there any reason you can't just have an x86 version of hv_get_vpreg_128() that gets the 128 bits bytes of data that comes back in the 4 CPUID registers?
That might even let you share some more code.
Re: [PATCH v2 02/15] mshyperv: Introduce hv_get_hypervisor_version function
Quoted 25 lines · Dave Hansen
Quoted 7 lines · Nuno Das Neves
arch/arm64/hyperv/mshyperv.c +7
-0+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 ; +}...
Quoted 16 lines
arch/x86/kernel/cpu/mshyperv.c +16
-0+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 ); +
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ return 0; +}I can't help but notice that the ARM version does *one* call to the hardware while the x86 version does CPUID four different times, once to get *EACH* register and throwing away the other three registers each time. Also recall that CPUID is a big, fat architecturally serializing instruction. This isn't a fast path, but CPUID is about as slow as you get.
Good point, it is quite wasteful. I just went and checked cpuid.h, and of course there is a generic cpuid() function that can get all 4 at once. I will update it to use this in the next version. Thanks!
Quoted 5 lines
Is there any reason you can't just have an x86 version of
hv_get_vpreg_128()that gets the 128 bits bytes of data that comes back in the 4 CPUID registers?That might even let you share some more code.
Unfortunately, for some reason the hypervisor only lets you get this data via CPUID on x86_64, and via hypercall - i.e. hv_get_vpreg_128() - on ARM64.
PATCH v2 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
Re: [PATCH v2 03/15] mshyperv: Introduce numa_node_to_proximity_domain_info
Quoted 6 lines · Nuno Das Neves
include/asm-generic/mshyperv.h +6
-0+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 ) {
include/asm-generic/mshyperv.h line 47
Quoted 10 lines
include/asm-generic/mshyperv.h +10
-0+ 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; +}
Pop quiz: What are the rules for the 30 bits of uninitialized data of proximity_domain_info.flags in the (node != NUMA_NO_NODE) case?
I actually don't know off the top of my head. I generally avoid bitfields, but if they were normal stack-allocated variable space, they'd be garbage.
I'd also *much* rather see the "as_uint64 = 0" coded up as a memset() or even explicitly zeroing all the same variables as the other half of the if(). As it stands, it's not 100% obvious that proximity_domain_info is 64 bits and that .as_uint64=0 zeroes the whole thing. It *WOULD* be totally obvious if it were a memset().
Re: [PATCH v2 03/15] mshyperv: Introduce numa_node_to_proximity_domain_info
Quoted 21 lines · Dave Hansen
Quoted 6 lines · Nuno Das Neves
include/asm-generic/mshyperv.h +6
-0+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 ) {include/asm-generic/mshyperv.h line 47
Quoted 10 lines
include/asm-generic/mshyperv.h +10
-0+ 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; +}Pop quiz: What are the rules for the 30 bits of uninitialized data of proximity_domain_info.flags in the (node !=
NUMA_NO_NODE) case?
Quoted 3 lines
I actually don't know off the top of my head. I generally avoid bitfields, but if they were normal stack-allocated variable space, they'd be garbage.
I'm not sure what you are getting at here - all the fields are initialized.
Quoted 6 lines
I'd also *much* rather see the "
as_uint64= 0" coded up as amemset()or even explicitly zeroing all the same variables as the other half of theif(). As it stands, it's not 100% obvious thatproximity_domain_infois 64 bits and that .as_uint64=0 zeroes the whole thing. It *WOULD* be totally obvious if it were amemset().
I agree that it could be made clearer with memset().
Now that I'm thinking about it, hv_proximity_domain_info should really just be a struct...then zeroing it is just:
struct hv_proximity_domain_info proximity_domain_info = {};and I can remove the else branch and zeroing the reserved bits.
Re: [PATCH v2 03/15] mshyperv: Introduce numa_node_to_proximity_domain_info
Quoted 14 lines · Nuno Das Neves
Quoted 14 lines
include/asm-generic/mshyperv.h line 47
Quoted 11 lines
include/asm-generic/mshyperv.h +11
-0+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; +}Pop quiz: What are the rules for the 30 bits of uninitialized data of proximity_domain_info.flags in the (node !=
NUMA_NO_NODE) case?
Quoted 5 lines
Quoted 3 lines
I actually don't know off the top of my head. I generally avoid bitfields, but if they were normal stack-allocated variable space, they'd be garbage.
I'm not sure what you are getting at here - all the fields are initialized.
Whoops, I somehow missed the reserved field initialization. But, yeah, a struct would be nice instead of the union here.
PATCH v2 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
@@ -212,17 +212,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 v2 5/15 hyperv: Move hv_connection_id to hyperv-tlfs
In reply to Nuno Das NevesThe definition conflicts with one added in hvgdk.h as part of the mshv driver so must be moved to hyperv-tlfs.h.
This structure should be in hyperv-tlfs.h anyway, since it is part of the TLFS document.
--- 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
Re: [PATCH v2 05/15] hyperv: Move hv_connection_id to hyperv-tlfs
Quoted 7 lines · Nuno Das Neves
The definition conflicts with one added in
hvgdk.has part of the mshv driver so must be moved tohyperv-tlfs.h.This structure should be in
hyperv-tlfs.hanyway, since it is part of the TLFS document.Signed-off-by Nuno Das Neves <[email protected]>
PATCH v2 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
Re: [PATCH v2 06/15] hyperv-tlfs: Introduce hv_status_to_string and hv_status_to_errno
Quoted 7 lines · Nuno Das Neves
hv_status_to_errnotranslates hyperv statuses to linux error codes. This is useful for returning something linux-friendly from a hypercall helper function.
hv_status_to_stringimproves clarity of error messages.Signed-off-by Nuno Das Neves <[email protected]>
PATCH v2 7/15 Drivers: hv: Move hv_call_deposit_pages and hv_call_create_vp to common code
In reply to Nuno Das NevesThese 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 v2 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 | 28 ++++++++++++++++++++++++++-- include/asm-generic/mshyperv.h | 2 ++ 2 files changed, 28 insertions(+), 2 deletions(-)
drivers/hv/hv_common.c +26 -2
@@ -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
@@ -83,6 +93,9 @@ void __init hv_common_free(void)free_percpu (hyperv_pcpu_input_arg); hyperv_pcpu_input_arg =NULL ; + +free_percpu (hv_synic_eventring_tail); + hv_synic_eventring_tail =NULL ; }/*
@@ -332,6 +345,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 +371,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 ;
@@ -366,8 +382,8 @@ int hv_common_cpu_init(unsigned int cpu) inputarg = (void **)this_cpu_ptr (hyperv_pcpu_input_arg);/* -* hyperv_pcpu_input_arg and hyperv_pcpu_output_arg memory is already -* allocated if this CPU was previously online and then taken offline +* The per-cpu memory is already allocated if this CPU was previously +* online and then taken offline */ if (!*inputarg) { *inputarg =kmalloc (pgcount *HV_HYP_PAGE_SIZE , flags);
@@ -377,6 +393,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 ; + } } }
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
Re: [PATCH v2 08/15] Drivers: hv: Introduce per-cpu event ring tail
Quoted 7 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]>
PATCH v2 9/15 Drivers: hv: Introduce hv_output_arg_exists in hv_common.c
In reply to Nuno Das NevesThis is a more flexible approach for determining whether to allocate the output page.
--- drivers/hv/hv_common.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/hv/hv_common.c +16 -4
@@ -57,6 +57,14 @@ 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 needed +*/ +static inline bool hv_output_arg_exists (void ) +{ +return hv_root_partition ? true : false; +} +static void hv_kmsg_dump_unregister (void );static struct ctl_table_header *hv_ctl_table_hdr;
@@ -341,10 +349,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 ); }
@@ -374,7 +384,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 ;
@@ -390,9 +400,11 @@ 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);
Signature · 1 line
2.25.1
Re: [PATCH v2 09/15] Drivers: hv: Introduce hv_output_arg_exists in hv_common.c
Quoted 4 lines · Nuno Das Neves
This is a more flexible approach for determining whether to allocate the output page.
Signed-off-by Nuno Das Neves <[email protected]>
PATCH v2 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 ();
@@ -124,6 +128,11 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_hyperv_callback)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
@@ -548,6 +548,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
Re: [PATCH v2 10/15] x86: hyperv: Add mshv_handler irq handler and setup function
Quoted 10 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]>Reviewed-by Wei Liu <[email protected]>--- arch/x86/kernel/cpu/mshyperv.c | 9 +++++++++ drivers/hv/hv_common.c | 5 +++++ include/asm-generic/mshyperv.h | 2 ++ 3 files changed, 16 insertions(+)
PATCH v2 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.
@@ -75,6 +76,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 v2 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
Re: [PATCH v2 12/15] Documentation: Reserve ioctl number for mshv driver
Quoted 2 lines · Nuno Das Neves
Signed-off-by Nuno Das Neves <[email protected]>Acked-by Jonathan Corbet <[email protected]>
PATCH v2 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
Wei Liu
maintainerRe: [PATCH v2 13/15] uapi: hyperv: Add mshv driver headers hvhdk.h, hvhdk_mini.h, hvgdk.h, hvgdk_mini.h
Quoted 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 7 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]>Acked-by Wei Liu <[email protected]>
There were some concerns raised internally about the stability of the APIs when they are put into UAPI.
I think this is still okay, for a few reasons:
1. When KVM was first introduced into the kernel tree, it was experimental. It was only made stable after some time.
2. There are other experimental or unstable APIs in UAPI. They are clearly marked so.
3. The coda file system, which has been in tree since 2008, has a header file in UAPI which clearly marks as experimental.
All in all introducing a set of unstable / experimental APIs under UAPI is not unheard of. Rules could've changed now, but I don't find any document under Documentation/.
I think it will be valuable to have this driver in tree sooner rather than later, so that it can evolve with Linux kernel, and we can in turn go back to the hypervisor side to gradually stabilize the APIs.
Greg, I'm told that you may have a strong opinion in this area. Please let me know what you think about this.
KY, do you have an opinion here?
Thanks,
Wei.
Re: [PATCH v2 13/15] uapi: hyperv: Add mshv driver headers hvhdk.h, hvhdk_mini.h, hvgdk.h, hvgdk_mini.h
Quoted 33 lines · Wei Liu
Quoted 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.h25294Quoted 7 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]>Acked-by Wei Liu <[email protected]>There were some concerns raised internally about the stability of the APIs when they are put into UAPI.
I think this is still okay, for a few reasons:
1. When KVM was first introduced into the kernel tree, it was experimental. It was only made stable after some time.
2. There are other experimental or unstable APIs in UAPI. They are clearly marked so.
3. The coda file system, which has been in tree since 2008, has a header file in UAPI which clearly marks as experimental.All in all introducing a set of unstable / experimental APIs under UAPI is not unheard of. Rules could've changed now, but I don't find any document under
Documentation/.
Quoted 6 lines
I think it will be valuable to have this driver in tree sooner rather than later, so that it can evolve with Linux kernel, and we can in turn go back to the hypervisor side to gradually stabilize the APIs.
Greg, I'm told that you may have a strong opinion in this area. Please let me know what you think about this.
My "strong" opinion is the one kernel development rule that we have, "you can not break userspace". So, if you change these values/structures/whatever in the future, and userspace tools break, that's not ok and the changes have to be reverted.
If you can control both sides of the API here (with open tools that you can guarantee everyone will always update to), then yes, you can change the api in the future.
It's really really hard to make a stable api the first time around, but we have "tricks" for how to do it well, and ensure that you can slowly change it over time (proper use of flags and zero-checked padding), but almost always the simplest way is to just add new apis and keep supporting the old ones by internally calling the new functions instead.
So, what do you think will change here in the future and why can't you say "this is stable" now? You have working userspace code for this api, right? What is left to be developed for it?
thanks,
greg k-h
Re: [PATCH v2 13/15] uapi: hyperv: Add mshv driver headers hvhdk.h, hvhdk_mini.h, hvgdk.h, hvgdk_mini.h
Quoted 10 lines · Greg KH
My "strong" opinion is the one kernel development rule that we have, "you can not break userspace". So, if you change these values/structures/whatever in the future, and userspace tools break, that's not ok and the changes have to be reverted.
If you can control both sides of the API here (with open tools that you can guarantee everyone will always update to), then yes, you can change the api in the future.
This is true for us - we contribute and maintain support for this driver in Cloud Hypervisor[1], an open source VMM.
We also do a check of the hypervisor version when the driver loads, and refuse to proceed if it is running on an incompatible hypervisor.
Thanks,
Nuno Das Neves
Re: [PATCH v2 13/15] uapi: hyperv: Add mshv driver headers hvhdk.h, hvhdk_mini.h, hvgdk.h, hvgdk_mini.h
Quoted 7 lines · Nuno Das Neves
Quoted 6 lines · Greg KH
My "strong" opinion is the one kernel development rule that we have, "you can not break userspace". So, if you change these values/structures/whatever in the future, and userspace tools break, that's not ok and the changes have to be reverted.
Quoted 8 lines
Quoted 4 lines
If you can control both sides of the API here (with open tools that you can guarantee everyone will always update to), then yes, you can change the api in the future.
This is true for us - we contribute and maintain support for this driver in Cloud Hypervisor[1], an open source VMM.
Hi Greg,
Bringing up this discussion again so we can clear up any confusion on the uapi headers in this patch set.
The headers consist of the ioctls in mshv.h, and the hypervisor ABIs in the *hdk.h files. The ioctls depend on the hypervisor ABIs.
We will add (to the next version), an ioctl like KVM_GET_API_VERSION [1]. This will return a version number for the ioctl interface that increments any time there is a breaking change. Userspace would be required to check this before calling any other ioctl, and it can exit gracefully if there is a mismatch.
That's how KVM evolved its userspace ABI. We want to use the same approach.
I also wanted to reiterate that we are the only maintainers and users of the userspace code for this driver via Cloud Hypervisor [2]. We generate rust bindings from these headers using bindgen [3].
Taking this into account, is the above a viable path for this patch set?
Thanks,
Nuno
[1] https://docs.kernel.org/virt/kvm/api.html#kvm-get-api-version
[2] https://github.com/cloud-hypervisor/cloud-hypervisor
[3] https://github.com/rust-lang/rust-bindgen
Re: [PATCH v2 13/15] uapi: hyperv: Add mshv driver headers hvhdk.h, hvhdk_mini.h, hvgdk.h, hvgdk_mini.h
Quoted 25 lines · Nuno Das Neves
Quoted 7 lines · Nuno Das Neves
Quoted 6 lines · Greg KH
My "strong" opinion is the one kernel development rule that we have, "you can not break userspace". So, if you change these values/structures/whatever in the future, and userspace tools break, that's not ok and the changes have to be reverted.
Quoted 8 lines
Quoted 4 lines
If you can control both sides of the API here (with open tools that you can guarantee everyone will always update to), then yes, you can change the api in the future.
This is true for us - we contribute and maintain support for this driver in Cloud Hypervisor[1], an open source VMM.
Hi Greg,
Bringing up this discussion again so we can clear up any confusion on the uapi headers in this patch set.
The headers consist of the ioctls in
mshv.h, and the hypervisor ABIs in the *hdk.h files. The ioctls depend on the hypervisor ABIs.
Quoted 7 lines
We will add (to the next version), an ioctl like
KVM_GET_API_VERSION[1]. This will return a version number for the ioctl interface that increments any time there is a breaking change. Userspace would be required to check this before calling any other ioctl, and it can exit gracefully if there is a mismatch.That's how KVM evolved its userspace ABI. We want to use the same approach.
That's one way to do interfaces, but there are better ways as you know. What do you expect to change that is going to require such heavy-handed treatment of structures and ioctls?
And how are you going to handle backwards compatiblity?
Versioning things is almost always a pain, and should only be done as a last resort as a sign of an api that is not well understood at creation time. Surely you have studied how other hypervisor interfaces work and know what you need to do for yours by now, right? This isn't the first hypervisor api in Linux like KVM was when it was introduced a few decades ago. Why not learn from past mistakes and design patterns instead of just blindly imitating old apis that perhaps should not be imitated at all?
Quoted 2 lines
I also wanted to reiterate that we are the only maintainers and users of the userspace code for this driver via Cloud Hypervisor [2].
For today, maybe, but you can never guarantee that in the future as you well know.
Quoted 1 line
We generate rust bindings from these headers using bindgen [3].
What does rust have to do with anything here? You can use m4 to parse the headers for all we care :)
Quoted 1 line
Taking this into account, is the above a viable path for this patch set?
I have no idea, sorry, I don't see any patches here to review as the original set is long-gone from my queue.
Just submit your fixed up patch series based on the previous review comments and it will be reviewed again, just like all kernel patches are. Why is this set somehow more special than anything else?
Perhaps you all should take the time to do some kernel patch reviews of other stuff sent to the mailing lists to get an idea of how this whole process works, and to get better integrated into the kernel development community, before dumping a huge patchset on us with lots of process questions like this? Why are you asking the community to do a lot of work and hand-holding when you aren't helping others out as well?
good luck!
greg k-h
Re: [PATCH v2 13/15] uapi: hyperv: Add mshv driver headers hvhdk.h, hvhdk_mini.h, hvgdk.h, hvgdk_mini.h
Quoted 9 lines · Greg KH
Quoted 8 lines · Nuno Das Neves
Quoted 7 lines · Nuno Das Neves
Quoted 6 lines · Greg KH
My "strong" opinion is the one kernel development rule that we have, "you can not break userspace". So, if you change these values/structures/whatever in the future, and userspace tools break, that's not ok and the changes have to be reverted.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
If you can control both sides of the API here (with open tools that you can guarantee everyone will always update to), then yes, you can change the api in the future.
We control both sides of the API. The code is open. No one else can use it today, therefore we can guarantee all the users will stay updated.
Quoted 3 lines
Just submit your fixed up patch series based on the previous review comments and it will be reviewed again, just like all kernel patches are.
I will do that.
Quoted 4 lines
Perhaps you all should take the time to do some kernel patch reviews of other stuff sent to the mailing lists to get an idea of how this whole process works, and to get better integrated into the kernel development community,
That is a good suggestion, I will do that.
Quoted 3 lines
before dumping a huge patchset on us with lots of process questions like this? Why are you asking the community to do a lot of work and hand-holding when you aren't helping others out as well?
I take your point, sorry my questions came off that way. I will work to improve on that :)
Thanks,
Nuno
PATCH v2 14/15 asm-generic: hyperv: Use mshv headers conditionally. Add asm-generic/hyperv-defs.h
In reply to Nuno Das NevesAdd 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.
This is needed to keep unstable Hyper-V interfaces independent of hyperv-tlfs.h. This ensures hvhdk.h replaces hyperv-tlfs.h in the mshv driver, even via indirect includes.
--- 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
Re: [PATCH v2 14/15] asm-generic: hyperv: Use mshv headers conditionally. Add asm-generic/hyperv-defs.h
Quoted 10 lines · Nuno Das Neves
Add
hyperv-defs.hto replace some inclusions ofhyperv-tlfs.h.It includes
hyperv-tlfs.horhvhdk.hdepending on a compile-time constantHV_HYPERV_DEFSwhich will be defined in the mshv driver.This is needed to keep unstable Hyper-V interfaces independent of
hyperv-tlfs.h. This ensureshvhdk.hreplaceshyperv-tlfs.hin the mshv driver, even via indirect includes.Signed-off-by Nuno Das Neves <[email protected]>
PATCH v2 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:
Module mshv is the parent module to the other two. It provides /dev/mshv, plus some common hypercall helper code. When one of the child modules is loaded, it is registered with the mshv module, which then provides entry point(s) to the child module via the IOCTLs defined in uapi/linux/mshv.h.
E.g. When the mshv_root module is loaded, it registers itself, and the MSHV_CREATE_PARTITION IOCTL becomes available in /dev/mshv. That is used to get a partition fd managed by mshv_root.
Similarly for mshv_vtl module, there is MSHV_CREATE_VTL, which creates an fd representing the lower vtl, managed by mshv_vtl.
Module mshv_root provides APIs for creating and managing child partitions. It defines abstractions for partitions (vms), vps (vcpus), and other things related to running a guest. It exposes the userspace interfaces for a VMM to manage the guest.
Module mshv_vtl provides VTL (Virtual Trust Level) support for VMMs. In this scenario, the host kernel and VMM run in a higher trust level than the guest, but within the same partition. This provides better isolation and performance.
--- drivers/hv/Kconfig | 50 + drivers/hv/Makefile | 20 + drivers/hv/hv_call.c | 119 ++ drivers/hv/hv_common.c | 4 + 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 | 1542 +++++++++++++++++++++++++ drivers/hv/xfer_to_guest.c | 28 + include/uapi/linux/mshv.h | 298 +++++ 18 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 +50 -0
@@ -54,4 +54,54 @@ 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_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_XFER_TO_GUEST_WORK + bool + endmenu
drivers/hv/Makefile +20 -0
@@ -2,10 +2,30 @@ obj-$(CONFIG_HYPERV) += hv_vmbus.o obj-$(CONFIG_HYPERV_UTILS) += hv_utils.o obj-$(CONFIG_HYPERV_BALLOON) += hv_balloon.o +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/hv_common.c +4 -0
@@ -62,7 +62,11 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg);*/ static inline bool hv_output_arg_exists (void ) { +#ifdef CONFIG_MSHV_VTL +return true; +#else return hv_root_partition ? true : false; +#endif }static void hv_kmsg_dump_unregister (void );
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
113 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 +1542 -0
1,542 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.
RE: [PATCH v2 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
Quoted 116 lines
-----Original Message-----
From: Nuno Das Neves <[email protected]>
Sent: Friday, August 18, 2023 3:32 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]
Cc: [email protected]; Michael Kelley (LINUX) <[email protected]>; KY Srinivasan <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; Dexuan Cui <[email protected]>; [email protected]; Tianyu Lan <[email protected]>; [email protected]; MUKESH RATHOR <[email protected]>; [email protected]; [email protected]; vkuznets <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v2 15/15] Drivers: hv: Add modules to expose/dev/mshvto VMMs running on Hyper-VAdd mshv,
mshv_root, andmshv_vtlmodules:Module mshv is the parent module to the other two. It provides
/dev/mshv, plus
some common hypercall helper code. When one of the child modules is loaded, it
is registered with the mshv module, which then provides entry point(s) to the child module via the IOCTLs defined inuapi/linux/mshv.h.E.g. When the
mshv_rootmodule is loaded, it registers itself, and theMSHV_CREATE_PARTITIONIOCTL becomes available in/dev/mshv. That is used to
get a partition fd managed bymshv_root.Similarly for
mshv_vtlmodule, there isMSHV_CREATE_VTL, which creates an fd representing the lower vtl, managed bymshv_vtl.Module
mshv_rootprovides APIs for creating and managing child partitions. It
defines abstractions for partitions (vms), vps (vcpus), and other things related to running a guest. It exposes the userspace interfaces for a VMM to manage the guest.Module
mshv_vtlprovides VTL (Virtual Trust Level) support for VMMs. In this scenario, the host kernel and VMM run in a higher trust level than the guest, but within the same partition. This provides better isolation and performance.Signed-off-by Nuno Das Neves <[email protected]>--- drivers/hv/Kconfig | 50 + drivers/hv/Makefile | 20 + drivers/hv/hv_call.c | 119 ++ drivers/hv/hv_common.c | 4 + 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 | 1542 +++++++++++++++++++++++++ drivers/hv/xfer_to_guest.c | 28 + include/uapi/linux/mshv.h | 298 +++++ 18 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 +21
-0@@ -54,4 +54,54 @@ 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_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.
drivers/hv/Kconfig config HYPERV_BALLOON · line 87
Quoted 10 lines
drivers/hv/Kconfig +10
-0+ + 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
TRANSPARENT_HUGEPAGE can be avoided for now.
Quoted 116 lines
drivers/hv/Kconfig +19
-0+ 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_XFER_TO_GUEST_WORK + bool + endmenudrivers/hv/Makefile +16
-0@@ -2,10 +2,30 @@ obj-$(CONFIG_HYPERV) += hv_vmbus.o obj-$(CONFIG_HYPERV_UTILS) += hv_utils.o obj-$(CONFIG_HYPERV_BALLOON) += hv_balloon.o +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.omshv_root_hv_call.o hv_call.o
drivers/hv/Makefile +4
-0+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.odrivers/hv/hv_call.c new file +52
-0@@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2023, Microsoft Corporation. +* +* Hypercall helper functions shared between mshv modules. +* +* Authors: +* Nuno Das Neves <[email protected]> +*/ + +#include <linux/kernel.h> +#include <linux/mm.h> +#include <asm/mshyperv.h> + +#define HV_GET_REGISTER_BATCH_SIZE \ + (HV_HYP_PAGE_SIZE / sizeof(union hv_register_value)) +#define HV_SET_REGISTER_BATCH_SIZE \ + ((HV_HYP_PAGE_SIZE - sizeof(struct hv_input_set_vp_registers)) \ + / sizeof(struct hv_register_assoc)) + +int hv_call_get_vp_registers ( +u32 vp_index, +u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers) +{ +struct hv_input_get_vp_registers *input_page; +union hv_register_value *output_page; +u16 completed =0 ; +unsigned long remaining = count; +int rep_count, i; +u64 status; +unsigned long flags; + +local_irq_save (flags); + + input_page = *this_cpu_ptr (hyperv_pcpu_input_arg); + output_page = *this_cpu_ptr (hyperv_pcpu_output_arg); + + input_page->partition_id = partition_id; + input_page->vp_index = vp_index; + input_page->input_vtl.as_uint8 = input_vtl.as_uint8; + input_page->rsvd_z8 =0 ; + input_page->rsvd_z16 =0 ; + +while (remaining) { + rep_count =min (remaining,HV_GET_REGISTER_BATCH_SIZE ); +for (i =0 ; i < rep_count; ++i) + input_page->names[i] = registers[i].name; + + status = hv_do_rep_hypercall(HVCALL_GET_VP_REGISTERS,
rep_count,
drivers/hv/hv_call.c
Quoted 1 line
drivers/hv/hv_call.c new file +1
-0+ 0, input_page, output_page);
Is there any possibility that count value is passed 0 by mistake ? In that case status will remain uninitialized.
Quoted 72 lines
drivers/hv/hv_call.c new file +48
-0+if (!hv_result_success (status)) { +pr_err ("%s: completed %li out of %u, %s\n" , + __func__, + count - remaining, count, +hv_status_to_string (status)); +break ; + } + completed =hv_repcomp (status); +for (i =0 ; i < completed; ++i) + registers[i].value = output_page[i]; + + registers += completed; + remaining -= completed; + } +local_irq_restore (flags); + +return hv_status_to_errno (status); +} + +int hv_call_set_vp_registers ( +u32 vp_index, +u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers) +{ +struct hv_input_set_vp_registers *input_page; +u16 completed =0 ; +unsigned long remaining = count; +int rep_count; +u64 status; +unsigned long flags; + +local_irq_save (flags); + input_page = *this_cpu_ptr (hyperv_pcpu_input_arg); + + input_page->partition_id = partition_id; + input_page->vp_index = vp_index; + input_page->input_vtl.as_uint8 = input_vtl.as_uint8; + input_page->rsvd_z8 =0 ; + input_page->rsvd_z16 =0 ; + +while (remaining) { + rep_count =min (remaining,HV_SET_REGISTER_BATCH_SIZE ); +memcpy (input_page->elements, registers, +sizeof (struct hv_register_assoc ) * rep_count); + + status = hv_do_rep_hypercall(HVCALL_SET_VP_REGISTERS,
rep_count,drivers/hv/hv_call.c new file +18
-0+ 0, input_page, NULL); +if (!hv_result_success (status)) { +pr_err ("%s: completed %li out of %u, %s\n" , + __func__, + count - remaining, count, +hv_status_to_string (status)); +break ; + } + completed =hv_repcomp (status); + registers += completed; + remaining -= completed; + } + +local_irq_restore (flags); + +return hv_status_to_errno (status); +} +drivers/hv/hv_common.c +0
-0
drivers/hv/hv_common.c EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg); · line 65
Quoted 4 lines
drivers/hv/hv_common.c +1
-0@@ -62,7 +62,11 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg);*/ static inline bool hv_output_arg_exists (void ) { +#ifdef CONFIG_MSHV_VTL
Although today both the option works together. But thinking which is more accurate CONFIG_HYPERV_VTL_MODE or CONFIG_MSHV_VTL here for scalability of VTL modules.
Quoted 61 lines
drivers/hv/hv_common.c +3
-0+return true; +#else return hv_root_partition ? true : false; +#endif }static void hv_kmsg_dump_unregister (void );drivers/hv/mshv.h new file +48
-0@@ -0,0 +1,156 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2023, Microsoft Corporation. +*/ + +#ifndef _MSHV_H_ +#define _MSHV_H_ + +#include <linux/spinlock.h> +#include <linux/mutex.h> +#include <linux/semaphore.h> +#include <linux/sched.h> +#include <linux/srcu.h> +#include <linux/wait.h> +#include <uapi/linux/mshv.h> + +/* +* Hyper-V hypercalls +*/ + +int hv_call_withdraw_memory (u64 count,int node,u64 partition_id); +int hv_call_create_partition ( +u64 flags, +struct hv_partition_creation_properties creation_properties, +union hv_partition_isolation_properties isolation_properties, +u64 *partition_id); +int hv_call_initialize_partition (u64 partition_id); +int hv_call_finalize_partition (u64 partition_id); +int hv_call_delete_partition (u64 partition_id); +int hv_call_map_gpa_pages ( +u64 partition_id, +u64 gpa_target, +u64 page_count,u32 flags, +struct page **pages); +int hv_call_unmap_gpa_pages ( +u64 partition_id, +u64 gpa_target, +u64 page_count,u32 flags); +int hv_call_get_vp_registers ( +u32 vp_index, +u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers); +int hv_call_get_gpa_access_states( + u64 partition_id, + u32 count, + u64 gpa_base_pfn,
drivers/hv/mshv.h line 58
Quoted 10 lines
drivers/hv/mshv.h new file +10
-0+u64 state_flags, + int *written_total, + union hv_gpa_page_access_state *states); + +int hv_call_set_vp_registers ( +u32 vp_index, +u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers);
Nit: Opportunity to fix many of the checkpatch.pl related to line break here and many other places.
Quoted 762 lines
drivers/hv/mshv.h new file +35
-0+int hv_call_install_intercept (u64 partition_id,u32 access_type, +enum hv_intercept_type intercept_type, +union hv_intercept_parameters intercept_parameter); +int hv_call_assert_virtual_interrupt ( +u64 partition_id, +u32 vector, +u64 dest_addr, +union hv_interrupt_control control); +int hv_call_clear_virtual_interrupt (u64 partition_id); + +#ifdef HV_SUPPORTS_VP_STATE +int hv_call_get_vp_state ( +u32 vp_index, +u64 partition_id, +enum hv_get_set_vp_state_type type, +struct hv_vp_state_data_xsave xsave, +/* Choose between pages and ret_output */ +u64 page_count, +struct page **pages, +union hv_output_get_vp_state *ret_output); +int hv_call_set_vp_state ( +u32 vp_index, +u64 partition_id, +enum hv_get_set_vp_state_type type, +struct hv_vp_state_data_xsave xsave, +/* Choose between pages and bytes */ +u64 page_count, +struct page **pages, +u32 num_bytes, +u8 *bytes); +#endif + +int hv_call_map_vp_state_page (u64 partition_id,u32 vp_index,u32 type, +struct page **state_page); +int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32type);
drivers/hv/mshv.h new file +24
-0+int hv_call_get_partition_property ( +u64 partition_id, +u64 property_code, +u64 *property_value); +int hv_call_set_partition_property ( +u64 partition_id,u64 property_code,u64 property_value, +void (*completion_handler)(void */* data */ ,u64 */* status */ ), +void *completion_data); +int hv_call_translate_virtual_address ( +u32 vp_index, +u64 partition_id, +u64 flags, +u64 gva, +u64 *gpa, +union hv_translate_gva_result *result); +int hv_call_get_vp_cpuid_values ( +u32 vp_index, +u64 partition_id, +union hv_get_vp_cpuid_values_flags values_flags, +struct hv_cpuid_leaf_info *info, +union hv_output_get_vp_cpuid_values *result); + +int hv_call_create_port (u64 port_partition_id,union hv_port_id port_id, + u64 connection_partition_id, struct hv_port_info
*port_info,drivers/hv/mshv.h new file +15
-0+ u8 port_vtl, u8 min_connection_vtl, int node); +int hv_call_delete_port (u64 port_partition_id,union hv_port_id port_id); +int hv_call_connect_port (u64 port_partition_id,union hv_port_id port_id, +u64 connection_partition_id, +union hv_connection_id connection_id, +struct hv_connection_info *connection_info, +u8 connection_vtl,int node); +int hv_call_disconnect_port (u64 connection_partition_id, +union hv_connection_id connection_id); +int hv_call_notify_port_ring_empty (u32 sint_index); +#ifdef HV_SUPPORTS_REGISTER_INTERCEPT +int hv_call_register_intercept_result(u32 vp_index, + u64 partition_id, + enum hv_intercept_type intercept_type, + union
hv_register_intercept_result_parameters*params);drivers/hv/mshv.h new file +14
-0+#endif +int hv_call_signal_event_direct (u32 vp_index, +u64 partition_id, +u8 vtl, +u8 sint, +u16 flag_number, +u8 *newly_signaled); +int hv_call_post_message_direct (u32 vp_index, +u64 partition_id, +u8 vtl, +u32 sint_index, +u8 *message); + +struct mshv_partition *mshv_partition_find (u64 partition_id)
__must_hold(RCU);drivers/hv/mshv.h new file +10
-0+ +int mshv_xfer_to_guest_mode_handle_work (unsigned long ti_work); + +typedef long (*mshv_create_func_t )(void __user *user_arg); +typedef long (*mshv_check_ext_func_t )(u32 arg); +int mshv_setup_vtl_func (const mshv_create_func_t create_vtl, +const mshv_check_ext_func_t check_ext); +int mshv_set_create_partition_func (const mshv_create_func_t func); + +#endif /* _MSHV_H */ drivers/hv/mshv_eventfd.c new file +82
-0@@ -0,0 +1,758 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* eventfd support for mshv +* +* Heavily inspired from KVM implementation of irqfd/ioeventfd. The basic +* framework code is taken from the kvm implementation. +* +* All credits to kvm developers. +*/ + +#include <linux/syscalls.h> +#include <linux/wait.h> +#include <linux/poll.h> +#include <linux/file.h> +#include <linux/list.h> +#include <linux/workqueue.h> +#include <linux/eventfd.h> + +#include "mshv_eventfd.h" +#include "mshv.h" +#include "mshv_root.h" + +static struct workqueue_struct *irqfd_cleanup_wq; + +void +mshv_register_irq_ack_notifier (struct mshv_partition *partition, +struct mshv_irq_ack_notifier *mian) +{ +mutex_lock (&partition->irq_lock); +hlist_add_head_rcu (&mian->link, &partition->irq_ack_notifier_list); +mutex_unlock (&partition->irq_lock); +} + +void +mshv_unregister_irq_ack_notifier (struct mshv_partition *partition, +struct mshv_irq_ack_notifier *mian) +{ +mutex_lock (&partition->irq_lock); +hlist_del_init_rcu (&mian->link); +mutex_unlock (&partition->irq_lock); +synchronize_rcu (); +} + +bool +mshv_notify_acked_gsi (struct mshv_partition *partition,int gsi) +{ +struct mshv_irq_ack_notifier *mian; +bool acked = false; + +rcu_read_lock (); +hlist_for_each_entry_rcu (mian, &partition->irq_ack_notifier_list, + link) { +if (mian->gsi == gsi) { + mian->irq_acked (mian); + acked = true; + } + } +rcu_read_unlock (); + +return acked; +} + +static inline bool hv_should_clear_interrupt (enum hv_interrupt_type type) +{ +return type ==HV_X64_INTERRUPT_TYPE_EXTINT ; +} + +static void +irqfd_resampler_ack (struct mshv_irq_ack_notifier *mian) +{ +struct mshv_kernel_irqfd_resampler *resampler; +struct mshv_partition *partition; +struct mshv_kernel_irqfd *irqfd; +int idx; + + resampler =container_of (mian, + struct mshv_kernel_irqfd_resampler, notifier); + partition = resampler->partition; + + idx =srcu_read_lock (&partition->irq_srcu); + + hlist_for_each_entry_rcu(irqfd, &resampler->irqfds_list,
resampler_hnode) {drivers/hv/mshv_eventfd.c new file +1
-0+ if (hv_should_clear_interrupt(irqfd-Quoted 1 line
lapic_irq.control.interrupt_type))
drivers/hv/mshv_eventfd.c new file +64
-0+hv_call_clear_virtual_interrupt (partition->id); + +eventfd_signal (irqfd->resamplefd,1 ); + } + +srcu_read_unlock (&partition->irq_srcu, idx); +} + +static void +irqfd_assert (struct work_struct *work) +{ +struct mshv_kernel_irqfd *irqfd = + container_of(work, struct mshv_kernel_irqfd, assert); +struct mshv_lapic_irq *irq = &irqfd->lapic_irq; + +hv_call_assert_virtual_interrupt (irqfd->partition->id, + irq->vector, irq->apic_id, + irq->control); +} + +static void +irqfd_inject (struct mshv_kernel_irqfd *irqfd) +{ +struct mshv_partition *partition = irqfd->partition; +struct mshv_lapic_irq *irq = &irqfd->lapic_irq; +unsigned int seq; +int idx; + +WARN_ON (irqfd->resampler && + !irq->control.level_triggered); + + idx =srcu_read_lock (&partition->irq_srcu); +if (irqfd->msi_entry.gsi) { +if (!irqfd->msi_entry.entry_valid) { +pr_warn ("Invalid routing info for gsi %u" , + irqfd->msi_entry.gsi); +srcu_read_unlock (&partition->irq_srcu, idx); +return ; + } + +do { + seq =read_seqcount_begin (&irqfd->msi_entry_sc); + }while (read_seqcount_retry (&irqfd->msi_entry_sc, seq)); + } + +srcu_read_unlock (&partition->irq_srcu, idx); + +schedule_work (&irqfd->assert); +} + +static void +irqfd_resampler_shutdown (struct mshv_kernel_irqfd *irqfd) +{ +struct mshv_kernel_irqfd_resampler *resampler = irqfd->resampler; +struct mshv_partition *partition = resampler->partition; + +mutex_lock (&partition->irqfds.resampler_lock); + +hlist_del_rcu (&irqfd->resampler_hnode); +synchronize_srcu (&partition->irq_srcu); + +if (hlist_empty (&resampler->irqfds_list)) { +hlist_del (&resampler->hnode); + mshv_unregister_irq_ack_notifier(partition, &resampler-Quoted 1 line
notifier);
drivers/hv/mshv_eventfd.c new file +210
-0+kfree (resampler); + } + +mutex_unlock (&partition->irqfds.resampler_lock); +} + +/* +* Race-free decouple logic (ordering is critical) +*/ +static void +irqfd_shutdown (struct work_struct *work) +{ +struct mshv_kernel_irqfd *irqfd = + container_of(work, struct mshv_kernel_irqfd, shutdown); + +/* +* Synchronize with the wait-queue and unhook ourselves to prevent +* further events. +*/ +remove_wait_queue (irqfd->wqh, &irqfd->wait); + +if (irqfd->resampler) { +irqfd_resampler_shutdown (irqfd); +eventfd_ctx_put (irqfd->resamplefd); + } + +/* +* We know no new events will be scheduled at this point, so block +* until all previously outstanding events have completed +*/ +flush_work (&irqfd->assert); + +/* +* It is now safe to release the object's resources +*/ +eventfd_ctx_put (irqfd->eventfd); +kfree (irqfd); +} + +/* assumes partition->irqfds.lock is held */ +static bool +irqfd_is_active (struct mshv_kernel_irqfd *irqfd) +{ +return !hlist_unhashed (&irqfd->hnode); +} + +/* +* Mark the irqfd as inactive and schedule it for removal +* +* assumes partition->irqfds.lock is held +*/ +static void +irqfd_deactivate (struct mshv_kernel_irqfd *irqfd) +{ +WARN_ON (!irqfd_is_active (irqfd)); + +hlist_del (&irqfd->hnode); + +queue_work (irqfd_cleanup_wq, &irqfd->shutdown); +} + +/* +* Called with wqh->lock held and interrupts disabled +*/ +static int +irqfd_wakeup (wait_queue_entry_t *wait,unsigned int mode, +int sync,void *key) +{ +struct mshv_kernel_irqfd *irqfd = + container_of(wait, struct mshv_kernel_irqfd, wait); +unsigned long flags = (unsigned long )key; +int idx; +unsigned int seq; +struct mshv_partition *partition = irqfd->partition; +int ret =0 ; + +if (flags &POLLIN ) { +u64 cnt; + +eventfd_ctx_do_read (irqfd->eventfd, &cnt); + idx =srcu_read_lock (&partition->irq_srcu); +do { + seq =read_seqcount_begin (&irqfd->msi_entry_sc); + }while (read_seqcount_retry (&irqfd->msi_entry_sc, seq)); + +/* An event has been signaled, inject an interrupt */ +irqfd_inject (irqfd); +srcu_read_unlock (&partition->irq_srcu, idx); + + ret =1 ; + } + +if (flags &POLLHUP ) { +/* The eventfd is closing, detach from Partition */ +unsigned long flags; + +spin_lock_irqsave (&partition->irqfds.lock, flags); + +/* +* We must check if someone deactivated the irqfd before +* we could acquire the irqfds.lock since the item is +* deactivated from the mshv side before it is unhooked from +* the wait-queue. If it is already deactivated, we can +* simply return knowing the other side will cleanup for us. +* We cannot race against the irqfd going away since the +* other side is required to acquire wqh->lock, which we hold +*/ +if (irqfd_is_active (irqfd)) +irqfd_deactivate (irqfd); + +spin_unlock_irqrestore (&partition->irqfds.lock, flags); + } + +return ret; +} + +/* Must be called under irqfds.lock */ +static void irqfd_update (struct mshv_partition *partition, +struct mshv_kernel_irqfd *irqfd) +{ +write_seqcount_begin (&irqfd->msi_entry_sc); + irqfd->msi_entry =mshv_msi_map_gsi (partition, irqfd->gsi); +mshv_set_msi_irq (&irqfd->msi_entry, &irqfd->lapic_irq); +write_seqcount_end (&irqfd->msi_entry_sc); +} + +void mshv_irqfd_routing_update (struct mshv_partition *partition) +{ +struct mshv_kernel_irqfd *irqfd; + +spin_lock_irq (&partition->irqfds.lock); +hlist_for_each_entry (irqfd, &partition->irqfds.items, hnode) +irqfd_update (partition, irqfd); +spin_unlock_irq (&partition->irqfds.lock); +} + +static void +irqfd_ptable_queue_proc (struct file *file,wait_queue_head_t *wqh, +poll_table *pt) +{ +struct mshv_kernel_irqfd *irqfd = + container_of(pt, struct mshv_kernel_irqfd, pt); + + irqfd->wqh = wqh; +add_wait_queue_priority (wqh, &irqfd->wait); +} + +static int +mshv_irqfd_assign (struct mshv_partition *partition, +struct mshv_irqfd *args) +{ +struct eventfd_ctx *eventfd =NULL , *resamplefd =NULL ; +struct mshv_kernel_irqfd *irqfd, *tmp; +unsigned int events; +struct fd f; +int ret; +int idx; + + irqfd =kzalloc (sizeof (*irqfd),GFP_KERNEL ); +if (!irqfd) +return -ENOMEM ; + + irqfd->partition = partition; + irqfd->gsi = args->gsi; +INIT_WORK (&irqfd->shutdown, irqfd_shutdown); +INIT_WORK (&irqfd->assert, irqfd_assert); +seqcount_spinlock_init (&irqfd->msi_entry_sc, + &partition->irqfds.lock); + + f =fdget (args->fd); +if (!f.file) { + ret = -EBADF ; + goto out; + } + + eventfd =eventfd_ctx_fileget (f.file); +if (IS_ERR (eventfd)) { + ret =PTR_ERR (eventfd); + goto fail; + } + + irqfd->eventfd = eventfd; + +if (args->flags &MSHV_IRQFD_FLAG_RESAMPLE ) { +struct mshv_kernel_irqfd_resampler *resampler; + + resamplefd =eventfd_ctx_fdget (args->resamplefd); +if (IS_ERR (resamplefd)) { + ret =PTR_ERR (resamplefd); + goto fail; + } + + irqfd->resamplefd = resamplefd; + +mutex_lock (&partition->irqfds.resampler_lock); + +hlist_for_each_entry (resampler, + &partition->irqfds.resampler_list, hnode) { +if (resampler->notifier.gsi == irqfd->gsi) { + irqfd->resampler = resampler; +break ; + } + } + +if (!irqfd->resampler) { + resampler =kzalloc (sizeof (*resampler), +GFP_KERNEL_ACCOUNT ); +if (!resampler) { + ret = -ENOMEM ; + mutex_unlock(&partition-Quoted 1 line
irqfds.resampler_lock);
drivers/hv/mshv_eventfd.c new file +9
-0+ goto fail; + } + + resampler->partition = partition; +INIT_HLIST_HEAD (&resampler->irqfds_list); + resampler->notifier.gsi = irqfd->gsi; + resampler->notifier.irq_acked = irqfd_resampler_ack; + + hlist_add_head(&resampler->hnode, &partition-Quoted 1 line
irqfds.resampler_list);
drivers/hv/mshv_eventfd.c new file +6
-0+mshv_register_irq_ack_notifier (partition, + &resampler->notifier); + irqfd->resampler = resampler; + } + + hlist_add_head_rcu(&irqfd->resampler_hnode, &irqfd-Quoted 1 line
resampler->irqfds_list);drivers/hv/mshv_eventfd.c new file +234
-0+ +mutex_unlock (&partition->irqfds.resampler_lock); + } + +/* +* Install our own custom wake-up handling so we are notified via +* a callback whenever someone signals the underlying eventfd +*/ +init_waitqueue_func_entry (&irqfd->wait, irqfd_wakeup); +init_poll_funcptr (&irqfd->pt, irqfd_ptable_queue_proc); + +spin_lock_irq (&partition->irqfds.lock); +if (args->flags &MSHV_IRQFD_FLAG_RESAMPLE && + !irqfd->lapic_irq.control.level_triggered) { +/* +* Resample Fd must be for level triggered interrupt +* Otherwise return with failure +*/ +spin_unlock_irq (&partition->irqfds.lock); + ret = -EINVAL ; + goto fail; + } + ret =0 ; +hlist_for_each_entry (tmp, &partition->irqfds.items, hnode) { +if (irqfd->eventfd != tmp->eventfd) +continue ; +/* This fd is used for another irq already. */ + ret = -EBUSY ; +spin_unlock_irq (&partition->irqfds.lock); + goto fail; + } + + idx =srcu_read_lock (&partition->irq_srcu); +irqfd_update (partition, irqfd); +hlist_add_head (&irqfd->hnode, &partition->irqfds.items); +spin_unlock_irq (&partition->irqfds.lock); + +/* +* Check if there was an event already pending on the eventfd +* before we registered, and trigger it as if we didn't miss it. +*/ + events =vfs_poll (f.file, &irqfd->pt); + +if (events &POLLIN ) +irqfd_inject (irqfd); + +srcu_read_unlock (&partition->irq_srcu, idx); +/* +* do not drop the file until the irqfd is fully initialized, otherwise +* we might race against the POLLHUP +*/ +fdput (f); + +return 0 ; + +fail: +if (irqfd->resampler) +irqfd_resampler_shutdown (irqfd); + +if (resamplefd && !IS_ERR (resamplefd)) +eventfd_ctx_put (resamplefd); + +if (eventfd && !IS_ERR (eventfd)) +eventfd_ctx_put (eventfd); + +fdput (f); + +out: +kfree (irqfd); +return ret; +} + +/* +* shutdown any irqfd's that match fd+gsi +*/ +static int +mshv_irqfd_deassign (struct mshv_partition *partition, +struct mshv_irqfd *args) +{ +struct mshv_kernel_irqfd *irqfd; +struct hlist_node *n; +struct eventfd_ctx *eventfd; + + eventfd =eventfd_ctx_fdget (args->fd); +if (IS_ERR (eventfd)) +return PTR_ERR (eventfd); + +hlist_for_each_entry_safe (irqfd, n, &partition->irqfds.items, hnode) { +if (irqfd->eventfd == eventfd && irqfd->gsi == args->gsi) +irqfd_deactivate (irqfd); + } + +eventfd_ctx_put (eventfd); + +/* +* Block until we know all outstanding shutdown jobs have completed +* so that we guarantee there will not be any more interrupts on this +* gsi once this deassign function returns. +*/ +flush_workqueue (irqfd_cleanup_wq); + +return 0 ; +} + +int +mshv_irqfd (struct mshv_partition *partition,struct mshv_irqfd *args) +{ +if (args->flags &MSHV_IRQFD_FLAG_DEASSIGN ) +return mshv_irqfd_deassign (partition, args); + +return mshv_irqfd_assign (partition, args); +} + +/* +* This function is called as the mshv VM fd is being released. +* Shutdown all irqfds that still remain open +*/ +static void +mshv_irqfd_release (struct mshv_partition *partition) +{ +struct mshv_kernel_irqfd *irqfd; +struct hlist_node *n; + +spin_lock_irq (&partition->irqfds.lock); + +hlist_for_each_entry_safe (irqfd, n, &partition->irqfds.items, hnode) +irqfd_deactivate (irqfd); + +spin_unlock_irq (&partition->irqfds.lock); + +/* +* Block until we know all outstanding shutdown jobs have completed +* since we do not take a mshv_partition* reference. +*/ +flush_workqueue (irqfd_cleanup_wq); + +} + +int mshv_irqfd_wq_init (void ) +{ + irqfd_cleanup_wq =alloc_workqueue ("mshv-irqfd-cleanup" ,0 ,0 ); +if (!irqfd_cleanup_wq) +return -ENOMEM ; + +return 0 ; +} + +void mshv_irqfd_wq_cleanup (void ) +{ +destroy_workqueue (irqfd_cleanup_wq); +} + +/* +* -------------------------------------------------------------------- +* ioeventfd: translate a MMIO memory write to an eventfd signal. +* +* userspace can register a MMIO address with an eventfd for receiving +* notification when the memory has been touched. +* +* TODO: Implement eventfd for PIO as well. +* -------------------------------------------------------------------- +*/ + +static void +ioeventfd_release (struct kernel_mshv_ioeventfd *p,u64 partition_id) +{ +if (p->doorbell_id >0 ) +mshv_unregister_doorbell (partition_id, p->doorbell_id); +eventfd_ctx_put (p->eventfd); +kfree (p); +} + +/* MMIO writes trigger an event if the addr/val match */ +static void +ioeventfd_mmio_write (int doorbell_id,void *data) +{ +struct mshv_partition *partition = (struct mshv_partition *)data; +struct kernel_mshv_ioeventfd *p; + +rcu_read_lock (); +hlist_for_each_entry_rcu (p, &partition->ioeventfds.items, hnode) { +if (p->doorbell_id == doorbell_id) { +eventfd_signal (p->eventfd,1 ); +break ; + } + } +rcu_read_unlock (); +} + +static bool +ioeventfd_check_collision (struct mshv_partition *partition, +struct kernel_mshv_ioeventfd *p) + __must_hold(&partition->mutex) +{ +struct kernel_mshv_ioeventfd *_p; + +hlist_for_each_entry (_p, &partition->ioeventfds.items, hnode) +if (_p->addr == p->addr && _p->length == p->length && + (_p->wildcard || p->wildcard || + _p->datamatch == p->datamatch)) +return true; + +return false; +} + +static int +mshv_assign_ioeventfd (struct mshv_partition *partition, +struct mshv_ioeventfd *args) + __must_hold(&partition->mutex) +{ +struct kernel_mshv_ioeventfd *p; +struct eventfd_ctx *eventfd; +u64 doorbell_flags =0 ; +int ret; + +/* This mutex is currently protecting ioeventfd.items list */ +WARN_ON_ONCE (!mutex_is_locked (&partition->mutex)); + +if (args->flags &MSHV_IOEVENTFD_FLAG_PIO ) +return -EOPNOTSUPP ; + +/* must be natural-word sized */ +switch (args->len) { +case 0 : + doorbell_flags =HV_DOORBELL_FLAG_TRIGGER_SIZE_ANY ; +break ; +case 1 : + doorbell_flags =HV_DOORBELL_FLAG_TRIGGER_SIZE_BYTE ; +break ; +case 2 : + doorbell_flags =HV_DOORBELL_FLAG_TRIGGER_SIZE_WORD ; +break ; +case 4 : + doorbell_flags =
HV_DOORBELL_FLAG_TRIGGER_SIZE_DWORD;drivers/hv/mshv_eventfd.c new file +3
-0+break ; +case 8 : + doorbell_flags =
HV_DOORBELL_FLAG_TRIGGER_SIZE_QWORD;drivers/hv/mshv_eventfd.c new file +34
-0+break ; +default : +pr_warn ("ioeventfd: invalid length specified\n" ); +return -EINVAL ; + } + +/* check for range overflow */ +if (args->addr + args->len < args->addr) +return -EINVAL ; + +/* check for extra flags that we don't understand */ +if (args->flags & ~MSHV_IOEVENTFD_VALID_FLAG_MASK ) +return -EINVAL ; + + eventfd =eventfd_ctx_fdget (args->fd); +if (IS_ERR (eventfd)) +return PTR_ERR (eventfd); + + p =kzalloc (sizeof (*p),GFP_KERNEL ); +if (!p) { + ret = -ENOMEM ; + goto fail; + } + + p->addr = args->addr; + p->length = args->len; + p->eventfd = eventfd; + +/* The datamatch feature is optional, otherwise this is a wildcard */ +if (args->flags &MSHV_IOEVENTFD_FLAG_DATAMATCH ) + p->datamatch = args->datamatch; +else { + p->wildcard = true; + doorbell_flags |=
HV_DOORBELL_FLAG_TRIGGER_ANY_VALUE;drivers/hv/mshv_eventfd.c new file +2
-0+ } +
drivers/hv/mshv_eventfd.c line 655
Quoted 10 lines
drivers/hv/mshv_eventfd.c new file +10
-0+if (ioeventfd_check_collision (partition, p)) { + ret = -EEXIST ; + goto unlock_fail; + } + + ret =mshv_register_doorbell (partition->id, ioeventfd_mmio_write, + (void *)partition, p->addr, + p->datamatch, doorbell_flags); +if (ret <0 ) { +pr_err ("Failed to register ioeventfd doorbell!\n" );
Nit: Do we like to print function name at the start of pr_err.
- Saurabh
Re: [PATCH v2 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
Quoted 9 lines · Saurabh Singh Sengar
drivers/hv/Kconfig config HYPERV_BALLOON · line 87
Quoted 6 lines
drivers/hv/Kconfig +6
-0+ +config MSHV_VTL + tristate "Microsoft Hyper-V VTL driver" + depends on MSHV + select HYPERV_VTL_MODE + select TRANSPARENT_HUGEPAGE
TRANSPARENT_HUGEPAGEcan be avoided for now.
I will remove it in the next version. Thanks.
Quoted 36 lines
Quoted 36 lines
drivers/hv/hv_call.c new file +36
-0+ +#define HV_GET_REGISTER_BATCH_SIZE \ + (HV_HYP_PAGE_SIZE / sizeof(union hv_register_value)) +#define HV_SET_REGISTER_BATCH_SIZE \ + ((HV_HYP_PAGE_SIZE - sizeof(struct hv_input_set_vp_registers)) \ + / sizeof(struct hv_register_assoc)) + +int hv_call_get_vp_registers ( +u32 vp_index, +u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers) +{ +struct hv_input_get_vp_registers *input_page; +union hv_register_value *output_page; +u16 completed =0 ; +unsigned long remaining = count; +int rep_count, i; +u64 status; +unsigned long flags; + +local_irq_save (flags); + + input_page = *this_cpu_ptr (hyperv_pcpu_input_arg); + output_page = *this_cpu_ptr (hyperv_pcpu_output_arg); + + input_page->partition_id = partition_id; + input_page->vp_index = vp_index; + input_page->input_vtl.as_uint8 = input_vtl.as_uint8; + input_page->rsvd_z8 =0 ; + input_page->rsvd_z16 =0 ; + +while (remaining) { + rep_count =min (remaining,HV_GET_REGISTER_BATCH_SIZE ); +for (i =0 ; i < rep_count; ++i)
Quoted 9 lines
Review
Quoted 5 lines
drivers/hv/hv_call.c new file +3
-0+ input_page->names[i] = registers[i].name; + + status = hv_do_rep_hypercall(HVCALL_GET_VP_REGISTERS,
rep_count,(quoted diff) +1
-0+ 0, input_page, output_page);Is there any possibility that count value is passed 0 by mistake ? In that case status will remain uninitialized.
These lines ensure rep_count is never 0 here:
while (remaining) {
rep_count = min(remaining, HV_GET_REGISTER_BATCH_SIZE);Remaining can't be 0 or the loop would exit, and HV_GET_REGISTER_BATCH_SIZE is not 0, or we would never get any registers.
Quoted 5 lines
Quoted 5 lines
drivers/hv/hv_common.c +0
-0@@ -62,7 +62,11 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg);
Quoted 9 lines
drivers/hv/hv_common.c EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg); · line 65
Quoted 4 lines
drivers/hv/hv_common.c +1
-0*/ static inline bool hv_output_arg_exists (void ) { +#ifdef CONFIG_MSHV_VTL Although today both the option works together. But thinking which is more accurate
CONFIG_HYPERV_VTL_MODEorCONFIG_MSHV_VTLhere for scalability of VTL modules.
Good point. Though I'm not sure it matters too much right now, since as you mention they will always be enabled together.
Does CONFIG_HYPERV_VTL_MODE use the output arg?
Quoted 59 lines
Quoted 59 lines
drivers/hv/mshv.h new file +53
-0@@ -0,0 +1,156 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2023, Microsoft Corporation. +*/ + +#ifndef _MSHV_H_ +#define _MSHV_H_ + +#include <linux/spinlock.h> +#include <linux/mutex.h> +#include <linux/semaphore.h> +#include <linux/sched.h> +#include <linux/srcu.h> +#include <linux/wait.h> +#include <uapi/linux/mshv.h> + +/* +* Hyper-V hypercalls +*/ + +int hv_call_withdraw_memory (u64 count,int node,u64 partition_id); +int hv_call_create_partition ( +u64 flags, +struct hv_partition_creation_properties creation_properties, +union hv_partition_isolation_properties isolation_properties, +u64 *partition_id); +int hv_call_initialize_partition (u64 partition_id); +int hv_call_finalize_partition (u64 partition_id); +int hv_call_delete_partition (u64 partition_id); +int hv_call_map_gpa_pages ( +u64 partition_id, +u64 gpa_target, +u64 page_count,u32 flags, +struct page **pages); +int hv_call_unmap_gpa_pages ( +u64 partition_id, +u64 gpa_target, +u64 page_count,u32 flags); +int hv_call_get_vp_registers ( +u32 vp_index, +u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers); +int hv_call_get_gpa_access_states ( +u64 partition_id, +u32 count, +u64 gpa_base_pfn, +u64 state_flags, +int *written_total, +union hv_gpa_page_access_state *states); + +int hv_call_set_vp_registers(
Quoted 9 lines
drivers/hv/mshv.h line 44
Quoted 5 lines
drivers/hv/mshv.h new file +5
-0+u32 vp_index, + u64 partition_id, + u16 count, + union hv_input_vtl input_vtl, + struct hv_register_assoc *registers);Nit: Opportunity to fix many of the checkpatch.pl related to line break here and many other places.
checkpatch.pl doesn't complain about anything in this file.
Quoted 75 lines
Quoted 75 lines
drivers/hv/mshv.h new file +29
-0+static int +mshv_assign_ioeventfd (struct mshv_partition *partition, +struct mshv_ioeventfd *args) + __must_hold(&partition->mutex) +{ +struct kernel_mshv_ioeventfd *p; +struct eventfd_ctx *eventfd; +u64 doorbell_flags =0 ; +int ret; + +/* This mutex is currently protecting ioeventfd.items list */ +WARN_ON_ONCE (!mutex_is_locked (&partition->mutex)); + +if (args->flags &MSHV_IOEVENTFD_FLAG_PIO ) +return -EOPNOTSUPP ; + +/* must be natural-word sized */ +switch (args->len) { +case 0 : + doorbell_flags =HV_DOORBELL_FLAG_TRIGGER_SIZE_ANY ; +break ; +case 1 : + doorbell_flags =HV_DOORBELL_FLAG_TRIGGER_SIZE_BYTE ; +break ; +case 2 : + doorbell_flags =HV_DOORBELL_FLAG_TRIGGER_SIZE_WORD ; +break ; +case 4 : + doorbell_flags =
HV_DOORBELL_FLAG_TRIGGER_SIZE_DWORD;drivers/hv/mshv.h new file +3
-0+break ; +case 8 : + doorbell_flags =
HV_DOORBELL_FLAG_TRIGGER_SIZE_QWORD;drivers/hv/mshv.h new file +34
-0+break ; +default : +pr_warn ("ioeventfd: invalid length specified\n" ); +return -EINVAL ; + } + +/* check for range overflow */ +if (args->addr + args->len < args->addr) +return -EINVAL ; + +/* check for extra flags that we don't understand */ +if (args->flags & ~MSHV_IOEVENTFD_VALID_FLAG_MASK ) +return -EINVAL ; + + eventfd =eventfd_ctx_fdget (args->fd); +if (IS_ERR (eventfd)) +return PTR_ERR (eventfd); + + p =kzalloc (sizeof (*p),GFP_KERNEL ); +if (!p) { + ret = -ENOMEM ; + goto fail; + } + + p->addr = args->addr; + p->length = args->len; + p->eventfd = eventfd; + +/* The datamatch feature is optional, otherwise this is a wildcard */ +if (args->flags &MSHV_IOEVENTFD_FLAG_DATAMATCH ) + p->datamatch = args->datamatch; +else { + p->wildcard = true; + doorbell_flags |=
HV_DOORBELL_FLAG_TRIGGER_ANY_VALUE;drivers/hv/mshv.h new file +6
-0+ } + +if (ioeventfd_check_collision (partition, p)) { + ret = -EEXIST ; + goto unlock_fail; + }
Quoted 9 lines
drivers/hv/mshv.h
Quoted 6 lines
drivers/hv/mshv.h new file +6
-0+ + ret =mshv_register_doorbell (partition->id, ioeventfd_mmio_write, + (void *)partition, p->addr, + p->datamatch, doorbell_flags); +if (ret <0 ) { +pr_err ("Failed to register ioeventfd doorbell!\n" );Nit: Do we like to print function name at the start of
pr_err.
Yes, we should. I will fix it. Thanks!
RE: [PATCH v2 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
Quoted 78 lines
-----Original Message-----
From: Nuno Das Neves <[email protected]>
Sent: Saturday, August 19, 2023 12:30 AM
To: Saurabh Singh Sengar <[email protected]>; linux- [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: [email protected]; Michael Kelley (LINUX) <[email protected]>; KY Srinivasan <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; Dexuan Cui <[email protected]>; [email protected]; Tianyu Lan <[email protected]>; [email protected]; MUKESH RATHOR <[email protected]>; [email protected]; [email protected]; vkuznets <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 15/15] Drivers: hv: Add modules to expose/dev/mshvto VMMs running on Hyper-VQuoted 9 lines · Saurabh Singh Sengar
drivers/hv/Kconfig config HYPERV_BALLOON · line 87
Quoted 6 lines
drivers/hv/Kconfig +6
-0+ +config MSHV_VTL + tristate "Microsoft Hyper-V VTL driver" + depends on MSHV + select HYPERV_VTL_MODE + select TRANSPARENT_HUGEPAGE
TRANSPARENT_HUGEPAGEcan be avoided for now.I will remove it in the next version. Thanks.
Quoted 35 lines
Quoted 35 lines
drivers/hv/hv_call.c new file +35
-0+ +#define HV_GET_REGISTER_BATCH_SIZE \ + (HV_HYP_PAGE_SIZE / sizeof(union hv_register_value)) +#define HV_SET_REGISTER_BATCH_SIZE \ + ((HV_HYP_PAGE_SIZE - sizeof(struct hv_input_set_vp_registers)) \ + / sizeof(struct hv_register_assoc)) + +int hv_call_get_vp_registers ( +u32 vp_index, +u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers) { +struct hv_input_get_vp_registers *input_page; +union hv_register_value *output_page; +u16 completed =0 ; +unsigned long remaining = count; +int rep_count, i; +u64 status; +unsigned long flags; + +local_irq_save (flags); + + input_page = *this_cpu_ptr (hyperv_pcpu_input_arg); + output_page = *this_cpu_ptr (hyperv_pcpu_output_arg); + + input_page->partition_id = partition_id; + input_page->vp_index = vp_index; + input_page->input_vtl.as_uint8 = input_vtl.as_uint8; + input_page->rsvd_z8 =0 ; + input_page->rsvd_z16 =0 ; + +while (remaining) { + rep_count =min (remaining,HV_GET_REGISTER_BATCH_SIZE ); +for (i =0 ; i < rep_count; ++i)Quoted 9 lines
Review
Quoted 5 lines
drivers/hv/hv_call.c new file +3
-0+ input_page->names[i] = registers[i].name; + + status = hv_do_rep_hypercall(HVCALL_GET_VP_REGISTERS,
rep_count,(quoted diff) +1
-0+ 0, input_page, output_page);Is there any possibility that count value is passed 0 by mistake ? In that case status will remain uninitialized.
Quoted 7 lines
These lines ensure
rep_countis never 0 here:while (remaining) { rep_count = min(remaining, HV_GET_REGISTER_BATCH_SIZE);Remaining can't be 0 or the loop would exit, and
HV_GET_REGISTER_BATCH_SIZEis not 0, or we would never get any registers.
There is a parameter in this function "count". I was checking if there is any possibility that is passed as 0 by mistake ? this will lead to "remaining" value as 0 and loop will never execute. Which results using "status" uninitialized later in the function.
Quoted 15 lines
Quoted 14 lines
drivers/hv/hv_common.c EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg); · line 64
Quoted 9 lines
drivers/hv/hv_common.c index renamed from drivers/hv/hv_common.c +0
-0
13f972e72375..ccd76f30a638100644drivers/hv/hv_common.c +1
-0@@ -62,7 +62,11 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg);*/ static inline bool hv_output_arg_exists (void ) { +#ifdef CONFIG_MSHV_VTL Although today both the option works together. But thinking which is more accurate
CONFIG_HYPERV_VTL_MODEorCONFIG_MSHV_VTLhere for scalability of VTL modules.
Quoted 4 lines
Good point. Though I'm not sure it matters too much right now, since as you mention they will always be enabled together.
Does
CONFIG_HYPERV_VTL_MODEuse the output arg?
Currently its not, I think MSHV_VTL is good for now. Thanks.
Quoted 70 lines
Quoted 60 lines
Quoted 60 lines
drivers/hv/mshv.h new file +53
-0@@ -0,0 +1,156 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2023, Microsoft Corporation. +*/ + +#ifndef _MSHV_H_ +#define _MSHV_H_ + +#include <linux/spinlock.h> +#include <linux/mutex.h> +#include <linux/semaphore.h> +#include <linux/sched.h> +#include <linux/srcu.h> +#include <linux/wait.h> +#include <uapi/linux/mshv.h> + +/* +* Hyper-V hypercalls +*/ + +int hv_call_withdraw_memory (u64 count,int node,u64 partition_id); +int hv_call_create_partition ( +u64 flags, +struct hv_partition_creation_properties creation_properties, +union hv_partition_isolation_properties isolation_properties, +u64 *partition_id); +int hv_call_initialize_partition (u64 partition_id); +int hv_call_finalize_partition (u64 partition_id); +int hv_call_delete_partition (u64 partition_id); +int hv_call_map_gpa_pages ( +u64 partition_id, +u64 gpa_target, +u64 page_count,u32 flags, +struct page **pages); +int hv_call_unmap_gpa_pages ( +u64 partition_id, +u64 gpa_target, +u64 page_count,u32 flags); +int hv_call_get_vp_registers ( +u32 vp_index, +u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers); +int hv_call_get_gpa_access_states ( +u64 partition_id, +u32 count, +u64 gpa_base_pfn, +u64 state_flags, +int *written_total, +union hv_gpa_page_access_state *states); + +int hv_call_set_vp_registers(Quoted 9 lines
drivers/hv/mshv.h line 44
Quoted 5 lines
drivers/hv/mshv.h new file +5
-0+u32 vp_index, + u64 partition_id, + u16 count, + union hv_input_vtl input_vtl, + struct hv_register_assoc *registers);Nit: Opportunity to fix many of the checkpatch.pl related to line break here and many other places.
Quoted 1 line
checkpatch.pl doesn't complain about anything in this file.
If we use --strict switch with checkpatch.pl we observe additional CHECK(s). I observe 159 CHECK(s) with this patch overall.
(total: 1 errors, 7 warnings, 159 checks, 7460 lines checked) Few examples:
CHECK: Lines should not end with a '('
#240: FILE: drivers/hv/hv_call.c:73:
+int hv_call_set_vp_registers(
CHECK: Alignment should match open parenthesis
#266: FILE: drivers/hv/hv_call.c:99:
+ memcpy(input_page->elements, registers,
+ sizeof(struct hv_register_assoc) * rep_count);
I also see an error with flexible array, possibly we can fix that as well.
ERROR: Use C99 flexible arrays - see https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
#7468: FILE: include/uapi/linux/mshv.h:134:
+ struct mshv_msi_routing_entry entries[0];
+};
- Saurabh
Re: [PATCH v2 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
Quoted 83 lines · Saurabh Singh Sengar
Quoted 83 lines
-----Original Message-----
From: Nuno Das Neves <[email protected]>
Sent: Saturday, August 19, 2023 12:30 AM
To: Saurabh Singh Sengar <[email protected]>; linux- [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: [email protected]; Michael Kelley (LINUX) <[email protected]>; KY Srinivasan <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; Dexuan Cui <[email protected]>; [email protected]; Tianyu Lan <[email protected]>; [email protected]; MUKESH RATHOR <[email protected]>; [email protected]; [email protected]; vkuznets <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 15/15] Drivers: hv: Add modules to expose/dev/mshvto VMMs running on Hyper-VQuoted 9 lines · Saurabh Singh Sengar
drivers/hv/Kconfig config HYPERV_BALLOON · line 87
Quoted 6 lines
drivers/hv/Kconfig +6
-0+ +config MSHV_VTL + tristate "Microsoft Hyper-V VTL driver" + depends on MSHV + select HYPERV_VTL_MODE + select TRANSPARENT_HUGEPAGE
TRANSPARENT_HUGEPAGEcan be avoided for now.I will remove it in the next version. Thanks.
Quoted 35 lines
Quoted 35 lines
drivers/hv/hv_call.c new file +35
-0+ +#define HV_GET_REGISTER_BATCH_SIZE \ + (HV_HYP_PAGE_SIZE / sizeof(union hv_register_value)) +#define HV_SET_REGISTER_BATCH_SIZE \ + ((HV_HYP_PAGE_SIZE - sizeof(struct hv_input_set_vp_registers)) \ + / sizeof(struct hv_register_assoc)) + +int hv_call_get_vp_registers ( +u32 vp_index, +u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers) { +struct hv_input_get_vp_registers *input_page; +union hv_register_value *output_page; +u16 completed =0 ; +unsigned long remaining = count; +int rep_count, i; +u64 status; +unsigned long flags; + +local_irq_save (flags); + + input_page = *this_cpu_ptr (hyperv_pcpu_input_arg); + output_page = *this_cpu_ptr (hyperv_pcpu_output_arg); + + input_page->partition_id = partition_id; + input_page->vp_index = vp_index; + input_page->input_vtl.as_uint8 = input_vtl.as_uint8; + input_page->rsvd_z8 =0 ; + input_page->rsvd_z16 =0 ; + +while (remaining) { + rep_count =min (remaining,HV_GET_REGISTER_BATCH_SIZE ); +for (i =0 ; i < rep_count; ++i)Quoted 9 lines
Review
Quoted 5 lines
drivers/hv/hv_call.c new file +3
-0+ input_page->names[i] = registers[i].name; + + status = hv_do_rep_hypercall(HVCALL_GET_VP_REGISTERS,
rep_count,(quoted diff) +1
-0+ 0, input_page, output_page);Is there any possibility that count value is passed 0 by mistake ? In that case status will remain uninitialized.
These lines ensure
rep_countis never 0 here:while (remaining) { rep_count = min(remaining, HV_GET_REGISTER_BATCH_SIZE);
Quoted 8 lines
Quoted 2 lines
Remaining can't be 0 or the loop would exit, and
HV_GET_REGISTER_BATCH_SIZEis not 0, or we would never get any registers.There is a parameter in this function "count". I was checking if there is any possibility that is passed as 0 by mistake ? this will lead to "remaining" value as 0 and loop will never execute. Which results using "status" uninitialized later in the function.
Ah ok, thanks! I will change it to return immediately in case count is 0.
Quoted 84 lines
Quoted 69 lines
Quoted 59 lines
Quoted 59 lines
drivers/hv/mshv.h new file +53
-0@@ -0,0 +1,156 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2023, Microsoft Corporation. +*/ + +#ifndef _MSHV_H_ +#define _MSHV_H_ + +#include <linux/spinlock.h> +#include <linux/mutex.h> +#include <linux/semaphore.h> +#include <linux/sched.h> +#include <linux/srcu.h> +#include <linux/wait.h> +#include <uapi/linux/mshv.h> + +/* +* Hyper-V hypercalls +*/ + +int hv_call_withdraw_memory (u64 count,int node,u64 partition_id); +int hv_call_create_partition ( +u64 flags, +struct hv_partition_creation_properties creation_properties, +union hv_partition_isolation_properties isolation_properties, +u64 *partition_id); +int hv_call_initialize_partition (u64 partition_id); +int hv_call_finalize_partition (u64 partition_id); +int hv_call_delete_partition (u64 partition_id); +int hv_call_map_gpa_pages ( +u64 partition_id, +u64 gpa_target, +u64 page_count,u32 flags, +struct page **pages); +int hv_call_unmap_gpa_pages ( +u64 partition_id, +u64 gpa_target, +u64 page_count,u32 flags); +int hv_call_get_vp_registers ( +u32 vp_index, +u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers); +int hv_call_get_gpa_access_states ( +u64 partition_id, +u32 count, +u64 gpa_base_pfn, +u64 state_flags, +int *written_total, +union hv_gpa_page_access_state *states); + +int hv_call_set_vp_registers(Quoted 9 lines
drivers/hv/mshv.h line 44
Quoted 5 lines
drivers/hv/mshv.h new file +5
-0+u32 vp_index, + u64 partition_id, + u16 count, + union hv_input_vtl input_vtl, + struct hv_register_assoc *registers);Nit: Opportunity to fix many of the checkpatch.pl related to line break here and many other places.
Quoted 1 line
checkpatch.pl doesn't complain about anything in this file.
If we use --strict switch with checkpatch.pl we observe additional CHECK(s). I observe 159 CHECK(s) with this patch overall.
(total: 1 errors, 7 warnings, 159 checks, 7460 lines checked) Few examples:CHECK: Lines should not end with a '('
#240: FILE:drivers/hv/hv_call.c:73:
+int hv_call_set_vp_registers(CHECK: Alignment should match open parenthesis
#266: FILE:drivers/hv/hv_call.c:99:
drivers/hv/hv_call.c line 99
Quoted 2 lines
drivers/hv/hv_call.c new file +2
-0+memcpy (input_page->elements, registers, +sizeof (struct hv_register_assoc ) * rep_count);
I didn't try --strict before. Thanks, I'll fix up the formatting.
include/uapi/linux/mshv.h line 134
Quoted 7 lines
I also see an error with flexible array, possibly we can fix that as well.
ERROR: Use C99 flexible arrays - see https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
#7468: FILE:include/uapi/linux/mshv.h:134:include/uapi/linux/mshv.h new file +2
-0+struct mshv_msi_routing_entry entries[0 ]; +};
Indeed, I'll fix it too.
RE: [PATCH v2 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
Quoted 110 lines
-----Original Message-----
From: Nuno Das Neves <[email protected]>
Sent: Wednesday, August 23, 2023 1:49 AM
To: Saurabh Singh Sengar <[email protected]>; linux- [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: [email protected]; Michael Kelley (LINUX) <[email protected]>; KY Srinivasan <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; Dexuan Cui <[email protected]>; [email protected]; Tianyu Lan <[email protected]>; [email protected]; MUKESH RATHOR <[email protected]>; [email protected]; [email protected]; vkuznets <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 15/15] Drivers: hv: Add modules to expose/dev/mshvto VMMs running on Hyper-VQuoted 14 lines · Saurabh Singh Sengar
Quoted 14 lines
-----Original Message-----
From: Nuno Das Neves <[email protected]>
Sent: Saturday, August 19, 2023 12:30 AM
To: Saurabh Singh Sengar <[email protected]>; linux- [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: [email protected]; Michael Kelley (LINUX) <[email protected]>; KY Srinivasan <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; Dexuan Cui <[email protected]>; [email protected]; Tianyu Lan <[email protected]>; [email protected]; MUKESH RATHOR <[email protected]>;Quoted 64 lines
Quoted 64 lines
[email protected]; vkuznets <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 15/15] Drivers: hv: Add modules to expose/dev/mshvto VMMs running on Hyper-VQuoted 9 lines · Saurabh Singh Sengar
drivers/hv/Kconfig config HYPERV_BALLOON · line 87
Quoted 6 lines
drivers/hv/Kconfig +6
-0+ +config MSHV_VTL + tristate "Microsoft Hyper-V VTL driver" + depends on MSHV + select HYPERV_VTL_MODE + select TRANSPARENT_HUGEPAGE
TRANSPARENT_HUGEPAGEcan be avoided for now.I will remove it in the next version. Thanks.
Quoted 44 lines
Quoted 39 lines
drivers/hv/hv_call.c new file +38
-0+ +#define HV_GET_REGISTER_BATCH_SIZE \ + (HV_HYP_PAGE_SIZE / sizeof(union hv_register_value)) +#define HV_SET_REGISTER_BATCH_SIZE \ + ((HV_HYP_PAGE_SIZE - sizeof(struct hv_input_set_vp_registers)) \ + / sizeof(struct hv_register_assoc)) + +int hv_call_get_vp_registers ( +u32 vp_index, +u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers) { +struct hv_input_get_vp_registers *input_page; +union hv_register_value *output_page; +u16 completed =0 ; +unsigned long remaining = count; +int rep_count, i; +u64 status; +unsigned long flags; + +local_irq_save (flags); + + input_page = *this_cpu_ptr (hyperv_pcpu_input_arg); + output_page = *this_cpu_ptr (hyperv_pcpu_output_arg); + + input_page->partition_id = partition_id; + input_page->vp_index = vp_index; + input_page->input_vtl.as_uint8 = input_vtl.as_uint8; + input_page->rsvd_z8 =0 ; + input_page->rsvd_z16 =0 ; + +while (remaining) { + rep_count =min (remaining,HV_GET_REGISTER_BATCH_SIZE ); +for (i =0 ; i < rep_count; ++i) + input_page->names[i] = registers[i].name; + + status = hv_do_rep_hypercall(HVCALL_GET_VP_REGISTERS,
rep_count,Review
Quoted 1 line
(quoted diff) +1
-0+ 0, input_page, output_page);Is there any possibility that count value is passed 0 by mistake ? In that case status will remain uninitialized.
Quoted 7 lines
Quoted 7 lines
These lines ensure
rep_countis never 0 here:while (remaining) { rep_count = min(remaining, HV_GET_REGISTER_BATCH_SIZE);Remaining can't be 0 or the loop would exit, and
HV_GET_REGISTER_BATCH_SIZEis not 0, or we would never get anyregisters.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
There is a parameter in this function "count". I was checking if there is any possibility that is passed as 0 by mistake ? this will lead to "remaining" value as 0 and loop will never execute. Which results using
"status" uninitialized later in the function.
Quoted 2 lines
Ah ok, thanks! I will change it to return immediately in case count is 0.
Or you can initialize status with appropriate error value, either way is fine. Please consider fixing the same issue in hv_call_set_vp_registers as well.
- Saurabh
Re: [PATCH v2 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
Quoted 113 lines · Saurabh Singh Sengar
Quoted 113 lines
-----Original Message-----
From: Nuno Das Neves <[email protected]>
Sent: Wednesday, August 23, 2023 1:49 AM
To: Saurabh Singh Sengar <[email protected]>; linux- [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: [email protected]; Michael Kelley (LINUX) <[email protected]>; KY Srinivasan <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; Dexuan Cui <[email protected]>; [email protected]; Tianyu Lan <[email protected]>; [email protected]; MUKESH RATHOR <[email protected]>; [email protected]; [email protected]; vkuznets <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 15/15] Drivers: hv: Add modules to expose/dev/mshvto VMMs running on Hyper-VQuoted 14 lines · Saurabh Singh Sengar
Quoted 14 lines
-----Original Message-----
From: Nuno Das Neves <[email protected]>
Sent: Saturday, August 19, 2023 12:30 AM
To: Saurabh Singh Sengar <[email protected]>; linux- [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: [email protected]; Michael Kelley (LINUX) <[email protected]>; KY Srinivasan <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; Dexuan Cui <[email protected]>; [email protected]; Tianyu Lan <[email protected]>; [email protected]; MUKESH RATHOR <[email protected]>;Quoted 64 lines
Quoted 64 lines
[email protected]; vkuznets <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 15/15] Drivers: hv: Add modules to expose/dev/mshvto VMMs running on Hyper-VQuoted 9 lines · Saurabh Singh Sengar
drivers/hv/Kconfig config HYPERV_BALLOON · line 87
Quoted 6 lines
drivers/hv/Kconfig +6
-0+ +config MSHV_VTL + tristate "Microsoft Hyper-V VTL driver" + depends on MSHV + select HYPERV_VTL_MODE + select TRANSPARENT_HUGEPAGE
TRANSPARENT_HUGEPAGEcan be avoided for now.I will remove it in the next version. Thanks.
Quoted 44 lines
Quoted 39 lines
drivers/hv/hv_call.c new file +38
-0+ +#define HV_GET_REGISTER_BATCH_SIZE \ + (HV_HYP_PAGE_SIZE / sizeof(union hv_register_value)) +#define HV_SET_REGISTER_BATCH_SIZE \ + ((HV_HYP_PAGE_SIZE - sizeof(struct hv_input_set_vp_registers)) \ + / sizeof(struct hv_register_assoc)) + +int hv_call_get_vp_registers ( +u32 vp_index, +u64 partition_id, +u16 count, +union hv_input_vtl input_vtl, +struct hv_register_assoc *registers) { +struct hv_input_get_vp_registers *input_page; +union hv_register_value *output_page; +u16 completed =0 ; +unsigned long remaining = count; +int rep_count, i; +u64 status; +unsigned long flags; + +local_irq_save (flags); + + input_page = *this_cpu_ptr (hyperv_pcpu_input_arg); + output_page = *this_cpu_ptr (hyperv_pcpu_output_arg); + + input_page->partition_id = partition_id; + input_page->vp_index = vp_index; + input_page->input_vtl.as_uint8 = input_vtl.as_uint8; + input_page->rsvd_z8 =0 ; + input_page->rsvd_z16 =0 ; + +while (remaining) { + rep_count =min (remaining,HV_GET_REGISTER_BATCH_SIZE ); +for (i =0 ; i < rep_count; ++i) + input_page->names[i] = registers[i].name; + + status = hv_do_rep_hypercall(HVCALL_GET_VP_REGISTERS,
rep_count,Review
Quoted 1 line
(quoted diff) +1
-0+ 0, input_page, output_page);Is there any possibility that count value is passed 0 by mistake ? In that case status will remain uninitialized.
Quoted 7 lines
Quoted 7 lines
These lines ensure
rep_countis never 0 here:while (remaining) { rep_count = min(remaining, HV_GET_REGISTER_BATCH_SIZE);Remaining can't be 0 or the loop would exit, and
HV_GET_REGISTER_BATCH_SIZEis not 0, or we would never get anyregisters.
Quoted 4 lines
There is a parameter in this function "count". I was checking if there is any possibility that is passed as 0 by mistake ? this will lead to "remaining" value as 0 and loop will never execute. Which results using
Quoted 9 lines
Quoted 5 lines
"status" uninitialized later in the function.
Quoted 2 lines
Ah ok, thanks! I will change it to return immediately in case count is 0.
Or you can initialize status with appropriate error value, either way is fine. Please consider fixing the same issue in
hv_call_set_vp_registersas well.
Thanks again - noted.
RE: [PATCH v2 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
In reply to Nuno Das NevesQuoted 23 lines
-----Original Message-----
From: Nuno Das Neves <[email protected]>
Sent: Friday, August 18, 2023 3:32 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]
Cc: [email protected]; Michael Kelley (LINUX) <[email protected]>; KY Srinivasan <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; Dexuan Cui <[email protected]>; [email protected]; Tianyu Lan <[email protected]>; [email protected]; MUKESH RATHOR <[email protected]>; [email protected]; [email protected]; vkuznets <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v2 15/15] Drivers: hv: Add modules to expose/dev/mshvto VMMs running on Hyper-VAdd mshv,
mshv_root, andmshv_vtlmodules:
<snip>
Quoted 23 lines
drivers/hv/mshv_root_main.c new file +22
-0+ ret =mshv_set_vp_registers (vp->index, vp->partition->id, +1 , &dispatch_suspend); +if (ret) +pr_err ("%s: failed to suspend partition %llu vp %u\n" , + __func__, vp->partition->id, vp->index); + +return ret; +} + +static int +get_vp_signaled_count (struct mshv_vp *vp,u64 *count) +{ +int ret; +struct hv_register_assoc root_signal_count = { + .name =HV_REGISTER_VP_ROOT_SIGNAL_COUNT , + }; + + ret =mshv_get_vp_registers (vp->index, vp->partition->id, +1 , &root_signal_count); + +if (ret) { + pr_err("%s: failed to get root signal count for partition %llu vp%u",
Review
Quoted 2 lines
(quoted diff) +2
-0+ __func__, vp->partition->id, vp->index); + *count = 0;
Have we missed a return here ?
Moreover, the return type of this function is never checked consider checking it or change it to void.
<snip>
Quoted 29 lines
drivers/hv/mshv_root_main.c new file +18
-0+ +/* Retrieve and stash the supported scheduler type */ +static int __init mshv_retrieve_scheduler_type (void ) +{ +struct hv_input_get_system_property *input; +struct hv_output_get_system_property *output; +unsigned long flags; +u64 status; + +local_irq_save (flags); + input = *this_cpu_ptr (hyperv_pcpu_input_arg); + output = *this_cpu_ptr (hyperv_pcpu_output_arg); + +memset (input,0 ,sizeof (*input)); +memset (output,0 ,sizeof (*output)); + input->property_id =HV_SYSTEM_PROPERTY_SCHEDULER_TYPE ; + + status = hv_do_hypercall(HVCALL_GET_SYSTEM_PROPERTY, input,output);
drivers/hv/mshv_root_main.c new file +10
-0+if (!hv_result_success (status)) { +local_irq_restore (flags); +pr_err ("%s: %s\n" , __func__,hv_status_to_string (status)); +return hv_status_to_errno (status); + } + + hv_scheduler_type = output->scheduler_type; +local_irq_restore (flags); + + pr_info("mshv: hypervisor using %s\n",
Quoted 1 line
scheduler_type_to_string(hv_scheduler_type));
Nit: In this file we are using two styles of prints, few are appended with "mshv:" and few with "__func__". It's better to have a single style for one module.
Re: [PATCH v2 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
Quoted 47 lines · Saurabh Singh Sengar
Quoted 23 lines
-----Original Message-----
From: Nuno Das Neves <[email protected]>
Sent: Friday, August 18, 2023 3:32 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]
Cc: [email protected]; Michael Kelley (LINUX) <[email protected]>; KY Srinivasan <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; Dexuan Cui <[email protected]>; [email protected]; Tianyu Lan <[email protected]>; [email protected]; MUKESH RATHOR <[email protected]>; [email protected]; [email protected]; vkuznets <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v2 15/15] Drivers: hv: Add modules to expose/dev/mshvto VMMs running on Hyper-VAdd mshv,
mshv_root, andmshv_vtlmodules:<snip>
Quoted 21 lines
drivers/hv/mshv_root_main.c new file +21
-0+ ret =mshv_set_vp_registers (vp->index, vp->partition->id, +1 , &dispatch_suspend); +if (ret) +pr_err ("%s: failed to suspend partition %llu vp %u\n" , + __func__, vp->partition->id, vp->index); + +return ret; +} + +static int +get_vp_signaled_count (struct mshv_vp *vp,u64 *count) +{ +int ret; +struct hv_register_assoc root_signal_count = { + .name =HV_REGISTER_VP_ROOT_SIGNAL_COUNT , + }; + + ret =mshv_get_vp_registers (vp->index, vp->partition->id, +1 , &root_signal_count); + +if (ret) {
Quoted 9 lines
Review
Quoted 4 lines
(quoted diff) +1
-0+ pr_err("%s: failed to get root signal count for partition %llu vp%u",
(quoted diff) +2
-0+ __func__, vp->partition->id, vp->index); + *count = 0;Have we missed a return here ?
Moreover, the return type of this function is never checked consider checking it or change it to void.
Thanks, we do need to return here.
This function is called on a cleanup path (deleting the guest VM), so if it fails something is wrong. Instead of returning void, I think we should check the return value with WARN_ON(), and abort the cleanup if it failed.
Quoted 26 lines
Quoted 26 lines
drivers/hv/mshv_root_main.c new file +18
-0+ +/* Retrieve and stash the supported scheduler type */ +static int __init mshv_retrieve_scheduler_type (void ) +{ +struct hv_input_get_system_property *input; +struct hv_output_get_system_property *output; +unsigned long flags; +u64 status; + +local_irq_save (flags); + input = *this_cpu_ptr (hyperv_pcpu_input_arg); + output = *this_cpu_ptr (hyperv_pcpu_output_arg); + +memset (input,0 ,sizeof (*input)); +memset (output,0 ,sizeof (*output)); + input->property_id =HV_SYSTEM_PROPERTY_SCHEDULER_TYPE ; + + status = hv_do_hypercall(HVCALL_GET_SYSTEM_PROPERTY, input,output);
drivers/hv/mshv_root_main.c new file +7
-0+if (!hv_result_success (status)) { +local_irq_restore (flags); +pr_err ("%s: %s\n" , __func__,hv_status_to_string (status)); +return hv_status_to_errno (status); + } + + hv_scheduler_type = output->scheduler_type;
Quoted 8 lines
Quoted 4 lines
drivers/hv/hv_call.c new file +3
-0+local_irq_restore (flags); + + pr_info("mshv: hypervisor using %s\n",
scheduler_type_to_string(hv_scheduler_type));Nit: In this file we are using two styles of prints, few are appended with "mshv:" and few with "
__func__". It's better to have a single style for one module.
Thanks, I'll switch them all to __func__
Re: [PATCH v2 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
In reply to Nuno Das NevesOn Thu, Aug 17, 2023 at 03:01:51PM -0700, Nuno Das Neves wrote:
[...]
drivers/hv/mshv_main.c line 175
Quoted 12 lines
drivers/hv/mshv_main.c new file +12
-0+static long +mshv_dev_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) +{ +switch (ioctl) { +case MSHV_CHECK_EXTENSION : +return mshv_ioctl_check_extension ((void __user *)arg); +case MSHV_CREATE_PARTITION : +return mshv.create_partition ((void __user *)arg); +case MSHV_CREATE_VTL : +return mshv.create_vtl ((void __user *)arg); + } +
Shouldn't we also have a MSHV_GET_API_VERSION ioctl similar as KVM? So that in the future when we change these ioctl interfaces or semantics, we can bump up the API version to avoid breaking userspace?
Regards,
Boqun
Re: [PATCH v2 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
Quoted 19 lines · Boqun Feng
On Thu, Aug 17, 2023 at 03:01:51PM -0700, Nuno Das Neves wrote:
[...]drivers/hv/mshv_main.c line 175
Quoted 12 lines
drivers/hv/mshv_main.c new file +12
-0+static long +mshv_dev_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) +{ +switch (ioctl) { +case MSHV_CHECK_EXTENSION : +return mshv_ioctl_check_extension ((void __user *)arg); +case MSHV_CREATE_PARTITION : +return mshv.create_partition ((void __user *)arg); +case MSHV_CREATE_VTL : +return mshv.create_vtl ((void __user *)arg); + } +Shouldn't we also have a
MSHV_GET_API_VERSIONioctl similar as KVM? So that in the future when we change these ioctl interfaces or semantics, we can bump up the API version to avoid breaking userspace?
Note that we contribute and maintain support for this driver in Cloud Hypervisor, so we control both sides of this API - if we break userspace we can fix it ourselves.
For now the MSHV_CHECK_EXTENSION ioctl is sufficient - we can pass it MSHV_CAP_CORE_API_STABLE, and it will return 0 to indicate that the API is not yet stable.
A version check may be useful in the future, but is not needed right now.
Thanks
Nuno Das Neves
Re: [PATCH v2 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
Quoted 21 lines · Nuno Das Neves
Quoted 19 lines · Boqun Feng
On Thu, Aug 17, 2023 at 03:01:51PM -0700, Nuno Das Neves wrote:
[...]drivers/hv/mshv_main.c line 175
Quoted 12 lines
drivers/hv/mshv_main.c new file +12
-0+static long +mshv_dev_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) +{ +switch (ioctl) { +case MSHV_CHECK_EXTENSION : +return mshv_ioctl_check_extension ((void __user *)arg); +case MSHV_CREATE_PARTITION : +return mshv.create_partition ((void __user *)arg); +case MSHV_CREATE_VTL : +return mshv.create_vtl ((void __user *)arg); + } +Shouldn't we also have a
MSHV_GET_API_VERSIONioctl similar as KVM? So that in the future when we change these ioctl interfaces or semantics, we can bump up the API version to avoid breaking userspace?
Quoted 4 lines
Note that we contribute and maintain support for this driver in Cloud Hypervisor, so we control both sides of this API - if we break userspace we can fix it ourselves.
This actually doesn't always work, e.g. old Clould Hypervisor + new kernel, but..
Quoted 4 lines
For now the
MSHV_CHECK_EXTENSIONioctl is sufficient - we can pass itMSHV_CAP_CORE_API_STABLE, and it will return 0 to indicate that the API is not yet stable.
.. I missed that we are using this to report API is not stable, so I agree, the API version is not needed for now.
Quoted 2 lines
A version check may be useful in the future, but is not needed right now.
Thanks for the explanation.
Regards,
Boqun
Quoted 2 lines
Thanks
Nuno Das Neves