mshv: add ioctl to get hypervisor system properties
Subsystems (2)
PATCH 1/1 mshv: add ioctl to get hypervisor system properties
VMMs need to know about some of the host capabilities before deciding how to configure their guests. For instance, before creating SEV-SNP isolated partitions, a VMM has to know whether the hypervisor supports them, which the hypervisor reports through the SNP status dynamic processor feature system property. However, there is currently no way for userspace to get hypervisor system properties. So, VMMs have to have to resort to probing (e.g. by trying to create an SEV-SNP partition).
So, add an MSHV_GET_SYSTEM_PROPERTY ioctl to /dev/mshv, which issues HVCALL_GET_SYSTEM_PROPERTY on behalf of the VMM and returns the value of the requested property. To avoid leaking any sensitive data, only allow the properties that have been audited to be safe to expose. For now, only expose the SEV-SNP status and the maximum number of encrypted partitions on x86 (which is what a VMM needs to determine whether it can create SEV-SNP partitions).
--- drivers/hv/mshv_root.h | 1 + drivers/hv/mshv_root_hv_call.c | 29 ++++++++++++++++++++ drivers/hv/mshv_root_main.c | 50 ++++++++++++++++++++++++++++++++++ include/hyperv/hvhdk_mini.h | 1 + include/uapi/linux/mshv.h | 22 +++++++++++++++ 5 files changed, 103 insertions(+)
drivers/hv/mshv_root.h +1 -0
@@ -333,6 +333,7 @@ int hv_call_modify_spa_host_access(u64 partition_id, struct page **pages, u32 flags, u8 acquire);int hv_call_get_partition_property_ex (u64 partition_id,u64 property_code,u64 arg,void *property_value,size_t property_value_sz); +int hv_call_get_system_property (u32 property_id,u64 arg,u64 *value);#if IS_ENABLED (CONFIG_DEBUG_FS )int __init mshv_debugfs_init (void );
drivers/hv/mshv_root_hv_call.c +29 -0
@@ -680,6 +680,35 @@ int hv_call_get_partition_property_ex(u64 partition_id, u64 property_code,return 0 ; } +int hv_call_get_system_property (u32 property_id,u64 arg,u64 *value) +{ +struct hv_output_get_system_property *output; +struct hv_input_get_system_property *input; +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 = property_id; + input->as_uint64 = arg; + status =hv_do_hypercall (HVCALL_GET_SYSTEM_PROPERTY , input, output); + +if (!hv_result_success (status)) { +local_irq_restore (flags); +hv_status_debug (status,"\n" ); +return hv_result_to_errno (status); + } + + *value = output->as_uint64; +local_irq_restore (flags); + +return 0 ; +} +int hv_call_clear_virtual_interrupt (u64 partition_id) {
drivers/hv/mshv_root_main.c +50 -0
62 lines not on this page · raw message
include/hyperv/hvhdk_mini.h +1 -0
@@ -197,6 +197,7 @@ struct hv_input_get_system_property {struct hv_output_get_system_property {union { +u64 as_uint64;u32 scheduler_type;/* enum hv_scheduler_type */ #if IS_ENABLED (CONFIG_X86 )u64 hv_processor_feature_value;
include/uapi/linux/mshv.h +22 -0
@@ -88,8 +88,30 @@ struct mshv_create_partition_v2 {#endif } __packed; +/** +* struct mshv_system_property - arguments for MSHV_GET_SYSTEM_PROPERTY +* @property_id: Hypervisor system property to get (enum hv_system_property). +* @rsvd: MBZ. +* @arg: Property-specific argument, e.g. the processor feature to get +* (enum hv_dynamic_processor_feature_property) for +* HV_DYNAMIC_PROCESSOR_FEATURE_PROPERTY. MBZ if the property doesn't take +* an argument. +* @value: out: Value of the property, as reported by the hypervisor. +* +* Only the system properties that are safe to expose to the VMM can be +* queried, e.g. the SEV-SNP status on x86_64. -EINVAL is returned for any +* other property. +*/ +struct mshv_system_property { +__u32 property_id; +__u32 rsvd; +__u64 arg; +__u64 value; +}; +/* /dev/mshv */ #define MSHV_CREATE_PARTITION _IOW(MSHV_IOCTL, 0x00, struct mshv_create_partition) +#define MSHV_GET_SYSTEM_PROPERTY _IOWR(MSHV_IOCTL, 0x01, struct mshv_system_property)/* ************************
Signature · 1 line
2.56.1