qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Dr . David Alan Gilbert" <dave@treblig.org>,
	"Cédric Le Goater" <clg@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Alexandr Moshkov" <dtalexundeer@yandex-team.ru>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@yandex-team.ru>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Thomas Huth" <thuth@redhat.com>, "Kevin Wolf" <kwolf@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	peterx@redhat.com, "Juraj Marcin" <jmarcin@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Eric Blake" <eblake@redhat.com>
Subject: [PATCH RFC 01/10] qom: Introduce object-compat
Date: Tue,  9 Dec 2025 11:28:48 -0500	[thread overview]
Message-ID: <20251209162857.857593-2-peterx@redhat.com> (raw)
In-Reply-To: <20251209162857.857593-1-peterx@redhat.com>

QEMU provides machine compat properties so that old machine types can
define device properties, which will be compatible with old QEMU binaris.

This is the core of how QEMU manages VM ABI across migrations between
different versions of QEMUs.

It used to almost only work for qdev, which was almost enough.  There were
already outliers showed up:

  - do_configure_accelerator()
  - host_memory_backend_post_init()
  - sev_guest_instance_init()

They all invoke object_apply_compat_props() explicitly, because they want
to benefit from the machine compat properties too, just like normal qdevs.
However they're not qdev, hence they need explicit code to support it.

MigrationState object is another example that wants to use similar feature
of qdev.  That was previously done by making TYPE_MIGRATION inherit
TYPE_DEVICE.  See comments for migration_type.  That's working but weird,
e.g. people may question what "-device migration" means..

Nowadays, there're more demands of that, e.g., what if we want to allow
compat properties to be applied to device backends ([1,2])?

Maybe it's time to think about extending the compat properties to a root
class so that more objects can inherit.

This patch introduces object-compat, which is almost object except that it
also allows apply machine compat properties on top.  Then any object that
is not qdev but wants to benefit from machine compat properties can opt-in.

[1] https://lore.kernel.org/r/20251030203116.870742-1-vsementsov@yandex-team.ru
[2] https://lore.kernel.org/r/d986f0ac-a0ae-44f6-b7a5-e002b7d3226e@yandex-team.ru

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 include/qom/object.h |  1 +
 qom/object.c         | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index 26df6137b9..e5b3116ad5 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -26,6 +26,7 @@ typedef struct InterfaceClass InterfaceClass;
 typedef struct InterfaceInfo InterfaceInfo;
 
 #define TYPE_OBJECT "object"
+#define TYPE_OBJECT_COMPAT "object-compat"
 #define TYPE_CONTAINER "container"
 
 typedef struct ObjectProperty ObjectProperty;
diff --git a/qom/object.c b/qom/object.c
index 4f32c1aba7..581c041b08 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2893,6 +2893,11 @@ void object_class_property_set_description(ObjectClass *klass,
     op->description = g_strdup(description);
 }
 
+static void object_compat_post_init(Object *obj)
+{
+    object_apply_compat_props(obj);
+}
+
 static void object_class_init(ObjectClass *klass, const void *data)
 {
     object_class_property_add_str(klass, "type", object_get_type,
@@ -2914,8 +2919,17 @@ static void register_types(void)
         .abstract = true,
     };
 
+    static const TypeInfo object_compat_info = {
+        .parent = TYPE_OBJECT,
+        .name = TYPE_OBJECT_COMPAT,
+        .instance_size = sizeof(Object),
+        .instance_post_init = object_compat_post_init,
+        .abstract = true,
+    };
+
     type_interface = type_register_internal(&interface_info);
     type_register_internal(&object_info);
+    type_register_internal(&object_compat_info);
 }
 
 type_init(register_types)
-- 
2.50.1



  reply	other threads:[~2025-12-09 16:30 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-09 16:28 [PATCH RFC 00/10] QOM: Introduce OBJECT_COMPAT class Peter Xu
2025-12-09 16:28 ` Peter Xu [this message]
2025-12-09 16:28 ` [PATCH RFC 02/10] qdev: Inherit from TYPE_OBJECT_COMPAT Peter Xu
2025-12-09 16:28 ` [PATCH RFC 03/10] hostmem: " Peter Xu
2025-12-09 16:28 ` [PATCH RFC 04/10] accel: " Peter Xu
2025-12-09 16:28 ` [PATCH RFC 05/10] confidential guest support: " Peter Xu
2025-12-09 16:28 ` [PATCH RFC 06/10] qom: Unexport object_apply_compat_props() Peter Xu
2025-12-09 16:28 ` [PATCH RFC 07/10] qdev: Pave way for exporting Property to be used in non-qdev Peter Xu
2025-12-09 16:28 ` [PATCH RFC 08/10] qdev: Introduce helper object_apply_globals() Peter Xu
2025-12-09 16:28 ` [PATCH RFC 09/10] qdev: Refactor and rename of qdev_class_add_property() Peter Xu
2025-12-09 16:28 ` [PATCH RFC 10/10] migration: Inherit from TYPE_OBJECT_COMPAT Peter Xu
2025-12-10 11:27 ` [PATCH RFC 00/10] QOM: Introduce OBJECT_COMPAT class Kevin Wolf
2025-12-10 11:52   ` Daniel P. Berrangé
2025-12-10 16:17     ` Peter Xu
2025-12-10 18:25       ` Vladimir Sementsov-Ogievskiy
2025-12-10 20:15         ` Peter Xu
2025-12-11  9:48       ` Daniel P. Berrangé
2025-12-11 15:09         ` Peter Xu
2025-12-11 15:26           ` Daniel P. Berrangé
2025-12-11 16:05             ` Peter Xu
2025-12-11 15:28 ` Akihiko Odaki
2025-12-11 15:57   ` Peter Xu
2025-12-12  5:38     ` Akihiko Odaki
2025-12-11 16:29 ` Cédric Le Goater
2025-12-11 17:14   ` Peter Xu

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=20251209162857.857593-2-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=clg@redhat.com \
    --cc=dave@treblig.org \
    --cc=dtalexundeer@yandex-team.ru \
    --cc=eblake@redhat.com \
    --cc=farosas@suse.de \
    --cc=jasowang@redhat.com \
    --cc=jmarcin@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mst@redhat.com \
    --cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=vsementsov@yandex-team.ru \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).