[PATCH 0/8] qom: pass TargetInfo to the is_available callback

Yonggang Luo posted 8 patches 1 month, 2 weeks ago
Failed in applying to current master (apply log)
MAINTAINERS                             |   2 +-
configs/targets/aarch64-softmmu.c       |  25 ------
configs/targets/arm-softmmu.c           |  25 ------
configs/targets/meson.build             |   6 --
configs/targets/riscv32-softmmu.c       |  24 -----
configs/targets/riscv64-softmmu.c       |  24 -----
hw/arm/aspeed_ast27x0-fc.c              |   2 +-
hw/arm/aspeed_ast27x0_evb.c             |   4 +-
hw/arm/raspi.c                          |   4 +-
hw/arm/raspi4b.c                        |   2 +-
hw/arm/virt.c                           |   4 +-
hw/m68k/virt.c                          |   4 +-
hw/or1k/virt.c                          |   2 +-
include/hw/core/cpu.h                   |   2 +-
include/qemu/module.h                   |   1 -
include/qemu/target-info-def.h          |  88 ++++++++++++++++++
include/qemu/target-info-impl.h         |  42 ---------
include/qemu/target-info-init.h         |  53 -----------
include/qemu/target-info-qom.h          |  31 -------
include/qemu/target-info.h              |  87 ++++--------------
include/qom/object.h                    |  12 ++-
meson.build                             |  52 ++++++++---
page-vary-common.c                      |   2 +-
page-vary-system.c                      |   2 +-
qom/object.c                            |   3 +-
scripts/gen-target-info.py              |  99 ++++++++++++++++++++
system/vl.c                             |   4 -
target-info-stub.c => target-info-def.c |   3 +-
target-info-qom.c                       |  60 -------------
target-info.c                           | 115 ++++++++++++------------
tests/qtest/fuzz/fuzz.c                 |   3 -
tests/unit/meson.build                  |   4 +
tests/unit/test-multi-target.c          |  12 +--
tests/unit/test-target-info.c           |  38 ++++++++
34 files changed, 379 insertions(+), 462 deletions(-)
delete mode 100644 configs/targets/aarch64-softmmu.c
delete mode 100644 configs/targets/arm-softmmu.c
delete mode 100644 configs/targets/meson.build
delete mode 100644 configs/targets/riscv32-softmmu.c
delete mode 100644 configs/targets/riscv64-softmmu.c
create mode 100644 include/qemu/target-info-def.h
delete mode 100644 include/qemu/target-info-impl.h
delete mode 100644 include/qemu/target-info-init.h
delete mode 100644 include/qemu/target-info-qom.h
create mode 100644 scripts/gen-target-info.py
rename target-info-stub.c => target-info-def.c (94%)
delete mode 100644 target-info-qom.c
create mode 100644 tests/unit/test-target-info.c
[PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Yonggang Luo 1 month, 2 weeks ago
This allows a combined binary to register machine types from all its targets.
Consequently, QMP `query-machines` can return machine entries from every
target, even when `none` is selected. For example, a client can query the
combined machine list with:

```json
{ "execute": "query-machines" }
```

The returned list includes the registered machine classes from all linked
targets. This is separate from selecting a machine: with `-target none`,
`-M virt` reports the targets that provide `virt` instead of choosing one
arbitrarily:

```text
qemu-system -target none -M virt
unsupported machine type: "virt" for target "none"
Available for targets:
  aarch64
  arm
```

It moves target_info() to a shared location so object.c can call it when
checking machine availability. The series also replaces QOM-based target-info
registration with a constructor list and passes TargetInfo to the
is_available callback.

Target metadata and architecture checks are generated from the configured
targets, there is too much arch to write biiolperate code. doing this for easier
Add TargetInfo* to is_available

The target-info API and implementation are shared, rather than compiled
separately for every target.

This series removes the per-target source files "configs/targets/*.c".
Their target-specific parameters are collected in a generated
target-info-def.c for each softmmu target. This lays the groundwork for
QEMU system builds in which target-info-def.c is the only target-specific
source file compiled for each target. Using the same filename lets
meson.build handle these definitions uniformly.

The series adds unit-test coverage for target info and multi-target builds.

Pierrick Bouvier (2):
  configs/targets: remove target info definitions
  target-info: rename target-info-stub.c in target-info-def.c

Yonggang Luo (6):
  target-info: rename target-info-impl.h to target-info-def.h
  target-info: replace QOM registration with a constructor list
  tests/unit: add target-info coverage for multi-target builds
  meson: load all target .mak files into target_mak_all
  target-info: Replace handwritten architecture checks with generated
    code
  qom: pass TargetInfo to is_available for later use

 MAINTAINERS                             |   2 +-
 configs/targets/aarch64-softmmu.c       |  25 ------
 configs/targets/arm-softmmu.c           |  25 ------
 configs/targets/meson.build             |   6 --
 configs/targets/riscv32-softmmu.c       |  24 -----
 configs/targets/riscv64-softmmu.c       |  24 -----
 hw/arm/aspeed_ast27x0-fc.c              |   2 +-
 hw/arm/aspeed_ast27x0_evb.c             |   4 +-
 hw/arm/raspi.c                          |   4 +-
 hw/arm/raspi4b.c                        |   2 +-
 hw/arm/virt.c                           |   4 +-
 hw/m68k/virt.c                          |   4 +-
 hw/or1k/virt.c                          |   2 +-
 include/hw/core/cpu.h                   |   2 +-
 include/qemu/module.h                   |   1 -
 include/qemu/target-info-def.h          |  88 ++++++++++++++++++
 include/qemu/target-info-impl.h         |  42 ---------
 include/qemu/target-info-init.h         |  53 -----------
 include/qemu/target-info-qom.h          |  31 -------
 include/qemu/target-info.h              |  87 ++++--------------
 include/qom/object.h                    |  12 ++-
 meson.build                             |  52 ++++++++---
 page-vary-common.c                      |   2 +-
 page-vary-system.c                      |   2 +-
 qom/object.c                            |   3 +-
 scripts/gen-target-info.py              |  99 ++++++++++++++++++++
 system/vl.c                             |   4 -
 target-info-stub.c => target-info-def.c |   3 +-
 target-info-qom.c                       |  60 -------------
 target-info.c                           | 115 ++++++++++++------------
 tests/qtest/fuzz/fuzz.c                 |   3 -
 tests/unit/meson.build                  |   4 +
 tests/unit/test-multi-target.c          |  12 +--
 tests/unit/test-target-info.c           |  38 ++++++++
 34 files changed, 379 insertions(+), 462 deletions(-)
 delete mode 100644 configs/targets/aarch64-softmmu.c
 delete mode 100644 configs/targets/arm-softmmu.c
 delete mode 100644 configs/targets/meson.build
 delete mode 100644 configs/targets/riscv32-softmmu.c
 delete mode 100644 configs/targets/riscv64-softmmu.c
 create mode 100644 include/qemu/target-info-def.h
 delete mode 100644 include/qemu/target-info-impl.h
 delete mode 100644 include/qemu/target-info-init.h
 delete mode 100644 include/qemu/target-info-qom.h
 create mode 100644 scripts/gen-target-info.py
 rename target-info-stub.c => target-info-def.c (94%)
 delete mode 100644 target-info-qom.c
 create mode 100644 tests/unit/test-target-info.c

-- 
2.55.0.windows.3
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Pierrick Bouvier 1 month, 2 weeks ago
On 10/7/2026 4:47 AM, Yonggang Luo wrote:
> This allows a combined binary to register machine types from all its targets.
> Consequently, QMP `query-machines` can return machine entries from every
> target, even when `none` is selected. For example, a client can query the
> combined machine list with:
> 
> ```json
> { "execute": "query-machines" }
> ```
> 
> The returned list includes the registered machine classes from all linked
> targets. This is separate from selecting a machine: with `-target none`,
> `-M virt` reports the targets that provide `virt` instead of choosing one
> arbitrarily:
> 
> ```text
> qemu-system -target none -M virt
> unsupported machine type: "virt" for target "none"
> Available for targets:
>   aarch64
>   arm
> ```
>

From the long conversation on a previous thread, I thought we reached
the conclusion that if we didn't expose any ambiguous name, then -target
option is unnecessary, or maybe I got lost on track of this thread.

https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/

I'm not sure which semantic we want to have with -target none. If there
is no ambiguous name registered, we just don't need it at all. It's a
win-win IMHO.

> It moves target_info() to a shared location so object.c can call it when
> checking machine availability. The series also replaces QOM-based target-info
> registration with a constructor list and passes TargetInfo to the
> is_available callback.
> 
> Target metadata and architecture checks are generated from the configured
> targets, there is too much arch to write biiolperate code. doing this for easier
> Add TargetInfo* to is_available
> 
> The target-info API and implementation are shared, rather than compiled
> separately for every target.
> 
> This series removes the per-target source files "configs/targets/*.c".
> Their target-specific parameters are collected in a generated
> target-info-def.c for each softmmu target. This lays the groundwork for
> QEMU system builds in which target-info-def.c is the only target-specific
> source file compiled for each target. Using the same filename lets
> meson.build handle these definitions uniformly.
> 
> The series adds unit-test coverage for target info and multi-target builds.
> 
> Pierrick Bouvier (2):
>   configs/targets: remove target info definitions
>   target-info: rename target-info-stub.c in target-info-def.c
> 
> Yonggang Luo (6):
>   target-info: rename target-info-impl.h to target-info-def.h
>   target-info: replace QOM registration with a constructor list
>   tests/unit: add target-info coverage for multi-target builds
>   meson: load all target .mak files into target_mak_all
>   target-info: Replace handwritten architecture checks with generated
>     code
>   qom: pass TargetInfo to is_available for later use
> 
>  MAINTAINERS                             |   2 +-
>  configs/targets/aarch64-softmmu.c       |  25 ------
>  configs/targets/arm-softmmu.c           |  25 ------
>  configs/targets/meson.build             |   6 --
>  configs/targets/riscv32-softmmu.c       |  24 -----
>  configs/targets/riscv64-softmmu.c       |  24 -----
>  hw/arm/aspeed_ast27x0-fc.c              |   2 +-
>  hw/arm/aspeed_ast27x0_evb.c             |   4 +-
>  hw/arm/raspi.c                          |   4 +-
>  hw/arm/raspi4b.c                        |   2 +-
>  hw/arm/virt.c                           |   4 +-
>  hw/m68k/virt.c                          |   4 +-
>  hw/or1k/virt.c                          |   2 +-
>  include/hw/core/cpu.h                   |   2 +-
>  include/qemu/module.h                   |   1 -
>  include/qemu/target-info-def.h          |  88 ++++++++++++++++++
>  include/qemu/target-info-impl.h         |  42 ---------
>  include/qemu/target-info-init.h         |  53 -----------
>  include/qemu/target-info-qom.h          |  31 -------
>  include/qemu/target-info.h              |  87 ++++--------------
>  include/qom/object.h                    |  12 ++-
>  meson.build                             |  52 ++++++++---
>  page-vary-common.c                      |   2 +-
>  page-vary-system.c                      |   2 +-
>  qom/object.c                            |   3 +-
>  scripts/gen-target-info.py              |  99 ++++++++++++++++++++
>  system/vl.c                             |   4 -
>  target-info-stub.c => target-info-def.c |   3 +-
>  target-info-qom.c                       |  60 -------------
>  target-info.c                           | 115 ++++++++++++------------
>  tests/qtest/fuzz/fuzz.c                 |   3 -
>  tests/unit/meson.build                  |   4 +
>  tests/unit/test-multi-target.c          |  12 +--
>  tests/unit/test-target-info.c           |  38 ++++++++
>  34 files changed, 379 insertions(+), 462 deletions(-)
>  delete mode 100644 configs/targets/aarch64-softmmu.c
>  delete mode 100644 configs/targets/arm-softmmu.c
>  delete mode 100644 configs/targets/meson.build
>  delete mode 100644 configs/targets/riscv32-softmmu.c
>  delete mode 100644 configs/targets/riscv64-softmmu.c
>  create mode 100644 include/qemu/target-info-def.h
>  delete mode 100644 include/qemu/target-info-impl.h
>  delete mode 100644 include/qemu/target-info-init.h
>  delete mode 100644 include/qemu/target-info-qom.h
>  create mode 100644 scripts/gen-target-info.py
>  rename target-info-stub.c => target-info-def.c (94%)
>  delete mode 100644 target-info-qom.c
>  create mode 100644 tests/unit/test-target-info.c
>
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Daniel P. Berrangé 1 month, 2 weeks ago
On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
> > This allows a combined binary to register machine types from all its targets.
> > Consequently, QMP `query-machines` can return machine entries from every
> > target, even when `none` is selected. For example, a client can query the
> > combined machine list with:
> > 
> > ```json
> > { "execute": "query-machines" }
> > ```
> > 
> > The returned list includes the registered machine classes from all linked
> > targets. This is separate from selecting a machine: with `-target none`,
> > `-M virt` reports the targets that provide `virt` instead of choosing one
> > arbitrarily:
> > 
> > ```text
> > qemu-system -target none -M virt
> > unsupported machine type: "virt" for target "none"
> > Available for targets:
> >   aarch64
> >   arm
> > ```
> >
> 
> From the long conversation on a previous thread, I thought we reached
> the conclusion that if we didn't expose any ambiguous name, then -target
> option is unnecessary, or maybe I got lost on track of this thread.
> 
> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
> 
> I'm not sure which semantic we want to have with -target none. If there
> is no ambiguous name registered, we just don't need it at all. It's a
> win-win IMHO.

Yes, if we expose unique names for every machine, then -target is then
redundant.

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Yonggang Luo 1 month, 2 weeks ago
On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
> > On 10/7/2026 4:47 AM, Yonggang Luo wrote:
> > > This allows a combined binary to register machine types from all its targets.
> > > Consequently, QMP `query-machines` can return machine entries from every
> > > target, even when `none` is selected. For example, a client can query the
> > > combined machine list with:
> > >
> > > ```json
> > > { "execute": "query-machines" }
> > > ```
> > >
> > > The returned list includes the registered machine classes from all linked
> > > targets. This is separate from selecting a machine: with `-target none`,
> > > `-M virt` reports the targets that provide `virt` instead of choosing one
> > > arbitrarily:
> > >
> > > ```text
> > > qemu-system -target none -M virt
> > > unsupported machine type: "virt" for target "none"
> > > Available for targets:
> > >   aarch64
> > >   arm
> > > ```
> > >
> >
> > From the long conversation on a previous thread, I thought we reached
> > the conclusion that if we didn't expose any ambiguous name, then -target
> > option is unnecessary, or maybe I got lost on track of this thread.
> >
> > https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
> >
> > I'm not sure which semantic we want to have with -target none. If there
> > is no ambiguous name registered, we just don't need it at all. It's a
> > win-win IMHO.
>
> Yes, if we expose unique names for every machine, then -target is then
> redundant.

so how to diff riscv32-virt and risv64-virt? oh so for this machine we
needs two name?
"virt" needs register twice for it? or register only a single time,
but we prefix the target_name()
automatically? for example machine::name === "virt", but we can use
"riscv32-virt" "risv64-virt" to reach it?

>
> With regards,
> Daniel
> --
> |: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
> |: https://libvirt.org          ~~          https://entangle-photo.org :|
> |: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
>


-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Pierrick Bouvier 1 month, 2 weeks ago
On 10/8/2026 2:46 AM, Yonggang Luo wrote:
> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>>
>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
>>>> This allows a combined binary to register machine types from all its targets.
>>>> Consequently, QMP `query-machines` can return machine entries from every
>>>> target, even when `none` is selected. For example, a client can query the
>>>> combined machine list with:
>>>>
>>>> ```json
>>>> { "execute": "query-machines" }
>>>> ```
>>>>
>>>> The returned list includes the registered machine classes from all linked
>>>> targets. This is separate from selecting a machine: with `-target none`,
>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
>>>> arbitrarily:
>>>>
>>>> ```text
>>>> qemu-system -target none -M virt
>>>> unsupported machine type: "virt" for target "none"
>>>> Available for targets:
>>>>   aarch64
>>>>   arm
>>>> ```
>>>>
>>>
>>> From the long conversation on a previous thread, I thought we reached
>>> the conclusion that if we didn't expose any ambiguous name, then -target
>>> option is unnecessary, or maybe I got lost on track of this thread.
>>>
>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
>>>
>>> I'm not sure which semantic we want to have with -target none. If there
>>> is no ambiguous name registered, we just don't need it at all. It's a
>>> win-win IMHO.
>>
>> Yes, if we expose unique names for every machine, then -target is then
>> redundant.
> 
> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
> needs two name?
> "virt" needs register twice for it? or register only a single time,
> but we prefix the target_name()
> automatically? for example machine::name === "virt", but we can use
> "riscv32-virt" "risv64-virt" to reach it?
>

Yes, ideally we should have different variant of virt for 32/64 bit.
Same goes for cpu max types.

QOM type is always registered unambiguously ("$arch-virt"). Then, for
the "alias" name, which is virt, in case multiple matches are found,
command line can return an error with list of unambiguous names to call it.

$ qemu-system -M virt
Multiple virt machines are available. Please choose one of them:
- aarch64-virt
- riscv64-virt

There is no "parsing" of the argument, it's just the real QOM type. Then
we can find which target it implements from mc->targets.
And then, we can automatically choose which cpus should be available
based on that, thanks to cpu->targets.

For existing binaries, nothing change.

>>
>> With regards,
>> Daniel
>> --
>> |: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
>> |: https://libvirt.org          ~~          https://entangle-photo.org :|
>> |: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
>>
> 
> 


Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Yonggang Luo 1 month, 2 weeks ago
On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
<pierrick.bouvier@oss.qualcomm.com> wrote:
>
> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
> > On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >>
> >> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
> >>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
> >>>> This allows a combined binary to register machine types from all its targets.
> >>>> Consequently, QMP `query-machines` can return machine entries from every
> >>>> target, even when `none` is selected. For example, a client can query the
> >>>> combined machine list with:
> >>>>
> >>>> ```json
> >>>> { "execute": "query-machines" }
> >>>> ```
> >>>>
> >>>> The returned list includes the registered machine classes from all linked
> >>>> targets. This is separate from selecting a machine: with `-target none`,
> >>>> `-M virt` reports the targets that provide `virt` instead of choosing one
> >>>> arbitrarily:
> >>>>
> >>>> ```text
> >>>> qemu-system -target none -M virt
> >>>> unsupported machine type: "virt" for target "none"
> >>>> Available for targets:
> >>>>   aarch64
> >>>>   arm
> >>>> ```
> >>>>
> >>>
> >>> From the long conversation on a previous thread, I thought we reached
> >>> the conclusion that if we didn't expose any ambiguous name, then -target
> >>> option is unnecessary, or maybe I got lost on track of this thread.
> >>>
> >>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
> >>>
> >>> I'm not sure which semantic we want to have with -target none. If there
> >>> is no ambiguous name registered, we just don't need it at all. It's a
> >>> win-win IMHO.
> >>
> >> Yes, if we expose unique names for every machine, then -target is then
> >> redundant.
> >
> > so how to diff riscv32-virt and risv64-virt? oh so for this machine we
> > needs two name?
> > "virt" needs register twice for it? or register only a single time,
> > but we prefix the target_name()
> > automatically? for example machine::name === "virt", but we can use
> > "riscv32-virt" "risv64-virt" to reach it?
> >
>
> Yes, ideally we should have different variant of virt for 32/64 bit.
> Same goes for cpu max types.
>
> QOM type is always registered unambiguously ("$arch-virt"). Then, for
> the "alias" name, which is virt, in case multiple matches are found,
> command line can return an error with list of unambiguous names to call it.
>
> $ qemu-system -M virt
> Multiple virt machines are available. Please choose one of them:
> - aarch64-virt
> - riscv64-virt
>
> There is no "parsing" of the argument, it's just the real QOM type. Then
> we can find which target it implements from mc->targets.
> And then, we can automatically choose which cpus should be available
> based on that, thanks to cpu->targets.
>
> For existing binaries, nothing change.

Good, I think we found a clean way now, is_available should be
removed, and TypeInfo::targets and TypeImpl::targets should be added.
I think
for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
the $arch specific virt. so that we only have a single "virt" registered.
And it's
targets is
QEMU_ARCH_I386 |
QEMU_ARCH_ARM |
QEMU_ARCH_RISCV |
QEMU_ARCH_LOONGARCH |
QEMU_ARCH_M68K |
QEMU_ARCH_OR1K |
QEMU_ARCH_XTENSA |
QEMU_ARCH_HEXAGON

So that we won't have a list of conflict QOM names for "virt" machines.
As now we indeed have only a single "virt" machine that redirects to
different targets.


For other types also conflict can be handled in the same way, such as
"-cpu host" "-cpu max"
maybe others, but I think they all have the same way to deal with.


That's why  TypeInfo::targets and TypeImpl::targets better than sole
Machine::targets

>
> >>
> >> With regards,
> >> Daniel
> >> --
> >> |: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
> >> |: https://libvirt.org          ~~          https://entangle-photo.org :|
> >> |: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
> >>
> >
> >
>


-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Pierrick Bouvier 1 month, 2 weeks ago
On 10/8/2026 10:13 AM, Yonggang Luo wrote:
> On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>
>> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
>>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>>>>
>>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
>>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
>>>>>> This allows a combined binary to register machine types from all its targets.
>>>>>> Consequently, QMP `query-machines` can return machine entries from every
>>>>>> target, even when `none` is selected. For example, a client can query the
>>>>>> combined machine list with:
>>>>>>
>>>>>> ```json
>>>>>> { "execute": "query-machines" }
>>>>>> ```
>>>>>>
>>>>>> The returned list includes the registered machine classes from all linked
>>>>>> targets. This is separate from selecting a machine: with `-target none`,
>>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
>>>>>> arbitrarily:
>>>>>>
>>>>>> ```text
>>>>>> qemu-system -target none -M virt
>>>>>> unsupported machine type: "virt" for target "none"
>>>>>> Available for targets:
>>>>>>   aarch64
>>>>>>   arm
>>>>>> ```
>>>>>>
>>>>>
>>>>> From the long conversation on a previous thread, I thought we reached
>>>>> the conclusion that if we didn't expose any ambiguous name, then -target
>>>>> option is unnecessary, or maybe I got lost on track of this thread.
>>>>>
>>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
>>>>>
>>>>> I'm not sure which semantic we want to have with -target none. If there
>>>>> is no ambiguous name registered, we just don't need it at all. It's a
>>>>> win-win IMHO.
>>>>
>>>> Yes, if we expose unique names for every machine, then -target is then
>>>> redundant.
>>>
>>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
>>> needs two name?
>>> "virt" needs register twice for it? or register only a single time,
>>> but we prefix the target_name()
>>> automatically? for example machine::name === "virt", but we can use
>>> "riscv32-virt" "risv64-virt" to reach it?
>>>
>>
>> Yes, ideally we should have different variant of virt for 32/64 bit.
>> Same goes for cpu max types.
>>
>> QOM type is always registered unambiguously ("$arch-virt"). Then, for
>> the "alias" name, which is virt, in case multiple matches are found,
>> command line can return an error with list of unambiguous names to call it.
>>
>> $ qemu-system -M virt
>> Multiple virt machines are available. Please choose one of them:
>> - aarch64-virt
>> - riscv64-virt
>>
>> There is no "parsing" of the argument, it's just the real QOM type. Then
>> we can find which target it implements from mc->targets.
>> And then, we can automatically choose which cpus should be available
>> based on that, thanks to cpu->targets.
>>
>> For existing binaries, nothing change.
> 
> Good, I think we found a clean way now, is_available should be
> removed, and TypeInfo::targets and TypeImpl::targets should be added.

It goes into MachineClass only for now.

> I think
> for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
> the $arch specific virt. so that we only have a single "virt" registered.
> And it's
> targets is
> QEMU_ARCH_I386 |
> QEMU_ARCH_ARM |
> QEMU_ARCH_RISCV |
> QEMU_ARCH_LOONGARCH |
> QEMU_ARCH_M68K |
> QEMU_ARCH_OR1K |
> QEMU_ARCH_XTENSA |
> QEMU_ARCH_HEXAGON
> 
> So that we won't have a list of conflict QOM names for "virt" machines.
> As now we indeed have only a single "virt" machine that redirects to
> different targets.
>

The idea looks appealing, but I don't think it solves the problem to
have multiple virt variants available at the same time.

The "alias" idea you introduced before is good, we just need to add a
check if an alias is really unique, else return an error, as explained
previously.

If "-M aarch64-virt" works for both the new and existing binary, and -M
virt only for existing binaries (and ambiguous for new one), I think
that's a safe approach.

> 
> For other types also conflict can be handled in the same way, such as
> "-cpu host" "-cpu max"
> maybe others, but I think they all have the same way to deal with.
> 
> 
> That's why  TypeInfo::targets and TypeImpl::targets better than sole
> Machine::targets
>

One step at a time.
Let's keep focused on declaring targets for a single machine first.
Then we can iterate to solve the "virt" problem.
Then convert all the existing machines and add a check in machine-target.c
Then, and only then, we can see what happens with cpus.

Regards,
Pierrick

Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Yonggang Luo 1 month, 1 week ago
On Fri, Oct 9, 2026 at 2:34 AM Pierrick Bouvier
<pierrick.bouvier@oss.qualcomm.com> wrote:
>
> On 10/8/2026 10:13 AM, Yonggang Luo wrote:
> > On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
> > <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>
> >> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
> >>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >>>>
> >>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
> >>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
> >>>>>> This allows a combined binary to register machine types from all its targets.
> >>>>>> Consequently, QMP `query-machines` can return machine entries from every
> >>>>>> target, even when `none` is selected. For example, a client can query the
> >>>>>> combined machine list with:
> >>>>>>
> >>>>>> ```json
> >>>>>> { "execute": "query-machines" }
> >>>>>> ```
> >>>>>>
> >>>>>> The returned list includes the registered machine classes from all linked
> >>>>>> targets. This is separate from selecting a machine: with `-target none`,
> >>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
> >>>>>> arbitrarily:
> >>>>>>
> >>>>>> ```text
> >>>>>> qemu-system -target none -M virt
> >>>>>> unsupported machine type: "virt" for target "none"
> >>>>>> Available for targets:
> >>>>>>   aarch64
> >>>>>>   arm
> >>>>>> ```
> >>>>>>
> >>>>>
> >>>>> From the long conversation on a previous thread, I thought we reached
> >>>>> the conclusion that if we didn't expose any ambiguous name, then -target
> >>>>> option is unnecessary, or maybe I got lost on track of this thread.
> >>>>>
> >>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
> >>>>>
> >>>>> I'm not sure which semantic we want to have with -target none. If there
> >>>>> is no ambiguous name registered, we just don't need it at all. It's a
> >>>>> win-win IMHO.
> >>>>
> >>>> Yes, if we expose unique names for every machine, then -target is then
> >>>> redundant.
> >>>
> >>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
> >>> needs two name?
> >>> "virt" needs register twice for it? or register only a single time,
> >>> but we prefix the target_name()
> >>> automatically? for example machine::name === "virt", but we can use
> >>> "riscv32-virt" "risv64-virt" to reach it?
> >>>
> >>
> >> Yes, ideally we should have different variant of virt for 32/64 bit.
> >> Same goes for cpu max types.
> >>
> >> QOM type is always registered unambiguously ("$arch-virt"). Then, for
> >> the "alias" name, which is virt, in case multiple matches are found,
> >> command line can return an error with list of unambiguous names to call it.
> >>
> >> $ qemu-system -M virt
> >> Multiple virt machines are available. Please choose one of them:
> >> - aarch64-virt
> >> - riscv64-virt
> >>
> >> There is no "parsing" of the argument, it's just the real QOM type. Then
> >> we can find which target it implements from mc->targets.
> >> And then, we can automatically choose which cpus should be available
> >> based on that, thanks to cpu->targets.
> >>
> >> For existing binaries, nothing change.
> >
> > Good, I think we found a clean way now, is_available should be
> > removed, and TypeInfo::targets and TypeImpl::targets should be added.
>
> It goes into MachineClass only for now.
>
> > I think
> > for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
> > the $arch specific virt. so that we only have a single "virt" registered.
> > And it's
> > targets is
> > QEMU_ARCH_I386 |
> > QEMU_ARCH_ARM |
> > QEMU_ARCH_RISCV |
> > QEMU_ARCH_LOONGARCH |
> > QEMU_ARCH_M68K |
> > QEMU_ARCH_OR1K |
> > QEMU_ARCH_XTENSA |
> > QEMU_ARCH_HEXAGON
> >
> > So that we won't have a list of conflict QOM names for "virt" machines.
> > As now we indeed have only a single "virt" machine that redirects to
> > different targets.
> >
>
> The idea looks appealing, but I don't think it solves the problem to
> have multiple virt variants available at the same time.
>
> The "alias" idea you introduced before is good, we just need to add a
> check if an alias is really unique, else return an error, as explained
> previously.
>
> If "-M aarch64-virt" works for both the new and existing binary, and -M
> virt only for existing binaries (and ambiguous for new one), I think
> that's a safe approach.
>
> >
> > For other types also conflict can be handled in the same way, such as
> > "-cpu host" "-cpu max"
> > maybe others, but I think they all have the same way to deal with.
> >
> >
> > That's why  TypeInfo::targets and TypeImpl::targets better than sole
> > Machine::targets
> >
>
> One step at a time.
> Let's keep focused on declaring targets for a single machine first.
> Then we can iterate to solve the "virt" problem.
> Then convert all the existing machines and add a check in machine-target.c
> Then, and only then, we can see what happens with cpus.
>
> Regards,
> Pierrick

Hi Pierrick,
this is something I have to do, please have a look

 target-info.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/target-info.c b/target-info.c
index 6c5c732eba9..b5d0dce1a87 100644
--- a/target-info.c
+++ b/target-info.c
@@ -43,55 +43,61 @@ bool target_big_endian(void)
     return target_endian_mode() == ENDIAN_MODE_BIG;
 }

