From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796249628; b=EyrxwCjA+FK0gOpbCb5+lSlAv2HUZ1ddBGv5cGxfCRNlPdcJ/Y5fl7lY5nsG/jr524/0 uRKz5MErzI8bDHEN1cvFRO++XvCSOMbpONwgi4vOCv8cADjUdQLYTMlC8x+Toyl/dsisn M6jPwQjh0REKUKLmHtt11QHR1EqC8hmU/ohaoSKEtDuGudfSaWaTTV4Ty3kJjAciDsPjk 6HX6O9fYEKnbJbQ7Gwg3KVr28TBqm/lL1nbC0BwV5U4l1Z0SFKFPR6Hso2PyuDx/8H/10 c+Y2biT0VW+GViNQIsY1MLz9aPPMNhfz453r4emDxtG9lg9TxO/bTUx0yNfLj9YT8JA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796249628; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=YOkPCeUl9sao81LjWHYr2KFvmjytRVarqRZi4eizo6Q=; b=EmewZBw9Nsgv+/QVPavwSYtbvdAExvfiZF+rf7DW3Ovx/B6LaEA55lIPA3uX//UsFHZw 3GYJWlbOxr8OFbXM1THkTMeQyJyX8Iz4XoR0YIFwmPLIQWLxcu9QEyagGxfbbxMjAGP96 Y9PMlD6s1QuY3LX5G9sFLIJiJc3CvqlGRUlMvPAwsc8kgtqhfJ5ZPXYEUofE/Xg2cvE2B zpw3rXAmuEiRFJwGmnuoBOyGoQjsaI/Pm5QKS09gxcxPb+wPAlPhlxcTUiyoq6+XfQ6oY Z15macnFQp+TVhBiS+JbqmZza4AC+NSFnsInOpbURfTy0qHwu/uJCt60divwv79+vgg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AukBH2i1; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12CFE606A322 for ; Wed, 2 Dec 2026 22:13:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AukBH2i1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13FEC1F00896; Wed, 2 Dec 2026 22:13:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796249627; bh=YOkPCeUl9sao81LjWHYr2KFvmjytRVarqRZi4eizo6Q=; h=From:To:Cc:Subject:Date; b=AukBH2i1PYv46aW2C9UlJt16Yr/65DPf9SZJcLyvdM/U9yg5n5tb8qI+/Ikgh6YDp QVXrZe7VfPDVdHtyYTNSNc5NYvtT9j+J8xBaymj4qIX9TCJMGmfyy+pvxMuMb1ri92 t+9qCpJ4PY7pB2wp6yMiT/vSFJGWoy86eo84Qg1lKiKgWde9lS4gZTppze8v81ssK6 aPohiVZBRkq/mzqOQWOWukqedC9oB9ctTLEn6ue9XnluZu8y0ln8ehfundsjSBbgzQ FLRWv1p57rHDeUo0V7tryHJoJiQB3xobW0cBpXbzSxB8dOOpf+127Vkf9fP6ymjXSn odebP9ztCKU7Q== From: Hamza Mahfooz To: linux-hyperv@vger.kernel.org Cc: Haiyang Zhang , Wei Liu , Dexuan Cui , Michael Kelley , Muminul Islam , Anatol Belski , Will Wright , Chris Oo , Hamza Mahfooz Subject: [PATCH] mshv: add ioctl to get hypervisor system properties Date: Wed, 2 Dec 2026 17:13:40 -0500 Message-ID: <20261202221340.334560-1-hamza@kernel.org> X-Mailer: git-send-email 2.43.7 X-Mailing-List: linux-hyperv@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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). Signed-off-by: Hamza Mahfooz --- 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(+) diff --git a/drivers/hv/mshv_root.h b/drivers/hv/mshv_root.h index 1f086dcb7aa1..069717b38745 100644 --- a/drivers/hv/mshv_root.h +++ b/drivers/hv/mshv_root.h @@ -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); diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c index b8d199f95299..4eab4095a341 100644 --- a/drivers/hv/mshv_root_hv_call.c +++ b/drivers/hv/mshv_root_hv_call.c @@ -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) { diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index cc2cfce2aefd..db143463e6ea 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -2126,6 +2126,54 @@ mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev) return ret; } +/* + * Only allow the VMM to get system properties that are safe to expose to it. + * Some system properties reveal hypervisor internals, e.g. physical addresses, + * so carefully audit a property before adding it here. Also, the value of the + * property must fit in a u64. + */ +static bool mshv_system_property_allowed(u32 property_id, u64 arg) +{ + switch (property_id) { + case HV_DYNAMIC_PROCESSOR_FEATURE_PROPERTY: + /* Dynamic processor features are only defined on x86 */ + if (!IS_ENABLED(CONFIG_X86_64)) + break; + + switch (arg) { + case HV_X64_DYNAMIC_PROCESSOR_FEATURE_MAX_ENCRYPTED_PARTITIONS: + case HV_X64_DYNAMIC_PROCESSOR_FEATURE_SNP_STATUS: + return true; + } + break; + } + + return false; +} + +static long mshv_ioctl_get_system_property(void __user *user_args) +{ + struct mshv_system_property args; + int ret; + + if (copy_from_user(&args, user_args, sizeof(args))) + return -EFAULT; + + if (args.rsvd || + !mshv_system_property_allowed(args.property_id, args.arg)) + return -EINVAL; + + ret = hv_call_get_system_property(args.property_id, args.arg, + &args.value); + if (ret) + return ret; + + if (copy_to_user(user_args, &args, sizeof(args))) + return -EFAULT; + + return 0; +} + static long mshv_dev_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) { @@ -2135,6 +2183,8 @@ static long mshv_dev_ioctl(struct file *filp, unsigned int ioctl, case MSHV_CREATE_PARTITION: return mshv_ioctl_create_partition((void __user *)arg, misc->this_device); + case MSHV_GET_SYSTEM_PROPERTY: + return mshv_ioctl_get_system_property((void __user *)arg); case MSHV_ROOT_HVCALL: return mshv_ioctl_passthru_hvcall(NULL, false, (void __user *)arg); diff --git a/include/hyperv/hvhdk_mini.h b/include/hyperv/hvhdk_mini.h index 57b70efe60d4..8dfd68cdcb4f 100644 --- a/include/hyperv/hvhdk_mini.h +++ b/include/hyperv/hvhdk_mini.h @@ -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; diff --git a/include/uapi/linux/mshv.h b/include/uapi/linux/mshv.h index 32ff92b6342b..b91a406e2dce 100644 --- a/include/uapi/linux/mshv.h +++ b/include/uapi/linux/mshv.h @@ -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) /* ************************ -- 2.56.1