Skip to contentSkip to conversation

mshv: Extend create partition ioctl to support cpu features

PATCH Superseded Nuno Das Neves 2 participants 6 messages Nov 4, 2025 – Nov 6, 2025

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 mshv: Extend create partition ioctl to support cpu features

From: Muminul Islam <[email protected]>

The existing mshv create partition ioctl does not provide a way to specify which cpu features are enabled in the guest. Instead, it attempts to enable all features and those that are not supported are silently disabled by the hypervisor.

This was done to reduce unnecessary complexity and is sufficient for many cases. However, new scenarios require fine-grained control over these features.

Define a new mshv_create_partition_v2 structure which supports passing the disabled processor and xsave feature bits through to the create partition hypercall directly.

The kernel does not introspect the bits in these new fields as they are part of the hypervisor ABI. Require the caller to provide the number of cpu feature banks passed, to support extending the number of banks in future. Disable all banks that are not specified to ensure the behavior is predictable with newer hypervisors.

Introduce a new flag MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES which enables the new structure. If unset, the original mshv_create_partition struct is used, with the old behavior of enabling all features.

---
Changes in v3:
- Remove the new cpu features definitions in hvhdk.h, and retain the old behavior of enabling all features for the old struct. For the v2 struct, still disable unspecified feature banks, since that makes it robust to future extensions.
- Amend comments and commit message to reflect the above
- Fix unused variable on arm64 [kernel test robot]

Changes in v2:
- Fix exposure of CONFIG_X86_64 to uapi [kernel test robot]
- Fix compilation issue on arm64 [kernel test robot]

---
 drivers/hv/mshv_root_main.c | 94 ++++++++++++++++++++++++++++++-------
 include/uapi/linux/mshv.h   | 34 ++++++++++++++
 2 files changed, 110 insertions(+), 18 deletions(-)
drivers/hv/mshv_root_main.c +76 -18
index d542a0143bb8..814465a0912d 100644
@@ -1900,43 +1900,101 @@ add_partition(struct mshv_partition *partition)
 	return 0;
 }
 