+static bool target_arch_matches(uint64_t mask)
+{
+    return target_combined_binary() ||
+           (mask & (1ULL << target_arch())) != 0;
+}
+
 bool target_base_arm(void)
 {
-    return (QEMU_ARCH_ARM & (1ULL << target_arch())) != 0;
+    return target_arch_matches(QEMU_ARCH_ARM);
 }

 bool target_arm(void)
 {
-    return target_arch() == EMU_TARGET_ARM ||
-           target_arch() == EMU_TARGET_ARMEB;
+    return target_arch_matches((1ULL << EMU_TARGET_ARM) |
+                               (1ULL << EMU_TARGET_ARMEB));
 }

 bool target_aarch64(void)
 {
-    return target_arch() == EMU_TARGET_AARCH64 ||
-           target_arch() == EMU_TARGET_AARCH64_BE;
+    return target_arch_matches((1ULL << EMU_TARGET_AARCH64) |
+                               (1ULL << EMU_TARGET_AARCH64_BE));
 }

 bool target_m68k(void)
 {
-    return target_arch() == EMU_TARGET_M68K;
+    return target_arch_matches(1ULL << EMU_TARGET_M68K);
 }

 bool target_or1k(void)
 {
-    return target_arch() == EMU_TARGET_OR1K;
+    return target_arch_matches(1ULL << EMU_TARGET_OR1K);
 }

 bool target_base_ppc(void)
 {
-    return (QEMU_ARCH_PPC & (1ULL << target_arch())) != 0;
+    return target_arch_matches(QEMU_ARCH_PPC);
 }

 bool target_ppc(void)
 {
-    return target_arch() == EMU_TARGET_PPC;
+    return target_arch_matches(1ULL << EMU_TARGET_PPC);
 }

 bool target_ppc64(void)
 {
-    return target_arch() == EMU_TARGET_PPC64 ||
-           target_arch() == EMU_TARGET_PPC64LE;
+    return target_arch_matches((1ULL << EMU_TARGET_PPC64) |
+                               (1ULL << EMU_TARGET_PPC64LE));
 }

 bool target_s390x(void)
 {
-    return target_arch() == EMU_TARGET_S390X;
+    return target_arch_matches(1ULL << EMU_TARGET_S390X);
 }

 bool target_riscv64(void)
 {
-    return target_arch() == EMU_TARGET_RISCV64;
+    return target_arch_matches(1ULL << EMU_TARGET_RISCV64);
 }


-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Yonggang Luo 1 month, 1 week ago
On Fri, Oct 9, 2026 at 2:34 AM Pierrick Bouvier
<pierrick.bouvier@oss.qualcomm.com> wrote:
>
> On 10/8/2026 10:13 AM, Yonggang Luo wrote:
> > On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
> > <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>
> >> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
> >>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >>>>
> >>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
> >>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
> >>>>>> This allows a combined binary to register machine types from all its targets.
> >>>>>> Consequently, QMP `query-machines` can return machine entries from every
> >>>>>> target, even when `none` is selected. For example, a client can query the
> >>>>>> combined machine list with:
> >>>>>>
> >>>>>> ```json
> >>>>>> { "execute": "query-machines" }
> >>>>>> ```
> >>>>>>
> >>>>>> The returned list includes the registered machine classes from all linked
> >>>>>> targets. This is separate from selecting a machine: with `-target none`,
> >>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
> >>>>>> arbitrarily:
> >>>>>>
> >>>>>> ```text
> >>>>>> qemu-system -target none -M virt
> >>>>>> unsupported machine type: "virt" for target "none"
> >>>>>> Available for targets:
> >>>>>>   aarch64
> >>>>>>   arm
> >>>>>> ```
> >>>>>>
> >>>>>
> >>>>> From the long conversation on a previous thread, I thought we reached
> >>>>> the conclusion that if we didn't expose any ambiguous name, then -target
> >>>>> option is unnecessary, or maybe I got lost on track of this thread.
> >>>>>
> >>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
> >>>>>
> >>>>> I'm not sure which semantic we want to have with -target none. If there
> >>>>> is no ambiguous name registered, we just don't need it at all. It's a
> >>>>> win-win IMHO.
> >>>>
> >>>> Yes, if we expose unique names for every machine, then -target is then
> >>>> redundant.
> >>>
> >>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
> >>> needs two name?
> >>> "virt" needs register twice for it? or register only a single time,
> >>> but we prefix the target_name()
> >>> automatically? for example machine::name === "virt", but we can use
> >>> "riscv32-virt" "risv64-virt" to reach it?
> >>>
> >>
> >> Yes, ideally we should have different variant of virt for 32/64 bit.
> >> Same goes for cpu max types.
> >>
> >> QOM type is always registered unambiguously ("$arch-virt"). Then, for
> >> the "alias" name, which is virt, in case multiple matches are found,
> >> command line can return an error with list of unambiguous names to call it.
> >>
> >> $ qemu-system -M virt
> >> Multiple virt machines are available. Please choose one of them:
> >> - aarch64-virt
> >> - riscv64-virt
> >>
> >> There is no "parsing" of the argument, it's just the real QOM type. Then
> >> we can find which target it implements from mc->targets.
> >> And then, we can automatically choose which cpus should be available
> >> based on that, thanks to cpu->targets.
> >>
> >> For existing binaries, nothing change.
> >
> > Good, I think we found a clean way now, is_available should be
> > removed, and TypeInfo::targets and TypeImpl::targets should be added.
>
> It goes into MachineClass only for now.
>
> > I think
> > for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
> > the $arch specific virt. so that we only have a single "virt" registered.
> > And it's
> > targets is
> > QEMU_ARCH_I386 |
> > QEMU_ARCH_ARM |
> > QEMU_ARCH_RISCV |
> > QEMU_ARCH_LOONGARCH |
> > QEMU_ARCH_M68K |
> > QEMU_ARCH_OR1K |
> > QEMU_ARCH_XTENSA |
> > QEMU_ARCH_HEXAGON
> >
> > So that we won't have a list of conflict QOM names for "virt" machines.
> > As now we indeed have only a single "virt" machine that redirects to
> > different targets.
> >
>
> The idea looks appealing, but I don't think it solves the problem to
> have multiple virt variants available at the same time.
>
> The "alias" idea you introduced before is good, we just need to add a
> check if an alias is really unique, else return an error, as explained
> previously.
>
> If "-M aarch64-virt" works for both the new and existing binary, and -M
> virt only for existing binaries (and ambiguous for new one), I think
> that's a safe approach.
>
> >
> > For other types also conflict can be handled in the same way, such as
> > "-cpu host" "-cpu max"
> > maybe others, but I think they all have the same way to deal with.
> >
> >
> > That's why  TypeInfo::targets and TypeImpl::targets better than sole
> > Machine::targets
> >
>
> One step at a time.
> Let's keep focused on declaring targets for a single machine first.
> Then we can iterate to solve the "virt" problem.
> Then convert all the existing machines and add a check in machine-target.c
> Then, and only then, we can see what happens with cpus.

