diff mbox

[4/7] ppc: move sdr1 value change detection logic to helper_store_sdr1()

Message ID 1419294981-17368-5-git-send-email-mark.cave-ayland@ilande.co.uk
State New
Headers show

Commit Message

Mark Cave-Ayland Dec. 23, 2014, 12:36 a.m. UTC
Otherwise when cpu_post_load calls ppc_store_sdr1() when restoring a VM
snapshot the value is deemed unchanged and so the internal env->htab*
variables aren't set correctly.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
CC: Paolo Bonzini <pbonzini@redhat.com>
---
 target-ppc/misc_helper.c |    7 ++++++-
 target-ppc/mmu_helper.c  |   35 +++++++++++++++--------------------
 2 files changed, 21 insertions(+), 21 deletions(-)

Comments

Paolo Bonzini Jan. 20, 2015, 2:57 p.m. UTC | #1
On 23/12/2014 01:36, Mark Cave-Ayland wrote:
> Otherwise when cpu_post_load calls ppc_store_sdr1() when restoring a VM
> snapshot the value is deemed unchanged and so the internal env->htab*
> variables aren't set correctly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  target-ppc/misc_helper.c |    7 ++++++-
>  target-ppc/mmu_helper.c  |   35 +++++++++++++++--------------------
>  2 files changed, 21 insertions(+), 21 deletions(-)
> 
> diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c
> index a577b3a..6b12ca8 100644
> --- a/target-ppc/misc_helper.c
> +++ b/target-ppc/misc_helper.c
> @@ -77,8 +77,13 @@ void helper_msr_facility_check(CPUPPCState *env, uint32_t bit,
>  
>  void helper_store_sdr1(CPUPPCState *env, target_ulong val)
>  {
> +    PowerPCCPU *cpu = ppc_env_get_cpu(env);
> +
>      if (!env->external_htab) {
> -        ppc_store_sdr1(env, val);
> +        if (env->spr[SPR_SDR1] != val) {
> +            ppc_store_sdr1(env, val);
> +            tlb_flush(CPU(cpu), 1);

Possibly stupid question: should this tlb_flush be in ppc_store_sdr1,
maybe guarded by "if (tcg_enabled())"?

Apart from this, the patch is okay.

Paolo

> +        }
>      }
>  }
>  
> diff --git a/target-ppc/mmu_helper.c b/target-ppc/mmu_helper.c
> index 660be7f..527c6ad 100644
> --- a/target-ppc/mmu_helper.c
> +++ b/target-ppc/mmu_helper.c
> @@ -2036,31 +2036,26 @@ void ppc_tlb_invalidate_one(CPUPPCState *env, target_ulong addr)
>  /* Special registers manipulation */
>  void ppc_store_sdr1(CPUPPCState *env, target_ulong value)
>  {
> -    PowerPCCPU *cpu = ppc_env_get_cpu(env);
> -
>      qemu_log_mask(CPU_LOG_MMU, "%s: " TARGET_FMT_lx "\n", __func__, value);
>      assert(!env->external_htab);
> -    if (env->spr[SPR_SDR1] != value) {
> -        env->spr[SPR_SDR1] = value;
> +    env->spr[SPR_SDR1] = value;
>  #if defined(TARGET_PPC64)
> -        if (env->mmu_model & POWERPC_MMU_64) {
> -            target_ulong htabsize = value & SDR_64_HTABSIZE;
> +    if (env->mmu_model & POWERPC_MMU_64) {
> +        target_ulong htabsize = value & SDR_64_HTABSIZE;
>  
> -            if (htabsize > 28) {
> -                fprintf(stderr, "Invalid HTABSIZE 0x" TARGET_FMT_lx
> -                        " stored in SDR1\n", htabsize);
> -                htabsize = 28;
> -            }
> -            env->htab_mask = (1ULL << (htabsize + 18 - 7)) - 1;
> -            env->htab_base = value & SDR_64_HTABORG;
> -        } else
> -#endif /* defined(TARGET_PPC64) */
> -        {
> -            /* FIXME: Should check for valid HTABMASK values */
> -            env->htab_mask = ((value & SDR_32_HTABMASK) << 16) | 0xFFFF;
> -            env->htab_base = value & SDR_32_HTABORG;
> +        if (htabsize > 28) {
> +            fprintf(stderr, "Invalid HTABSIZE 0x" TARGET_FMT_lx
> +                    " stored in SDR1\n", htabsize);
> +            htabsize = 28;
>          }
> -        tlb_flush(CPU(cpu), 1);
> +        env->htab_mask = (1ULL << (htabsize + 18 - 7)) - 1;
> +        env->htab_base = value & SDR_64_HTABORG;
> +    } else
> +#endif /* defined(TARGET_PPC64) */
> +    {
> +        /* FIXME: Should check for valid HTABMASK values */
> +        env->htab_mask = ((value & SDR_32_HTABMASK) << 16) | 0xFFFF;
> +        env->htab_base = value & SDR_32_HTABORG;
>      }
>  }
>  
>
Mark Cave-Ayland Jan. 20, 2015, 3:23 p.m. UTC | #2
On 20/01/15 14:57, Paolo Bonzini wrote:

> On 23/12/2014 01:36, Mark Cave-Ayland wrote:
>> Otherwise when cpu_post_load calls ppc_store_sdr1() when restoring a VM
>> snapshot the value is deemed unchanged and so the internal env->htab*
>> variables aren't set correctly.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>> CC: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  target-ppc/misc_helper.c |    7 ++++++-
>>  target-ppc/mmu_helper.c  |   35 +++++++++++++++--------------------
>>  2 files changed, 21 insertions(+), 21 deletions(-)
>>
>> diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c
>> index a577b3a..6b12ca8 100644
>> --- a/target-ppc/misc_helper.c
>> +++ b/target-ppc/misc_helper.c
>> @@ -77,8 +77,13 @@ void helper_msr_facility_check(CPUPPCState *env, uint32_t bit,
>>  
>>  void helper_store_sdr1(CPUPPCState *env, target_ulong val)
>>  {
>> +    PowerPCCPU *cpu = ppc_env_get_cpu(env);
>> +
>>      if (!env->external_htab) {
>> -        ppc_store_sdr1(env, val);
>> +        if (env->spr[SPR_SDR1] != val) {
>> +            ppc_store_sdr1(env, val);
>> +            tlb_flush(CPU(cpu), 1);
> 
> Possibly stupid question: should this tlb_flush be in ppc_store_sdr1,
> maybe guarded by "if (tcg_enabled())"?
> 
> Apart from this, the patch is okay.

Thanks Paolo. I based this patch upon a comment in a slightly earlier
thread here:
http://lists.gnu.org/archive/html/qemu-devel/2014-12/msg03146.html.

Is this still relevant or would you still like me to make the change?
This is a little beyond my area of knowledge, but at the very least I
can test any suggested changes under TCG fairly easily.


ATB,

Mark.
Paolo Bonzini Jan. 20, 2015, 3:58 p.m. UTC | #3
On 20/01/2015 16:23, Mark Cave-Ayland wrote:
> On 20/01/15 14:57, Paolo Bonzini wrote:
> 
>> On 23/12/2014 01:36, Mark Cave-Ayland wrote:
>>> Otherwise when cpu_post_load calls ppc_store_sdr1() when restoring a VM
>>> snapshot the value is deemed unchanged and so the internal env->htab*
>>> variables aren't set correctly.
>>>
>>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>>> CC: Paolo Bonzini <pbonzini@redhat.com>
>>> ---
>>>  target-ppc/misc_helper.c |    7 ++++++-
>>>  target-ppc/mmu_helper.c  |   35 +++++++++++++++--------------------
>>>  2 files changed, 21 insertions(+), 21 deletions(-)
>>>
>>> diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c
>>> index a577b3a..6b12ca8 100644
>>> --- a/target-ppc/misc_helper.c
>>> +++ b/target-ppc/misc_helper.c
>>> @@ -77,8 +77,13 @@ void helper_msr_facility_check(CPUPPCState *env, uint32_t bit,
>>>  
>>>  void helper_store_sdr1(CPUPPCState *env, target_ulong val)
>>>  {
>>> +    PowerPCCPU *cpu = ppc_env_get_cpu(env);
>>> +
>>>      if (!env->external_htab) {
>>> -        ppc_store_sdr1(env, val);
>>> +        if (env->spr[SPR_SDR1] != val) {
>>> +            ppc_store_sdr1(env, val);
>>> +            tlb_flush(CPU(cpu), 1);
>>
>> Possibly stupid question: should this tlb_flush be in ppc_store_sdr1,
>> maybe guarded by "if (tcg_enabled())"?
>>
>> Apart from this, the patch is okay.
> 
> Thanks Paolo. I based this patch upon a comment in a slightly earlier
> thread here:
> http://lists.gnu.org/archive/html/qemu-devel/2014-12/msg03146.html.
> 
> Is this still relevant or would you still like me to make the change?
> This is a little beyond my area of knowledge, but at the very least I
> can test any suggested changes under TCG fairly easily.

No big deal, it's really just personal preference and as you saw even
that can change easily...

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
diff mbox

Patch

diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c
index a577b3a..6b12ca8 100644
--- a/target-ppc/misc_helper.c
+++ b/target-ppc/misc_helper.c
@@ -77,8 +77,13 @@  void helper_msr_facility_check(CPUPPCState *env, uint32_t bit,
 
 void helper_store_sdr1(CPUPPCState *env, target_ulong val)
 {
+    PowerPCCPU *cpu = ppc_env_get_cpu(env);
+
     if (!env->external_htab) {
-        ppc_store_sdr1(env, val);
+        if (env->spr[SPR_SDR1] != val) {
+            ppc_store_sdr1(env, val);
+            tlb_flush(CPU(cpu), 1);
+        }
     }
 }
 
diff --git a/target-ppc/mmu_helper.c b/target-ppc/mmu_helper.c
index 660be7f..527c6ad 100644
--- a/target-ppc/mmu_helper.c
+++ b/target-ppc/mmu_helper.c
@@ -2036,31 +2036,26 @@  void ppc_tlb_invalidate_one(CPUPPCState *env, target_ulong addr)
 /* Special registers manipulation */
 void ppc_store_sdr1(CPUPPCState *env, target_ulong value)
 {
-    PowerPCCPU *cpu = ppc_env_get_cpu(env);
-
     qemu_log_mask(CPU_LOG_MMU, "%s: " TARGET_FMT_lx "\n", __func__, value);
     assert(!env->external_htab);
-    if (env->spr[SPR_SDR1] != value) {
-        env->spr[SPR_SDR1] = value;
+    env->spr[SPR_SDR1] = value;
 #if defined(TARGET_PPC64)
-        if (env->mmu_model & POWERPC_MMU_64) {
-            target_ulong htabsize = value & SDR_64_HTABSIZE;
+    if (env->mmu_model & POWERPC_MMU_64) {
+        target_ulong htabsize = value & SDR_64_HTABSIZE;
 
-            if (htabsize > 28) {
-                fprintf(stderr, "Invalid HTABSIZE 0x" TARGET_FMT_lx
-                        " stored in SDR1\n", htabsize);
-                htabsize = 28;
-            }
-            env->htab_mask = (1ULL << (htabsize + 18 - 7)) - 1;
-            env->htab_base = value & SDR_64_HTABORG;
-        } else
-#endif /* defined(TARGET_PPC64) */
-        {
-            /* FIXME: Should check for valid HTABMASK values */
-            env->htab_mask = ((value & SDR_32_HTABMASK) << 16) | 0xFFFF;
-            env->htab_base = value & SDR_32_HTABORG;
+        if (htabsize > 28) {
+            fprintf(stderr, "Invalid HTABSIZE 0x" TARGET_FMT_lx
+                    " stored in SDR1\n", htabsize);
+            htabsize = 28;
         }
-        tlb_flush(CPU(cpu), 1);
+        env->htab_mask = (1ULL << (htabsize + 18 - 7)) - 1;
+        env->htab_base = value & SDR_64_HTABORG;
+    } else
+#endif /* defined(TARGET_PPC64) */
+    {
+        /* FIXME: Should check for valid HTABMASK values */
+        env->htab_mask = ((value & SDR_32_HTABMASK) << 16) | 0xFFFF;
+        env->htab_base = value & SDR_32_HTABORG;
     }
 }