From: Luigi Leonardi <[email protected]> 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 <[email protected]> Signed-off-by: Luigi Leonardi <[email protected]> Message-ID: <[email protected]> Signed-off-by: Gerd Hoffmann <[email protected]> --- target/i386/sev.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index b53d13e2fa28..38f97fd9b2b3 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 * -- 2.56.0
