From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>, qemu-devel@nongnu.org
Cc: "Dr . David Alan Gilbert" <dave@treblig.org>,
Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>,
Alistair Francis <alistair.francis@wdc.com>,
Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
Artyom Tarasenko <atar4qemu@gmail.com>,
Zhao Liu <zhao1.liu@intel.com>,
Paolo Bonzini <pbonzini@redhat.com>,
qemu-riscv@nongnu.org, Anton Johansson <anjo@rev.ng>,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
Yanan Wang <wangyanan55@huawei.com>
Subject: Re: [PATCH-for-11.1 03/10] cpus: Introduce CPUClass::legacy_monitor_defs hook
Date: Mon, 23 Mar 2026 13:00:12 -0700 [thread overview]
Message-ID: <9f6d106a-878f-4fdf-ba30-1af86a2a0500@linaro.org> (raw)
In-Reply-To: <7c724cf7-c0d8-4e8b-8c74-8a78ace9f4d2@linaro.org>
On 3/23/26 2:19 AM, Philippe Mathieu-Daudé wrote:
> On 21/3/26 20:51, Pierrick Bouvier wrote:
>> On 3/21/26 8:19 AM, Philippe Mathieu-Daudé wrote:
>>> On 20/3/26 23:01, Pierrick Bouvier wrote:
>>>> On 3/20/26 9:08 AM, Philippe Mathieu-Daudé wrote:
>>>>> Allow targets to register their legacy target_monitor_defs()
>>>>> in CPUClass; check it first in get_monitor_def() otherwise
>>>>> fall back to previous per-target helper.
>>>>>
>>>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>>>> ---
>>>>> include/hw/core/cpu.h | 3 +++
>>>>> monitor/hmp.c | 3 ++-
>>>>> 2 files changed, 5 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
>>>>> index 04e1f970caf..072f58bead5 100644
>>>>> --- a/include/hw/core/cpu.h
>>>>> +++ b/include/hw/core/cpu.h
>>>>> @@ -148,6 +148,8 @@ struct SysemuCPUOps;
>>>>> * @max_as: Maximum valid index used to refer to the address spaces
>>>>> supported by
>>>>> * the architecture, i.e., to refer to CPUAddressSpaces in
>>>>> * CPUState::cpu_ases.
>>>>> + * @legacy_monitor_defs: Array of MonitorDef entries. This field is
>>>>> legacy,
>>>>> + * use @gdb_core_xml_file to dump registers
>>>>> instead.
>>>>> *
>>>>> * Represents a CPU family or model.
>>>>> */
>>>>> @@ -174,6 +176,7 @@ struct CPUClass {
>>>>> const char *gdb_core_xml_file;
>>>>> const char * (*gdb_arch_name)(CPUState *cpu);
>>>>> const char * (*gdb_get_core_xml_file)(CPUState *cpu);
>>>>> + const MonitorDef *legacy_monitor_defs;
>>>>> void (*disas_set_info)(const CPUState *cpu, disassemble_info
>>>>> *info);
>>>>> diff --git a/monitor/hmp.c b/monitor/hmp.c
>>>>> index c63da13e310..a2b6269d0ff 100644
>>>>> --- a/monitor/hmp.c
>>>>> +++ b/monitor/hmp.c
>>>>> @@ -24,6 +24,7 @@
>>>>> #include "qemu/osdep.h"
>>>>> #include <dirent.h>
>>>>> +#include "hw/core/cpu.h"
>>>>> #include "hw/core/qdev.h"
>>>>> #include "monitor-internal.h"
>>>>> #include "monitor/hmp.h"
>>>>> @@ -1603,8 +1604,8 @@ void monitor_register_hmp_info_hrt(const char
>>>>> *name,
>>>>> */
>>>>> int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
>>>>> {
>>>>> - const MonitorDef *md = target_monitor_defs();
>>>>> CPUState *cs = mon_get_cpu(mon);
>>>>> + const MonitorDef *md = cs->cc->legacy_monitor_defs ?:
>>>>> target_monitor_defs();
>>>>> void *ptr;
>>>>> uint64_t tmp = 0;
>>>>> int ret;
>>>>
>>>> I'm not very fond of the "keep legacy callback for the N targets that
>>>> might require it". Either set it for every target, using a default
>>>> implementation if needed, or...
>>>>
>>>> As an alternative, we could use a dispatch function like:
>>>>
>>>> const MonitorDef *target_monitor_defs()
>>>> {
>>>> switch (target_arch()) {
>>>> case
>>>> SYS_EMU_TARGET_X:
>>>> return X_target_monitor_defs();
>>>> SYS_EMU_TARGET_Y:
>>>> return Y_target_monitor_defs();
>>>> default:
>>>> return default_target_monitor_defs();
>>>> }
>>>> }
>>>>
>>>> Personally, I prefer the dispatch approach, as it's very clear to see
>>>> what happens per target. This solves the symbol duplication by manually
>>>> name them differently.
>>>>
>>>> It's just a suggestion though, and I'm ok to have a per target field, as
>>>> long as we enforce it to be set for all targets, and not using a
>>>> 'legacy' callback for a few of them only.
>>>>
>>>> Pick the one you prefer :)
>>>
>>> My preference would be to remove this legacy code altogether, as
>>> I'm pretty sure it isn't used anymore (see for the example the
>>> issues RISC-V folks had with it before giving up).
>>
>> I'm not sure what you mean.
>>
>> If it's not used, then we simply remove it.
>> If it's used, then let's keep it, but just make it consistent with all
>> targets without having a special case named "legacy". If it's here to
>> stay, it's not legacy.
>>
>> Do you have something else in mind?
>
> As a software engineer I prefer to deal with code. Unfortunately in my
> experience with QEMU development, removing legacy code means endless
> bikesheeding debates. I'm not judging they are bad, just they drain my
> time and energy. I agree legacy code should be removed, but again this
> is the QEMU project here, where we have bad habbits of adding new APIs
> with the promise of removing the previous one but never finish API
> conversions, not even marking legacy one. With that in mind, I think
> mentioning "legacy" is still a good first step.
>
I agree, and it's *not* your responsibility to refactor any piece of
code you have to touch for another purpose. In this case, I was just
suggesting to make the callback consistent between all targets (i.e.
force all them to implement it) instead of having a conditional legacy
callback.
All the rest of the series (symbol renaming, etc) stays intact.
> Anyway, I suppose what you are asking is me starting a poll for each
> target array and ask "Who is still using this SPARC 'canrestore' monitor
> command?" etc., wait 2 months for replies, then if possible deprecate
> them, wait 2 more releases, and eventually remove. Then we'll be able
> to link this file in single binary. As of today I'm not motivated enough
> for that so I'm looking for alternatives. Looking at mailing list
> archives I apparently started to tackle this 9 weeks ago, long enough to
> keep working on the single binary with HMP code disable until we get
> a working proof of concept; then revisit.
I was just curious about your mention "My preference would be to remove
this legacy code altogether", but no one expects you to do it.
I think having consistent callbacks through all targets is a very
acceptable solution. The only difference with your series is to rename
"legacy*" and set a default callback for all other targets.
If it's creating too much friction, I can also hear it and accept your
current series as it is.
Regards,
Pierrick
next prev parent reply other threads:[~2026-03-23 20:01 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 16:08 [PATCH-for-11.1 00/10] monitor: Remove need of per-target handlers Philippe Mathieu-Daudé
2026-03-20 16:08 ` [PATCH-for-11.1 01/10] monitor: Extract completion declarations to 'monitor/hmp-completion.h' Philippe Mathieu-Daudé
2026-03-20 21:52 ` Pierrick Bouvier
2026-03-20 16:08 ` [PATCH-for-11.1 02/10] monitor: Forward-declare the MonitorDef type Philippe Mathieu-Daudé
2026-03-20 21:52 ` Pierrick Bouvier
2026-03-20 16:08 ` [PATCH-for-11.1 03/10] cpus: Introduce CPUClass::legacy_monitor_defs hook Philippe Mathieu-Daudé
2026-03-20 22:01 ` Pierrick Bouvier
2026-03-21 15:19 ` Philippe Mathieu-Daudé
2026-03-21 19:51 ` Pierrick Bouvier
2026-03-23 9:19 ` Philippe Mathieu-Daudé
2026-03-23 20:00 ` Pierrick Bouvier [this message]
2026-03-20 16:08 ` [PATCH-for-11.1 04/10] target/i386: Replace legacy target_monitor_defs -> legacy_monitor_defs Philippe Mathieu-Daudé
2026-03-20 16:08 ` [PATCH-for-11.1 05/10] target/m68k: " Philippe Mathieu-Daudé
2026-03-20 16:08 ` [PATCH-for-11.1 06/10] target/sparc: " Philippe Mathieu-Daudé
2026-03-20 16:08 ` [PATCH-for-11.1 07/10] monitor: Remove target_monitor_defs() Philippe Mathieu-Daudé
2026-03-20 16:08 ` [PATCH-for-11.1 08/10] cpus: Introduce CPUClass::legacy_monitor_get_register() hook Philippe Mathieu-Daudé
2026-03-20 16:08 ` [PATCH-for-11.1 09/10] target/riscv: Register target_get_monitor_def in CPUClass Philippe Mathieu-Daudé
2026-03-20 16:08 ` [PATCH-for-11.1 10/10] monitor: Remove target_get_monitor_def() Philippe Mathieu-Daudé
2026-03-23 12:03 ` [PATCH-for-11.1 00/10] monitor: Remove need of per-target handlers Daniel Henrique Barboza
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=9f6d106a-878f-4fdf-ba30-1af86a2a0500@linaro.org \
--to=pierrick.bouvier@linaro.org \
--cc=alistair.francis@wdc.com \
--cc=anjo@rev.ng \
--cc=atar4qemu@gmail.com \
--cc=daniel.barboza@oss.qualcomm.com \
--cc=dave@treblig.org \
--cc=marcel.apfelbaum@gmail.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=wangyanan55@huawei.com \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox