All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
To: luoyonggang@gmail.com
Cc: qemu-devel@nongnu.org, anjo@rev.ng,
	"Daniel Henrique Barboza" <daniel.barboza@oss.qualcomm.com>,
	philmd@oss.qualcomm.com,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Daniel P. Berrangé" <berrange@redhat.com>
Subject: Re: [PATCH 33/47] system/vl: add new option -target
Date: Mon, 31 Aug 2026 11:10:15 -0700	[thread overview]
Message-ID: <144ee2dd-371d-4508-9cdb-be6e9c52e657@oss.qualcomm.com> (raw)
In-Reply-To: <CAE2XoE8sGoz9pJcPgqDVKgWa=WbZ1eMk91u6AkEZ4BcRVyyNew@mail.gmail.com>

On 8/31/2026 5:39 AM, Yonggang Luo wrote:
> I would suggest to handle the condition and argv0 and target name
> consitencely, here is my patch summary:
> - Parse -target with QEMU_OPTION_nouserconfig, right after
>   MODULE_INIT_TARGET_INFO, because later init depends on TargetInfo.
> - target_info_qom_set_target() takes Error **errp. A name comes from
>   -target or from argv0 (qemu-system-aarch64).
> - Define SYS_EMU_TARGET_UNSPECIFIED as SYS_EMU_TARGET__MAX. Bare
>   qemu-system with no suffix and no -target binds a dummy TargetInfo.
>   qemu-system-* still selects from the argv[0] suffix.
> - -M help lists the union. Starting a real board without a target
>   errors; -M none is allowed.
> - qemu_arch_available() is true when unspecified. query-target errors
>   instead of emitting an invalid SysEmuTarget.
> - Fuzz passes TARGET_NAME instead of relying on a unique TargetInfo.
> 
> and patch is attached to replace this commit and next commit
>

For now, I'll focus the efforts on the filtering mechanism for this
series. Once we agree, we can debate the details of single-binary itself.

