diff mbox

[v2,2/6] tcg: set up tb->page_addr before insertion

Message ID 1467735496-16256-3-git-send-email-alex.bennee@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Alex Bennée July 5, 2016, 4:18 p.m. UTC
This ensures that if we find the TB on the slow path that tb->page_addr
is correctly set before being tested.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 translate-all.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

sergey.fedorov@linaro.org July 7, 2016, 2:08 p.m. UTC | #1
On 05/07/16 19:18, Alex Bennée wrote:
> This ensures that if we find the TB on the slow path that tb->page_addr
> is correctly set before being tested.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

Reveiwed-by: Sergey Fedorov <sergey.fedorov@linaro.org>

> ---
>  translate-all.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/translate-all.c b/translate-all.c
> index 96efe48..97e834a 100644
> --- a/translate-all.c
> +++ b/translate-all.c
> @@ -1126,10 +1126,6 @@ static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,
>  {
>      uint32_t h;
>  
> -    /* add in the hash table */
> -    h = tb_hash_func(phys_pc, tb->pc, tb->flags);
> -    qht_insert(&tcg_ctx.tb_ctx.htable, tb, h);
> -
>      /* add in the page list */
>      tb_alloc_page(tb, 0, phys_pc & TARGET_PAGE_MASK);
>      if (phys_page2 != -1) {
> @@ -1138,6 +1134,10 @@ static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,
>          tb->page_addr[1] = -1;
>      }
>  
> +    /* add in the hash table */
> +    h = tb_hash_func(phys_pc, tb->pc, tb->flags);
> +    qht_insert(&tcg_ctx.tb_ctx.htable, tb, h);
> +
>  #ifdef DEBUG_TB_CHECK
>      tb_page_check();
>  #endif
Sergey Fedorov July 8, 2016, 9:40 a.m. UTC | #2
On 07/07/16 17:08, Sergey Fedorov wrote:
> On 05/07/16 19:18, Alex Bennée wrote:
>> This ensures that if we find the TB on the slow path that tb->page_addr
>> is correctly set before being tested.
>>
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reveiwed-by: Sergey Fedorov <sergey.fedorov@linaro.org>

However, we may need to use smp_wmb() here paired with smp_rmb() in
tb_find_fast().

Alternatively, QHT might provide some explicit guarantee about memory
ordering around qht_insert() and qht_lookup(). Actually, there is
already right ordering thanks to seqlock operations in QHT
implementation. This means we could elide explicit memory barrier from
the first patch as well.

Kind regards,
Sergey

>
>> ---
>>  translate-all.c | 8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/translate-all.c b/translate-all.c
>> index 96efe48..97e834a 100644
>> --- a/translate-all.c
>> +++ b/translate-all.c
>> @@ -1126,10 +1126,6 @@ static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,
>>  {
>>      uint32_t h;
>>  
>> -    /* add in the hash table */
>> -    h = tb_hash_func(phys_pc, tb->pc, tb->flags);
>> -    qht_insert(&tcg_ctx.tb_ctx.htable, tb, h);
>> -
>>      /* add in the page list */
>>      tb_alloc_page(tb, 0, phys_pc & TARGET_PAGE_MASK);
>>      if (phys_page2 != -1) {
>> @@ -1138,6 +1134,10 @@ static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,
>>          tb->page_addr[1] = -1;
>>      }
>>  
>> +    /* add in the hash table */
>> +    h = tb_hash_func(phys_pc, tb->pc, tb->flags);
>> +    qht_insert(&tcg_ctx.tb_ctx.htable, tb, h);
>> +
>>  #ifdef DEBUG_TB_CHECK
>>      tb_page_check();
>>  #endif
diff mbox

Patch

diff --git a/translate-all.c b/translate-all.c
index 96efe48..97e834a 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -1126,10 +1126,6 @@  static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,
 {
     uint32_t h;
 
-    /* add in the hash table */
-    h = tb_hash_func(phys_pc, tb->pc, tb->flags);
-    qht_insert(&tcg_ctx.tb_ctx.htable, tb, h);
-
     /* add in the page list */
     tb_alloc_page(tb, 0, phys_pc & TARGET_PAGE_MASK);
     if (phys_page2 != -1) {
@@ -1138,6 +1134,10 @@  static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,
         tb->page_addr[1] = -1;
     }
 
+    /* add in the hash table */
+    h = tb_hash_func(phys_pc, tb->pc, tb->flags);
+    qht_insert(&tcg_ctx.tb_ctx.htable, tb, h);
+
 #ifdef DEBUG_TB_CHECK
     tb_page_check();
 #endif