[PATCH-for-11.0 v3 18/22] target/ppc: Inline cpu_ld/st_data_ra() calls in do_hash()

Philippe Mathieu-Daudé posted 22 patches 2 months, 2 weeks ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Laurent Vivier <laurent@vivier.eu>, Brian Cain <brian.cain@oss.qualcomm.com>, Helge Deller <deller@gmx.de>, Zhao Liu <zhao1.liu@intel.com>, Eduardo Habkost <eduardo@habkost.net>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <arikalo@gmail.com>, Nicholas Piggin <npiggin@gmail.com>, Chinmay Rath <rathc@linux.ibm.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Yoshinori Sato <yoshinori.sato@nifty.com>, Ilya Leoshkevich <iii@linux.ibm.com>, David Hildenbrand <david@kernel.org>, Thomas Huth <thuth@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
[PATCH-for-11.0 v3 18/22] target/ppc: Inline cpu_ld/st_data_ra() calls in do_hash()
Posted by Philippe Mathieu-Daudé 2 months, 2 weeks ago
In preparation of removing the cpu_ld*_data_ra()
and cpu_st*_data_ra() calls, inline them.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/ppc/tcg-excp_helper.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/target/ppc/tcg-excp_helper.c b/target/ppc/tcg-excp_helper.c
index edecfb85725..244aeb23c16 100644
--- a/target/ppc/tcg-excp_helper.c
+++ b/target/ppc/tcg-excp_helper.c
@@ -160,14 +160,17 @@ static void do_hash(CPUPPCState *env, target_ulong ea, target_ulong ra,
                     target_ulong rb, uint64_t key, bool store)
 {
     uint64_t calculated_hash = hash_digest(ra, rb, key), loaded_hash;
+    unsigned mmu_idx = cpu_mmu_index(env_cpu(env), false);
+    MemOpIdx oi = make_memop_idx(MO_TE | MO_UQ | MO_UNALN, mmu_idx);
+    uintptr_t retaddr = GETPC();
 
     if (store) {
-        cpu_stq_data_ra(env, ea, calculated_hash, GETPC());
+        cpu_stq_mmu(env, ea, calculated_hash, oi, retaddr);
     } else {
-        loaded_hash = cpu_ldq_data_ra(env, ea, GETPC());
+        loaded_hash = cpu_ldq_mmu(env, ea, oi, retaddr);
         if (loaded_hash != calculated_hash) {
             raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
-                POWERPC_EXCP_TRAP, GETPC());
+                                   POWERPC_EXCP_TRAP, retaddr);
         }
     }
 }
-- 
2.51.0


Re: [PATCH-for-11.0 v3 18/22] target/ppc: Inline cpu_ld/st_data_ra() calls in do_hash()
Posted by Richard Henderson 1 month, 4 weeks ago
On 11/26/25 14:21, Philippe Mathieu-Daudé wrote:
> In preparation of removing the cpu_ld*_data_ra()
> and cpu_st*_data_ra() calls, inline them.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   target/ppc/tcg-excp_helper.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/target/ppc/tcg-excp_helper.c b/target/ppc/tcg-excp_helper.c
> index edecfb85725..244aeb23c16 100644
> --- a/target/ppc/tcg-excp_helper.c
> +++ b/target/ppc/tcg-excp_helper.c
> @@ -160,14 +160,17 @@ static void do_hash(CPUPPCState *env, target_ulong ea, target_ulong ra,
>                       target_ulong rb, uint64_t key, bool store)
>   {
>       uint64_t calculated_hash = hash_digest(ra, rb, key), loaded_hash;
> +    unsigned mmu_idx = cpu_mmu_index(env_cpu(env), false);
> +    MemOpIdx oi = make_memop_idx(MO_TE | MO_UQ | MO_UNALN, mmu_idx);
> +    uintptr_t retaddr = GETPC();
>   
>       if (store) {
> -        cpu_stq_data_ra(env, ea, calculated_hash, GETPC());
> +        cpu_stq_mmu(env, ea, calculated_hash, oi, retaddr);
>       } else {
> -        loaded_hash = cpu_ldq_data_ra(env, ea, GETPC());
> +        loaded_hash = cpu_ldq_mmu(env, ea, oi, retaddr);
>           if (loaded_hash != calculated_hash) {
>               raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
> -                POWERPC_EXCP_TRAP, GETPC());
> +                                   POWERPC_EXCP_TRAP, retaddr);
>           }
>       }
>   }

This is the page translation hash.  I suspect the actual address must be aligned, and 
probably forcibly so via computation.  The MO_UNALN is either wrong or misleading.

r~

Re: [PATCH-for-11.0 v3 18/22] target/ppc: Inline cpu_ld/st_data_ra() calls in do_hash()
Posted by Philippe Mathieu-Daudé 2 weeks, 3 days ago
On 12/12/25 17:57, Richard Henderson wrote:
> On 11/26/25 14:21, Philippe Mathieu-Daudé wrote:
>> In preparation of removing the cpu_ld*_data_ra()
>> and cpu_st*_data_ra() calls, inline them.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   target/ppc/tcg-excp_helper.c | 9 ++++++---
>>   1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/target/ppc/tcg-excp_helper.c b/target/ppc/tcg-excp_helper.c
>> index edecfb85725..244aeb23c16 100644
>> --- a/target/ppc/tcg-excp_helper.c
>> +++ b/target/ppc/tcg-excp_helper.c
>> @@ -160,14 +160,17 @@ static void do_hash(CPUPPCState *env, 
>> target_ulong ea, target_ulong ra,
>>                       target_ulong rb, uint64_t key, bool store)
>>   {
>>       uint64_t calculated_hash = hash_digest(ra, rb, key), loaded_hash;
>> +    unsigned mmu_idx = cpu_mmu_index(env_cpu(env), false);
>> +    MemOpIdx oi = make_memop_idx(MO_TE | MO_UQ | MO_UNALN, mmu_idx);
>> +    uintptr_t retaddr = GETPC();
>>       if (store) {
>> -        cpu_stq_data_ra(env, ea, calculated_hash, GETPC());
>> +        cpu_stq_mmu(env, ea, calculated_hash, oi, retaddr);
>>       } else {
>> -        loaded_hash = cpu_ldq_data_ra(env, ea, GETPC());
>> +        loaded_hash = cpu_ldq_mmu(env, ea, oi, retaddr);
>>           if (loaded_hash != calculated_hash) {
>>               raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
>> -                POWERPC_EXCP_TRAP, GETPC());
>> +                                   POWERPC_EXCP_TRAP, retaddr);
>>           }
>>       }
>>   }
> 
> This is the page translation hash.  I suspect the actual address must be 
> aligned, and probably forcibly so via computation.  The MO_UNALN is 
> either wrong or misleading.

This is a faithful expansion of inlined helpers, showing the current
logical state of the code. I'll remove MO_UNALN in a subsequent patch.