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: 435462 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp4602805jao; Wed, 12 May 2021 01:13:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhIGeXF/PZvvxa6o3FMb+x3to6BzmYKPua4Vvj5brLrTgXwBmO+5COOHo69ab/8gYWBsEn X-Received: by 2002:a05:6638:1650:: with SMTP id a16mr30689038jat.23.1620807187896; Wed, 12 May 2021 01:13:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620807187; cv=none; d=google.com; s=arc-20160816; b=RXUPvuYqu8itSAf1bOtblv6O99/ZW0Fyhhw/esGrUKe+34flPwu/8lAr0ta1VdXUFS HPYuKBEl0Hjbsb8lR3hlKixcWUTnII+3CJro6jL2w7SRXijH0J8WvGkF4apqpaGRTi2Y TLXPhAnyC31z1HJvFBUhLEh/jlM1df6Bq/FJq/X+AjY9xo8pKwycLEgmg27u3OgP622Y i9VtgCv6AAjwWjw4BUQK29fY+BHlRWxZnnSTiucvp8cR0zdebMEm7lYL8hjUPqGb8MA4 m4x64zgGcwmCTCdGnYEzFpc3E8F/zGCIz54D0h1mqPQiXlKkF4kLszGtbq3B1DoisSfP XZlg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=KGcfvC9JZe3LDPcgCIgj0yBnuL+eO6fxbfZAk6Ee36Y=; b=cPfha8/9jmOLXjr9f7TbwUmRAXOLAsK0nLHgD/jzeG4sOo0gJRsFpb8igrkOQgdqQE oZp9S4lpqOKokVNUrFIWpJnUyWwfLY3YkanLGRpu2bvmp6xiNyWtl80KJQgIikJTEefI Dn9XBp9fWmwS4hJKc5UwuEG8sXs6xpo/o4t3TRjNuRQtfFOnfdqRhCEOuLrBa6foSM5K F+DpgTL278eSywzW09Sn2MxiHXxKghaHCZDEXses7o4TG+iGJlF4AVHhB47QyoLcppod EHW9ryHJasrg9DAKiBhXtYw4IwhevKSJmIU4giyhUVQXXcFwtr1bRaTlEC8X8gbp8zJI mtsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XNSq1m9a; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 r14si17330795iod.2.2021.05.12.01.13.07; Wed, 12 May 2021 01:13:07 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=XNSq1m9a; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S230218AbhELION (ORCPT + 12 others); Wed, 12 May 2021 04:14:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:60922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230026AbhELIOL (ORCPT ); Wed, 12 May 2021 04:14:11 -0400 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 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.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 --- arch/arm/kernel/setup.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) -- 2.29.2 Acked-by: Ard Biesheuvel Reviewed-by: Linus Walleij 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 }