Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4459448pxj; Wed, 12 May 2021 06:13:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/WdEN0g9ZSrRHijCchQasF4f36ti52NLVSevzKxddvTQsxnS6I0l+95UINj25KxxVajmr X-Received: by 2002:a05:6402:5201:: with SMTP id s1mr5129654edd.86.1620825224673; Wed, 12 May 2021 06:13:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620825224; cv=none; d=google.com; s=arc-20160816; b=TH2RjEcjtEaK3ZpKOEd6kbgYcfWvmg27L9nCzvzlR4CrUPXyHgbcPo/XJApxRRLQfy eCxeGZiwDdC6y7VdvBYoR3IqrBt4JZebaHx66Y/ggCFK3j9/5TXc79xXvhHgucnHg57P LvTfaMqqS2JZ2qntfb29NguXH87500+HwBXLb59OpuzVKPGzKZoLRCvQZmF/JSKzvDzE vMdm0sqdO21qQaoc/wz3D4INgNuBpKQ8KXu0GcdNYNbUqpw45iaRAd1V+ZRniDAIKgmz QGvS26Ekom16eQyWdpzHqWEj0PKysYNSvXgtyz1/kFLEllqWUJ9BCxv8ItGS1CIaWsrY WYfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=f9bT0p2YKF3I/Im99Hh6HstNNq8mCv9QCTkmew6R+ew=; b=gB4OoRqgjT95CQMIkKiOwE+p5k5SXDR6Ibd84VLTX2cG62uCvZB3z7TEMIpbK1istq NZyxwob9hfodvoPn+HDV6AHIqlz6kw0GfUCo1ACU8Io62RX8CjSkfFI8/zS5YhNqtWC9 cASzQdTW9s4wOdtMLUsHdO3DuA6CydNqQPHmfzcV3pbMBr4oVR9avn0f1IJJ1Ol2b5EQ BqClI+Avq5SRdwME3NkEbQcp9Z26+SUbY3NrHSiM84o0PuJx1TNQkZV5mbOIo7N8o/he ndbUooBttx6MlQOBllDOloh66R/MonkNka0U4l57Kg0/gfGW/y5VH7v5tuPmkYln8M+I FPnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EhluFSXe; 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 w1si19110591edc.221.2021.05.12.06.13.20; Wed, 12 May 2021 06:13:44 -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=EhluFSXe; 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 S232894AbhELMj7 (ORCPT + 99 others); Wed, 12 May 2021 08:39:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:35342 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232883AbhELMj6 (ORCPT ); Wed, 12 May 2021 08:39:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 80D82613EB; Wed, 12 May 2021 12:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620823130; bh=U/gxAeewTiKq3NLv6xkw5kHBZSrDQoOv3EdDAkj+rHw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=EhluFSXeRQ9uIMcVhFd03T1Gv/kx0fOmos1rq5xUICKJSfddq5BlQZuDBD2XaVADW B6EBJUAI4bnStohdmahmDr+qevSGcmPUExMUZym/lPDzkvnGos0njgBc5hPhTQzbnf 9du2ZbvQBe6D7KcwSlF6RkRgt6HbRPVVlN8y3zEmAOk9KuRDPskJGwypsJ3oq+mXdK 7NNNf3wLX5P9hsMHOM3V99u5tW0zCTYn6a8l13BMROphXEn3NM+GPPWraSm/m73W3+ t2hgMXctRcqQKkvFERIXbPRoBr5LWE5iFs3/HuNlWLWWkZtzxFmt6Wlp5VJZlp1gr9 qSekJU2sRGkig== Received: by mail-oi1-f170.google.com with SMTP id j75so22075849oih.10; Wed, 12 May 2021 05:38:50 -0700 (PDT) X-Gm-Message-State: AOAM533p8qT1Gqf2+ZkmACleAjkV+e0hrRQsqnyAWGDTfR02k1g1GYmm Ca8FBC62CJcW7tORi3xTELYeGjP9ePy8s/Fu3A0= X-Received: by 2002:aca:e142:: with SMTP id y63mr26156865oig.33.1620823127705; Wed, 12 May 2021 05:38:47 -0700 (PDT) MIME-Version: 1.0 References: <20210512081211.200025-1-arnd@kernel.org> In-Reply-To: <20210512081211.200025-1-arnd@kernel.org> From: Ard Biesheuvel Date: Wed, 12 May 2021 14:38:36 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] ARM: fix gcc-10 thumb2-kernel regression To: Arnd Bergmann Cc: Russell King , Arnd Bergmann , "# 3.4.x" , Daniel Thompson , Marek Vasut , Nathan Chancellor , Nick Desaulniers , Linus Walleij , Nicolas Pitre , Geert Uytterhoeven , Mike Rapoport , Linux ARM , Linux Kernel Mailing List , clang-built-linux Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 12 May 2021 at 10:13, Arnd Bergmann wrote: > > 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 Nice bug! Acked-by: Ard Biesheuvel > --- > 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 >