From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, alex.bennee@linaro.org,
stefanha@redhat.com, peter.maydell@linaro.org,
Markus Armbruster <armbru@redhat.com>,
richard.henderson@linaro.org, pbonzini@redhat.com,
jsnow@redhat.com, philmd@linaro.org, thuth@redhat.com,
Michael Roth <michael.roth@amd.com>
Subject: Re: [PATCH 09/13] qapi: transform target specific 'if' in runtime checks
Date: Thu, 8 May 2025 13:48:46 -0700 [thread overview]
Message-ID: <c5c482b2-35a2-451d-a1b0-25f850167bc2@linaro.org> (raw)
In-Reply-To: <aBzCXNTebh8B5sQ_@redhat.com>
On 5/8/25 7:40 AM, Daniel P. Berrangé wrote:
> On Wed, May 07, 2025 at 04:14:39PM -0700, Pierrick Bouvier wrote:
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>> qapi/machine-target.json | 84 ++++++++++++++++++++++++----------------
>> qapi/misc-target.json | 48 ++++++++++++-----------
>> scripts/qapi/expr.py | 9 +++--
>> 3 files changed, 81 insertions(+), 60 deletions(-)
>>
>> diff --git a/qapi/machine-target.json b/qapi/machine-target.json
>> index 541f93eeb78..6174b7291ca 100644
>> --- a/qapi/machine-target.json
>> +++ b/qapi/machine-target.json
>> @@ -96,7 +96,7 @@
>> ##
>> { 'struct': 'CpuModelBaselineInfo',
>> 'data': { 'model': 'CpuModelInfo' },
>> - 'if': 'TARGET_S390X' }
>> + 'runtime_if': 'target_s390x()' }
>
> The existing 'if' conditions are already slightly uncomfortable
> for QAPI when considering alternate code generators, because the
> definition of what "CONFIG_xxx" or "TARGET_xxx" condition means,
> is essentially known only to our build system. While we expose
> the conditions in the docs, the meaning of those conditions is
> totally opaque to anyone reading the docs. Essentially our QAPI
> schema ceased to be self-documenting/self-describing when we
> introduced the 'if' conditions :-(
>
>
> In retrospect, IMHO, for 'if' conditions we probably should have
> created some kind of built-in QAPI concept of feature flag constants
> with well defined & documented meaning.
>
> eg hypothetically
>
> ##
> # @target-s390x
> #
> # Whether this is an s390x emulator target
> { 'constant': 'target-s390x' }
>
> ##
> # @accel-kvm
> #
> # Whether the KVM accelerator is built
> { 'constant': 'accel-kvm' }
>
> Then our 'if' conditions would have only been permitted to
> reference defined 'constant'.
>
> { 'struct': 'CpuModelCompareInfo',
> 'data': { 'result': 'CpuModelCompareResult',
> 'responsible-properties': ['str'] },
> 'if': 'target-s390x' }
>
> The build system would need generate an input document for the
> QAPI visitor that defines whether each constant is set to true
> or false, based on suitable CONFIG/TARGET conditions from meson.
>
> With this QAPI schemas would have remained fully self-contained.
>
> Anyway, this is a long way of saying that having 'runtime_if'
> conditions directly referencing the names of internal C
> functions makes me even more uncomfortable than I already am
> with the 'if' conditions.
>
I understand the concern.
However, one argument may be that QAPI json, as perfect as we could
expect they are, are simply known and used inside QEMU right now, which
is written in C at the moment.
Even if that assumption should change, I'm pretty sure we can create
functions named in the same way in C, python, Go, Rust or any other
languages we would like to generate code for.
It's not like if we started using complex expressions that only works in
nightly version of Rust.
> The meaning of the QAPI schema now varies based on both the build
> system, and an arbitrary amount of C, and is thus (conceptually)
> even more opaque, even if you could infer some meaning from the
> 'target_s390x()' function name you've used. I think this is a very
> undesirable characteristic for what is our public API definition.
>
Correct if I'm wrong, but it was said in previous threads that those
json are simply used and consumed by QEMU itself, and not by any
external projects.
I would be prudent to call this a public API definition, when it's just
a DSL for an ad-hoc code generator internal to QEMU.
> With regards,
> Daniel
Overall, and I would like to state it again, I'm really open to any
solution to get rid of TARGET_* compile time defines in QAPI json.
And I appreciate the solution you posted as well.
For now, it's blocking the single binary work, because any file pulling
QAPI definitions is tainted with TARGET_* defines, so we are blocked
waiting for them to be removed upstream, before being able to post a
series touching those files.
I hope we can get a clear answer from QAPI maintainers, so you or I can
take ownership of this and finish the work. From the previous thread, I
thought (and I may be wrong) that Markus was more enclined to the
current solution, but it was not entirely clear for me to be honest.
Let's hope that having both approaches implemented will give a good
insight of where things should go.
Thanks,
Pierrick
next prev parent reply other threads:[~2025-05-08 20:49 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 23:14 [PATCH 00/13] single-binary: make QAPI generated files common Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 01/13] qapi: introduce 'runtime_if' for QAPI json Pierrick Bouvier
2025-05-08 6:53 ` Philippe Mathieu-Daudé
2025-05-08 20:22 ` Pierrick Bouvier
2025-05-15 4:39 ` Markus Armbruster
2025-05-15 15:42 ` Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 02/13] qapi/introspect: generate schema as a QObject directly Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 03/13] qobject/qlit: allow to hide dict or list entries Pierrick Bouvier
2025-05-08 14:21 ` Daniel P. Berrangé
2025-05-08 20:25 ` Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 04/13] qapi/introspect: hide fields in schema Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 05/13] qapi/commands: register commands conditionally Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 06/13] qapi/visit: hide fields in JSON marshalling Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 07/13] qapi: add access to qemu/target-info.h Pierrick Bouvier
2025-05-08 6:57 ` Philippe Mathieu-Daudé
2025-05-07 23:14 ` [PATCH 08/13] qemu/target-info: implement missing helpers Pierrick Bouvier
2025-05-08 6:40 ` Philippe Mathieu-Daudé
2025-05-08 20:30 ` Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 09/13] qapi: transform target specific 'if' in runtime checks Pierrick Bouvier
2025-05-08 6:44 ` Philippe Mathieu-Daudé
2025-05-08 14:40 ` Daniel P. Berrangé
2025-05-08 20:48 ` Pierrick Bouvier [this message]
2025-05-10 6:57 ` Markus Armbruster
2025-05-13 0:36 ` Pierrick Bouvier
2025-05-13 7:08 ` Markus Armbruster
2025-05-13 22:52 ` Pierrick Bouvier
2025-05-14 7:13 ` Markus Armbruster
2025-05-14 16:54 ` Pierrick Bouvier
2025-05-14 14:09 ` Markus Armbruster
2025-05-14 16:50 ` Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 10/13] qapi: add weak stubs for target specific commands Pierrick Bouvier
2025-05-08 6:57 ` Philippe Mathieu-Daudé
2025-05-08 20:33 ` Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 11/13] qapi: make all generated files common Pierrick Bouvier
2025-05-08 6:57 ` Philippe Mathieu-Daudé
2025-05-07 23:14 ` [PATCH 13/13] [ANNEX] build/qapi: after series Pierrick Bouvier
2025-05-07 23:33 ` [PATCH 00/13] single-binary: make QAPI generated files common Pierrick Bouvier
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=c5c482b2-35a2-451d-a1b0-25f850167bc2@linaro.org \
--to=pierrick.bouvier@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=jsnow@redhat.com \
--cc=michael.roth@amd.com \
--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 \
/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).