diff mbox series

[v4,07/19] hw/arm/smmu: Introduce CACHED_ENTRY_TO_ADDR

Message ID 20240701110241.2005222-8-smostafa@google.com
State New
Headers show
Series SMMUv3 nested translation support | expand

Commit Message

Mostafa Saleh July 1, 2024, 11:02 a.m. UTC
Soon, smmuv3_do_translate() will be used to translate the CD and the
TTBx, instead of re-writting the same logic to convert the returned
cached entry to an address, add a new macro CACHED_ENTRY_TO_ADDR.

Signed-off-by: Mostafa Saleh <smostafa@google.com>
---
 hw/arm/smmuv3.c              | 3 +--
 include/hw/arm/smmu-common.h | 3 +++
 2 files changed, 4 insertions(+), 2 deletions(-)

Comments

Jean-Philippe Brucker July 4, 2024, 6:04 p.m. UTC | #1
On Mon, Jul 01, 2024 at 11:02:29AM +0000, Mostafa Saleh wrote:
> Soon, smmuv3_do_translate() will be used to translate the CD and the
> TTBx, instead of re-writting the same logic to convert the returned
> cached entry to an address, add a new macro CACHED_ENTRY_TO_ADDR.
> 
> Signed-off-by: Mostafa Saleh <smostafa@google.com>
> ---
>  hw/arm/smmuv3.c              | 3 +--
>  include/hw/arm/smmu-common.h | 3 +++
>  2 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
> index cc61708160..229b3c388c 100644
> --- a/hw/arm/smmuv3.c
> +++ b/hw/arm/smmuv3.c
> @@ -950,8 +950,7 @@ epilogue:
>      switch (status) {
>      case SMMU_TRANS_SUCCESS:
>          entry.perm = cached_entry->entry.perm;
> -        entry.translated_addr = cached_entry->entry.translated_addr +
> -                                    (addr & cached_entry->entry.addr_mask);
> +        entry.translated_addr = CACHED_ENTRY_TO_ADDR(cached_entry, addr);
>          entry.addr_mask = cached_entry->entry.addr_mask;
>          trace_smmuv3_translate_success(mr->parent_obj.name, sid, addr,
>                                         entry.translated_addr, entry.perm,
> diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h
> index 96eb017e50..09d3b9e734 100644
> --- a/include/hw/arm/smmu-common.h
> +++ b/include/hw/arm/smmu-common.h
> @@ -37,6 +37,9 @@
>  #define VMSA_IDXMSK(isz, strd, lvl)         ((1ULL << \
>                                               VMSA_BIT_LVL(isz, strd, lvl)) - 1)
>  
> +#define CACHED_ENTRY_TO_ADDR(ent, addr)      (ent)->entry.translated_addr + \
> +                                             ((addr) & (ent)->entry.addr_mask);

nit: maybe wrap this in parenthesis to avoid future usage mistakes and
drop the semicolon 

Thanks,
Jean

> +
>  /*
>   * Page table walk error types
>   */
> -- 
> 2.45.2.803.g4e1b14247a-goog
>
Eric Auger July 8, 2024, 1:27 p.m. UTC | #2
Hi Mostafa,

On 7/4/24 20:04, Jean-Philippe Brucker wrote:
> On Mon, Jul 01, 2024 at 11:02:29AM +0000, Mostafa Saleh wrote:
>> Soon, smmuv3_do_translate() will be used to translate the CD and the
>> TTBx, instead of re-writting the same logic to convert the returned
>> cached entry to an address, add a new macro CACHED_ENTRY_TO_ADDR.
>>
>> Signed-off-by: Mostafa Saleh <smostafa@google.com>
>> ---
>>  hw/arm/smmuv3.c              | 3 +--
>>  include/hw/arm/smmu-common.h | 3 +++
>>  2 files changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
>> index cc61708160..229b3c388c 100644
>> --- a/hw/arm/smmuv3.c
>> +++ b/hw/arm/smmuv3.c
>> @@ -950,8 +950,7 @@ epilogue:
>>      switch (status) {
>>      case SMMU_TRANS_SUCCESS:
>>          entry.perm = cached_entry->entry.perm;
>> -        entry.translated_addr = cached_entry->entry.translated_addr +
>> -                                    (addr & cached_entry->entry.addr_mask);
>> +        entry.translated_addr = CACHED_ENTRY_TO_ADDR(cached_entry, addr);
>>          entry.addr_mask = cached_entry->entry.addr_mask;
>>          trace_smmuv3_translate_success(mr->parent_obj.name, sid, addr,
>>                                         entry.translated_addr, entry.perm,
>> diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h
>> index 96eb017e50..09d3b9e734 100644
>> --- a/include/hw/arm/smmu-common.h
>> +++ b/include/hw/arm/smmu-common.h
>> @@ -37,6 +37,9 @@
>>  #define VMSA_IDXMSK(isz, strd, lvl)         ((1ULL << \
>>                                               VMSA_BIT_LVL(isz, strd, lvl)) - 1)
>>  
>> +#define CACHED_ENTRY_TO_ADDR(ent, addr)      (ent)->entry.translated_addr + \
>> +                                             ((addr) & (ent)->entry.addr_mask);
> nit: maybe wrap this in parenthesis to avoid future usage mistakes and
> drop the semicolon 
With Jean's comments taken into account,
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Eric
>
> Thanks,
> Jean
>
>> +
>>  /*
>>   * Page table walk error types
>>   */
>> -- 
>> 2.45.2.803.g4e1b14247a-goog
>>
diff mbox series

Patch

diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index cc61708160..229b3c388c 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -950,8 +950,7 @@  epilogue:
     switch (status) {
     case SMMU_TRANS_SUCCESS:
         entry.perm = cached_entry->entry.perm;
-        entry.translated_addr = cached_entry->entry.translated_addr +
-                                    (addr & cached_entry->entry.addr_mask);
+        entry.translated_addr = CACHED_ENTRY_TO_ADDR(cached_entry, addr);
         entry.addr_mask = cached_entry->entry.addr_mask;
         trace_smmuv3_translate_success(mr->parent_obj.name, sid, addr,
                                        entry.translated_addr, entry.perm,
diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h
index 96eb017e50..09d3b9e734 100644
--- a/include/hw/arm/smmu-common.h
+++ b/include/hw/arm/smmu-common.h
@@ -37,6 +37,9 @@ 
 #define VMSA_IDXMSK(isz, strd, lvl)         ((1ULL << \
                                              VMSA_BIT_LVL(isz, strd, lvl)) - 1)
 
+#define CACHED_ENTRY_TO_ADDR(ent, addr)      (ent)->entry.translated_addr + \
+                                             ((addr) & (ent)->entry.addr_mask);
+
 /*
  * Page table walk error types
  */