-static long
-mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev)
+static_assert(MSHV_NUM_CPU_FEATURES_BANKS <=
+	      HV_PARTITION_PROCESSOR_FEATURES_BANKS);
+
+static long mshv_ioctl_process_pt_flags(void __user *user_arg, u64 *pt_flags,
+					struct hv_partition_creation_properties *cr_props,
+					union hv_partition_isolation_properties *isol_props)
 {
-	struct mshv_create_partition args;
-	u64 creation_flags;
-	struct hv_partition_creation_properties creation_properties = {};
-	union hv_partition_isolation_properties isolation_properties = {};
-	struct mshv_partition *partition;
-	struct file *file;
-	int fd;
-	long ret;
+	int i;
+	struct mshv_create_partition_v2 args;
+	union hv_partition_processor_features *disabled_procs;
+	union hv_partition_processor_xsave_features *disabled_xsave;
 
-	if (copy_from_user(&args, user_arg, sizeof(args)))
+	/* First, copy orig struct in case user is on previous versions */
+	if (copy_from_user(&args, user_arg,
+			   sizeof(struct mshv_create_partition)))
 		return -EFAULT;
 
 	if ((args.pt_flags & ~MSHV_PT_FLAGS_MASK) ||
 	    args.pt_isolation >= MSHV_PT_ISOLATION_COUNT)
 		return -EINVAL;
 
+	disabled_procs = &cr_props->disabled_processor_features;
+	disabled_xsave = &cr_props->disabled_processor_xsave_features;
+
+	/* Check if user provided newer struct with feature fields */
+	if (args.pt_flags & BIT(MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES)) {
+		if (copy_from_user(&args, user_arg, sizeof(args)))
+			return -EFAULT;
+
+		if (args.pt_num_cpu_fbanks > MSHV_NUM_CPU_FEATURES_BANKS ||
+		    mshv_field_nonzero(args, pt_rsvd) ||
+		    mshv_field_nonzero(args, pt_rsvd1))
+			return -EINVAL;
+
+
+		for (i = 0; i < args.pt_num_cpu_fbanks; i++)
+			disabled_procs->as_uint64[i] = args.pt_cpu_fbanks[i];
+
+		/* Disable any features left unspecified */
+		for (; i < HV_PARTITION_PROCESSOR_FEATURES_BANKS; i++)
+			disabled_procs->as_uint64[i] = -1;
+
+#if IS_ENABLED(CONFIG_X86_64)
+		disabled_xsave->as_uint64 = args.pt_disabled_xsave;
+#else
+		if (mshv_field_nonzero(args, pt_rsvd2))
+			return -EINVAL;
+
+		disabled_xsave->as_uint64 = -1;
+#endif
+	} else {
+		/* v1 behavior: try to enable everything */
+		for (i = 0; i < HV_PARTITION_PROCESSOR_FEATURES_BANKS; i++)
+			disabled_procs->as_uint64[i] = 0;
+
+		disabled_xsave->as_uint64 = 0;
+	}
+
 	/* Only support EXO partitions */
-	creation_flags = HV_PARTITION_CREATION_FLAG_EXO_PARTITION |
-			 HV_PARTITION_CREATION_FLAG_INTERCEPT_MESSAGE_PAGE_ENABLED;
+	*pt_flags = HV_PARTITION_CREATION_FLAG_EXO_PARTITION |
+		    HV_PARTITION_CREATION_FLAG_INTERCEPT_MESSAGE_PAGE_ENABLED;
 
 	if (args.pt_flags & BIT(MSHV_PT_BIT_LAPIC))
-		creation_flags |= HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED;
+		*pt_flags |= HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED;
 	if (args.pt_flags & BIT(MSHV_PT_BIT_X2APIC))
-		creation_flags |= HV_PARTITION_CREATION_FLAG_X2APIC_CAPABLE;
+		*pt_flags |= HV_PARTITION_CREATION_FLAG_X2APIC_CAPABLE;
 	if (args.pt_flags & BIT(MSHV_PT_BIT_GPA_SUPER_PAGES))
-		creation_flags |= HV_PARTITION_CREATION_FLAG_GPA_SUPER_PAGES_ENABLED;
+		*pt_flags |= HV_PARTITION_CREATION_FLAG_GPA_SUPER_PAGES_ENABLED;
 
 	switch (args.pt_isolation) {
 	case MSHV_PT_ISOLATION_NONE:
-		isolation_properties.isolation_type =
-			HV_PARTITION_ISOLATION_TYPE_NONE;
+		isol_props->isolation_type = HV_PARTITION_ISOLATION_TYPE_NONE;
 		break;
 	}
 
+	return 0;
+}
+
+static long
+mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev)
+{
+	u64 creation_flags;
+	struct hv_partition_creation_properties creation_properties = {};
+	union hv_partition_isolation_properties isolation_properties = {};
+	struct mshv_partition *partition;
+	struct file *file;
+	int fd;
+	long ret;
+
+	ret = mshv_ioctl_process_pt_flags(user_arg, &creation_flags,
+					  &creation_properties,
+					  &isolation_properties);
+	if (ret)
+		return ret;
+
 	partition = kzalloc(sizeof(*partition), GFP_KERNEL);
 	if (!partition)
 		return -ENOMEM;
include/uapi/linux/mshv.h +34 -0
index 876bfe4e4227..9091946cba23 100644
@@ -26,6 +26,7 @@ enum {
 	MSHV_PT_BIT_LAPIC,
 	MSHV_PT_BIT_X2APIC,
 	MSHV_PT_BIT_GPA_SUPER_PAGES,
+	MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES,
 	MSHV_PT_BIT_COUNT,
 };
 
@@ -41,6 +42,8 @@ enum {
  * @pt_flags: Bitmask of 1 << MSHV_PT_BIT_*
  * @pt_isolation: MSHV_PT_ISOLATION_*
  *
+ * This is the initial/v0 version for backward compatibility.
+ *
  * Returns a file descriptor to act as a handle to a guest partition.
  * At this point the partition is not yet initialized in the hypervisor.
  * Some operations must be done with the partition in this state, e.g. setting
@@ -52,6 +55,37 @@ struct mshv_create_partition {
 	__u64 pt_isolation;
 };
 
+#define MSHV_NUM_CPU_FEATURES_BANKS 2
+
+/**
+ * struct mshv_create_partition_v2
+ *
+ * This is extended version of the above initial MSHV_CREATE_PARTITION
+ * ioctl and allows for following additional parameters:
+ *
+ * @pt_num_cpu_fbanks: number of processor feature banks being provided.
+ *                     This must not exceed MSHV_NUM_CPU_FEATURES_BANKS.
+ *                     If set to less than the number of available banks,
+ *                     additional banks will be set to -1 (disabled).
+ * @pt_cpu_fbanks: disabled processor feature banks array.
+ * @pt_disabled_xsave: disabled xsave feature bits.
+ *
+ * Returns : same as above original mshv_create_partition
+ */
+struct mshv_create_partition_v2 {
+	__u64 pt_flags;
+	__u64 pt_isolation;
+	__u16 pt_num_cpu_fbanks;
+	__u8  pt_rsvd[6];		/* MBZ */
+	__u64 pt_cpu_fbanks[MSHV_NUM_CPU_FEATURES_BANKS];
+	__u64 pt_rsvd1[2];		/* MBZ */
+#if defined(__x86_64__)
+	__u64 pt_disabled_xsave;
+#else
+	__u64 pt_rsvd2;			/* MBZ */
+#endif
+} __packed;
+
 /* /dev/mshv */
 #define MSHV_CREATE_PARTITION	_IOW(MSHV_IOCTL, 0x00, struct mshv_create_partition)
 
Signature · 1 line
2.34.1
#1 lore raw

From: Nuno Das Neves <[email protected]> Sent: Tuesday, November 4, 2025 1:47 PM

Quoted 83 lines

From: Muminul Islam <[email protected]>

The existing mshv create partition ioctl does not provide a way to specify which cpu features are enabled in the guest. Instead, it attempts to enable all features and those that are not supported are silently disabled by the hypervisor.

This was done to reduce unnecessary complexity and is sufficient for many cases. However, new scenarios require fine-grained control over these features.

Define a new mshv_create_partition_v2 structure which supports passing the disabled processor and xsave feature bits through to the create partition hypercall directly.

The kernel does not introspect the bits in these new fields as they are part of the hypervisor ABI. Require the caller to provide the number of cpu feature banks passed, to support extending the number of banks in future. Disable all banks that are not specified to ensure the behavior is predictable with newer hypervisors.

Introduce a new flag MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES which enables the new structure. If unset, the original mshv_create_partition struct is used, with the old behavior of enabling all features.

---
Changes in v3:
- Remove the new cpu features definitions in hvhdk.h, and retain the old behavior of enabling all features for the old struct. For the v2 struct, still disable unspecified feature banks, since that makes it robust to future extensions.
- Amend comments and commit message to reflect the above
- Fix unused variable on arm64 [kernel test robot]

Changes in v2:
- Fix exposure of CONFIG_X86_64 to uapi [kernel test robot]
- Fix compilation issue on arm64 [kernel test robot]

---
 drivers/hv/mshv_root_main.c | 94 ++++++++++++++++++++++++++++++-------
 include/uapi/linux/mshv.h   | 34 ++++++++++++++
 2 files changed, 110 insertions(+), 18 deletions(-)
drivers/hv/mshv_root_main.c +13 -11
index d542a0143bb8..814465a0912d 100644
@@ -1900,43 +1900,101 @@ add_partition(struct mshv_partition *partition)
 	return 0;
 }
 
-static long
-mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev)
+static_assert(MSHV_NUM_CPU_FEATURES_BANKS <=
+	      HV_PARTITION_PROCESSOR_FEATURES_BANKS);
+
+static long mshv_ioctl_process_pt_flags(void __user *user_arg, u64 *pt_flags,
+					struct hv_partition_creation_properties *cr_props,
+					union hv_partition_isolation_properties *isol_props)
 {
-	struct mshv_create_partition args;
-	u64 creation_flags;
-	struct hv_partition_creation_properties creation_properties = {};
-	union hv_partition_isolation_properties isolation_properties = {};
-	struct mshv_partition *partition;
-	struct file *file;
-	int fd;
-	long ret;
+	int i;
+	struct mshv_create_partition_v2 args;
+	union hv_partition_processor_features *disabled_procs;
+	union hv_partition_processor_xsave_features *disabled_xsave;
 
-	if (copy_from_user(&args, user_arg, sizeof(args)))
+	/* First, copy orig struct in case user is on previous versions */
+	if (copy_from_user(&args, user_arg,
+			   sizeof(struct mshv_create_partition)))
 		return -EFAULT;

drivers/hv/mshv_root_main.c add_partition(struct mshv_partition *partition) · line 1928

Quoted 10 lines
drivers/hv/mshv_root_main.c +5 -0
 
 	if ((args.pt_flags & ~MSHV_PT_FLAGS_MASK) ||
 	    args.pt_isolation >= MSHV_PT_ISOLATION_COUNT)
 		return -EINVAL;
 
+	disabled_procs = &cr_props->disabled_processor_features;
+	disabled_xsave = &cr_props->disabled_processor_xsave_features;
+
+	/* Check if user provided newer struct with feature fields */
+	if (args.pt_flags & BIT(MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES)) {

Should probably be "BIT_ULL" instead of "BIT" since args.pt_flags is a long long field, though it really doesn't matter as long as the number of flags is <= 32.

Quoted 5 lines
drivers/hv/mshv_root_main.c +5 -0
+		if (copy_from_user(&args, user_arg, sizeof(args)))
+			return -EFAULT;
+
+		if (args.pt_num_cpu_fbanks > MSHV_NUM_CPU_FEATURES_BANKS ||
+		    mshv_field_nonzero(args, pt_rsvd) ||

drivers/hv/mshv_root_main.c add_partition(struct mshv_partition *partition) · line 1943

Quoted 10 lines
drivers/hv/mshv_root_main.c +10 -0
+		    mshv_field_nonzero(args, pt_rsvd1))
+			return -EINVAL;
+
+
+		for (i = 0; i < args.pt_num_cpu_fbanks; i++)
+			disabled_procs->as_uint64[i] = args.pt_cpu_fbanks[i];
+
+		/* Disable any features left unspecified */
+		for (; i < HV_PARTITION_PROCESSOR_FEATURES_BANKS; i++)
+			disabled_procs->as_uint64[i] = -1;

I'm trying to convince myself that disabling unspecified features is the right thing to do. In the current hypervisor scenario with 2 banks, if the VMM caller specifies only one bank of disable flags, then all the features in the 2nd bank are disabled. That's certainly the reverse from the current code which always enables all features, and from the hypervisor itself which in the hypercall ABI defines the flags as "disable" flags rather than "enable" flags.

Then in a scenario where a new version of the hypervisor shows up with support for 3 banks, the old VMM code that only knows about 2 banks will cause all features in that 3rd bank to be disabled. Again, that's the reverse of the current code.

I guess it depends on how the hypervisor defines any such new features. Are they typically defined to be benign if they are enabled by default? Or is the polarity the opposite, where the VMM must know about new features before they are enabled? The hypercall interface seems to imply the former but maybe I'm reading too much into it.

A code comment about the thinking here would be useful for future readers.

drivers/hv/mshv_root_main.c add_partition(struct mshv_partition *partition) · line 1951

Quoted 8 lines
drivers/hv/mshv_root_main.c +8 -0
+
+#if IS_ENABLED(CONFIG_X86_64)
+		disabled_xsave->as_uint64 = args.pt_disabled_xsave;
+#else
+		if (mshv_field_nonzero(args, pt_rsvd2))
+			return -EINVAL;
+
+		disabled_xsave->as_uint64 = -1;

Does the arm64 version of the hypercall do anything with this field? Or does it just ignore it? I would be more inclined to set ignored fields to zero unless there's an identifiable reason otherwise. (especially since the VMM is required to pass in zero on arm64).

Quoted 94 lines
drivers/hv/mshv_root_main.c +35 -6
+#endif
+	} else {
+		/* v1 behavior: try to enable everything */
+		for (i = 0; i < HV_PARTITION_PROCESSOR_FEATURES_BANKS; i++)
+			disabled_procs->as_uint64[i] = 0;
+
+		disabled_xsave->as_uint64 = 0;
+	}
+
 	/* Only support EXO partitions */
-	creation_flags = HV_PARTITION_CREATION_FLAG_EXO_PARTITION  HV_PARTITION_CREATION_FLAG_INTERCEPT_MESSAGE_PAGE_ENABLED;
+	*pt_flags = HV_PARTITION_CREATION_FLAG_EXO_PARTITION |
+		 HV_PARTITION_CREATION_FLAG_INTERCEPT_MESSAGE_PAGE_ENABLED;
 
 	if (args.pt_flags & BIT(MSHV_PT_BIT_LAPIC))
-		creation_flags |= HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED;
+		*pt_flags |= HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED;
 	if (args.pt_flags & BIT(MSHV_PT_BIT_X2APIC))
-		creation_flags |= HV_PARTITION_CREATION_FLAG_X2APIC_CAPABLE;
+		*pt_flags |= HV_PARTITION_CREATION_FLAG_X2APIC_CAPABLE;
 	if (args.pt_flags & BIT(MSHV_PT_BIT_GPA_SUPER_PAGES))
-		creation_flags |= HV_PARTITION_CREATION_FLAG_GPA_SUPER_PAGES_ENABLED;
+		*pt_flags |= HV_PARTITION_CREATION_FLAG_GPA_SUPER_PAGES_ENABLED;
 
 	switch (args.pt_isolation) {
 	case MSHV_PT_ISOLATION_NONE:
-		isolation_properties.isolation_type =
-			HV_PARTITION_ISOLATION_TYPE_NONE;
+		isol_props->isolation_type = HV_PARTITION_ISOLATION_TYPE_NONE;
 		break;
 	}
 
+	return 0;
+}
+
+static long
+mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev)
+{
+	u64 creation_flags;
+	struct hv_partition_creation_properties creation_properties = {};
+	union hv_partition_isolation_properties isolation_properties = {};
+	struct mshv_partition *partition;
+	struct file *file;
+	int fd;
+	long ret;
+
+	ret = mshv_ioctl_process_pt_flags(user_arg, &creation_flags,
+					  &creation_properties,
+					  &isolation_properties);
+	if (ret)
+		return ret;
+
 	partition = kzalloc(sizeof(*partition), GFP_KERNEL);
 	if (!partition)
 		return -ENOMEM;
include/uapi/linux/mshv.h +17 -0
index 876bfe4e4227..9091946cba23 100644
@@ -26,6 +26,7 @@ enum {
 	MSHV_PT_BIT_LAPIC,
 	MSHV_PT_BIT_X2APIC,
 	MSHV_PT_BIT_GPA_SUPER_PAGES,
+	MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES,
 	MSHV_PT_BIT_COUNT,
 };
 
@@ -41,6 +42,8 @@ enum {
  * @pt_flags: Bitmask of 1 << MSHV_PT_BIT_*
  * @pt_isolation: MSHV_PT_ISOLATION_*
  *
+ * This is the initial/v0 version for backward compatibility.
+ *
  * Returns a file descriptor to act as a handle to a guest partition.
  * At this point the partition is not yet initialized in the hypervisor.
  * Some operations must be done with the partition in this state, e.g. setting
@@ -52,6 +55,37 @@ struct mshv_create_partition {
 	__u64 pt_isolation;
 };
 
+#define MSHV_NUM_CPU_FEATURES_BANKS 2
+
+/**
+ * struct mshv_create_partition_v2
+ *
+ * This is extended version of the above initial MSHV_CREATE_PARTITION
+ * ioctl and allows for following additional parameters:
+ *
+ * @pt_num_cpu_fbanks: number of processor feature banks being provided.
+ *                     This must not exceed MSHV_NUM_CPU_FEATURES_BANKS.
+ *                     If set to less than the number of available banks,
+ *                     additional banks will be set to -1 (disabled).
+ * @pt_cpu_fbanks: disabled processor feature banks array.
+ * @pt_disabled_xsave: disabled xsave feature bits.

include/uapi/linux/mshv.h struct mshv_create_partition { · line 81

Quoted 10 lines
include/uapi/linux/mshv.h +10 -0
+ *
+ * Returns : same as above original mshv_create_partition
+ */
+struct mshv_create_partition_v2 {
+	__u64 pt_flags;
+	__u64 pt_isolation;
+	__u16 pt_num_cpu_fbanks;
+	__u8  pt_rsvd[6];		/* MBZ */
+	__u64 pt_cpu_fbanks[MSHV_NUM_CPU_FEATURES_BANKS];
+	__u64 pt_rsvd1[2];		/* MBZ */

I presume this is for future expansion of the number of banks? And that the choice of 2 additional banks is somewhat arbitrary?

Michael

Quoted 13 lines
include/uapi/linux/mshv.h +7 -1
+#if defined(__x86_64__)
+	__u64 pt_disabled_xsave;
+#else
+	__u64 pt_rsvd2;			/* MBZ */
+#endif
+} __packed;
+
 /* /dev/mshv */
 #define MSHV_CREATE_PARTITION	_IOW(MSHV_IOCTL, 0x00, struct
 mshv_create_partition)
 
--

2.34.1

#2 lore raw
Quoted 89 lines · Michael Kelley

From: Nuno Das Neves <[email protected]> Sent: Tuesday, November 4, 2025 1:47 PM

Quoted 88 lines

From: Muminul Islam <[email protected]>

The existing mshv create partition ioctl does not provide a way to specify which cpu features are enabled in the guest. Instead, it attempts to enable all features and those that are not supported are silently disabled by the hypervisor.

This was done to reduce unnecessary complexity and is sufficient for many cases. However, new scenarios require fine-grained control over these features.

Define a new mshv_create_partition_v2 structure which supports passing the disabled processor and xsave feature bits through to the create partition hypercall directly.

The kernel does not introspect the bits in these new fields as they are part of the hypervisor ABI. Require the caller to provide the number of cpu feature banks passed, to support extending the number of banks in future. Disable all banks that are not specified to ensure the behavior is predictable with newer hypervisors.

Introduce a new flag MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES which enables the new structure. If unset, the original mshv_create_partition struct is used, with the old behavior of enabling all features.

---
Changes in v3:
- Remove the new cpu features definitions in hvhdk.h, and retain the old behavior of enabling all features for the old struct. For the v2 struct, still disable unspecified feature banks, since that makes it robust to future extensions.
- Amend comments and commit message to reflect the above
- Fix unused variable on arm64 [kernel test robot]

Changes in v2:
- Fix exposure of CONFIG_X86_64 to uapi [kernel test robot]
- Fix compilation issue on arm64 [kernel test robot]

---
 drivers/hv/mshv_root_main.c | 94 ++++++++++++++++++++++++++++++-------
 include/uapi/linux/mshv.h   | 34 ++++++++++++++
 2 files changed, 110 insertions(+), 18 deletions(-)
drivers/hv/mshv_root_main.c +13 -11
index d542a0143bb8..814465a0912d 100644
@@ -1900,43 +1900,101 @@ add_partition(struct mshv_partition *partition)
 	return 0;
 }
 
