Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4257198pxj; Wed, 12 May 2021 01:16:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzmRnuD4+D5xrNRSIami8ArF7KnD0gsZDnbKxS2HNmCpgttpLJs+B1URhHdh6cr8caDTPH X-Received: by 2002:aa7:cdca:: with SMTP id h10mr41950577edw.271.1620807415367; Wed, 12 May 2021 01:16:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620807415; cv=none; d=google.com; s=arc-20160816; b=m/Q4OSpRGgxMSd0fVYR9d7DDiYcC/+QHPDjEPZRGC7E2IZO+O5qyD4XgXQfON3kVcI TlklF1G5vYi0F4CMLnKCI+R+nwmI8t+6IzwozFjvIE+jhMb5rAuyVWCNVHEzcnguGDfR 60m+B10dsqnMCreZKJAQJh/bIQNmgFBokyqnq6HbBWNKr481/H++/eqfmr2MCRO4XckI 0w/XwuG6vG7xx5JjIUZab5qC+q+qBZNKlGF30wBhOe6LiBaXV6RY0hbsKgCO42HKIyoI 0v4AIFJczx2Bkyce9Wi6l7qN3AoKkrgUv3AeE/VbHvgeTWwwXJxqnhk76BwZRZrUFSv0 OPQQ== 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=nq52t8jeP4PyzS5KwTlvrGIR1OeQ48+qESxEjeBFQXnB2Oi6XweXtlsHi6YZMF+lSa 1E/hb4ilusCFqFngExHyD/c2BY3xRjt6yODViRGvUGaWvJI+FTvXqT8CY1/NAxWC/HWt mRp2lxxeo7SLaKcFv9WsgCVhjse87hQDCIXB2THKq4mDICr9CdpRGFeqs50o4CSxdNw+ UuFeIiYr+rwgRxQ03HGgcjkU5koWvtMcQgTO4fSIyVvPmt3R/Sc5jdJ5mDFJD1vozrhR x29qClMbFw6mlMFTKj7sdDUn6nSOdUayVBSAmL+YQPofXs8kq/7vYJg6Wapf3R5xNZqa EGIA== 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 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 p8si16237916ejc.107.2021.05.12.01.16.31; Wed, 12 May 2021 01:16:55 -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=XNSq1m9a; 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 S230328AbhELIOO (ORCPT + 99 others); Wed, 12 May 2021 04:14:14 -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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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 } -- 2.29.2