mirror of
https://github.com/qemu/qemu.git
synced 2026-02-04 05:35:39 +00:00
Create the MSHV virtual machine by opening a partition and issuing the necessary ioctl to initialize it. This sets up the basic VM structure and initial configuration used by MSHV to manage guest state. Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com> Link: https://lore.kernel.org/r/20250916164847.77883-10-magnuskulke@linux.microsoft.com [Add stubs; fix format strings for trace-events; make mshv_hvcall available only in per-target files; mshv.h/mshv_int.h split. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
73 lines
1.9 KiB
C
73 lines
1.9 KiB
C
/*
|
|
* QEMU MSHV support
|
|
*
|
|
* Copyright Microsoft, Corp. 2025
|
|
*
|
|
* Authors: Ziqiao Zhou <ziqiaozhou@microsoft.com>
|
|
* Magnus Kulke <magnuskulke@microsoft.com>
|
|
* Jinank Jain <jinankjain@microsoft.com>
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qemu/error-report.h"
|
|
#include "qemu/typedefs.h"
|
|
|
|
#include "system/mshv.h"
|
|
#include "system/mshv_int.h"
|
|
#include "system/address-spaces.h"
|
|
#include "linux/mshv.h"
|
|
#include "hw/hyperv/hvgdk.h"
|
|
#include "hw/hyperv/hvgdk_mini.h"
|
|
#include "hw/hyperv/hvhdk_mini.h"
|
|
|
|
#include "trace-accel_mshv.h"
|
|
#include "trace.h"
|
|
|
|
void mshv_arch_amend_proc_features(
|
|
union hv_partition_synthetic_processor_features *features)
|
|
{
|
|
features->access_guest_idle_reg = 1;
|
|
}
|
|
|
|
/*
|
|
* Default Microsoft Hypervisor behavior for unimplemented MSR is to send a
|
|
* fault to the guest if it tries to access it. It is possible to override
|
|
* this behavior with a more suitable option i.e., ignore writes from the guest
|
|
* and return zero in attempt to read unimplemented.
|
|
*/
|
|
static int set_unimplemented_msr_action(int vm_fd)
|
|
{
|
|
struct hv_input_set_partition_property in = {0};
|
|
struct mshv_root_hvcall args = {0};
|
|
|
|
in.property_code = HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION;
|
|
in.property_value = HV_UNIMPLEMENTED_MSR_ACTION_IGNORE_WRITE_READ_ZERO;
|
|
|
|
args.code = HVCALL_SET_PARTITION_PROPERTY;
|
|
args.in_sz = sizeof(in);
|
|
args.in_ptr = (uint64_t)∈
|
|
|
|
trace_mshv_hvcall_args("unimplemented_msr_action", args.code, args.in_sz);
|
|
|
|
int ret = mshv_hvcall(vm_fd, &args);
|
|
if (ret < 0) {
|
|
error_report("Failed to set unimplemented MSR action");
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int mshv_arch_post_init_vm(int vm_fd)
|
|
{
|
|
int ret;
|
|
|
|
ret = set_unimplemented_msr_action(vm_fd);
|
|
if (ret < 0) {
|
|
error_report("Failed to set unimplemented MSR action");
|
|
}
|
|
|
|
return ret;
|
|
}
|