All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
	qemu-devel@nongnu.org,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>
Subject: Re: [PATCH] system: Convert qemu_arch_available() to TargetInfo API
Date: Fri, 09 Jan 2026 07:09:52 +0100	[thread overview]
Message-ID: <87secf5nbj.fsf@pond.sub.org> (raw)
In-Reply-To: <b51889b4-b101-4618-83dd-2d7be9a97f0c@linaro.org> (Pierrick Bouvier's message of "Thu, 8 Jan 2026 10:53:10 -0800")

Pierrick Bouvier <pierrick.bouvier@linaro.org> writes:

> On 1/8/26 8:32 AM, Philippe Mathieu-Daudé wrote:
>> On 8/1/26 01:36, Pierrick Bouvier wrote:
>>> On 1/7/26 10:10 AM, Philippe Mathieu-Daudé wrote:
>>>> Get the base arch_mask from the current SysEmuTarget,
>>>> making qemu_arch_available() target-agnostic.
>>>>
>>>> We don't need the per-target QEMU_ARCH definition anymore,
>>>> remove it.
>>>>
>>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

[...]

>>>> @@ -33,6 +34,46 @@ SysEmuTarget target_arch(void)
>>>>        return arch;
>>>>    }
>>>> +bool qemu_arch_available(unsigned qemu_arch_mask)
>>>> +{
>>>> +    static const unsigned base_arch_mask[SYS_EMU_TARGET__MAX] = {
>>>> +        [SYS_EMU_TARGET_AARCH64]        = QEMU_ARCH_ARM,
>>>> +        [SYS_EMU_TARGET_ALPHA]          = QEMU_ARCH_ALPHA,
>>>> +        [SYS_EMU_TARGET_ARM]            = QEMU_ARCH_ARM,
>>>> +        [SYS_EMU_TARGET_AVR]            = QEMU_ARCH_AVR,
>>>> +        /*
>>>> +        [SYS_EMU_TARGET_HEXAGON]        = QEMU_ARCH_HEXAGON,
>>>> +        */
>>>> +        [SYS_EMU_TARGET_HPPA]           = QEMU_ARCH_HPPA,
>>>> +        [SYS_EMU_TARGET_I386]           = QEMU_ARCH_I386,
>>>> +        [SYS_EMU_TARGET_LOONGARCH64]    = QEMU_ARCH_LOONGARCH,
>>>> +        [SYS_EMU_TARGET_M68K]           = QEMU_ARCH_M68K,
>>>> +        [SYS_EMU_TARGET_MICROBLAZE]     = QEMU_ARCH_MICROBLAZE,
>>>> +        [SYS_EMU_TARGET_MICROBLAZEEL]   = QEMU_ARCH_MICROBLAZE,
>>>> +        [SYS_EMU_TARGET_MIPS]           = QEMU_ARCH_MIPS,
>>>> +        [SYS_EMU_TARGET_MIPS64]         = QEMU_ARCH_MIPS,
>>>> +        [SYS_EMU_TARGET_MIPS64EL]       = QEMU_ARCH_MIPS,
>>>> +        [SYS_EMU_TARGET_MIPSEL]         = QEMU_ARCH_MIPS,
>>>> +        [SYS_EMU_TARGET_OR1K]           = QEMU_ARCH_OPENRISC,
>>>> +        [SYS_EMU_TARGET_PPC]            = QEMU_ARCH_PPC,
>>>> +        [SYS_EMU_TARGET_PPC64]          = QEMU_ARCH_PPC,
>>>> +        [SYS_EMU_TARGET_RISCV32]        = QEMU_ARCH_RISCV,
>>>> +        [SYS_EMU_TARGET_RISCV64]        = QEMU_ARCH_RISCV,
>>>> +        [SYS_EMU_TARGET_RX]             = QEMU_ARCH_RX,
>>>> +        [SYS_EMU_TARGET_S390X]          = QEMU_ARCH_S390X,
>>>> +        [SYS_EMU_TARGET_SH4]            = QEMU_ARCH_SH4,
>>>> +        [SYS_EMU_TARGET_SH4EB]          = QEMU_ARCH_SH4,
>>>> +        [SYS_EMU_TARGET_SPARC]          = QEMU_ARCH_SPARC,
>>>> +        [SYS_EMU_TARGET_SPARC64]        = QEMU_ARCH_SPARC,
>>>> +        [SYS_EMU_TARGET_TRICORE]        = QEMU_ARCH_TRICORE,
>>>> +        [SYS_EMU_TARGET_X86_64]         = QEMU_ARCH_I386,
>>>> +        [SYS_EMU_TARGET_XTENSA]         = QEMU_ARCH_XTENSA,
>>>> +        [SYS_EMU_TARGET_XTENSAEB]       = QEMU_ARCH_XTENSA,
>>>> +    };
>>>> +
>>>
>>> Just a remark: is that worth having the "static const" array approach
>>> when we could have a proper switch than can be checked for
>>> exhaustiveness with compiler warnings instead?
>>
>> I thought 40 LoC would be simpler to review than 80, and it was
>> simpler to generate the template in bash.

I find the array solution much easier to grasp at a glance.  The
initializer shows the mapping concisely.  With a switch, there's noise
around the mapping, and the fact that all all switch cases do nothing
but assign a constant to the same variable is not obvious at a glance.

>> Besides, we don't use compiler warnings for enum (such -Wswitch)
>> due to QAPI:
>> https://lore.kernel.org/qemu-devel/20230315112811.22355-1-philmd@linaro.org/
>> 
>
> Reading the thread above, the only mention I find is the 3rd commit that precisely change definition because -Wswitch is enabled with clang.
>
> And it's not only a clang thing, gcc has it in Wall also [1].
>
> I don't mind the array approach, but maybe just add a *static* assert making sure (SYS_EMU_TARGET__MAX-1 == SYS_EMU_TARGET_XTENSAEB) so this file will break as soon as there is a new target added. It's simple and the next developer who won't have to debug this will thank you.

Won't help when new enum values are added in the middle.  We keep them
alphabetically sorted...

We could use a simple run-time assertion:

    arch_mask = qemu_arch_mask & base_arch_mask[target_arch()];
    assert(arch_mask);
    return arch_mask;

Works because the QEMU_ARCH_FOO are all non-zero.

Pick your poison.

> [1] https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html
>
>>>
>>> Beyond that,
>>> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>

      reply	other threads:[~2026-01-09  6:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-07 18:10 [PATCH] system: Convert qemu_arch_available() to TargetInfo API Philippe Mathieu-Daudé
2026-01-08  0:36 ` Pierrick Bouvier
2026-01-08 16:32   ` Philippe Mathieu-Daudé
2026-01-08 18:53     ` Pierrick Bouvier
2026-01-09  6:09       ` Markus Armbruster [this message]

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=87secf5nbj.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

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

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