translate-all: exit from tb_phys_invalidate if qht_remove fails
PATCH 1/1 translate-all: exit from tb_phys_invalidate if qht_remove fails
Two or more threads might race while invalidating the same TB. We currently do not check for this at all despite taking tb_lock, which means we would wrongly invalidate the same TB more than once. This bug has actually been hit by users: I recently saw a report on IRC, although I have yet to see the corresponding test case.
Fix this by using qht_remove as the synchronization point; if it fails, that means the TB has already been invalidated, and therefore there is nothing left to do in tb_phys_invalidate.
Note that this solution works now that we still have tb_lock, and will continue working once we remove tb_lock.
---
This patch applies on top of the "[PATCH v6 00/50] tcg tb_lock removal" series:
https://lists.gnu.org/archive/html/qemu-devel/2017-10/msg03612.html
--- accel/tcg/translate-all.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
accel/tcg/translate-all.c +3 -1
@@ -1081,7 +1081,9 @@ void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr) phys_pc = tb->page_addr[0 ] + (tb->pc & ~TARGET_PAGE_MASK ); h =tb_hash_func (phys_pc, tb->pc, tb->flags, tb->cflags &CF_HASH_MASK , tb->trace_vcpu_dstate); -qht_remove (&tb_ctx.htable, tb, h); +if (!qht_remove (&tb_ctx.htable, tb, h)) { +return ; + }/* remove the TB from the page list */ if (tb->page_addr[0 ] != page_addr) {
Signature · 1 line
2.7.4
Richard Henderson
AppliedQuoted 13 lines · Emilio G. Cota
Two or more threads might race while invalidating the same TB. We currently do not check for this at all despite taking
tb_lock, which means we would wrongly invalidate the same TB more than once. This bug has actually been hit by users: I recently saw a report on IRC, although I have yet to see the corresponding test case.Fix this by using
qht_removeas the synchronization point; if it fails, that means the TB has already been invalidated, and therefore there is nothing left to do intb_phys_invalidate.Note that this solution works now that we still have
tb_lock, and will continue working once we removetb_lock.
Quoted 8 lines
Signed-off-by Emilio G. Cota <[email protected]>---
This patch applies on top of the "[PATCH v6 00/50] tcgtb_lockremoval" series:
https://lists.gnu.org/archive/html/qemu-devel/2017-10/msg03612.html--- accel/tcg/translate-all.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Applied, thanks.
r~