@samitouri / QOSamiQemu / commits / 49cd174b56

accel/mshv: write synthetic MSRs after migration

Write partition-wide synthetic MSRs. This ensures the hypercall page and SynIC facilities are set up before vCPUs attempt to use it. Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com> Link: https://lore.kernel.org/r/20260710101534.664604-10-magnuskulke@linux.microsoft.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Magnus Kulke committed Jul 10, 2026 at 12:15 UTC 49cd174b56ae5db509a075752a8a9e5247ebbc2e
4 files changed +34
accel/mshv/mshv-all.c
+15
@@ -60,6 +60,20 @@ static int init_mshv(int *mshv_fd)
60 return 0;
61 }
62
63 +static int mshv_load_cleanup(void *opaque)
64 +{
65 + int ret;
66 +
67 + ret = mshv_arch_set_partition_msrs(first_cpu);
68 + if (ret < 0) {
69 + error_report("Failed to set partition MSRs: %s", strerror(-ret));
70 + return -1;
71 + }
72 +
73 + return 0;
74 +}
75 +
76 +
77 static int get_host_partition_property(int mshv_fd, uint32_t property_code,
78 uint64_t *value)
79 {
@@ -496,6 +510,7 @@ static int mshv_init_vcpu(CPUState *cpu)
510 }
511
512 static SaveVMHandlers savevm_mshv = {
513 + .load_cleanup = mshv_load_cleanup,
514 };
515
516 static int mshv_init(AccelState *as, MachineState *ms)
include/hw/hyperv/hvgdk_mini.h
+3
@@ -23,6 +23,9 @@
23 #define HV_X64_MSR_APIC_FREQUENCY 0x40000023
24
25 typedef enum hv_register_name {
26 + /* VP Management Registers */
27 + HV_REGISTER_INTERNAL_ACTIVITY_STATE = 0x00000004,
28 +
29 /* Pending Interruption Register */
30 HV_REGISTER_PENDING_INTERRUPTION = 0x00010002,
31 HV_REGISTER_INTERRUPT_STATE = 0x00010003,
include/system/mshv_int.h
+1
@@ -98,6 +98,7 @@ int mshv_get_generic_regs(CPUState *cpu, hv_register_assoc *assocs,
98 size_t n_regs);
99 int mshv_arch_store_vcpu_state(const CPUState *cpu);
100 int mshv_arch_load_vcpu_state(CPUState *cpu);
101 +int mshv_arch_set_partition_msrs(const CPUState *cpu);
102 void mshv_arch_init_vcpu(CPUState *cpu);
103 void mshv_arch_destroy_vcpu(CPUState *cpu);
104 void mshv_arch_amend_proc_features(
target/i386/mshv/mshv-cpu.c
+15
@@ -1506,6 +1506,21 @@ int mshv_arch_store_vcpu_state(const CPUState *cpu)
1506 return 0;
1507 }
1508
1509 +int mshv_arch_set_partition_msrs(const CPUState *cpu)
1510 +{
1511 + CPUX86State *env = &X86_CPU(cpu)->env;
1512 + struct hv_register_assoc assocs[] = {
1513 + { .name = HV_REGISTER_GUEST_OS_ID,
1514 + .value.reg64 = env->msr_hv_guest_os_id },
1515 + { .name = HV_REGISTER_REFERENCE_TSC,
1516 + .value.reg64 = env->msr_hv_tsc },
1517 + { .name = HV_X64_REGISTER_HYPERCALL,
1518 + .value.reg64 = env->msr_hv_hypercall },
1519 + };
1520 +
1521 + return mshv_set_generic_regs(cpu, assocs, ARRAY_SIZE(assocs));
1522 +}
1523 +
1524 void mshv_arch_amend_proc_features(
1525 union hv_partition_synthetic_processor_features *features)
1526 {