From patchwork Fri Mar 16 15:53:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 131929 Delivered-To: patch@linaro.org Received: by 10.80.152.129 with SMTP id j1csp496457edb; Fri, 16 Mar 2018 08:55:31 -0700 (PDT) X-Google-Smtp-Source: AG47ELsprJ8GXADcITLlY8vNAjLdLN3k+H1dD0YHGMj4RiCtKlTBgItQ1vcUEvB7+1XQEl4pYqdl X-Received: by 10.55.42.131 with SMTP id q3mr3216474qkq.77.1521215731452; Fri, 16 Mar 2018 08:55:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521215731; cv=none; d=google.com; s=arc-20160816; b=TyLFpB5Dqz6w5v87npUnZV9KPYdM535d8pD7CpBqCV8zQVCH547PJhLZbTwv4fB1Ic LNvCP3ueAs+vlQz7V9hKasusUtFhc8D+RhmPKSQYteZZpPydCfjKmaQAcArhwjV3ExJe qPMnru3UyijQey8O3SFlTvD5fmdqHNhDVBtAeV5FzfjkJYIf9BzpRMCRIxb4K93jALrX /QmUon4kc1AXTYfKOTlCSmR01ATmyXoGlt67yOi9b/L0SzSKCC2jLAiG9JEmmTXbTSEm 4x88aZJNjhGs61T+6IHlZPc9uZxODTxAE5R9z01UGpUGoGyEY/FaPNgDAXGh3m7yXNqj vSkw== 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:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=1ITj1xLgsBt2S90I/CSe9EiSNIHIDoBoNu+Dx2I5iHA=; b=NNq7EI8bv5AY40xE4DiOwVHKAFPo2zij/NknDcg09AN33b01T41wGGc/mgzrRVd4rg j5xcp8jdmYtz/XPTxJJ2jMd8cLYZ/Zl+RBAm7U9wVPqA1+dm/5OMo/GsK3iU3O2SZEuk h5lgQ59pKUKqRfL/0MxOBAGR7oM/9+2V3z+WvqJ6wE4fELDcAoZ/n60TIhzIjqc/v+gO S9uiscihxLyf2bYx1Uffq24uqoftohWalZVs1Za83DZgw7NKHl27pu3TPWiipwlbnYBb F1eMtY2EST2q/WKRVbblTr/TmfjdGrEWSoi4IYyQTHGI/2eOBjSwfqY0geHtVyb0Oy4D puwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dinIccVB; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o127si1295085qkc.98.2018.03.16.08.55.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 16 Mar 2018 08:55:31 -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=@linaro.org header.s=google header.b=dinIccVB; 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=linaro.org Received: from localhost ([::1]:58212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewrhb-000287-1b for patch@linaro.org; Fri, 16 Mar 2018 11:55:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40918) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewrg3-0001I4-Iz for qemu-devel@nongnu.org; Fri, 16 Mar 2018 11:53:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewrfy-0006IK-OL for qemu-devel@nongnu.org; Fri, 16 Mar 2018 11:53:55 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:35238) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ewrfy-0006I5-HM for qemu-devel@nongnu.org; Fri, 16 Mar 2018 11:53:50 -0400 Received: by mail-pg0-x242.google.com with SMTP id d1so4233125pgv.2 for ; Fri, 16 Mar 2018 08:53:50 -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; bh=1ITj1xLgsBt2S90I/CSe9EiSNIHIDoBoNu+Dx2I5iHA=; b=dinIccVB4mm5R0qqU6iTVzwm5zsAuA+VFAxR3AJlZ64qLhu6mk/lkZ6KQSXguNgSsi 5mbkNJTb+VWqwZltU1K16dQ3De4L/CAxY1F+sBfN9UfUxbku8yiSwtJSDz80t+OEB54v XVA+T2cw4OgAXqwLwYkhzLKIXstDFkqeheu7E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1ITj1xLgsBt2S90I/CSe9EiSNIHIDoBoNu+Dx2I5iHA=; b=TUHCxX9ulAHeKMFV6PyfN9LfN4p3/MeKX4xZ4h3i/Yh5drsziei3HhVGcdsQs9ofzy h1dOLbZACHeIqYo+V/Q3qtEbJ0+akPKWk5MiZM55HYPX2L0/roPdkTMAV/f9HEnY3/yd j3rHkwxhOmzlkch3qGEBXdKpdABA0apEAhTxZwwY508IYGq6B2Hrz9dKLPg3fN77CFer 4XMIJtnUK8iFB7NTY8QMjIKAWAofdyvIVkP7AQLAawxGIOYGCWJushXjy8qqPbRG8dkN fdf64fOadtjeTt9Wb3pIx/tHR6xkKSOXj5/Cv5FwEWiFzXWF0TB07tSriB7BKEBFB5JF 8qqg== X-Gm-Message-State: AElRT7FxcUgejRd4HFR9XXulQBWGhuVi9kHcVGdXNin9oVujZEn9fYoz mORdcsdofuRFmX+T941P6ZO0T//8AYM= X-Received: by 10.101.100.144 with SMTP id e16mr1871289pgv.315.1521215628831; Fri, 16 Mar 2018 08:53:48 -0700 (PDT) Received: from cloudburst.twiddle.net ([182.239.85.222]) by smtp.gmail.com with ESMTPSA id l22sm15649559pfj.98.2018.03.16.08.53.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Mar 2018 08:53:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 23:53:40 +0800 Message-Id: <20180316155340.25734-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PATCH] tcg: 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: peter.maydell@linaro.org, Pavel.Dovgaluk@ispras.ru, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Richard Henderson --- accel/tcg/translate-all.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) -- 2.14.3 Reviewed-by: Philippe Mathieu-Daudé diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 67795cd78c..d4190602d1 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1736,37 +1736,32 @@ 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"); - } - /* Adjust the execution state of the next TB. */ + /* Generate a new TB executing the I/O insn. */ cpu->cflags_next_tb = curr_cflags() | CF_LAST_IO | n; if (tb->cflags & CF_NOCACHE) {