I tried this idea, but I faced a fatal error, because the
target_info() is not available until
the machine selected(the target arch will be select just along with
the machine selected), so basically
all calls to target_info() would raise an error(null pointer), how to
deal with it?

>
> Regards,
> Pierrick



-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Pierrick Bouvier 1 month, 1 week ago
On 10/11/26 1:22 PM, Yonggang Luo wrote:
> On Fri, Oct 9, 2026 at 2:34 AM Pierrick Bouvier
> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>
>> On 10/8/2026 10:13 AM, Yonggang Luo wrote:
>>> On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>>
>>>> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
>>>>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>>>>>>
>>>>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
>>>>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
>>>>>>>> This allows a combined binary to register machine types from all its targets.
>>>>>>>> Consequently, QMP `query-machines` can return machine entries from every
>>>>>>>> target, even when `none` is selected. For example, a client can query the
>>>>>>>> combined machine list with:
>>>>>>>>
>>>>>>>> ```json
>>>>>>>> { "execute": "query-machines" }
>>>>>>>> ```
>>>>>>>>
>>>>>>>> The returned list includes the registered machine classes from all linked
>>>>>>>> targets. This is separate from selecting a machine: with `-target none`,
>>>>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
>>>>>>>> arbitrarily:
>>>>>>>>
>>>>>>>> ```text
>>>>>>>> qemu-system -target none -M virt
>>>>>>>> unsupported machine type: "virt" for target "none"
>>>>>>>> Available for targets:
>>>>>>>>    aarch64
>>>>>>>>    arm
>>>>>>>> ```
>>>>>>>>
>>>>>>>
>>>>>>>  From the long conversation on a previous thread, I thought we reached
>>>>>>> the conclusion that if we didn't expose any ambiguous name, then -target
>>>>>>> option is unnecessary, or maybe I got lost on track of this thread.
>>>>>>>
>>>>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
>>>>>>>
>>>>>>> I'm not sure which semantic we want to have with -target none. If there
>>>>>>> is no ambiguous name registered, we just don't need it at all. It's a
>>>>>>> win-win IMHO.
>>>>>>
>>>>>> Yes, if we expose unique names for every machine, then -target is then
>>>>>> redundant.
>>>>>
>>>>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
>>>>> needs two name?
>>>>> "virt" needs register twice for it? or register only a single time,
>>>>> but we prefix the target_name()
>>>>> automatically? for example machine::name === "virt", but we can use
>>>>> "riscv32-virt" "risv64-virt" to reach it?
>>>>>
>>>>
>>>> Yes, ideally we should have different variant of virt for 32/64 bit.
>>>> Same goes for cpu max types.
>>>>
>>>> QOM type is always registered unambiguously ("$arch-virt"). Then, for
>>>> the "alias" name, which is virt, in case multiple matches are found,
>>>> command line can return an error with list of unambiguous names to call it.
>>>>
>>>> $ qemu-system -M virt
>>>> Multiple virt machines are available. Please choose one of them:
>>>> - aarch64-virt
>>>> - riscv64-virt
>>>>
>>>> There is no "parsing" of the argument, it's just the real QOM type. Then
>>>> we can find which target it implements from mc->targets.
>>>> And then, we can automatically choose which cpus should be available
>>>> based on that, thanks to cpu->targets.
>>>>
>>>> For existing binaries, nothing change.
>>>
>>> Good, I think we found a clean way now, is_available should be
>>> removed, and TypeInfo::targets and TypeImpl::targets should be added.
>>
>> It goes into MachineClass only for now.
>>
>>> I think
>>> for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
>>> the $arch specific virt. so that we only have a single "virt" registered.
>>> And it's
>>> targets is
>>> QEMU_ARCH_I386 |
>>> QEMU_ARCH_ARM |
>>> QEMU_ARCH_RISCV |
>>> QEMU_ARCH_LOONGARCH |
>>> QEMU_ARCH_M68K |
>>> QEMU_ARCH_OR1K |
>>> QEMU_ARCH_XTENSA |
>>> QEMU_ARCH_HEXAGON
>>>
>>> So that we won't have a list of conflict QOM names for "virt" machines.
>>> As now we indeed have only a single "virt" machine that redirects to
>>> different targets.
>>>
>>
>> The idea looks appealing, but I don't think it solves the problem to
>> have multiple virt variants available at the same time.
>>
>> The "alias" idea you introduced before is good, we just need to add a
>> check if an alias is really unique, else return an error, as explained
>> previously.
>>
>> If "-M aarch64-virt" works for both the new and existing binary, and -M
>> virt only for existing binaries (and ambiguous for new one), I think
>> that's a safe approach.
>>
>>>
>>> For other types also conflict can be handled in the same way, such as
>>> "-cpu host" "-cpu max"
>>> maybe others, but I think they all have the same way to deal with.
>>>
>>>
>>> That's why  TypeInfo::targets and TypeImpl::targets better than sole
>>> Machine::targets
>>>
>>
>> One step at a time.
>> Let's keep focused on declaring targets for a single machine first.
>> Then we can iterate to solve the "virt" problem.
>> Then convert all the existing machines and add a check in machine-target.c
>> Then, and only then, we can see what happens with cpus.
> 
> I tried this idea, but I faced a fatal error, because the
> target_info() is not available until
> the machine selected(the target arch will be select just along with
> the machine selected), so basically
> all calls to target_info() would raise an error(null pointer), how to
> deal with it?
>

I see. Indeed, since we can't set a target before registering all types, 
it implies that all the types class_init can't use target_* functions.


- register_accel_target_type
- cpu_max_v8_register_type


>>
>> Regards,
>> Pierrick
> 
> 
> 


Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Pierrick Bouvier 1 month, 1 week ago
On 10/11/26 7:13 PM, Pierrick Bouvier wrote:
> On 10/11/26 1:22 PM, Yonggang Luo wrote:
>> On Fri, Oct 9, 2026 at 2:34 AM Pierrick Bouvier
>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>
>>> On 10/8/2026 10:13 AM, Yonggang Luo wrote:
>>>> On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
>>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>>>
>>>>> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
>>>>>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>>>>>>>
>>>>>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
>>>>>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
>>>>>>>>> This allows a combined binary to register machine types from all its targets.
>>>>>>>>> Consequently, QMP `query-machines` can return machine entries from every
>>>>>>>>> target, even when `none` is selected. For example, a client can query the
>>>>>>>>> combined machine list with:
>>>>>>>>>
>>>>>>>>> ```json
>>>>>>>>> { "execute": "query-machines" }
>>>>>>>>> ```
>>>>>>>>>
>>>>>>>>> The returned list includes the registered machine classes from all linked
>>>>>>>>> targets. This is separate from selecting a machine: with `-target none`,
>>>>>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
>>>>>>>>> arbitrarily:
>>>>>>>>>
>>>>>>>>> ```text
>>>>>>>>> qemu-system -target none -M virt
>>>>>>>>> unsupported machine type: "virt" for target "none"
>>>>>>>>> Available for targets:
>>>>>>>>>     aarch64
>>>>>>>>>     arm
>>>>>>>>> ```
>>>>>>>>>
>>>>>>>>
>>>>>>>>   From the long conversation on a previous thread, I thought we reached
>>>>>>>> the conclusion that if we didn't expose any ambiguous name, then -target
>>>>>>>> option is unnecessary, or maybe I got lost on track of this thread.
>>>>>>>>
>>>>>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
>>>>>>>>
>>>>>>>> I'm not sure which semantic we want to have with -target none. If there
>>>>>>>> is no ambiguous name registered, we just don't need it at all. It's a
>>>>>>>> win-win IMHO.
>>>>>>>
>>>>>>> Yes, if we expose unique names for every machine, then -target is then
>>>>>>> redundant.
>>>>>>
>>>>>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
>>>>>> needs two name?
>>>>>> "virt" needs register twice for it? or register only a single time,
>>>>>> but we prefix the target_name()
>>>>>> automatically? for example machine::name === "virt", but we can use
>>>>>> "riscv32-virt" "risv64-virt" to reach it?
>>>>>>
>>>>>
>>>>> Yes, ideally we should have different variant of virt for 32/64 bit.
>>>>> Same goes for cpu max types.
>>>>>
>>>>> QOM type is always registered unambiguously ("$arch-virt"). Then, for
>>>>> the "alias" name, which is virt, in case multiple matches are found,
>>>>> command line can return an error with list of unambiguous names to call it.
>>>>>
>>>>> $ qemu-system -M virt
>>>>> Multiple virt machines are available. Please choose one of them:
>>>>> - aarch64-virt
>>>>> - riscv64-virt
>>>>>
>>>>> There is no "parsing" of the argument, it's just the real QOM type. Then
>>>>> we can find which target it implements from mc->targets.
>>>>> And then, we can automatically choose which cpus should be available
>>>>> based on that, thanks to cpu->targets.
>>>>>
>>>>> For existing binaries, nothing change.
>>>>
>>>> Good, I think we found a clean way now, is_available should be
>>>> removed, and TypeInfo::targets and TypeImpl::targets should be added.
>>>
>>> It goes into MachineClass only for now.
>>>
>>>> I think
>>>> for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
>>>> the $arch specific virt. so that we only have a single "virt" registered.
>>>> And it's
>>>> targets is
>>>> QEMU_ARCH_I386 |
>>>> QEMU_ARCH_ARM |
>>>> QEMU_ARCH_RISCV |
>>>> QEMU_ARCH_LOONGARCH |
>>>> QEMU_ARCH_M68K |
>>>> QEMU_ARCH_OR1K |
>>>> QEMU_ARCH_XTENSA |
>>>> QEMU_ARCH_HEXAGON
>>>>
>>>> So that we won't have a list of conflict QOM names for "virt" machines.
>>>> As now we indeed have only a single "virt" machine that redirects to
>>>> different targets.
>>>>
>>>
>>> The idea looks appealing, but I don't think it solves the problem to
>>> have multiple virt variants available at the same time.
>>>
>>> The "alias" idea you introduced before is good, we just need to add a
>>> check if an alias is really unique, else return an error, as explained
>>> previously.
>>>
>>> If "-M aarch64-virt" works for both the new and existing binary, and -M
>>> virt only for existing binaries (and ambiguous for new one), I think
>>> that's a safe approach.
>>>
>>>>
>>>> For other types also conflict can be handled in the same way, such as
>>>> "-cpu host" "-cpu max"
>>>> maybe others, but I think they all have the same way to deal with.
>>>>
>>>>
>>>> That's why  TypeInfo::targets and TypeImpl::targets better than sole
>>>> Machine::targets
>>>>
>>>
>>> One step at a time.
>>> Let's keep focused on declaring targets for a single machine first.
>>> Then we can iterate to solve the "virt" problem.
>>> Then convert all the existing machines and add a check in machine-target.c
>>> Then, and only then, we can see what happens with cpus.
>>
>> I tried this idea, but I faced a fatal error, because the
>> target_info() is not available until
>> the machine selected(the target arch will be select just along with
>> the machine selected), so basically
>> all calls to target_info() would raise an error(null pointer), how to
>> deal with it?
>>
> 
> I see. Indeed, since we can't set a target before registering all types,
> it implies that all the types class_init can't use target_* functions.
> 
> 
> - register_accel_target_type
> - cpu_max_v8_register_type
>

Sorry, mail sent to early.

For the is_available callback usage, it should be easy to do the switch, 
since it's basically the same information that what we are trying to do 
- we can leave them for now.

Some types (like accel and max mentioned above), explicitly change their 
definition depending on the target. It's a behavior we can't rely on 
anymore, and it means we need proper distinct types instead of a single 
one with dynamic definition driven by target-info.

I think that's the preliminary work needed, before being able to go 
further: convert all existing usage in class_init with distinct types + 
is_available, and then we can do the switch from is_available to the new 
.targets approach.

It's probably worth having the conversion in its own series (only 
cleanup usage of target_* in class_init), before trying to get rid of 
is_available.

For the implementation, you can use the multi-targets.c binary test to 
drive the change. Remove the module init for target info (leaving no 
target set), and add a hacky patch to skip call to is_available (and 
return true instead) and allow double definition (which will rely on 
is_available). Then, fix all the segfault. Once it compiles and runs, 
only double definition will be left, which can be handled by inserting 
the right is_available callbacks. Then in a subsequent series, the 
switch to .targets can be made.

It's a work we'll need to do for heterogeneous anyway, I was just hoping 
to delay that until there, but seems we need to deal with it now.
A good thing is that it means target-info won't have to be registered 
before all QOM types anymore, so it's worth the effort IMHO.

Thanks,
Pierrick

Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Yonggang Luo 1 month, 1 week ago
On Mon, Oct 12, 2026 at 10:25 AM Pierrick Bouvier
<pierrick.bouvier@oss.qualcomm.com> wrote:
>
> On 10/11/26 7:13 PM, Pierrick Bouvier wrote:
> > On 10/11/26 1:22 PM, Yonggang Luo wrote:
> >> On Fri, Oct 9, 2026 at 2:34 AM Pierrick Bouvier
> >> <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>>
> >>> On 10/8/2026 10:13 AM, Yonggang Luo wrote:
> >>>> On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
> >>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>>>>
> >>>>> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
> >>>>>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >>>>>>>
> >>>>>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
> >>>>>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
> >>>>>>>>> This allows a combined binary to register machine types from all its targets.
> >>>>>>>>> Consequently, QMP `query-machines` can return machine entries from every
> >>>>>>>>> target, even when `none` is selected. For example, a client can query the
> >>>>>>>>> combined machine list with:
> >>>>>>>>>
> >>>>>>>>> ```json
> >>>>>>>>> { "execute": "query-machines" }
> >>>>>>>>> ```
> >>>>>>>>>
> >>>>>>>>> The returned list includes the registered machine classes from all linked
> >>>>>>>>> targets. This is separate from selecting a machine: with `-target none`,
> >>>>>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
> >>>>>>>>> arbitrarily:
> >>>>>>>>>
> >>>>>>>>> ```text
> >>>>>>>>> qemu-system -target none -M virt
> >>>>>>>>> unsupported machine type: "virt" for target "none"
> >>>>>>>>> Available for targets:
> >>>>>>>>>     aarch64
> >>>>>>>>>     arm
> >>>>>>>>> ```
> >>>>>>>>>
> >>>>>>>>
> >>>>>>>>   From the long conversation on a previous thread, I thought we reached
> >>>>>>>> the conclusion that if we didn't expose any ambiguous name, then -target
> >>>>>>>> option is unnecessary, or maybe I got lost on track of this thread.
> >>>>>>>>
> >>>>>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
> >>>>>>>>
> >>>>>>>> I'm not sure which semantic we want to have with -target none. If there
> >>>>>>>> is no ambiguous name registered, we just don't need it at all. It's a
> >>>>>>>> win-win IMHO.
> >>>>>>>
> >>>>>>> Yes, if we expose unique names for every machine, then -target is then
> >>>>>>> redundant.
> >>>>>>
> >>>>>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
> >>>>>> needs two name?
> >>>>>> "virt" needs register twice for it? or register only a single time,
> >>>>>> but we prefix the target_name()
> >>>>>> automatically? for example machine::name === "virt", but we can use
> >>>>>> "riscv32-virt" "risv64-virt" to reach it?
> >>>>>>
> >>>>>
> >>>>> Yes, ideally we should have different variant of virt for 32/64 bit.
> >>>>> Same goes for cpu max types.
> >>>>>
> >>>>> QOM type is always registered unambiguously ("$arch-virt"). Then, for
> >>>>> the "alias" name, which is virt, in case multiple matches are found,
> >>>>> command line can return an error with list of unambiguous names to call it.
> >>>>>
> >>>>> $ qemu-system -M virt
> >>>>> Multiple virt machines are available. Please choose one of them:
> >>>>> - aarch64-virt
> >>>>> - riscv64-virt
> >>>>>
> >>>>> There is no "parsing" of the argument, it's just the real QOM type. Then
> >>>>> we can find which target it implements from mc->targets.
> >>>>> And then, we can automatically choose which cpus should be available
> >>>>> based on that, thanks to cpu->targets.
> >>>>>
> >>>>> For existing binaries, nothing change.
> >>>>
> >>>> Good, I think we found a clean way now, is_available should be
> >>>> removed, and TypeInfo::targets and TypeImpl::targets should be added.
> >>>
> >>> It goes into MachineClass only for now.
> >>>
> >>>> I think
> >>>> for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
> >>>> the $arch specific virt. so that we only have a single "virt" registered.
> >>>> And it's
> >>>> targets is
> >>>> QEMU_ARCH_I386 |
> >>>> QEMU_ARCH_ARM |
> >>>> QEMU_ARCH_RISCV |
> >>>> QEMU_ARCH_LOONGARCH |
> >>>> QEMU_ARCH_M68K |
> >>>> QEMU_ARCH_OR1K |
> >>>> QEMU_ARCH_XTENSA |
> >>>> QEMU_ARCH_HEXAGON
> >>>>
> >>>> So that we won't have a list of conflict QOM names for "virt" machines.
> >>>> As now we indeed have only a single "virt" machine that redirects to
> >>>> different targets.
> >>>>
> >>>
> >>> The idea looks appealing, but I don't think it solves the problem to
> >>> have multiple virt variants available at the same time.
> >>>
> >>> The "alias" idea you introduced before is good, we just need to add a
> >>> check if an alias is really unique, else return an error, as explained
> >>> previously.
> >>>
> >>> If "-M aarch64-virt" works for both the new and existing binary, and -M
> >>> virt only for existing binaries (and ambiguous for new one), I think
> >>> that's a safe approach.
> >>>
> >>>>
> >>>> For other types also conflict can be handled in the same way, such as
> >>>> "-cpu host" "-cpu max"
> >>>> maybe others, but I think they all have the same way to deal with.
> >>>>
> >>>>
> >>>> That's why  TypeInfo::targets and TypeImpl::targets better than sole
> >>>> Machine::targets
> >>>>
> >>>
> >>> One step at a time.
> >>> Let's keep focused on declaring targets for a single machine first.
> >>> Then we can iterate to solve the "virt" problem.
> >>> Then convert all the existing machines and add a check in machine-target.c
> >>> Then, and only then, we can see what happens with cpus.
> >>
> >> I tried this idea, but I faced a fatal error, because the
> >> target_info() is not available until
> >> the machine selected(the target arch will be select just along with
> >> the machine selected), so basically
> >> all calls to target_info() would raise an error(null pointer), how to
> >> deal with it?
> >>
> >
> > I see. Indeed, since we can't set a target before registering all types,
> > it implies that all the types class_init can't use target_* functions.
> >
> >
> > - register_accel_target_type
> > - cpu_max_v8_register_type
> >
>
> Sorry, mail sent to early.
>
> For the is_available callback usage, it should be easy to do the switch,
> since it's basically the same information that what we are trying to do
> - we can leave them for now.
>
> Some types (like accel and max mentioned above), explicitly change their
> definition depending on the target. It's a behavior we can't rely on
> anymore, and it means we need proper distinct types instead of a single
> one with dynamic definition driven by target-info.
>
> I think that's the preliminary work needed, before being able to go
> further: convert all existing usage in class_init with distinct types +
> is_available, and then we can do the switch from is_available to the new
> .targets approach.

