Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp735970ybc; Sat, 16 Nov 2019 07:48:24 -0800 (PST) X-Google-Smtp-Source: APXvYqxF/RNRBsGDTj/4BN7b0Pn9j77ECluzRgThrL7eVjYCEHWMe5Grdchg/28KcPG4gZx86lVb X-Received: by 2002:a17:906:4bcb:: with SMTP id x11mr10982478ejv.100.1573919304467; Sat, 16 Nov 2019 07:48:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573919304; cv=none; d=google.com; s=arc-20160816; b=BMnDwDUA/c+xQU5LRcN6OFNqEt9M3zdpta4sCQPq5ZKNYVbRVXV1/T6a3SvuAk6lLD 1UKB2d1tesTW/8i7PZMHNhY9C+bgdaC+CiMIA1NdxyEWKERSqrpTG3HnjX/fuAEgI+H/ lDt1NO0n0BXBBFf60jkc2ki4lpTpoEUJ93zFVQnNL8gU9UcFxmOye5hxZANdGe2zUmK/ rahsG48ftwkDUCYede/Z/AeXPy4Hrvs5NVgSZsvig4tkMik+MY+B1ycY7OoPW6waNgPG 928KKVmuOnijyfTdMGsfSK3FLM6Vx3DZBI7ktTq7w7dApvsPlQfZEs7PZgZEpqwqQv3L GaSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2WOChZ4VaXngSUTWvphDvL0v5rqZ1i1HsuO5bM2jO7Y=; b=hisdi8W4+Jq1HM19eElTGlEPZ0ReIBErJW01yIFniURC9bcdAkC00ABM4aFpb1+l5q fA7+nePILkZo7d+h5n9CKPA8k0RHIFFiNHrrYcQjewwyaJBB18n7pfT31+9CaTUvNaC2 rEmQWneDPcdQlsLXErKseorxG2G+pdMtjXeZJgmQQIAzbQByaF/1I2XIMW0+B3Jbnucq dUVvVBArKf6MiOYHhkrtOcqMHSOH7AjxB54bd0pZo91tiassKepR/B5+dh3BQSbkZcJ/ nc20swcxbpudf2N8f3x/VeEY5ewJLnuDLjL1bW9P+CBDsSBpJyhgPfdoOrkkyBbQjpI5 UKKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fhvBtnvF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id a61si9401259edf.157.2019.11.16.07.47.59; Sat, 16 Nov 2019 07:48:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fhvBtnvF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728894AbfKPPnx (ORCPT + 99 others); Sat, 16 Nov 2019 10:43:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:48106 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727870AbfKPPnt (ORCPT ); Sat, 16 Nov 2019 10:43:49 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A843A20729; Sat, 16 Nov 2019 15:43:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573919028; bh=zWF5U4xg7nt3/h5P3T6bRnH5eZb0im/xahs52GP8njM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fhvBtnvFY4od+uheu6kih3XaR6W7n/Go86Vsz12TR2GNvABTY9gldAsbPimX4yH/X VSmdA2afmJ2D15IxbPhL/kxpOCwOHxVwNlyut0+RnekLlzXSY3gG4gqjDcrN2B2lbO jnV/Y+XtUJKQU9xdP42t5d6uKfl/D/ifORnzuhtY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Felipe Rechia , Michael Ellerman , Sasha Levin , linuxppc-dev@lists.ozlabs.org Subject: [PATCH AUTOSEL 4.19 126/237] powerpc/process: Fix flush_all_to_thread for SPE Date: Sat, 16 Nov 2019 10:39:21 -0500 Message-Id: <20191116154113.7417-126-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Felipe Rechia [ Upstream commit e901378578c62202594cba0f6c076f3df365ec91 ] Fix a bug introduced by the creation of flush_all_to_thread() for processors that have SPE (Signal Processing Engine) and use it to compute floating-point operations. >From userspace perspective, the problem was seen in attempts of computing floating-point operations which should generate exceptions. For example: fork(); float x = 0.0 / 0.0; isnan(x); // forked process returns False (should be True) The operation above also should always cause the SPEFSCR FINV bit to be set. However, the SPE floating-point exceptions were turned off after a fork(). Kernel versions prior to the bug used flush_spe_to_thread(), which first saves SPEFSCR register values in tsk->thread and then calls giveup_spe(tsk). After commit 579e633e764e, the save_all() function was called first to giveup_spe(), and then the SPEFSCR register values were saved in tsk->thread. This would save the SPEFSCR register values after disabling SPE for that thread, causing the bug described above. Fixes 579e633e764e ("powerpc: create flush_all_to_thread()") Signed-off-by: Felipe Rechia Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/kernel/process.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 909c9407e392a..02b69a68139cc 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -575,12 +575,11 @@ void flush_all_to_thread(struct task_struct *tsk) if (tsk->thread.regs) { preempt_disable(); BUG_ON(tsk != current); - save_all(tsk); - #ifdef CONFIG_SPE if (tsk->thread.regs->msr & MSR_SPE) tsk->thread.spefscr = mfspr(SPRN_SPEFSCR); #endif + save_all(tsk); preempt_enable(); } -- 2.20.1