mshv: Extend create partition ioctl to support cpu features
Subsystems (2)
PATCH v2 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. This was done to reduce unnecessary complexity in the API.
However, some new scenarios require fine-grained control over the cpu feature bits.
Define a new mshv_create_partition_v2 structure which supports passing through the disabled cpu flags and xsave flags to the hypervisor directly.
When these are not specified (pt_num_cpu_fbanks == 0) or the old structure is used, define a set of default flags which cover most cases.
Retain backward compatibility with the old structure via a new flag MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES which enables the new struct.
---
Changes in v2:
- Fix compilation issues [kernel test robot]
--- drivers/hv/mshv_root_main.c | 176 ++++++++++++++++++++++++++++++++---- include/hyperv/hvhdk.h | 86 +++++++++++++++++- include/uapi/linux/mshv.h | 34 +++++++ 3 files changed, 272 insertions(+), 24 deletions(-)
drivers/hv/mshv_root_main.c +157 -19
@@ -1900,43 +1900,181 @@ 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 ) + args.pt_isolation >=MSHV_PT_ISOLATION_COUNT )return -EINVAL ; + disabled_procs = &cr_props->disabled_processor_features; + +/* Disable all processor features first */ +for (i =0 ; i <HV_PARTITION_PROCESSOR_FEATURES_BANKS ; i++) + disabled_procs->as_uint64[i] =-1 ; + +#if IS_ENABLED (CONFIG_X86_64 ) +/* Enable default features that are known to be supported */ + disabled_procs->cet_ibt_support =0 ; + disabled_procs->cet_ss_support =0 ; + disabled_procs->smep_support =0 ; + disabled_procs->rdtscp_support =0 ; + disabled_procs->tsc_invariant_support =0 ; + disabled_procs->sse3_support =0 ; + disabled_procs->lahf_sahf_support =0 ; + disabled_procs->ssse3_support =0 ; + disabled_procs->sse4_1_support =0 ; + disabled_procs->sse4_2_support =0 ; + disabled_procs->sse4a_support =0 ; + disabled_procs->xop_support =0 ; + disabled_procs->pop_cnt_support =0 ; + disabled_procs->cmpxchg16b_support =0 ; + disabled_procs->altmovcr8_support =0 ; + disabled_procs->lzcnt_support =0 ; + disabled_procs->mis_align_sse_support =0 ; + disabled_procs->mmx_ext_support =0 ; + disabled_procs->amd3dnow_support =0 ; + disabled_procs->extended_amd3dnow_support =0 ; + disabled_procs->aes_support =0 ; + disabled_procs->pclmulqdq_support =0 ; + disabled_procs->pcid_support =0 ; + disabled_procs->fma4_support =0 ; + disabled_procs->f16c_support =0 ; + disabled_procs->rd_rand_support =0 ; + disabled_procs->rd_wr_fs_gs_support =0 ; + disabled_procs->enhanced_fast_string_support =0 ; + disabled_procs->bmi1_support =0 ; + disabled_procs->bmi2_support =0 ; + disabled_procs->hle_support_deprecated =0 ; + disabled_procs->rtm_support_deprecated =0 ; + disabled_procs->movbe_support =0 ; + disabled_procs->npiep1_support =0 ; + disabled_procs->dep_x87_fpu_save_support =0 ; + disabled_procs->rd_seed_support =0 ; + disabled_procs->adx_support =0 ; + disabled_procs->intel_prefetch_support =0 ; + disabled_procs->smap_support =0 ; + disabled_procs->hle_support =0 ; + disabled_procs->rtm_support =0 ; + disabled_procs->invpcid_support =0 ; + disabled_procs->ibrs_support =0 ; + disabled_procs->stibp_support =0 ; + disabled_procs->mdd_support =0 ; + disabled_procs->ibpb_support =0 ; + disabled_procs->l1dcache_flush_support =0 ; + disabled_procs->virt_spec_ctrl_support =0 ; + disabled_procs->mb_clear_support =0 ; + disabled_procs->tsx_ctrl_support =0 ; + disabled_procs->clflushopt_support =0 ; + disabled_procs->rdcl_no_support =0 ; + disabled_procs->ibrs_all_support =0 ; + disabled_procs->page_1gb_support =0 ; + disabled_procs->skip_l1df_support =0 ; + disabled_procs->ssb_no_support =0 ; + disabled_procs->mbs_no_support =0 ; + disabled_procs->taa_no_support =0 ; + disabled_procs->fb_clear_support =0 ; + disabled_procs->gds_no_support =0 ; + disabled_procs->bhi_no_support =0 ; + disabled_procs->bhi_dis_support =0 ; + disabled_procs->btc_no_support =0 ; + disabled_procs->mitigation_ctrl_support =0 ; + disabled_procs->rfds_no_support =0 ; + disabled_procs->rfds_clear_support =0 ; + disabled_procs->unrestricted_guest_support =0 ; + disabled_procs->fast_short_rep_mov_support =0 ; + disabled_procs->rsb_a_no_support =0 ; + disabled_procs->rd_pid_support =0 ; + disabled_procs->umip_support =0 ; + disabled_procs->vmx_exception_inject_support =0 ; + disabled_procs->rdpru_support =0 ; + disabled_procs->mbec_support =0 ; + disabled_procs->psfd_support =0 ; + +/* Enable default XSave features that are known to be supported*/ + disabled_xsave = &cr_props->disabled_processor_xsave_features; + disabled_xsave->as_uint64 =-1 ; + disabled_xsave->xsave_support =0 ; + disabled_xsave->xsaveopt_support =0 ; + disabled_xsave->avx_support =0 ; + disabled_xsave->xsave_supervisor_support =0 ; + disabled_xsave->xsave_comp_support =0 ; +#endif +/* 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]; + +#if IS_ENABLED (CONFIG_X86_64 ) + disabled_xsave->as_uint64 = args.pt_disabled_xsave; +#else +if (mshv_field_nonzero (args, pt_rsvd2)) +return -EINVAL ; +#endif + } +/* 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 ; +case MSHV_PT_ISOLATION_SNP : + isol_props->isolation_type =HV_PARTITION_ISOLATION_TYPE_SNP ;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/hyperv/hvhdk.h +81 -5
98 lines not on this page · raw message
include/uapi/linux/mshv.h +34 -0
@@ -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, };
@@ -33,6 +34,7 @@ enum {enum {MSHV_PT_ISOLATION_NONE , +MSHV_PT_ISOLATION_SNP ,MSHV_PT_ISOLATION_COUNT , };
@@ -41,6 +43,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 +56,36 @@ 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. +* @pt_cpu_fbanks: processor feature banks array +* @pt_disabled_xsave: disabled xsave feature bits. Refer to +* union hv_partition_processor_xsave_feature +* +* 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
Wei Liu
maintainerQuoted 24 lines · Nuno Das Neves
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. This was done to reduce unnecessary complexity in the API.
However, some new scenarios require fine-grained control over the cpu feature bits.
Define a new
mshv_create_partition_v2structure which supports passing through the disabled cpu flags and xsave flags to the hypervisor directly.When these are not specified (
pt_num_cpu_fbanks== 0) or the old structure is used, define a set of default flags which cover most cases.Retain backward compatibility with the old structure via a new flag
MSHV_PT_BIT_CPU_AND_XSAVE_FEATURESwhich enables the new struct.Co-developed-by Jinank Jain <[email protected]>Signed-off-by Jinank Jain <[email protected]>Signed-off-by Muminul Islam <[email protected]>Signed-off-by Nuno Das Neves <[email protected]>
Quoted 7 lines
---
Changes in v2:
- Fix compilation issues [kernel test robot]--- drivers/hv/mshv_root_main.c | 176 ++++++++++++++++++++++++++++++++---- include/hyperv/hvhdk.h | 86 +++++++++++++++++-
There is no mention of updating hvhdk.h in the commit message.
Can you split out this part to a separate commit?
Wei
Quoted 28 lines · Nuno Das Neves
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. This was done to reduce unnecessary complexity in the API.
However, some new scenarios require fine-grained control over the cpu feature bits.
Define a new
mshv_create_partition_v2structure which supports passing through the disabled cpu flags and xsave flags to the hypervisor directly.When these are not specified (
pt_num_cpu_fbanks== 0) or the old structure is used, define a set of default flags which cover most cases.Retain backward compatibility with the old structure via a new flag
MSHV_PT_BIT_CPU_AND_XSAVE_FEATURESwhich enables the new struct.Co-developed-by Jinank Jain <[email protected]>Signed-off-by Jinank Jain <[email protected]>Signed-off-by Muminul Islam <[email protected]>Signed-off-by Nuno Das Neves <[email protected]>---
Changes in v2:
- Fix compilation issues [kernel test robot]
Quoted 5 lines
--- drivers/hv/mshv_root_main.c | 176 ++++++++++++++++++++++++++++++++---- include/hyperv/hvhdk.h | 86 +++++++++++++++++- include/uapi/linux/mshv.h | 34 +++++++ 3 files changed, 272 insertions(+), 24 deletions(-)
lkp also pointed out that we are leaking a kernel config to userspace:
https://lore.kernel.org/all/[email protected]/
In the v3 that Wei requested, please address that as well.
Thanks,
Easwar (he/him)
<snip>
Quoted 35 lines · Easwar Hariharan
Quoted 28 lines · Nuno Das Neves
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. This was done to reduce unnecessary complexity in the API.
However, some new scenarios require fine-grained control over the cpu feature bits.
Define a new
mshv_create_partition_v2structure which supports passing through the disabled cpu flags and xsave flags to the hypervisor directly.When these are not specified (
pt_num_cpu_fbanks== 0) or the old structure is used, define a set of default flags which cover most cases.Retain backward compatibility with the old structure via a new flag
MSHV_PT_BIT_CPU_AND_XSAVE_FEATURESwhich enables the new struct.Co-developed-by Jinank Jain <[email protected]>Signed-off-by Jinank Jain <[email protected]>Signed-off-by Muminul Islam <[email protected]>Signed-off-by Nuno Das Neves <[email protected]>---
Changes in v2:
- Fix compilation issues [kernel test robot]Quoted 5 lines
--- drivers/hv/mshv_root_main.c | 176 ++++++++++++++++++++++++++++++++---- include/hyperv/hvhdk.h | 86 +++++++++++++++++- include/uapi/linux/mshv.h | 34 +++++++ 3 files changed, 272 insertions(+), 24 deletions(-)
Quoted 4 lines
lkp also pointed out that we are leaking a kernel config to userspace:
https://lore.kernel.org/all/[email protected]/In the v3 that Wei requested, please address that as well.
Thanks, I did fix this issue in v2 but I didn't mention it explicitly. I'll update the changelog in v3 to call it out.
Quoted 5 lines
Thanks,
Easwar (he/him)<snip>
Quoted 29 lines · Wei Liu
Quoted 28 lines · Nuno Das Neves
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. This was done to reduce unnecessary complexity in the API.
However, some new scenarios require fine-grained control over the cpu feature bits.
Define a new
mshv_create_partition_v2structure which supports passing through the disabled cpu flags and xsave flags to the hypervisor directly.When these are not specified (
pt_num_cpu_fbanks== 0) or the old structure is used, define a set of default flags which cover most cases.Retain backward compatibility with the old structure via a new flag
MSHV_PT_BIT_CPU_AND_XSAVE_FEATURESwhich enables the new struct.Co-developed-by Jinank Jain <[email protected]>Signed-off-by Jinank Jain <[email protected]>Signed-off-by Muminul Islam <[email protected]>Signed-off-by Nuno Das Neves <[email protected]>---
Changes in v2:
- Fix compilation issues [kernel test robot]
Quoted 6 lines
Quoted 3 lines
--- drivers/hv/mshv_root_main.c | 176 ++++++++++++++++++++++++++++++++---- include/hyperv/hvhdk.h | 86 +++++++++++++++++-There is no mention of updating
hvhdk.hin the commit message.
Ah, that's true..
Quoted 1 line
Can you split out this part to a separate commit?
I put the header changes in this patch because a patch containing those alone doesn't have much merit on its own.
I know we have split header changes into separate patches in the past but I'm not sure it's always the right choice.
Thinking about this, I could also split it up another way: one patch to introduce the new cpu features flags and use them in the driver, and one patch to introduce mshv_create_partition_v2.
Nuno>
Quoted 1 line
Wei
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Nuno,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linus/master]
[also build test WARNING on v6.18-rc3 next-20251031]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Nuno-Das-Neves/mshv-Extend-create-partition-ioctl-to-support-cpu-features/20251031-054134 base: linus/master patch link: https://lore.kernel.org/r/1761860431-11208-1-git-send-email-nunodasneves%40linux.microsoft.com patch subject: [PATCH v2] mshv: Extend create partition ioctl to support cpu features config: arm64-randconfig-001-20251102 (https://download.01.org/0day-ci/archive/20251102/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project d2625a438020ad35330cda29c3def102c1687b1b) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251102/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/hv/mshv_root_main.c:1875:47: warning: unused variable 'disabled_xsave' [-Wunused-variable]
1875 | union hv_partition_processor_xsave_features *disabled_xsave;
| ^~~~~~~~~~~~~~1 warning generated.
vim +/disabled_xsave +1875 drivers/hv/mshv_root_main.c
1864
1865 static_assert(MSHV_NUM_CPU_FEATURES_BANKS <=
1866 HV_PARTITION_PROCESSOR_FEATURES_BANKS);
1867
1868 static long mshv_ioctl_process_pt_flags(void __user *user_arg, u64 *pt_flags,
1869 struct hv_partition_creation_properties *cr_props,
1870 union hv_partition_isolation_properties *isol_props)
1871 {
1872 int i;
1873 struct mshv_create_partition_v2 args;
1874 union hv_partition_processor_features *disabled_procs;
> 1875 union hv_partition_processor_xsave_features *disabled_xsave;
1876
1877 /* First, copy orig struct in case user is on previous versions */
1878 if (copy_from_user(&args, user_arg,
1879 sizeof(struct mshv_create_partition)))
1880 return -EFAULT;
1881
1882 if ((args.pt_flags & ~MSHV_PT_FLAGS_MASK) ||
1883 args.pt_isolation >= MSHV_PT_ISOLATION_COUNT)
1884 return -EINVAL;
1885
1886 disabled_procs = &cr_props->disabled_processor_features;
1887
1888 /* Disable all processor features first */
1889 for (i = 0; i < HV_PARTITION_PROCESSOR_FEATURES_BANKS; i++)
1890 disabled_procs->as_uint64[i] = -1;
1891
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Wei Liu
maintainerQuoted 38 lines · Nuno Das Neves
Quoted 29 lines · Wei Liu
Quoted 28 lines · Nuno Das Neves
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. This was done to reduce unnecessary complexity in the API.
However, some new scenarios require fine-grained control over the cpu feature bits.
Define a new
mshv_create_partition_v2structure which supports passing through the disabled cpu flags and xsave flags to the hypervisor directly.When these are not specified (
pt_num_cpu_fbanks== 0) or the old structure is used, define a set of default flags which cover most cases.Retain backward compatibility with the old structure via a new flag
MSHV_PT_BIT_CPU_AND_XSAVE_FEATURESwhich enables the new struct.Co-developed-by Jinank Jain <[email protected]>Signed-off-by Jinank Jain <[email protected]>Signed-off-by Muminul Islam <[email protected]>Signed-off-by Nuno Das Neves <[email protected]>---
Changes in v2:
- Fix compilation issues [kernel test robot]Quoted 6 lines
Quoted 3 lines
--- drivers/hv/mshv_root_main.c | 176 ++++++++++++++++++++++++++++++++---- include/hyperv/hvhdk.h | 86 +++++++++++++++++-There is no mention of updating
hvhdk.hin the commit message.Ah, that's true..
Quoted 8 lines
Quoted 1 line
Can you split out this part to a separate commit?
I put the header changes in this patch because a patch containing those alone doesn't have much merit on its own.
I know we have split header changes into separate patches in the past but I'm not sure it's always the right choice.
This makes it easier for me or other maintainers to track specifically the header changes.
Quoted 3 lines
Thinking about this, I could also split it up another way: one patch to introduce the new cpu features flags and use them in the driver, and one patch to introduce
mshv_create_partition_v2.
That's fine by me.
Wei
Quoted 4 lines
Nuno>
Quoted 1 line
Wei