Hi Pierrick,
I have already tried that introducing new QOM names just to make class_init
 target-independent is too broad(means all usage of it should be handled)
and could complicate compatibility(changed too much code).
Can we avoid new names by some new means(ideas welcome)?


>
> It's probably worth having the conversion in its own series (only
> cleanup usage of target_* in class_init), before trying to get rid of
> is_available.

>
> For the implementation, you can use the multi-targets.c binary test to
> drive the change. Remove the module init for target info (leaving no
> target set), and add a hacky patch to skip call to is_available (and
> return true instead) and allow double definition (which will rely on
> is_available). Then, fix all the segfault. Once it compiles and runs,
> only double definition will be left, which can be handled by inserting
> the right is_available callbacks. Then in a subsequent series, the
> switch to .targets can be made.


Still have no clean clue about how to remove is_available , as we have many
"virt" machines. Do you means all "virt" machines with "virt-machine" QOM names
are inserted to the table? How to get it working because the "key" is string.


>
> It's a work we'll need to do for heterogeneous anyway, I was just hoping
> to delay that until there, but seems we need to deal with it now.
> A good thing is that it means target-info won't have to be registered
> before all QOM types anymore, so it's worth the effort IMHO.
>
> Thanks,
> Pierrick



-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Pierrick Bouvier 1 month, 1 week ago
On 10/11/26 9:26 PM, Yonggang Luo wrote:
> On Mon, Oct 12, 2026 at 10:25 AM Pierrick Bouvier
> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>
>> On 10/11/26 7:13 PM, Pierrick Bouvier wrote:
>>> On 10/11/26 1:22 PM, Yonggang Luo wrote:
>>>> On Fri, Oct 9, 2026 at 2:34 AM Pierrick Bouvier
>>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>>>
>>>>> On 10/8/2026 10:13 AM, Yonggang Luo wrote:
>>>>>> On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
>>>>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>>>>>
>>>>>>> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
>>>>>>>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>>>>>>>>>
>>>>>>>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
>>>>>>>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
>>>>>>>>>>> This allows a combined binary to register machine types from all its targets.
>>>>>>>>>>> Consequently, QMP `query-machines` can return machine entries from every
>>>>>>>>>>> target, even when `none` is selected. For example, a client can query the
>>>>>>>>>>> combined machine list with:
>>>>>>>>>>>
>>>>>>>>>>> ```json
>>>>>>>>>>> { "execute": "query-machines" }
>>>>>>>>>>> ```
>>>>>>>>>>>
>>>>>>>>>>> The returned list includes the registered machine classes from all linked
>>>>>>>>>>> targets. This is separate from selecting a machine: with `-target none`,
>>>>>>>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
>>>>>>>>>>> arbitrarily:
>>>>>>>>>>>
>>>>>>>>>>> ```text
>>>>>>>>>>> qemu-system -target none -M virt
>>>>>>>>>>> unsupported machine type: "virt" for target "none"
>>>>>>>>>>> Available for targets:
>>>>>>>>>>>      aarch64
>>>>>>>>>>>      arm
>>>>>>>>>>> ```
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>    From the long conversation on a previous thread, I thought we reached
>>>>>>>>>> the conclusion that if we didn't expose any ambiguous name, then -target
>>>>>>>>>> option is unnecessary, or maybe I got lost on track of this thread.
>>>>>>>>>>
>>>>>>>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
>>>>>>>>>>
>>>>>>>>>> I'm not sure which semantic we want to have with -target none. If there
>>>>>>>>>> is no ambiguous name registered, we just don't need it at all. It's a
>>>>>>>>>> win-win IMHO.
>>>>>>>>>
>>>>>>>>> Yes, if we expose unique names for every machine, then -target is then
>>>>>>>>> redundant.
>>>>>>>>
>>>>>>>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
>>>>>>>> needs two name?
>>>>>>>> "virt" needs register twice for it? or register only a single time,
>>>>>>>> but we prefix the target_name()
>>>>>>>> automatically? for example machine::name === "virt", but we can use
>>>>>>>> "riscv32-virt" "risv64-virt" to reach it?
>>>>>>>>
>>>>>>>
>>>>>>> Yes, ideally we should have different variant of virt for 32/64 bit.
>>>>>>> Same goes for cpu max types.
>>>>>>>
>>>>>>> QOM type is always registered unambiguously ("$arch-virt"). Then, for
>>>>>>> the "alias" name, which is virt, in case multiple matches are found,
>>>>>>> command line can return an error with list of unambiguous names to call it.
>>>>>>>
>>>>>>> $ qemu-system -M virt
>>>>>>> Multiple virt machines are available. Please choose one of them:
>>>>>>> - aarch64-virt
>>>>>>> - riscv64-virt
>>>>>>>
>>>>>>> There is no "parsing" of the argument, it's just the real QOM type. Then
>>>>>>> we can find which target it implements from mc->targets.
>>>>>>> And then, we can automatically choose which cpus should be available
>>>>>>> based on that, thanks to cpu->targets.
>>>>>>>
>>>>>>> For existing binaries, nothing change.
>>>>>>
>>>>>> Good, I think we found a clean way now, is_available should be
>>>>>> removed, and TypeInfo::targets and TypeImpl::targets should be added.
>>>>>
>>>>> It goes into MachineClass only for now.
>>>>>
>>>>>> I think
>>>>>> for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
>>>>>> the $arch specific virt. so that we only have a single "virt" registered.
>>>>>> And it's
>>>>>> targets is
>>>>>> QEMU_ARCH_I386 |
>>>>>> QEMU_ARCH_ARM |
>>>>>> QEMU_ARCH_RISCV |
>>>>>> QEMU_ARCH_LOONGARCH |
>>>>>> QEMU_ARCH_M68K |
>>>>>> QEMU_ARCH_OR1K |
>>>>>> QEMU_ARCH_XTENSA |
>>>>>> QEMU_ARCH_HEXAGON
>>>>>>
>>>>>> So that we won't have a list of conflict QOM names for "virt" machines.
>>>>>> As now we indeed have only a single "virt" machine that redirects to
>>>>>> different targets.
>>>>>>
>>>>>
>>>>> The idea looks appealing, but I don't think it solves the problem to
>>>>> have multiple virt variants available at the same time.
>>>>>
>>>>> The "alias" idea you introduced before is good, we just need to add a
>>>>> check if an alias is really unique, else return an error, as explained
>>>>> previously.
>>>>>
>>>>> If "-M aarch64-virt" works for both the new and existing binary, and -M
>>>>> virt only for existing binaries (and ambiguous for new one), I think
>>>>> that's a safe approach.
>>>>>
>>>>>>
>>>>>> For other types also conflict can be handled in the same way, such as
>>>>>> "-cpu host" "-cpu max"
>>>>>> maybe others, but I think they all have the same way to deal with.
>>>>>>
>>>>>>
>>>>>> That's why  TypeInfo::targets and TypeImpl::targets better than sole
>>>>>> Machine::targets
>>>>>>
>>>>>
>>>>> One step at a time.
>>>>> Let's keep focused on declaring targets for a single machine first.
>>>>> Then we can iterate to solve the "virt" problem.
>>>>> Then convert all the existing machines and add a check in machine-target.c
>>>>> Then, and only then, we can see what happens with cpus.
>>>>
>>>> I tried this idea, but I faced a fatal error, because the
>>>> target_info() is not available until
>>>> the machine selected(the target arch will be select just along with
>>>> the machine selected), so basically
>>>> all calls to target_info() would raise an error(null pointer), how to
>>>> deal with it?
>>>>
>>>
>>> I see. Indeed, since we can't set a target before registering all types,
>>> it implies that all the types class_init can't use target_* functions.
>>>
>>>
>>> - register_accel_target_type
>>> - cpu_max_v8_register_type
>>>
>>
>> Sorry, mail sent to early.
>>
>> For the is_available callback usage, it should be easy to do the switch,
>> since it's basically the same information that what we are trying to do
>> - we can leave them for now.
>>
>> Some types (like accel and max mentioned above), explicitly change their
>> definition depending on the target. It's a behavior we can't rely on
>> anymore, and it means we need proper distinct types instead of a single
>> one with dynamic definition driven by target-info.
>>
>> I think that's the preliminary work needed, before being able to go
>> further: convert all existing usage in class_init with distinct types +
>> is_available, and then we can do the switch from is_available to the new
>> .targets approach.
> 
> Hi Pierrick,
> I have already tried that introducing new QOM names just to make class_init
>   target-independent is too broad(means all usage of it should be handled)
> and could complicate compatibility(changed too much code).
> Can we avoid new names by some new means(ideas welcome)?
>

As a first step, I don't think we need new names, is_available can be 
used to selectively register one definition or another and avoid any 
clash. What is missing at the moment though, is that some types (like 
cpu max above) change their definition based on target definition.

So for cpu max, we would have two distinct types, both named max, but 
one with is_available(target_arm), and other one with 
is_available(target_aarch64), so they are never registered at the same time.

Same for virt machines. It's already what we have, duplication is 
handled at the moment with distinct is_available callbacks.

Then, see below.

> 
>>
>> It's probably worth having the conversion in its own series (only
>> cleanup usage of target_* in class_init), before trying to get rid of
>> is_available.
> 
>>
>> For the implementation, you can use the multi-targets.c binary test to
>> drive the change. Remove the module init for target info (leaving no
>> target set), and add a hacky patch to skip call to is_available (and
>> return true instead) and allow double definition (which will rely on
>> is_available). Then, fix all the segfault. Once it compiles and runs,
>> only double definition will be left, which can be handled by inserting
>> the right is_available callbacks. Then in a subsequent series, the
>> switch to .targets can be made.
> 
> 
> Still have no clean clue about how to remove is_available , as we have many
> "virt" machines. Do you means all "virt" machines with "virt-machine" QOM names
> are inserted to the table? How to get it working because the "key" is string.
>

Once we have type definition which only depends on is_available, we can 
convert this to .targets, which would contain the same information.
For the rest, I have some ideas, but I would like first we do the first 
part (convert to is_available), which is already a huge work in itself, 
and a series of its own.

Regards,
Pierrick

Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Yonggang Luo 1 month, 1 week ago
On Tue, Oct 13, 2026 at 9:26 AM Pierrick Bouvier
<pierrick.bouvier@oss.qualcomm.com> wrote:
>
> On 10/11/26 9:26 PM, Yonggang Luo wrote:
> > On Mon, Oct 12, 2026 at 10:25 AM Pierrick Bouvier
> > <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>
> >> On 10/11/26 7:13 PM, Pierrick Bouvier wrote:
> >>> On 10/11/26 1:22 PM, Yonggang Luo wrote:
> >>>> On Fri, Oct 9, 2026 at 2:34 AM Pierrick Bouvier
> >>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>>>>
> >>>>> On 10/8/2026 10:13 AM, Yonggang Luo wrote:
> >>>>>> On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
> >>>>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>>>>>>
> >>>>>>> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
> >>>>>>>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >>>>>>>>>
> >>>>>>>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
> >>>>>>>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
> >>>>>>>>>>> This allows a combined binary to register machine types from all its targets.
> >>>>>>>>>>> Consequently, QMP `query-machines` can return machine entries from every
> >>>>>>>>>>> target, even when `none` is selected. For example, a client can query the
> >>>>>>>>>>> combined machine list with:
> >>>>>>>>>>>
> >>>>>>>>>>> ```json
> >>>>>>>>>>> { "execute": "query-machines" }
> >>>>>>>>>>> ```
> >>>>>>>>>>>
> >>>>>>>>>>> The returned list includes the registered machine classes from all linked
> >>>>>>>>>>> targets. This is separate from selecting a machine: with `-target none`,
> >>>>>>>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
> >>>>>>>>>>> arbitrarily:
> >>>>>>>>>>>
> >>>>>>>>>>> ```text
> >>>>>>>>>>> qemu-system -target none -M virt
> >>>>>>>>>>> unsupported machine type: "virt" for target "none"
> >>>>>>>>>>> Available for targets:
> >>>>>>>>>>>      aarch64
> >>>>>>>>>>>      arm
> >>>>>>>>>>> ```
> >>>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>    From the long conversation on a previous thread, I thought we reached
> >>>>>>>>>> the conclusion that if we didn't expose any ambiguous name, then -target
> >>>>>>>>>> option is unnecessary, or maybe I got lost on track of this thread.
> >>>>>>>>>>
> >>>>>>>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
> >>>>>>>>>>
> >>>>>>>>>> I'm not sure which semantic we want to have with -target none. If there
> >>>>>>>>>> is no ambiguous name registered, we just don't need it at all. It's a
> >>>>>>>>>> win-win IMHO.
> >>>>>>>>>
> >>>>>>>>> Yes, if we expose unique names for every machine, then -target is then
> >>>>>>>>> redundant.
> >>>>>>>>
> >>>>>>>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
> >>>>>>>> needs two name?
> >>>>>>>> "virt" needs register twice for it? or register only a single time,
> >>>>>>>> but we prefix the target_name()
> >>>>>>>> automatically? for example machine::name === "virt", but we can use
> >>>>>>>> "riscv32-virt" "risv64-virt" to reach it?
> >>>>>>>>
> >>>>>>>
> >>>>>>> Yes, ideally we should have different variant of virt for 32/64 bit.
> >>>>>>> Same goes for cpu max types.
> >>>>>>>
> >>>>>>> QOM type is always registered unambiguously ("$arch-virt"). Then, for
> >>>>>>> the "alias" name, which is virt, in case multiple matches are found,
> >>>>>>> command line can return an error with list of unambiguous names to call it.
> >>>>>>>
> >>>>>>> $ qemu-system -M virt
> >>>>>>> Multiple virt machines are available. Please choose one of them:
> >>>>>>> - aarch64-virt
> >>>>>>> - riscv64-virt
> >>>>>>>
> >>>>>>> There is no "parsing" of the argument, it's just the real QOM type. Then
> >>>>>>> we can find which target it implements from mc->targets.
> >>>>>>> And then, we can automatically choose which cpus should be available
> >>>>>>> based on that, thanks to cpu->targets.
> >>>>>>>
> >>>>>>> For existing binaries, nothing change.
> >>>>>>
> >>>>>> Good, I think we found a clean way now, is_available should be
> >>>>>> removed, and TypeInfo::targets and TypeImpl::targets should be added.
> >>>>>
> >>>>> It goes into MachineClass only for now.
> >>>>>
> >>>>>> I think
> >>>>>> for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
> >>>>>> the $arch specific virt. so that we only have a single "virt" registered.
> >>>>>> And it's
> >>>>>> targets is
> >>>>>> QEMU_ARCH_I386 |
> >>>>>> QEMU_ARCH_ARM |
> >>>>>> QEMU_ARCH_RISCV |
> >>>>>> QEMU_ARCH_LOONGARCH |
> >>>>>> QEMU_ARCH_M68K |
> >>>>>> QEMU_ARCH_OR1K |
> >>>>>> QEMU_ARCH_XTENSA |
> >>>>>> QEMU_ARCH_HEXAGON
> >>>>>>
> >>>>>> So that we won't have a list of conflict QOM names for "virt" machines.
> >>>>>> As now we indeed have only a single "virt" machine that redirects to
> >>>>>> different targets.
> >>>>>>
> >>>>>
> >>>>> The idea looks appealing, but I don't think it solves the problem to
> >>>>> have multiple virt variants available at the same time.
> >>>>>
> >>>>> The "alias" idea you introduced before is good, we just need to add a
> >>>>> check if an alias is really unique, else return an error, as explained
> >>>>> previously.
> >>>>>
> >>>>> If "-M aarch64-virt" works for both the new and existing binary, and -M
> >>>>> virt only for existing binaries (and ambiguous for new one), I think
> >>>>> that's a safe approach.
> >>>>>
> >>>>>>
> >>>>>> For other types also conflict can be handled in the same way, such as
> >>>>>> "-cpu host" "-cpu max"
> >>>>>> maybe others, but I think they all have the same way to deal with.
> >>>>>>
> >>>>>>
> >>>>>> That's why  TypeInfo::targets and TypeImpl::targets better than sole
> >>>>>> Machine::targets
> >>>>>>
> >>>>>
> >>>>> One step at a time.
> >>>>> Let's keep focused on declaring targets for a single machine first.
> >>>>> Then we can iterate to solve the "virt" problem.
> >>>>> Then convert all the existing machines and add a check in machine-target.c
> >>>>> Then, and only then, we can see what happens with cpus.
> >>>>
> >>>> I tried this idea, but I faced a fatal error, because the
> >>>> target_info() is not available until
> >>>> the machine selected(the target arch will be select just along with
> >>>> the machine selected), so basically
> >>>> all calls to target_info() would raise an error(null pointer), how to
> >>>> deal with it?
> >>>>
> >>>
> >>> I see. Indeed, since we can't set a target before registering all types,
> >>> it implies that all the types class_init can't use target_* functions.
> >>>
> >>>
> >>> - register_accel_target_type
> >>> - cpu_max_v8_register_type
> >>>
> >>
> >> Sorry, mail sent to early.
> >>
> >> For the is_available callback usage, it should be easy to do the switch,
> >> since it's basically the same information that what we are trying to do
> >> - we can leave them for now.
> >>
> >> Some types (like accel and max mentioned above), explicitly change their
> >> definition depending on the target. It's a behavior we can't rely on
> >> anymore, and it means we need proper distinct types instead of a single
> >> one with dynamic definition driven by target-info.
> >>
> >> I think that's the preliminary work needed, before being able to go
> >> further: convert all existing usage in class_init with distinct types +
> >> is_available, and then we can do the switch from is_available to the new
> >> .targets approach.
> >
> > Hi Pierrick,
> > I have already tried that introducing new QOM names just to make class_init
> >   target-independent is too broad(means all usage of it should be handled)
> > and could complicate compatibility(changed too much code).
> > Can we avoid new names by some new means(ideas welcome)?
> >
>
> As a first step, I don't think we need new names, is_available can be
> used to selectively register one definition or another and avoid any
> clash. What is missing at the moment though, is that some types (like
> cpu max above) change their definition based on target definition.