-static long
-mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev)
+static_assert(MSHV_NUM_CPU_FEATURES_BANKS <=
+	      HV_PARTITION_PROCESSOR_FEATURES_BANKS);
+
+static long mshv_ioctl_process_pt_flags(void __user *user_arg, u64 *pt_flags,
+					struct hv_partition_creation_properties *cr_props,
+					union hv_partition_isolation_properties *isol_props)
 {
-	struct mshv_create_partition args;
-	u64 creation_flags;
-	struct hv_partition_creation_properties creation_properties = {};
-	union hv_partition_isolation_properties isolation_properties = {};
-	struct mshv_partition *partition;
-	struct file *file;
-	int fd;
-	long ret;
+	int i;
+	struct mshv_create_partition_v2 args;
+	union hv_partition_processor_features *disabled_procs;
+	union hv_partition_processor_xsave_features *disabled_xsave;
 
-	if (copy_from_user(&args, user_arg, sizeof(args)))
+	/* First, copy orig struct in case user is on previous versions */
+	if (copy_from_user(&args, user_arg,
+			   sizeof(struct mshv_create_partition)))
 		return -EFAULT;
 
 	if ((args.pt_flags & ~MSHV_PT_FLAGS_MASK) ||
 	    args.pt_isolation >= MSHV_PT_ISOLATION_COUNT)
 		return -EINVAL;
 
Quoted 9 lines

drivers/hv/mshv_root_main.c add_partition(struct mshv_partition *partition) · line 1928

Quoted 5 lines
drivers/hv/mshv_root_main.c +5 -0
+	disabled_procs = &cr_props->disabled_processor_features;
+	disabled_xsave = &cr_props->disabled_processor_xsave_features;
+
+	/* Check if user provided newer struct with feature fields */
+	if (args.pt_flags & BIT(MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES)) {

Should probably be "BIT_ULL" instead of "BIT" since args.pt_flags is a long long field, though it really doesn't matter as long as the number of flags is <= 32.

Noted, thanks

Quoted 28 lines
Quoted 5 lines
drivers/hv/mshv_root_main.c +5 -0
+		if (copy_from_user(&args, user_arg, sizeof(args)))
+			return -EFAULT;
+
+		if (args.pt_num_cpu_fbanks > MSHV_NUM_CPU_FEATURES_BANKS ||
+		    mshv_field_nonzero(args, pt_rsvd) ||

drivers/hv/mshv_root_main.c add_partition(struct mshv_partition *partition) · line 1943

Quoted 10 lines
drivers/hv/mshv_root_main.c +10 -0
+		    mshv_field_nonzero(args, pt_rsvd1))
+			return -EINVAL;
+
+
+		for (i = 0; i < args.pt_num_cpu_fbanks; i++)
+			disabled_procs->as_uint64[i] = args.pt_cpu_fbanks[i];
+
+		/* Disable any features left unspecified */
+		for (; i < HV_PARTITION_PROCESSOR_FEATURES_BANKS; i++)
+			disabled_procs->as_uint64[i] = -1;

I'm trying to convince myself that disabling unspecified features is the right thing to do. In the current hypervisor scenario with 2 banks, if the VMM caller specifies only one bank of disable flags, then all the features in the 2nd bank are disabled. That's certainly the reverse from the current code which always enables all features, and from the hypervisor itself which in the hypercall ABI defines the flags as "disable" flags rather than "enable" flags.

Then in a scenario where a new version of the hypervisor shows up with support for 3 banks, the old VMM code that only knows about 2 banks will cause all features in that 3rd bank to be disabled. Again, that's the reverse of the current code.

Quoted 6 lines

I guess it depends on how the hypervisor defines any such new features. Are they typically defined to be benign if they are enabled by default? Or is the polarity the opposite, where the VMM must know about new features before they are enabled? The hypercall interface seems to imply the former but maybe I'm reading too much into it.

The intent is to provide an interface which allows the VMM to control exactly which features are enabled/disabled. E.g. for live migration of a VM, if the target machine has more features available and they are enabled inadvertently, the state may not be restored properly (particularly an issue for xsave).

So to me it makes sense to disable anything unspecified. In general, enabling features by default doesn't cause problems, it's only for specific scenarios like the above. I suppose that's why it's a "disable" mask, though I can't say I fully understand the reasoning...

Quoted 2 lines

A code comment about the thinking here would be useful for future readers.

Noted. I can repeat the reasoning from the commit message if that is sufficient:
"
Disable all banks that are not specified to ensure
the behavior is predictable with newer hypervisors.
"

Quoted 5 lines
Quoted 5 lines
drivers/hv/mshv_root_main.c +5 -0
+
+#if IS_ENABLED(CONFIG_X86_64)
+		disabled_xsave->as_uint64 = args.pt_disabled_xsave;
+#else
+		if (mshv_field_nonzero(args, pt_rsvd2))
Quoted 9 lines

drivers/hv/mshv_root_main.c add_partition(struct mshv_partition *partition) · line 1951

Quoted 3 lines
drivers/hv/mshv_root_main.c +3 -0
+			return -EINVAL;
+
+		disabled_xsave->as_uint64 = -1;

Does the arm64 version of the hypercall do anything with this field? Or does it just ignore it? I would be more inclined to set ignored fields to zero unless there's an identifiable reason otherwise. (especially since the VMM is required to pass in zero on arm64).

Good point. Checking the code, it seems to be completely ignored on arm64. I will remove this line.

Quoted 99 lines
Quoted 99 lines
drivers/hv/mshv_root_main.c +35 -6
+#endif
+	} else {
+		/* v1 behavior: try to enable everything */
+		for (i = 0; i < HV_PARTITION_PROCESSOR_FEATURES_BANKS; i++)
+			disabled_procs->as_uint64[i] = 0;
+
+		disabled_xsave->as_uint64 = 0;
+	}
+
 	/* Only support EXO partitions */
-	creation_flags = HV_PARTITION_CREATION_FLAG_EXO_PARTITION  HV_PARTITION_CREATION_FLAG_INTERCEPT_MESSAGE_PAGE_ENABLED;
+	*pt_flags = HV_PARTITION_CREATION_FLAG_EXO_PARTITION |
+		 HV_PARTITION_CREATION_FLAG_INTERCEPT_MESSAGE_PAGE_ENABLED;
 
 	if (args.pt_flags & BIT(MSHV_PT_BIT_LAPIC))
-		creation_flags |= HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED;
+		*pt_flags |= HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED;
 	if (args.pt_flags & BIT(MSHV_PT_BIT_X2APIC))
-		creation_flags |= HV_PARTITION_CREATION_FLAG_X2APIC_CAPABLE;
+		*pt_flags |= HV_PARTITION_CREATION_FLAG_X2APIC_CAPABLE;
 	if (args.pt_flags & BIT(MSHV_PT_BIT_GPA_SUPER_PAGES))
-		creation_flags |= HV_PARTITION_CREATION_FLAG_GPA_SUPER_PAGES_ENABLED;
+		*pt_flags |= HV_PARTITION_CREATION_FLAG_GPA_SUPER_PAGES_ENABLED;
 
 	switch (args.pt_isolation) {
 	case MSHV_PT_ISOLATION_NONE:
-		isolation_properties.isolation_type =
-			HV_PARTITION_ISOLATION_TYPE_NONE;
+		isol_props->isolation_type = HV_PARTITION_ISOLATION_TYPE_NONE;
 		break;
 	}
 
+	return 0;
+}
+
+static long
+mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev)
+{
+	u64 creation_flags;
+	struct hv_partition_creation_properties creation_properties = {};
+	union hv_partition_isolation_properties isolation_properties = {};
+	struct mshv_partition *partition;
+	struct file *file;
+	int fd;
+	long ret;
+
+	ret = mshv_ioctl_process_pt_flags(user_arg, &creation_flags,
+					  &creation_properties,
+					  &isolation_properties);
+	if (ret)
+		return ret;
+
 	partition = kzalloc(sizeof(*partition), GFP_KERNEL);
 	if (!partition)
 		return -ENOMEM;
include/uapi/linux/mshv.h +22 -0
index 876bfe4e4227..9091946cba23 100644
@@ -26,6 +26,7 @@ enum {
 	MSHV_PT_BIT_LAPIC,
 	MSHV_PT_BIT_X2APIC,
 	MSHV_PT_BIT_GPA_SUPER_PAGES,
+	MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES,
 	MSHV_PT_BIT_COUNT,
 };
 
@@ -41,6 +42,8 @@ enum {
  * @pt_flags: Bitmask of 1 << MSHV_PT_BIT_*
  * @pt_isolation: MSHV_PT_ISOLATION_*
  *
+ * This is the initial/v0 version for backward compatibility.
+ *
  * Returns a file descriptor to act as a handle to a guest partition.
  * At this point the partition is not yet initialized in the hypervisor.
  * Some operations must be done with the partition in this state, e.g. setting
@@ -52,6 +55,37 @@ struct mshv_create_partition {
 	__u64 pt_isolation;
 };
 
+#define MSHV_NUM_CPU_FEATURES_BANKS 2
+
+/**
+ * struct mshv_create_partition_v2
+ *
+ * This is extended version of the above initial MSHV_CREATE_PARTITION
+ * ioctl and allows for following additional parameters:
+ *
+ * @pt_num_cpu_fbanks: number of processor feature banks being provided.
+ *                     This must not exceed MSHV_NUM_CPU_FEATURES_BANKS.
+ *                     If set to less than the number of available banks,
+ *                     additional banks will be set to -1 (disabled).
+ * @pt_cpu_fbanks: disabled processor feature banks array.
+ * @pt_disabled_xsave: disabled xsave feature bits.
+ *
+ * Returns : same as above original mshv_create_partition
+ */
+struct mshv_create_partition_v2 {
+	__u64 pt_flags;
Quoted 9 lines

include/uapi/linux/mshv.h struct mshv_create_partition { · line 81

Quoted 5 lines
include/uapi/linux/mshv.h +5 -0
+	__u64 pt_isolation;
+	__u16 pt_num_cpu_fbanks;
+	__u8  pt_rsvd[6];		/* MBZ */
+	__u64 pt_cpu_fbanks[MSHV_NUM_CPU_FEATURES_BANKS];
+	__u64 pt_rsvd1[2];		/* MBZ */

I presume this is for future expansion of the number of banks? And that the choice of 2 additional banks is somewhat arbitrary?

A 3rd bank is sure to be added in the near future. At this rate it seems likely a 4th will eventually be needed, though it's hard to say for sure.

Nuno

Quoted 15 lines

Michael

Quoted 13 lines
include/uapi/linux/mshv.h +7 -1
+#if defined(__x86_64__)
+	__u64 pt_disabled_xsave;
+#else
+	__u64 pt_rsvd2;			/* MBZ */
+#endif
+} __packed;
+
 /* /dev/mshv */
 #define MSHV_CREATE_PARTITION	_IOW(MSHV_IOCTL, 0x00, struct
 mshv_create_partition)
 
--

2.34.1

#3 lore raw

From: Nuno Das Neves <[email protected]> Sent: Wednesday, November 5, 2025 11:10 AM

Quoted 146 lines · Michael Kelley
Quoted 89 lines

From: Nuno Das Neves <[email protected]> Sent: Tuesday, November 4, 2025 1:47 PM

Quoted 88 lines

From: Muminul Islam <[email protected]>

The existing mshv create partition ioctl does not provide a way to specify which cpu features are enabled in the guest. Instead, it attempts to enable all features and those that are not supported are silently disabled by the hypervisor.

This was done to reduce unnecessary complexity and is sufficient for many cases. However, new scenarios require fine-grained control over these features.

Define a new mshv_create_partition_v2 structure which supports passing the disabled processor and xsave feature bits through to the create partition hypercall directly.

The kernel does not introspect the bits in these new fields as they are part of the hypervisor ABI. Require the caller to provide the number of cpu feature banks passed, to support extending the number of banks in future. Disable all banks that are not specified to ensure the behavior is predictable with newer hypervisors.

Introduce a new flag MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES which enables the new structure. If unset, the original mshv_create_partition struct is used, with the old behavior of enabling all features.

---
Changes in v3:
- Remove the new cpu features definitions in hvhdk.h, and retain the old behavior of enabling all features for the old struct. For the v2 struct, still disable unspecified feature banks, since that makes it robust to future extensions.
- Amend comments and commit message to reflect the above
- Fix unused variable on arm64 [kernel test robot]

Changes in v2:
- Fix exposure of CONFIG_X86_64 to uapi [kernel test robot]
- Fix compilation issue on arm64 [kernel test robot]

---
 drivers/hv/mshv_root_main.c | 94 ++++++++++++++++++++++++++++++-------
 include/uapi/linux/mshv.h   | 34 ++++++++++++++
 2 files changed, 110 insertions(+), 18 deletions(-)
drivers/hv/mshv_root_main.c +13 -11
index d542a0143bb8..814465a0912d 100644
@@ -1900,43 +1900,101 @@ add_partition(struct mshv_partition *partition)
 	return 0;
 }
 
-static long
-mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev)
+static_assert(MSHV_NUM_CPU_FEATURES_BANKS <=
+	      HV_PARTITION_PROCESSOR_FEATURES_BANKS);
+
+static long mshv_ioctl_process_pt_flags(void __user *user_arg, u64 *pt_flags,
+					struct hv_partition_creation_properties *cr_props,
+					union hv_partition_isolation_properties *isol_props)
 {
-	struct mshv_create_partition args;
-	u64 creation_flags;
-	struct hv_partition_creation_properties creation_properties = {};
-	union hv_partition_isolation_properties isolation_properties = {};
-	struct mshv_partition *partition;
-	struct file *file;
-	int fd;
-	long ret;
+	int i;
+	struct mshv_create_partition_v2 args;
+	union hv_partition_processor_features *disabled_procs;
+	union hv_partition_processor_xsave_features *disabled_xsave;
 
-	if (copy_from_user(&args, user_arg, sizeof(args)))
+	/* First, copy orig struct in case user is on previous versions */
+	if (copy_from_user(&args, user_arg,
+			   sizeof(struct mshv_create_partition)))
 		return -EFAULT;
 
 	if ((args.pt_flags & ~MSHV_PT_FLAGS_MASK) ||
 	    args.pt_isolation >= MSHV_PT_ISOLATION_COUNT)
 		return -EINVAL;
 
Quoted 9 lines

drivers/hv/mshv_root_main.c add_partition(struct mshv_partition *partition) · line 1928

Quoted 5 lines
drivers/hv/mshv_root_main.c +5 -0
+	disabled_procs = &cr_props->disabled_processor_features;
+	disabled_xsave = &cr_props->disabled_processor_xsave_features;
+
+	/* Check if user provided newer struct with feature fields */
+	if (args.pt_flags & BIT(MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES)) {

Should probably be "BIT_ULL" instead of "BIT" since args.pt_flags is a long long field, though it really doesn't matter as long as the number of flags is <= 32.

Noted, thanks

Quoted 28 lines
Quoted 5 lines
drivers/hv/mshv_root_main.c +5 -0
+		if (copy_from_user(&args, user_arg, sizeof(args)))
+			return -EFAULT;
+
+		if (args.pt_num_cpu_fbanks > MSHV_NUM_CPU_FEATURES_BANKS ||
+		    mshv_field_nonzero(args, pt_rsvd) ||

drivers/hv/mshv_root_main.c add_partition(struct mshv_partition *partition) · line 1943

Quoted 10 lines
drivers/hv/mshv_root_main.c +10 -0
+		    mshv_field_nonzero(args, pt_rsvd1))
+			return -EINVAL;
+
+
+		for (i = 0; i < args.pt_num_cpu_fbanks; i++)
+			disabled_procs->as_uint64[i] = args.pt_cpu_fbanks[i];
+
+		/* Disable any features left unspecified */
+		for (; i < HV_PARTITION_PROCESSOR_FEATURES_BANKS; i++)
+			disabled_procs->as_uint64[i] = -1;

I'm trying to convince myself that disabling unspecified features is the right thing to do. In the current hypervisor scenario with 2 banks, if the VMM caller specifies only one bank of disable flags, then all the features in the 2nd bank are disabled. That's certainly the reverse from the current code which always enables all features, and from the hypervisor itself which in the hypercall ABI defines the flags as "disable" flags rather than "enable" flags.

Then in a scenario where a new version of the hypervisor shows up with support for 3 banks, the old VMM code that only knows about 2 banks will cause all features in that 3rd bank to be disabled. Again, that's the reverse of the current code.

Quoted 6 lines

I guess it depends on how the hypervisor defines any such new features. Are they typically defined to be benign if they are enabled by default? Or is the polarity the opposite, where the VMM must know about new features before they are enabled? The hypercall interface seems to imply the former but maybe I'm reading too much into it.

The intent is to provide an interface which allows the VMM to control exactly which features are enabled/disabled. E.g. for live migration of a VM, if the target machine has more features available and they are enabled inadvertently, the state may not be restored properly (particularly an issue for xsave).

So to me it makes sense to disable anything unspecified. In general, enabling features by default doesn't cause problems, it's only for specific scenarios like the above. I suppose that's why it's a "disable" mask, though I can't say I fully understand the reasoning...

Quoted 8 lines
Quoted 2 lines

A code comment about the thinking here would be useful for future readers.

Noted. I can repeat the reasoning from the commit message if that is sufficient:
"
Disable all banks that are not specified to ensure
the behavior is predictable with newer hypervisors.
"

Before deciding on the wording of the comment, one more thought occurred to me. union hv_partition_processor_features is currently two 64-bit banks. Bank 0 currently has 63 features plus 1 reserved bit. Bank 1 currently has 22 features, and 42 reserved bits. A new version of the hypervisor could use one or more of those 42 reserved bits for new features.

If a VMM is running on a newer hypervisor version that implements features the VMM is unaware of, the intent is that those features should be disabled by default. So is the expectation that when a VMM provides Bank 0 and Bank 1 values, it should set all the reserved bits to 1? (currently the single bit in Bank 0 and the 42 bits in Bank 1) My point is that the default disabling of new features can't be handled entirely by the kernel implementation of the ioctl based on the bank count passed in the argument to the ioctl. The VMM must cooperate as well. And such splitting of the responsibility seems rather messy.

I see three cleaner alternatives:

1) Have the argument to the ioctl pass the "max known feature number" instead of the bank count. Then the kernel implementation could set to 1 all feature bits after that max. This alternative makes the kernel fully responsible for doing the default disabling, based on what the VMM tells the kernel it knows about.

2) Define the expected future Bank 2 and Bank 3 fields in
struct mshv_create_partition_v2, and require the VMM to set them to all 1's as well as the reserved fields in Bank 0 and Bank 1. This alternative makes the VMM fully responsible for doing the default disabling.

