Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp704182pxb; Mon, 25 Oct 2021 17:02:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0CTf8PPTJxXnOhEBA+YolaW/SfiFnG/D6ItWVB8VYZiP8a9BHAn3hWQhaghGiu7qNv0Ee X-Received: by 2002:a17:906:1450:: with SMTP id q16mr19039607ejc.213.1635206561906; Mon, 25 Oct 2021 17:02:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635206561; cv=none; d=google.com; s=arc-20160816; b=JeGx66L8kYFOV4KMVmxubmgdyrn+xuu4UA1cc/fwLDlOHVUDuYyKdQwE+m/l0AG6Pu Wh/9rQRtyD7LGg1+pG52Pj6lvmFsh65P6HWAwYNdtd3b+Pk5FHkZEtdPGO8uE8pm4AP2 MQCa4qgglukI2JhRFuyLy1gznEdJLJ3bQD9Bshpjz7DN/EuPkR0q3c7CfFdxZu3VPwJF rQxGwPHsD9KptXSUMJ9ofXwgmg4+uyWcXvFWbLFhpv5jDB5LCXQq4AY5Qwln2OriGqeq BpV493JqysgDoX/mE/CoPN1TS+iumoiW4sKtjpClALONCEpJfCWCu1liTrtA506Eni4Q vhHw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HLBTX6C4N6ulNjoKANSkDqkZ7K9jBQyv8e3Rs0/sHoc=; b=hA3sG7iT/cx0WWKKV+UCACsQRZIcu87qcmOKnL+GYpqUkla8x0bPHHhLuHtLYoYv4i GClaGBdUECdFzbdPaMMkjBPaimWQrkTa1WnpvnxR0ykxDefDvsjssjpZ/WWOGuOiXuUP 2GKjcB2s+EbWGFsZ7cSVOAboYJNCyWzZrI5UFKOJHBVS29/bxOc7bigFF5QYSvuZSuEs IHC59EKujeGqM+hWgon924QIHbl5fGHBs8AWqAsXmXgaeaEbcdAZLJGyDHVkAylyJEu/ ZPd59pphp5kOwI5YJCkoT9eil8Iigo+vYCpumzPrtKbKNQOtTk83eqRfqDxaUvsCNe1t nY8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=phTjwv0o; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp16si3503304ejc.458.2021.10.25.17.02.05; Mon, 25 Oct 2021 17:02:41 -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=@linuxfoundation.org header.s=korg header.b=phTjwv0o; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234186AbhJYTmW (ORCPT + 99 others); Mon, 25 Oct 2021 15:42:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:49900 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235314AbhJYTcI (ORCPT ); Mon, 25 Oct 2021 15:32:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0791C611BD; Mon, 25 Oct 2021 19:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635190106; bh=3KAaVflUzHq2MNaSlzL9XMoFFPSco4C9eLInPYqAdVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=phTjwv0ojjFIdTlDqQi/7kaAdXZwUhRt90EFZEQ8SVkY1S0ZT3fD9R630S6f32ztT D6S6avuyzMpTrBuiPtbbaHA0RCJJwgkOwAdn1fveUpsfat+U4La2uspTi9+Fdi0Sy8 u/ALF0nftQ+xhPT0geDqgPl7JX3DPCKoacMivjcQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Christopher M. Riedl" , Michael Ellerman Subject: [PATCH 5.4 35/58] powerpc64/idle: Fix SP offsets when saving GPRs Date: Mon, 25 Oct 2021 21:14:52 +0200 Message-Id: <20211025190943.310240815@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211025190937.555108060@linuxfoundation.org> References: <20211025190937.555108060@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christopher M. Riedl commit 73287caa9210ded6066833195f4335f7f688a46b upstream. The idle entry/exit code saves/restores GPRs in the stack "red zone" (Protected Zone according to PowerPC64 ELF ABI v2). However, the offset used for the first GPR is incorrect and overwrites the back chain - the Protected Zone actually starts below the current SP. In practice this is probably not an issue, but it's still incorrect so fix it. Also expand the comments to explain why using the stack "red zone" instead of creating a new stackframe is appropriate here. Signed-off-by: Christopher M. Riedl Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210206072342.5067-1-cmr@codefail.de Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kernel/idle_book3s.S | 138 ++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 65 deletions(-) --- a/arch/powerpc/kernel/idle_book3s.S +++ b/arch/powerpc/kernel/idle_book3s.S @@ -50,28 +50,32 @@ _GLOBAL(isa300_idle_stop_mayloss) std r1,PACAR1(r13) mflr r4 mfcr r5 - /* use stack red zone rather than a new frame for saving regs */ - std r2,-8*0(r1) - std r14,-8*1(r1) - std r15,-8*2(r1) - std r16,-8*3(r1) - std r17,-8*4(r1) - std r18,-8*5(r1) - std r19,-8*6(r1) - std r20,-8*7(r1) - std r21,-8*8(r1) - std r22,-8*9(r1) - std r23,-8*10(r1) - std r24,-8*11(r1) - std r25,-8*12(r1) - std r26,-8*13(r1) - std r27,-8*14(r1) - std r28,-8*15(r1) - std r29,-8*16(r1) - std r30,-8*17(r1) - std r31,-8*18(r1) - std r4,-8*19(r1) - std r5,-8*20(r1) + /* + * Use the stack red zone rather than a new frame for saving regs since + * in the case of no GPR loss the wakeup code branches directly back to + * the caller without deallocating the stack frame first. + */ + std r2,-8*1(r1) + std r14,-8*2(r1) + std r15,-8*3(r1) + std r16,-8*4(r1) + std r17,-8*5(r1) + std r18,-8*6(r1) + std r19,-8*7(r1) + std r20,-8*8(r1) + std r21,-8*9(r1) + std r22,-8*10(r1) + std r23,-8*11(r1) + std r24,-8*12(r1) + std r25,-8*13(r1) + std r26,-8*14(r1) + std r27,-8*15(r1) + std r28,-8*16(r1) + std r29,-8*17(r1) + std r30,-8*18(r1) + std r31,-8*19(r1) + std r4,-8*20(r1) + std r5,-8*21(r1) /* 168 bytes */ PPC_STOP b . /* catch bugs */ @@ -87,8 +91,8 @@ _GLOBAL(isa300_idle_stop_mayloss) */ _GLOBAL(idle_return_gpr_loss) ld r1,PACAR1(r13) - ld r4,-8*19(r1) - ld r5,-8*20(r1) + ld r4,-8*20(r1) + ld r5,-8*21(r1) mtlr r4 mtcr r5 /* @@ -96,25 +100,25 @@ _GLOBAL(idle_return_gpr_loss) * from PACATOC. This could be avoided for that less common case * if KVM saved its r2. */ - ld r2,-8*0(r1) - ld r14,-8*1(r1) - ld r15,-8*2(r1) - ld r16,-8*3(r1) - ld r17,-8*4(r1) - ld r18,-8*5(r1) - ld r19,-8*6(r1) - ld r20,-8*7(r1) - ld r21,-8*8(r1) - ld r22,-8*9(r1) - ld r23,-8*10(r1) - ld r24,-8*11(r1) - ld r25,-8*12(r1) - ld r26,-8*13(r1) - ld r27,-8*14(r1) - ld r28,-8*15(r1) - ld r29,-8*16(r1) - ld r30,-8*17(r1) - ld r31,-8*18(r1) + ld r2,-8*1(r1) + ld r14,-8*2(r1) + ld r15,-8*3(r1) + ld r16,-8*4(r1) + ld r17,-8*5(r1) + ld r18,-8*6(r1) + ld r19,-8*7(r1) + ld r20,-8*8(r1) + ld r21,-8*9(r1) + ld r22,-8*10(r1) + ld r23,-8*11(r1) + ld r24,-8*12(r1) + ld r25,-8*13(r1) + ld r26,-8*14(r1) + ld r27,-8*15(r1) + ld r28,-8*16(r1) + ld r29,-8*17(r1) + ld r30,-8*18(r1) + ld r31,-8*19(r1) blr /* @@ -152,28 +156,32 @@ _GLOBAL(isa206_idle_insn_mayloss) std r1,PACAR1(r13) mflr r4 mfcr r5 - /* use stack red zone rather than a new frame for saving regs */ - std r2,-8*0(r1) - std r14,-8*1(r1) - std r15,-8*2(r1) - std r16,-8*3(r1) - std r17,-8*4(r1) - std r18,-8*5(r1) - std r19,-8*6(r1) - std r20,-8*7(r1) - std r21,-8*8(r1) - std r22,-8*9(r1) - std r23,-8*10(r1) - std r24,-8*11(r1) - std r25,-8*12(r1) - std r26,-8*13(r1) - std r27,-8*14(r1) - std r28,-8*15(r1) - std r29,-8*16(r1) - std r30,-8*17(r1) - std r31,-8*18(r1) - std r4,-8*19(r1) - std r5,-8*20(r1) + /* + * Use the stack red zone rather than a new frame for saving regs since + * in the case of no GPR loss the wakeup code branches directly back to + * the caller without deallocating the stack frame first. + */ + std r2,-8*1(r1) + std r14,-8*2(r1) + std r15,-8*3(r1) + std r16,-8*4(r1) + std r17,-8*5(r1) + std r18,-8*6(r1) + std r19,-8*7(r1) + std r20,-8*8(r1) + std r21,-8*9(r1) + std r22,-8*10(r1) + std r23,-8*11(r1) + std r24,-8*12(r1) + std r25,-8*13(r1) + std r26,-8*14(r1) + std r27,-8*15(r1) + std r28,-8*16(r1) + std r29,-8*17(r1) + std r30,-8*18(r1) + std r31,-8*19(r1) + std r4,-8*20(r1) + std r5,-8*21(r1) cmpwi r3,PNV_THREAD_NAP bne 1f IDLE_STATE_ENTER_SEQ_NORET(PPC_NAP)