Commit c03834a570 for qemu.org

commit c03834a570ed0212571555c65e78de7726656f17
Author: Luigi Leonardi <leonardi@redhat.com>
Date:   Mon Sep 7 17:56:59 2026 +0200

    i386/sev: convert the guest policy properties to custom accessors

    Both SEV/SEV-ES and SEV-SNP expose a "policy" object property. The
    SEV/SEV-ES one was registered as a plain uint32 pointer property, and
    the SEV-SNP setter ignored the result of the visit.

    Give both properties explicit getter/setter functions and check the
    return value of the visit in the setters. This is preparation for
    tracking whether the guest policy was set on the command line.

    No functional change intended.

    Reviewed-by: Ani Sinha <anisinha@redhat.com>
    Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
    Message-ID: <20260907-fix_igvm_policy-v2-3-c8c50f1dbfda@redhat.com>
    Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

diff --git a/target/i386/sev.c b/target/i386/sev.c
index b53d13e2fa..38f97fd9b2 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -2996,6 +2996,22 @@ sev_guest_class_init(ObjectClass *oc, const void *data)
             "use legacy VM type to maintain measurement compatibility with older QEMU or kernel versions.");
 }

+static void
+sev_guest_get_policy(Object *obj, Visitor *v, const char *name,
+                     void *opaque, Error **errp)
+{
+    visit_type_uint32(v, name, &SEV_GUEST(obj)->policy, errp);
+}
+
+static void
+sev_guest_set_policy(Object *obj, Visitor *v, const char *name,
+                     void *opaque, Error **errp)
+{
+    if (!visit_type_uint32(v, name, &SEV_GUEST(obj)->policy, errp)) {
+        return;
+    }
+}
+
 static void
 sev_guest_instance_init(Object *obj)
 {
@@ -3004,8 +3020,8 @@ sev_guest_instance_init(Object *obj)
     sev_guest->policy = DEFAULT_GUEST_POLICY;
     object_property_add_uint32_ptr(obj, "handle", &sev_guest->handle,
                                    OBJ_PROP_FLAG_READWRITE);
-    object_property_add_uint32_ptr(obj, "policy", &sev_guest->policy,
-                                   OBJ_PROP_FLAG_READWRITE);
+    object_property_add(obj, "policy", "uint32", sev_guest_get_policy,
+                        sev_guest_set_policy, NULL, NULL);
     object_apply_compat_props(obj);

     sev_guest->legacy_vm_type = ON_OFF_AUTO_AUTO;
@@ -3044,9 +3060,13 @@ static void
 sev_snp_guest_set_policy(Object *obj, Visitor *v, const char *name,
                          void *opaque, Error **errp)
 {
-    visit_type_uint64(v, name,
-                      (uint64_t *)&SEV_SNP_GUEST(obj)->kvm_start_conf.policy,
-                      errp);
+    SevSnpGuestState *sev_snp_guest = SEV_SNP_GUEST(obj);
+
+    if (!visit_type_uint64(v, name,
+                           (uint64_t *)&sev_snp_guest->kvm_start_conf.policy,
+                           errp)) {
+        return;
+    }
 }

 static char *