public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: Markus Armbruster <armbru@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
	qemu-devel@nongnu.org,
	"Daniel Henrique Barboza" <dbarboza@ventanamicro.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	"Artyom Tarasenko" <atar4qemu@gmail.com>,
	"Dr. David Alan Gilbert" <dave@treblig.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Zhao Liu" <zhao1.liu@intel.com>
Subject: Re: [PATCH-for-11.1 v6 3/6] monitor: Have MonitorDef::get_value() always return int64_t type
Date: Tue, 24 Mar 2026 11:34:38 -0700	[thread overview]
Message-ID: <c0f35257-98ae-4cb8-a73e-2e36bac91a55@linaro.org> (raw)
In-Reply-To: <87tsu5qofj.fsf@pond.sub.org>

On 3/24/26 7:42 AM, Markus Armbruster wrote:
> Peter Maydell <peter.maydell@linaro.org> writes:
> 
>> On Tue, 24 Mar 2026 at 12:57, Markus Armbruster <armbru@redhat.com> wrote:
>>>
>>> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
>>>
>>>> Simplify MonitorDef::get_value() handler by having it always
>>>> return a int64_t type. Truncate to 32-bit in the single caller.
>>>>
>>>> Note, this handler is only implemented once for the x86 targets.
>>
>>>> @@ -78,7 +80,8 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
>>>>       for(; md->name != NULL; md++) {
>>>>           if (hmp_compare_cmd(name, md->name)) {
>>>>               if (md->get_value) {
>>>> -                *pval = md->get_value(mon, md, md->offset);
>>>> +                int64_t val = md->get_value(mon, md, md->offset);
>>>> +                *pval = target_long_bits() == 32 ? (int32_t)val : val;
>>>
>>> This assumes target_long_bits() returns either 32 or 64, doesn't it?
>>>
>>> Is this true today?
>>
>> It's certainly true today, and we insist on that: exec/target_long.h
>> handles TARGET_LONG_SIZE being 4 or 8 and will #error on anything else.
> 
> Good.
> 
>> What other values do you expect it could have ?
> 
> There might be a need for 128 in the future.  Not an easy change to
> make.
>

The day this will happen, there will be more places to fix than the 
current patch, as it's assumed everywhere else that target_long_bits or 
TARGET_LONG_BITS is 32 or 64 only. So I would not worry too much about 
it at the moment.

>>> Will it remain true?
>>>
>>> Could we use something like
>>>
>>>      val & ((1 << target_long_bits()) - 1)
>>>
>>> to truncate to target_long_bits() bits?
>>
>> This is UB for the case where target_long_bits returns 64,
>> and isn't what the code currently does because it zero
>> extends rather than sign extending.
> 
> I signalled my cavalier neglect for these details by writing "something
> like" ;)
> 
>> If we wanted to programmatically sign extend from
>> target_long_bits() to the int64_t, that would be
>>
>>   *pval = sextract64(val, 0, target_long_bits());
>>
>> (Whether sign extension is what we actually want for your
>> average register is questionable, but it's what the code
>> does now both for the get_value functions and also for the
>> generic cases handled by the switch on md->type.)
>>
>> Incidentally, we currently behave differently here for
>> qemu-system-i386 and qemu-system-x86_64:
>>
>> $ ./build/all/qemu-system-x86_64 -S -monitor stdio -display none
>> QEMU 10.2.50 monitor - type 'help' for more information
>> (qemu) print $pc
>> 0xfffffff0
>> (qemu) q
>> $ ./build/all/qemu-system-i386 -S -monitor stdio -display none
>> QEMU 10.2.50 monitor - type 'help' for more information
>> (qemu) print $pc
>> 0xfffffffffffffff0
>>
>> For qemu-system-x86_64 we have a 64-bit target_long, so
>> the unsigned addition of env->eip and env->segs[R_CS].base
>> in monitor_get_pc() is done at 64 bits, and that width is
>> then carried through get_monitor_def() and to the caller.
>> For qemu-system-i386 we have a 32-bit target_long, so
>> we do an unsigned 32-bit addition in monitor_get_pc(),
>> return a signed 32-bit result, and then sign extend that
>> to 64 bits in get_monitor_def().
> 
> I'm carefully retracing my steps out of this swamp.
> 
> Thanks!
> 



  reply	other threads:[~2026-03-24 18:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20  9:10 [PATCH-for-11.1 v6 0/6] monitor/hmp: Reduce target-specific definitions Philippe Mathieu-Daudé
2026-03-20  9:10 ` [PATCH-for-11.1 v6 1/6] target/sparc/monitor: Dump all registers as 32-bit Philippe Mathieu-Daudé
2026-03-20 21:44   ` Pierrick Bouvier
2026-03-24 12:49   ` Markus Armbruster
2026-03-20  9:10 ` [PATCH-for-11.1 v6 2/6] monitor: Remove MonitorDef::type field and MD_TLONG / MD_I32 Philippe Mathieu-Daudé
2026-03-20 21:44   ` Pierrick Bouvier
2026-03-20  9:10 ` [PATCH-for-11.1 v6 3/6] monitor: Have MonitorDef::get_value() always return int64_t type Philippe Mathieu-Daudé
2026-03-20 21:45   ` Pierrick Bouvier
2026-03-24 12:56   ` Markus Armbruster
2026-03-24 13:24     ` Peter Maydell
2026-03-24 14:42       ` Markus Armbruster
2026-03-24 18:34         ` Pierrick Bouvier [this message]
2026-03-25  5:51           ` Markus Armbruster
2026-03-25 17:37             ` Pierrick Bouvier
2026-03-20  9:10 ` [PATCH-for-11.1 v6 4/6] monitor: Remove last target_long use in get_monitor_def() Philippe Mathieu-Daudé
2026-03-20 21:45   ` Pierrick Bouvier
2026-03-20 21:51   ` Pierrick Bouvier
2026-03-20  9:10 ` [PATCH-for-11.1 v6 5/6] monitor: Reduce target-specific methods further Philippe Mathieu-Daudé
2026-03-20 21:52   ` Pierrick Bouvier
2026-03-20  9:10 ` [PATCH-for-11.1 v6 6/6] monitor: Remove 'monitor/hmp-target.h' header Philippe Mathieu-Daudé
2026-03-20 21:52   ` Pierrick Bouvier

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=c0f35257-98ae-4cb8-a73e-2e36bac91a55@linaro.org \
    --to=pierrick.bouvier@linaro.org \
    --cc=armbru@redhat.com \
    --cc=atar4qemu@gmail.com \
    --cc=dave@treblig.org \
    --cc=dbarboza@ventanamicro.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --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