]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
whpx: i386: unknown MSR configurability
authorMohamed Mediouni <mohamed@unpredictable.fr>
Wed, 22 Apr 2026 21:42:05 +0000 (23:42 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 30 Apr 2026 15:55:03 +0000 (17:55 +0200)
Add an option to inject back a GPF for unknown MSRs.

Keep it on by default for now as Linux expects accesses to some
AMD-specific MSRs to always succeed when on an AMD host.

Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>
Link: https://lore.kernel.org/r/20260422214225.2242-18-mohamed@unpredictable.fr
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
accel/whpx/whpx-common.c
include/system/whpx-all.h
include/system/whpx-internal.h
target/arm/whpx/whpx-all.c
target/i386/whpx/whpx-all.c

index 59be996aefc9de69855b683d49dcc63429c83e70..497c03138ecc5534ccd3798ffb05a0a18b35df50 100644 (file)
@@ -538,6 +538,8 @@ static void whpx_accel_class_init(ObjectClass *oc, const void *data)
         NULL, NULL);
     object_class_property_set_description(oc, "hyperv",
         "Configure Hyper-V enlightenments");
+
+    whpx_arch_accel_class_init(oc);
 }
 
 static void whpx_accel_instance_init(Object *obj)
@@ -552,6 +554,7 @@ static void whpx_accel_instance_init(Object *obj)
     whpx->hyperv_enlightenments_required = false;
     /* Value determined at whpx_accel_init */
     whpx->hyperv_enlightenments_enabled = false;
+    whpx->ignore_unknown_msr = true;
 }
 
 static const TypeInfo whpx_accel_type = {
index 2cbea71b1496db1e15624143dd2eb88e72983537..4022571ffffb8d69e327bed4a6cec84e8dd9658f 100644 (file)
@@ -20,6 +20,7 @@ void whpx_translate_cpu_breakpoints(
     CPUState *cpu,
     int cpu_breakpoint_count);
 void whpx_arch_destroy_vcpu(CPUState *cpu);
+void whpx_arch_accel_class_init(ObjectClass *oc);
 
 /* called by whpx-accel-ops */
 bool whpx_arch_supports_guest_debug(void);
index cf782cf5f89aa8e2c61079790f4857b3f25869f7..86639627b365081d2d4ee10c6a425adfa945048b 100644 (file)
@@ -47,6 +47,7 @@ struct whpx_state {
     bool hyperv_enlightenments_required;
     bool hyperv_enlightenments_enabled;
 
+    bool ignore_unknown_msr;
 };
 
 extern struct whpx_state whpx_global;
index 4019a513aa75e2e876c8d62a0c6eafa54abf3883..94304a4230bd2b7f8fbd1afc8ebebed6e2158aa3 100644 (file)
@@ -823,6 +823,10 @@ void whpx_cpu_instance_init(CPUState *cs)
 {
 }
 
+void whpx_arch_accel_class_init(ObjectClass *oc)
+{
+}
+
 int whpx_accel_init(AccelState *as, MachineState *ms)
 {
     struct whpx_state *whpx;
index 9fc44f8a67e23afe827d647ac1480b39059f823a..eecc7f48ed9ae8e581e9701c45a30f7554bc3406 100644 (file)
@@ -2133,6 +2133,10 @@ int whpx_vcpu_run(CPUState *cpu)
                     vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite);
             }
 
+            if (!is_known_msr && !whpx->ignore_unknown_msr) {
+                x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0D_GPF, 0);
+            }
+
             hr = whp_dispatch.WHvSetVirtualProcessorRegisters(
                 whpx->partition,
                 cpu->cpu_index,
@@ -2532,6 +2536,47 @@ void whpx_cpu_instance_init(CPUState *cs)
  * Partition support
  */
 
+static void whpx_set_unknown_msr(Object *obj, Visitor *v,
+                                   const char *name, void *opaque,
+                                   Error **errp)
+{
+    struct whpx_state *whpx = &whpx_global;
+    OnOffAuto mode;
+
+    if (!visit_type_OnOffAuto(v, name, &mode, errp)) {
+        return;
+    }
+
+    switch (mode) {
+    case ON_OFF_AUTO_ON:
+        whpx->ignore_unknown_msr = true;
+        break;
+
+    case ON_OFF_AUTO_OFF:
+        whpx->ignore_unknown_msr = false;
+        break;
+
+    case ON_OFF_AUTO_AUTO:
+        whpx->ignore_unknown_msr = true;
+        break;
+    default:
+        /*
+         * The value was checked in visit_type_OnOffAuto() above. If
+         * we get here, then something is wrong in QEMU.
+         */
+        abort();
+    }
+}
+
+void whpx_arch_accel_class_init(ObjectClass *oc)
+{
+    object_class_property_add(oc, "ignore-unknown-msr", "OnOffAuto",
+        NULL, whpx_set_unknown_msr,
+        NULL, NULL);
+    object_class_property_set_description(oc, "ignore-unknown-msr",
+        "Configure unknown MSR behavior");
+}
+
 int whpx_accel_init(AccelState *as, MachineState *ms)
 {
     struct whpx_state *whpx;