qom: Restrict compat properties API to system emulation
Subsystems (3)
cover qom: Restrict compat properties API to system emulation
Remove QDev uses from QOM to help build the guest-agent binary without pulling in QDev methods.
After that only util/qsp.c is left (cond/mutex atomics), see this thread:
https://lore.kernel.org/qemu-devel/[email protected]/
Philippe Mathieu-Daudé (6):
MAINTAINERS: Separate QDev section from QOM one hw/core: Move compat_props_add() to 'hw/core/boards.h'
qom: Declare GlobalProperty structure in 'qom/compat-properties.h'
qom: Declare compat properties API in 'qom/compat-properties.h'
qom: Restrict compat properties API to system emulation
buildsys: Allow building guest-agent on 32-bit hosts
MAINTAINERS | 21 +++--- configure | 64 +++++++++++++---- meson.build | 2 +- include/hw/core/boards.h | 11 +++ include/hw/core/qdev-properties.h | 1 + include/hw/core/qdev.h | 27 ------- include/qom/compat-properties.h | 40 +++++++++++ include/qom/object.h | 8 --- accel/accel-system.c | 1 + backends/hostmem.c | 1 + hw/core/machine.c | 1 + hw/core/qdev-properties.c | 1 + hw/core/qdev.c | 1 + hw/i386/pc_q35.c | 1 + qom/compat-properties.c | 116 ++++++++++++++++++++++++++++++ qom/object.c | 102 +------------------------- system/rtc.c | 1 + system/vl.c | 1 + target/i386/sev.c | 1 + ui/vdagent.c | 1 + qom/meson.build | 3 + 21 files changed, 248 insertions(+), 157 deletions(-) create mode 100644 include/qom/compat-properties.h create mode 100644 qom/compat-properties.c
Signature · 1 line
2.53.0
PATCH 1/6 MAINTAINERS: Separate QDev section from QOM one
QDev is about QEMU devices model API, while
QOM is about QEMU object model in plain C.
--- MAINTAINERS | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
MAINTAINERS +13 -8
@@ -3546,24 +3546,29 @@ M: Paolo Bonzini <[email protected]> R: Daniel P. Berrange <[email protected]> S: Supported F: docs/devel/qom.rst +F: include/qom/ +F: qapi/qom.json +F: scripts/coccinelle/qom-parent-type.cocci +F: scripts/qom-cast-macro-clean-cocci-gen.py +F: qom/ +F: tests/unit/check-qom-interface.c +F: tests/unit/check-qom-proplist.c +F: tests/qtest/qom-test.c + +QDev +M: Paolo Bonzini <[email protected]> +R: Daniel P. Berrange <[email protected]> +S: Supported F: docs/qdev-device-use.txt F: hw/core/qdev* F: hw/core/bus.c F: hw/core/sysbus.c F: include/hw/qdev* F: include/monitor/qdev.h -F: include/qom/ -F: qapi/qom.json F: qapi/qdev.json -F: scripts/coccinelle/qom-parent-type.cocci -F: scripts/qom-cast-macro-clean-cocci-gen.py F: system/qdev-monitor.c F: stubs/qdev.c -F: qom/ -F: tests/unit/check-qom-interface.c -F: tests/unit/check-qom-proplist.c F: tests/unit/test-qdev-global-props.c -F: tests/qtest/qom-test.c QOM boilerplate conversion script S: Orphan
Signature · 1 line
2.53.0
PATCH 2/6 hw/core: Move compat_props_add() to 'hw/core/boards.h'
In reply to Philippe Mathieu-Daudécompat_props_add() is only used by board models, no need to expose it to any device model. Restrict by defining it only in "hw/core/boards.h".
--- include/hw/core/boards.h | 10 ++++++++++ include/hw/core/qdev.h | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-)
include/hw/core/boards.h +10 -0
@@ -804,6 +804,16 @@ struct MachineState { } \ }while (0 ) +static inline void +compat_props_add (GPtrArray *arr, +GlobalProperty props[],size_t nelem) +{ +int i; +for (i =0 ; i < nelem; i++) { +g_ptr_array_add (arr, (void *)&props[i]); + } +} +extern GlobalProperty hw_compat_10_2[];extern const size_t hw_compat_10_2_len;
include/hw/core/qdev.h +0 -10
@@ -421,16 +421,6 @@ typedef struct GlobalProperty {bool optional; } GlobalProperty; -static inline void -compat_props_add (GPtrArray *arr, -GlobalProperty props[],size_t nelem) -{ -int i; -for (i =0 ; i < nelem; i++) { -g_ptr_array_add (arr, (void *)&props[i]); - } -} -/*** Board API. This should go away once we have a machine config file. ***/ /**
Signature · 1 line
2.53.0
PATCH 3/6 qom: Declare GlobalProperty structure in 'qom/compat-properties.h'
In reply to Philippe Mathieu-DaudéWhile GlobalProperty is expected to only be used by QDev board layer, it is used by the lower QOM API, so define it in the qom/ namespace. This helps to build binary which use QOM but don't need the QDev layer.
--- include/hw/core/boards.h | 1 + include/hw/core/qdev-properties.h | 1 + include/hw/core/qdev.h | 17 ---------------- include/qom/compat-properties.h | 32 +++++++++++++++++++++++++++++++ qom/object.c | 2 +- 5 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 include/qom/compat-properties.h
include/hw/core/boards.h +1 -0
@@ -8,6 +8,7 @@#include "system/blockdev.h" #include "qapi/qapi-types-machine.h" #include "qemu/module.h" +#include "qom/compat-properties.h" #include "qom/object.h" #include "hw/core/cpu.h" #include "hw/core/resettable.h"
include/hw/core/qdev-properties.h +1 -0
@@ -1,6 +1,7 @@#ifndef QEMU_QDEV_PROPERTIES_H #define QEMU_QDEV_PROPERTIES_H +#include "qom/compat-properties.h" #include "hw/core/qdev.h" /**
include/hw/core/qdev.h +0 -17
@@ -404,23 +404,6 @@ struct BusState {ResettableState reset; }; -/** -* typedef GlobalProperty - a global property type -* -* @used: Set to true if property was used when initializing a device. -* @optional: If set to true, GlobalProperty will be skipped without errors -* if the property doesn't exist. -* -* An error is fatal for non-hotplugged devices, when the global is applied. -*/ -typedef struct GlobalProperty { -const char *driver; -const char *property; -const char *value; -bool used; -bool optional; -}GlobalProperty ; -/*** Board API. This should go away once we have a machine config file. ***/ /**
include/qom/compat-properties.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* QEMU Object Model +* +* Copyright IBM, Corp. 2011 +* +* Authors: +* Anthony Liguori <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef QEMU_COMPAT_PROPERTIES_H +#define QEMU_COMPAT_PROPERTIES_H + +/** +* typedef GlobalProperty - a global property type +* +* @used: Set to true if property was used when initializing a device. +* @optional: If set to true, GlobalProperty will be skipped without errors +* if the property doesn't exist. +* +* An error is fatal for non-hotplugged devices, when the global is applied. +*/ +typedef struct GlobalProperty { +const char *driver; +const char *property; +const char *value; +bool used; +bool optional; +}GlobalProperty ; + +#endif
qom/object.c +1 -1
@@ -11,8 +11,8 @@*/ #include "qemu/osdep.h" -#include "hw/core/qdev.h" #include "qapi/error.h" +#include "qom/compat-properties.h" #include "qom/object.h" #include "qom/object_interfaces.h" #include "qemu/cutils.h"
Signature · 1 line
2.53.0
PATCH 4/6 qom: Declare compat properties API in 'qom/compat-properties.h'
In reply to Philippe Mathieu-DaudéWhile most of QEMU files use the QOM concept, few of them use the compatibility properties API (mostly use in system emulation). Move its prototype to a new "qom/compat-properties.h" header, keeping "qom/object.h" for generic QOM.
--- include/qom/compat-properties.h | 8 ++++++++ include/qom/object.h | 8 -------- accel/accel-system.c | 1 + backends/hostmem.c | 1 + hw/core/machine.c | 1 + hw/core/qdev-properties.c | 1 + hw/core/qdev.c | 1 + hw/i386/pc_q35.c | 1 + system/rtc.c | 1 + system/vl.c | 1 + target/i386/sev.c | 1 + ui/vdagent.c | 1 + 12 files changed, 18 insertions(+), 8 deletions(-)
include/qom/compat-properties.h +8 -0
@@ -29,4 +29,12 @@ typedef struct GlobalProperty { bool optional; } GlobalProperty; +void object_set_machine_compat_props (GPtrArray *compat_props); +void object_set_accelerator_compat_props (GPtrArray *compat_props); +void object_register_sugar_prop (const char *driver,const char *prop, +const char *value,bool optional); +void object_apply_compat_props (Object *obj); +bool object_apply_global_props (Object *obj,const GPtrArray *props, +Error **errp); +#endif
include/qom/object.h +0 -8
@@ -700,14 +700,6 @@ Object *object_new_with_propv(const char *typename,Error **errp, va_list vargs); -bool object_apply_global_props (Object *obj,const GPtrArray *props, -Error **errp); -void object_set_machine_compat_props (GPtrArray *compat_props); -void object_set_accelerator_compat_props (GPtrArray *compat_props); -void object_register_sugar_prop (const char *driver,const char *prop, -const char *value,bool optional); -void object_apply_compat_props (Object *obj); -/** * object_set_props: * @obj: the object instance to set properties on
accel/accel-system.c +1 -0
@@ -25,6 +25,7 @@#include "qemu/osdep.h" #include "qemu/accel.h" +#include "qom/compat-properties.h" #include "qapi/qapi-commands-accelerator.h" #include "monitor/monitor.h" #include "hw/core/boards.h"
backends/hostmem.c +1 -0
@@ -18,6 +18,7 @@#include "qapi/qapi-builtin-visit.h" #include "qapi/visitor.h" #include "qemu/config-file.h" +#include "qom/compat-properties.h" #include "qom/object_interfaces.h" #include "qemu/mmap-alloc.h" #include "qemu/madvise.h"
hw/core/machine.c +1 -0
@@ -21,6 +21,7 @@#include "qapi/qapi-visit-machine.h" #include "qapi/qapi-commands-machine.h" #include "qemu/madvise.h" +#include "qom/compat-properties.h" #include "qom/object_interfaces.h" #include "system/cpus.h" #include "system/system.h"
hw/core/qdev-properties.c +1 -0
@@ -10,6 +10,7 @@#include "qemu/units.h" #include "qemu/cutils.h" #include "qdev-prop-internal.h" +#include "qom/compat-properties.h" #include "qom/qom-qobject.h" void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
hw/core/qdev.c +1 -0
@@ -32,6 +32,7 @@#include "qapi/visitor.h" #include "qemu/error-report.h" #include "qemu/option.h" +#include "qom/compat-properties.h" #include "hw/core/irq.h" #include "hw/core/qdev-properties.h" #include "hw/core/boards.h"
hw/i386/pc_q35.c +1 -0
@@ -56,6 +56,7 @@#include "hw/usb/hcd-uhci.h" #include "qapi/error.h" #include "qemu/error-report.h" +#include "qom/compat-properties.h" #include "system/numa.h" #include "hw/hyperv/vmbus-bridge.h" #include "hw/mem/nvdimm.h"
system/rtc.c +1 -0
@@ -28,6 +28,7 @@#include "qemu/error-report.h" #include "qemu/option.h" #include "qemu/timer.h" +#include "qom/compat-properties.h" #include "qom/object.h" #include "system/replay.h" #include "system/system.h"
system/vl.c +1 -0
@@ -119,6 +119,7 @@#include "qapi/string-input-visitor.h" #include "qapi/opts-visitor.h" #include "qapi/clone-visitor.h" +#include "qom/compat-properties.h" #include "qom/object_interfaces.h" #include "semihosting/semihost.h" #include "crypto/init.h"
target/i386/sev.c +1 -0
@@ -36,6 +36,7 @@#include "system/reset.h" #include "trace.h" #include "migration/blocker.h" +#include "qom/compat-properties.h" #include "qom/object.h" #include "monitor/monitor.h" #include "monitor/hmp.h"
ui/vdagent.c +1 -0
@@ -5,6 +5,7 @@#include "qemu/error-report.h" #include "qemu/option.h" #include "qemu/units.h" +#include "qom/compat-properties.h" #include "hw/core/qdev.h" #include "hw/core/qdev-properties.h" #include "migration/blocker.h"
Signature · 1 line
2.53.0
PATCH 5/6 qom: Restrict compat properties API to system emulation
In reply to Philippe Mathieu-DaudéMove compat properties API definitions to their own file unit, compile it only when system emulation is configured.
--- qom/compat-properties.c | 116 ++++++++++++++++++++++++++++++++++++++++ qom/object.c | 100 ---------------------------------- qom/meson.build | 3 ++ 3 files changed, 119 insertions(+), 100 deletions(-) create mode 100644 qom/compat-properties.c
qom/compat-properties.c new file +116 -0
@@ -0,0 +1,116 @@ +/* +* QEMU Object Model +* +* Copyright IBM, Corp. 2011 +* +* Authors: +* Anthony Liguori <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qom/compat-properties.h" +#include "qom/qom-qobject.h" +#include "hw/core/qdev.h" + +bool object_apply_global_props (Object *obj,const GPtrArray *props, +Error **errp) +{ +int i; + +if (!props) { +return true; + } + +for (i =0 ; i < props->len; i++) { +GlobalProperty *p =g_ptr_array_index (props, i); +Error *err =NULL ; + +if (object_dynamic_cast (obj, p->driver) ==NULL ) { +continue ; + } +if (p->optional && !object_property_find (obj, p->property)) { +continue ; + } + p->used = true; +if (!object_property_parse (obj, p->property, p->value, &err)) { +error_prepend (&err,"can't apply global %s.%s=%s: " , + p->driver, p->property, p->value); +/* +* If errp != NULL, propagate error and return. +* If errp == NULL, report a warning, but keep going +* with the remaining globals. +*/ +if (errp) { +error_propagate (errp, err); +return false; + }else { +warn_report_err (err); + } + } + } + +return true; +} + +/* +* Global property defaults +* Slot 0: accelerator's global property defaults +* Slot 1: machine's global property defaults +* Slot 2: global properties from legacy command line option +* Each is a GPtrArray of GlobalProperty. +* Applied in order, later entries override earlier ones. +*/ +static GPtrArray *object_compat_props[3 ]; + +/* +* Retrieve @GPtrArray for global property defined with options +* other than "-global". These are generally used for syntactic +* sugar and legacy command line options. +*/ +void object_register_sugar_prop (const char *driver,const char *prop, +const char *value,bool optional) +{ +GlobalProperty *g; +if (!object_compat_props[2 ]) { + object_compat_props[2 ] =g_ptr_array_new (); + } + g =g_new0 (GlobalProperty,1 ); + g->driver =g_strdup (driver); + g->property =g_strdup (prop); + g->value =g_strdup (value); + g->optional = optional; +g_ptr_array_add (object_compat_props[2 ], g); +} + +/* +* Set machine's global property defaults to @compat_props. +* May be called at most once. +*/ +void object_set_machine_compat_props (GPtrArray *compat_props) +{ +assert (!object_compat_props[1 ]); + object_compat_props[1 ] = compat_props; +} + +/* +* Set accelerator's global property defaults to @compat_props. +* May be called at most once. +*/ +void object_set_accelerator_compat_props (GPtrArray *compat_props) +{ +assert (!object_compat_props[0 ]); + object_compat_props[0 ] = compat_props; +} + +void object_apply_compat_props (Object *obj) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (object_compat_props); i++) { +object_apply_global_props (obj, object_compat_props[i], + i ==2 ? &error_fatal : &error_abort); + } +}
qom/object.c +0 -100
106 lines not on this page · raw message
qom/meson.build +3 -0
@@ -5,6 +5,9 @@ qom_ss.add(files( 'object_interfaces.c', 'qom-qobject.c', )) +if have_system + qom_ss.add(files('compat-properties.c')) +endif qmp_ss.add(files('qom-qmp-cmds.c')) system_ss.add(files('qom-hmp-cmds.c'))
Signature · 1 line
2.53.0
PATCH 6/6 buildsys: Allow building guest-agent on 32-bit hosts
In reply to Philippe Mathieu-DaudéPartially revert commit range 5053e0a65db...90e2e8ada7c.
--- configure | 64 +++++++++++++++++++++++++++++++++++++++++++---------- meson.build | 2 +- 2 files changed, 53 insertions(+), 13 deletions(-)
configure +52 -12
@@ -381,6 +381,8 @@ fi if test ! -z "$cpu" ; then # command line argument : +elif check_define __i386__ ; then + cpu="i386" elif check_define __x86_64__ ; then if check_define __ILP32__ ; then cpu="x32"
@@ -399,22 +401,30 @@ elif check_define _ARCH_PPC64 ; then else cpu="ppc64" fi -elif check_define __mips64 ; then - cpu="mips64" +elif check_define __mips__ ; then + if check_define __mips64 ; then + cpu="mips64" + fi elif check_define __s390__ ; then if check_define __s390x__ ; then cpu="s390x" else cpu="s390" fi -elif check_define __riscv && check_define _LP64 ; then - cpu="riscv64" +elif check_define __riscv ; then + if check_define _LP64 ; then + cpu="riscv64" + else + cpu="riscv32" + fi +elif check_define __arm__ ; then + cpu="arm" elif check_define __aarch64__ ; then cpu="aarch64" elif check_define __loongarch64 ; then cpu="loongarch64" elif check_define EMSCRIPTEN ; then - error_exit "wasm64 must be specified to the cpu flag" + error_exit "wasm32 or wasm64 must be specified to the cpu flag" else # Using uname is really broken, but it is just a fallback for architectures # that are going to use TCI anyway
@@ -440,6 +450,18 @@ case "$cpu" in linux_arch=arm64 ;; + armv*b|armv*l|arm) + cpu=arm + host_arch=arm + ;; + + i386|i486|i586|i686) + cpu="i386" + host_arch=i386 + linux_arch=x86 + CPU_CFLAGS="-m32" + ;; + loongarch*) cpu=loongarch64 host_arch=loongarch64
@@ -448,7 +470,7 @@ case "$cpu" in mips64*|mipsisa64*) cpu=mips64 - host_arch=mips64 + host_arch=mips linux_arch=mips ;;
@@ -464,8 +486,8 @@ case "$cpu" in CPU_CFLAGS="-m64 -mlittle-endian" ;; - riscv64) - host_arch=riscv64 + riscv32 | riscv64) + host_arch=riscv linux_arch=riscv ;;
@@ -500,6 +522,9 @@ case "$cpu" in linux_arch=x86 CPU_CFLAGS="-m64" ;; + wasm32) + CPU_CFLAGS="-m32" + ;; wasm64) CPU_CFLAGS="-m64 -sMEMORY64=$wasm64_memory64" ;;
@@ -1287,7 +1312,7 @@ EOF test "$bigendian" = no && rust_arch=${rust_arch}el ;; - riscv64) + riscv32|riscv64) # e.g. riscv64gc-unknown-linux-gnu, but riscv64-linux-android test "$android" = no && rust_arch=${rust_arch}gc ;;
@@ -1449,18 +1474,26 @@ probe_target_compiler() { container_image=debian-all-test-cross container_cross_prefix=aarch64-linux-gnu- ;; - alpha|hppa|m68k|mips|riscv64|sh4|sparc64) + hppa|m68k|mips|riscv64|sparc64) container_image=debian-all-test-cross ;; mips64) container_image=debian-all-test-cross container_cross_prefix=mips64-linux-gnuabi64- ;; - ppc|ppc64|ppc64le) + ppc64|ppc64le) container_image=debian-all-test-cross container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu- ;; + # debian-legacy-test-cross architectures (need Debian 11) + # - libc6.1-dev-alpha-cross: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1054412 + # - sh4-linux-user: binaries don't run with bookworm compiler + + alpha|sh4) + container_image=debian-legacy-test-cross + ;; + # architectures with individual containers aarch64)
@@ -1930,7 +1963,14 @@ if test "$skip_meson" = no; then if test "$cross_compile" = "yes"; then echo "[host_machine]" >> $cross echo "system = '$host_os'" >> $cross - echo "cpu_family = '$cpu'" >> $cross + case "$cpu" in + i386) + echo "cpu_family = 'x86'" >> $cross + ;; + *) + echo "cpu_family = '$cpu'" >> $cross + ;; + esac echo "cpu = '$cpu'" >> $cross if test "$bigendian" = "yes" ; then echo "endian = 'big'" >> $cross
meson.build +1 -1
@@ -323,7 +323,7 @@ endif # Compiler flags # ################## -if cc.sizeof('void *') < 8 +if not have_ga and cc.sizeof('void *') < 8 error('QEMU requires a 64-bit CPU host architecture') endif
Signature · 1 line
2.53.0
Quoted 7 lines · Philippe Mathieu-Daudé
Remove QDev uses from QOM to help build the guest-agent binary without pulling in QDev methods.
After that only
util/qsp.cis left (cond/mutex atomics), see this thread:
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 7 lines
Philippe Mathieu-Daudé (6):
MAINTAINERS: Separate QDev section from QOM one hw/core: Movecompat_props_add()to 'hw/core/boards.h'
qom: Declare GlobalProperty structure in 'qom/compat-properties.h'
qom: Declare compat properties API in 'qom/compat-properties.h'
qom: Restrict compat properties API to system emulation
buildsys: Allow building guest-agent on 32-bit hosts
Series:
This definitely helps with qemu-ga issue (a few steps closer to it, anyway), makes things better separated and cleaner, and might even be simple enough for 11.0. Though I'm not sure for the latter.
Thank you Philippe for this!
/mjt
Quoted 25 lines
MAINTAINERS | 21 +++--- configure | 64 +++++++++++++---- meson.build | 2 +- include/hw/core/boards.h | 11 +++ include/hw/core/qdev-properties.h | 1 + include/hw/core/qdev.h | 27 ------- include/qom/compat-properties.h | 40 +++++++++++ include/qom/object.h | 8 --- accel/accel-system.c | 1 + backends/hostmem.c | 1 + hw/core/machine.c | 1 + hw/core/qdev-properties.c | 1 + hw/core/qdev.c | 1 + hw/i386/pc_q35.c | 1 + qom/compat-properties.c | 116 ++++++++++++++++++++++++++++++ qom/object.c | 102 +------------------------- system/rtc.c | 1 + system/vl.c | 1 + target/i386/sev.c | 1 + ui/vdagent.c | 1 + qom/meson.build | 3 + 21 files changed, 248 insertions(+), 157 deletions(-)create mode 100644
include/qom/compat-properties.hcreate mode 100644qom/compat-properties.c
Quoted 6 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (6):
hw/core: Move
compat_props_add()to 'hw/core/boards.h'
qom: Declare GlobalProperty structure in 'qom/compat-properties.h'
qom: Declare compat properties API in 'qom/compat-properties.h'
qom: Restrict compat properties API to system emulation
Patches 1-5 queued, thanks.
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (6):
hw/core: Move
compat_props_add()to 'hw/core/boards.h'
qom: Declare GlobalProperty structure in 'qom/compat-properties.h'
qom: Declare compat properties API in 'qom/compat-properties.h'
qom: Restrict compat properties API to system emulationPatches 1-5 queued, thanks.
Thank you Philippe! I didn't push this definitely good stuff to 11.0 because at the time, that late in the release cycle, I wanted just the bare minimum to go.
/mjt