From patchwork Fri Oct 16 13:57:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 55118 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lf0-f72.google.com (mail-lf0-f72.google.com [209.85.215.72]) by patches.linaro.org (Postfix) with ESMTPS id 2D29B22EAC for ; Fri, 16 Oct 2015 14:28:14 +0000 (UTC) Received: by lffy185 with SMTP id y185sf18686783lff.2 for ; Fri, 16 Oct 2015 07:28:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=ruUg65c2k+hCt22QLR3EjunyTWVfDZ69saCgTeXhSHA=; b=iT5PAU2fr9pjX827eZUMrQ8fOJqkzPy5gbo3gAqPwvcx3UAO31uVjwgW3Fo4QPQZny 5K/cWbsdkNXTK6bMFASGx2R5I30zsTx0Hl7uYEld3EYLGHqS1TNszDueKIOmgboTvn5u SH+We6xu3ZsjGfi+GfHbel37+2MaAFdgNDGsQBeFdC02b6z3qhZvRTKmT9sNzZeUZ7pR /m4DjfLMujW7mfT0zOT7W5/xoYjOExuyi1MLi2tpjnr8BmdlmgPGYKAz1GlJcwvJ2Ast 8qcP5SeOJBglO8H9pp825Nm3OyfLHjrMfo3ixYjPyKUoXcwb7WrOhtF6NCoTwcnZWK9W Rghw== X-Gm-Message-State: ALoCoQlBPU6BmwtqhC8GnJ8SiSvPbkw+qH0IcF2/oLnzqh5qGOEP6qnJuF3DmXPSoTte4mt0VgFi X-Received: by 10.180.10.135 with SMTP id i7mr1224296wib.2.1445005692977; Fri, 16 Oct 2015 07:28:12 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.218.207 with SMTP id r198ls323747lfg.40.gmail; Fri, 16 Oct 2015 07:28:12 -0700 (PDT) X-Received: by 10.112.62.232 with SMTP id b8mr8322729lbs.27.1445005692808; Fri, 16 Oct 2015 07:28:12 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id p19si13095997lfe.43.2015.10.16.07.28.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Oct 2015 07:28:12 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by lbbwb3 with SMTP id wb3so40334622lbb.1 for ; Fri, 16 Oct 2015 07:28:12 -0700 (PDT) X-Received: by 10.112.64.72 with SMTP id m8mr8244357lbs.41.1445005692284; Fri, 16 Oct 2015 07:28:12 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1326184lbq; Fri, 16 Oct 2015 07:28:11 -0700 (PDT) X-Received: by 10.55.201.16 with SMTP id q16mr19663066qki.6.1445005691087; Fri, 16 Oct 2015 07:28:11 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 15si6063899qgx.123.2015.10.16.07.28.10 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 16 Oct 2015 07:28:11 -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; Received: from localhost ([::1]:53909 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn5gj-0007pt-B6 for patch@linaro.org; Fri, 16 Oct 2015 10:08:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn5WP-000230-QF for qemu-devel@nongnu.org; Fri, 16 Oct 2015 09:58:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zn5WO-0000nu-GP for qemu-devel@nongnu.org; Fri, 16 Oct 2015 09:58:13 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:35158) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn5WO-0000ht-9K for qemu-devel@nongnu.org; Fri, 16 Oct 2015 09:58:12 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Zn5WJ-0003m4-K0 for qemu-devel@nongnu.org; Fri, 16 Oct 2015 14:58:07 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 16 Oct 2015 14:57:56 +0100 Message-Id: <1445003887-14475-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1445003887-14475-1-git-send-email-peter.maydell@linaro.org> References: <1445003887-14475-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 02/13] target-arm: Break the TB after ISB to execute self-modified code correctly 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Sergey Sorokin If any store instruction writes the code inside the same TB after this store insn, the execution of the TB must be stopped to execute new code correctly. As described in ARMv8 manual D3.4.6 self-modifying code must do an IC invalidation to be valid, and an ISB after it. So it's enough to end the TB after ISB instruction on the code translation. Also this TB break is necessary to take any pending interrupts immediately after an ISB (as required by ARMv8 ARM D1.14.4). Signed-off-by: Sergey Sorokin [PMM: tweaked commit message and comments slightly] Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- target-arm/helper.c | 6 +++++- target-arm/translate-a64.c | 8 +++++++- target-arm/translate.c | 17 +++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/target-arm/helper.c b/target-arm/helper.c index 584f6df..b498670 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -657,8 +657,12 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { { .name = "MVA_prefetch", .cp = 15, .crn = 7, .crm = 13, .opc1 = 0, .opc2 = 1, .access = PL1_W, .type = ARM_CP_NOP }, + /* We need to break the TB after ISB to execute self-modifying code + * correctly and also to take any pending interrupts immediately. + * So use arm_cp_write_ignore() function instead of ARM_CP_NOP flag. + */ { .name = "ISB", .cp = 15, .crn = 7, .crm = 5, .opc1 = 0, .opc2 = 4, - .access = PL0_W, .type = ARM_CP_NOP }, + .access = PL0_W, .type = ARM_CP_NO_RAW, .writefn = arm_cp_write_ignore }, { .name = "DSB", .cp = 15, .crn = 7, .crm = 10, .opc1 = 0, .opc2 = 4, .access = PL0_W, .type = ARM_CP_NOP }, { .name = "DMB", .cp = 15, .crn = 7, .crm = 10, .opc1 = 0, .opc2 = 5, diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c index e65e309..a4580c0 100644 --- a/target-arm/translate-a64.c +++ b/target-arm/translate-a64.c @@ -1230,9 +1230,15 @@ static void handle_sync(DisasContext *s, uint32_t insn, return; case 4: /* DSB */ case 5: /* DMB */ - case 6: /* ISB */ /* We don't emulate caches so barriers are no-ops */ return; + case 6: /* ISB */ + /* We need to break the TB after this insn to execute + * a self-modified code correctly and also to take + * any pending interrupts immediately. + */ + s->is_jmp = DISAS_UPDATE; + return; default: unallocated_encoding(s); return; diff --git a/target-arm/translate.c b/target-arm/translate.c index 22c3587..1273000 100644 --- a/target-arm/translate.c +++ b/target-arm/translate.c @@ -7720,10 +7720,16 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn) return; case 4: /* dsb */ case 5: /* dmb */ - case 6: /* isb */ ARCH(7); /* We don't emulate caches so these are a no-op. */ return; + case 6: /* isb */ + /* We need to break the TB after this insn to execute + * self-modifying code correctly and also to take + * any pending interrupts immediately. + */ + gen_lookup_tb(s); + return; default: goto illegal_op; } @@ -10030,9 +10036,16 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw break; case 4: /* dsb */ case 5: /* dmb */ - case 6: /* isb */ /* These execute as NOPs. */ break; + case 6: /* isb */ + /* We need to break the TB after this insn + * to execute self-modifying code correctly + * and also to take any pending interrupts + * immediately. + */ + gen_lookup_tb(s); + break; default: goto illegal_op; }