qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] cpu: flush TB cache when loading VMState
@ 2018-01-10 13:48 Pavel Dovgalyuk
  2018-01-10 13:49 ` Paolo Bonzini
  2018-01-10 17:49 ` Richard Henderson
  0 siblings, 2 replies; 8+ messages in thread
From: Pavel Dovgalyuk @ 2018-01-10 13:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: quintela, dgilbert, maria.klimushenkova, dovgaluk, pavel.dovgaluk,
	pbonzini

Flushing TB cache is required because TBs key in the cache may match
different code which existed in the previous state.

Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
Signed-off-by: Maria Klimushenkova <maria.klimushenkova@ispras.ru>
---
 exec.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/exec.c b/exec.c
index 4722e52..ff31e71 100644
--- a/exec.c
+++ b/exec.c
@@ -622,6 +622,7 @@ static int cpu_common_post_load(void *opaque, int version_id)
        version_id is increased. */
     cpu->interrupt_request &= ~0x01;
     tlb_flush(cpu);
+    tb_flush(cpu);
 
     return 0;
 }

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] cpu: flush TB cache when loading VMState
  2018-01-10 13:48 [Qemu-devel] [PATCH] cpu: flush TB cache when loading VMState Pavel Dovgalyuk
@ 2018-01-10 13:49 ` Paolo Bonzini
  2018-01-10 17:49 ` Richard Henderson
  1 sibling, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2018-01-10 13:49 UTC (permalink / raw)
  To: Pavel Dovgalyuk, qemu-devel
  Cc: quintela, dgilbert, maria.klimushenkova, dovgaluk

On 10/01/2018 14:48, Pavel Dovgalyuk wrote:
> Flushing TB cache is required because TBs key in the cache may match
> different code which existed in the previous state.
> 
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
> Signed-off-by: Maria Klimushenkova <maria.klimushenkova@ispras.ru>
> ---
>  exec.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/exec.c b/exec.c
> index 4722e52..ff31e71 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -622,6 +622,7 @@ static int cpu_common_post_load(void *opaque, int version_id)
>         version_id is increased. */
>      cpu->interrupt_request &= ~0x01;
>      tlb_flush(cpu);
> +    tb_flush(cpu);
>  
>      return 0;
>  }
> 

Queued, thanks.

Paolo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] cpu: flush TB cache when loading VMState
  2018-01-10 13:48 [Qemu-devel] [PATCH] cpu: flush TB cache when loading VMState Pavel Dovgalyuk
  2018-01-10 13:49 ` Paolo Bonzini
@ 2018-01-10 17:49 ` Richard Henderson
  2018-01-10 17:55   ` Dr. David Alan Gilbert
  2018-01-10 18:32   ` Peter Maydell
  1 sibling, 2 replies; 8+ messages in thread
From: Richard Henderson @ 2018-01-10 17:49 UTC (permalink / raw)
  To: Pavel Dovgalyuk, qemu-devel
  Cc: quintela, dgilbert, maria.klimushenkova, dovgaluk, pbonzini

On 01/10/2018 05:48 AM, Pavel Dovgalyuk wrote:
> Flushing TB cache is required because TBs key in the cache may match
> different code which existed in the previous state.
> 
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
> Signed-off-by: Maria Klimushenkova <maria.klimushenkova@ispras.ru>
> ---
>  exec.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/exec.c b/exec.c
> index 4722e52..ff31e71 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -622,6 +622,7 @@ static int cpu_common_post_load(void *opaque, int version_id)
>         version_id is increased. */
>      cpu->interrupt_request &= ~0x01;
>      tlb_flush(cpu);
> +    tb_flush(cpu);

I'm not necessarily objecting, but what do you mean by "may match different code"?

What this patch suggests is that the inputs to the computation of TB->FLAGS are
different for some unspecified reason.  Without further explanation, to me this
suggests a bug in vmstate save/restore.

What is the observed problem here?


