qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] target/ppc: Fix tlbie
@ 2022-05-03 16:39 Leandro Lupori
  2022-05-03 16:54 ` Cédric Le Goater
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Leandro Lupori @ 2022-05-03 16:39 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: clg, danielhb413, david, groug, Leandro Lupori

Commit 74c4912f097bab98 changed check_tlb_flush() to use
tlb_flush_all_cpus_synced() instead of calling tlb_flush() on each
CPU. However, as side effect of this, a CPU executing a ptesync
after a tlbie will have its TLB flushed only after exiting its
current Translation Block (TB).

This causes memory accesses to invalid pages to succeed, if they
happen to be on the same TB as the ptesync.

To fix this, use tlb_flush_all_cpus() instead, that immediately
flushes the TLB of the CPU executing the ptesync instruction.

Fixes: 74c4912f097bab98 ("target/ppc: Fix synchronization of mttcg with broadcast TLB flushes")
Signed-off-by: Leandro Lupori <leandro.lupori@eldorado.org.br>
---
 target/ppc/helper_regs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/ppc/helper_regs.c b/target/ppc/helper_regs.c
index 9a691d6833..1fa032e4d0 100644
--- a/target/ppc/helper_regs.c
+++ b/target/ppc/helper_regs.c
@@ -293,7 +293,7 @@ void check_tlb_flush(CPUPPCState *env, bool global)
     if (global && (env->tlb_need_flush & TLB_NEED_GLOBAL_FLUSH)) {
         env->tlb_need_flush &= ~TLB_NEED_GLOBAL_FLUSH;
         env->tlb_need_flush &= ~TLB_NEED_LOCAL_FLUSH;
-        tlb_flush_all_cpus_synced(cs);
+        tlb_flush_all_cpus(cs);
         return;
     }
 
-- 
2.25.1



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

* Re: [PATCH] target/ppc: Fix tlbie
  2022-05-03 16:39 [PATCH] target/ppc: Fix tlbie Leandro Lupori
@ 2022-05-03 16:54 ` Cédric Le Goater
  2022-05-03 18:09   ` Leandro Lupori
  2022-05-13 17:12 ` Fabiano Rosas
  2022-05-17 19:02 ` Daniel Henrique Barboza
  2 siblings, 1 reply; 5+ messages in thread
From: Cédric Le Goater @ 2022-05-03 16:54 UTC (permalink / raw)
  To: Leandro Lupori, qemu-devel, qemu-ppc; +Cc: danielhb413, david, groug

On 5/3/22 18:39, Leandro Lupori wrote:
> Commit 74c4912f097bab98 changed check_tlb_flush() to use
> tlb_flush_all_cpus_synced() instead of calling tlb_flush() on each
> CPU. However, as side effect of this, a CPU executing a ptesync
> after a tlbie will have its TLB flushed only after exiting its
> current Translation Block (TB).
> 
> This causes memory accesses to invalid pages to succeed, if they
> happen to be on the same TB as the ptesync.

How did you track the issue ? Do you have a test case ?

Thanks,

C.


> To fix this, use tlb_flush_all_cpus() instead, that immediately
> flushes the TLB of the CPU executing the ptesync instruction.
> 
> Fixes: 74c4912f097bab98 ("target/ppc: Fix synchronization of mttcg with broadcast TLB flushes")
> Signed-off-by: Leandro Lupori <leandro.lupori@eldorado.org.br>
> ---
>   target/ppc/helper_regs.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/target/ppc/helper_regs.c b/target/ppc/helper_regs.c
> index 9a691d6833..1fa032e4d0 100644
> --- a/target/ppc/helper_regs.c
> +++ b/target/ppc/helper_regs.c
> @@ -293,7 +293,7 @@ void check_tlb_flush(CPUPPCState *env, bool global)
>       if (global && (env->tlb_need_flush & TLB_NEED_GLOBAL_FLUSH)) {
>           env->tlb_need_flush &= ~TLB_NEED_GLOBAL_FLUSH;
>           env->tlb_need_flush &= ~TLB_NEED_LOCAL_FLUSH;
> -        tlb_flush_all_cpus_synced(cs);
> +        tlb_flush_all_cpus(cs);
>           return;
>       }
>   



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

* Re: [PATCH] target/ppc: Fix tlbie
  2022-05-03 16:54 ` Cédric Le Goater
@ 2022-05-03 18:09   ` Leandro Lupori
  0 siblings, 0 replies; 5+ messages in thread
From: Leandro Lupori @ 2022-05-03 18:09 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel, qemu-ppc; +Cc: danielhb413, david, groug

On 5/3/22 13:54, Cédric Le Goater wrote:

> On 5/3/22 18:39, Leandro Lupori wrote:
>> Commit 74c4912f097bab98 changed check_tlb_flush() to use
>> tlb_flush_all_cpus_synced() instead of calling tlb_flush() on each
>> CPU. However, as side effect of this, a CPU executing a ptesync
>> after a tlbie will have its TLB flushed only after exiting its
>> current Translation Block (TB).
>>
>> This causes memory accesses to invalid pages to succeed, if they
>> happen to be on the same TB as the ptesync.
> 
> How did you track the issue ? Do you have a test case ?
> 

I've initially found it with a hacked Linux kernel module that I was 
using to test tlbie behavior, before trying to improve its 
implementation to only invalidate the needed entries.

Now I've added a new test to those MMU tests from pnv-test, to be able 
to reproduce and test it more easily. I've not included it because it 
depends on other code from MMU tests and semihosting or attn. But you 
can check it here:

https://github.com/PPC64/qemu/commit/ccb60e4b950d1376b7f5d72843f6ce082a1a9edb 
(mmu_test_18)

Thanks,
Leandro

> Thanks,
> 
> C.
> 


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

* Re: [PATCH] target/ppc: Fix tlbie
  2022-05-03 16:39 [PATCH] target/ppc: Fix tlbie Leandro Lupori
  2022-05-03 16:54 ` Cédric Le Goater