3) As a variant of my #2, invert the polarity of the bits in the pt_cpu_fbanks field of the ioctl argument, so that from the VMM's standpoint they are feature *enable* bits, not feature *disable* bits. The VMM sets bits for the features it knows about and wants to have enabled, which is the much more common pattern. Kernel code would then invert each bank before passing to the hypercall. The Bank 2 and Bank 3 fields would be set to zero by the VMM, and get the same kernel treatment when future hypervisor versions accept the additional banks.

Thoughts?

Michael

#4 lore raw
Quoted 196 lines · Michael Kelley

From: Nuno Das Neves <[email protected]> Sent: Wednesday, November 5, 2025 11:10 AM

Quoted 146 lines · Michael Kelley
Quoted 89 lines

From: Nuno Das Neves <[email protected]> Sent: Tuesday, November 4, 2025 1:47 PM

Quoted 88 lines

From: Muminul Islam <[email protected]>

The existing mshv create partition ioctl does not provide a way to specify which cpu features are enabled in the guest. Instead, it attempts to enable all features and those that are not supported are silently disabled by the hypervisor.

This was done to reduce unnecessary complexity and is sufficient for many cases. However, new scenarios require fine-grained control over these features.

Define a new mshv_create_partition_v2 structure which supports passing the disabled processor and xsave feature bits through to the create partition hypercall directly.

