From patchwork Thu Oct 29 17:31:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 7520061 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id ADF449F37F for ; Thu, 29 Oct 2015 17:37:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CAF1A2084D for ; Thu, 29 Oct 2015 17:37:46 +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 BB6A320804 for ; Thu, 29 Oct 2015 17:37:45 +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 1Zrr7G-0000uw-Ab; Thu, 29 Oct 2015 17:35:58 +0000 Received: from mail-qg0-x22f.google.com ([2607:f8b0:400d:c04::22f]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zrr7D-0000po-5E for linux-arm-kernel@lists.infradead.org; Thu, 29 Oct 2015 17:35:56 +0000 Received: by qgbb65 with SMTP id b65so40462371qgb.2 for ; Thu, 29 Oct 2015 10:35:33 -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; bh=gZUtHusKZ1xWZI/KvcgflvWFV1hLENIvJHjAq+GeZO4=; b=tFJ9PEIDjZiHEl2e6iNPJ/N85v4NsU317wnT/infcOfzTbatVvdR8zMIf0cOQt1QHg JYX7m7PTCtdZiYGyusGKOkVlkG3KtvRuAFfqOzDn9ufHbIQav3l3ISepbnP9suL10Fyi tk4Q+HFr2za310AxAoCWZIaY2B3v+VKHjUFIvxAo3wa0x3djEhS/QnvNpyyp87gpFT5h bAYUcamUZ8QAEN8Sy8kL+3sIndWmrW+5aAW5wVUilYnAieBFGkS/hIVVO/iUWelLIA0K G/39Jol1tiaROYQZ4zQM5cFlbQV7vrC0WQu0DvfXNfcKKUCYvB36TNPdoNy7WA5qxwUB Bldg== 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=gZUtHusKZ1xWZI/KvcgflvWFV1hLENIvJHjAq+GeZO4=; b=NG5b52v+Q6IEjBFJ2/SvU3BwbtxNE0H+dXFlsDuPKY4JFqU3G5wHNzrE6BoHBIkKDV 15thAKes0ubu0lkiipyzh8yACWYPk0daG7vzIupgFmHGqfFEctFZGy0lmMChczWdvCnI d4LQHkybmnDKMQNM8apsxeYU2/MvOuxw/C8/DfJ6WTm6lNx13F0kNj68obXzLyo6bRjC A86rXHv9AroTBH/uNjzmrgKT9olpK5PAgM35+kGjNaokakTVQcwhwQTz25nLllSFWN7k VhZkCE6cTnGlj9fmDw9ZhLUsXpMm8eT5OEVhi4oQfOxQToUxWxsWpKgudK9vrrEY04rC uMFg== X-Gm-Message-State: ALoCoQnQbBwooSQTFPPJ2z72xy5ZlVCuGHVSTnLo/I2fNBD7o/Xe9Jmq6pi4rBZ5xqoZUtM7rOem X-Received: by 10.140.238.214 with SMTP id j205mr4125396qhc.21.1446140133583; Thu, 29 Oct 2015 10:35:33 -0700 (PDT) Received: from localhost.localdomain ([190.2.108.156]) by smtp.gmail.com with ESMTPSA id z123sm935915qhd.15.2015.10.29.10.35.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Oct 2015 10:35:32 -0700 (PDT) From: Ezequiel Garcia To: , Russell King , u.kleine-koenig@pengutronix.de Subject: [PATCH] ARM: v7-M: Fix the stack set by __v7m_setup Date: Thu, 29 Oct 2015 14:31:20 -0300 Message-Id: <1446139880-17311-1-git-send-email-ezequiel@vanguardiasur.com.ar> X-Mailer: git-send-email 2.5.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151029_103555_576141_15F05F10 X-CRM114-Status: GOOD ( 14.73 ) 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 MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.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. This commit fixes this 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 --- As suggested by Uwe, this commit tries to set a proper stack before calling the SVC in __v7m_setup. Instead of putting that in a .data section, I'm just using the usual stack location. The stack will be reset to the same place in __mmap_switched. This means the stack is set twice in the v7-M case, but for simplicity I figure we can just leave this that way. 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..f42d4e2774c7 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 run the kernel in this mode, + @ notice that we need to set a stack for SVC to save + @ the context. 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"