From patchwork Thu Mar 17 13:46:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sergey.fedorov@linaro.org X-Patchwork-Id: 8612071 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8D1FD9F44D for ; Thu, 17 Mar 2016 14:53:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BE44520375 for ; Thu, 17 Mar 2016 14:53:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 340FD201F2 for ; Thu, 17 Mar 2016 14:53:02 +0000 (UTC) Received: from localhost ([::1]:35503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agZIL-0003zV-Li for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Mar 2016 10:53:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53031) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agYIK-0003rx-4d for qemu-devel@nongnu.org; Thu, 17 Mar 2016 09:49:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agYIG-0008Nf-S1 for qemu-devel@nongnu.org; Thu, 17 Mar 2016 09:48:55 -0400 Received: from mail-lf0-x22f.google.com ([2a00:1450:4010:c07::22f]:34884) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agYIG-0008NM-GB for qemu-devel@nongnu.org; Thu, 17 Mar 2016 09:48:52 -0400 Received: by mail-lf0-x22f.google.com with SMTP id v130so15799076lfd.2 for ; Thu, 17 Mar 2016 06:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9Vm1YDFGzA5Dry6Ev1sE3uGqqORsgqwxIkpybIyAONQ=; b=GsPiG66Qw9ZdwtZ409xlhe4s9wO5fo2n9CeG0O2P73v8viTfaZqIZhGF9jnqDUZD5B T6/0R0HzS8eqQmBaqfp0Btfc5wK6zXisD9TzL8MEpZlM9kd0acIWizoYaZExmDTg9+8j 1HVJW1vAdsqHYo8JtG8+y4Pf5q53K2qHB3yGk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9Vm1YDFGzA5Dry6Ev1sE3uGqqORsgqwxIkpybIyAONQ=; b=M5Kok3JhoU8ecrtUciV8tiuhwrwNCXEpUoDJZr+fWf43gvx+wIppYy7Y6nNf1U+fuc QSObPrefZMTpxFxr5iWQDgUEFnLX3j7CaLtWIed/V4Hi2VHPyyJ+KH+P4EN9OJZ1Hs0H ZSdnwAhwAOZaGsxyHkFk2aSeoZabdT8khlDEsK+4Rqu94uxAQZkK53DCfajt1YO0a/bw 639m1po/o/7KPfPdIR91I14migSC1IOYTpPSmjqFybK6R4ZPR8JLz1PeMjohNefkGUhP wwar6JSyUoiFwyNfDl20Hr23XdcJv7hwsCv06FAubOb51Il7g7n/vnoT53zBielfHxzh 8pfQ== X-Gm-Message-State: AD7BkJKrN9aWIlVJ1+zWfV3agbi/3NU7nlGAF2Ahr+wbKAIYQ1/CA50EfTDmaADpqs9/jbYz X-Received: by 10.25.7.206 with SMTP id 197mr2969676lfh.107.1458222531675; Thu, 17 Mar 2016 06:48:51 -0700 (PDT) Received: from localhost.localdomain ([89.208.20.115]) by smtp.gmail.com with ESMTPSA id wj2sm1371399lbb.5.2016.03.17.06.48.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Mar 2016 06:48:50 -0700 (PDT) From: sergey.fedorov@linaro.org To: qemu-devel@nongnu.org Date: Thu, 17 Mar 2016 16:46:21 +0300 Message-Id: <1458222382-6498-5-git-send-email-sergey.fedorov@linaro.org> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1458222382-6498-1-git-send-email-sergey.fedorov@linaro.org> References: <1458222382-6498-1-git-send-email-sergey.fedorov@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::22f X-Mailman-Approved-At: Thu, 17 Mar 2016 10:44:16 -0400 Cc: Sergey Fedorov , Richard Henderson , Peter Crosthwaite , Sergey Fedorov , Paolo Bonzini Subject: [Qemu-devel] [PATCH 4/5] tcg: reorder removal from lists in tb_phys_invalidate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Paolo Bonzini First the translation block is invalidated, for which a simple write to tb->pc is enough. This means that cpu-exec will not pick up anymore the block, though it may still execute it through chained jumps. This also replaces the NULLing out of the pointer in the CPUs' local cache. Then the chained jumps are removed, meaning that CPUs will only execute the translation block once after this point. Finally, the TB is removed from the per-page list and the phys-hash bucket to clean up the data structure. This has no effect for now, but it will be the right order when tb_find_fast is moved outside the tb_lock. Signed-off-by: Paolo Bonzini Signed-off-by: Sergey Fedorov --- translate-all.c | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/translate-all.c b/translate-all.c index a1ac9841de48..1db5a914d9a3 100644 --- a/translate-all.c +++ b/translate-all.c @@ -966,40 +966,21 @@ static inline void tb_jmp_remove(TranslationBlock *tb, int n) /* invalidate one TB */ void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr) { - CPUState *cpu; PageDesc *p; unsigned int h, n1; + tb_page_addr_t pc; tb_page_addr_t phys_pc; TranslationBlock *tb1, *tb2; - /* remove the TB from the hash list */ - phys_pc = tb->page_addr[0] + (tb->pc & ~TARGET_PAGE_MASK); - h = tb_phys_hash_func(phys_pc); - tb_hash_remove(&tcg_ctx.tb_ctx.tb_phys_hash[h], tb); - - /* remove the TB from the page list */ - if (tb->page_addr[0] != page_addr) { - p = page_find(tb->page_addr[0] >> TARGET_PAGE_BITS); - tb_page_remove(&p->first_tb, tb); - invalidate_page_bitmap(p); - } - if (tb->page_addr[1] != -1 && tb->page_addr[1] != page_addr) { - p = page_find(tb->page_addr[1] >> TARGET_PAGE_BITS); - tb_page_remove(&p->first_tb, tb); - invalidate_page_bitmap(p); - } - - tcg_ctx.tb_ctx.tb_invalidated_flag = 1; - - /* remove the TB from the hash list */ - h = tb_jmp_cache_hash_func(tb->pc); - CPU_FOREACH(cpu) { - if (cpu->tb_jmp_cache[h] == tb) { - cpu->tb_jmp_cache[h] = NULL; - } - } + /* First invalidate the translation block. CPUs will not use it anymore + * from their local caches. + */ + pc = tb->pc; + tb->pc = -1; - /* suppress this TB from the two jump lists */ + /* Then suppress this TB from the two jump lists. CPUs will not jump + * anymore into this translation block. + */ tb_jmp_remove(tb, 0); tb_jmp_remove(tb, 1); @@ -1017,6 +998,25 @@ void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr) } tb->jmp_first = (TranslationBlock *)((uintptr_t)tb | 2); /* fail safe */ + /* Now remove the TB from the hash list, so that tb_find_slow + * cannot find it anymore. + */ + phys_pc = tb->page_addr[0] + (pc & ~TARGET_PAGE_MASK); + h = tb_phys_hash_func(phys_pc); + tb_hash_remove(&tcg_ctx.tb_ctx.tb_phys_hash[h], tb); + + /* remove the TB from the page list */ + if (tb->page_addr[0] != page_addr) { + p = page_find(tb->page_addr[0] >> TARGET_PAGE_BITS); + tb_page_remove(&p->first_tb, tb); + invalidate_page_bitmap(p); + } + if (tb->page_addr[1] != -1 && tb->page_addr[1] != page_addr) { + p = page_find(tb->page_addr[1] >> TARGET_PAGE_BITS); + tb_page_remove(&p->first_tb, tb); + invalidate_page_bitmap(p); + } + tcg_ctx.tb_ctx.tb_phys_invalidate_count++; }