From patchwork Mon Mar 26 13:36:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 132403 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp3860324ljb; Mon, 26 Mar 2018 06:43:57 -0700 (PDT) X-Google-Smtp-Source: AG47ELvCuEfCVSNMpyKEQxrzcuzJLeiAWxtiRvSw4vjfCQJa0S/J3X/S4D1F1l0tSR6BQ0Ukwdvj X-Received: by 10.55.166.215 with SMTP id p206mr56830279qke.312.1522071836965; Mon, 26 Mar 2018 06:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522071836; cv=none; d=google.com; s=arc-20160816; b=B9B92Ss5lotjpz9s1MGuuiqo11UiEs9UR1TmMWuZFECBL430EEqIAkgE4GuN6/X2hH YSt+wFRbnG8UfYu5Lnzz0j/a8xqfsqOnFL0R9eC6Bdg3dlglCTNhU0/LlS3eKyOOJuil 0pb8SxYUphXcsiWE5AubKsAGtp/3ek0h2tUNcZhs/+1kno+whI9nE+RtWrkSPc+8wKIA X1tP+24JgdcdxvPXb8jaKJClfAmLB99YM0uSE77Jk9CjP2KwTEhlrd9HO217bE3bVNke IYmA/4zVvKJj6gqXvQKpbKBKjwav7WX7mObKGgDhruKInGcGq6JVHY4wAQCRqcdaYmJN VeVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=qL2bgJJbnk3TW1qAwN/FJhCE59hJkf/wNPD7z2Wp0EU=; b=d1woe4Dqzb15nFYy8vUalc7jRBSE63BM0rHWd2sEOdq4DrizvGtUoFhtzc21lEgfO8 1syKfgD6sVl+uAQRmsDozUZd5gToH9HV8o/HzZlAP8c5zSzbiwEGcb6vLjxQ/7T/quoW 04zmG4lFmT4LwyKztuYbanO7uPmU8PBMikjDduApRk5VAtOEOTl6mx0ugvgBMdUm1EIc uyurgq+g54VdIiFKwL4tAObeekuINR4/9WYjQCLopuacfgV/HwkFIGBO6j/kTue0oQul DuAzL8qilVbMzDm4ayDFxTzgikj6/4teoU1IATSYrqwfPCC9+3uSkRm1Q+vmuiapxa3M MPYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=n6ls8pmd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o3si304433qto.302.2018.03.26.06.43.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 26 Mar 2018 06:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=n6ls8pmd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:56833 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0SPk-0004Kq-B3 for patch@linaro.org; Mon, 26 Mar 2018 09:43:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0SJ6-0006eF-3G for qemu-devel@nongnu.org; Mon, 26 Mar 2018 09:37:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0SJ3-00070R-Ce for qemu-devel@nongnu.org; Mon, 26 Mar 2018 09:37:04 -0400 Received: from mail-wr0-x22f.google.com ([2a00:1450:400c:c0c::22f]:42063) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f0SJ3-0006zw-5g for qemu-devel@nongnu.org; Mon, 26 Mar 2018 09:37:01 -0400 Received: by mail-wr0-x22f.google.com with SMTP id s18so18939419wrg.9 for ; Mon, 26 Mar 2018 06:37:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=qL2bgJJbnk3TW1qAwN/FJhCE59hJkf/wNPD7z2Wp0EU=; b=n6ls8pmdrBe8qB78YLccMLzD/C8abC8XUNIR7783RoQRH6+Lk2/ZJttWLpQBt092Vk ifUtmuW7FrFsVkFV3UxYkDUTAcAzhGKossolRZBZ1DErkWk6x28FdGpnDmQEXDbzPF9G UW5FPrnJz6pIcg39hBkQ8A2PqcbxE/fRJR0Fc5c0juv+w0xLEhjfFJ/rLNx6nUkTTgWb wnkFkE7N9ABAkfexvw1U3l7m0Rdp7oGbOy8wj80hWlZSfaWlL1iYSECTvfoUy5kYdrfU t/bg8j366Habf/SwX/tHdBR5hw3A6fE2AHQ4U+oveTlGGcZaq6Fb/g8l4yypv4dk/vtM 7STw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=qL2bgJJbnk3TW1qAwN/FJhCE59hJkf/wNPD7z2Wp0EU=; b=KNzzuXw1EPRFfqi9/WmP/tzPPoEzhLj+kbMK5PrAqBYPSPSg2FB2KKaT/lTDE4/U+D N5MtyveBKEEwAVObjuHc31qjwtLZKw3jNX1Q8ZhiaykojmDpZpwQ7C4v34O61h4suCtC 8WLgKAzXU9d92icg/Ljz0Jakv0UC3Rxm1ABOEWXWR5fPPovHzhpuhTuqsNcmqFvvyE0o qWVB6v//2Y1fcqZm+c8L9Ayw7r9omYg/YNMmgf0ldPgOQV5SSyeakH8MTUOEBzpKJNXr s/ojIL9sW5NHc0d9F8vNK6D3P7xQAjhbgYy4jDIYRwdgPH6dPj2S3AB6k1r3J3HI5isX gp9g== X-Gm-Message-State: AElRT7EHOpFGeKQm8fBv/mUTQ8LZgPOOYrm8Bq4w+AOxPY3gsIux/9I7 Ee47+PIPpWwXx8w8P79eQk4xg090 X-Received: by 10.223.176.7 with SMTP id f7mr30161240wra.257.1522071419662; Mon, 26 Mar 2018 06:36:59 -0700 (PDT) Received: from 640k.lan (94-36-194-48.adsl-ull.clienti.tiscali.it. [94.36.194.48]) by smtp.gmail.com with ESMTPSA id g186sm6710105wmd.41.2018.03.26.06.36.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Mar 2018 06:36:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 26 Mar 2018 15:36:38 +0200 Message-Id: <1522071403-52486-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1522071403-52486-1-git-send-email-pbonzini@redhat.com> References: <1522071403-52486-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22f Subject: [Qemu-devel] [PULL 11/16] tcg: Really fix cpu_io_recompile X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson We have confused the number of instructions that have been executed in the TB with the number of instructions needed to repeat the I/O instruction. We have used cpu_restore_state_from_tb, which means that the guest pc is pointing to the I/O instruction. The only time the answer to the later question is not 1 is when MIPS or SH4 need to re-execute the branch for the delay slot as well. We must rely on cpu->cflags_next_tb to generate the next TB, as otherwise we have a race condition with other guest cpus within the TB cache. Fixes: 0790f86861079b1932679d0f011e431aaf4ee9e2 Signed-off-by: Richard Henderson Message-Id: <20180319031545.29359-1-richard.henderson@linaro.org> Tested-by: Pavel Dovgalyuk Signed-off-by: Paolo Bonzini --- accel/tcg/translate-all.c | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) -- 1.8.3.1 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 5ad1b91..d419060 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1728,8 +1728,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) CPUArchState *env = cpu->env_ptr; #endif TranslationBlock *tb; - uint32_t n, flags; - target_ulong pc, cs_base; + uint32_t n; tb_lock(); tb = tb_find_pc(retaddr); @@ -1737,44 +1736,33 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) cpu_abort(cpu, "cpu_io_recompile: could not find TB for pc=%p", (void *)retaddr); } - n = cpu->icount_decr.u16.low + tb->icount; cpu_restore_state_from_tb(cpu, tb, retaddr); - /* Calculate how many instructions had been executed before the fault - occurred. */ - n = n - cpu->icount_decr.u16.low; - /* Generate a new TB ending on the I/O insn. */ - n++; + /* On MIPS and SH, delay slot instructions can only be restarted if they were already the first instruction in the TB. If this is not the first instruction in a TB then re-execute the preceding branch. */ + n = 1; #if defined(TARGET_MIPS) - if ((env->hflags & MIPS_HFLAG_BMASK) != 0 && n > 1) { + if ((env->hflags & MIPS_HFLAG_BMASK) != 0 + && env->active_tc.PC != tb->pc) { env->active_tc.PC -= (env->hflags & MIPS_HFLAG_B16 ? 2 : 4); cpu->icount_decr.u16.low++; env->hflags &= ~MIPS_HFLAG_BMASK; + n = 2; } #elif defined(TARGET_SH4) if ((env->flags & ((DELAY_SLOT | DELAY_SLOT_CONDITIONAL))) != 0 - && n > 1) { + && env->pc != tb->pc) { env->pc -= 2; cpu->icount_decr.u16.low++; env->flags &= ~(DELAY_SLOT | DELAY_SLOT_CONDITIONAL); + n = 2; } #endif - /* This should never happen. */ - if (n > CF_COUNT_MASK) { - cpu_abort(cpu, "TB too big during recompile"); - } - pc = tb->pc; - cs_base = tb->cs_base; - flags = tb->flags; - tb_phys_invalidate(tb, -1); - - /* Execute one IO instruction without caching - instead of creating large TB. */ - cpu->cflags_next_tb = curr_cflags() | CF_LAST_IO | CF_NOCACHE | 1; + /* Generate a new TB executing the I/O insn. */ + cpu->cflags_next_tb = curr_cflags() | CF_LAST_IO | n; if (tb->cflags & CF_NOCACHE) { if (tb->orig_tb) { @@ -1785,11 +1773,6 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) tb_remove(tb); } - /* Generate new TB instead of the current one. */ - /* FIXME: In theory this could raise an exception. In practice - we have already translated the block once so it's probably ok. */ - tb_gen_code(cpu, pc, cs_base, flags, curr_cflags() | CF_LAST_IO | n); - /* TODO: If env->pc != tb->pc (i.e. the faulting instruction was not * the first in the TB) then we end up generating a whole new TB and * repeating the fault, which is horribly inefficient.