The kernel does not introspect the bits in these new fields as they are part of the hypervisor ABI. Require the caller to provide the number of cpu feature banks passed, to support extending the number of banks in future. Disable all banks that are not specified to ensure the behavior is predictable with newer hypervisors.

Introduce a new flag MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES which enables the new structure. If unset, the original mshv_create_partition struct is used, with the old behavior of enabling all features.

---
Changes in v3:
- Remove the new cpu features definitions in hvhdk.h, and retain the old behavior of enabling all features for the old struct. For the v2 struct, still disable unspecified feature banks, since that makes it robust to future extensions.
- Amend comments and commit message to reflect the above
- Fix unused variable on arm64 [kernel test robot]

Changes in v2:
- Fix exposure of CONFIG_X86_64 to uapi [kernel test robot]
- Fix compilation issue on arm64 [kernel test robot]

---
 drivers/hv/mshv_root_main.c | 94 ++++++++++++++++++++++++++++++-------
 include/uapi/linux/mshv.h   | 34 ++++++++++++++
 2 files changed, 110 insertions(+), 18 deletions(-)
drivers/hv/mshv_root_main.c +13 -11
index d542a0143bb8..814465a0912d 100644
@@ -1900,43 +1900,101 @@ add_partition(struct mshv_partition *partition)
 	return 0;
 }
 
