From: Markus Armbruster <armbru@redhat.com>
To: Mark Cave-Ayland <mark.caveayland@nutanix.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
pbonzini@redhat.com, richard.henderson@linaro.org,
mst@redhat.com, mtosatti@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH v3 2/8] qom/object.c: introduce object_class_property_add_alias()
Date: Fri, 18 Sep 2026 11:04:31 +0200 [thread overview]
Message-ID: <875x03nd5s.fsf@pond.sub.org> (raw)
In-Reply-To: <8d9f755c-a82a-4b22-8a9c-ff75bdc23da2@nutanix.com> (Mark Cave-Ayland's message of "Fri, 18 Sep 2026 09:38:21 +0100")
Mark Cave-Ayland <mark.caveayland@nutanix.com> writes:
> On 17/09/2026 09:52, Marc-André Lureau wrote:
>
>> Hi
>> On Wed, Sep 2, 2026 at 6:42 PM Mark Cave-Ayland
>> <mark.caveayland@nutanix.com> wrote:
>>>
>>> This is eventually intended to be a replacement for object_property_add_alias()
>>> which uses an object property instead of a class property.
>>>
>>> With the advent of class properties, it is possible that QOM may attempt to
>>> set or retrieve the value of an unset alias property. Update the existing
>>> property_get_alias() and property_set_alias() functions to use the null visitor
>>> if the alias target has not been set, and property_resolve_alias() to return
>>> NULL for the same case.
>>>
>>> This ensures that unset class alias properties accessed e.g. via the monitor do
>>> not cause QEMU to crash.
>>>
>>> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
>>> ---
>>> include/qom/object.h | 25 +++++++++++
>>> qom/object.c | 100 +++++++++++++++++++++++++++++++++++++------
>>> 2 files changed, 113 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/include/qom/object.h b/include/qom/object.h
>>> index e24f0a2b2d..96c76975ef 100644
>>> --- a/include/qom/object.h
>>> +++ b/include/qom/object.h
>>> @@ -2263,6 +2263,11 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
>>> const uint64_t *v,
>>> ObjectPropertyFlags flags);
>>>
>>> +typedef enum {
>>> + /* private */
>>> + OBJ_PROP_ALIAS_CLASS = 0x1,
>>> +} ObjectPropertyAliasFlags;
>>> +
>>> /**
>>> * object_property_add_alias:
>>> * @obj: the object to add a property to
>>> @@ -2283,6 +2288,26 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
>>> ObjectProperty *object_property_add_alias(Object *obj, const char *name,
>>> Object *target_obj, const char *target_name);
>>>
>>> +/**
>>> + * object_class_property_add_alias:
>>> + * @klass: the object class to add a property to
>>> + * @name: the name of the property
>>> + * @offset: the offset from the object instance where the object alias is
>>> + * stored
>>> + * @target_type: QOM type we expect the alias to resolve to
>>> + * @target_name: the name of the property on the forwarded object
>>> + *
>>> + * Add an alias for a property on an object. This function will add a property
>>> + * of the same type as the forwarded property.
>>> + *
>>> + * Returns: The newly added property on success, or %NULL on failure.
>> actually, it assert() on error and never returns NULL.
>
> I was able to reproduce this by attempting to add a class alias property with the same name again, and then started to look at other related functions do to understand what the behaviour should be. There seems to be a number of existing issues here:
>
> - object_property_try_add() returns NULL in the case a property cannot
> be created (which seems to be only when an attempt to make add a
> property that already exists). However since object_property_add()
> always passes &error_abort, then QEMU terminates immediately without
> returning the NULL.
Convention: when we have a pair of functions FOO_try_BAR() and
FOO_BAR(), the former can fail and the latter cannot. The latter is
useful when failure would be a programming error.
When FOO_try_BAR() sets an Error on failure, FOO_BAR() is a thin wrapper
that passes &error_abort.
We pass &error_abort when failure would be a programming error. It's
more concise than "call then assert it didn't fail". Concise is good.
The wrapper makes calls that cannot fail even more concise. Worth
having only when there are plenty of callers that profit from that.
Someone decided this is the case for object_property_try_add() /
object_property_add().
> - object_class_property_add() will currently assert() if an attempt is
> made to add a duplicate property: it is fairly trivial to update it to
> return the same error that object_property_add() does, however it is
> interesting to note that the kernel-doc states that
> error_setg(&error_abort, ...) should NOT be used. However in this case
> it appears to return a genuinely helpful message which I think is
> worth keeping.
The only difference between object_class_property_add() and
object_property_add() should be where the property is recorded (class
vs. object). In particular, they should treat failure the same way.
This may make object_class_property_try_add() necessary.
> - There are several places in qom/object.c that do not check the
> return value of object_property_add() / object_class_property_add()
> such as object_add_link_prop(), object_property_add_alias() which
> could potentially dereference a NULL pointer.
object_property_add() is specified not to fail, i.e. not to return null.
It's a programming error if it does. Letting the program crash on
programming errors by dereferencing a null pointer is just fine. We can
dress up the crash with assert(obj), but I wouldn't bother.
Use object_property_add() when failure is a programming error. Use
object_property_try_add() and handle the error when it's not.
> It feels like the assumption is actually that these functions will &error_abort rather than returning NULL as indicated by the kernel-doc. Any thoughts on what we should do here? Ideally we want the same behaviour between the object_property*() and object_class_property*() functions to aid the transition.
Hope this helps!
[...]
next prev parent reply other threads:[~2026-09-18 9:05 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 14:40 [PATCH v3 0/8] hw/i386: convert object props to class props Mark Cave-Ayland
2026-09-02 14:40 ` [PATCH v3 1/8] qom/object.c: introduce object_alias_get_targetp() lookup function Mark Cave-Ayland
2026-09-02 14:40 ` [PATCH v3 2/8] qom/object.c: introduce object_class_property_add_alias() Mark Cave-Ayland
2026-09-17 8:52 ` Marc-André Lureau
2026-09-18 8:38 ` Mark Cave-Ayland
2026-09-18 9:04 ` Markus Armbruster [this message]
2026-09-21 9:06 ` Daniel P. Berrangé
2026-09-21 13:28 ` Markus Armbruster
2026-09-02 14:40 ` [PATCH v3 3/8] qom/object.c: introduce object_property_set_alias() function Mark Cave-Ayland
2026-09-02 14:40 ` [PATCH v3 4/8] hw/i386/pc.c: convert pcspk-audiodev object prop to a class prop Mark Cave-Ayland
2026-09-02 21:08 ` Philippe Mathieu-Daudé
2026-09-02 14:40 ` [PATCH v3 5/8] hw/i386/pc.c: convert rtc-time " Mark Cave-Ayland
2026-09-02 14:40 ` [PATCH v3 6/8] hw/i386/pc.c: convert PC_MACHINE_ACPI_DEVICE_PROP from object prop to " Mark Cave-Ayland
2026-09-02 14:40 ` [PATCH v3 7/8] hw/i386/pc_sysfw.c: convert pflash0 and pflash1 object props to class props Mark Cave-Ayland
2026-09-02 14:40 ` [PATCH v3 8/8] hw/i386/sgx-epc.c: convert SGX_EPC_SIZE_PROP object prop to class prop Mark Cave-Ayland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875x03nd5s.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mark.caveayland@nutanix.com \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.