From patchwork Thu Jun 29 07:52:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pranith Kumar X-Patchwork-Id: 9816191 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B550B603F2 for ; Thu, 29 Jun 2017 07:53:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEF0128536 for ; Thu, 29 Jun 2017 07:53:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A397C28675; Thu, 29 Jun 2017 07:53:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 3448F28654 for ; Thu, 29 Jun 2017 07:53:43 +0000 (UTC) Received: from localhost ([::1]:37464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQUGk-0006Hk-Aq for patchwork-qemu-devel@patchwork.kernel.org; Thu, 29 Jun 2017 03:53:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQUFs-0006H8-VJ for qemu-devel@nongnu.org; Thu, 29 Jun 2017 03:52:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQUFr-0005wR-WF for qemu-devel@nongnu.org; Thu, 29 Jun 2017 03:52:49 -0400 Received: from mail-yb0-x243.google.com ([2607:f8b0:4002:c09::243]:33050) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQUFr-0005wK-Qw for qemu-devel@nongnu.org; Thu, 29 Jun 2017 03:52:47 -0400 Received: by mail-yb0-x243.google.com with SMTP id 84so3588645ybe.0 for ; Thu, 29 Jun 2017 00:52:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dY5i51aDNY3E09hgtGCbJ2+uQFOT5W+QyFrVQJnyfaQ=; b=tpA9BmyxwAbegfPZ++uLmZUFwvTUPeYLo2DLPEwYKnQm4in7F4twm3plLOpA8u91Al gD8Mxt2tXB+TzVXGIJQiueUzEzf6D1TzSF7RlwFO9ZJt+AE41rYlWoDe0bmlpKXpJej1 JWvDUZccY4OEV0lGMy1xdvKEDghZjqebI2dm+u3kx70q+tIyT4yWZ1ieWPxxx1BgX1Uf pWgJkk+4Jzaix1ooqEybz7cQGy2UJwuH555z2OWduXHKY0Cp2G8ofSjl8e9qmTiZe0v4 YZDExQUdGgpJYBUCl1mFPRxDWRpWShTEH/vOVL4dh3h/SfXZc8DZvNCxQ9ZGNmoO1E8J Cb5A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=dY5i51aDNY3E09hgtGCbJ2+uQFOT5W+QyFrVQJnyfaQ=; b=fUIlToSpPu9+QHUbhljw7XXN2pHvHKYZTQXC2ISXEmb8TA3sidtgHM9PkJujkK1CLG Gi0X77Ozvg5XLh1IecIVjwONDcewuixXOqvy7xpDMMyfBbhOWP60pt/5cN4gXQ85ZJkR xgVQgex+p0lCwDIewQdTAA6ZnUja2YD9WdvYRMwgVsCeLEMhdDUP6+Tb84xxSSw6qhFc qA085I8QoAXn6I+0gBso0GF7M6w7L7IynkGGDzT+aUX/B5UZL9q6ZsB0JXBRPJ1vg114 cY09JNfk6tjIDWlLREXiZVlEUoriBmSjpHTZeTQSY9HTPQMwHdhrgAt9S3Vd+htasaCv kMFQ== X-Gm-Message-State: AKS2vOyq5LRzzQ/U6ydx9PvIxNH53t3036YdV/Bnie1+doL8lYRaqAyc O3xXlc6gtuKgKQ== X-Received: by 10.37.194.196 with SMTP id s187mr2559888ybf.65.1498722767113; Thu, 29 Jun 2017 00:52:47 -0700 (PDT) Received: from localhost.localdomain (c-73-207-178-95.hsd1.ga.comcast.net. [73.207.178.95]) by smtp.gmail.com with ESMTPSA id p189sm1816553ywb.30.2017.06.29.00.52.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 00:52:45 -0700 (PDT) From: Pranith Kumar To: alex.bennee@linaro.org Date: Thu, 29 Jun 2017 03:52:42 -0400 Message-Id: <20170629075243.26984-3-bobby.prani@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170629075243.26984-1-bobby.prani@gmail.com> References: <20170629075243.26984-1-bobby.prani@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4002:c09::243 Subject: [Qemu-devel] [PATCH v2 2/3] tcg/aarch64: Use ADRP+ADD to compute target address 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: qemu-devel@nongnu.org, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We use ADRP+ADD to compute the target address for goto_tb. This patch introduces the NOP instruction which is used to align the above instruction pair so that we can use one atomic instruction to patch the destination offsets. CC: Richard Henderson CC: Alex Bennée Signed-off-by: Pranith Kumar --- accel/tcg/translate-all.c | 2 +- tcg/aarch64/tcg-target.inc.c | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index f6ad46b613..b6d122e087 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -522,7 +522,7 @@ static inline PageDesc *page_find(tb_page_addr_t index) #elif defined(__powerpc__) # define MAX_CODE_GEN_BUFFER_SIZE (32u * 1024 * 1024) #elif defined(__aarch64__) -# define MAX_CODE_GEN_BUFFER_SIZE (128ul * 1024 * 1024) +# define MAX_CODE_GEN_BUFFER_SIZE (3ul * 1024 * 1024 * 1024) #elif defined(__s390x__) /* We have a +- 4GB range on the branches; leave some slop. */ # define MAX_CODE_GEN_BUFFER_SIZE (3ul * 1024 * 1024 * 1024) diff --git a/tcg/aarch64/tcg-target.inc.c b/tcg/aarch64/tcg-target.inc.c index 8fce11ace7..b7670ecc90 100644 --- a/tcg/aarch64/tcg-target.inc.c +++ b/tcg/aarch64/tcg-target.inc.c @@ -372,6 +372,7 @@ typedef enum { I3510_EON = 0x4a200000, I3510_ANDS = 0x6a000000, + NOP = 0xd503201f, /* System instructions. */ DMB_ISH = 0xd50338bf, DMB_LD = 0x00000100, @@ -866,10 +867,18 @@ static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *target) void aarch64_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr) { tcg_insn_unit *code_ptr = (tcg_insn_unit *)jmp_addr; - tcg_insn_unit *target = (tcg_insn_unit *)addr; + tcg_insn_unit adrp_insn = *code_ptr++; + tcg_insn_unit addi_insn = *code_ptr; - reloc_pc26_atomic(code_ptr, target); - flush_icache_range(jmp_addr, jmp_addr + 4); + ptrdiff_t offset = (addr >> 12) - (jmp_addr >> 12); + + /* patch ADRP */ + adrp_insn = deposit32(adrp_insn, 29, 2, offset & 0x3); + adrp_insn = deposit32(adrp_insn, 5, 19, offset >> 2); + /* patch ADDI */ + addi_insn = deposit32(addi_insn, 10, 12, addr & 0xfff); + atomic_set((uint64_t *)jmp_addr, adrp_insn | ((uint64_t)addi_insn << 32)); + flush_icache_range(jmp_addr, jmp_addr + 8); } static inline void tcg_out_goto_label(TCGContext *s, TCGLabel *l) @@ -1388,10 +1397,17 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, #endif /* consistency for USE_DIRECT_JUMP */ tcg_debug_assert(s->tb_jmp_insn_offset != NULL); + /* Ensure that ADRP+ADD are 8-byte aligned so that an atomic + write can be used to patch the target address. */ + if ((uintptr_t)s->code_ptr & 7) { + tcg_out32(s, NOP); + } s->tb_jmp_insn_offset[a0] = tcg_current_code_size(s); /* actual branch destination will be patched by - aarch64_tb_set_jmp_target later, beware retranslation. */ - tcg_out_goto_noaddr(s); + aarch64_tb_set_jmp_target later, beware of retranslation */ + tcg_out_insn(s, 3406, ADRP, TCG_REG_TMP, 0); + tcg_out_insn(s, 3401, ADDI, TCG_TYPE_I64, TCG_REG_TMP, TCG_REG_TMP, 0); + tcg_out_callr(s, TCG_REG_TMP); s->tb_jmp_reset_offset[a0] = tcg_current_code_size(s); break;