From: Hamza Mahfooz <hamza@kernel.org>
To: linux-hyperv@vger.kernel.org
Cc: Haiyang Zhang <haiyangz@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
Michael Kelley <mhklinux@outlook.com>,
Muminul Islam <muislam@microsoft.com>,
Anatol Belski <anbelski@linux.microsoft.com>,
Will Wright <wwright@microsoft.com>, Chris Oo <cho@microsoft.com>,
Hamza Mahfooz <hamza@kernel.org>
Subject: [PATCH] mshv: add ioctl to get hypervisor system properties
Date: Wed, 2 Dec 2026 17:13:40 -0500 [thread overview]
Message-ID: <20261202221340.334560-1-hamza@kernel.org> (raw)
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 <hamza@kernel.org>
---
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
reply other threads:[~2026-12-02 22:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202221340.334560-1-hamza@kernel.org \
--to=hamza@kernel.org \
--cc=anbelski@linux.microsoft.com \
--cc=cho@microsoft.com \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=mhklinux@outlook.com \
--cc=muislam@microsoft.com \
--cc=wei.liu@kernel.org \
--cc=wwright@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.