>
> So for cpu max, we would have two distinct types, both named max, but
> one with is_available(target_arm), and other one with
> is_available(target_aarch64), so they are never registered at the same time.

>
> Same for virt machines. It's already what we have, duplication is
> handled at the moment with distinct is_available callbacks.
>
> Then, see below.
>
> >
> >>
> >> It's probably worth having the conversion in its own series (only
> >> cleanup usage of target_* in class_init), before trying to get rid of
> >> is_available.
> >
> >>
> >> For the implementation, you can use the multi-targets.c binary test to
> >> drive the change. Remove the module init for target info (leaving no
> >> target set), and add a hacky patch to skip call to is_available (and
> >> return true instead) and allow double definition (which will rely on
> >> is_available). Then, fix all the segfault. Once it compiles and runs,
> >> only double definition will be left, which can be handled by inserting
> >> the right is_available callbacks. Then in a subsequent series, the
> >> switch to .targets can be made.
> >
> >
> > Still have no clean clue about how to remove is_available , as we have many
> > "virt" machines. Do you means all "virt" machines with "virt-machine" QOM names
> > are inserted to the table? How to get it working because the "key" is string.
> >
>
> Once we have type definition which only depends on is_available, we can
> convert this to .targets, which would contain the same information.
> For the rest, I have some ideas, but I would like first we do the first
> part (convert to is_available), which is already a huge work in itself,
> and a series of its own.

Indeed I am confused .targets only exists on Machine, how is it
related to -cpu host -cpu max?


I already have a working copy that does not depend on target_info()
and selects target_info() when the machine
is selected, no QOM name introduced. only for machines, we will have
$target_name-$machine_name as a name for selecting
the exact machine.

The cpu max cpu host is dealt by moving the choose code out of
class_init, into object_init. I really did not get your idea by use
is_avaiable. because when I try to get all QOMs to be registered. then
I won't call is_available at all.
because "is_available" depends on target_info(),(we won't have
target_info() till the machine is selected).

>
> Regards,
> Pierrick



-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Pierrick Bouvier 1 month, 1 week ago
On 10/12/26 7:43 PM, Yonggang Luo wrote:
> On Tue, Oct 13, 2026 at 9:26 AM Pierrick Bouvier
> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>
>> On 10/11/26 9:26 PM, Yonggang Luo wrote:
>>> On Mon, Oct 12, 2026 at 10:25 AM Pierrick Bouvier
>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>>
>>>> On 10/11/26 7:13 PM, Pierrick Bouvier wrote:
>>>>> On 10/11/26 1:22 PM, Yonggang Luo wrote:
>>>>>> On Fri, Oct 9, 2026 at 2:34 AM Pierrick Bouvier
>>>>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>>>>>
>>>>>>> On 10/8/2026 10:13 AM, Yonggang Luo wrote:
>>>>>>>> On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
>>>>>>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>>>>>>>
>>>>>>>>> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
>>>>>>>>>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
>>>>>>>>>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
>>>>>>>>>>>>> This allows a combined binary to register machine types from all its targets.
>>>>>>>>>>>>> Consequently, QMP `query-machines` can return machine entries from every
>>>>>>>>>>>>> target, even when `none` is selected. For example, a client can query the
>>>>>>>>>>>>> combined machine list with:
>>>>>>>>>>>>>
>>>>>>>>>>>>> ```json
>>>>>>>>>>>>> { "execute": "query-machines" }
>>>>>>>>>>>>> ```
>>>>>>>>>>>>>
>>>>>>>>>>>>> The returned list includes the registered machine classes from all linked
>>>>>>>>>>>>> targets. This is separate from selecting a machine: with `-target none`,
>>>>>>>>>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
>>>>>>>>>>>>> arbitrarily:
>>>>>>>>>>>>>
>>>>>>>>>>>>> ```text
>>>>>>>>>>>>> qemu-system -target none -M virt
>>>>>>>>>>>>> unsupported machine type: "virt" for target "none"
>>>>>>>>>>>>> Available for targets:
>>>>>>>>>>>>>       aarch64
>>>>>>>>>>>>>       arm
>>>>>>>>>>>>> ```
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>     From the long conversation on a previous thread, I thought we reached
>>>>>>>>>>>> the conclusion that if we didn't expose any ambiguous name, then -target
>>>>>>>>>>>> option is unnecessary, or maybe I got lost on track of this thread.
>>>>>>>>>>>>
>>>>>>>>>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
>>>>>>>>>>>>
>>>>>>>>>>>> I'm not sure which semantic we want to have with -target none. If there
>>>>>>>>>>>> is no ambiguous name registered, we just don't need it at all. It's a
>>>>>>>>>>>> win-win IMHO.
>>>>>>>>>>>
>>>>>>>>>>> Yes, if we expose unique names for every machine, then -target is then
>>>>>>>>>>> redundant.
>>>>>>>>>>
>>>>>>>>>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
>>>>>>>>>> needs two name?
>>>>>>>>>> "virt" needs register twice for it? or register only a single time,
>>>>>>>>>> but we prefix the target_name()
>>>>>>>>>> automatically? for example machine::name === "virt", but we can use
>>>>>>>>>> "riscv32-virt" "risv64-virt" to reach it?
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Yes, ideally we should have different variant of virt for 32/64 bit.
>>>>>>>>> Same goes for cpu max types.
>>>>>>>>>
>>>>>>>>> QOM type is always registered unambiguously ("$arch-virt"). Then, for
>>>>>>>>> the "alias" name, which is virt, in case multiple matches are found,
>>>>>>>>> command line can return an error with list of unambiguous names to call it.
>>>>>>>>>
>>>>>>>>> $ qemu-system -M virt
>>>>>>>>> Multiple virt machines are available. Please choose one of them:
>>>>>>>>> - aarch64-virt
>>>>>>>>> - riscv64-virt
>>>>>>>>>
>>>>>>>>> There is no "parsing" of the argument, it's just the real QOM type. Then
>>>>>>>>> we can find which target it implements from mc->targets.
>>>>>>>>> And then, we can automatically choose which cpus should be available
>>>>>>>>> based on that, thanks to cpu->targets.
>>>>>>>>>
>>>>>>>>> For existing binaries, nothing change.
>>>>>>>>
>>>>>>>> Good, I think we found a clean way now, is_available should be
>>>>>>>> removed, and TypeInfo::targets and TypeImpl::targets should be added.
>>>>>>>
>>>>>>> It goes into MachineClass only for now.
>>>>>>>
>>>>>>>> I think
>>>>>>>> for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
>>>>>>>> the $arch specific virt. so that we only have a single "virt" registered.
>>>>>>>> And it's
>>>>>>>> targets is
>>>>>>>> QEMU_ARCH_I386 |
>>>>>>>> QEMU_ARCH_ARM |
>>>>>>>> QEMU_ARCH_RISCV |
>>>>>>>> QEMU_ARCH_LOONGARCH |
>>>>>>>> QEMU_ARCH_M68K |
>>>>>>>> QEMU_ARCH_OR1K |
>>>>>>>> QEMU_ARCH_XTENSA |
>>>>>>>> QEMU_ARCH_HEXAGON
>>>>>>>>
>>>>>>>> So that we won't have a list of conflict QOM names for "virt" machines.
>>>>>>>> As now we indeed have only a single "virt" machine that redirects to
>>>>>>>> different targets.
>>>>>>>>
>>>>>>>
>>>>>>> The idea looks appealing, but I don't think it solves the problem to
>>>>>>> have multiple virt variants available at the same time.
>>>>>>>
>>>>>>> The "alias" idea you introduced before is good, we just need to add a
>>>>>>> check if an alias is really unique, else return an error, as explained
>>>>>>> previously.
>>>>>>>
>>>>>>> If "-M aarch64-virt" works for both the new and existing binary, and -M
>>>>>>> virt only for existing binaries (and ambiguous for new one), I think
>>>>>>> that's a safe approach.
>>>>>>>
>>>>>>>>
>>>>>>>> For other types also conflict can be handled in the same way, such as
>>>>>>>> "-cpu host" "-cpu max"
>>>>>>>> maybe others, but I think they all have the same way to deal with.
>>>>>>>>
>>>>>>>>
>>>>>>>> That's why  TypeInfo::targets and TypeImpl::targets better than sole
>>>>>>>> Machine::targets
>>>>>>>>
>>>>>>>
>>>>>>> One step at a time.
>>>>>>> Let's keep focused on declaring targets for a single machine first.
>>>>>>> Then we can iterate to solve the "virt" problem.
>>>>>>> Then convert all the existing machines and add a check in machine-target.c
>>>>>>> Then, and only then, we can see what happens with cpus.
>>>>>>
>>>>>> I tried this idea, but I faced a fatal error, because the
>>>>>> target_info() is not available until
>>>>>> the machine selected(the target arch will be select just along with
>>>>>> the machine selected), so basically
>>>>>> all calls to target_info() would raise an error(null pointer), how to
>>>>>> deal with it?
>>>>>>
>>>>>
>>>>> I see. Indeed, since we can't set a target before registering all types,
>>>>> it implies that all the types class_init can't use target_* functions.
>>>>>
>>>>>
>>>>> - register_accel_target_type
>>>>> - cpu_max_v8_register_type
>>>>>
>>>>
>>>> Sorry, mail sent to early.
>>>>
>>>> For the is_available callback usage, it should be easy to do the switch,
>>>> since it's basically the same information that what we are trying to do
>>>> - we can leave them for now.
>>>>
>>>> Some types (like accel and max mentioned above), explicitly change their
>>>> definition depending on the target. It's a behavior we can't rely on
>>>> anymore, and it means we need proper distinct types instead of a single
>>>> one with dynamic definition driven by target-info.
>>>>
>>>> I think that's the preliminary work needed, before being able to go
>>>> further: convert all existing usage in class_init with distinct types +
>>>> is_available, and then we can do the switch from is_available to the new
>>>> .targets approach.
>>>
>>> Hi Pierrick,
>>> I have already tried that introducing new QOM names just to make class_init
>>>    target-independent is too broad(means all usage of it should be handled)
>>> and could complicate compatibility(changed too much code).
>>> Can we avoid new names by some new means(ideas welcome)?
>>>
>>
>> As a first step, I don't think we need new names, is_available can be
>> used to selectively register one definition or another and avoid any
>> clash. What is missing at the moment though, is that some types (like
>> cpu max above) change their definition based on target definition.
> 
> 
>>
>> So for cpu max, we would have two distinct types, both named max, but
>> one with is_available(target_arm), and other one with
>> is_available(target_aarch64), so they are never registered at the same time.
> 
>>
>> Same for virt machines. It's already what we have, duplication is
>> handled at the moment with distinct is_available callbacks.
>>
>> Then, see below.
>>
>>>
>>>>
>>>> It's probably worth having the conversion in its own series (only
>>>> cleanup usage of target_* in class_init), before trying to get rid of
>>>> is_available.
>>>
>>>>
>>>> For the implementation, you can use the multi-targets.c binary test to
>>>> drive the change. Remove the module init for target info (leaving no
>>>> target set), and add a hacky patch to skip call to is_available (and
>>>> return true instead) and allow double definition (which will rely on
>>>> is_available). Then, fix all the segfault. Once it compiles and runs,
>>>> only double definition will be left, which can be handled by inserting
>>>> the right is_available callbacks. Then in a subsequent series, the
>>>> switch to .targets can be made.
>>>
>>>
>>> Still have no clean clue about how to remove is_available , as we have many
>>> "virt" machines. Do you means all "virt" machines with "virt-machine" QOM names
>>> are inserted to the table? How to get it working because the "key" is string.
>>>
>>
>> Once we have type definition which only depends on is_available, we can
>> convert this to .targets, which would contain the same information.
>> For the rest, I have some ideas, but I would like first we do the first
>> part (convert to is_available), which is already a huge work in itself,
>> and a series of its own.
> 
> Indeed I am confused .targets only exists on Machine, how is it
> related to -cpu host -cpu max?
>

We can introduce cpu.targets after machine.targets.
First step is just to get something that works with is_available and 
does not require any target info to be set.

> 
> I already have a working copy that does not depend on target_info()
> and selects target_info() when the machine
> is selected, no QOM name introduced. only for machines, we will have
> $target_name-$machine_name as a name for selecting
> the exact machine.
>
> The cpu max cpu host is dealt by moving the choose code out of
> class_init, into object_init. I really did not get your idea by use
> is_avaiable. because when I try to get all QOMs to be registered. then
> I won't call is_available at all.

As a first step, we rely on is_available, to work on distinguishing 
proper types per target and break the dependency of multiple class_init 
to target_info. Then, we can replace is_available with .targets.

> because "is_available" depends on target_info(),(we won't have
> target_info() till the machine is selected).
>

We can imagine registering types in different buckets per target, which 
would allow for duplication.

