target/ppc: Fix broadcast tlbie synchronisation
authorNicholas Piggin <npiggin@gmail.com>
Tue, 26 Mar 2024 13:20:43 +0000 (23:20 +1000)
committerNicholas Piggin <npiggin@gmail.com>
Thu, 23 May 2024 22:57:50 +0000 (08:57 +1000)
commit82676f1fc4b1511a5fe32256aaec885d200ffbf6
tree1f4e8a23d188d8c45e5dd2047ee83bd7c7d1e2e6
parent95912ce1ebe4303d17118219691573ae6227b0e2
target/ppc: Fix broadcast tlbie synchronisation

With mttcg, broadcast tlbie instructions do not wait until other vCPUs
have been kicked out of TCG execution before they complete (including
necessary subsequent tlbsync, etc., instructions). This is contrary to
the ISA, and it permits other vCPUs to use translations after the TLB
flush. For example:

   CPU0
   // *memP is initially 0, memV maps to memP with *pte
   *pte = 0;
   ptesync ; tlbie ; eieio ; tlbsync ; ptesync
   *memP = 1;

   CPU1
   assert(*memV == 0);

It is possible for the assertion to fail because CPU1 translates memV
using the TLB after CPU0 has stored 1 to the underlying memory. This
race was observed with a careful test case where CPU1 checks run in a
very large expensive TB so it can run for the entire CPU0 period between
clearing the pte and storing the memory, but host vCPU thread preemption
could cause the race to hit anywhere.

As explained in commit 4ddc104689b ("target/ppc: Fix tlbie"), it is not
enough to just use tlb_flush_all_cpus_synced(), because that does not
execute until the calling CPU has finished its TB. It is also required
that the TB is ended at the point where the TLB flush must subsequently
take effect.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
target/ppc/helper_regs.c
target/ppc/mmu_helper.c
target/ppc/translate.c
target/ppc/translate/storage-ctrl-impl.c.inc