From nobody Sat Oct 25 02:31:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521215789400534.8413097626644; Fri, 16 Mar 2018 08:56:29 -0700 (PDT) Received: from localhost ([::1]:58214 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewriU-0002c9-Au for importer@patchew.org; Fri, 16 Mar 2018 11:56:26 -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) 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) 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-Google-Smtp-Source: AG47ELuKCey0B/3YinB32jjsqakRjBbYpEAX7MnX0g6UXUIASrioEN/JNNDdjs4EJQzzOYxWe42ARA== X-Received: by 10.101.100.144 with SMTP id e16mr1871289pgv.315.1521215628831; Fri, 16 Mar 2018 08:53:48 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- accel/tcg/translate-all.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) 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 reta= ddr) cpu_abort(cpu, "cpu_io_recompile: could not find TB for pc=3D%p", (void *)retaddr); } - n =3D 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 =3D 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 =3D 1; #if defined(TARGET_MIPS) - if ((env->hflags & MIPS_HFLAG_BMASK) !=3D 0 && n > 1) { + if ((env->hflags & MIPS_HFLAG_BMASK) !=3D 0 + && env->active_tc.PC !=3D tb->pc) { env->active_tc.PC -=3D (env->hflags & MIPS_HFLAG_B16 ? 2 : 4); cpu->icount_decr.u16.low++; env->hflags &=3D ~MIPS_HFLAG_BMASK; + n =3D 2; } #elif defined(TARGET_SH4) if ((env->flags & ((DELAY_SLOT | DELAY_SLOT_CONDITIONAL))) !=3D 0 - && n > 1) { + && env->pc !=3D tb->pc) { env->pc -=3D 2; cpu->icount_decr.u16.low++; env->flags &=3D ~(DELAY_SLOT | DELAY_SLOT_CONDITIONAL); + n =3D 2; } #endif - /* This should never happen. */ - if (n > CF_COUNT_MASK) { - cpu_abort(cpu, "TB too big during recompile"); - } =20 - /* Adjust the execution state of the next TB. */ + /* Generate a new TB executing the I/O insn. */ cpu->cflags_next_tb =3D curr_cflags() | CF_LAST_IO | n; =20 if (tb->cflags & CF_NOCACHE) { --=20 2.14.3