Query HV_PARTITION_PROPERTY_PROCESSOR_FEATURES to obtain the feature set
supported by the host and pass on this feature set to the guest during
partition creation.
Signed-off-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com>
---
accel/mshv/mshv-all.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c
index d4cc7f5371..3b8b9ef116 100644
--- a/accel/mshv/mshv-all.c
+++ b/accel/mshv/mshv-all.c
@@ -110,21 +110,64 @@ static int resume_vm(int vm_fd)
return 0;
}
+static int get_host_property(int mshv_fd, uint32_t prop_code, uint64_t *value)
+{
+ int ret;
+ struct hv_input_get_partition_property in = {0};
+ struct mshv_root_hvcall args = {0};
+ struct hv_output_get_partition_property out = {0};
+
+ in.property_code = prop_code;
+
+ args.code = HVCALL_GET_PARTITION_PROPERTY;
+ args.in_sz = sizeof(in);
+ args.in_ptr = (uint64_t)∈
+ args.out_sz = sizeof(out);
+ args.out_ptr = (uint64_t)&out;
+
+ ret = mshv_hvcall(mshv_fd, &args);
+ if (ret < 0) {
+ return -errno;
+ }
+
+ *value = out.property_value;
+ return 0;
+}
+
static int create_partition(int mshv_fd, int *vm_fd)
{
int ret;
- struct mshv_create_partition args = {0};
+ struct mshv_create_partition_v2 args = {0};
+ uint64_t host_proc_features0, host_proc_features1;
+
+ ret = get_host_property(mshv_fd, HV_PARTITION_PROPERTY_PROCESSOR_FEATURES0,
+ &host_proc_features0);
+ if (ret < 0) {
+ error_report("Failed to get host processor features (bank 0)");
+ return -1;
+ }
+
+ ret = get_host_property(mshv_fd, HV_PARTITION_PROPERTY_PROCESSOR_FEATURES1,
+ &host_proc_features1);
+ if (ret < 0) {
+ error_report("Failed to get host processor features (bank 1)");
+ return -1;
+ }
/* Initialize pt_flags with the desired features */
uint64_t pt_flags = (1ULL << MSHV_PT_BIT_LAPIC) |
(1ULL << MSHV_PT_BIT_X2APIC) |
- (1ULL << MSHV_PT_BIT_GPA_SUPER_PAGES);
+ (1ULL << MSHV_PT_BIT_GPA_SUPER_PAGES) |
+ (1ULL << MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES);
/* Set default isolation type */
uint64_t pt_isolation = MSHV_PT_ISOLATION_NONE;
args.pt_flags = pt_flags;
args.pt_isolation = pt_isolation;
+ args.pt_num_cpu_fbanks = MSHV_NUM_CPU_FEATURES_BANKS;
+ args.pt_cpu_fbanks[0] = ~host_proc_features0;
+ args.pt_cpu_fbanks[1] = ~host_proc_features1;
ret = ioctl(mshv_fd, MSHV_CREATE_PARTITION, &args);
if (ret < 0) {
--
2.43.0