Regards,
Pierrick

Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Yonggang Luo 1 month, 1 week ago
On Tue, Oct 13, 2026 at 11:53 AM Pierrick Bouvier
<pierrick.bouvier@oss.qualcomm.com> wrote:
>
> On 10/12/26 7:43 PM, Yonggang Luo wrote:
> > On Tue, Oct 13, 2026 at 9:26 AM Pierrick Bouvier
> > <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>
> >> On 10/11/26 9:26 PM, Yonggang Luo wrote:
> >>> On Mon, Oct 12, 2026 at 10:25 AM Pierrick Bouvier
> >>> <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>>>
> >>>> On 10/11/26 7:13 PM, Pierrick Bouvier wrote:
> >>>>> On 10/11/26 1:22 PM, Yonggang Luo wrote:
> >>>>>> On Fri, Oct 9, 2026 at 2:34 AM Pierrick Bouvier
> >>>>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>>>>>>
> >>>>>>> On 10/8/2026 10:13 AM, Yonggang Luo wrote:
> >>>>>>>> On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
> >>>>>>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>>>>>>>>
> >>>>>>>>> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
> >>>>>>>>>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >>>>>>>>>>>
> >>>>>>>>>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
> >>>>>>>>>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
> >>>>>>>>>>>>> This allows a combined binary to register machine types from all its targets.
> >>>>>>>>>>>>> Consequently, QMP `query-machines` can return machine entries from every
> >>>>>>>>>>>>> target, even when `none` is selected. For example, a client can query the
> >>>>>>>>>>>>> combined machine list with:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> ```json
> >>>>>>>>>>>>> { "execute": "query-machines" }
> >>>>>>>>>>>>> ```
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> The returned list includes the registered machine classes from all linked
> >>>>>>>>>>>>> targets. This is separate from selecting a machine: with `-target none`,
> >>>>>>>>>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
> >>>>>>>>>>>>> arbitrarily:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> ```text
> >>>>>>>>>>>>> qemu-system -target none -M virt
> >>>>>>>>>>>>> unsupported machine type: "virt" for target "none"
> >>>>>>>>>>>>> Available for targets:
> >>>>>>>>>>>>>       aarch64
> >>>>>>>>>>>>>       arm
> >>>>>>>>>>>>> ```
> >>>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>     From the long conversation on a previous thread, I thought we reached
> >>>>>>>>>>>> the conclusion that if we didn't expose any ambiguous name, then -target
> >>>>>>>>>>>> option is unnecessary, or maybe I got lost on track of this thread.
> >>>>>>>>>>>>
> >>>>>>>>>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
> >>>>>>>>>>>>
> >>>>>>>>>>>> I'm not sure which semantic we want to have with -target none. If there
> >>>>>>>>>>>> is no ambiguous name registered, we just don't need it at all. It's a
> >>>>>>>>>>>> win-win IMHO.
> >>>>>>>>>>>
> >>>>>>>>>>> Yes, if we expose unique names for every machine, then -target is then
> >>>>>>>>>>> redundant.
> >>>>>>>>>>
> >>>>>>>>>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
> >>>>>>>>>> needs two name?
> >>>>>>>>>> "virt" needs register twice for it? or register only a single time,
> >>>>>>>>>> but we prefix the target_name()
> >>>>>>>>>> automatically? for example machine::name === "virt", but we can use
> >>>>>>>>>> "riscv32-virt" "risv64-virt" to reach it?
> >>>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> Yes, ideally we should have different variant of virt for 32/64 bit.
> >>>>>>>>> Same goes for cpu max types.
> >>>>>>>>>
> >>>>>>>>> QOM type is always registered unambiguously ("$arch-virt"). Then, for
> >>>>>>>>> the "alias" name, which is virt, in case multiple matches are found,
> >>>>>>>>> command line can return an error with list of unambiguous names to call it.
> >>>>>>>>>
> >>>>>>>>> $ qemu-system -M virt
> >>>>>>>>> Multiple virt machines are available. Please choose one of them:
> >>>>>>>>> - aarch64-virt
> >>>>>>>>> - riscv64-virt
> >>>>>>>>>
> >>>>>>>>> There is no "parsing" of the argument, it's just the real QOM type. Then
> >>>>>>>>> we can find which target it implements from mc->targets.
> >>>>>>>>> And then, we can automatically choose which cpus should be available
> >>>>>>>>> based on that, thanks to cpu->targets.
> >>>>>>>>>
> >>>>>>>>> For existing binaries, nothing change.
> >>>>>>>>
> >>>>>>>> Good, I think we found a clean way now, is_available should be
> >>>>>>>> removed, and TypeInfo::targets and TypeImpl::targets should be added.
> >>>>>>>
> >>>>>>> It goes into MachineClass only for now.
> >>>>>>>
> >>>>>>>> I think
> >>>>>>>> for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
> >>>>>>>> the $arch specific virt. so that we only have a single "virt" registered.
> >>>>>>>> And it's
> >>>>>>>> targets is
> >>>>>>>> QEMU_ARCH_I386 |
> >>>>>>>> QEMU_ARCH_ARM |
> >>>>>>>> QEMU_ARCH_RISCV |
> >>>>>>>> QEMU_ARCH_LOONGARCH |
> >>>>>>>> QEMU_ARCH_M68K |
> >>>>>>>> QEMU_ARCH_OR1K |
> >>>>>>>> QEMU_ARCH_XTENSA |
> >>>>>>>> QEMU_ARCH_HEXAGON
> >>>>>>>>
> >>>>>>>> So that we won't have a list of conflict QOM names for "virt" machines.
> >>>>>>>> As now we indeed have only a single "virt" machine that redirects to
> >>>>>>>> different targets.
> >>>>>>>>
> >>>>>>>
> >>>>>>> The idea looks appealing, but I don't think it solves the problem to
> >>>>>>> have multiple virt variants available at the same time.
> >>>>>>>
> >>>>>>> The "alias" idea you introduced before is good, we just need to add a
> >>>>>>> check if an alias is really unique, else return an error, as explained
> >>>>>>> previously.
> >>>>>>>
> >>>>>>> If "-M aarch64-virt" works for both the new and existing binary, and -M
> >>>>>>> virt only for existing binaries (and ambiguous for new one), I think
> >>>>>>> that's a safe approach.
> >>>>>>>
> >>>>>>>>
> >>>>>>>> For other types also conflict can be handled in the same way, such as
> >>>>>>>> "-cpu host" "-cpu max"
> >>>>>>>> maybe others, but I think they all have the same way to deal with.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> That's why  TypeInfo::targets and TypeImpl::targets better than sole
> >>>>>>>> Machine::targets
> >>>>>>>>
> >>>>>>>
> >>>>>>> One step at a time.
> >>>>>>> Let's keep focused on declaring targets for a single machine first.
> >>>>>>> Then we can iterate to solve the "virt" problem.
> >>>>>>> Then convert all the existing machines and add a check in machine-target.c
> >>>>>>> Then, and only then, we can see what happens with cpus.
> >>>>>>
> >>>>>> I tried this idea, but I faced a fatal error, because the
> >>>>>> target_info() is not available until
> >>>>>> the machine selected(the target arch will be select just along with
> >>>>>> the machine selected), so basically
> >>>>>> all calls to target_info() would raise an error(null pointer), how to
> >>>>>> deal with it?
> >>>>>>
> >>>>>
> >>>>> I see. Indeed, since we can't set a target before registering all types,
> >>>>> it implies that all the types class_init can't use target_* functions.
> >>>>>
> >>>>>
> >>>>> - register_accel_target_type
> >>>>> - cpu_max_v8_register_type
> >>>>>
> >>>>
> >>>> Sorry, mail sent to early.
> >>>>
> >>>> For the is_available callback usage, it should be easy to do the switch,
> >>>> since it's basically the same information that what we are trying to do
> >>>> - we can leave them for now.
> >>>>
> >>>> Some types (like accel and max mentioned above), explicitly change their
> >>>> definition depending on the target. It's a behavior we can't rely on
> >>>> anymore, and it means we need proper distinct types instead of a single
> >>>> one with dynamic definition driven by target-info.
> >>>>
> >>>> I think that's the preliminary work needed, before being able to go
> >>>> further: convert all existing usage in class_init with distinct types +
> >>>> is_available, and then we can do the switch from is_available to the new
> >>>> .targets approach.
> >>>
> >>> Hi Pierrick,
> >>> I have already tried that introducing new QOM names just to make class_init
> >>>    target-independent is too broad(means all usage of it should be handled)
> >>> and could complicate compatibility(changed too much code).
> >>> Can we avoid new names by some new means(ideas welcome)?
> >>>
> >>
> >> As a first step, I don't think we need new names, is_available can be
> >> used to selectively register one definition or another and avoid any
> >> clash. What is missing at the moment though, is that some types (like
> >> cpu max above) change their definition based on target definition.
> >
> >
> >>
> >> So for cpu max, we would have two distinct types, both named max, but
> >> one with is_available(target_arm), and other one with
> >> is_available(target_aarch64), so they are never registered at the same time.
> >
> >>
> >> Same for virt machines. It's already what we have, duplication is
> >> handled at the moment with distinct is_available callbacks.
> >>
> >> Then, see below.
> >>
> >>>
> >>>>
> >>>> It's probably worth having the conversion in its own series (only
> >>>> cleanup usage of target_* in class_init), before trying to get rid of
> >>>> is_available.
> >>>
> >>>>
> >>>> For the implementation, you can use the multi-targets.c binary test to
> >>>> drive the change. Remove the module init for target info (leaving no
> >>>> target set), and add a hacky patch to skip call to is_available (and
> >>>> return true instead) and allow double definition (which will rely on
> >>>> is_available). Then, fix all the segfault. Once it compiles and runs,
> >>>> only double definition will be left, which can be handled by inserting
> >>>> the right is_available callbacks. Then in a subsequent series, the
> >>>> switch to .targets can be made.
> >>>
> >>>
> >>> Still have no clean clue about how to remove is_available , as we have many
> >>> "virt" machines. Do you means all "virt" machines with "virt-machine" QOM names
> >>> are inserted to the table? How to get it working because the "key" is string.
> >>>
> >>
> >> Once we have type definition which only depends on is_available, we can
> >> convert this to .targets, which would contain the same information.
> >> For the rest, I have some ideas, but I would like first we do the first
> >> part (convert to is_available), which is already a huge work in itself,
> >> and a series of its own.
> >
> > Indeed I am confused .targets only exists on Machine, how is it
> > related to -cpu host -cpu max?
> >
>
> We can introduce cpu.targets after machine.targets.
> First step is just to get something that works with is_available and
> does not require any target info to be set.

Feels weird, what's wrong with this method:
 target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/target/arm/tcg/cpu-max-v8.c b/target/arm/tcg/cpu-max-v8.c
index 65f851f2006..d7323ab431c 100644
--- a/target/arm/tcg/cpu-max-v8.c
+++ b/target/arm/tcg/cpu-max-v8.c
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
 #endif
 }

+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
 static void cpu_max_v8_register_type(void)
 {
-    static const ARMCPUInfo max_v8[2] = {
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
     };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
 }
 type_init(cpu_max_v8_register_type)


>
> >
> > I already have a working copy that does not depend on target_info()
> > and selects target_info() when the machine
> > is selected, no QOM name introduced. only for machines, we will have
> > $target_name-$machine_name as a name for selecting
> > the exact machine.
> >
> > The cpu max cpu host is dealt by moving the choose code out of
> > class_init, into object_init. I really did not get your idea by use
> > is_avaiable. because when I try to get all QOMs to be registered. then
> > I won't call is_available at all.
>
> As a first step, we rely on is_available, to work on distinguishing
> proper types per target and break the dependency of multiple class_init
> to target_info. Then, we can replace is_available with .targets.
>
> > because "is_available" depends on target_info(),(we won't have
> > target_info() till the machine is selected).
> >
>
> We can imagine registering types in different buckets per target, which
> would allow for duplication.


So your idea is multiple hash-tables for QOM types? key is the target_arch?

>
> Regards,
> Pierrick