r~

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] cpu: flush TB cache when loading VMState
  2018-01-10 17:49 ` Richard Henderson
@ 2018-01-10 17:55   ` Dr. David Alan Gilbert
  2018-01-10 18:32   ` Peter Maydell
  1 sibling, 0 replies; 8+ messages in thread
From: Dr. David Alan Gilbert @ 2018-01-10 17:55 UTC (permalink / raw)
  To: Richard Henderson
  Cc: Pavel Dovgalyuk, qemu-devel, quintela, maria.klimushenkova,
	dovgaluk, pbonzini

* Richard Henderson (richard.henderson@linaro.org) wrote:
> On 01/10/2018 05:48 AM, Pavel Dovgalyuk wrote:
> > Flushing TB cache is required because TBs key in the cache may match
> > different code which existed in the previous state.
> > 
> > Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
> > Signed-off-by: Maria Klimushenkova <maria.klimushenkova@ispras.ru>
> > ---
> >  exec.c |    1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/exec.c b/exec.c
> > index 4722e52..ff31e71 100644
> > --- a/exec.c
> > +++ b/exec.c
> > @@ -622,6 +622,7 @@ static int cpu_common_post_load(void *opaque, int version_id)
> >         version_id is increased. */
> >      cpu->interrupt_request &= ~0x01;
> >      tlb_flush(cpu);
> > +    tb_flush(cpu);
> 
> I'm not necessarily objecting, but what do you mean by "may match different code"?
> 
> What this patch suggests is that the inputs to the computation of TB->FLAGS are
> different for some unspecified reason.  Without further explanation, to me this
> suggests a bug in vmstate save/restore.
> 
> What is the observed problem here?

Is this a case where you're repeatedly running 'loadvm' to revert to a
previous snapshot (or I guess the debug stuff); so you've been running
and translating code and then reload state ?

Dave

> 
> r~
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] cpu: flush TB cache when loading VMState
  2018-01-10 17:49 ` Richard Henderson
  2018-01-10 17:55   ` Dr. David Alan Gilbert
@ 2018-01-10 18:32   ` Peter Maydell
  2018-01-11 10:15     ` Paolo Bonzini
  1 sibling, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2018-01-10 18:32 UTC (permalink / raw)
  To: Richard Henderson
  Cc: Pavel Dovgalyuk, QEMU Developers, Paolo Bonzini,
	maria.klimushenkova, Pavel Dovgalyuk, Dr. David Alan Gilbert,
	Juan Quintela

On 10 January 2018 at 17:49, Richard Henderson
<richard.henderson@linaro.org> wrote:
> On 01/10/2018 05:48 AM, Pavel Dovgalyuk wrote:
>> Flushing TB cache is required because TBs key in the cache may match
>> different code which existed in the previous state.
>>
>> Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
>> Signed-off-by: Maria Klimushenkova <maria.klimushenkova@ispras.ru>
>> ---
>>  exec.c |    1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/exec.c b/exec.c
>> index 4722e52..ff31e71 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -622,6 +622,7 @@ static int cpu_common_post_load(void *opaque, int version_id)
>>         version_id is increased. */
>>      cpu->interrupt_request &= ~0x01;
>>      tlb_flush(cpu);
>> +    tb_flush(cpu);
>
> I'm not necessarily objecting, but what do you mean by "may match different code"?
>
> What this patch suggests is that the inputs to the computation of TB->FLAGS are
> different for some unspecified reason.  Without further explanation, to me this
> suggests a bug in vmstate save/restore.

Yeah, this looks a little fishy. If there's code in the TB cache
which would be wrong for the freshly-reset (or whatever)
CPU after a VM state load, then it could just as easily
be wrong for a 2nd CPU in an SMP config.

I used to think it was OK to have the generated code bake
in some information that wasn't in tb_flags as long as you
then did a tb_flush when that information changed, but
I realized I was wrong about that (because of the SMP issue).

git grep suggests we do still have a few places in targets
that are calling tb_flush(), but I think we should try to
fix those.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] cpu: flush TB cache when loading VMState
  2018-01-10 18:32   ` Peter Maydell
@ 2018-01-11 10:15     ` Paolo Bonzini
  2018-01-11 10:20       ` Peter Maydell
  0 siblings, 1 reply; 8+ messages in thread
From: Paolo Bonzini @ 2018-01-11 10:15 UTC (permalink / raw)
  To: Peter Maydell, Richard Henderson
  Cc: Pavel Dovgalyuk, QEMU Developers, maria.klimushenkova,
	Pavel Dovgalyuk, Dr. David Alan Gilbert, Juan Quintela

