From patchwork Fri Oct 30 20:00:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 7529071 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8A4F0BEEA4 for ; Fri, 30 Oct 2015 20:07:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7E337207B1 for ; Fri, 30 Oct 2015 20:07:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 189232073A for ; Fri, 30 Oct 2015 20:07:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZsFvF-0004P1-5g; Fri, 30 Oct 2015 20:05:13 +0000 Received: from mail-qg0-x22a.google.com ([2607:f8b0:400d:c04::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZsFvA-0003BC-OX for linux-arm-kernel@lists.infradead.org; Fri, 30 Oct 2015 20:05:09 +0000 Received: by qgad10 with SMTP id d10so70841753qga.3 for ; Fri, 30 Oct 2015 13:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vanguardiasur_com_ar.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=sYYCMENZyWZfb8j37tn5FBHuhzEtWPJv6nluNyu/AGQ=; b=DgdkeC6aVQLIGgr7YI2ZGsBq2Ac/HFUuCY7rFdHQyMo+5vlxPZl2mEnxIWA2WCAsRA ayFmxU4YrYqmvFix05CyY6x01tLuq5hSwbbPZ4qDDXLDHIcclUoWOhm7tDFouM2z+9WL OhwTVuq9apZ1aKcWW211s1GJTdQvbdII5N2pMDSXWH19pmVkhhdvgTiNzgJ9iTuIIsbe b6g5u4NNSoOnoZzB2153H10PC1NumHwE6WpHXYlMAp2jb8gpWQ8+YamtzuRf8NxEhkVS S95fM8ecMT4i8yq9zZyqaT493eWujQ33BKvMMG87a3FpSPeV+ID3G/rDo8Z3TWyHyXPF vcyQ== 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:mime-version :content-type:content-transfer-encoding; bh=sYYCMENZyWZfb8j37tn5FBHuhzEtWPJv6nluNyu/AGQ=; b=lZ0JqMSv8XPdbYIYDfGr+PSJVsVNKtTZ43Hf5q8KiYbdc4q7s669O/jB+MR04684iU m+8uGn6Ycj34mb96GDYxP/cT0LnGCLwZFZQYyaD7p+xQXANcv8pWLit8E79IwpNyOFce 40qdbFvnVtYteNkl5iwnMgD2vOGupwuKRDEeFlzZ2BoGUnbavwrJmV3PUPnS5tKiuU8z jc5KlzEKqLbH1Ate3a/ptdtj2ekKY3dy0s3tsFUZxf5JCpMvNFCJ2Ri6q1CiyBFTv1Pl goF3sda7zLACCM3P0rBMHrl5JEN7Lmszz0MGW+EYDUGh/a06HVvMJo9NZpSZBFO1LAFR ZiRA== X-Gm-Message-State: ALoCoQkGHiakAxnPpMxTIDrwWD4voE8IAveNK2/Vxfi792tSOxztclEXJgjCSkS5LBO+94lNZKhx X-Received: by 10.140.102.104 with SMTP id v95mr12667982qge.33.1446235485813; Fri, 30 Oct 2015 13:04:45 -0700 (PDT) Received: from localhost.localdomain ([190.2.108.156]) by smtp.gmail.com with ESMTPSA id t35sm3138058qge.29.2015.10.30.13.04.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Oct 2015 13:04:45 -0700 (PDT) From: Ezequiel Garcia To: , Russell King , u.kleine-koenig@pengutronix.de Subject: [PATCH v2] ARM: v7-M: Set an early stack for __v7m_setup Date: Fri, 30 Oct 2015 17:00:35 -0300 Message-Id: <1446235235-18179-1-git-send-email-ezequiel@vanguardiasur.com.ar> X-Mailer: git-send-email 2.5.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151030_130509_017299_55C0E885 X-CRM114-Status: GOOD ( 15.21 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: catalin.marinas@arm.com, Joachim Eastwood , mcoquelin.stm32@gmail.com, stefan@agner.ch, Ezequiel Garcia Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On ARM v7-M, when PROCINFO_INITFUNC (__v7m_setup) is called, a stack is needed before calling the supervisor call (SVC), which is used by the supervisor call to save the context. Currently, __v7m_setup() prepares a temporary stack in the .text.init section, which is is broken if the kernel is executing directly from read-only memory. In particular, this is the case for LPC43xx, which allows to execute the kernel in-place from a serial flash through its SPIFI controller. This commit fixes the issue by seting an early stack to its usual location. Also, __v7m_setup() is currently saving and restoring the previous stack. That was bogus, because there's no stack previously set, so this commit removes it. Signed-off-by: Ezequiel Garcia Acked-by: Uwe Kleine-König --- Unless there are any further comments, I'll be pushing this into Russell's tracker. arch/arm/mm/proc-v7m.S | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/arch/arm/mm/proc-v7m.S b/arch/arm/mm/proc-v7m.S index 67d9209077c6..7229d8d0be1a 100644 --- a/arch/arm/mm/proc-v7m.S +++ b/arch/arm/mm/proc-v7m.S @@ -12,6 +12,7 @@ */ #include #include +#include #include #include "proc-macros.S" @@ -97,19 +98,19 @@ __v7m_setup: mov r5, #0x00800000 str r5, [r0, V7M_SCB_SHPR3] @ set PendSV priority - @ SVC to run the kernel in this mode + @ SVC to switch to handler mode. Notice that this requires sp to + @ point to writeable memory because the processor saves + @ some registers to the stack. badr r1, 1f ldr r5, [r12, #11 * 4] @ read the SVC vector entry str r1, [r12, #11 * 4] @ write the temporary SVC vector entry mov r6, lr @ save LR - mov r7, sp @ save SP - ldr sp, =__v7m_setup_stack_top + ldr sp, =init_thread_union + THREAD_START_SP cpsie i svc #0 1: cpsid i str r5, [r12, #11 * 4] @ restore the original SVC vector entry mov lr, r6 @ restore LR - mov sp, r7 @ restore SP @ Special-purpose control register mov r1, #1 @@ -123,11 +124,6 @@ __v7m_setup: ret lr ENDPROC(__v7m_setup) - .align 2 -__v7m_setup_stack: - .space 4 * 8 @ 8 registers -__v7m_setup_stack_top: - define_processor_functions v7m, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1 .section ".rodata"