> 
> 
> On Sat, Aug 29, 2026 at 7:04 AM Pierrick Bouvier
> <pierrick.bouvier@oss.qualcomm.com
> <mailto:pierrick.bouvier@oss.qualcomm.com>> wrote:
>>
>> This commit adds a new option -target, which can be allowed to set
>> current target, or retrieve list of targets available with 'help'.
>>
>> This option is the first we need to handle, as all the rest of
>> initialization depends on it.
>>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com
> <mailto:pierrick.bouvier@oss.qualcomm.com>>
>> ---
>>  include/qemu/target-info-qom.h |  1 +
>>  qemu-options.hx                |  8 ++++++++
>>  system/vl.c                    | 34 +++++++++++++++++++++++++++++++++-
>>  target-info-qom.c              | 33 ++++++++++++++++++++++++++++++++-
>>  4 files changed, 74 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-
> info-qom.h
>> index 91be415ed33..87f3a51ccd4 100644
>> --- a/include/qemu/target-info-qom.h
>> +++ b/include/qemu/target-info-qom.h
>> @@ -26,5 +26,6 @@ typedef struct TargetInfoQomClass {
>>  OBJECT_DECLARE_TYPE(TargetInfoQom, TargetInfoQomClass, TARGET_INFO)
>>
>>  void target_info_qom_set_target(void);
>> +void target_info_qom_set_target_from_name(const char *name);
>>
>>  #endif /* QEMU_TARGET_INFO_QOM_H */
>> diff --git a/qemu-options.hx b/qemu-options.hx
>> index 562c4c2b035..68d0c1d42da 100644
>> --- a/qemu-options.hx
>> +++ b/qemu-options.hx
>> @@ -24,6 +24,14 @@ SRST
>>      Display version information and exit
>>  ERST
>>
>> +DEF("target", HAS_ARG, QEMU_OPTION_target, \
>> +    "-target target  selects the target architecture ('-target help'
> for list)\n",
>> +    QEMU_ARCH_ALL)
>> +SRST
>> +``-target target``
>> +    Selects target architecture ('-target help' for list)
>> +ERST
>> +
>>  DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
>>      "-machine [type=]name[,prop=value[,...]]\n"
>>      "                selects emulated machine ('-machine help' for
> list)\n"
>> diff --git a/system/vl.c b/system/vl.c
>> index f7f8aabd122..60c5ce85580 100644
>> --- a/system/vl.c
>> +++ b/system/vl.c
>> @@ -281,6 +281,15 @@ static QemuOptsList qemu_accel_opts = {
>>      },
>>  };
>>
>> +static QemuOptsList qemu_target_opts = {
>> +    .name = "target",
>> +    .implied_opt_name = "target",
>> +    .head = QTAILQ_HEAD_INITIALIZER(qemu_target_opts.head),
>> +    .desc = {
>> +        { /* end of list */ },
>> +    },
>> +};
>> +
>>  static QemuOptsList qemu_boot_opts = {
>>      .name = "boot-opts",
>>      .implied_opt_name = "order",
>> @@ -2891,6 +2900,7 @@ void qemu_init(int argc, char **argv)
>>      qemu_add_opts(&qemu_semihosting_config_opts);
>>      qemu_add_opts(&qemu_fw_cfg_opts);
>>      qemu_add_opts(&qemu_action_opts);
>> +    qemu_add_opts(&qemu_target_opts);
>>      qemu_add_run_with_opts();
>>      module_call_init(MODULE_INIT_OPTS);
>>
>> @@ -2900,7 +2910,26 @@ void qemu_init(int argc, char **argv)
>>      os_setup_limits();
>>
>>      module_call_init(MODULE_INIT_TARGET_INFO);
>> -    target_info_qom_set_target();
>> +
>> +    /*
>> +     * Identify target: first from option, then from argv[0].
>> +     * This happens even before handling --help option, because it
> may contain
>> +     * entries that are target specific.
>> +     */
>> +    for (int idx = 1; idx < argc;) {
>> +        if (argv[idx][0] != '-') {
>> +            idx++;
>> +        } else {
>> +            const QEMUOption *popt = lookup_opt(argc, argv, &optarg,
> &idx);
>> +            if (popt->index == QEMU_OPTION_target) {
>> +                target_info_qom_set_target_from_name(optarg);
>> +                break;
>> +            }
>> +        }
>> +    }
>> +    if (!target_info()) {
>> +        target_info_qom_set_target();
>> +    }
>>
>>      module_init_info(qemu_modinfo);
>>      module_allow_arch(target_name());
>> @@ -2948,6 +2977,9 @@ void qemu_init(int argc, char **argv)
>>                  exit(1);
>>              }
>>              switch(popt->index) {
>> +            case QEMU_OPTION_target:
>> +                /* handled previously, ignore it here */
>> +                break;
>>              case QEMU_OPTION_cpu:
>>                  /* hw initialization will check this */
>>                  cpu_option = optarg;
>> diff --git a/target-info-qom.c b/target-info-qom.c
>> index 6965e4d1169..a2f506c15ef 100644
>> --- a/target-info-qom.c
>> +++ b/target-info-qom.c
>> @@ -9,6 +9,7 @@
>>  #include "qemu/osdep.h"
>>  #include "qapi/error.h"
>>  #include "qom/object.h"
>> +#include "qemu/error-report.h"
>>  #include "qemu/target-info-impl.h"
>>  #include "qemu/target-info-init.h"
>>  #include "qemu/target-info-qom.h"
>> @@ -50,6 +51,36 @@ void target_info_qom_set_target(void)
>>                                   "no target-info is available" :
>>                                   "more than one target-info is
> available");
>>      }
>> -
>>      target_info_ptr = TARGET_INFO_CLASS(targets->data)->target_info;
>>  }
>> +
>> +static void list_targets_available(void)
>> +{
>> +    printf("List of targets available:\n");
>> +    g_autoptr(GSList) targets =
> object_class_get_list_sorted(TYPE_TARGET_INFO, false);
>> +    for (GSList *elem = targets; elem; elem = elem->next) {
>> +        const TargetInfo *ti = TARGET_INFO_CLASS(elem->data)-
>>target_info;
>> +        printf("- %s\n", ti->target_name);
>> +    }
>> +}
>> +
>> +void target_info_qom_set_target_from_name(const char *name)
>> +{
>> +    if (!strcmp(name, "help")) {
>> +        list_targets_available();
>> +        exit(0);
>> +    }
>> +
>> +    g_autoptr(GSList) targets =
> object_class_get_list(TYPE_TARGET_INFO, false);
>> +    for (GSList *elem = targets; elem; elem = elem->next) {
>> +        const TargetInfo *ti = TARGET_INFO_CLASS(elem->data)-
>>target_info;
>> +        if (!strcmp(name, ti->target_name)) {
>> +            target_info_ptr = ti;
>> +            return;
>> +        }
>> +    }
>> +
>> +    error_report("target '%s' is not available", name);
>> +    list_targets_available();
>> +    exit(1);
>> +}
>> --
>> 2.43.0
>>
>>
> 
> 
> --
>          此致
> 礼
> 罗勇刚
> Yours
>     sincerely,
> Yonggang Luo



  reply	other threads:[~2026-08-31 18:10 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 22:58 [PATCH 00/47] single-binary: implement dynamic filtering for QOM types Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 01/47] target/arm: Move -cpu max stuff out of cpu32.c Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 02/47] target/arm: Build cpu32.c once in system mode Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 03/47] target/arm: Rename and adjust aarch32_max_v8_tcg_initfn Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 04/47] target/arm: Introduce cpu types max-v8 and max-v9 Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 05/47] target/arm: Use -cpu max-v8 with aarch64=off Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 06/47] target/arm: Separate cpu types max-v8 and max-v9 Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 07/47] hw/remote/machine: remove unsupported arm target Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 09/47] qom/object: add is_available callback to TypeInfo Pierrick Bouvier
