Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3599256pxv; Mon, 28 Jun 2021 08:16:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0Rm5PJYsF2WknjAmHM5m2rdwhqVQkjevpdp7rzh7+MGAhuyFI+eitFtJ/FL+brSevzYfN X-Received: by 2002:aa7:dccb:: with SMTP id w11mr32678922edu.96.1624893415078; Mon, 28 Jun 2021 08:16:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624893415; cv=none; d=google.com; s=arc-20160816; b=q6faJgROEOy8CfWsAVQEmtfAQOm5Y+rplIOiYvHwzE1fFJBPrKavKnctyG1WC+JozE wkc9I3yh7/ns9O9r90TF6X8T8emoE43Wi4wskLu0Uz2lQnfjQc66ou9O6pWPVcIbbGp/ x8HSpQ2ohY6L7wQHD1aYwQcmoSd9im3xH80pS6x5MSqOlJeCb3tYoNUfWS11ILtMY53p twEV1KS2NUGNzD1X5PpyMvbwZnQuWfC4BMA6fIxBA8t0/eICUQ3J5j3gi3kKF0TX7P3i vlBPF6uKTO7ZzsxeGRc0k6Xohn2CG4Gf3hO+ywALBDRX5stAdCFqWqgBpgucF+t6n2Yb ZXxw== 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=TF1LdQfJxFGm1ZNsjA6oTWFeBDxtoqZ3y1YT4qTrZUg=; b=gltPfchL5Z/m+6PXH/ZW/0ZlEJQjEHYE41KLNxpffRGdCrROPnNiJeaTbAT0VfBFEd Tx/8xBGm+EdNSVDyOcitTt0Vt6RszVbSt19xj6CHekjzVd3/rcncpHeJ34N8aslhdRQH ws+x0gYpoBrkj9y+oT6R1vZgdgYd4/NSsduCmuMpFrNWV0zQMBMMH57ThcB/mlaPUVa7 J/3IqMWDNgW0nUpu7B5CU9N2Njn1BD6M1O1/nJWnlgAp0jPDmo5vTCZmAHO4r1rpNZX+ rOegh6Ecpp3ED4k1QkJLNZ2w1PczZWm21cO2j5M+dsBb897IKgvtpI7VdCSJQqy6ApUX GG/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DvVpVp6D; 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 p2si15118372edu.249.2021.06.28.08.16.27; Mon, 28 Jun 2021 08: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=DvVpVp6D; 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 S237933AbhF1PPD (ORCPT + 99 others); Mon, 28 Jun 2021 11:15:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:60296 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235069AbhF1OxT (ORCPT ); Mon, 28 Jun 2021 10:53:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 66D3561CBA; Mon, 28 Jun 2021 14:37:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891048; bh=hINdB0PpwNgM9NxJ2A9RUg1nH3H83OgYfY4Mlm1dhtg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DvVpVp6DeVXV85gOAgJgyVK2Ywsaz+wMuefER0rC3QX20egnI79J8P2r6uuWh3+IB aPW1mIYHLB5IIdUteWCn1dnP/OKtvjicqPOQtgC0ydryTUk6d1aUktLQ0sXkiFyE93 Ee4hfefNH2sqR8bpuo8qu4N+JWmir3CE8dyDurlVQI57tQUkp/b3YjWKb+wyz1KjyE c054ohu+leTa4HLfKrSR2dBwdxZUfMkyByAK1cfUH7Jr+8DJBan+QKJpd4FfvIHsfe mnODnT13UF3y2uK4ndaSIikSdxfYLFtOHdBwDMJobAyB9LtedSB8lmv5F2TysptDUR dxAUNrebgTjXw== 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.14 67/88] ARM: 9081/1: fix gcc-10 thumb2-kernel regression Date: Mon, 28 Jun 2021 10:36:07 -0400 Message-Id: <20210628143628.33342-68-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143628.33342-1-sashal@kernel.org> References: <20210628143628.33342-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.238-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.238-rc1 X-KernelTest-Deadline: 2021-06-30T14:36+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 a6d27284105a..ac4ffd97ae82 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -547,9 +547,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 /* @@ -571,15 +573,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