-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Pierrick Bouvier 1 month, 1 week ago
On 10/12/2026 9:03 PM, Yonggang Luo wrote:
> On Tue, Oct 13, 2026 at 11:53 AM Pierrick Bouvier
> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>
>> On 10/12/26 7:43 PM, Yonggang Luo wrote:
>>> On Tue, Oct 13, 2026 at 9:26 AM Pierrick Bouvier
>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>>
>>>> On 10/11/26 9:26 PM, Yonggang Luo wrote:
>>>>> On Mon, Oct 12, 2026 at 10:25 AM Pierrick Bouvier
>>>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>>>>
>>>>>> On 10/11/26 7:13 PM, Pierrick Bouvier wrote:
>>>>>>> On 10/11/26 1:22 PM, Yonggang Luo wrote:
>>>>>>>> On Fri, Oct 9, 2026 at 2:34 AM Pierrick Bouvier
>>>>>>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>>>>>>>
>>>>>>>>> On 10/8/2026 10:13 AM, Yonggang Luo wrote:
>>>>>>>>>> On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
>>>>>>>>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
>>>>>>>>>>>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
>>>>>>>>>>>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
>>>>>>>>>>>>>>> This allows a combined binary to register machine types from all its targets.
>>>>>>>>>>>>>>> Consequently, QMP `query-machines` can return machine entries from every
>>>>>>>>>>>>>>> target, even when `none` is selected. For example, a client can query the
>>>>>>>>>>>>>>> combined machine list with:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> ```json
>>>>>>>>>>>>>>> { "execute": "query-machines" }
>>>>>>>>>>>>>>> ```
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> The returned list includes the registered machine classes from all linked
>>>>>>>>>>>>>>> targets. This is separate from selecting a machine: with `-target none`,
>>>>>>>>>>>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
>>>>>>>>>>>>>>> arbitrarily:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> ```text
>>>>>>>>>>>>>>> qemu-system -target none -M virt
>>>>>>>>>>>>>>> unsupported machine type: "virt" for target "none"
>>>>>>>>>>>>>>> Available for targets:
>>>>>>>>>>>>>>>       aarch64
>>>>>>>>>>>>>>>       arm
>>>>>>>>>>>>>>> ```
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>     From the long conversation on a previous thread, I thought we reached
>>>>>>>>>>>>>> the conclusion that if we didn't expose any ambiguous name, then -target
>>>>>>>>>>>>>> option is unnecessary, or maybe I got lost on track of this thread.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I'm not sure which semantic we want to have with -target none. If there
>>>>>>>>>>>>>> is no ambiguous name registered, we just don't need it at all. It's a
>>>>>>>>>>>>>> win-win IMHO.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Yes, if we expose unique names for every machine, then -target is then
>>>>>>>>>>>>> redundant.
>>>>>>>>>>>>
>>>>>>>>>>>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
>>>>>>>>>>>> needs two name?
>>>>>>>>>>>> "virt" needs register twice for it? or register only a single time,
>>>>>>>>>>>> but we prefix the target_name()
>>>>>>>>>>>> automatically? for example machine::name === "virt", but we can use
>>>>>>>>>>>> "riscv32-virt" "risv64-virt" to reach it?
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Yes, ideally we should have different variant of virt for 32/64 bit.
>>>>>>>>>>> Same goes for cpu max types.
>>>>>>>>>>>
>>>>>>>>>>> QOM type is always registered unambiguously ("$arch-virt"). Then, for
>>>>>>>>>>> the "alias" name, which is virt, in case multiple matches are found,
>>>>>>>>>>> command line can return an error with list of unambiguous names to call it.
>>>>>>>>>>>
>>>>>>>>>>> $ qemu-system -M virt
>>>>>>>>>>> Multiple virt machines are available. Please choose one of them:
>>>>>>>>>>> - aarch64-virt
>>>>>>>>>>> - riscv64-virt
>>>>>>>>>>>
>>>>>>>>>>> There is no "parsing" of the argument, it's just the real QOM type. Then
>>>>>>>>>>> we can find which target it implements from mc->targets.
>>>>>>>>>>> And then, we can automatically choose which cpus should be available
>>>>>>>>>>> based on that, thanks to cpu->targets.
>>>>>>>>>>>
>>>>>>>>>>> For existing binaries, nothing change.
>>>>>>>>>>
>>>>>>>>>> Good, I think we found a clean way now, is_available should be
>>>>>>>>>> removed, and TypeInfo::targets and TypeImpl::targets should be added.
>>>>>>>>>
>>>>>>>>> It goes into MachineClass only for now.
>>>>>>>>>
>>>>>>>>>> I think
>>>>>>>>>> for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
>>>>>>>>>> the $arch specific virt. so that we only have a single "virt" registered.
>>>>>>>>>> And it's
>>>>>>>>>> targets is
>>>>>>>>>> QEMU_ARCH_I386 |
>>>>>>>>>> QEMU_ARCH_ARM |
>>>>>>>>>> QEMU_ARCH_RISCV |
>>>>>>>>>> QEMU_ARCH_LOONGARCH |
>>>>>>>>>> QEMU_ARCH_M68K |
>>>>>>>>>> QEMU_ARCH_OR1K |
>>>>>>>>>> QEMU_ARCH_XTENSA |
>>>>>>>>>> QEMU_ARCH_HEXAGON
>>>>>>>>>>
>>>>>>>>>> So that we won't have a list of conflict QOM names for "virt" machines.
>>>>>>>>>> As now we indeed have only a single "virt" machine that redirects to
>>>>>>>>>> different targets.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> The idea looks appealing, but I don't think it solves the problem to
>>>>>>>>> have multiple virt variants available at the same time.
>>>>>>>>>
>>>>>>>>> The "alias" idea you introduced before is good, we just need to add a
>>>>>>>>> check if an alias is really unique, else return an error, as explained
>>>>>>>>> previously.
>>>>>>>>>
>>>>>>>>> If "-M aarch64-virt" works for both the new and existing binary, and -M
>>>>>>>>> virt only for existing binaries (and ambiguous for new one), I think
>>>>>>>>> that's a safe approach.
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> For other types also conflict can be handled in the same way, such as
>>>>>>>>>> "-cpu host" "-cpu max"
>>>>>>>>>> maybe others, but I think they all have the same way to deal with.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> That's why  TypeInfo::targets and TypeImpl::targets better than sole
>>>>>>>>>> Machine::targets
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> One step at a time.
>>>>>>>>> Let's keep focused on declaring targets for a single machine first.
>>>>>>>>> Then we can iterate to solve the "virt" problem.
>>>>>>>>> Then convert all the existing machines and add a check in machine-target.c
>>>>>>>>> Then, and only then, we can see what happens with cpus.
>>>>>>>>
>>>>>>>> I tried this idea, but I faced a fatal error, because the
>>>>>>>> target_info() is not available until
>>>>>>>> the machine selected(the target arch will be select just along with
>>>>>>>> the machine selected), so basically
>>>>>>>> all calls to target_info() would raise an error(null pointer), how to
>>>>>>>> deal with it?
>>>>>>>>
>>>>>>>
>>>>>>> I see. Indeed, since we can't set a target before registering all types,
>>>>>>> it implies that all the types class_init can't use target_* functions.
>>>>>>>
>>>>>>>
>>>>>>> - register_accel_target_type
>>>>>>> - cpu_max_v8_register_type
>>>>>>>
>>>>>>
>>>>>> Sorry, mail sent to early.
>>>>>>
>>>>>> For the is_available callback usage, it should be easy to do the switch,
>>>>>> since it's basically the same information that what we are trying to do
>>>>>> - we can leave them for now.
>>>>>>
>>>>>> Some types (like accel and max mentioned above), explicitly change their
>>>>>> definition depending on the target. It's a behavior we can't rely on
>>>>>> anymore, and it means we need proper distinct types instead of a single
>>>>>> one with dynamic definition driven by target-info.
>>>>>>
>>>>>> I think that's the preliminary work needed, before being able to go
>>>>>> further: convert all existing usage in class_init with distinct types +
>>>>>> is_available, and then we can do the switch from is_available to the new
>>>>>> .targets approach.
>>>>>
>>>>> Hi Pierrick,
>>>>> I have already tried that introducing new QOM names just to make class_init
>>>>>    target-independent is too broad(means all usage of it should be handled)
>>>>> and could complicate compatibility(changed too much code).
>>>>> Can we avoid new names by some new means(ideas welcome)?
>>>>>
>>>>
>>>> As a first step, I don't think we need new names, is_available can be
>>>> used to selectively register one definition or another and avoid any
>>>> clash. What is missing at the moment though, is that some types (like
>>>> cpu max above) change their definition based on target definition.
>>>
>>>
>>>>
>>>> So for cpu max, we would have two distinct types, both named max, but
>>>> one with is_available(target_arm), and other one with
>>>> is_available(target_aarch64), so they are never registered at the same time.
>>>
>>>>
>>>> Same for virt machines. It's already what we have, duplication is
>>>> handled at the moment with distinct is_available callbacks.
>>>>
>>>> Then, see below.
>>>>
>>>>>
>>>>>>
>>>>>> It's probably worth having the conversion in its own series (only
>>>>>> cleanup usage of target_* in class_init), before trying to get rid of
>>>>>> is_available.
>>>>>
>>>>>>
>>>>>> For the implementation, you can use the multi-targets.c binary test to
>>>>>> drive the change. Remove the module init for target info (leaving no
>>>>>> target set), and add a hacky patch to skip call to is_available (and
>>>>>> return true instead) and allow double definition (which will rely on
>>>>>> is_available). Then, fix all the segfault. Once it compiles and runs,
>>>>>> only double definition will be left, which can be handled by inserting
>>>>>> the right is_available callbacks. Then in a subsequent series, the
>>>>>> switch to .targets can be made.
>>>>>
>>>>>
>>>>> Still have no clean clue about how to remove is_available , as we have many
>>>>> "virt" machines. Do you means all "virt" machines with "virt-machine" QOM names
>>>>> are inserted to the table? How to get it working because the "key" is string.
>>>>>
>>>>
>>>> Once we have type definition which only depends on is_available, we can
>>>> convert this to .targets, which would contain the same information.
>>>> For the rest, I have some ideas, but I would like first we do the first
>>>> part (convert to is_available), which is already a huge work in itself,
>>>> and a series of its own.
>>>
>>> Indeed I am confused .targets only exists on Machine, how is it
>>> related to -cpu host -cpu max?
>>>
>>
>> We can introduce cpu.targets after machine.targets.
>> First step is just to get something that works with is_available and
>> does not require any target info to be set.
> 
> Feels weird, what's wrong with this method:
>  target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/target/arm/tcg/cpu-max-v8.c b/target/arm/tcg/cpu-max-v8.c
> index 65f851f2006..d7323ab431c 100644
> --- a/target/arm/tcg/cpu-max-v8.c
> +++ b/target/arm/tcg/cpu-max-v8.c
> @@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
>  #endif
>  }
> 
> +static void max_v8_tcg_initfn(Object *obj)
> +{
> +    if (target_aarch64()) {
> +        aarch64_max_v8_tcg_initfn(obj);
> +    } else {
> +        aarch32_max_v8_tcg_initfn(obj);
> +    }
> +}
> +
>  static void cpu_max_v8_register_type(void)
>  {
> -    static const ARMCPUInfo max_v8[2] = {
> -        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
> -        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
> +    static const ARMCPUInfo max_v8 = {
> +        .name = "max-v8",
> +        .initfn = max_v8_tcg_initfn,
>      };
> -    arm_cpu_register(&max_v8[target_aarch64()]);
> +    arm_cpu_register(&max_v8);
>  }
>  type_init(cpu_max_v8_register_type)
>

In this case, It seems simpler to me to register two max types, with
different is_available. Arm maintainers might have a different opinion,
so I encourage you to post this as a separate series with them in cc.

It's also the last inline patch I'll answer to (next ones will be
silently ignored).

> 
>>
>>>
>>> I already have a working copy that does not depend on target_info()
>>> and selects target_info() when the machine
>>> is selected, no QOM name introduced. only for machines, we will have
>>> $target_name-$machine_name as a name for selecting
>>> the exact machine.
>>>
>>> The cpu max cpu host is dealt by moving the choose code out of
>>> class_init, into object_init. I really did not get your idea by use
>>> is_avaiable. because when I try to get all QOMs to be registered. then
>>> I won't call is_available at all.
>>
>> As a first step, we rely on is_available, to work on distinguishing
>> proper types per target and break the dependency of multiple class_init
>> to target_info. Then, we can replace is_available with .targets.
>>
>>> because "is_available" depends on target_info(),(we won't have
>>> target_info() till the machine is selected).
>>>
>>
>> We can imagine registering types in different buckets per target, which
>> would allow for duplication.
> 
> 
> So your idea is multiple hash-tables for QOM types? key is the target_arch?
>

I don't want to dig more into this now, a lot of preliminary work has
been discussed already, let's focus on that.

Regards,
Pierrick

Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Pierrick Bouvier 1 month, 1 week ago
On 10/11/26 9:26 PM, Yonggang Luo wrote:
> On Mon, Oct 12, 2026 at 10:25 AM Pierrick Bouvier
> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>
>> On 10/11/26 7:13 PM, Pierrick Bouvier wrote:
>>> On 10/11/26 1:22 PM, Yonggang Luo wrote:
>>>> On Fri, Oct 9, 2026 at 2:34 AM Pierrick Bouvier
>>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>>>
>>>>> On 10/8/2026 10:13 AM, Yonggang Luo wrote:
>>>>>> On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
>>>>>> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>>>>>>
>>>>>>> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
>>>>>>>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>>>>>>>>>
>>>>>>>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
>>>>>>>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
>>>>>>>>>>> This allows a combined binary to register machine types from all its targets.
>>>>>>>>>>> Consequently, QMP `query-machines` can return machine entries from every
>>>>>>>>>>> target, even when `none` is selected. For example, a client can query the
>>>>>>>>>>> combined machine list with:
>>>>>>>>>>>
>>>>>>>>>>> ```json
>>>>>>>>>>> { "execute": "query-machines" }
>>>>>>>>>>> ```
>>>>>>>>>>>
>>>>>>>>>>> The returned list includes the registered machine classes from all linked
>>>>>>>>>>> targets. This is separate from selecting a machine: with `-target none`,
>>>>>>>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
>>>>>>>>>>> arbitrarily:
>>>>>>>>>>>
>>>>>>>>>>> ```text
>>>>>>>>>>> qemu-system -target none -M virt
>>>>>>>>>>> unsupported machine type: "virt" for target "none"
>>>>>>>>>>> Available for targets:
>>>>>>>>>>>      aarch64
>>>>>>>>>>>      arm
>>>>>>>>>>> ```
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>    From the long conversation on a previous thread, I thought we reached
>>>>>>>>>> the conclusion that if we didn't expose any ambiguous name, then -target
>>>>>>>>>> option is unnecessary, or maybe I got lost on track of this thread.
>>>>>>>>>>
>>>>>>>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
>>>>>>>>>>
>>>>>>>>>> I'm not sure which semantic we want to have with -target none. If there
>>>>>>>>>> is no ambiguous name registered, we just don't need it at all. It's a
>>>>>>>>>> win-win IMHO.
>>>>>>>>>
>>>>>>>>> Yes, if we expose unique names for every machine, then -target is then
>>>>>>>>> redundant.
>>>>>>>>
>>>>>>>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
>>>>>>>> needs two name?
>>>>>>>> "virt" needs register twice for it? or register only a single time,
>>>>>>>> but we prefix the target_name()
>>>>>>>> automatically? for example machine::name === "virt", but we can use
>>>>>>>> "riscv32-virt" "risv64-virt" to reach it?
>>>>>>>>
>>>>>>>
>>>>>>> Yes, ideally we should have different variant of virt for 32/64 bit.
>>>>>>> Same goes for cpu max types.
>>>>>>>
>>>>>>> QOM type is always registered unambiguously ("$arch-virt"). Then, for
>>>>>>> the "alias" name, which is virt, in case multiple matches are found,
>>>>>>> command line can return an error with list of unambiguous names to call it.
>>>>>>>
>>>>>>> $ qemu-system -M virt
>>>>>>> Multiple virt machines are available. Please choose one of them:
>>>>>>> - aarch64-virt
>>>>>>> - riscv64-virt
>>>>>>>
>>>>>>> There is no "parsing" of the argument, it's just the real QOM type. Then
>>>>>>> we can find which target it implements from mc->targets.
>>>>>>> And then, we can automatically choose which cpus should be available
>>>>>>> based on that, thanks to cpu->targets.
>>>>>>>
>>>>>>> For existing binaries, nothing change.
>>>>>>
>>>>>> Good, I think we found a clean way now, is_available should be
>>>>>> removed, and TypeInfo::targets and TypeImpl::targets should be added.
>>>>>
>>>>> It goes into MachineClass only for now.
>>>>>
>>>>>> I think
>>>>>> for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
>>>>>> the $arch specific virt. so that we only have a single "virt" registered.
>>>>>> And it's
>>>>>> targets is
>>>>>> QEMU_ARCH_I386 |
>>>>>> QEMU_ARCH_ARM |
>>>>>> QEMU_ARCH_RISCV |
>>>>>> QEMU_ARCH_LOONGARCH |
>>>>>> QEMU_ARCH_M68K |
>>>>>> QEMU_ARCH_OR1K |
>>>>>> QEMU_ARCH_XTENSA |
>>>>>> QEMU_ARCH_HEXAGON
>>>>>>
>>>>>> So that we won't have a list of conflict QOM names for "virt" machines.
>>>>>> As now we indeed have only a single "virt" machine that redirects to
>>>>>> different targets.
>>>>>>
>>>>>
>>>>> The idea looks appealing, but I don't think it solves the problem to
>>>>> have multiple virt variants available at the same time.
>>>>>
>>>>> The "alias" idea you introduced before is good, we just need to add a
>>>>> check if an alias is really unique, else return an error, as explained
>>>>> previously.
>>>>>
>>>>> If "-M aarch64-virt" works for both the new and existing binary, and -M
>>>>> virt only for existing binaries (and ambiguous for new one), I think
>>>>> that's a safe approach.
>>>>>
>>>>>>
>>>>>> For other types also conflict can be handled in the same way, such as
>>>>>> "-cpu host" "-cpu max"
>>>>>> maybe others, but I think they all have the same way to deal with.
>>>>>>
>>>>>>
>>>>>> That's why  TypeInfo::targets and TypeImpl::targets better than sole
>>>>>> Machine::targets
>>>>>>
>>>>>
>>>>> One step at a time.
>>>>> Let's keep focused on declaring targets for a single machine first.
>>>>> Then we can iterate to solve the "virt" problem.
>>>>> Then convert all the existing machines and add a check in machine-target.c
>>>>> Then, and only then, we can see what happens with cpus.
>>>>
>>>> I tried this idea, but I faced a fatal error, because the
>>>> target_info() is not available until
>>>> the machine selected(the target arch will be select just along with
>>>> the machine selected), so basically
>>>> all calls to target_info() would raise an error(null pointer), how to
>>>> deal with it?
>>>>
>>>
>>> I see. Indeed, since we can't set a target before registering all types,
>>> it implies that all the types class_init can't use target_* functions.
>>>
>>>
>>> - register_accel_target_type
>>> - cpu_max_v8_register_type
>>>
>>
>> Sorry, mail sent to early.
>>
>> For the is_available callback usage, it should be easy to do the switch,
>> since it's basically the same information that what we are trying to do
>> - we can leave them for now.
>>
>> Some types (like accel and max mentioned above), explicitly change their
>> definition depending on the target. It's a behavior we can't rely on
>> anymore, and it means we need proper distinct types instead of a single
>> one with dynamic definition driven by target-info.
>>
>> I think that's the preliminary work needed, before being able to go
>> further: convert all existing usage in class_init with distinct types +
>> is_available, and then we can do the switch from is_available to the new
>> .targets approach.
> 
> Hi Pierrick,
> I have already tried that introducing new QOM names just to make class_init
>   target-independent is too broad(means all usage of it should be handled)
> and could complicate compatibility(changed too much code).
> Can we avoid new names by some new means(ideas welcome)?
>

We can use is_available as an intermediate step.
The good thing is that removing target_* from class_init can be done as 
much incrementally as we want: there is no need to do all the changes at 
once.

Once we get to the point where there is no target_* in class_init and 
all types are properly defined with is_available filters, we can see how 
to deal with the duplication. My point of view after our discussions is 
that we should keep current name for existing binaries, and should be 
free to force user to deal with ambiguity with new single-binary 
(machine type "X" is ambiguous, please choose among arch-X, arch-Y, ...).

> 
>>
>> It's probably worth having the conversion in its own series (only
>> cleanup usage of target_* in class_init), before trying to get rid of
>> is_available.
> 
>>
>> For the implementation, you can use the multi-targets.c binary test to
>> drive the change. Remove the module init for target info (leaving no
>> target set), and add a hacky patch to skip call to is_available (and
>> return true instead) and allow double definition (which will rely on
>> is_available). Then, fix all the segfault. Once it compiles and runs,
>> only double definition will be left, which can be handled by inserting
>> the right is_available callbacks. Then in a subsequent series, the
>> switch to .targets can be made.
> 
> 
> Still have no clean clue about how to remove is_available , as we have many
> "virt" machines. Do you means all "virt" machines with "virt-machine" QOM names
> are inserted to the table? How to get it working because the "key" is string.
>

The alias series you posted initially was good, with the addition to 
detect when multiple machines have the same alias (and report an error 
in this case).

I triggered the conversation we are having now because things have not 
been defined properly, and the direction to have -target + arch:machine 
was not really satisfactory. Now we settled on excluding -target, and 
embedding all types, I think it's clearer.

> 
>>
>> It's a work we'll need to do for heterogeneous anyway, I was just hoping
>> to delay that until there, but seems we need to deal with it now.
>> A good thing is that it means target-info won't have to be registered
>> before all QOM types anymore, so it's worth the effort IMHO.
>>
>> Thanks,
>> Pierrick
> 
> 
> 


Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Yonggang Luo 1 month, 1 week ago
On Mon, Oct 12, 2026 at 10:13 AM Pierrick Bouvier
<pierrick.bouvier@oss.qualcomm.com> wrote:
>
> On 10/11/26 1:22 PM, Yonggang Luo wrote:
> > On Fri, Oct 9, 2026 at 2:34 AM Pierrick Bouvier
> > <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>
> >> On 10/8/2026 10:13 AM, Yonggang Luo wrote:
> >>> On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
> >>> <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>>>
> >>>> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
> >>>>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >>>>>>
> >>>>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
> >>>>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
> >>>>>>>> This allows a combined binary to register machine types from all its targets.
> >>>>>>>> Consequently, QMP `query-machines` can return machine entries from every
> >>>>>>>> target, even when `none` is selected. For example, a client can query the
> >>>>>>>> combined machine list with:
> >>>>>>>>
> >>>>>>>> ```json
> >>>>>>>> { "execute": "query-machines" }
> >>>>>>>> ```
> >>>>>>>>
> >>>>>>>> The returned list includes the registered machine classes from all linked
> >>>>>>>> targets. This is separate from selecting a machine: with `-target none`,
> >>>>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
> >>>>>>>> arbitrarily:
> >>>>>>>>
> >>>>>>>> ```text
> >>>>>>>> qemu-system -target none -M virt
> >>>>>>>> unsupported machine type: "virt" for target "none"
> >>>>>>>> Available for targets:
> >>>>>>>>    aarch64
> >>>>>>>>    arm
> >>>>>>>> ```
> >>>>>>>>
> >>>>>>>
> >>>>>>>  From the long conversation on a previous thread, I thought we reached
> >>>>>>> the conclusion that if we didn't expose any ambiguous name, then -target
> >>>>>>> option is unnecessary, or maybe I got lost on track of this thread.
> >>>>>>>
> >>>>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
> >>>>>>>
> >>>>>>> I'm not sure which semantic we want to have with -target none. If there
> >>>>>>> is no ambiguous name registered, we just don't need it at all. It's a
> >>>>>>> win-win IMHO.
> >>>>>>
> >>>>>> Yes, if we expose unique names for every machine, then -target is then
> >>>>>> redundant.
> >>>>>
> >>>>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
> >>>>> needs two name?
> >>>>> "virt" needs register twice for it? or register only a single time,
> >>>>> but we prefix the target_name()
> >>>>> automatically? for example machine::name === "virt", but we can use
> >>>>> "riscv32-virt" "risv64-virt" to reach it?
> >>>>>
> >>>>
> >>>> Yes, ideally we should have different variant of virt for 32/64 bit.
> >>>> Same goes for cpu max types.
> >>>>
> >>>> QOM type is always registered unambiguously ("$arch-virt"). Then, for
> >>>> the "alias" name, which is virt, in case multiple matches are found,
> >>>> command line can return an error with list of unambiguous names to call it.
> >>>>
> >>>> $ qemu-system -M virt
> >>>> Multiple virt machines are available. Please choose one of them:
> >>>> - aarch64-virt
> >>>> - riscv64-virt
> >>>>
> >>>> There is no "parsing" of the argument, it's just the real QOM type. Then
> >>>> we can find which target it implements from mc->targets.
> >>>> And then, we can automatically choose which cpus should be available
> >>>> based on that, thanks to cpu->targets.
> >>>>
> >>>> For existing binaries, nothing change.
> >>>
> >>> Good, I think we found a clean way now, is_available should be
> >>> removed, and TypeInfo::targets and TypeImpl::targets should be added.
> >>
> >> It goes into MachineClass only for now.
> >>
> >>> I think
> >>> for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
> >>> the $arch specific virt. so that we only have a single "virt" registered.
> >>> And it's
> >>> targets is
> >>> QEMU_ARCH_I386 |
> >>> QEMU_ARCH_ARM |
> >>> QEMU_ARCH_RISCV |
> >>> QEMU_ARCH_LOONGARCH |
> >>> QEMU_ARCH_M68K |
> >>> QEMU_ARCH_OR1K |
> >>> QEMU_ARCH_XTENSA |
> >>> QEMU_ARCH_HEXAGON
> >>>
> >>> So that we won't have a list of conflict QOM names for "virt" machines.
> >>> As now we indeed have only a single "virt" machine that redirects to
> >>> different targets.
> >>>
> >>
> >> The idea looks appealing, but I don't think it solves the problem to
> >> have multiple virt variants available at the same time.
> >>
> >> The "alias" idea you introduced before is good, we just need to add a
> >> check if an alias is really unique, else return an error, as explained
> >> previously.
> >>
> >> If "-M aarch64-virt" works for both the new and existing binary, and -M
> >> virt only for existing binaries (and ambiguous for new one), I think
> >> that's a safe approach.
> >>
> >>>
> >>> For other types also conflict can be handled in the same way, such as
> >>> "-cpu host" "-cpu max"
> >>> maybe others, but I think they all have the same way to deal with.
> >>>
> >>>
> >>> That's why  TypeInfo::targets and TypeImpl::targets better than sole
> >>> Machine::targets
> >>>
> >>
> >> One step at a time.
> >> Let's keep focused on declaring targets for a single machine first.
> >> Then we can iterate to solve the "virt" problem.
> >> Then convert all the existing machines and add a check in machine-target.c
> >> Then, and only then, we can see what happens with cpus.
> >
> > I tried this idea, but I faced a fatal error, because the
> > target_info() is not available until
> > the machine selected(the target arch will be select just along with
> > the machine selected), so basically
> > all calls to target_info() would raise an error(null pointer), how to
> > deal with it?
> >
>
> I see. Indeed, since we can't set a target before registering all types,
> it implies that all the types class_init can't use target_* functions.
>
>
> - register_accel_target_type
> - cpu_max_v8_register_type

