Microsoft Hypervisor root partition ioctl interface
Subsystems (6)
v3 cover Microsoft Hypervisor root partition ioctl interface
This patch series provides a userspace interface for creating and running guest virtual machines while running on the Microsoft Hypervisor [0].
Since managing guest machines can only be done when Linux is the root partition, this series depends on Wei Liu's patch series merged in 5.12:
https://lore.kernel.org/linux-hyperv/[email protected]/
The first two patches provide some helpers for converting hypervisor status codes to linux error codes, and printing hypervisor status codes to dmesg for debugging.
Hyper-V related headers asm-generic/hyperv-tlfs.h and x86/asm/hyperv-tlfs.h are split into uapi and non-uapi. The uapi versions contain structures used in both the ioctl interface and the kernel.
The mshv API is introduced in drivers/hv/mshv_main.c. As each interface is introduced, documentation is added in Documentation/virt/mshv/api.rst. The API is file-desciptor based, like KVM. The entry point is /dev/mshv.
/dev/mshv ioctls:MSHV_CHECK_EXTENSIONMSHV_CREATE_PARTITION
Partition (vm) ioctls:MSHV_MAP_GUEST_MEMORY, MSHV_UNMAP_GUEST_MEMORY MSHV_INSTALL_INTERCEPTMSHV_ASSERT_INTERRUPT MSHV_GET_PARTITION_PROPERTY, MSHV_SET_PARTITION_PROPERTY MSHV_CREATE_VP
Vp (vcpu) ioctls:MSHV_GET_VP_REGISTERS, MSHV_SET_VP_REGISTERSMSHV_RUN_VPMSHV_GET_VP_STATE, MSHV_SET_VP_STATEMSHV_VP_TRANSLATE_GVAmmap() (register page)
[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.
Changes since v2:
1. Fix kernel test robot issues
2. Bugfix in GVA to GPA patch provided by Anatol Belski
Changes since v1:
1. Correct mshv_dev mode to octal 0600
2. Fix bug in mshv_vp_iotcl_run - correctly set suspend registers on early exit
3. Address comments from Wei Liu, Sunil Muthuswamy, and Vitaly Kuznetsov
4. Run checkpatch.pl - fix whitespace and other style issues
Changes since RFC:
1. Moved code from virt/mshv to drivers/hv
2. Split hypercall helper functions and synic code to hv_call.c and hv_synic.c
3. MSHV_REQUEST_VERSION ioctl replaced with MSHV_CHECK_EXTENSION
3. Numerous suggestions, fixes, style changes, etc from Michael Kelley, Vitaly Kuznetsov, Wei Liu, and Vineeth Pillai
4. Added patch to enable hypervisor enlightenments on partition creation
5. Added Wei Liu's patch for GVA to GPA translation
Nuno Das Neves (18):
x86/hyperv: convert hyperv statuses to linux error codes x86/hyperv: convert hyperv statuses to strings
drivers/hv: minimal mshv module (/dev/mshv/)
drivers/hv: check extension ioctl
drivers/hv: create partition ioctl
drivers/hv: create, initialize, finalize, delete partition hypercalls drivers/hv: withdraw memory hypercall
drivers/hv: map and unmap guest memory
drivers/hv: create vcpu ioctl
drivers/hv: get and set vcpu registers ioctls
drivers/hv: set up synic pages for intercept messages drivers/hv: run vp ioctl and isr
drivers/hv: install intercept ioctl
drivers/hv: assert interrupt ioctl
drivers/hv: get and set vp state ioctls
drivers/hv: mmap vp register page
drivers/hv: get and set partition property ioctls drivers/hv: Add enlightenment bits to create partition ioctl
Wei Liu (1):
drivers/hv: Translate GVA to GPA
.../userspace-api/ioctl/ioctl-number.rst | 2 + Documentation/virt/mshv/api.rst | 173 +++ arch/x86/hyperv/Makefile | 1 + arch/x86/hyperv/hv_init.c | 2 +- arch/x86/hyperv/hv_proc.c | 51 +- arch/x86/include/asm/hyperv-tlfs.h | 15 +- arch/x86/include/asm/mshyperv.h | 1 + arch/x86/include/uapi/asm/hyperv-tlfs.h | 1274 +++++++++++++++++ arch/x86/kernel/cpu/mshyperv.c | 16 + drivers/hv/Kconfig | 18 + drivers/hv/Makefile | 4 + drivers/hv/hv_call.c | 742 ++++++++++ drivers/hv/hv_synic.c | 181 +++ drivers/hv/mshv.h | 120 ++ drivers/hv/mshv_main.c | 1166 +++++++++++++++ include/asm-generic/hyperv-tlfs.h | 354 +++-- include/asm-generic/mshyperv.h | 4 + include/linux/mshv.h | 61 + include/uapi/asm-generic/hyperv-tlfs.h | 242 ++++ include/uapi/linux/mshv.h | 117 ++ 20 files changed, 4399 insertions(+), 145 deletions(-) create mode 100644 Documentation/virt/mshv/api.rst create mode 100644 arch/x86/include/uapi/asm/hyperv-tlfs.h create mode 100644 drivers/hv/hv_call.c create mode 100644 drivers/hv/hv_synic.c create mode 100644 drivers/hv/mshv.h create mode 100644 drivers/hv/mshv_main.c create mode 100644 include/linux/mshv.h create mode 100644 include/uapi/asm-generic/hyperv-tlfs.h create mode 100644 include/uapi/linux/mshv.h
Signature · 1 line
2.23.4
PATCH v3 1/19 x86/hyperv: convert hyperv statuses to linux error codes
Return linux-friendly error codes from hypercall wrapper functions. This will be needed in the mshv module.
--- arch/x86/hyperv/hv_proc.c | 30 ++++++++++++++++++++++++++--- arch/x86/include/asm/mshyperv.h | 1 + include/asm-generic/hyperv-tlfs.h | 32 +++++++++++++++++++++---------- 3 files changed, 50 insertions(+), 13 deletions(-)
arch/x86/hyperv/hv_proc.c +27 -3
@@ -14,6 +14,30 @@#include <asm/trace/hyperv.h> +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 : +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 ; +} +EXPORT_SYMBOL_GPL (hv_status_to_errno); +/* * See struct hv_deposit_memory. The first u64 is partition ID, the rest * are GPAs.
@@ -94,7 +118,7 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)local_irq_restore (flags);if (!hv_result_success (status)) {pr_err ("Failed to deposit pages: %lld\n" , status); - ret =hv_result (status); + ret =hv_status_to_errno (status); goto err_free_allocations; }
@@ -150,7 +174,7 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)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); + ret =hv_status_to_errno (status); }break ; }
@@ -200,7 +224,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)if (!hv_result_success (status)) {pr_err ("%s: vcpu %u, lp %u, %lld\n" , __func__, vp_index, flags, status); - ret =hv_result (status); + ret =hv_status_to_errno (status); }break ; }
arch/x86/include/asm/mshyperv.h +1 -0
@@ -169,6 +169,7 @@ int hyperv_flush_guest_mapping_range(u64 as,int hyperv_fill_flush_guest_mapping_list (struct hv_guest_mapping_flush_list *flush,u64 start_gfn,u64 end_gfn); +int hv_status_to_errno (u64 hv_status);extern bool hv_root_partition;
include/asm-generic/hyperv-tlfs.h +22 -10
@@ -189,16 +189,28 @@ enum HV_GENERIC_SET_FORMAT {#define HV_HYPERCALL_REP_START_MASK GENMASK_ULL(59, 48)/* hypercall status code */ -#define HV_STATUS_SUCCESS 0 -#define HV_STATUS_INVALID_HYPERCALL_CODE 2 -#define HV_STATUS_INVALID_HYPERCALL_INPUT 3 -#define HV_STATUS_INVALID_ALIGNMENT 4 -#define HV_STATUS_INVALID_PARAMETER 5 -#define HV_STATUS_OPERATION_DENIED 8 -#define HV_STATUS_INSUFFICIENT_MEMORY 11 -#define HV_STATUS_INVALID_PORT_ID 17 -#define HV_STATUS_INVALID_CONNECTION_ID 18 -#define HV_STATUS_INSUFFICIENT_BUFFERS 19 +#define HV_STATUS_SUCCESS 0x0 +#define HV_STATUS_INVALID_HYPERCALL_CODE 0x2 +#define HV_STATUS_INVALID_HYPERCALL_INPUT 0x3 +#define HV_STATUS_INVALID_ALIGNMENT 0x4 +#define HV_STATUS_INVALID_PARAMETER 0x5 +#define HV_STATUS_ACCESS_DENIED 0x6 +#define HV_STATUS_INVALID_PARTITION_STATE 0x7 +#define HV_STATUS_OPERATION_DENIED 0x8 +#define HV_STATUS_UNKNOWN_PROPERTY 0x9 +#define HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE 0xA +#define HV_STATUS_INSUFFICIENT_MEMORY 0xB +#define HV_STATUS_INVALID_PARTITION_ID 0xD +#define HV_STATUS_INVALID_VP_INDEX 0xE +#define HV_STATUS_NOT_FOUND 0x10 +#define HV_STATUS_INVALID_PORT_ID 0x11 +#define HV_STATUS_INVALID_CONNECTION_ID 0x12 +#define HV_STATUS_INSUFFICIENT_BUFFERS 0x13 +#define HV_STATUS_NOT_ACKNOWLEDGED 0x14 +#define HV_STATUS_INVALID_VP_STATE 0x15 +#define HV_STATUS_NO_RESOURCES 0x1D +#define HV_STATUS_INVALID_LP_INDEX 0x41 +#define HV_STATUS_INVALID_REGISTER_VALUE 0x50/* * The Hyper-V TimeRefCount register and the TSC
Signature · 1 line
2.23.4
PATCH v3 2/19 x86/hyperv: convert hyperv statuses to strings
In reply to Nuno Das NevesAllow hyperv hypercall failures to be debugged more easily with dmesg. This will be used in the mshv module.
--- arch/x86/hyperv/hv_init.c | 2 +- arch/x86/hyperv/hv_proc.c | 19 ++++++++--- include/asm-generic/hyperv-tlfs.h | 52 ++++++++++++++++++------------- include/asm-generic/mshyperv.h | 1 + 4 files changed, 46 insertions(+), 28 deletions(-)
arch/x86/hyperv/hv_init.c +1 -1
@@ -349,7 +349,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 +14 -5
@@ -38,6 +38,15 @@ int hv_status_to_errno(u64 hv_status) }EXPORT_SYMBOL_GPL (hv_status_to_errno); +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"; + } +} +EXPORT_SYMBOL_GPL (hv_status_to_string); +/* * See struct hv_deposit_memory. The first u64 is partition ID, the rest * are GPAs.
@@ -117,7 +126,7 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages) page_count, 0, input_page, NULL);local_irq_restore (flags);if (!hv_result_success (status)) { -pr_err ("Failed to deposit pages: %lld\n" , status); +pr_err ("Failed to deposit pages: %s\n" ,hv_status_to_string (status)); ret =hv_status_to_errno (status); goto err_free_allocations; }
@@ -172,8 +181,8 @@ 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); +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 ;
@@ -222,8 +231,8 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 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); +pr_err ("%s: vcpu %u, lp %u, %s\n" , __func__, + vp_index, flags,hv_status_to_string (status)); ret =hv_status_to_errno (status); }break ;
include/asm-generic/hyperv-tlfs.h +30 -22
58 lines not on this page · raw message
include/asm-generic/mshyperv.h +1 -0
@@ -219,6 +219,7 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset,return nr_bank; } +const char *hv_status_to_string (u64 hv_status);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.23.4
PATCH v3 3/19 drivers/hv: minimal mshv module (/dev/mshv/)
In reply to Nuno Das NevesIntroduce a barebones module file for the mshv API. Introduce CONFIG_HYPERV_VMM_API for controlling compilation of mshv.
--- arch/x86/hyperv/Makefile | 1 + drivers/hv/Kconfig | 18 ++++++++++ drivers/hv/Makefile | 3 ++ drivers/hv/mshv_main.c | 77 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 drivers/hv/mshv_main.c
arch/x86/hyperv/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_X86_64) += hv_apic.o hv_proc.o ifdef CONFIG_X86_64 obj-$(CONFIG_PARAVIRT_SPINLOCKS) += hv_spinlock.o endif +
drivers/hv/Kconfig +18 -0
@@ -27,4 +27,22 @@ config HYPERV_BALLOON help Select this option to enable Hyper-V Balloon driver. +config HYPERV_VMM_API + tristate "Microsoft Hypervisor root partition interfaces: /dev/mshv" + depends on HYPERV + help + Provides access to interfaces for managing guest virtual machines + running under the Microsoft Hypervisor. + + These interfaces will only work when Linux is running as root + partition on the Microsoft Hypervisor. + + The interfaces are provided via a device named /dev/mshv. + + To compile this as a module, choose M here. + The module is named mshv. + + If unsure, say N. + + endmenu
drivers/hv/Makefile +3 -0
@@ -2,6 +2,7 @@ obj-$(CONFIG_HYPERV) += hv_vmbus.o obj-$(CONFIG_HYPERV_UTILS) += hv_utils.o obj-$(CONFIG_HYPERV_BALLOON) += hv_balloon.o +obj-$(CONFIG_HYPERV_VMM_API) += mshv.o CFLAGS_hv_trace.o = -I$(src) CFLAGS_hv_balloon.o = -I$(src)
@@ -11,3 +12,5 @@ hv_vmbus-y := vmbus_drv.o \ channel_mgmt.o ring_buffer.o hv_trace.o hv_vmbus-$(CONFIG_HYPERV_TESTING) += hv_debugfs.o hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_fcopy.o hv_utils_transport.o + +mshv-y += mshv_main.o
drivers/hv/mshv_main.c new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
2.23.4
PATCH v3 4/19 drivers/hv: check extension ioctl
In reply to Nuno Das NevesReserve ioctl number in userpsace-api/ioctl/ioctl-number.rst Introduce MSHV_CHECK_EXTENSION ioctl.
Introduce documentation for /dev/mshv in Documentation/virt/mshv
--- .../userspace-api/ioctl/ioctl-number.rst | 2 + Documentation/virt/mshv/api.rst | 60 +++++++++++++++++++ drivers/hv/mshv_main.c | 23 +++++++ include/linux/mshv.h | 11 ++++ include/uapi/linux/mshv.h | 20 +++++++ 5 files changed, 116 insertions(+) create mode 100644 Documentation/virt/mshv/api.rst create mode 100644 include/linux/mshv.h create mode 100644 include/uapi/linux/mshv.h
Documentation/userspace-api/ioctl/ioctl-number.rst +2 -0
@@ -350,6 +350,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 root partition 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
Documentation/virt/mshv/api.rst new file +60 -0
60 lines not on this page · raw message
drivers/hv/mshv_main.c +23 -0
@@ -11,6 +11,8 @@#include <linux/module.h> #include <linux/fs.h> #include <linux/miscdevice.h> +#include <linux/slab.h> +#include <linux/mshv.h> MODULE_AUTHOR ("Microsoft" );MODULE_LICENSE ("GPL" );
@@ -34,9 +36,30 @@ static struct miscdevice mshv_dev = { .mode = 0600, }; +static long +mshv_ioctl_check_extension (void __user *user_arg) +{ +u32 arg; + +if (copy_from_user (&arg, user_arg,sizeof (arg))) +return -EFAULT ; + +switch (arg) { +case MSHV_CAP_CORE_API_STABLE : +return 0 ; + } + +return -EOPNOTSUPP ; +} +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); + } +return -ENOTTY ; }
include/linux/mshv.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _LINUX_MSHV_H +#define _LINUX_MSHV_H + +/* +* Microsoft Hypervisor root partition driver for /dev/mshv +*/ + +#include <uapi/linux/mshv.h> + +#endif
include/uapi/linux/mshv.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_MSHV_H +#define _UAPI_LINUX_MSHV_H + +/* +* Userspace interface for /dev/mshv +* Microsoft Hypervisor root partition APIs +* NOTE: This API is not yet stable! +*/ + +#include <linux/types.h> + +#define MSHV_CAP_CORE_API_STABLE 0x0 + +#define MSHV_IOCTL 0xB8 + +/* mshv device */ +#define MSHV_CHECK_EXTENSION _IOW(MSHV_IOCTL, 0x00, __u32) + +#endif
Signature · 1 line
2.23.4
PATCH v3 5/19 drivers/hv: create partition ioctl
In reply to Nuno Das NevesAdd MSHV_CREATE_PARTITION, which creates an fd to track a new partition. Partition is not yet created in the hypervisor itself. Introduce header files for userspace-facing hyperv structures.
--- Documentation/virt/mshv/api.rst | 12 ++ arch/x86/include/asm/hyperv-tlfs.h | 1 + arch/x86/include/uapi/asm/hyperv-tlfs.h | 124 +++++++++++++++++++++ drivers/hv/mshv_main.c | 141 ++++++++++++++++++++++++ include/asm-generic/hyperv-tlfs.h | 1 + include/linux/mshv.h | 16 +++ include/uapi/asm-generic/hyperv-tlfs.h | 15 +++ include/uapi/linux/mshv.h | 8 ++ 8 files changed, 318 insertions(+) create mode 100644 arch/x86/include/uapi/asm/hyperv-tlfs.h create mode 100644 include/uapi/asm-generic/hyperv-tlfs.h
Documentation/virt/mshv/api.rst +12 -0
@@ -39,6 +39,9 @@ root partition can use mshv APIs to create guest partitions. The module is named mshv and can be configured with CONFIG_HYPERV_ROOT_API. +The uapi header files you need are linux/mshv.h, asm/hyperv-tlfs.h, and +asm-generic/hyperv-tlfs.h. + Mshv is file descriptor-based, following a similar pattern to KVM. To get a handle to the mshv driver, use open("/dev/mshv").
@@ -58,3 +61,12 @@ number. If not, it will return 0. The first extension that can be checked is MSHV_CAP_CORE_API_STABLE. This will be supported when the core API is stable. +3.2 MSHV_CREATE_PARTITION +------------------------- +:Type: /dev/mshv ioctl +:Parameters: struct mshv_create_partition +:Returns: partition file descriptor, or -1 on failure + +This ioctl creates a guest partition, returning a file descriptor to use as a +handle for partition ioctls. +
arch/x86/include/asm/hyperv-tlfs.h +1 -0
@@ -11,6 +11,7 @@#include <linux/types.h> #include <asm/page.h> +#include <uapi/asm/hyperv-tlfs.h> /* * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent * is set by CPUID(HvCpuIdFunctionVersionAndFeatures).
arch/x86/include/uapi/asm/hyperv-tlfs.h new file +124 -0
124 lines not on this page · raw message
drivers/hv/mshv_main.c +141 -0
174 lines not on this page · raw message
include/asm-generic/hyperv-tlfs.h +1 -0
@@ -12,6 +12,7 @@#include <linux/types.h> #include <linux/bits.h> #include <linux/time64.h> +#include <uapi/asm-generic/hyperv-tlfs.h> /* * While not explicitly listed in the TLFS, Hyper-V always runs with a page size
include/linux/mshv.h +16 -0
@@ -6,6 +6,22 @@* Microsoft Hypervisor root partition driver for /dev/mshv */ +#include <linux/spinlock.h> #include <uapi/linux/mshv.h> +#define MSHV_MAX_PARTITIONS 128 + +struct mshv_partition { +u64 id; +refcount_t ref_count; +}; + +struct mshv { +struct { +spinlock_t lock; +u64 count; +struct mshv_partition *array[MSHV_MAX_PARTITIONS ]; + } partitions; +}; +#endif
include/uapi/asm-generic/hyperv-tlfs.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_ASM_GENERIC_HYPERV_TLFS_USER_H +#define _UAPI_ASM_GENERIC_HYPERV_TLFS_USER_H + +#ifndef BIT +#define BIT (X ) (1ULL << (X)) +#endif + +/* Userspace-visible partition creation flags */ +#define HV_PARTITION_CREATION_FLAG_SMT_ENABLED_GUEST BIT(0) +#define HV_PARTITION_CREATION_FLAG_GPA_LARGE_PAGES_DISABLED BIT(3) +#define HV_PARTITION_CREATION_FLAG_GPA_SUPER_PAGES_ENABLED BIT(4) +#define HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED BIT(13) + +#endif
include/uapi/linux/mshv.h +8 -0
@@ -9,12 +9,20 @@*/ #include <linux/types.h> +#include <asm/hyperv-tlfs.h> +#include <asm-generic/hyperv-tlfs.h> #define MSHV_CAP_CORE_API_STABLE 0x0 +struct mshv_create_partition { +__u64 flags; +struct hv_partition_creation_properties partition_creation_properties; +}; +#define MSHV_IOCTL 0xB8/* mshv device */ #define MSHV_CHECK_EXTENSION _IOW(MSHV_IOCTL, 0x00, __u32) +#define MSHV_CREATE_PARTITION _IOW(MSHV_IOCTL, 0x01, struct mshv_create_partition)#endif
Signature · 1 line
2.23.4
PATCH v3 6/19 drivers/hv: create, initialize, finalize, delete partition hypercalls
In reply to Nuno Das NevesAdd hypercalls for fully setting up and mostly tearing down a guest partition.
Export hv_call_deposit_memory and hv_call_create_vp.
The teardown operation will generate an error as the deposited memory has not been withdrawn.
This is fixed in the next patch.
--- arch/x86/hyperv/hv_proc.c | 2 + drivers/hv/Makefile | 3 +- drivers/hv/hv_call.c | 129 ++++++++++++++++++++++++++++++ drivers/hv/mshv.h | 28 +++++++ drivers/hv/mshv_main.c | 34 +++++++- include/asm-generic/hyperv-tlfs.h | 49 ++++++++++++ 6 files changed, 243 insertions(+), 2 deletions(-) create mode 100644 drivers/hv/hv_call.c create mode 100644 drivers/hv/mshv.h
arch/x86/hyperv/hv_proc.c +2 -0
@@ -146,6 +146,7 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)kfree (counts);return ret; } +EXPORT_SYMBOL_GPL (hv_call_deposit_pages);int hv_call_add_logical_proc (int node,u32 lp_index,u32 apic_id) {
@@ -243,4 +244,5 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)return ret; } +EXPORT_SYMBOL_GPL (hv_call_create_vp);
drivers/hv/Makefile +2 -1
@@ -13,4 +13,5 @@ hv_vmbus-y := vmbus_drv.o \ hv_vmbus-$(CONFIG_HYPERV_TESTING) += hv_debugfs.o hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_fcopy.o hv_utils_transport.o -mshv-y += mshv_main.o +mshv-y += mshv_main.o hv_call.o +
drivers/hv/hv_call.c new file +129 -0
129 lines not on this page · raw message
drivers/hv/mshv.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2021, Microsoft Corporation. +* +* Authors: +* Nuno Das Neves <[email protected]> +* Lillian Grassin-Drake <[email protected]> +* Vineeth Pillai <[email protected]> +*/ + +#ifndef _MSHV_H_ +#define _MSHV_H_ + +/* Determined empirically */ +#define HV_INIT_PARTITION_DEPOSIT_PAGES 208 + +/* +* Hyper-V hypercalls +*/ +int hv_call_create_partition ( +u64 flags, +struct hv_partition_creation_properties creation_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); + +#endif /* _MSHV_H */
drivers/hv/mshv_main.c +33 -1
@@ -15,6 +15,9 @@#include <linux/file.h> #include <linux/anon_inodes.h> #include <linux/mshv.h> +#include <asm/mshyperv.h> + +#include "mshv.h" MODULE_AUTHOR ("Microsoft" );MODULE_LICENSE ("GPL" );
@@ -49,6 +52,7 @@ static struct miscdevice mshv_dev = { .mode = 0600, }; +static long mshv_partition_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) {
@@ -78,6 +82,17 @@ destroy_partition(struct mshv_partition *partition)spin_unlock_irqrestore (&mshv.partitions.lock, flags); +/* +* There are no remaining references to the partition, +* so the remaining cleanup can be lockless +*/ + +/* Deallocates and unmaps everything including vcpus, GPA mappings etc */ +hv_call_finalize_partition (partition->id); +/* TODO: Withdraw and free all pages we deposited */ + +hv_call_delete_partition (partition->id); +kfree (partition); }
@@ -138,6 +153,9 @@ mshv_ioctl_create_partition(void __user *user_arg)if (copy_from_user (&args, user_arg,sizeof (args)))return -EFAULT ; +/* Only support EXO partitions */ + args.flags |=HV_PARTITION_CREATION_FLAG_EXO_PARTITION ; + partition =kzalloc (sizeof (*partition),GFP_KERNEL );if (!partition)return -ENOMEM ;
@@ -148,11 +166,21 @@ mshv_ioctl_create_partition(void __user *user_arg) goto free_partition; } + ret =hv_call_create_partition (args.flags, + args.partition_creation_properties, + &partition->id); +if (ret) + goto put_fd; + + ret =hv_call_initialize_partition (partition->id); +if (ret) + goto delete_partition; + file =anon_inode_getfile ("mshv_partition" , &mshv_partition_fops, partition,O_RDWR );if (IS_ERR (file)) { ret =PTR_ERR (file); - goto put_fd; + goto finalize_partition; }refcount_set (&partition->ref_count,1 );
@@ -166,6 +194,10 @@ mshv_ioctl_create_partition(void __user *user_arg) release_file: file->f_op->release (file->f_inode, file); +finalize_partition: +hv_call_finalize_partition (partition->id); +delete_partition: +hv_call_delete_partition (partition->id); put_fd:put_unused_fd (fd); free_partition:
include/asm-generic/hyperv-tlfs.h +49 -0
59 lines not on this page · raw message
Signature · 1 line
2.23.4
PATCH v3 7/19 drivers/hv: withdraw memory hypercall
In reply to Nuno Das NevesWithdraw the memory from a finalized partition and free the pages. The partition is now cleaned up correctly when the fd is released.
--- drivers/hv/hv_call.c | 53 +++++++++++++++++++++++++++++++ drivers/hv/mshv.h | 6 ++++ drivers/hv/mshv_main.c | 5 +-- include/asm-generic/hyperv-tlfs.h | 11 +++++++ 4 files changed, 73 insertions(+), 2 deletions(-)
drivers/hv/hv_call.c +53 -0
@@ -14,6 +14,59 @@#include "mshv.h" +int hv_call_withdraw_memory (u64 count,int node,u64 partition_id) +{ +struct hv_withdraw_memory_in *input_page; +struct hv_withdraw_memory_out *output_page; +struct page *page; +u16 completed; +unsigned long remaining = count; +u64 status; +int i; +unsigned long flags; + + page =alloc_page (GFP_KERNEL ); +if (!page) +return -ENOMEM ; + output_page =page_address (page); + +while (remaining) { +local_irq_save (flags); + + input_page = (struct hv_withdraw_memory_in *)(*this_cpu_ptr ( + hyperv_pcpu_input_arg)); + + input_page->partition_id = partition_id; + input_page->proximity_domain_info.as_uint64 =0 ; + status =hv_do_rep_hypercall ( +HVCALL_WITHDRAW_MEMORY , +min (remaining,HV_WITHDRAW_BATCH_SIZE ),0 , input_page, + output_page); + +local_irq_restore (flags); + + completed =hv_repcomp (status); + +for (i =0 ; i < completed; i++) +__free_page (pfn_to_page (output_page->gpa_page_list[i])); + +if (!hv_result_success (status)) { +if (hv_result (status) ==HV_STATUS_NO_RESOURCES ) + status =HV_STATUS_SUCCESS ; +else +pr_err ("%s: %s\n" , __func__, +hv_status_to_string (status)); +break ; + } + + remaining -= completed; + } +free_page ((unsigned long )output_page); + +return hv_status_to_errno (status); +} + + int hv_call_create_partition( u64 flags, struct hv_partition_creation_properties creation_properties,
drivers/hv/mshv.h +6 -0
@@ -11,12 +11,18 @@#ifndef _MSHV_H_#define _MSHV_H_ +#include <asm/hyperv-tlfs.h> +/* Determined empirically */ #define HV_INIT_PARTITION_DEPOSIT_PAGES 208 +#define HV_WITHDRAW_BATCH_SIZE (HV_HYP_PAGE_SIZE / sizeof(u64)) +/* * 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,
drivers/hv/mshv_main.c +3 -2
@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/file.h> #include <linux/anon_inodes.h> +#include <linux/mm.h> #include <linux/mshv.h> #include <asm/mshyperv.h>
@@ -52,7 +53,6 @@ static struct miscdevice mshv_dev = { .mode = 0600, }; -static long mshv_partition_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) {
@@ -89,7 +89,8 @@ destroy_partition(struct mshv_partition *partition)/* Deallocates and unmaps everything including vcpus, GPA mappings etc */ hv_call_finalize_partition (partition->id); -/* TODO: Withdraw and free all pages we deposited */ +/* Withdraw and free all pages we deposited */ +hv_call_withdraw_memory (U64_MAX ,NUMA_NO_NODE , partition->id);hv_call_delete_partition (partition->id);
include/asm-generic/hyperv-tlfs.h +11 -0
@@ -149,6 +149,7 @@ struct ms_hyperv_tsc_page {#define HVCALL_DELETE_PARTITION 0x0043#define HVCALL_GET_PARTITION_ID 0x0046#define HVCALL_DEPOSIT_MEMORY 0x0048 +#define HVCALL_WITHDRAW_MEMORY 0x0049#define HVCALL_CREATE_VP 0x004e#define HVCALL_GET_VP_REGISTERS 0x0050#define HVCALL_SET_VP_REGISTERS 0x0051
@@ -515,6 +516,16 @@ union hv_proximity_domain_info {u64 as_uint64; } __packed; +struct hv_withdraw_memory_in { +u64 partition_id; +union hv_proximity_domain_info proximity_domain_info; +} __packed; + +struct hv_withdraw_memory_out { +/* Hack - compiler doesn't like empty array size in struct with no other members */ +u64 gpa_page_list[0 ]; +} __packed; +struct hv_lp_startup_status {u64 hv_status;u64 substatus1;
Signature · 1 line
2.23.4
PATCH v3 8/19 drivers/hv: map and unmap guest memory
In reply to Nuno Das NevesIntroduce ioctls for mapping and unmapping regions of guest memory.
Uses a table of memory 'slots' similar to KVM, but the slot number is not visible to userspace.
For now, this simple implementation requires each new mapping to be disjoint - the underlying hypercalls have no such restriction, and implicitly overwrite any mappings on the pages in the specified regions.
--- Documentation/virt/mshv/api.rst | 17 +++ drivers/hv/hv_call.c | 114 +++++++++++++++ drivers/hv/mshv.h | 13 ++ drivers/hv/mshv_main.c | 194 ++++++++++++++++++++++++- include/asm-generic/hyperv-tlfs.h | 23 ++- include/linux/mshv.h | 14 ++ include/uapi/asm-generic/hyperv-tlfs.h | 9 ++ include/uapi/linux/mshv.h | 15 ++ 8 files changed, 394 insertions(+), 5 deletions(-)
Documentation/virt/mshv/api.rst +17 -0
@@ -70,3 +70,20 @@ will be supported when the core API is stable. This ioctl creates a guest partition, returning a file descriptor to use as a handle for partition ioctls. +3.3 MSHV_MAP_GUEST_MEMORY and MSHV_UNMAP_GUEST_MEMORY +----------------------------------------------------- +:Type: partition ioctl +:Parameters: struct mshv_user_mem_region +:Returns: 0 on success + +Create a mapping from memory in the user space of the calling process (running +in the root partition) to a region of guest physical memory in a guest partition. + +Mappings must be disjoint from each other in both userspace and guest physical +address space. + +Note: In the current implementation, this memory is pinned to real physical +memory to stop the pages being moved by Linux in the root partition, +and subsequently being clobbered by the hypervisor. So the region is backed +by real physical memory. +
drivers/hv/hv_call.c +114 -0
117 lines not on this page · raw message
drivers/hv/mshv.h +13 -0
@@ -15,8 +15,12 @@/* Determined empirically */ #define HV_INIT_PARTITION_DEPOSIT_PAGES 208 +#define HV_MAP_GPA_DEPOSIT_PAGES 256#define HV_WITHDRAW_BATCH_SIZE (HV_HYP_PAGE_SIZE / sizeof(u64)) +#define HV_MAP_GPA_BATCH_SIZE \ + ((HV_HYP_PAGE_SIZE - sizeof(struct hv_map_gpa_pages)) / sizeof(u64)) +#define PIN_PAGES_BATCH_SIZE (0x10000000 / HV_HYP_PAGE_SIZE)/* * Hyper-V hypercalls
@@ -30,5 +34,14 @@ int hv_call_create_partition(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);#endif /* _MSHV_H */
drivers/hv/mshv_main.c +192 -2
220 lines not on this page · raw message
include/asm-generic/hyperv-tlfs.h +20 -3
@@ -20,9 +20,9 @@* guest physical pages and guest physical page addresses, since the guest page * size may not be 4096 on all architectures. */ -#define HV_HYP_PAGE_SHIFT 12 -#define HV_HYP_PAGE_SIZE BIT(HV_HYP_PAGE_SHIFT) -#define HV_HYP_PAGE_MASK (~(HV_HYP_PAGE_SIZE - 1)) +#define HV_HYP_PAGE_SHIFT 12 +#define HV_HYP_PAGE_SIZE BIT(HV_HYP_PAGE_SHIFT) +#define HV_HYP_PAGE_MASK (~(HV_HYP_PAGE_SIZE - 1))/* * Hyper-V provides two categories of flags relevant to guest VMs. The
@@ -150,6 +150,8 @@ struct ms_hyperv_tsc_page {#define HVCALL_GET_PARTITION_ID 0x0046#define HVCALL_DEPOSIT_MEMORY 0x0048#define HVCALL_WITHDRAW_MEMORY 0x0049 +#define HVCALL_MAP_GPA_PAGES 0x004b +#define HVCALL_UNMAP_GPA_PAGES 0x004c#define HVCALL_CREATE_VP 0x004e#define HVCALL_GET_VP_REGISTERS 0x0050#define HVCALL_SET_VP_REGISTERS 0x0051
@@ -886,4 +888,19 @@ struct hv_delete_partition { u64 partition_id; } __packed; +struct hv_map_gpa_pages { +u64 target_partition_id; +u64 target_gpa_base; +u32 map_flags; +u32 padding; +u64 source_gpa_page_list[]; +} __packed; + +struct hv_unmap_gpa_pages { +u64 target_partition_id; +u64 target_gpa_base; +u32 unmap_flags; +u32 padding; +} __packed; +#endif
include/linux/mshv.h +14 -0
@@ -7,13 +7,27 @@*/ #include <linux/spinlock.h> +#include <linux/mutex.h> #include <uapi/linux/mshv.h> #define MSHV_MAX_PARTITIONS 128 +#define MSHV_MAX_MEM_REGIONS 64 + +struct mshv_mem_region { +u64 size;/* bytes */ +u64 guest_pfn; +u64 userspace_addr;/* start of the userspace allocated memory */ +struct page **pages; +};struct mshv_partition {u64 id;refcount_t ref_count; +struct mutex mutex; +struct { +u32 count; +struct mshv_mem_region slots[MSHV_MAX_MEM_REGIONS ]; + } regions; };struct mshv {
include/uapi/asm-generic/hyperv-tlfs.h +9 -0
@@ -12,4 +12,13 @@#define HV_PARTITION_CREATION_FLAG_GPA_SUPER_PAGES_ENABLED BIT(4)#define HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED BIT(13) +/* HV Map GPA (Guest Physical Address) Flags */ +#define HV_MAP_GPA_PERMISSIONS_NONE 0x0 +#define HV_MAP_GPA_READABLE 0x1 +#define HV_MAP_GPA_WRITABLE 0x2 +#define HV_MAP_GPA_KERNEL_EXECUTABLE 0x4 +#define HV_MAP_GPA_USER_EXECUTABLE 0x8 +#define HV_MAP_GPA_EXECUTABLE 0xC +#define HV_MAP_GPA_PERMISSIONS_MASK 0xF +#endif
include/uapi/linux/mshv.h +15 -0
@@ -19,10 +19,25 @@ struct mshv_create_partition { struct hv_partition_creation_properties partition_creation_properties; }; +/* +* Mappings can't overlap in GPA space or userspace +* To unmap, these fields must match an existing mapping +*/ +struct mshv_user_mem_region { +__u64 size;/* bytes */ +__u64 guest_pfn; +__u64 userspace_addr;/* start of the userspace allocated memory */ +__u32 flags;/* ignored on unmap */ +}; +#define MSHV_IOCTL 0xB8/* mshv device */ #define MSHV_CHECK_EXTENSION _IOW(MSHV_IOCTL, 0x00, __u32)#define MSHV_CREATE_PARTITION _IOW(MSHV_IOCTL, 0x01, struct mshv_create_partition) +/* partition device */ +#define MSHV_MAP_GUEST_MEMORY _IOW(MSHV_IOCTL, 0x02, struct mshv_user_mem_region) +#define MSHV_UNMAP_GUEST_MEMORY _IOW(MSHV_IOCTL, 0x03, struct mshv_user_mem_region) +#endif
Signature · 1 line
2.23.4
Re: [PATCH v3 08/19] drivers/hv: map and unmap guest memory
Am Tue, 28 Sep 2021 11:31:04 -0700
schrieb Nuno Das Neves <[email protected]>:
include/asm-generic/hyperv-tlfs.h line 23
Quoted 3 lines
+++
b/include/asm-generic/hyperv-tlfs.hinclude/asm-generic/hyperv-tlfs.h +1
-1-#define HV_HYP_PAGE_SHIFT 12 +#define HV_HYP_PAGE_SHIFT 12
I think in case this change is really required, it should be in a separate patch.
Olaf
Wei Liu
maintainerRe: [PATCH v3 08/19] drivers/hv: map and unmap guest memory
Quoted 8 lines · Olaf Hering
Am Tue, 28 Sep 2021 11:31:04 -0700
schrieb Nuno Das Neves <[email protected]>:include/asm-generic/hyperv-tlfs.h line 23
Quoted 3 lines
+++
b/include/asm-generic/hyperv-tlfs.hinclude/asm-generic/hyperv-tlfs.h +1
-1-#define HV_HYP_PAGE_SHIFT 12 +#define HV_HYP_PAGE_SHIFT 12I think in case this change is really required, it should be in a separate patch.
I don't think this hunk should be in this patch. It is just changing whitespaces.
Wei.
Quoted 3 lines
Olaf
Re: [PATCH v3 08/19] drivers/hv: map and unmap guest memory
Quoted 4 lines · Wei Liu
Quoted 3 lines · Olaf Hering
Am Tue, 28 Sep 2021 11:31:04 -0700
schrieb Nuno Das Neves <[email protected]>:
Quoted 9 lines
Quoted 5 lines
include/asm-generic/hyperv-tlfs.h line 23
Quoted 3 lines
+++
b/include/asm-generic/hyperv-tlfs.hinclude/asm-generic/hyperv-tlfs.h +1
-1-#define HV_HYP_PAGE_SHIFT 12 +#define HV_HYP_PAGE_SHIFT 12I think in case this change is really required, it should be in a separate patch.
I don't think this hunk should be in this patch. It is just changing whitespaces.
Thanks, good point. I think I'll remove this hunk from the series altogether.
Quoted 6 lines
Wei.
Quoted 3 lines
Olaf
PATCH v3 9/19 drivers/hv: create vcpu ioctl
In reply to Nuno Das NevesIntroduce ioctl for creating a virtual processor in a partition.
--- Documentation/virt/mshv/api.rst | 9 +++ drivers/hv/mshv_main.c | 119 +++++++++++++++++++++++++++++++- include/linux/mshv.h | 10 +++ include/uapi/linux/mshv.h | 5 ++ 4 files changed, 142 insertions(+), 1 deletion(-)
Documentation/virt/mshv/api.rst +9 -0
@@ -87,3 +87,12 @@ memory to stop the pages being moved by Linux in the root partition, and subsequently being clobbered by the hypervisor. So the region is backed by real physical memory. +3.4 MSHV_CREATE_VP +------------------ +:Type: partition ioctl +:Parameters: struct mshv_create_vp +:Returns: vp file descriptor, or -1 on failure + +Create a virtual processor in a guest partition, returning a file descriptor to +represent the vp and perform ioctls on. +
drivers/hv/mshv_main.c +118 -1
163 lines not on this page · raw message
include/linux/mshv.h +10 -0
@@ -12,6 +12,12 @@#define MSHV_MAX_PARTITIONS 128#define MSHV_MAX_MEM_REGIONS 64 +#define MSHV_MAX_VPS 256 + +struct mshv_vp { +u32 index; +struct mshv_partition *partition; +};struct mshv_mem_region {u64 size;/* bytes */
@@ -28,6 +34,10 @@ struct mshv_partition {u32 count;struct mshv_mem_region slots[MSHV_MAX_MEM_REGIONS ]; } regions; +struct { +u32 count; +struct mshv_vp *array[MSHV_MAX_VPS ]; + } vps; };struct mshv {
include/uapi/linux/mshv.h +5 -0
@@ -30,6 +30,10 @@ struct mshv_user_mem_region {__u32 flags;/* ignored on unmap */ }; +struct mshv_create_vp { +__u32 vp_index; +}; +#define MSHV_IOCTL 0xB8/* mshv device */
@@ -39,5 +43,6 @@ struct mshv_user_mem_region {/* partition device */ #define MSHV_MAP_GUEST_MEMORY _IOW(MSHV_IOCTL, 0x02, struct mshv_user_mem_region)#define MSHV_UNMAP_GUEST_MEMORY _IOW(MSHV_IOCTL, 0x03, struct mshv_user_mem_region) +#define MSHV_CREATE_VP _IOW(MSHV_IOCTL, 0x04, struct mshv_create_vp)#endif
Signature · 1 line
2.23.4
PATCH v3 10/19 drivers/hv: get and set vcpu registers ioctls
In reply to Nuno Das NevesAdd ioctls for getting and setting virtual processor registers.
--- Documentation/virt/mshv/api.rst | 11 + arch/x86/include/uapi/asm/hyperv-tlfs.h | 602 ++++++++++++++++++++++++ drivers/hv/hv_call.c | 100 ++++ drivers/hv/mshv.h | 15 + drivers/hv/mshv_main.c | 96 +++- include/asm-generic/hyperv-tlfs.h | 47 +- include/linux/mshv.h | 1 + include/uapi/asm-generic/hyperv-tlfs.h | 7 + include/uapi/linux/mshv.h | 11 + 9 files changed, 859 insertions(+), 31 deletions(-)
Documentation/virt/mshv/api.rst +11 -0
@@ -96,3 +96,14 @@ by real physical memory. Create a virtual processor in a guest partition, returning a file descriptor to represent the vp and perform ioctls on. +3.5 MSHV_GET_VP_REGISTERS and MSHV_SET_VP_REGISTERS +--------------------------------------------------- +:Type: vp ioctl +:Parameters: struct mshv_vp_registers +:Returns: 0 on success + +Get/set vp registers. See asm/hyperv-tlfs.h for the complete set of registers. +Includes general purpose platform registers, MSRs, and virtual registers that +are part of Microsoft Hypervisor platform and not directly exposed to the guest. + +
arch/x86/include/uapi/asm/hyperv-tlfs.h +602 -0
606 lines not on this page · raw message
drivers/hv/hv_call.c +100 -0
103 lines not on this page · raw message
drivers/hv/mshv.h +15 -0
@@ -21,6 +21,11 @@#define HV_MAP_GPA_BATCH_SIZE \ ((HV_HYP_PAGE_SIZE - sizeof(struct hv_map_gpa_pages)) / sizeof(u64))#define PIN_PAGES_BATCH_SIZE (0x10000000 / HV_HYP_PAGE_SIZE) +#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_set_vp_registers)) \ + / sizeof(struct hv_register_assoc))/* * Hyper-V hypercalls
@@ -43,5 +48,15 @@ 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, +struct hv_register_assoc *registers); +int hv_call_set_vp_registers ( +u32 vp_index, +u64 partition_id, +u16 count, +struct hv_register_assoc *registers);#endif /* _MSHV_H */
drivers/hv/mshv_main.c +95 -1
111 lines not on this page · raw message
include/asm-generic/hyperv-tlfs.h +17 -30
63 lines not on this page · raw message
include/linux/mshv.h +1 -0
@@ -17,6 +17,7 @@struct mshv_vp {u32 index;struct mshv_partition *partition; +struct mutex mutex; };struct mshv_mem_region {
include/uapi/asm-generic/hyperv-tlfs.h +7 -0
@@ -21,4 +21,11 @@#define HV_MAP_GPA_EXECUTABLE 0xC#define HV_MAP_GPA_PERMISSIONS_MASK 0xF +struct hv_register_assoc { +__u32 name;/* enum hv_register_name */ +__u32 reserved1; +__u64 reserved2; +union hv_register_value value; +} __packed; +#endif
include/uapi/linux/mshv.h +11 -0
@@ -34,6 +34,13 @@ struct mshv_create_vp {__u32 vp_index; }; +#define MSHV_VP_MAX_REGISTERS 128 + +struct mshv_vp_registers { +int count;/* at most MSHV_VP_MAX_REGISTERS */ +struct hv_register_assoc *regs; +}; +#define MSHV_IOCTL 0xB8/* mshv device */
@@ -45,4 +52,8 @@ struct mshv_create_vp {#define MSHV_UNMAP_GUEST_MEMORY _IOW(MSHV_IOCTL, 0x03, struct mshv_user_mem_region)#define MSHV_CREATE_VP _IOW(MSHV_IOCTL, 0x04, struct mshv_create_vp) +/* vp device */ +#define MSHV_GET_VP_REGISTERS _IOWR(MSHV_IOCTL, 0x05, struct mshv_vp_registers) +#define MSHV_SET_VP_REGISTERS _IOW(MSHV_IOCTL, 0x06, struct mshv_vp_registers) +#endif
Signature · 1 line
2.23.4
PATCH v3 11/19 drivers/hv: set up synic pages for intercept messages
In reply to Nuno Das NevesSame idea as synic setup in drivers/hv/hv.c:hv_synic_enable_regs() and hv_synic_disable_regs().
Setting up synic registers in both vmbus driver and mshv would clobber them, but the vmbus driver will not run in the root partition, so this is safe.
Move struct hv_message and related definitions to uapi.
--- arch/x86/include/uapi/asm/hyperv-tlfs.h | 225 ++++++++++++++++++++++++ drivers/hv/Makefile | 2 +- drivers/hv/hv_synic.c | 85 +++++++++ drivers/hv/mshv.h | 5 + drivers/hv/mshv_main.c | 30 +++- include/asm-generic/hyperv-tlfs.h | 81 +-------- include/linux/mshv.h | 1 + include/uapi/asm-generic/hyperv-tlfs.h | 75 ++++++++ 8 files changed, 422 insertions(+), 82 deletions(-) create mode 100644 drivers/hv/hv_synic.c
arch/x86/include/uapi/asm/hyperv-tlfs.h +225 -0
@@ -723,4 +723,229 @@ union hv_register_value { pending_virtualization_fault_event; }; +union hv_x64_vp_execution_state { +__u16 as_uint16; +struct { +__u16 cpl:2 ; +__u16 cr0_pe:1 ; +__u16 cr0_am:1 ; +__u16 efer_lma:1 ; +__u16 debug_active:1 ; +__u16 interruption_pending:1 ; +__u16 vtl:4 ; +__u16 enclave_mode:1 ; +__u16 interrupt_shadow:1 ; +__u16 virtualization_fault_active:1 ; +__u16 reserved:2 ; + } __packed; +}; + +/* Values for intercept_access_type field */ +#define HV_INTERCEPT_ACCESS_READ 0 +#define HV_INTERCEPT_ACCESS_WRITE 1 +#define HV_INTERCEPT_ACCESS_EXECUTE 2 + +struct hv_x64_intercept_message_header { +__u32 vp_index; +__u8 instruction_length:4 ; +__u8 cr8:4 ;// only set for exo partitions +__u8 intercept_access_type; +union hv_x64_vp_execution_state execution_state; +struct hv_x64_segment_register cs_segment; +__u64 rip; +__u64 rflags; +} __packed; + +#define HV_HYPERCALL_INTERCEPT_MAX_XMM_REGISTERS 6 + +struct hv_x64_hypercall_intercept_message { +struct hv_x64_intercept_message_header header; +__u64 rax; +__u64 rbx; +__u64 rcx; +__u64 rdx; +__u64 r8; +__u64 rsi; +__u64 rdi; +struct hv_u128 xmmregisters[HV_HYPERCALL_INTERCEPT_MAX_XMM_REGISTERS ]; +struct { +__u32 isolated:1 ; +__u32 reserved:31 ; + } __packed; +} __packed; + +union hv_x64_register_access_info { +union hv_register_value source_value; +__u32 destination_register; +__u64 source_address; +__u64 destination_address; +}; + +struct hv_x64_register_intercept_message { +struct hv_x64_intercept_message_header header; +struct { +__u8 is_memory_op:1 ; +__u8 reserved:7 ; + } __packed; +__u8 reserved8; +__u16 reserved16; +__u32 register_name; +union hv_x64_register_access_info access_info; +} __packed; + +union hv_x64_memory_access_info { +__u8 as_uint8; +struct { +__u8 gva_valid:1 ; +__u8 gva_gpa_valid:1 ; +__u8 hypercall_output_pending:1 ; +__u8 tlb_locked_no_overlay:1 ; +__u8 reserved:4 ; + } __packed; +}; + +union hv_x64_io_port_access_info { +__u8 as_uint8; +struct { +__u8 access_size:3 ; +__u8 string_op:1 ; +__u8 rep_prefix:1 ; +__u8 reserved:3 ; + } __packed; +}; + +union hv_x64_exception_info { +__u8 as_uint8; +struct { +__u8 error_code_valid:1 ; +__u8 software_exception:1 ; +__u8 reserved:6 ; + } __packed; +}; + +#define HV_CACHE_TYPE_UNCACHED 0 +#define HV_CACHE_TYPE_WRITE_COMBINING 1 +#define HV_CACHE_TYPE_WRITE_THROUGH 4 +#define HV_CACHE_TYPE_WRITE_PROTECTED 5 +#define HV_CACHE_TYPE_WRITE_BACK 6 + +struct hv_x64_memory_intercept_message { +struct hv_x64_intercept_message_header header; +__u32 cache_type; +__u8 instruction_byte_count; +union hv_x64_memory_access_info memory_access_info; +__u8 tpr_priority; +__u8 reserved1; +__u64 guest_virtual_address; +__u64 guest_physical_address; +__u8 instruction_bytes[16 ]; +} __packed; + +struct hv_x64_cpuid_intercept_message { +struct hv_x64_intercept_message_header header; +__u64 rax; +__u64 rcx; +__u64 rdx; +__u64 rbx; +__u64 default_result_rax; +__u64 default_result_rcx; +__u64 default_result_rdx; +__u64 default_result_rbx; +} __packed; + +struct hv_x64_msr_intercept_message { +struct hv_x64_intercept_message_header header; +__u32 msr_number; +__u32 reserved; +__u64 rdx; +__u64 rax; +} __packed; + +struct hv_x64_io_port_intercept_message { +struct hv_x64_intercept_message_header header; +__u16 port_number; +union hv_x64_io_port_access_info access_info; +__u8 instruction_byte_count; +__u32 reserved; +__u64 rax; +__u8 instruction_bytes[16 ]; +struct hv_x64_segment_register ds_segment; +struct hv_x64_segment_register es_segment; +__u64 rcx; +__u64 rsi; +__u64 rdi; +} __packed; + +struct hv_x64_exception_intercept_message { +struct hv_x64_intercept_message_header header; +__u16 exception_vector; +union hv_x64_exception_info exception_info; +__u8 instruction_byte_count; +__u32 error_code; +__u64 exception_parameter; +__u64 reserved; +__u8 instruction_bytes[16 ]; +struct hv_x64_segment_register ds_segment; +struct hv_x64_segment_register ss_segment; +__u64 rax; +__u64 rcx; +__u64 rdx; +__u64 rbx; +__u64 rsp; +__u64 rbp; +__u64 rsi; +__u64 rdi; +__u64 r8; +__u64 r9; +__u64 r10; +__u64 r11; +__u64 r12; +__u64 r13; +__u64 r14; +__u64 r15; +} __packed; + +struct hv_x64_invalid_vp_register_message { +__u32 vp_index; +__u32 reserved; +} __packed; + +struct hv_x64_unrecoverable_exception_message { +struct hv_x64_intercept_message_header header; +} __packed; + +#define HV_UNSUPPORTED_FEATURE_INTERCEPT 1 +#define HV_UNSUPPORTED_FEATURE_TASK_SWITCH_TSS 2 + +struct hv_x64_unsupported_feature_message { +__u32 vp_index; +__u32 feature_code; +__u64 feature_parameter; +} __packed; + +struct hv_x64_halt_message { +struct hv_x64_intercept_message_header header; +} __packed; + +#define HV_X64_PENDING_INTERRUPT 0 +#define HV_X64_PENDING_NMI 2 +#define HV_X64_PENDING_EXCEPTION 3 + +struct hv_x64_interruption_deliverable_message { +struct hv_x64_intercept_message_header header; +__u32 deliverable_type;/* pending interruption type */ +__u32 rsvd; +} __packed; + +struct hv_x64_sipi_intercept_message { +struct hv_x64_intercept_message_header header; +__u32 target_vp_index; +__u32 interrupt_vector; +} __packed; + +struct hv_x64_apic_eoi_message { +__u32 vp_index; +__u32 interrupt_vector; +} __packed; +#endif
drivers/hv/Makefile +1 -1
@@ -13,5 +13,5 @@ hv_vmbus-y := vmbus_drv.o \ hv_vmbus-$(CONFIG_HYPERV_TESTING) += hv_debugfs.o hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_fcopy.o hv_utils_transport.o -mshv-y += mshv_main.o hv_call.o +mshv-y += mshv_main.o hv_call.o hv_synic.o
drivers/hv/hv_synic.c new file +85 -0
85 lines not on this page · raw message
drivers/hv/mshv.h +5 -0
@@ -27,6 +27,11 @@ ((HV_HYP_PAGE_SIZE -sizeof (struct hv_set_vp_registers )) \ / sizeof(struct hv_register_assoc)) +extern struct mshv mshv; + +int mshv_synic_init (unsigned int cpu); +int mshv_synic_cleanup (unsigned int cpu); +/* * Hyper-V hypercalls */
drivers/hv/mshv_main.c +28 -2
@@ -15,6 +15,8 @@#include <linux/file.h> #include <linux/anon_inodes.h> #include <linux/mm.h> +#include <linux/io.h> +#include <linux/cpuhotplug.h> #include <linux/mshv.h> #include <asm/mshyperv.h>
@@ -648,6 +650,8 @@ mshv_dev_release(struct inode *inode, struct file *filp)return 0 ; } +static int mshv_cpuhp_online; +static int __init mshv_init (void ) {
@@ -657,17 +661,39 @@ __init mshv_init(void)return -ENODEV ; ret =misc_register (&mshv_dev); -if (ret) +if (ret) {pr_err ("%s: misc device register failed\n" , __func__); +return ret; + } + + mshv.synic_message_page = alloc_percpu(struct hv_message_page *); +if (!mshv.synic_message_page) { +pr_err ("%s: failed to allocate percpu synic page\n" , __func__); +misc_deregister (&mshv_dev); +return -ENOMEM ; + } + ret =cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"mshv_synic" , + mshv_synic_init, + mshv_synic_cleanup); +if (ret <0 ) { +pr_err ("%s: failed to setup cpu hotplug state: %i\n" , + __func__, ret); +return ret; + } + + mshv_cpuhp_online = ret;spin_lock_init (&mshv.partitions.lock); -return ret; +return 0 ; }static void __exit mshv_exit(void) { +cpuhp_remove_state (mshv_cpuhp_online); +free_percpu (mshv.synic_message_page); +misc_deregister (&mshv_dev); }
include/asm-generic/hyperv-tlfs.h +2 -79
99 lines not on this page · raw message
include/linux/mshv.h +1 -0
@@ -42,6 +42,7 @@ struct mshv_partition { };struct mshv { +struct hv_message_page __percpu **synic_message_page;struct {spinlock_t lock;u64 count;
include/uapi/asm-generic/hyperv-tlfs.h +75 -0
81 lines not on this page · raw message
Signature · 1 line
2.23.4
Re: [PATCH v3 11/19] drivers/hv: set up synic pages for intercept messages
Am Tue, 28 Sep 2021 11:31:07 -0700
schrieb Nuno Das Neves <[email protected]>:
Quoted 2 lines
+++
b/include/asm-generic/hyperv-tlfs.h
-/* Define synthetic interrupt controller message constants. */
I think this code movement could be done in a separate patch. This will reduce conflicts during backporting.
Olaf
PATCH v3 12/19 drivers/hv: run vp ioctl and isr
In reply to Nuno Das NevesIntroduce an ioctl for running a vp and an isr to copy messages from the synic page to the vp data structure.
Add synchronization primitives to ensure that the isr is finished when the run vp ioctl is entered.
--- Documentation/virt/mshv/api.rst | 14 +++ arch/x86/kernel/cpu/mshyperv.c | 16 +++ drivers/hv/hv_synic.c | 96 ++++++++++++++++++ drivers/hv/mshv.h | 1 + drivers/hv/mshv_main.c | 173 +++++++++++++++++++++++++++++++- include/asm-generic/mshyperv.h | 3 + include/linux/mshv.h | 7 ++ include/uapi/linux/mshv.h | 1 + 8 files changed, 310 insertions(+), 1 deletion(-)
Documentation/virt/mshv/api.rst +14 -0
@@ -106,4 +106,18 @@ Get/set vp registers. See asm/hyperv-tlfs.h for the complete set of registers. Includes general purpose platform registers, MSRs, and virtual registers that are part of Microsoft Hypervisor platform and not directly exposed to the guest. +3.6 MSHV_RUN_VP +--------------- +:Type: vp ioctl +:Parameters: struct hv_message +:Returns: 0 on success + +Run the vp, returning when it triggers an intercept, or if the calling thread +is interrupted by a signal. In this case errno will be set to EINTR. + +On return, the vp will be suspended. +This ioctl will fail on any vp that's already running (not suspended). + +Information about the intercept is returned in the hv_message struct. +
arch/x86/kernel/cpu/mshyperv.c +16 -0
@@ -41,6 +41,7 @@ struct ms_hyperv_info ms_hyperv;EXPORT_SYMBOL_GPL (ms_hyperv);#if IS_ENABLED (CONFIG_HYPERV ) +static void (*mshv_handler)(void );static void (*vmbus_handler)(void );static void (*hv_stimer0_handler)(void );static void (*hv_kexec_handler)(void );
@@ -51,6 +52,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 ();
@@ -60,6 +64,18 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_hyperv_callback)set_irq_regs (old_regs); } +void hv_setup_mshv_irq (void (*handler)(void )) +{ + mshv_handler = handler; +} +EXPORT_SYMBOL_GPL (hv_setup_mshv_irq); + +void hv_remove_mshv_irq (void ) +{ + mshv_handler =NULL ; +} +EXPORT_SYMBOL_GPL (hv_remove_mshv_irq); +void hv_setup_vmbus_handler (void (*handler)(void )) { vmbus_handler = handler;
drivers/hv/hv_synic.c +96 -0
107 lines not on this page · raw message
drivers/hv/mshv.h +1 -0
@@ -29,6 +29,7 @@extern struct mshv mshv; +void mshv_isr (void );int mshv_synic_init (unsigned int cpu);int mshv_synic_cleanup (unsigned int cpu);
drivers/hv/mshv_main.c +172 -1
238 lines not on this page · raw message
include/asm-generic/mshyperv.h +3 -0
@@ -143,6 +143,9 @@ 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_remove_mshv_irq (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));
include/linux/mshv.h +7 -0
@@ -8,6 +8,8 @@#include <linux/spinlock.h> #include <linux/mutex.h> +#include <linux/semaphore.h> +#include <linux/sched.h> #include <uapi/linux/mshv.h> #define MSHV_MAX_PARTITIONS 128
@@ -18,6 +20,11 @@ struct mshv_vp {u32 index;struct mshv_partition *partition;struct mutex mutex; +struct { +struct semaphore sem; +struct task_struct *task; +struct hv_message *intercept_message; + } run; };struct mshv_mem_region {
include/uapi/linux/mshv.h +1 -0
@@ -55,5 +55,6 @@ struct mshv_vp_registers {/* vp device */ #define MSHV_GET_VP_REGISTERS _IOWR(MSHV_IOCTL, 0x05, struct mshv_vp_registers)#define MSHV_SET_VP_REGISTERS _IOW(MSHV_IOCTL, 0x06, struct mshv_vp_registers) +#define MSHV_RUN_VP _IOR(MSHV_IOCTL, 0x07, struct hv_message)#endif
Signature · 1 line
2.23.4
PATCH v3 13/19 drivers/hv: install intercept ioctl
In reply to Nuno Das NevesIntroduce ioctl for configuring intercept messages from a guest partition.
--- Documentation/virt/mshv/api.rst | 9 ++++++ arch/x86/include/uapi/asm/hyperv-tlfs.h | 43 +++++++++++++++++++++++++ drivers/hv/hv_call.c | 38 ++++++++++++++++++++++ drivers/hv/mshv.h | 3 ++ drivers/hv/mshv_main.c | 20 ++++++++++++ include/asm-generic/hyperv-tlfs.h | 8 +++++ include/uapi/linux/mshv.h | 7 ++++ 7 files changed, 128 insertions(+)
Documentation/virt/mshv/api.rst +9 -0
@@ -120,4 +120,13 @@ This ioctl will fail on any vp that's already running (not suspended). Information about the intercept is returned in the hv_message struct. +3.7 MSHV_INSTALL_INTERCEPT +-------------------------- +:Type: partition ioctl +:Parameters: struct mshv_install_intercept +:Returns: 0 on success + +Enable and configure different types of intercepts. Intercepts are events in a +guest partition that will suspend the guest vp and send a message to the root +partition (returned from MSHV_RUN_VP).
arch/x86/include/uapi/asm/hyperv-tlfs.h +43 -0
47 lines not on this page · raw message
drivers/hv/hv_call.c +38 -0
@@ -394,3 +394,41 @@ int hv_call_set_vp_registers(return hv_status_to_errno (status); } +int hv_call_install_intercept ( +u64 partition_id, +u32 access_type, +enum hv_intercept_type intercept_type, +union hv_intercept_parameters intercept_parameter) +{ +struct hv_install_intercept *input; +unsigned long flags; +u64 status; +int ret; + +do { +local_irq_save (flags); + input = (struct hv_install_intercept *)(*this_cpu_ptr ( + hyperv_pcpu_input_arg)); + input->partition_id = partition_id; + input->access_type = access_type; + input->intercept_type = intercept_type; + input->intercept_parameter = intercept_parameter; + status =hv_do_hypercall ( +HVCALL_INSTALL_INTERCEPT , input,NULL ); + +local_irq_restore (flags); +if (hv_result (status) !=HV_STATUS_INSUFFICIENT_MEMORY ) { +if (!hv_result_success (status)) +pr_err ("%s: %s\n" , __func__, +hv_status_to_string (status)); + ret =hv_status_to_errno (status); +break ; + } + + ret =hv_call_deposit_pages (NUMA_NO_NODE , partition_id,1 ); + + }while (!ret); + +return ret; +} +
drivers/hv/mshv.h +3 -0
@@ -64,5 +64,8 @@ int hv_call_set_vp_registers(u64 partition_id, u16 count, struct hv_register_assoc *registers); +int hv_call_install_intercept (u64 partition_id,u32 access_type, +enum hv_intercept_type intercept_type, +union hv_intercept_parameters intercept_parameter);#endif /* _MSHV_H */
drivers/hv/mshv_main.c +20 -0
@@ -567,6 +567,22 @@ mshv_partition_ioctl_unmap_memory(struct mshv_partition *partition,return 0 ; } +static long +mshv_partition_ioctl_install_intercept (struct mshv_partition *partition, +void __user *user_args) +{ +struct mshv_install_intercept args; + +if (copy_from_user (&args, user_args,sizeof (args))) +return -EFAULT ; + +return hv_call_install_intercept ( + partition->id, + args.access_type_mask, + args.intercept_type, + args.intercept_parameter); +} +static long mshv_partition_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) {
@@ -589,6 +605,10 @@ mshv_partition_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) ret =mshv_partition_ioctl_create_vp (partition, (void __user *)arg);break ; +case MSHV_INSTALL_INTERCEPT : + ret =mshv_partition_ioctl_install_intercept (partition, + (void __user *)arg); +break ;default : ret = -ENOTTY ; }
include/asm-generic/hyperv-tlfs.h +8 -0
@@ -152,6 +152,7 @@ struct ms_hyperv_tsc_page {#define HVCALL_WITHDRAW_MEMORY 0x0049#define HVCALL_MAP_GPA_PAGES 0x004b#define HVCALL_UNMAP_GPA_PAGES 0x004c +#define HVCALL_INSTALL_INTERCEPT 0x004d#define HVCALL_CREATE_VP 0x004e#define HVCALL_GET_VP_REGISTERS 0x0050#define HVCALL_SET_VP_REGISTERS 0x0051
@@ -813,4 +814,11 @@ struct hv_unmap_gpa_pages { u32 padding; } __packed; +struct hv_install_intercept { +u64 partition_id; +u32 access_type;/* mask */ +u32 intercept_type; +union hv_intercept_parameters intercept_parameter; +} __packed; +#endif
include/uapi/linux/mshv.h +7 -0
@@ -41,6 +41,12 @@ struct mshv_vp_registers {struct hv_register_assoc *regs; }; +struct mshv_install_intercept { +__u32 access_type_mask; +enum hv_intercept_type intercept_type; +union hv_intercept_parameters intercept_parameter; +}; +#define MSHV_IOCTL 0xB8/* mshv device */
@@ -51,6 +57,7 @@ struct mshv_vp_registers {#define MSHV_MAP_GUEST_MEMORY _IOW(MSHV_IOCTL, 0x02, struct mshv_user_mem_region)#define MSHV_UNMAP_GUEST_MEMORY _IOW(MSHV_IOCTL, 0x03, struct mshv_user_mem_region)#define MSHV_CREATE_VP _IOW(MSHV_IOCTL, 0x04, struct mshv_create_vp) +#define MSHV_INSTALL_INTERCEPT _IOW(MSHV_IOCTL, 0x08, struct mshv_install_intercept)/* vp device */ #define MSHV_GET_VP_REGISTERS _IOWR(MSHV_IOCTL, 0x05, struct mshv_vp_registers)
Signature · 1 line
2.23.4
PATCH v3 14/19 drivers/hv: assert interrupt ioctl
In reply to Nuno Das NevesIntroduce ioctl for asserting an interrupt on a given APIC within a guest partition.
--- Documentation/virt/mshv/api.rst | 11 ++++++++++ arch/x86/include/asm/hyperv-tlfs.h | 14 ------------ arch/x86/include/uapi/asm/hyperv-tlfs.h | 22 +++++++++++++++++++ drivers/hv/hv_call.c | 29 +++++++++++++++++++++++++ drivers/hv/mshv.h | 5 +++++ drivers/hv/mshv_main.c | 20 +++++++++++++++++ include/asm-generic/hyperv-tlfs.h | 11 ++++++++++ include/uapi/linux/mshv.h | 7 ++++++ 8 files changed, 105 insertions(+), 14 deletions(-)
Documentation/virt/mshv/api.rst +11 -0
@@ -130,3 +130,14 @@ Enable and configure different types of intercepts. Intercepts are events in a guest partition that will suspend the guest vp and send a message to the root partition (returned from MSHV_RUN_VP). +3.8 MSHV_ASSERT_INTERRUPT +-------------------------- +:Type: partition ioctl +:Parameters: struct mshv_assert_interrupt +:Returns: 0 on success + +Assert interrupts in partitions that use Microsoft Hypervisor's internal +emulated LAPIC. This must be enabled on partition creation with the flag: +HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED + +
arch/x86/include/asm/hyperv-tlfs.h +0 -14
@@ -546,20 +546,6 @@ struct hv_partition_assist_pg { u32 tlb_lock_count; }; -enum hv_interrupt_type { -HV_X64_INTERRUPT_TYPE_FIXED =0x0000 , -HV_X64_INTERRUPT_TYPE_LOWESTPRIORITY =0x0001 , -HV_X64_INTERRUPT_TYPE_SMI =0x0002 , -HV_X64_INTERRUPT_TYPE_REMOTEREAD =0x0003 , -HV_X64_INTERRUPT_TYPE_NMI =0x0004 , -HV_X64_INTERRUPT_TYPE_INIT =0x0005 , -HV_X64_INTERRUPT_TYPE_SIPI =0x0006 , -HV_X64_INTERRUPT_TYPE_EXTINT =0x0007 , -HV_X64_INTERRUPT_TYPE_LOCALINT0 =0x0008 , -HV_X64_INTERRUPT_TYPE_LOCALINT1 =0x0009 , -HV_X64_INTERRUPT_TYPE_MAXIMUM =0x000A , -}; -#include <asm-generic/hyperv-tlfs.h> #endif
arch/x86/include/uapi/asm/hyperv-tlfs.h +22 -0
@@ -989,6 +989,28 @@ union hv_intercept_parameters {#define HV_INTERCEPT_ACCESS_MASK_WRITE 0x02#define HV_INTERCEPT_ACCESS_MASK_EXECUTE 0x04 +enum hv_interrupt_type { +HV_X64_INTERRUPT_TYPE_FIXED =0x0000 , +HV_X64_INTERRUPT_TYPE_LOWESTPRIORITY =0x0001 , +HV_X64_INTERRUPT_TYPE_SMI =0x0002 , +HV_X64_INTERRUPT_TYPE_REMOTEREAD =0x0003 , +HV_X64_INTERRUPT_TYPE_NMI =0x0004 , +HV_X64_INTERRUPT_TYPE_INIT =0x0005 , +HV_X64_INTERRUPT_TYPE_SIPI =0x0006 , +HV_X64_INTERRUPT_TYPE_EXTINT =0x0007 , +HV_X64_INTERRUPT_TYPE_LOCALINT0 =0x0008 , +HV_X64_INTERRUPT_TYPE_LOCALINT1 =0x0009 , +HV_X64_INTERRUPT_TYPE_MAXIMUM =0x000A +}; +union hv_interrupt_control { +struct { +__u32 interrupt_type;/* enum hv_interrupt type */ +__u32 level_triggered :1 ; +__u32 logical_dest_mode :1 ; +__u32 rsvd :30 ; + } __packed; +__u64 as_uint64; +};#endif
drivers/hv/hv_call.c +29 -0
@@ -432,3 +432,32 @@ int hv_call_install_intercept(return ret; } +int hv_call_assert_virtual_interrupt ( +u64 partition_id, +u32 vector, +u64 dest_addr, +union hv_interrupt_control control) +{ +struct hv_assert_virtual_interrupt *input; +unsigned long flags; +u64 status; + +local_irq_save (flags); + input = (struct hv_assert_virtual_interrupt *)(*this_cpu_ptr ( + hyperv_pcpu_input_arg)); +memset (input,0 ,sizeof (*input)); + input->partition_id = partition_id; + input->vector = vector; + input->dest_addr = dest_addr; + input->control = control; + status =hv_do_hypercall (HVCALL_ASSERT_VIRTUAL_INTERRUPT , input,NULL ); +local_irq_restore (flags); + +if (!hv_result_success (status)) { +pr_err ("%s: %s\n" , __func__,hv_status_to_string (status)); +return hv_status_to_errno (status); + } + +return 0 ; +} +
drivers/hv/mshv.h +5 -0
@@ -67,5 +67,10 @@ int hv_call_set_vp_registers(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);#endif /* _MSHV_H */
drivers/hv/mshv_main.c +20 -0
@@ -583,6 +583,22 @@ mshv_partition_ioctl_install_intercept(struct mshv_partition *partition, args.intercept_parameter); } +static long +mshv_partition_ioctl_assert_interrupt (struct mshv_partition *partition, +void __user *user_args) +{ +struct mshv_assert_interrupt args; + +if (copy_from_user (&args, user_args,sizeof (args))) +return -EFAULT ; + +return hv_call_assert_virtual_interrupt ( + partition->id, + args.vector, + args.dest_addr, + args.control); +} +static long mshv_partition_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) {
@@ -609,6 +625,10 @@ mshv_partition_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) ret =mshv_partition_ioctl_install_intercept (partition, (void __user *)arg);break ; +case MSHV_ASSERT_INTERRUPT : + ret =mshv_partition_ioctl_assert_interrupt (partition, + (void __user *)arg); +break ;default : ret = -ENOTTY ; }
include/asm-generic/hyperv-tlfs.h +11 -0
@@ -165,6 +165,7 @@ struct ms_hyperv_tsc_page {#define HVCALL_MAP_DEVICE_INTERRUPT 0x007c#define HVCALL_UNMAP_DEVICE_INTERRUPT 0x007d#define HVCALL_RETARGET_INTERRUPT 0x007e +#define HVCALL_ASSERT_VIRTUAL_INTERRUPT 0x0094#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0
@@ -821,4 +822,14 @@ struct hv_install_intercept { union hv_intercept_parameters intercept_parameter; } __packed; +struct hv_assert_virtual_interrupt { +u64 partition_id; +union hv_interrupt_control control; +u64 dest_addr;/* cpu's apic id */ +u32 vector; +u8 target_vtl; +u8 rsvd_z0; +u16 rsvd_z1; +} __packed; +#endif
include/uapi/linux/mshv.h +7 -0
@@ -47,6 +47,12 @@ struct mshv_install_intercept {union hv_intercept_parameters intercept_parameter; }; +struct mshv_assert_interrupt { +union hv_interrupt_control control; +__u64 dest_addr; +__u32 vector; +}; +#define MSHV_IOCTL 0xB8/* mshv device */
@@ -58,6 +64,7 @@ struct mshv_install_intercept {#define MSHV_UNMAP_GUEST_MEMORY _IOW(MSHV_IOCTL, 0x03, struct mshv_user_mem_region)#define MSHV_CREATE_VP _IOW(MSHV_IOCTL, 0x04, struct mshv_create_vp)#define MSHV_INSTALL_INTERCEPT _IOW(MSHV_IOCTL, 0x08, struct mshv_install_intercept) +#define MSHV_ASSERT_INTERRUPT _IOW(MSHV_IOCTL, 0x09, struct mshv_assert_interrupt)/* vp device */ #define MSHV_GET_VP_REGISTERS _IOWR(MSHV_IOCTL, 0x05, struct mshv_vp_registers)
Signature · 1 line
2.23.4
PATCH v3 15/19 drivers/hv: get and set vp state ioctls
In reply to Nuno Das NevesIntroduce ioctls for getting and setting guest vcpu emulated LAPIC state, and xsave data.
--- Documentation/virt/mshv/api.rst | 8 ++ arch/x86/include/uapi/asm/hyperv-tlfs.h | 59 ++++++++++ drivers/hv/hv_call.c | 138 +++++++++++++++++++++++- drivers/hv/mshv.h | 25 +++++ drivers/hv/mshv_main.c | 122 +++++++++++++++++++++ include/asm-generic/hyperv-tlfs.h | 40 +++++++ include/uapi/asm-generic/hyperv-tlfs.h | 28 +++++ include/uapi/linux/mshv.h | 13 +++ 8 files changed, 432 insertions(+), 1 deletion(-)
Documentation/virt/mshv/api.rst +8 -0
@@ -140,4 +140,12 @@ Assert interrupts in partitions that use Microsoft Hypervisor's internal emulated LAPIC. This must be enabled on partition creation with the flag: HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED +3.9 MSHV_GET_VP_STATE and MSHV_SET_VP_STATE +-------------------------- +:Type: vp ioctl +:Parameters: struct mshv_vp_state +:Returns: 0 on success + +Get/set various vp state. Currently these can be used to get and set +emulated LAPIC state, and xsave data.
arch/x86/include/uapi/asm/hyperv-tlfs.h +59 -0
63 lines not on this page · raw message
drivers/hv/hv_call.c +137 -1
147 lines not on this page · raw message
drivers/hv/mshv.h +25 -0
@@ -26,6 +26,12 @@#define HV_SET_REGISTER_BATCH_SIZE \ ((HV_HYP_PAGE_SIZE - sizeof(struct hv_set_vp_registers)) \ / sizeof(struct hv_register_assoc)) +#define HV_GET_VP_STATE_BATCH_SIZE \ + ((HV_HYP_PAGE_SIZE - sizeof(struct hv_get_vp_state_in)) \ + / sizeof(u64)) +#define HV_SET_VP_STATE_BATCH_SIZE \ + ((HV_HYP_PAGE_SIZE - sizeof(struct hv_set_vp_state_in)) \ + / sizeof(u64))extern struct mshv mshv;
@@ -72,5 +78,24 @@ int hv_call_assert_virtual_interrupt(u32 vector, u64 dest_addr, union hv_interrupt_control control); +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_get_vp_state_out *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 /* _MSHV_H */
drivers/hv/mshv_main.c +122 -0
134 lines not on this page · raw message
include/asm-generic/hyperv-tlfs.h +40 -0
@@ -168,6 +168,9 @@ struct ms_hyperv_tsc_page {#define HVCALL_ASSERT_VIRTUAL_INTERRUPT 0x0094#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0 +#define HVCALL_MAP_VP_STATE_PAGE 0x00e1 +#define HVCALL_GET_VP_STATE 0x00e3 +#define HVCALL_SET_VP_STATE 0x00e4/* Extended hypercalls */ #define HV_EXT_CALL_QUERY_CAPABILITIES 0x8001
@@ -832,4 +835,41 @@ struct hv_assert_virtual_interrupt { u16 rsvd_z1; } __packed; +struct hv_vp_state_data { +u32 type; +u32 rsvd; +struct hv_vp_state_data_xsave xsave; +} __packed; + +struct hv_get_vp_state_in { +u64 partition_id; +u32 vp_index; +u8 input_vtl; +u8 rsvd0; +u16 rsvd1; +struct hv_vp_state_data state_data; +u64 output_data_pfns[]; +} __packed; + +union hv_get_vp_state_out { +struct hv_local_interrupt_controller_state interrupt_controller_state; +/* Not supported yet */ +/* struct hv_synthetic_timers_state synthetic_timers_state; */ +} __packed; + +union hv_input_set_vp_state_data { +u64 pfns; +u8 bytes; +} __packed; + +struct hv_set_vp_state_in { +u64 partition_id; +u32 vp_index; +u8 input_vtl; +u8 rsvd0; +u16 rsvd1; +struct hv_vp_state_data state_data; +union hv_input_set_vp_state_data data[]; +} __packed; +#endif
include/uapi/asm-generic/hyperv-tlfs.h +28 -0
@@ -103,4 +103,32 @@ struct hv_register_assoc { union hv_register_value value; } __packed; +/* +* For getting and setting VP state, there are two options based on the state type: +* +* 1.) Data that is accessed by PFNs in the input hypercall page. This is used +* for state which may not fit into the hypercall pages. +* 2.) Data that is accessed directly in the input\output hypercall pages. +* This is used for state that will always fit into the hypercall pages. +* +* In the future this could be dynamic based on the size if needed. +* +* Note these hypercalls have an 8-byte aligned variable header size as per the tlfs +*/ + +#define HV_GET_SET_VP_STATE_TYPE_PFN BIT(31) + +enum hv_get_set_vp_state_type { +HV_GET_SET_VP_STATE_LOCAL_INTERRUPT_CONTROLLER_STATE =0 , + +HV_GET_SET_VP_STATE_XSAVE =1 |HV_GET_SET_VP_STATE_TYPE_PFN , +/* Synthetic message page */ +HV_GET_SET_VP_STATE_SIM_PAGE =2 |HV_GET_SET_VP_STATE_TYPE_PFN , +/* Synthetic interrupt event flags page. */ +HV_GET_SET_VP_STATE_SIEF_PAGE =3 |HV_GET_SET_VP_STATE_TYPE_PFN , + +/* Synthetic timers. */ +HV_GET_SET_VP_STATE_SYNTHETIC_TIMERS =4 , +}; +#endif
include/uapi/linux/mshv.h +13 -0
@@ -53,6 +53,17 @@ struct mshv_assert_interrupt {__u32 vector; }; +struct mshv_vp_state { +enum hv_get_set_vp_state_type type; +struct hv_vp_state_data_xsave xsave;/* only for xsave request */ + +__u64 buf_size;/* If xsave, must be page-aligned */ +union { +struct hv_local_interrupt_controller_state *lapic; +__u8 *bytes;/* Xsave data. must be page-aligned */ + } buf; +}; +#define MSHV_IOCTL 0xB8/* mshv device */
@@ -70,5 +81,7 @@ struct mshv_assert_interrupt {#define MSHV_GET_VP_REGISTERS _IOWR(MSHV_IOCTL, 0x05, struct mshv_vp_registers)#define MSHV_SET_VP_REGISTERS _IOW(MSHV_IOCTL, 0x06, struct mshv_vp_registers)#define MSHV_RUN_VP _IOR(MSHV_IOCTL, 0x07, struct hv_message) +#define MSHV_GET_VP_STATE _IOWR(MSHV_IOCTL, 0x0A, struct mshv_vp_state) +#define MSHV_SET_VP_STATE _IOWR(MSHV_IOCTL, 0x0B, struct mshv_vp_state)#endif
Signature · 1 line
2.23.4
PATCH v3 16/19 drivers/hv: mmap vp register page
In reply to Nuno Das NevesIntroduce mmap interface for a virtual processor, exposing a page for setting and getting common registers while the VP is suspended.
This provides a more performant and convenient way to get and set these registers in the context of a vmm's run-loop.
--- Documentation/virt/mshv/api.rst | 11 ++++ arch/x86/include/uapi/asm/hyperv-tlfs.h | 74 +++++++++++++++++++++++++ drivers/hv/hv_call.c | 41 ++++++++++++++ drivers/hv/mshv.h | 4 ++ drivers/hv/mshv_main.c | 44 +++++++++++++++ include/asm-generic/hyperv-tlfs.h | 10 ++++ include/linux/mshv.h | 1 + include/uapi/asm-generic/hyperv-tlfs.h | 5 ++ include/uapi/linux/mshv.h | 12 ++++ 9 files changed, 202 insertions(+)
Documentation/virt/mshv/api.rst +11 -0
@@ -149,3 +149,14 @@ HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED Get/set various vp state. Currently these can be used to get and set emulated LAPIC state, and xsave data. +3.10 mmap(vp) +------------- +:Type: vp mmap +:Parameters: offset should be HV_VP_MMAP_REGISTERS_OFFSET +:Returns: 0 on success + +Maps a page into userspace that can be used to get and set common registers +while the vp is suspended. +The page is laid out in struct hv_vp_register_page in asm/hyperv-tlfs.h. + +
arch/x86/include/uapi/asm/hyperv-tlfs.h +74 -0
78 lines not on this page · raw message
drivers/hv/hv_call.c +41 -0
44 lines not on this page · raw message
drivers/hv/mshv.h +4 -0
@@ -97,5 +97,9 @@ int hv_call_set_vp_state(struct page **pages, u32 num_bytes, u8 *bytes); +int hv_call_map_vp_state_page ( +u32 vp_index, +u64 partition_id, +struct page **state_page);#endif /* _MSHV_H */
drivers/hv/mshv_main.c +44 -0
61 lines not on this page · raw message
include/asm-generic/hyperv-tlfs.h +10 -0
@@ -872,4 +872,14 @@ struct hv_set_vp_state_in { union hv_input_set_vp_state_data data[]; } __packed; +struct hv_map_vp_state_page_in { +u64 partition_id; +u32 vp_index; +u32 type;/* enum hv_vp_state_page_type */ +} __packed; + +struct hv_map_vp_state_page_out { +u64 map_location;/* page number */ +} __packed; +#endif
include/linux/mshv.h +1 -0
@@ -20,6 +20,7 @@ struct mshv_vp {u32 index;struct mshv_partition *partition;struct mutex mutex; +struct page *register_page;struct {struct semaphore sem;struct task_struct *task;
include/uapi/asm-generic/hyperv-tlfs.h +5 -0
@@ -131,4 +131,9 @@ enum hv_get_set_vp_state_type { HV_GET_SET_VP_STATE_SYNTHETIC_TIMERS = 4, }; +enum hv_vp_state_page_type { +HV_VP_STATE_PAGE_REGISTERS =0 , +HV_VP_STATE_PAGE_COUNT +}; +#endif
include/uapi/linux/mshv.h +12 -0
@@ -14,6 +14,8 @@#define MSHV_CAP_CORE_API_STABLE 0x0 +#define MSHV_VP_MMAP_REGISTERS_OFFSET (HV_VP_STATE_PAGE_REGISTERS * 0x1000) +struct mshv_create_partition {__u64 flags;struct hv_partition_creation_properties partition_creation_properties;
@@ -84,4 +86,14 @@ struct mshv_vp_state {#define MSHV_GET_VP_STATE _IOWR(MSHV_IOCTL, 0x0A, struct mshv_vp_state)#define MSHV_SET_VP_STATE _IOWR(MSHV_IOCTL, 0x0B, struct mshv_vp_state) +/* register page mapping example: +* struct hv_vp_register_page *regs = mmap(NULL, +* 4096, +* PROT_READ | PROT_WRITE, +* MAP_SHARED, +* vp_fd, +* HV_VP_MMAP_REGISTERS_OFFSET); +* munmap(regs, 4096); +*/ +#endif
Signature · 1 line
2.23.4
PATCH v3 17/19 drivers/hv: get and set partition property ioctls
In reply to Nuno Das NevesIntroduce ioctls for getting and setting properties of guest partitions.
--- Documentation/virt/mshv/api.rst | 8 ++++ drivers/hv/hv_call.c | 58 +++++++++++++++++++++++++ drivers/hv/mshv.h | 8 ++++ drivers/hv/mshv_main.c | 47 ++++++++++++++++++++ include/asm-generic/hyperv-tlfs.h | 19 +++++++++ include/uapi/asm-generic/hyperv-tlfs.h | 59 ++++++++++++++++++++++++++ include/uapi/linux/mshv.h | 9 ++++ 7 files changed, 208 insertions(+)
Documentation/virt/mshv/api.rst +8 -0
@@ -159,4 +159,12 @@ Maps a page into userspace that can be used to get and set common registers while the vp is suspended. The page is laid out in struct hv_vp_register_page in asm/hyperv-tlfs.h. +3.11 MSHV_SET_PARTITION_PROPERTY and MSHV_GET_PARTITION_PROPERTY +---------------------------------------------------------------- +:Type: partition ioctl +:Parameters: struct mshv_partition_property +:Returns: 0 on success + +Can be used to get/set various properties of a partition. +
drivers/hv/hv_call.c +58 -0
61 lines not on this page · raw message
drivers/hv/mshv.h +8 -0
@@ -101,5 +101,13 @@ int hv_call_map_vp_state_page(u32 vp_index, u64 partition_id, struct page **state_page); +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);#endif /* _MSHV_H */
drivers/hv/mshv_main.c +47 -0
59 lines not on this page · raw message
include/asm-generic/hyperv-tlfs.h +19 -0
@@ -147,6 +147,8 @@ struct ms_hyperv_tsc_page {#define HVCALL_INITIALIZE_PARTITION 0x0041#define HVCALL_FINALIZE_PARTITION 0x0042#define HVCALL_DELETE_PARTITION 0x0043 +#define HVCALL_GET_PARTITION_PROPERTY 0x0044 +#define HVCALL_SET_PARTITION_PROPERTY 0x0045#define HVCALL_GET_PARTITION_ID 0x0046#define HVCALL_DEPOSIT_MEMORY 0x0048#define HVCALL_WITHDRAW_MEMORY 0x0049
@@ -882,4 +884,21 @@ struct hv_map_vp_state_page_out { u64 map_location; /* page number */ } __packed; +struct hv_get_partition_property_in { +u64 partition_id; +u32 property_code;/* enum hv_partition_property_code */ +u32 padding; +} __packed; + +struct hv_get_partition_property_out { +u64 property_value; +} __packed; + +struct hv_set_partition_property { +u64 partition_id; +u32 property_code;/* enum hv_partition_property_code */ +u32 padding; +u64 property_value; +} __packed; +#endif
include/uapi/asm-generic/hyperv-tlfs.h +59 -0
63 lines not on this page · raw message
include/uapi/linux/mshv.h +9 -0
@@ -66,6 +66,11 @@ struct mshv_vp_state { } buf; }; +struct mshv_partition_property { +enum hv_partition_property_code property_code; +__u64 property_value; +}; +#define MSHV_IOCTL 0xB8/* mshv device */
@@ -78,6 +83,10 @@ struct mshv_vp_state {#define MSHV_CREATE_VP _IOW(MSHV_IOCTL, 0x04, struct mshv_create_vp)#define MSHV_INSTALL_INTERCEPT _IOW(MSHV_IOCTL, 0x08, struct mshv_install_intercept)#define MSHV_ASSERT_INTERRUPT _IOW(MSHV_IOCTL, 0x09, struct mshv_assert_interrupt) +#define MSHV_SET_PARTITION_PROPERTY \ + _IOW(MSHV_IOCTL, 0xC, struct mshv_partition_property) +#define MSHV_GET_PARTITION_PROPERTY \ + _IOWR(MSHV_IOCTL, 0xD, struct mshv_partition_property)/* vp device */ #define MSHV_GET_VP_REGISTERS _IOWR(MSHV_IOCTL, 0x05, struct mshv_vp_registers)
Signature · 1 line
2.23.4
PATCH v3 18/19 drivers/hv: Add enlightenment bits to create partition ioctl
In reply to Nuno Das NevesIntroduce hv_partition_synthetic_processor features mask to MSHV_CREATE_PARTITION ioctl, which can be used to enable hypervisor enlightenments for exo partitions.
--- Documentation/virt/mshv/api.rst | 3 + arch/x86/include/uapi/asm/hyperv-tlfs.h | 125 ++++++++++++++++++++++++ drivers/hv/mshv_main.c | 7 ++ include/uapi/asm-generic/hyperv-tlfs.h | 1 + include/uapi/linux/mshv.h | 1 + 5 files changed, 137 insertions(+)
Documentation/virt/mshv/api.rst +3 -0
@@ -167,4 +167,7 @@ The page is laid out in struct hv_vp_register_page in asm/hyperv-tlfs.h. Can be used to get/set various properties of a partition. +Some properties can only be set at partition creation. For these, there are +parameters in MSHV_CREATE_PARTITION. +
arch/x86/include/uapi/asm/hyperv-tlfs.h +125 -0
129 lines not on this page · raw message
drivers/hv/mshv_main.c +7 -0
@@ -1000,6 +1000,13 @@ mshv_ioctl_create_partition(void __user *user_arg)if (ret) goto put_fd; + ret =hv_call_set_partition_property ( + partition->id, +HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES , + args.synthetic_processor_features.as_uint64[0 ]); +if (ret) + goto delete_partition; + ret =hv_call_initialize_partition (partition->id);if (ret) goto delete_partition;
include/uapi/asm-generic/hyperv-tlfs.h +1 -0
@@ -139,6 +139,7 @@ enum hv_vp_state_page_type {enum hv_partition_property_code {/* Privilege properties */ HV_PARTITION_PROPERTY_PRIVILEGE_FLAGS =0x00010000 , +HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES =0x00010001 ,/* Scheduling properties */ HV_PARTITION_PROPERTY_SUSPEND =0x00020000 ,
include/uapi/linux/mshv.h +1 -0
@@ -19,6 +19,7 @@struct mshv_create_partition {__u64 flags;struct hv_partition_creation_properties partition_creation_properties; +union hv_partition_synthetic_processor_features synthetic_processor_features; };/*
Signature · 1 line
2.23.4
PATCH v3 19/19 drivers/hv: Translate GVA to GPA
In reply to Nuno Das NevesFrom: Wei Liu <[email protected]>
Introduce ioctl for translating Guest Virtual Address (GVA) to Guest Physical Address (GPA)
--- drivers/hv/hv_call.c | 44 ++++++++++++++++++++++++++ drivers/hv/mshv.h | 7 ++++ drivers/hv/mshv_main.c | 34 ++++++++++++++++++++ include/asm-generic/hyperv-tlfs.h | 14 ++++++++ include/uapi/asm-generic/hyperv-tlfs.h | 43 +++++++++++++++++++++++++ include/uapi/linux/mshv.h | 8 +++++ 6 files changed, 150 insertions(+)
drivers/hv/hv_call.c +44 -0
@@ -10,6 +10,7 @@#include <linux/kernel.h> #include <linux/mm.h> +#include <linux/hyperv.h> #include <asm/mshyperv.h> #include "mshv.h"
@@ -696,3 +697,46 @@ int hv_call_set_partition_property(return hv_status_to_errno (status); } + +int hv_call_translate_virtual_address ( +u32 vp_index, +u64 partition_id, +u64 flags, +u64 gva, +u64 *gpa, +union hv_translate_gva_result *result) +{ +u64 status; +unsigned long irq_flags; +struct hv_translate_virtual_address_in *input; +struct hv_translate_virtual_address_out *output; + +local_irq_save (irq_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->partition_id = partition_id; + input->vp_index = vp_index; + input->control_flags = flags; + input->gva_page = gva >>HV_HYP_PAGE_SHIFT ; + + status =hv_do_hypercall (HVCALL_TRANSLATE_VIRTUAL_ADDRESS , input, output); + +if (!hv_result_success (status)) { +pr_err ("%s: %s\n" , __func__,hv_status_to_string (status)); + goto out; + } + + *result = output->translation_result; + *gpa = (output->gpa_page <<HV_HYP_PAGE_SHIFT ) +offset_in_hvpage (gva); + +out: +local_irq_restore (irq_flags); + +return hv_status_to_errno (status); +} +
drivers/hv/mshv.h +7 -0
@@ -109,5 +109,12 @@ int hv_call_set_partition_property(u64 partition_id, u64 property_code, u64 property_value); +int hv_call_translate_virtual_address ( +u32 vp_index, +u64 partition_id, +u64 flags, +u64 gva, +u64 *gpa, +union hv_translate_gva_result *result);#endif /* _MSHV_H */
drivers/hv/mshv_main.c +34 -0
@@ -411,6 +411,37 @@ mshv_vp_ioctl_get_set_state(struct mshv_vp *vp, void __user *user_args, bool is_return 0 ; } +static long +mshv_vp_ioctl_translate_gva (struct mshv_vp *vp,void __user *user_args) +{ +long ret; +struct mshv_translate_gva args; +u64 gpa; +union hv_translate_gva_result result; + +if (copy_from_user (&args, user_args,sizeof (args))) +return -EFAULT ; + + ret =hv_call_translate_virtual_address ( + vp->index, + vp->partition->id, + args.flags, + args.gva, + &gpa, + &result); + +if (ret) +return ret; + +if (copy_to_user (args.result, &result,sizeof (*args.result))) +return -EFAULT ; + +if (copy_to_user (args.gpa, &gpa,sizeof (*args.gpa))) +return -EFAULT ; + +return 0 ; +} +static long mshv_vp_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) {
@@ -436,6 +467,9 @@ mshv_vp_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)case MSHV_SET_VP_STATE : r =mshv_vp_ioctl_get_set_state (vp, (void __user *)arg, true);break ; +case MSHV_TRANSLATE_GVA : + r =mshv_vp_ioctl_translate_gva (vp, (void __user *)arg); +break ;default : r = -ENOTTY ;break ;
include/asm-generic/hyperv-tlfs.h +14 -0
@@ -158,6 +158,7 @@ struct ms_hyperv_tsc_page {#define HVCALL_CREATE_VP 0x004e#define HVCALL_GET_VP_REGISTERS 0x0050#define HVCALL_SET_VP_REGISTERS 0x0051 +#define HVCALL_TRANSLATE_VIRTUAL_ADDRESS 0x0052#define HVCALL_POST_MESSAGE 0x005c#define HVCALL_SIGNAL_EVENT 0x005d#define HVCALL_POST_DEBUG_DATA 0x0069
@@ -901,4 +902,17 @@ struct hv_set_partition_property { u64 property_value; } __packed; +struct hv_translate_virtual_address_in { +u64 partition_id; +u32 vp_index; +u32 padding; +u64 control_flags; +u64 gva_page; +} __packed; + +struct hv_translate_virtual_address_out { +union hv_translate_gva_result translation_result; +u64 gpa_page; +} __packed; +#endif
include/uapi/asm-generic/hyperv-tlfs.h +43 -0
47 lines not on this page · raw message
include/uapi/linux/mshv.h +8 -0
@@ -72,6 +72,13 @@ struct mshv_partition_property {__u64 property_value; }; +struct mshv_translate_gva { +__u64 gva; +__u64 flags; +union hv_translate_gva_result *result; +__u64 *gpa; +}; +#define MSHV_IOCTL 0xB8/* mshv device */
@@ -95,6 +102,7 @@ struct mshv_partition_property {#define MSHV_RUN_VP _IOR(MSHV_IOCTL, 0x07, struct hv_message)#define MSHV_GET_VP_STATE _IOWR(MSHV_IOCTL, 0x0A, struct mshv_vp_state)#define MSHV_SET_VP_STATE _IOWR(MSHV_IOCTL, 0x0B, struct mshv_vp_state) +#define MSHV_TRANSLATE_GVA _IOWR(MSHV_IOCTL, 0x0E, struct mshv_translate_gva)/* register page mapping example: * struct hv_vp_register_page *regs = mmap(NULL,
Signature · 1 line
2.23.4