-static long
-mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev)
+static_assert(MSHV_NUM_CPU_FEATURES_BANKS <=
+	      HV_PARTITION_PROCESSOR_FEATURES_BANKS);
+
+static long mshv_ioctl_process_pt_flags(void __user *user_arg, u64 *pt_flags,
+					struct hv_partition_creation_properties *cr_props,
+					union hv_partition_isolation_properties *isol_props)
 {
-	struct mshv_create_partition args;
-	u64 creation_flags;
-	struct hv_partition_creation_properties creation_properties = {};
-	union hv_partition_isolation_properties isolation_properties = {};
-	struct mshv_partition *partition;
-	struct file *file;
-	int fd;
-	long ret;
+	int i;
+	struct mshv_create_partition_v2 args;
+	union hv_partition_processor_features *disabled_procs;
+	union hv_partition_processor_xsave_features *disabled_xsave;
 
-	if (copy_from_user(&args, user_arg, sizeof(args)))
+	/* First, copy orig struct in case user is on previous versions */
+	if (copy_from_user(&args, user_arg,
+			   sizeof(struct mshv_create_partition)))
 		return -EFAULT;
 
 	if ((args.pt_flags & ~MSHV_PT_FLAGS_MASK) ||
 	    args.pt_isolation >= MSHV_PT_ISOLATION_COUNT)
 		return -EINVAL;
 
Quoted 9 lines

drivers/hv/mshv_root_main.c add_partition(struct mshv_partition *partition) · line 1928

Quoted 5 lines
drivers/hv/mshv_root_main.c +5 -0
+	disabled_procs = &cr_props->disabled_processor_features;
+	disabled_xsave = &cr_props->disabled_processor_xsave_features;
+
+	/* Check if user provided newer struct with feature fields */
+	if (args.pt_flags & BIT(MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES)) {

Should probably be "BIT_ULL" instead of "BIT" since args.pt_flags is a long long field, though it really doesn't matter as long as the number of flags is <= 32.

Noted, thanks

Quoted 28 lines
Quoted 5 lines
drivers/hv/mshv_root_main.c +5 -0
+		if (copy_from_user(&args, user_arg, sizeof(args)))
+			return -EFAULT;
+
+		if (args.pt_num_cpu_fbanks > MSHV_NUM_CPU_FEATURES_BANKS ||
+		    mshv_field_nonzero(args, pt_rsvd) ||

drivers/hv/mshv_root_main.c add_partition(struct mshv_partition *partition) · line 1943

Quoted 10 lines
drivers/hv/mshv_root_main.c +10 -0
+		    mshv_field_nonzero(args, pt_rsvd1))
+			return -EINVAL;
+
+
+		for (i = 0; i < args.pt_num_cpu_fbanks; i++)
+			disabled_procs->as_uint64[i] = args.pt_cpu_fbanks[i];
+
+		/* Disable any features left unspecified */
+		for (; i < HV_PARTITION_PROCESSOR_FEATURES_BANKS; i++)
+			disabled_procs->as_uint64[i] = -1;

I'm trying to convince myself that disabling unspecified features is the right thing to do. In the current hypervisor scenario with 2 banks, if the VMM caller specifies only one bank of disable flags, then all the features in the 2nd bank are disabled. That's certainly the reverse from the current code which always enables all features, and from the hypervisor itself which in the hypercall ABI defines the flags as "disable" flags rather than "enable" flags.

Then in a scenario where a new version of the hypervisor shows up with support for 3 banks, the old VMM code that only knows about 2 banks will cause all features in that 3rd bank to be disabled. Again, that's the reverse of the current code.

Quoted 6 lines

I guess it depends on how the hypervisor defines any such new features. Are they typically defined to be benign if they are enabled by default? Or is the polarity the opposite, where the VMM must know about new features before they are enabled? The hypercall interface seems to imply the former but maybe I'm reading too much into it.

The intent is to provide an interface which allows the VMM to control exactly which features are enabled/disabled. E.g. for live migration of a VM, if the target machine has more features available and they are enabled inadvertently, the state may not be restored properly (particularly an issue for xsave).

So to me it makes sense to disable anything unspecified. In general, enabling features by default doesn't cause problems, it's only for specific scenarios like the above. I suppose that's why it's a "disable" mask, though I can't say I fully understand the reasoning...

Quoted 8 lines
Quoted 2 lines

A code comment about the thinking here would be useful for future readers.

Noted. I can repeat the reasoning from the commit message if that is sufficient:
"
Disable all banks that are not specified to ensure
the behavior is predictable with newer hypervisors.
"

Before deciding on the wording of the comment, one more thought occurred to me. union hv_partition_processor_features is currently two 64-bit banks. Bank 0 currently has 63 features plus 1 reserved bit. Bank 1 currently has 22 features, and 42 reserved bits. A new version of the hypervisor could use one or more of those 42 reserved bits for new features.

If a VMM is running on a newer hypervisor version that implements features the VMM is unaware of, the intent is that those features should be disabled by default. So is the expectation that when a VMM provides Bank 0 and Bank 1 values, it should set all the reserved bits to 1? (currently the single bit in Bank 0 and the 42 bits in Bank 1) My point is that the default disabling of new features can't be handled entirely by the kernel implementation of the ioctl based on the bank count passed in the argument to the ioctl. The VMM must cooperate as well. And such splitting of the responsibility seems rather messy.

I see three cleaner alternatives:

1) Have the argument to the ioctl pass the "max known feature number" instead of the bank count. Then the kernel implementation could set to 1 all feature bits after that max. This alternative makes the kernel fully responsible for doing the default disabling, based on what the VMM tells the kernel it knows about.

2) Define the expected future Bank 2 and Bank 3 fields in
struct mshv_create_partition_v2, and require the VMM to set them to all 1's as well as the reserved fields in Bank 0 and Bank 1. This alternative makes the VMM fully responsible for doing the default disabling.