2026-08-31  6:37   ` Philippe Mathieu-Daudé
2026-08-28 22:58 ` [PATCH 10/47] hw/arm: filter minimal set of machines Pierrick Bouvier
2026-08-31  6:38   ` Philippe Mathieu-Daudé
2026-08-28 22:58 ` [PATCH 11/47] system: query machines using TYPE_MACHINE Pierrick Bouvier
2026-08-31  6:40   ` Philippe Mathieu-Daudé
2026-08-28 22:58 ` [PATCH 12/47] target-info: remove machine_typename Pierrick Bouvier
2026-08-31  6:40   ` Philippe Mathieu-Daudé
2026-08-28 22:58 ` [PATCH 13/47] configs/targets: remove target info definitions Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 14/47] target-info: rename target-info-stub.c in target-info-def.c Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 15/47] hw/arm: remove TYPE_TARGET_{AARCH64,ARM}_MACHINE Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 16/47] hw/arm: remove {arm, arm_aarch64, aarch64}_machine_interfaces Pierrick Bouvier via qemu development
2026-08-28 22:58 ` [PATCH 17/47] hw/arm: remove DEFINE_MACHINE_{AARCH64,ARM} Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 18/47] hw/arm: remove machines-qom.h Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 19/47] hw/riscv: remove TYPE_TARGET_{RISCV32,RISCV64}_MACHINE Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 20/47] hw/riscv: remove {riscv32, riscv32_64, riscv64}_machine_interfaces Pierrick Bouvier via qemu development
2026-08-28 22:58 ` [PATCH 21/47] hw/riscv: remove DEFINE_MACHINE_{RISCV32,RISCV64} Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 22/47] hw/riscv: remove machines-qom.h Pierrick Bouvier
2026-08-31 12:36   ` Yonggang Luo
2026-08-31 17:58     ` Pierrick Bouvier
2026-08-31 18:28       ` Yonggang Luo
2026-08-28 22:58 ` [PATCH 23/47] target-info: add target_config_multiprocess Pierrick Bouvier
2026-08-31 14:48   ` Philippe Mathieu-Daudé
2026-08-31 14:57     ` Yonggang Luo
2026-08-31 18:00     ` Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 24/47] hw/remote/machine: filter from CONFIG_MULTIPROCESS Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 25/47] target-info: add target_config_nitro Pierrick Bouvier
2026-08-31  7:15   ` Philippe Mathieu-Daudé
2026-08-31 14:33     ` Philippe Mathieu-Daudé
2026-08-31 18:05       ` Pierrick Bouvier
2026-08-31 18:03     ` Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 26/47] hw/nitro/machine: filter from CONFIG_NITRO Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 27/47] hw/arm: filter aarch64 only machines Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 28/47] target-info: add target_config_dpcd Pierrick Bouvier
2026-08-31  7:04   ` Philippe Mathieu-Daudé
2026-08-31 10:15     ` Philippe Mathieu-Daudé
2026-08-31 18:07     ` Pierrick Bouvier
2026-08-31 18:08     ` Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 29/47] hw/display/dpcd: filter from CONFIG_DPCD Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 30/47] hw/nitro: filter from CONFIG_NITRO Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 31/47] hw/remote/proxy: filter from CONFIG_MULTIPROCESS Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 32/47] target/arm: filter cpus from target Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 33/47] system/vl: add new option -target Pierrick Bouvier
2026-08-31 12:39   ` Yonggang Luo
2026-08-31 18:10     ` Pierrick Bouvier [this message]
2026-08-28 22:58 ` [PATCH 34/47] system/vl: fallback to detect target from argv[0] Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 35/47] meson: build single binary for arm+aarch64 targets Pierrick Bouvier
2026-08-31 14:50   ` Philippe Mathieu-Daudé
2026-08-31 15:21   ` Yonggang Luo
2026-08-31 18:12     ` Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 36/47] scripts: add single-binary-compare-cmdline.sh Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 37/47] hw/core/boards.h: add available callback to DEFINE_MACHINE_EXTENDED Pierrick Bouvier
2026-08-31 12:43   ` Yonggang Luo
2026-08-31 18:13     ` Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 38/47] hw/core/boards.h: remove unused DEFINE_MACHINE_WITH_INTERFACE* Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 39/47] hw/core/boards.h: add available callback to DEFINE_MACHINE Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 40/47] hw/arm: filter arm machines Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 41/47] target-info: add target_microblaze Pierrick Bouvier
2026-08-31  7:16   ` Philippe Mathieu-Daudé
2026-08-31 15:01     ` Philippe Mathieu-Daudé
2026-08-28 22:58 ` [PATCH 42/47] hw/microblaze: filter microblaze machines Pierrick Bouvier
2026-08-31  7:17   ` Philippe Mathieu-Daudé
2026-08-28 22:58 ` [PATCH 43/47] target/microblaze/cpu: filter microblaze cpu Pierrick Bouvier
2026-08-31  7:17   ` Philippe Mathieu-Daudé
2026-08-28 22:58 ` [PATCH 44/47] hw: filter arm devices Pierrick Bouvier
2026-08-28 22:58 ` [PATCH 45/47] target-info: add target_config_cxl Pierrick Bouvier
2026-08-28 22:59 ` [PATCH 46/47] hw/pci-bridge: filter from CONFIG_CXL Pierrick Bouvier
2026-08-28 22:59 ` [PATCH 47/47] meson: add microblaze to single-binary Pierrick Bouvier
2026-08-28 23:13 ` [PATCH 00/47] single-binary: implement dynamic filtering for QOM types Pierrick Bouvier
2026-08-28 23:17   ` Pierrick Bouvier
2026-09-04  8:19   ` Daniel P. Berrangé
2026-09-04  8:58     ` Yonggang Luo
2026-09-04  9:13       ` Peter Maydell
2026-09-04  9:34         ` Yonggang Luo
2026-09-04  9:41           ` Peter Maydell
2026-09-04 13:02             ` Philippe Mathieu-Daudé
2026-09-04  9:55         ` Daniel P. Berrangé
2026-09-04 10:04           ` Yonggang Luo
2026-09-04 10:11             ` Daniel P. Berrangé
2026-09-04 13:08               ` Philippe Mathieu-Daudé
2026-09-04 10:23           ` Peter Maydell
2026-09-04 10:33             ` Daniel P. Berrangé
2026-09-04 11:19           ` Markus Armbruster
2026-09-04 11:27             ` Daniel P. Berrangé
2026-09-04 11:55               ` Markus Armbruster
2026-09-04 13:05                 ` Philippe Mathieu-Daudé
2026-09-04 11:01         ` Markus Armbruster
2026-09-04 11:06           ` Daniel P. Berrangé
2026-09-04  9:45       ` Daniel P. Berrangé
2026-09-04 11:25         ` Markus Armbruster
2026-09-04 11:36           ` Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=144ee2dd-371d-4508-9cdb-be6e9c52e657@oss.qualcomm.com \
    --to=pierrick.bouvier@oss.qualcomm.com \
    --cc=anjo@rev.ng \
    --cc=berrange@redhat.com \
    --cc=daniel.barboza@oss.qualcomm.com \
    --cc=luoyonggang@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.