Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3901898pxv; Mon, 28 Jun 2021 16:10:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLsr/yrHpTFrhgV0zMzOCqLb+bcL69erY9Nb42XL/Y/is7KxPED+i+h7lbqVea1vX3BX22 X-Received: by 2002:a17:906:8aaf:: with SMTP id mu47mr25827274ejc.195.1624921853926; Mon, 28 Jun 2021 16:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624921853; cv=none; d=google.com; s=arc-20160816; b=fLRfDmLy/KlpEw2KTJzUBAqWxU4UPywQfU7B90v0ku3x1JRiMU+UOotun2RC80udQG 1me9PRwo7DfvmxG820RMX3NBak7p+V40kSvtTHqx2C/sQl7R2oWJfVB2K8LO0NubOrhz n4LIPdq7na4vKbiUE5ptsqZZ7fTVxz316xYWYElMVz1bJ+JS5/DOQe+pF6PSZNiNbTqL 2hTxmR7kxvMxtttd9c8wQeH0PC2fqkWP8U87WQs8AWHI6cXKfNuMUImYBvqMO89hrulp e+wapj/UwgZsTsbPSHhLkLi30Cnqs82rBOfLCMpEVPJaeTyaC0H6MuACh//INdpYrGeV f5tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pDLAZNUtZS+Ebm8ySuczZQ0kp6US3P076lVDAIGRTxo=; b=onCyQFo3IKZ2gGP8kjzL2E0xv7+IyA/y1AMkIhtzxaEsiSh0VusFMQD/oazHIH0rrt /xJk3p0TJG2HhkUXPhInb6oylGRpUxnO6LhTnqcpLJeu57mQfRNQv7ft+Rx5edmRpz7c 5jAT6eMGeOlk83M7bgZ8lsC0REvdq3O+ZAE5JKQWfk041WHUlVAdrDyWM13a7qKw5GFs z1cQ7JYSBSqn55Q4yddlWSvPsWsBXyQykISzXhcQrMkFfm5EwMnP86kUd96ABggRIsfP Bb/zXwBI3+0QvUkVP4LDgRZBZAPHfsE2abH4hqUQSb4VH0BmpubAEQ+pwWT5gAPkCegP E0nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tqJ5i1HR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a8si15272050edx.42.2021.06.28.16.10.27; Mon, 28 Jun 2021 16:10:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tqJ5i1HR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234658AbhF1Pay (ORCPT + 99 others); Mon, 28 Jun 2021 11:30:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:39696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237288AbhF1PFg (ORCPT ); Mon, 28 Jun 2021 11:05:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3FF1661D69; Mon, 28 Jun 2021 14:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891415; bh=M/eZB3HtLGlWINjgA55EZF33v/2G8dDTM9N+yg3DodU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tqJ5i1HR5tLnvRrsQeLNy1VOmMLYYhMB/oULhjGLCIuqt2jZ+sJJ1GBRWlya+PmWK Cyss47wfapvGPMPGa37vQOIpiahDqNEp17btUpIGtjwreNJzYljeTiaI8qdk4odxsQ 2oRV/186DKP9w03JJe2/kBXM1OZbwENDSXQJkjPUPC0YYaJIMUG2NeMPdu4SH6gJpN 5sEkzLF9luxjjEP7DgvoU1A3oXJmvDXp5pKB1ZbjtR9TDA7n280sLd/1DThXqp7Clr WS2Itguezpi4bXlU9dnX++t5mJfwmqGyxUAoTEiSLlvoTmKTSOpy6AV1fWpDxjzTD/ 9uTI+8gfnpTOQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Arnd Bergmann , Daniel Thompson , Marek Vasut , Ard Biesheuvel , Russell King , Greg Kroah-Hartman Subject: [PATCH 4.4 43/57] ARM: 9081/1: fix gcc-10 thumb2-kernel regression Date: Mon, 28 Jun 2021 10:42:42 -0400 Message-Id: <20210628144256.34524-44-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628144256.34524-1-sashal@kernel.org> References: <20210628144256.34524-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.4.274-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.4.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.4.274-rc1 X-KernelTest-Deadline: 2021-06-30T14:42+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann commit dad7b9896a5dbac5da8275d5a6147c65c81fb5f2 upstream. 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 Acked-by: Ard Biesheuvel Fixes: c0e7f7ee717e ("ARM: 8150/3: fiq: Replace default FIQ handler") Signed-off-by: Arnd Bergmann Signed-off-by: Russell King Signed-off-by: Greg Kroah-Hartman --- 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 e9c3d38d995d..ad72e83e11d1 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -479,9 +479,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 /* @@ -503,15 +505,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 } -- 2.30.2