From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Yonggang Luo" <luoyonggang@gmail.com>,
"Daniel P. Berrangé" <berrange@redhat.com>
Subject: [PATCH 03/48] qom: define a TargetSpecific interface
Date: Thu, 12 Nov 2026 13:30:09 +0000 [thread overview]
Message-ID: <20261112133054.1977618-4-berrange@redhat.com> (raw)
In-Reply-To: <20261112133054.1977618-1-berrange@redhat.com>
This can be used to declare a type as being target specific.
Implementing the interface just records the target metadata,
applying the enforcement requires the object creation path to
call 'target_specific_class_check()' to validate the system
state.
This approach is intended to allow classes to be unconditionally
registered, which allows introspection at any time. The target
specific enforcement is applied at runtime in the object
creation codepaths that need to apply restrictions. This implies
that QOM class names must be globally unique across all targets
known to QEMU.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
include/qom/object_interfaces.h | 75 +++++++++++++++++++++++++++++++++
qom/object_interfaces.c | 31 ++++++++++++++
2 files changed, 106 insertions(+)
diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
index afd0fb93b2b..d222a3d7481 100644
--- a/include/qom/object_interfaces.h
+++ b/include/qom/object_interfaces.h
@@ -16,6 +16,17 @@ DECLARE_CLASS_CHECKERS(UserCreatableClass, USER_CREATABLE,
typedef struct UserCreatable UserCreatable;
+#define TYPE_TARGET_SPECIFIC "target-specific"
+
+typedef struct TargetSpecificClass TargetSpecificClass;
+DECLARE_CLASS_CHECKERS(TargetSpecificClass, TARGET_SPECIFIC,
+ TYPE_TARGET_SPECIFIC)
+#define TARGET_SPECIFIC(obj) \
+ INTERFACE_CHECK(TargetSpecific, (obj), \
+ TYPE_TARGET_SPECIFIC)
+
+typedef struct TargetSpecific TargetSpecific;
+
/**
* UserCreatableClass:
* @parent_class: the base class
@@ -167,4 +178,68 @@ bool user_creatable_del(const char *id, Error **errp);
*/
void user_creatable_cleanup(void);
+/**
+ * TargetSpecificClass:
+ * @parent_class: the base class
+ *
+ * Interface for classes that want to declare they have target
+ * specific restrictions. This is intended to allow classes to
+ * be registered and introspected unconditionally, while
+ * preventing creation of instances unless a compatible target
+ * is selected.
+ */
+struct TargetSpecificClass {
+ InterfaceClass parent_class;
+
+ /*
+ * Leave as 0 to indicate no target specific creation restrictions,
+ * or set to a bitmask of QEMU_ARCH_nnn constants to limit what
+ * targets it can be created under.
+ */
+ int targets;
+};
+
+
+/**
+ * target_specific_class_creatable:
+ * @oc: the object class to check
+ *
+ * Determine whether @oc implements the TargetSpecific
+ * interface and if so, whether its declared targets
+ * allow creation in the current system state.
+ *
+ * If @oc does not implement the TargetSpecific interface
+ * it is assumed there are no creation restrictions.
+ *
+ * If @oc implements the TargetSpecific interface but leaves
+ * the 'targets' field as zero, it is assumed there are
+ * no creation restrictions.
+ *
+ * If @oc implements the TargetSpecific interface and the
+ * 'targets' field is non-zero, it is compared to
+ * target_mask_selected() to determine if it is valid to
+ * create an instance of @oc.
+ *
+ * Returns: true if it is valid to create an instance of @oc
+ * in the current system state, false otherwise.
+ */
+bool target_specific_class_creatable(ObjectClass *oc);
+
+
+/**
+ * target_specific_class_check:
+ * @oc: the object class to check
+ * @errp: pointer to a NULL-initialized error object
+ *
+ * Check whether it is permitted to create an instance
+ * of @oc in the current system target state.
+ *
+ * This validates @oc against target_specific_class_creatable
+ * and sets @errp if it is not creatable.
+ *
+ * Returns: @oc if it is creatable, NULL otherwise with @errp set.
+ */
+ObjectClass *target_specific_class_check(ObjectClass *oc,
+ Error **errp);
+
#endif
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index d83c12744b7..f523a55b93a 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -20,6 +20,7 @@
#include "qapi/opts-visitor.h"
#include "qemu/config-file.h"
#include "qemu/keyval.h"
+#include "qemu/target-info.h"
#include "trace.h"
bool user_creatable_complete(UserCreatable *uc, Error **errp)
@@ -280,6 +281,30 @@ void user_creatable_cleanup(void)
object_unparent(object_get_objects_root());
}
+
+bool target_specific_class_creatable(ObjectClass *oc)
+{
+ TargetSpecificClass *tsc =
+ (TargetSpecificClass *)object_class_dynamic_cast(
+ oc, TYPE_TARGET_SPECIFIC);
+
+ return !tsc || !tsc->targets || (tsc->targets & target_mask_selected());
+}
+
+
+ObjectClass *target_specific_class_check(ObjectClass *oc,
+ Error **errp)
+{
+ if (!target_specific_class_creatable(oc)) {
+ error_setg(errp, "Object '%s' not compatible with selected target",
+ object_class_get_name(oc));
+ return NULL;
+ }
+
+ return oc;
+}
+
+
static void register_types(void)
{
static const TypeInfo uc_interface_info = {
@@ -287,8 +312,14 @@ static void register_types(void)
.parent = TYPE_INTERFACE,
.class_size = sizeof(UserCreatableClass),
};
+ static const TypeInfo ts_interface_info = {
+ .name = TYPE_TARGET_SPECIFIC,
+ .parent = TYPE_INTERFACE,
+ .class_size = sizeof(TargetSpecificClass),
+ };
type_register_static(&uc_interface_info);
+ type_register_static(&ts_interface_info);
}
type_init(register_types)
--
2.56.1
next prev parent reply other threads:[~2026-11-12 13:31 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 13:30 [PATCH 00/48] hw: resolve QOM type conflicts in multi-target builds Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 01/48] iotests: better heuristics to find I/O tests build/source dirs Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 02/48] target-info: add target_mask_selected() Daniel P. Berrangé
2026-11-12 13:30 ` Daniel P. Berrangé [this message]
2026-11-12 13:30 ` [PATCH 04/48] qom: define an Aliased interface Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 05/48] hw: tweak approach to setting alias in machine macros Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 06/48] hw/core: implement TYPE_ALIASED interface in machines Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 07/48] qapi: report multiple aliases in MachineInfo Daniel P. Berrangé
2026-11-13 7:41 ` Markus Armbruster
2026-11-12 13:30 ` [PATCH 08/48] system: report multiple machine aliases in help output Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 09/48] system: increase space for machine name in '-machine help' Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 10/48] system: resolve multiple aliases when creating machines Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 11/48] qapi: deprecate 'alias' field in MachineInfo Daniel P. Berrangé
2026-11-13 7:51 ` Markus Armbruster
2026-11-12 13:30 ` [PATCH 12/48] hw/arm: convert machines to use AliasedClass interface Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 13/48] hw/avr: " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 14/48] hw/hexagon: " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 15/48] hw/i386: " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 16/48] hw/loongarch: " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 17/48] hw/m68k: " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 18/48] hw/ppc: " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 19/48] hw/s390x: " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 20/48] include/hw: convert machine docs " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 21/48] hw: drop 'alias' field from MachineClass Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 22/48] hw/arm: rename the 'virt' machines to 'arm-virt' Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 23/48] hw/riscv: rename the 'virt' machines to 'riscv-virt' Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 24/48] hw/hexagon: rename the 'virt' machine to 'hexagon-virt' Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 25/48] hw/loongarch: rename the 'virt' machine to 'loongarch-virt' Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 26/48] hw/m68k: rename the 'virt' machine to 'm68k-virt' Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 27/48] hw/or1k: rename the 'virt' machine to 'or1k-virt' Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 28/48] hw/xtensa: rename the 'virt' machine to 'xtensa-virt' Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 29/48] system: stop sorting machine names based on 'family' Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 30/48] system: put machine aliases in alphbetical order Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 31/48] system: filter machine type list if a target is selected Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 32/48] hw/core: " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 33/48] system: filter machines based on target during creation Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 34/48] hw/core: implement TYPE_TARGET_SPECIFIC for machine Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 35/48] qapi: report target compatibility for machine types Daniel P. Berrangé
2026-11-13 7:53 ` Markus Armbruster
2026-11-12 13:30 ` [PATCH 36/48] hw/arm: declare arm machine targets Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 37/48] hw/hexagon: declare hexagon machine target Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 38/48] hw/m68k: declare m68k " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 39/48] hw/or1k: declare or1k " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 40/48] hw/riscv: declare riscv " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 41/48] accel: make TYPE_ACCEL_CPU name target independent Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 42/48] Revert "multi-target: restrict whpx-accel-*-cpu to matching target" Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 43/48] Revert "target/riscv/kvm: restrict kvm-accel-riscv-cpu to riscv targets" Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 44/48] Revert "target/riscv/tcg: restrict tcg-accel-riscv-cpu " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 45/48] qom: drop the 'is_available' callback from TypeInfo Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 46/48] hw/pci: unconditionally expose the 'loadparm' property Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 47/48] hw/scsi: " Daniel P. Berrangé
2026-11-12 13:30 ` [PATCH 48/48] hw/virtio/virtio-mem: unconditionally expose 'unplugged-inaccessible' Daniel P. Berrangé
2026-11-12 15:08 ` [PATCH 00/48] hw: resolve QOM type conflicts in multi-target builds Yonggang Luo
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=20261112133054.1977618-4-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=luoyonggang@gmail.com \
--cc=philmd@oss.qualcomm.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-devel@nongnu.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.