3) As a variant of my #2, invert the polarity of the bits in the pt_cpu_fbanks field of the ioctl argument, so that from the VMM's standpoint they are feature *enable* bits, not feature *disable* bits. The VMM sets bits for the features it knows about and wants to have enabled, which is the much more common pattern. Kernel code would then invert each bank before passing to the hypercall. The Bank 2 and Bank 3 fields would be set to zero by the VMM, and get the same kernel treatment when future hypervisor versions accept the additional banks.

Quoted 2 lines

Thoughts?

I discussed the future direction of this API with the hypervisor team. Surprisingly, it turns out they will add new feature banks but those will NOT be exposed at partition creation time. Rather, they will be set via the set partition property hypercall as an "early" property. That is, after partition creation but before initialization.

This means that we will only need to ever expose 2 banks in this ioctl. I think requiring the VMM to provide both banks is reasonable, as well as not doing any default disabling in the kernel. i.e. Your suggested #2 but with only the 2 banks.

Regarding #3, I want to keep the feature bits as a 'passthrough' field that the kernel doesn't touch, and anyway with a known number of banks this is unnecessary.

On a related note, discussing the reasoning for the inversion in the first place, the hypervisor team told me the primary reason is so that new processor security features can be added to the mask and enabled by default when set to 0. This logic is a little funny given the hypervisor doesn't seem to care whether the reserved bits are 1 or 0 today, but I guess they are meant to be always 0.

In light of all this, now the reserved fields in the ioctl struct aren't serving any purpose. However, unfortunately I don't think I can remove them since userspace code already depends on this structure.

I think pt_num_cpu_fbanks has to stay, too, although I think it's better to enforce that it is set to 2 by userspace and return -EINVAL otherwise.

Does that all make sense or did I miss something?

This information about how the banks will be extended came as a surprise to me. I only brought it up with the hypervisor folks due to your questions here. This is a good thing, thanks for promoting this discussion.

Nuno

Quoted 1 line

Michael

#5 lore raw

From: Nuno Das Neves <[email protected]> Sent: Thursday, November 6, 2025 9:42 AM

Quoted 224 lines · Michael Kelley
Quoted 1 line

From: Nuno Das Neves <[email protected]> Sent: Wednesday,

November 5, 2025 11:10 AM

Quoted 195 lines
Quoted 146 lines · Michael Kelley
Quoted 89 lines

From: Nuno Das Neves <[email protected]> Sent: Tuesday, November 4, 2025 1:47 PM

Quoted 88 lines

From: Muminul Islam <[email protected]>

The existing mshv create partition ioctl does not provide a way to specify which cpu features are enabled in the guest. Instead, it attempts to enable all features and those that are not supported are silently disabled by the hypervisor.

This was done to reduce unnecessary complexity and is sufficient for many cases. However, new scenarios require fine-grained control over these features.

Define a new mshv_create_partition_v2 structure which supports passing the disabled processor and xsave feature bits through to the create partition hypercall directly.

The kernel does not introspect the bits in these new fields as they are part of the hypervisor ABI. Require the caller to provide the number of cpu feature banks passed, to support extending the number of banks in future. Disable all banks that are not specified to ensure the behavior is predictable with newer hypervisors.

Introduce a new flag MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES which enables the new structure. If unset, the original mshv_create_partition struct is used, with the old behavior of enabling all features.

---
Changes in v3:
- Remove the new cpu features definitions in hvhdk.h, and retain the old behavior of enabling all features for the old struct. For the v2 struct, still disable unspecified feature banks, since that makes it robust to future extensions.
- Amend comments and commit message to reflect the above
- Fix unused variable on arm64 [kernel test robot]

Changes in v2:
- Fix exposure of CONFIG_X86_64 to uapi [kernel test robot]
- Fix compilation issue on arm64 [kernel test robot]

---
 drivers/hv/mshv_root_main.c | 94 ++++++++++++++++++++++++++++++-------
 include/uapi/linux/mshv.h   | 34 ++++++++++++++
 2 files changed, 110 insertions(+), 18 deletions(-)
drivers/hv/mshv_root_main.c +13 -11
index d542a0143bb8..814465a0912d 100644
@@ -1900,43 +1900,101 @@ add_partition(struct mshv_partition *partition)
 	return 0;
 }
 
