From: Claudio Fontana <cfontana@suse.de>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Claudio Fontana" <cfontana@centriq4.arch.suse.de>,
"Richard Henderson" <richard.henderson@linaro.org>,
qemu-devel@nongnu.org, "Roman Bolshakov" <r.bolshakov@yadro.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>
Subject: Re: [RFC v1 34/38] target/arm: cpu: only initialize TCG gt timers under CONFIG_TCG
Date: Tue, 23 Feb 2021 13:38:54 +0100 [thread overview]
Message-ID: <2b3556b7-8f10-5c59-d098-7d1ca0598e8b@suse.de> (raw)
In-Reply-To: <b93a69bd-e8db-bf4a-2357-be51151c2c13@suse.de>
On 2/23/21 12:36 PM, Claudio Fontana wrote:
> On 2/23/21 12:01 PM, Alex Bennée wrote:
>>
>> Claudio Fontana <cfontana@suse.de> writes:
>>
>>> On 2/22/21 4:34 PM, Alex Bennée wrote:
>>>>
>>>> Claudio Fontana <cfontana@suse.de> writes:
>>>>
>>>>> From: Claudio Fontana <cfontana@centriq4.arch.suse.de>
>>>>>
>>>>> KVM has its own cpu->kvm_vtime.
>>>>>
>>>>> Adjust cpu vmstate by putting unused fields instead of the
>>>>> VMSTATE_TIMER_PTR when TCG is not available.
>>>>>
>>>>> Signed-off-by: Claudio Fontana <cfontana@suse.de>
>>>>> ---
>>>>> target/arm/cpu.c | 4 +++-
>>>>> target/arm/machine.c | 5 +++++
>>>>> 2 files changed, 8 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/target/arm/cpu.c b/target/arm/cpu.c
>>>>> index 1d81a1e7ac..b929109054 100644
>>>>> --- a/target/arm/cpu.c
>>>>> +++ b/target/arm/cpu.c
>>>>> @@ -1322,6 +1322,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
>>>>> }
>>>>> }
>>>>>
>>>>> +#ifdef CONFIG_TCG
>>>>> {
>>>>> uint64_t scale;
>>>>>
>>>>> @@ -1347,7 +1348,8 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
>>>>> cpu->gt_timer[GTIMER_HYPVIRT] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
>>>>> arm_gt_hvtimer_cb, cpu);
>>>>> }
>>>>> -#endif
>>>>> +#endif /* CONFIG_TCG */
>>>>> +#endif /* !CONFIG_USER_ONLY */
>>>>>
>>>>> cpu_exec_realizefn(cs, &local_err);
>>>>> if (local_err != NULL) {
>>>>> diff --git a/target/arm/machine.c b/target/arm/machine.c
>>>>> index 666ef329ef..13d7c6d930 100644
>>>>> --- a/target/arm/machine.c
>>>>> +++ b/target/arm/machine.c
>>>>> @@ -822,8 +822,13 @@ const VMStateDescription vmstate_arm_cpu = {
>>>>> VMSTATE_UINT32(env.exception.syndrome, ARMCPU),
>>>>> VMSTATE_UINT32(env.exception.fsr, ARMCPU),
>>>>> VMSTATE_UINT64(env.exception.vaddress, ARMCPU),
>>>>> +#ifdef CONFIG_TCG
>>>>> VMSTATE_TIMER_PTR(gt_timer[GTIMER_PHYS], ARMCPU),
>>>>> VMSTATE_TIMER_PTR(gt_timer[GTIMER_VIRT], ARMCPU),
>>>>> +#else
>>>>> + VMSTATE_UNUSED(sizeof(QEMUTimer *)),
>>>>> + VMSTATE_UNUSED(sizeof(QEMUTimer *)),
>>>>> +#endif /* CONFIG_TCG */
>>>>
>>>> I'm not sure this is correct - VMSTATE_TIMER_PTR chases the links to
>>>> just expose expired time but QEMUTimer has more in it than that. Paolo
>>>
>>>
>>> I am not sure I follow can you state more precisely where the issue could be?
>>>
>>> it's not a VMSTATE_TIMER, it's a VMSTATE_TIMER_PTR,
>>> it ends up in VMSTATE_POINTER where a single pointer is assigned;
>>
>> Does it? I thought it ended up with the .expire_time (int64_t) which
>> will be bigger than sizeof(QemuTimer *) on a 32 bit system.
>
> Ok I understand what you mean. Lets see:
>
> Looking at vmstate.h,
>
> #define VMSTATE_TIMER_PTR(_f, _s) \
> VMSTATE_TIMER_PTR_V(_f, _s, 0)
>
> #define VMSTATE_TIMER_PTR_V(_f, _s, _v) \
> VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
>
> #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
> .name = (stringify(_field)), \
> .version_id = (_version), \
> .info = &(_info), \
> .size = sizeof(_type), \
> .flags = VMS_SINGLE|VMS_POINTER, \
> .offset = vmstate_offset_value(_state, _field, _type), \
> }
>
> so here we get the vmstate field definition.
>
> .size is fine, as it is sizeof(QEMUTimer *).
>
> .info, is &vmstate_info_timer, migration/savevm.c:
>
> const VMStateInfo vmstate_info_timer = {
> .name = "timer",
> .get = get_timer,
> .put = put_timer,
> };
>
> void timer_put(QEMUFile *f, QEMUTimer *ts)
> {
> uint64_t expire_time;
>
> expire_time = timer_expire_time_ns(ts);
> qemu_put_be64(f, expire_time);
> }
>
> void timer_get(QEMUFile *f, QEMUTimer *ts)
> {
> uint64_t expire_time;
>
> expire_time = qemu_get_be64(f);
> if (expire_time != -1) {
> timer_mod_ns(ts, expire_time);
> } else {
> timer_del(ts);
> }
> }
>
> ---
>
> And the migration code does: (migration/vmstate.c):
>
> int vmstate_save_state_v() {
> ...
> ret = field->info->put(f, curr_elem, size, field, vmdesc_loop);
> ...
> }
>
> which puts a BE64 in the QEMUFile *f (see timer_put above).
>
> The load code in the same file does:
>
> int vmstate_load_state() {
> ...
> ret = field->info->get(f, curr_elem, size, field);
> ...
> }
>
> which reads a BE64 from the QEMUFile *f (see timer_get above).
>
> Would be "fine" from the field sizes perspective (the .size of the field type, and the value of the BE64),
>
> but it's the calculations done in timer_get and timer_put which are scary, as they dereference the timer pointer.
>
>
> Should we actually have a check for null pointer in vmstate.c?
>
> We _do_ have one in vmstate_save_state_v and vmstate_load_state, but it is actually active only for VMS_ARRAY_OF_POINTER.
> Why? Why not also do the same (write the null pointer and not following it) for normal VMS_POINTER ?
>
> int vmstate_save_state_v() {
> ...
> if (!curr_elem && size) {
> /* if null pointer write placeholder and do not follow */
> assert(field->flags & VMS_ARRAY_OF_POINTER);
> ret = vmstate_info_nullptr.put(f, curr_elem, size, NULL,
> NULL);
>
> ...
>
>
> int vmstate_load_state() {
>
> ...
> if (!curr_elem && size) {
> /* if null pointer check placeholder and do not follow */
> assert(field->flags & VMS_ARRAY_OF_POINTER);
> ret = vmstate_info_nullptr.get(f, curr_elem, size, NULL);
> ...
>
> }
>
>
> This is worthwhile investigating further, any other ideas?
>
> Thanks,
>
> Claudio
>
>
Btw here it would be good to be able to rely on the existing tests,
do we have full coverage of these compatibility situations?
According to make check it's all a-ok, but... is the testing coverage insufficient
for these VMSTATE compatibility issues?
Ciao,
Claudio
>>
>>>
>>> so if we don't use gt_timer at all (as is the case with !CONFIG_TCG), we just
>>> need to ensure that an unused number is there to assign, migrating from old to new version?
>>>
>>>
>>>> suggested a straight VMSTATE_UNUSED(8) on IRC but I wonder if it would
>>>> be better to have a VMSTATE_UNUSED_TIMER?
>>>>
>>>> I don't think there is an impact for Xen because I'm fairly certain
>>>> migration isn't a thing we do - but I'll double check.
>>>>
>>>
>>> Thanks Alex, that would be helpful,
>>> if Xen uses gt_timer in any way I would not want to unwillingly break
>>> it.
>>
>> Not for ARM no, currently there is no ARM specific machine emulated by
>> QEMU for Xen. All ARM guests are PV guests.
>>
>>>
>>> Thanks,
>>>
>>> Claudio
>>
>>
>
next prev parent reply other threads:[~2021-02-23 12:40 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210221092449.7545-1-cfontana@suse.de>
[not found] ` <20210221092449.7545-33-cfontana@suse.de>
2021-02-21 9:53 ` [RFC v1 32/38] target/arm: cpu: do not initialize TCG PMU for KVM Philippe Mathieu-Daudé
2021-02-21 13:59 ` Claudio Fontana
2021-02-22 6:11 ` Richard Henderson
[not found] ` <20210221092449.7545-35-cfontana@suse.de>
2021-02-21 9:55 ` [RFC v1 34/38] target/arm: cpu: only initialize TCG gt timers under CONFIG_TCG Philippe Mathieu-Daudé
2021-02-21 13:59 ` Claudio Fontana
2021-02-22 8:35 ` Claudio Fontana
2021-03-01 18:19 ` Olaf Hering
[not found] ` <87v9ak5cz0.fsf@linaro.org>
2021-02-23 9:12 ` Claudio Fontana
2021-02-23 11:01 ` Alex Bennée
2021-02-23 11:36 ` Claudio Fontana
2021-02-23 12:38 ` Claudio Fontana [this message]
2021-02-23 14:47 ` Paolo Bonzini
2021-02-22 5:35 ` [RFC v1 00/38] arm cleanup experiment for kvm-only build Richard Henderson
2021-02-22 8:43 ` Claudio Fontana
2021-02-22 11:56 ` Philippe Mathieu-Daudé
2021-02-22 16:08 ` Richard Henderson
2021-02-22 16:57 ` Alex Bennée
2021-02-23 9:17 ` Claudio Fontana
[not found] ` <20210221092449.7545-21-cfontana@suse.de>
2021-02-22 5:48 ` [RFC v1 20/38] target/arm: move arm_hcr_el2_eff to common_cpu Richard Henderson
[not found] ` <20210221092449.7545-24-cfontana@suse.de>
2021-02-22 5:52 ` [RFC v1 23/38] target/arm: move arm_mmu_idx_el to common-cpu Richard Henderson
[not found] ` <20210221092449.7545-25-cfontana@suse.de>
2021-02-22 6:02 ` [RFC v1 24/38] target/arm: move aa64_va_parameter_tbi,tbid,tcma and arm_rebuild_hflags Richard Henderson
2021-02-23 10:07 ` Claudio Fontana
2021-02-23 16:30 ` Richard Henderson
[not found] ` <20210221092449.7545-26-cfontana@suse.de>
2021-02-22 6:04 ` [RFC v1 25/38] target/arm: move fp_exception_el outside of tcg helpers Richard Henderson
[not found] ` <20210221092449.7545-27-cfontana@suse.de>
2021-02-22 6:05 ` [RFC v1 26/38] target/arm: move sve_exception_el to cpu Richard Henderson
[not found] ` <20210221092449.7545-28-cfontana@suse.de>
2021-02-22 6:06 ` [RFC v1 27/38] target/arm: move sve_zcr_len_for_el to common_cpu Richard Henderson
2021-02-25 17:28 ` Claudio Fontana
2021-02-25 20:13 ` Claudio Fontana
2021-02-26 4:01 ` Richard Henderson
[not found] ` <20210221092449.7545-29-cfontana@suse.de>
2021-02-22 6:09 ` [RFC v1 28/38] target/arm: make arm_pmu_timer_cb TCG-only, starting tcg-stub Richard Henderson
[not found] ` <20210221092449.7545-2-cfontana@suse.de>
2021-02-22 6:14 ` [RFC v1 01/38] target/arm: move translate modules to tcg/ Richard Henderson
[not found] ` <20210221092449.7545-3-cfontana@suse.de>
2021-02-22 6:16 ` [RFC v1 02/38] target/arm: move helpers " Richard Henderson
2021-02-22 17:20 ` Philippe Mathieu-Daudé
[not found] ` <20210221092449.7545-4-cfontana@suse.de>
2021-02-22 6:16 ` [RFC v1 03/38] arm: tcg: only build under CONFIG_TCG Richard Henderson
[not found] ` <20210221092449.7545-6-cfontana@suse.de>
2021-02-22 6:21 ` [RFC v1 05/38] target/arm: wrap arm_cpu_exec_interrupt in CONFIG_TCG Richard Henderson
2021-02-22 8:31 ` Claudio Fontana
2021-02-22 15:54 ` Richard Henderson
2021-02-23 8:46 ` Claudio Fontana
[not found] ` <20210221092449.7545-9-cfontana@suse.de>
2021-02-22 6:29 ` [RFC v1 08/38] target/arm/tcg: split softmmu parts of v8_cp_reginfo and el2_cp_reginfo Richard Henderson
[not found] ` <20210221092449.7545-5-cfontana@suse.de>
[not found] ` <87eeh857xf.fsf@linaro.org>
2021-02-23 8:44 ` [RFC v1 04/38] target/arm: move psci.c into tcg/softmmu/ Claudio Fontana
[not found] ` <20210221092449.7545-7-cfontana@suse.de>
[not found] ` <87blcc57rj.fsf@linaro.org>
2021-02-23 8:55 ` [RFC v1 06/38] target/arm: split off cpu-softmmu.c Claudio Fontana
2021-02-23 9:16 ` Philippe Mathieu-Daudé
2021-02-23 9:35 ` Claudio Fontana
2021-02-23 18:18 ` softmmu vs sysemu [Was: Re: [RFC v1 06/38] target/arm: split off cpu-softmmu.c] Claudio Fontana
2021-02-23 18:51 ` Richard Henderson
2021-02-23 23:43 ` Philippe Mathieu-Daudé
2021-02-24 0:06 ` Richard Henderson
2021-02-24 9:20 ` Paolo Bonzini
2021-02-24 9:30 ` Claudio Fontana
2021-02-24 10:00 ` Paolo Bonzini
[not found] ` <875z2k53mn.fsf@linaro.org>
2021-02-23 9:18 ` [RFC v1 00/38] arm cleanup experiment for kvm-only build Philippe Mathieu-Daudé
2021-03-01 11:52 ` Claudio Fontana
2021-03-01 16:23 ` Alex Bennée
2021-03-03 17:57 ` Claudio Fontana
2021-03-03 18:09 ` Peter Maydell
2021-03-03 18:17 ` Claudio Fontana
2021-03-03 18:20 ` Claudio Fontana
2021-03-03 18:30 ` Philippe Mathieu-Daudé
2021-03-03 18:39 ` Richard Henderson
2021-03-03 18:45 ` Claudio Fontana
2021-03-03 18:54 ` Richard Henderson
2021-03-04 16:39 ` Philippe Mathieu-Daudé
2021-03-04 17:19 ` Claudio Fontana
2021-03-04 17:47 ` Philippe Mathieu-Daudé
2021-03-04 19:24 ` Peter Maydell
2021-03-05 9:04 ` Claudio Fontana
2021-03-03 18:34 ` Philippe Mathieu-Daudé
2021-03-03 18:38 ` Claudio Fontana
2021-02-23 9:18 ` Claudio Fontana
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=2b3556b7-8f10-5c59-d098-7d1ca0598e8b@suse.de \
--to=cfontana@suse.de \
--cc=alex.bennee@linaro.org \
--cc=cfontana@centriq4.arch.suse.de \
--cc=ehabkost@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=r.bolshakov@yadro.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).