On 10/01/2018 19:32, Peter Maydell wrote:
> On 10 January 2018 at 17:49, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>> On 01/10/2018 05:48 AM, Pavel Dovgalyuk wrote:
>>> Flushing TB cache is required because TBs key in the cache may match
>>> different code which existed in the previous state.
>>>
>>> Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
>>> Signed-off-by: Maria Klimushenkova <maria.klimushenkova@ispras.ru>
>>> ---
>>>  exec.c |    1 +
>>>  1 file changed, 1 insertion(+)
>>>
>>> diff --git a/exec.c b/exec.c
>>> index 4722e52..ff31e71 100644
>>> --- a/exec.c
>>> +++ b/exec.c
>>> @@ -622,6 +622,7 @@ static int cpu_common_post_load(void *opaque, int version_id)
>>>         version_id is increased. */
>>>      cpu->interrupt_request &= ~0x01;
>>>      tlb_flush(cpu);
>>> +    tb_flush(cpu);
>>
>> I'm not necessarily objecting, but what do you mean by "may match different code"?
>>
>> What this patch suggests is that the inputs to the computation of TB->FLAGS are
>> different for some unspecified reason.  Without further explanation, to me this
>> suggests a bug in vmstate save/restore.
> 
> Yeah, this looks a little fishy. If there's code in the TB cache
> which would be wrong for the freshly-reset (or whatever)
> CPU after a VM state load, then it could just as easily
> be wrong for a 2nd CPU in an SMP config.

RAM contents are memcpy'd blindly during loadvm.  I think that's what
requires a tb_flush.

Paolo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] cpu: flush TB cache when loading VMState
  2018-01-11 10:15     ` Paolo Bonzini
@ 2018-01-11 10:20       ` Peter Maydell
  2018-01-11 13:24         ` Paolo Bonzini
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2018-01-11 10:20 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Richard Henderson, Pavel Dovgalyuk, QEMU Developers,
	maria.klimushenkova, Pavel Dovgalyuk, Dr. David Alan Gilbert,
	Juan Quintela

On 11 January 2018 at 10:15, Paolo Bonzini <pbonzini@redhat.com> wrote:
> RAM contents are memcpy'd blindly during loadvm.  I think that's what
> requires a tb_flush.

Ah, that makes sense. Could we have a comment documenting the
rationale, please? Something like:

/* vmload has just updated the content of RAM, bypassing the
 * usual mechanisms that ensure we flush TBs for writes to
 * memory we've translated code from. So we must flush all TBs,
 * which will now be stale.
 */

thanks
-- PMM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] cpu: flush TB cache when loading VMState
  2018-01-11 10:20       ` Peter Maydell
@ 2018-01-11 13:24         ` Paolo Bonzini
  0 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2018-01-11 13:24 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Richard Henderson, Pavel Dovgalyuk, QEMU Developers,
	maria.klimushenkova, Pavel Dovgalyuk, Dr. David Alan Gilbert,
	Juan Quintela

On 11/01/2018 11:20, Peter Maydell wrote:
> On 11 January 2018 at 10:15, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> RAM contents are memcpy'd blindly during loadvm.  I think that's what
>> requires a tb_flush.
> 
> Ah, that makes sense. Could we have a comment documenting the
> rationale, please? Something like:
> 
> /* vmload has just updated the content of RAM, bypassing the
>  * usual mechanisms that ensure we flush TBs for writes to
>  * memory we've translated code from. So we must flush all TBs,
>  * which will now be stale.
>  */
> 
> thanks
> -- PMM
> 

Sure, will add it.

Paolo

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-01-11 13:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-10 13:48 [Qemu-devel] [PATCH] cpu: flush TB cache when loading VMState Pavel Dovgalyuk
2018-01-10 13:49 ` Paolo Bonzini
2018-01-10 17:49 ` Richard Henderson
2018-01-10 17:55   ` Dr. David Alan Gilbert
2018-01-10 18:32   ` Peter Maydell
2018-01-11 10:15     ` Paolo Bonzini
2018-01-11 10:20       ` Peter Maydell
2018-01-11 13:24         ` Paolo Bonzini

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).