-static long
-mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev)
+static_assert(MSHV_NUM_CPU_FEATURES_BANKS <=
+	      HV_PARTITION_PROCESSOR_FEATURES_BANKS);
+
+static long mshv_ioctl_process_pt_flags(void __user *user_arg, u64 *pt_flags,
+					struct hv_partition_creation_properties *cr_props,
+					union hv_partition_isolation_properties *isol_props)
 {
-	struct mshv_create_partition args;
-	u64 creation_flags;
-	struct hv_partition_creation_properties creation_properties = {};
-	union hv_partition_isolation_properties isolation_properties = {};
-	struct mshv_partition *partition;
-	struct file *file;
-	int fd;
-	long ret;
+	int i;
+	struct mshv_create_partition_v2 args;
+	union hv_partition_processor_features *disabled_procs;
+	union hv_partition_processor_xsave_features *disabled_xsave;
 
-	if (copy_from_user(&args, user_arg, sizeof(args)))
+	/* First, copy orig struct in case user is on previous versions */
+	if (copy_from_user(&args, user_arg,
+			   sizeof(struct mshv_create_partition)))
 		return -EFAULT;
 
 	if ((args.pt_flags & ~MSHV_PT_FLAGS_MASK) ||
 	    args.pt_isolation >= MSHV_PT_ISOLATION_COUNT)
 		return -EINVAL;
 
Quoted 9 lines

drivers/hv/mshv_root_main.c add_partition(struct mshv_partition *partition) · line 1928

Quoted 5 lines
drivers/hv/mshv_root_main.c +5 -0
+	disabled_procs = &cr_props->disabled_processor_features;
+	disabled_xsave = &cr_props->disabled_processor_xsave_features;
+
+	/* Check if user provided newer struct with feature fields */
+	if (args.pt_flags & BIT(MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES)) {

Should probably be "BIT_ULL" instead of "BIT" since args.pt_flags is a long long field, though it really doesn't matter as long as the number of flags is <= 32.

Noted, thanks

Quoted 28 lines
Quoted 5 lines
drivers/hv/mshv_root_main.c +5 -0
+		if (copy_from_user(&args, user_arg, sizeof(args)))
+			return -EFAULT;
+
+		if (args.pt_num_cpu_fbanks > MSHV_NUM_CPU_FEATURES_BANKS ||
+		    mshv_field_nonzero(args, pt_rsvd) ||

drivers/hv/mshv_root_main.c add_partition(struct mshv_partition *partition) · line 1943

Quoted 10 lines
drivers/hv/mshv_root_main.c +10 -0
+		    mshv_field_nonzero(args, pt_rsvd1))
+			return -EINVAL;
+
+
+		for (i = 0; i < args.pt_num_cpu_fbanks; i++)
+			disabled_procs->as_uint64[i] = args.pt_cpu_fbanks[i];
+
+		/* Disable any features left unspecified */
+		for (; i < HV_PARTITION_PROCESSOR_FEATURES_BANKS; i++)
+			disabled_procs->as_uint64[i] = -1;

I'm trying to convince myself that disabling unspecified features is the right thing to do. In the current hypervisor scenario with 2 banks, if the VMM caller specifies only one bank of disable flags, then all the features in the 2nd bank are disabled. That's certainly the reverse from the current code which always enables all features, and from the hypervisor itself which in the hypercall ABI defines the flags as "disable" flags rather than "enable" flags.

Then in a scenario where a new version of the hypervisor shows up with support for 3 banks, the old VMM code that only knows about 2 banks will cause all features in that 3rd bank to be disabled. Again, that's the reverse of the current code.

Quoted 6 lines

I guess it depends on how the hypervisor defines any such new features. Are they typically defined to be benign if they are enabled by default? Or is the polarity the opposite, where the VMM must know about new features before they are enabled? The hypercall interface seems to imply the former but maybe I'm reading too much into it.

The intent is to provide an interface which allows the VMM to control exactly which features are enabled/disabled. E.g. for live migration of a VM, if the target machine has more features available and they are enabled inadvertently, the state may not be restored properly (particularly an issue for xsave).

So to me it makes sense to disable anything unspecified. In general, enabling features by default doesn't cause problems, it's only for specific scenarios like the above. I suppose that's why it's a "disable" mask, though I can't say I fully understand the reasoning...

Quoted 8 lines
Quoted 2 lines

A code comment about the thinking here would be useful for future readers.

Noted. I can repeat the reasoning from the commit message if that is sufficient:
"
Disable all banks that are not specified to ensure
the behavior is predictable with newer hypervisors.
"

Before deciding on the wording of the comment, one more thought occurred to me. union hv_partition_processor_features is currently two 64-bit banks. Bank 0 currently has 63 features plus 1 reserved bit. Bank 1 currently has 22 features, and 42 reserved bits. A new version of the hypervisor could use one or more of those 42 reserved bits for new features.

If a VMM is running on a newer hypervisor version that implements features the VMM is unaware of, the intent is that those features should be disabled by default. So is the expectation that when a VMM provides Bank 0 and Bank 1 values, it should set all the reserved bits to 1? (currently the single bit in Bank 0 and the 42 bits in Bank 1) My point is that the default disabling of new features can't be handled entirely by the kernel implementation of the ioctl based on the bank count passed in the argument to the ioctl. The VMM must cooperate as well. And such splitting of the responsibility seems rather messy.

I see three cleaner alternatives:

1) Have the argument to the ioctl pass the "max known feature number" instead of the bank count. Then the kernel implementation could set to 1 all feature bits after that max. This alternative makes the kernel fully responsible for doing the default disabling, based on what the VMM tells the kernel it knows about.

2) Define the expected future Bank 2 and Bank 3 fields in
struct mshv_create_partition_v2, and require the VMM to set them to all 1's as well as the reserved fields in Bank 0 and Bank 1. This alternative makes the VMM fully responsible for doing the default disabling.

3) As a variant of my #2, invert the polarity of the bits in the pt_cpu_fbanks field of the ioctl argument, so that from the VMM's standpoint they are feature *enable* bits, not feature *disable* bits. The VMM sets bits for the features it knows about and wants to have enabled, which is the much more common pattern. Kernel code would then invert each bank before passing to the hypercall. The Bank 2 and Bank 3 fields would be set to zero by the VMM, and get the same kernel treatment when future hypervisor versions accept the additional banks.

Quoted 2 lines

Thoughts?

I discussed the future direction of this API with the hypervisor team. Surprisingly, it turns out they will add new feature banks but those will NOT be exposed at partition creation time. Rather, they will be set via the set partition property hypercall as an "early" property. That is, after partition creation but before initialization.

This means that we will only need to ever expose 2 banks in this ioctl. I think requiring the VMM to provide both banks is reasonable, as well as not doing any default disabling in the kernel. i.e. Your suggested #2 but with only the 2 banks.

Regarding #3, I want to keep the feature bits as a 'passthrough' field that the kernel doesn't touch, and anyway with a known number of banks this is unnecessary.

On a related note, discussing the reasoning for the inversion in the first place, the hypervisor team told me the primary reason is so that new processor security features can be added to the mask and enabled by default when set to 0. This logic is a little funny given the hypervisor doesn't seem to care whether the reserved bits are 1 or 0 today, but I guess they are meant to be always 0.

Quoted 8 lines

In light of all this, now the reserved fields in the ioctl struct aren't serving any purpose. However, unfortunately I don't think I can remove them since userspace code already depends on this structure.

I think pt_num_cpu_fbanks has to stay, too, although I think it's better to enforce that it is set to 2 by userspace and return -EINVAL otherwise.

Does that all make sense or did I miss something?

Yes, this all makes sense, and I'm good with it. Leaving the reserved fields in the ioctl structure is OK, as is requiring pt_num_cpu_fbanks to be 2.

I was going to compare with how HVCALL_SET_PARTITION_PROPERTY is handled with the potential for Bank 2 and Bank 3 to appear, but I see that's a pass-thru hypercall whose inputs are constructed entirely in the user space VMM. So there's no kernel code to compare against, and the VMM code must "Do The Right Thing".

To summarize, the design of mshv_ioctl_create_partition() will be to follow the behavior of the underlying hypercall. The hypercall arguments (and therefore mshv_ioctl_create_partition) are designed to allow the hypervisor to add new features, and have them be enabled by default. The kernel code for mshv_ioctl_create_partition() will pass-thru to the hypercall the Bank 0 and Bank 1 values provided by the VMM in the ioctl. To achieve the "new features enabled by default" behavior, the VMM should set the reserved bits in Bank 1 to zero. To turn off the default enablement, a VMM must know about a feature and explicitly decide to disable it by setting to 1 its assigned bit in Bank 0 or Bank 1.

Quoted 4 lines

This information about how the banks will be extended came as a surprise to me. I only brought it up with the hypervisor folks due to your questions here. This is a good thing, thanks for promoting this discussion.

Thx. I'm glad it was useful. Sometimes I wonder if I'm just being annoying with my comments, but hopefully there are enough real issues that just being annoying is rare. :-)

Michael