@ 2022-05-13 17:12 ` Fabiano Rosas
  2022-05-17 19:02 ` Daniel Henrique Barboza
  2 siblings, 0 replies; 5+ messages in thread
From: Fabiano Rosas @ 2022-05-13 17:12 UTC (permalink / raw)
  To: Leandro Lupori, qemu-devel, qemu-ppc
  Cc: clg, danielhb413, david, groug, Leandro Lupori

Leandro Lupori <leandro.lupori@eldorado.org.br> writes:

> Commit 74c4912f097bab98 changed check_tlb_flush() to use
> tlb_flush_all_cpus_synced() instead of calling tlb_flush() on each
> CPU. However, as side effect of this, a CPU executing a ptesync
> after a tlbie will have its TLB flushed only after exiting its
> current Translation Block (TB).
>
> This causes memory accesses to invalid pages to succeed, if they
> happen to be on the same TB as the ptesync.
>
> To fix this, use tlb_flush_all_cpus() instead, that immediately
> flushes the TLB of the CPU executing the ptesync instruction.
>
> Fixes: 74c4912f097bab98 ("target/ppc: Fix synchronization of mttcg with broadcast TLB flushes")
> Signed-off-by: Leandro Lupori <leandro.lupori@eldorado.org.br>

Reviewed-by: Fabiano Rosas <farosas@linux.ibm.com>

> ---
>  target/ppc/helper_regs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/ppc/helper_regs.c b/target/ppc/helper_regs.c
> index 9a691d6833..1fa032e4d0 100644
> --- a/target/ppc/helper_regs.c
> +++ b/target/ppc/helper_regs.c
> @@ -293,7 +293,7 @@ void check_tlb_flush(CPUPPCState *env, bool global)
>      if (global && (env->tlb_need_flush & TLB_NEED_GLOBAL_FLUSH)) {
>          env->tlb_need_flush &= ~TLB_NEED_GLOBAL_FLUSH;
>          env->tlb_need_flush &= ~TLB_NEED_LOCAL_FLUSH;
> -        tlb_flush_all_cpus_synced(cs);
> +        tlb_flush_all_cpus(cs);
>          return;
>      }


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

* Re: [PATCH] target/ppc: Fix tlbie
  2022-05-03 16:39 [PATCH] target/ppc: Fix tlbie Leandro Lupori
  2022-05-03 16:54 ` Cédric Le Goater
  2022-05-13 17:12 ` Fabiano Rosas
@ 2022-05-17 19:02 ` Daniel Henrique Barboza
  2 siblings, 0 replies; 5+ messages in thread
From: Daniel Henrique Barboza @ 2022-05-17 19:02 UTC (permalink / raw)
  To: Leandro Lupori, qemu-devel, qemu-ppc; +Cc: clg, david, groug

Queued in gitlab.com/danielhb/qemu/tree/ppc-next. Thanks,


Daniel

On 5/3/22 13:39, Leandro Lupori wrote:
> Commit 74c4912f097bab98 changed check_tlb_flush() to use
> tlb_flush_all_cpus_synced() instead of calling tlb_flush() on each
> CPU. However, as side effect of this, a CPU executing a ptesync
> after a tlbie will have its TLB flushed only after exiting its
> current Translation Block (TB).
> 
> This causes memory accesses to invalid pages to succeed, if they
> happen to be on the same TB as the ptesync.
> 
> To fix this, use tlb_flush_all_cpus() instead, that immediately
> flushes the TLB of the CPU executing the ptesync instruction.
> 
> Fixes: 74c4912f097bab98 ("target/ppc: Fix synchronization of mttcg with broadcast TLB flushes")
> Signed-off-by: Leandro Lupori <leandro.lupori@eldorado.org.br>
> ---
>   target/ppc/helper_regs.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/target/ppc/helper_regs.c b/target/ppc/helper_regs.c
> index 9a691d6833..1fa032e4d0 100644
> --- a/target/ppc/helper_regs.c
> +++ b/target/ppc/helper_regs.c
> @@ -293,7 +293,7 @@ void check_tlb_flush(CPUPPCState *env, bool global)
>       if (global && (env->tlb_need_flush & TLB_NEED_GLOBAL_FLUSH)) {
>           env->tlb_need_flush &= ~TLB_NEED_GLOBAL_FLUSH;
>           env->tlb_need_flush &= ~TLB_NEED_LOCAL_FLUSH;
> -        tlb_flush_all_cpus_synced(cs);
> +        tlb_flush_all_cpus(cs);
>           return;
>       }
>   


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

end of thread, other threads:[~2022-05-17 19:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-03 16:39 [PATCH] target/ppc: Fix tlbie Leandro Lupori
2022-05-03 16:54 ` Cédric Le Goater
2022-05-03 18:09   ` Leandro Lupori
2022-05-13 17:12 ` Fabiano Rosas
2022-05-17 19:02 ` Daniel Henrique Barboza

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