From patchwork Wed May 12 08:12:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 12253037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB911C433B4 for ; Wed, 12 May 2021 08:15:26 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2DBF1613C9 for ; Wed, 12 May 2021 08:15:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DBF1613C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=Ou4oEt/2kOJWWFepZ0KK79Op3O7Ncx2s4ljP/M0WWFI=; b=T5DDibXun+/AXG8Fj5wwd4K1LP Ifjnj1vInV6wZd8Qb7MSCALH/cYD3mPgmOWbpIycHvxoOAPPKhI7F3/mBaA9yT3l/euAe1eN0Zadw w7bCmBlCcDumKxGLlez4emWmXEZCctPWCzYvDMjdC8OXYw6Vi410DyIm9LXIZSl3cbxpql+q26GE1 Zbm5NBP0jRn6jJy9t7rta8tvxQvS+BWC6yDecgPf4z8crjmqvUEtmEWjcKduek4a7hStFChXUXPXU NWnHyrp1b25JE3slyye7RyNPSQe9jt/9Y7H8n/ndlb45A7fn9UCHRT6NnQBdkIGuWpZBF1FvDABWv FuefTnvA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgjzQ-002Iru-Kx; Wed, 12 May 2021 08:13:08 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgjzP-002Ira-4A for linux-arm-kernel@desiato.infradead.org; Wed, 12 May 2021 08:13:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=KGcfvC9JZe3LDPcgCIgj0yBnuL+eO6fxbfZAk6Ee36Y=; b=DJldQIzwdaUTneBDRsXggwkzqA v7zBzYR/4IWQ+cKdxvBURz2BuXSBk8welVMRhqhHhInNnm3jwo2ORcy/uaSFFN9HKQlpF9T9aqXwL QUEJqPDNOlOT0ogbkolRZ9JlZXqZTuRc8g7/zAmHvXGlWIosTrIt1y+hoSZMRxVDmLclp3IGeFSc6 WHMjBVmWmOvflpeCbDQl5BmPUqVQ4YEPEx6qB7uSf8L1n0kqO64lICiqX8lm/vMh9x6t+rntRiwpa VB2Cfi5deDSjwYBvFF7qoz9gbYfX9CVj0Eq2vZ28ClhPjKiiZhfiJbrYDaB94AldZZbro8buJ9dYt 9nzTSe1w==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgjzM-00ACbW-Cw for linux-arm-kernel@lists.infradead.org; Wed, 12 May 2021 08:13:05 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id CCE3D610CA; Wed, 12 May 2021 08:12:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620807183; bh=1l2aL6MQW5LUJydNXgkrG+07wfw0dHz3q3rtI8bM68c=; h=From:To:Cc:Subject:Date:From; b=XNSq1m9aPv2daYt3A1iSM4aUB1FpHHDzyOUiidhwjsxiFNYE9m6WCxlTKRW4KcVKS uaCrA5MDqjzpsL7q96yYuZq96NJlV/AZ7s2/pto438EtJgkIUkE4E/vr6w//EXFBxQ 1GT+iukc6JX38Na3RqDmYce8ih7C30DYG8ewf5wvtMDOCW8BsF1xQL9CTrRYs8WghA hv2LNGOkAOh8o7Mhol3gYEsU2pTo0riLzQTfHc+RguNtkCGfZZT3hYdv2t6ZhfvaAV hOrymnNI+a6Qa4fv0s4WU+bZ/BkBoC/ph3dZ94EjbjSXEPYx64j6y1s/WOYlz8GjLV eGkhjWPadlTRg== From: Arnd Bergmann To: Russell King Cc: Arnd Bergmann , stable@vger.kernel.org, Daniel Thompson , Marek Vasut , Nathan Chancellor , Nick Desaulniers , Ard Biesheuvel , Linus Walleij , Nicolas Pitre , Geert Uytterhoeven , Mike Rapoport , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: [PATCH] ARM: fix gcc-10 thumb2-kernel regression Date: Wed, 12 May 2021 10:12:01 +0200 Message-Id: <20210512081211.200025-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210512_011304_528694_CCB41D3F X-CRM114-Status: GOOD ( 13.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Arnd Bergmann When building the kernel wtih gcc-10 or higher using the CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y flag, the compiler picks a slightly different set of registers for the inline assembly in cpu_init() that subsequently results in a corrupt kernel stack as well as remaining in FIQ mode. If a banked register is used for the last argument, the wrong version of that register gets loaded into CPSR_c. When building in Arm mode, the arguments are passed as immediate values and the bug cannot happen. This got introduced when Daniel reworked the FIQ handling and was technically always broken, but happened to work with both clang and gcc before gcc-10 as long as they picked one of the lower registers. This is probably an indication that still very few people build the kernel in Thumb2 mode. Marek pointed out the problem on IRC, Arnd narrowed it down to this inline assembly and Russell pinpointed the exact bug. Change the constraints to force the final mode switch to use a non-banked register for the argument to ensure that the correct constant gets loaded. Another alternative would be to always use registers for the constant arguments to avoid the #ifdef that has now become more complex. Cc: # v3.18+ Cc: Daniel Thompson Reported-by: Marek Vasut Fixes: c0e7f7ee717e ("ARM: 8150/3: fiq: Replace default FIQ handler") Signed-off-by: Arnd Bergmann Acked-by: Ard Biesheuvel Reviewed-by: Linus Walleij --- arch/arm/kernel/setup.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 1a5edf562e85..73ca7797b92f 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -545,9 +545,11 @@ void notrace cpu_init(void) * In Thumb-2, msr with an immediate value is not allowed. */ #ifdef CONFIG_THUMB2_KERNEL -#define PLC "r" +#define PLC_l "l" +#define PLC_r "r" #else -#define PLC "I" +#define PLC_l "I" +#define PLC_r "I" #endif /* @@ -569,15 +571,15 @@ void notrace cpu_init(void) "msr cpsr_c, %9" : : "r" (stk), - PLC (PSR_F_BIT | PSR_I_BIT | IRQ_MODE), + PLC_r (PSR_F_BIT | PSR_I_BIT | IRQ_MODE), "I" (offsetof(struct stack, irq[0])), - PLC (PSR_F_BIT | PSR_I_BIT | ABT_MODE), + PLC_r (PSR_F_BIT | PSR_I_BIT | ABT_MODE), "I" (offsetof(struct stack, abt[0])), - PLC (PSR_F_BIT | PSR_I_BIT | UND_MODE), + PLC_r (PSR_F_BIT | PSR_I_BIT | UND_MODE), "I" (offsetof(struct stack, und[0])), - PLC (PSR_F_BIT | PSR_I_BIT | FIQ_MODE), + PLC_r (PSR_F_BIT | PSR_I_BIT | FIQ_MODE), "I" (offsetof(struct stack, fiq[0])), - PLC (PSR_F_BIT | PSR_I_BIT | SVC_MODE) + PLC_l (PSR_F_BIT | PSR_I_BIT | SVC_MODE) : "r14"); #endif }