From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fanbS-0007ny-Nz for qemu-devel@nongnu.org; Wed, 04 Jul 2018 15:38:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fanbP-0005b8-LD for qemu-devel@nongnu.org; Wed, 04 Jul 2018 15:38:14 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:58149) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fanbP-0005XU-C2 for qemu-devel@nongnu.org; Wed, 04 Jul 2018 15:38:11 -0400 Date: Wed, 4 Jul 2018 15:38:08 -0400 From: "Emilio G. Cota" Message-ID: <20180704193808.GA32390@flamenco> References: <20180614193147.29680-15-richard.henderson@linaro.org> <000601d40f7a$4be320b0$e3a96210$@ru> <20180629184832.GB14726@flamenco> <000901d411c8$d3bfc9c0$7b3f5d40$@ru> <20180702195234.GB20840@flamenco> <000601d41290$205c56a0$611503e0$@ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <000601d41290$205c56a0$611503e0$@ru> Subject: Re: [Qemu-devel] [PULL, 14/18] translate-all: discard TB when tb_link_page returns an existing matching TB List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Pavel Dovgalyuk Cc: Richard Henderson , qemu-devel@nongnu.org, peter.maydell@linaro.org On Tue, Jul 03, 2018 at 08:38:52 +0300, Pavel Dovgalyuk wrote: > > From: Emilio G. Cota [mailto:cota@braap.org] > > On Mon, Jul 02, 2018 at 08:52:14 +0300, Pavel Dovgalyuk wrote: > > > The same failure can be reproduced with linux-0.2.img, which was > > > downloaded from QEMU site. > > > I can't find it now, but I can upload this file if needed. > > > > Please upload it somewhere and share the full QEMU invocation > > needed to replicate. > > https://github.com/Dovgalyuk/qemu-images/blob/master/linux-0.2.img > > qemu-system-i386 -drive file=images/linux-0.2.img,if=none,snapshot,id=img -drive > driver=blkreplay,if=none,id=rr,image=img -device ide-hd,drive=rr -net none -icount > shift=5,rr=record,rrfile=linux02.rr The appended patch fixes it for me. Can you please test on your windows image? The rationale is to honour CF_NOCACHE, so that we always return a new TB from tb_gen_code. Thanks, Emilio --- diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 170b957..49d77fa 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1446,7 +1446,8 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list) phys_pc = tb->page_addr[0] + (tb->pc & ~TARGET_PAGE_MASK); h = tb_hash_func(phys_pc, tb->pc, tb->flags, tb_cflags(tb) & CF_HASH_MASK, tb->trace_vcpu_dstate); - if (!qht_remove(&tb_ctx.htable, tb, h)) { + if (!(tb->cflags & CF_NOCACHE) && + !qht_remove(&tb_ctx.htable, tb, h)) { return; } @@ -1604,8 +1605,6 @@ tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc, { PageDesc *p; PageDesc *p2 = NULL; - void *existing_tb = NULL; - uint32_t h; assert_memory_lock(); @@ -1625,20 +1624,25 @@ 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, tb->cflags & CF_HASH_MASK, - tb->trace_vcpu_dstate); - qht_insert(&tb_ctx.htable, tb, h, &existing_tb); + if (!(tb->cflags & CF_NOCACHE)) { + void *existing_tb = NULL; + uint32_t h; - /* remove TB from the page(s) if we couldn't insert it */ - if (unlikely(existing_tb)) { - tb_page_remove(p, tb); - invalidate_page_bitmap(p); - if (p2) { - tb_page_remove(p2, tb); - invalidate_page_bitmap(p2); + /* add in the hash table */ + h = tb_hash_func(phys_pc, tb->pc, tb->flags, tb->cflags & CF_HASH_MASK, + tb->trace_vcpu_dstate); + qht_insert(&tb_ctx.htable, tb, h, &existing_tb); + + /* remove TB from the page(s) if we couldn't insert it */ + if (unlikely(existing_tb)) { + tb_page_remove(p, tb); + invalidate_page_bitmap(p); + if (p2) { + tb_page_remove(p2, tb); + invalidate_page_bitmap(p2); + } + tb = existing_tb; } - tb = existing_tb; } if (p2 && p2 != p) {