From patchwork Fri Aug 12 08:19:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 9276573 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 CC57360231 for ; Fri, 12 Aug 2016 08:19:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD5CB288BB for ; Fri, 12 Aug 2016 08:19:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B16322890A; Fri, 12 Aug 2016 08:19:53 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A353288BB for ; Fri, 12 Aug 2016 08:19:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752353AbcHLITn (ORCPT ); Fri, 12 Aug 2016 04:19:43 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:33833 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752447AbcHLITk (ORCPT ); Fri, 12 Aug 2016 04:19:40 -0400 Received: by mail-pa0-f66.google.com with SMTP id hh10so1131270pac.1; Fri, 12 Aug 2016 01:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=R/ogtxdvflwgjQIi6yn13Bce8UuVs+VM8yLw6sJy1hw=; b=VkNhGOh0VCpkL45dynGri5PgAR35J72CMq1boQVjCKbR/wTRpYLhyg8dwHJwoIDnRP 7xhlLZyuUyav5xzY0mzR4v6JXVstH15Hy/9R3B2e1cdhUh596Z+RrDGEQ72ygDuwWXsd 6esCFpcQNUqez5jxgulTme8uMxxqyQ/wEJ52qa7wS7HzpnPtI/PUR3+FpTBArkmplzjS Mtvwi4aYZMZis+m5ssf0TXAo26iZERChtZPEC33evgCq4ZK0RZD+eOAEfz6DNbNt2mxg JS0ETQ06osZ3lks+4lm23T/WOebeeeZhY8Si544MXlykOBXbI5DwIttjdAYD82osfSt5 AklA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=R/ogtxdvflwgjQIi6yn13Bce8UuVs+VM8yLw6sJy1hw=; b=Irdds6cRrUKU+hPLhb6zozwduTyVkPEqhS/A8StYxFCpx+rIeRp0k/YeZuRTz9f9G8 n8/nTbVPhlL5u1RLjtOjRQJLsaMZs2NPMKtXNzOXRLfIfHdGIoiBA2C0+85DQ7WVvadJ 7mMKJ+YLhY4WzsriRruTfwqdCRJ4OCZuXU1xr0MWGn6CLkQwpy1QUDINvzI8wf0fsQeC wGmRQuOaqMPjzCioz6p6nGS9N7NBDKjmL5BNCmgGoXZfocrXxJc6o3jDofTX0zbRJciq 8CLVvjucz6uYs4zUiVhk0aC6xzc4DlVwzIQFOqsUe1UwlwvM7xGAgKF84XMtlUSt1Lii mvPw== X-Gm-Message-State: AEkoouuL0X91e1jYuxiOb/Plu1hDXwBZlfc0fDV4978g0Q5anW/GcFMyd/HxRC2dLKpdKA== X-Received: by 10.66.127.38 with SMTP id nd6mr25121706pab.74.1470989979648; Fri, 12 Aug 2016 01:19:39 -0700 (PDT) Received: from roar.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id fj19sm10719046pab.37.2016.08.12.01.19.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Aug 2016 01:19:38 -0700 (PDT) From: Nicholas Piggin To: linux-arm-kernel@lists.infradead.org, Russell King Cc: Nicholas Piggin , linux-kbuild@vger.kernel.org, Arnd Bergmann , Nicolas Pitre , Julian Brown , Alan Modra , Segher Boessenkool , linux-arch@vger.kernel.org, Michal Marek , Sam Ravnborg , Stephen Rothwell Subject: [PATCH] arm: add an option for erratum 657417 Date: Fri, 12 Aug 2016 18:19:17 +1000 Message-Id: <1470989957-23671-1-git-send-email-npiggin@gmail.com> X-Mailer: git-send-email 2.8.1 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Erratum 657417 is worked around by the linker by inserting additional branch trampolines to avoid problematic branch target locations. This results in much higher linking time and presumably slower and larger generated code. The workaround also seems to only be required when linking thumb2 code, but the linker applies it for non-thumb2 code as well. The workaround today is left to the linker to apply, which is overly conservative. https://sourceware.org/ml/binutils/2009-05/msg00297.html This patch adds an option which defaults to "y" in cases where we could possibly be running Cortex A8 and using Thumb2 instructions. In reality the workaround might not be required at all for the kernel if virtual instruction memory is linear in physical memory. However it is more conservative to keep the workaround, and it may be the case that the TLB lookup would be required in order to catch branches to unmapped or no-execute pages. In an allyesconfig build, this workaround causes a large load on the linker's branch stub hash and slows down the final link by a factor of 5. Signed-off-by: Nicholas Piggin --- arch/arm/Kconfig | 14 ++++++++++++++ arch/arm/Makefile | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 90542db..3c7dde1 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1033,6 +1033,20 @@ config ARM_ERRATA_460075 ACTLR register. Note that setting specific bits in the ACTLR register may not be available in non-secure mode. +config ARM_ERRATA_657417 + bool "ARM errata: A 32-bit branch instruction that spans two 4K regions can result in an incorrect operation" + depends on CPU_V7 + depends on THUMB2_KERNEL + default y + help + This option enables the workaround for the 657417 Cortex-A8 erratum. + If, while executing code in Thumb or ThumbEE state, a 32-bit Thumb-2 + branch instruction is executed that spans two 4KB regions, and the + target address of the branch falls within the first region, it is + possible for the processor to behave incorrectly. This workaround + enables a linker workaround that adds branch trampolines that bounce + offending branches via a safe location. + config ARM_ERRATA_742230 bool "ARM errata: DMB operation may be faulty" depends on CPU_V7 && SMP diff --git a/arch/arm/Makefile b/arch/arm/Makefile index 274e8a6..b49a2e0 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -43,6 +43,13 @@ ifeq ($(CONFIG_FRAME_POINTER),y) KBUILD_CFLAGS +=-fno-omit-frame-pointer -mapcs -mno-sched-prolog endif +ifneq ($(CONFIG_ARM_ERRATA_657417),y) +# ld-option has to run before we override LD otherwise it fails on +# cross compile with mismatched endian (C compiler outputs one endian, +# LD accepts another) +LDFLAGS +=$(call ld-option, --no-fix-cortex-a8,) +endif + ifeq ($(CONFIG_CPU_BIG_ENDIAN),y) KBUILD_CPPFLAGS += -mbig-endian AS += -EB