Hi Pierrick

These two I can handle it properly, only for the "virt" machine I can
not handle it properly
What you suggest, it's a must-be requirement now.


for example, cpu_max_v8_register_type can be handle in such way:

 target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/target/arm/tcg/cpu-max-v8.c b/target/arm/tcg/cpu-max-v8.c
index 65f851f2006..d7323ab431c 100644
--- a/target/arm/tcg/cpu-max-v8.c
+++ b/target/arm/tcg/cpu-max-v8.c
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
 #endif
 }

+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
 static void cpu_max_v8_register_type(void)
 {
-    static const ARMCPUInfo max_v8[2] = {
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
     };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
 }
 type_init(cpu_max_v8_register_type)



register_accel_target_type:

 accel/accel-common.c             | 21 ++++++---------------
 include/accel/accel-cpu-target.h |  3 +--
 include/accel/accel-cpu.h        |  2 ++
 3 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/accel/accel-common.c b/accel/accel-common.c
index 00a400243f0..c4c365f38c7 100644
--- a/accel/accel-common.c
+++ b/accel/accel-common.c
@@ -126,21 +126,12 @@ static const TypeInfo accel_types[] = {
         .instance_size  = sizeof(AccelState),
         .abstract       = true,
     },
+    {
+        .name           = TYPE_ACCEL_CPU,
+        .parent         = TYPE_OBJECT,
+        .abstract       = true,
+        .class_size     = sizeof(AccelCPUClass),
+    },
 };

 DEFINE_TYPES(accel_types)
-
-static void register_accel_target_type(void)
-{
-    g_autofree char *name = g_strconcat("accel-", target_cpu_type(), NULL);
-    const TypeInfo accel_cpu_type = {
-        .name = name,
-        .parent = TYPE_OBJECT,
-        .abstract = true,
-        .class_size = sizeof(AccelCPUClass),
-    };
-
-    type_register_static(&accel_cpu_type);
-}
-
-type_init(register_accel_target_type);
diff --git a/include/accel/accel-cpu-target.h b/include/accel/accel-cpu-target.h
index 6feb344e29b..cf33ebd79fc 100644
--- a/include/accel/accel-cpu-target.h
+++ b/include/accel/accel-cpu-target.h
@@ -24,8 +24,7 @@
 #include "accel/accel-cpu.h"
 #include "cpu.h"

-#define TYPE_ACCEL_CPU "accel-" CPU_RESOLVING_TYPE
-#define ACCEL_CPU_NAME(name) (name "-" TYPE_ACCEL_CPU)
+#define ACCEL_CPU_NAME(name) (name "-accel-" CPU_RESOLVING_TYPE)
 DECLARE_CLASS_CHECKERS(AccelCPUClass, ACCEL_CPU, TYPE_ACCEL_CPU)

 #endif /* ACCEL_CPU_H */
diff --git a/include/accel/accel-cpu.h b/include/accel/accel-cpu.h
index 9e7eede7c3c..5cfc2b24223 100644
--- a/include/accel/accel-cpu.h
+++ b/include/accel/accel-cpu.h
@@ -12,6 +12,8 @@
 #include "qom/object.h"
 #include "hw/core/cpu.h"

+#define TYPE_ACCEL_CPU "accel-cpu"
+
 typedef struct AccelCPUClass {
     ObjectClass parent_class;


>
>
> >>
> >> Regards,
> >> Pierrick
> >
> >
> >
>


-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Yonggang Luo 1 month, 2 weeks ago
On Fri, Oct 9, 2026 at 2:34 AM Pierrick Bouvier
<pierrick.bouvier@oss.qualcomm.com> wrote:
>
> On 10/8/2026 10:13 AM, Yonggang Luo wrote:
> > On Fri, Oct 9, 2026 at 12:06 AM Pierrick Bouvier
> > <pierrick.bouvier@oss.qualcomm.com> wrote:
> >>
> >> On 10/8/2026 2:46 AM, Yonggang Luo wrote:
> >>> On Thu, Oct 8, 2026 at 5:42 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >>>>
> >>>> On Wed, Oct 07, 2026 at 01:25:46PM -0700, Pierrick Bouvier wrote:
> >>>>> On 10/7/2026 4:47 AM, Yonggang Luo wrote:
> >>>>>> This allows a combined binary to register machine types from all its targets.
> >>>>>> Consequently, QMP `query-machines` can return machine entries from every
> >>>>>> target, even when `none` is selected. For example, a client can query the
> >>>>>> combined machine list with:
> >>>>>>
> >>>>>> ```json
> >>>>>> { "execute": "query-machines" }
> >>>>>> ```
> >>>>>>
> >>>>>> The returned list includes the registered machine classes from all linked
> >>>>>> targets. This is separate from selecting a machine: with `-target none`,
> >>>>>> `-M virt` reports the targets that provide `virt` instead of choosing one
> >>>>>> arbitrarily:
> >>>>>>
> >>>>>> ```text
> >>>>>> qemu-system -target none -M virt
> >>>>>> unsupported machine type: "virt" for target "none"
> >>>>>> Available for targets:
> >>>>>>   aarch64
> >>>>>>   arm
> >>>>>> ```
> >>>>>>
> >>>>>
> >>>>> From the long conversation on a previous thread, I thought we reached
> >>>>> the conclusion that if we didn't expose any ambiguous name, then -target
> >>>>> option is unnecessary, or maybe I got lost on track of this thread.
> >>>>>
> >>>>> https://lore.kernel.org/qemu-devel/ar_coT44h5-zJPVV@redhat.com/
> >>>>>
> >>>>> I'm not sure which semantic we want to have with -target none. If there
> >>>>> is no ambiguous name registered, we just don't need it at all. It's a
> >>>>> win-win IMHO.
> >>>>
> >>>> Yes, if we expose unique names for every machine, then -target is then
> >>>> redundant.
> >>>
> >>> so how to diff riscv32-virt and risv64-virt? oh so for this machine we
> >>> needs two name?
> >>> "virt" needs register twice for it? or register only a single time,
> >>> but we prefix the target_name()
> >>> automatically? for example machine::name === "virt", but we can use
> >>> "riscv32-virt" "risv64-virt" to reach it?
> >>>
> >>
> >> Yes, ideally we should have different variant of virt for 32/64 bit.
> >> Same goes for cpu max types.
> >>
> >> QOM type is always registered unambiguously ("$arch-virt"). Then, for
> >> the "alias" name, which is virt, in case multiple matches are found,
> >> command line can return an error with list of unambiguous names to call it.
> >>
> >> $ qemu-system -M virt
> >> Multiple virt machines are available. Please choose one of them:
> >> - aarch64-virt
> >> - riscv64-virt
> >>
> >> There is no "parsing" of the argument, it's just the real QOM type. Then
> >> we can find which target it implements from mc->targets.
> >> And then, we can automatically choose which cpus should be available
> >> based on that, thanks to cpu->targets.
> >>
> >> For existing binaries, nothing change.
> >
> > Good, I think we found a clean way now, is_available should be
> > removed, and TypeInfo::targets and TypeImpl::targets should be added.
>
> It goes into MachineClass only for now.
>
> > I think
> > for "virt" we can add a shared hw/machine-virt.c instead, and forwarding to
> > the $arch specific virt. so that we only have a single "virt" registered.
> > And it's
> > targets is
> > QEMU_ARCH_I386 |
> > QEMU_ARCH_ARM |
> > QEMU_ARCH_RISCV |
> > QEMU_ARCH_LOONGARCH |
> > QEMU_ARCH_M68K |
> > QEMU_ARCH_OR1K |
> > QEMU_ARCH_XTENSA |
> > QEMU_ARCH_HEXAGON
> >
> > So that we won't have a list of conflict QOM names for "virt" machines.
> > As now we indeed have only a single "virt" machine that redirects to
> > different targets.
> >
>
> The idea looks appealing, but I don't think it solves the problem to
> have multiple virt variants available at the same time.
>
> The "alias" idea you introduced before is good, we just need to add a
> check if an alias is really unique, else return an error, as explained
> previously.
>
> If "-M aarch64-virt" works for both the new and existing binary, and -M
> virt only for existing binaries (and ambiguous for new one), I think
> that's a safe approach.
>
> >
> > For other types also conflict can be handled in the same way, such as
> > "-cpu host" "-cpu max"
> > maybe others, but I think they all have the same way to deal with.
> >
> >
> > That's why  TypeInfo::targets and TypeImpl::targets better than sole
> > Machine::targets
> >
>
> One step at a time.

That makes sense, I am afraid I have no time to trace it currently(at
least a month).
At least we now have a good agreement. So it should be much easier,
otherwise it's really frustrating.

> Let's keep focused on declaring targets for a single machine first.
> Then we can iterate to solve the "virt" problem.
> Then convert all the existing machines and add a check in machine-target.c
> Then, and only then, we can see what happens with cpus.
>
> Regards,
> Pierrick



-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Pierrick Bouvier 1 month, 2 weeks ago
On 10/7/2026 4:47 AM, Yonggang Luo wrote:
> This allows a combined binary to register machine types from all its targets.
> Consequently, QMP `query-machines` can return machine entries from every
> target, even when `none` is selected. For example, a client can query the
> combined machine list with:
> 
> ```json
> { "execute": "query-machines" }
> ```
> 
> The returned list includes the registered machine classes from all linked
> targets. This is separate from selecting a machine: with `-target none`,
> `-M virt` reports the targets that provide `virt` instead of choosing one
> arbitrarily:
> 
> ```text
> qemu-system -target none -M virt
> unsupported machine type: "virt" for target "none"
> Available for targets:
>   aarch64
>   arm
> ```
> 
> It moves target_info() to a shared location so object.c can call it when
> checking machine availability. The series also replaces QOM-based target-info
> registration with a constructor list and passes TargetInfo to the
> is_available callback.
> 
> Target metadata and architecture checks are generated from the configured
> targets, there is too much arch to write biiolperate code. doing this for easier
> Add TargetInfo* to is_available
> 
> The target-info API and implementation are shared, rather than compiled
> separately for every target.
> 
> This series removes the per-target source files "configs/targets/*.c".
> Their target-specific parameters are collected in a generated
> target-info-def.c for each softmmu target. This lays the groundwork for
> QEMU system builds in which target-info-def.c is the only target-specific
> source file compiled for each target. Using the same filename lets
> meson.build handle these definitions uniformly.
> 
> The series adds unit-test coverage for target info and multi-target builds.
> 
> Pierrick Bouvier (2):
>   configs/targets: remove target info definitions
>   target-info: rename target-info-stub.c in target-info-def.c
> 
> Yonggang Luo (6):
>   target-info: rename target-info-impl.h to target-info-def.h
>   target-info: replace QOM registration with a constructor list
>   tests/unit: add target-info coverage for multi-target builds
>   meson: load all target .mak files into target_mak_all
>   target-info: Replace handwritten architecture checks with generated
>     code
>   qom: pass TargetInfo to is_available for later use
> 
>  MAINTAINERS                             |   2 +-
>  configs/targets/aarch64-softmmu.c       |  25 ------
>  configs/targets/arm-softmmu.c           |  25 ------
>  configs/targets/meson.build             |   6 --
>  configs/targets/riscv32-softmmu.c       |  24 -----
>  configs/targets/riscv64-softmmu.c       |  24 -----
>  hw/arm/aspeed_ast27x0-fc.c              |   2 +-
>  hw/arm/aspeed_ast27x0_evb.c             |   4 +-
>  hw/arm/raspi.c                          |   4 +-
>  hw/arm/raspi4b.c                        |   2 +-
>  hw/arm/virt.c                           |   4 +-
>  hw/m68k/virt.c                          |   4 +-
>  hw/or1k/virt.c                          |   2 +-
>  include/hw/core/cpu.h                   |   2 +-
>  include/qemu/module.h                   |   1 -
>  include/qemu/target-info-def.h          |  88 ++++++++++++++++++
>  include/qemu/target-info-impl.h         |  42 ---------
>  include/qemu/target-info-init.h         |  53 -----------
>  include/qemu/target-info-qom.h          |  31 -------
>  include/qemu/target-info.h              |  87 ++++--------------
>  include/qom/object.h                    |  12 ++-
>  meson.build                             |  52 ++++++++---
>  page-vary-common.c                      |   2 +-
>  page-vary-system.c                      |   2 +-
>  qom/object.c                            |   3 +-
>  scripts/gen-target-info.py              |  99 ++++++++++++++++++++
>  system/vl.c                             |   4 -
>  target-info-stub.c => target-info-def.c |   3 +-
>  target-info-qom.c                       |  60 -------------
>  target-info.c                           | 115 ++++++++++++------------
>  tests/qtest/fuzz/fuzz.c                 |   3 -
>  tests/unit/meson.build                  |   4 +
>  tests/unit/test-multi-target.c          |  12 +--
>  tests/unit/test-target-info.c           |  38 ++++++++
>  34 files changed, 379 insertions(+), 462 deletions(-)
>  delete mode 100644 configs/targets/aarch64-softmmu.c
>  delete mode 100644 configs/targets/arm-softmmu.c
>  delete mode 100644 configs/targets/meson.build
>  delete mode 100644 configs/targets/riscv32-softmmu.c
>  delete mode 100644 configs/targets/riscv64-softmmu.c
>  create mode 100644 include/qemu/target-info-def.h
>  delete mode 100644 include/qemu/target-info-impl.h
>  delete mode 100644 include/qemu/target-info-init.h
>  delete mode 100644 include/qemu/target-info-qom.h
>  create mode 100644 scripts/gen-target-info.py
>  rename target-info-stub.c => target-info-def.c (94%)
>  delete mode 100644 target-info-qom.c
>  create mode 100644 tests/unit/test-target-info.c
> 

I'll pull the first three patches.

Regards,
Pierrick
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Pierrick Bouvier 1 month, 2 weeks ago
On 10/7/2026 1:46 PM, Pierrick Bouvier wrote:
> 
> I'll pull the first three patches.
>

Now merged upstream (40ba85501c0b6ac2a7319d3804dab072edf67564)

Thanks,
Pierrick
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Yonggang Luo 1 month, 2 weeks ago
On Sat, Oct 10, 2026 at 5:58 AM Pierrick Bouvier
<pierrick.bouvier@oss.qualcomm.com> wrote:
>
> On 10/7/2026 1:46 PM, Pierrick Bouvier wrote:
> >
> > I'll pull the first three patches.
> >
>
> Now merged upstream (40ba85501c0b6ac2a7319d3804dab072edf67564)
>

Hi Pierrick
Seems you post to the wrong place.

> Thanks,
> Pierrick



-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
Re: [PATCH 0/8] qom: pass TargetInfo to the is_available callback
Posted by Pierrick Bouvier 1 month, 2 weeks ago
On 10/9/2026 3:08 PM, Yonggang Luo wrote:
> On Sat, Oct 10, 2026 at 5:58 AM Pierrick Bouvier
> <pierrick.bouvier@oss.qualcomm.com> wrote:
>>
>> On 10/7/2026 1:46 PM, Pierrick Bouvier wrote:
>>>
>>> I'll pull the first three patches.
>>>
>>
>> Now merged upstream (40ba85501c0b6ac2a7319d3804dab072edf67564)
>>
> 
> Hi Pierrick
> Seems you post to the wrong place.
>

Hi Yonggang,
oops sorry indeed.
I was waiting for previous patches to be merged to send those ones.