Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp862243rdb; Fri, 26 Jan 2024 13:06:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IHYwgwOpvUKA3fVT7Nv5ABEUSXNpcgpIdyxjumlkus2MunTuDiRZF2GC2UFd7eSW5KVzpFE X-Received: by 2002:a05:651c:c86:b0:2ce:fac6:2465 with SMTP id bz6-20020a05651c0c8600b002cefac62465mr367958ljb.77.1706303189920; Fri, 26 Jan 2024 13:06:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706303189; cv=pass; d=google.com; s=arc-20160816; b=S4MHj5wi+0hcwmGk+qKmWYjOVeOGFgv+FDbzPD3pHqnnRmL9GTH0GlCKpPmcDnPSnC Cqpdfe4KBw2ZaZhiUB89eZdVFyPvvmK4Hz4oy/JGuw3YI3Qw1JIa9bdSjoYUuWvuQNO1 bM7NY8s5CauHY2B03mshAbt5VW9oKgd3LsWwsTYE/LqExefMUEmdyMDUftsl+vwXHq4z BNqej2WR2oaB+umKtlA4cnDD+/XDqUA9yXE4aTtHuZtn1VAGt5zViiucThovbDxVTXe3 1dNidCWzJ1kF/C4SL5Cn1g7EOQuCpzz9LP4nUsrG17KY19IHzTKECPRkaSNd583cQfCr K8hg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=EoJemsG7zxUo/FmjwJatg9m7Gv+XGAu+lwvDkceBtrc=; fh=Tx6dpK7U6GtDaFhICg47P4hfe05Mu0pTx93yT0T/fiE=; b=ifqf4BO/exKEmBLW3pdtJOuZKEJ8a+GNmh5aC7GcUSeAQbY+8eD7ELZGgsPVT1ZOYG OXLN1vpYdBMSzKbAv5Q9ucHyVobi1RTpaIfQ0EQUjhTB9gWSZ8GA5DFXh35HRQ4ZZCLA u2nBc5CoD0SOz49GFDS/3cdRjGbmLuK34/sQQBXjtRTfFlzDeK0AR0tOtaeg0RQwLywr z1mBSyLvvYGRsJg2y1gzBHOsAH3C8kLq26q2I7ZK4kX5JzBWnCS1wXv6gDKJUoVjpRX2 NV9+K4mx6MD0Jsjg5TZSSWMQjGrK39C0oOBfe5dC/Mt0Qxy6fvzHzWVkl5JTv4f411Lq 0b1g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b="S/zVRU6E"; arc=pass (i=1 spf=pass spfdomain=xry111.site dkim=pass dkdomain=xry111.site dmarc=pass fromdomain=xry111.site); spf=pass (google.com: domain of linux-kernel+bounces-40648-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40648-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 14-20020a0564021f4e00b0055c3249b1d0si1017642edz.43.2024.01.26.13.06.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 13:06:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40648-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b="S/zVRU6E"; arc=pass (i=1 spf=pass spfdomain=xry111.site dkim=pass dkdomain=xry111.site dmarc=pass fromdomain=xry111.site); spf=pass (google.com: domain of linux-kernel+bounces-40648-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40648-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A45A61F2522B for ; Fri, 26 Jan 2024 21:06:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2BF14249E4; Fri, 26 Jan 2024 21:06:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xry111.site header.i=@xry111.site header.b="S/zVRU6E" Received: from xry111.site (xry111.site [89.208.246.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04D7B22EF9; Fri, 26 Jan 2024 21:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=89.208.246.23 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706303180; cv=none; b=HqCGFdCf0CrGzfTLYyyhr22IQlqwGsENUXLZtei6Ig6xQ2SeYQABZ2V1DDzeGCJpfRw50jRiin5fKwcAcrS0reECcZOMMtB40k4siF0MBnh5OLAGqcBfb1aBIFM3VMikgqC+FwbJGVgzu8z4oTF21LwTW4vBD6Y+OLN419MxNEQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706303180; c=relaxed/simple; bh=AV1ZofWLKqVz1PfTeAIMra2ot1/I4iebX4fFRvtm+Uw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=D4FWsLTam7eiOQO5mnfUKqZedITOmy8838uvg7YCWyGUk9Z3ELDTAt6s16n0kLPn3kry6ROHB0yrblwkZYHm5Aj3SddwoZyCOL4iAn4vM6IHHwYM6nDKEK6oWeTr8EGHtua64h4w6F9v5soepWCROFyXJsgEztvBag0fcAhF8tw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xry111.site; spf=pass smtp.mailfrom=xry111.site; dkim=pass (1024-bit key) header.d=xry111.site header.i=@xry111.site header.b=S/zVRU6E; arc=none smtp.client-ip=89.208.246.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1706303177; bh=AV1ZofWLKqVz1PfTeAIMra2ot1/I4iebX4fFRvtm+Uw=; h=From:To:Cc:Subject:Date:From; b=S/zVRU6E9Q+G3QqJe79cHk0eD7ZSmd0XFyrUlcwTqi3+4Nn4KctzPxOJXVu2Ngdtk sxmANB7LCY3lE8puILgATdGJ9t2ZlQM2o5uV8JpPqAg2XUvm/DlFjYYQhYtsoLgvsO P1Hcspk9qHqUxtAXVx6itlHof7JHxaCKKlB85aJo= Received: from stargazer.. (unknown [IPv6:240e:358:1181:9d00:dc73:854d:832e:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 35E7F66A29; Fri, 26 Jan 2024 16:06:10 -0500 (EST) From: Xi Ruoyao To: Thomas Bogendoerfer , Jiaxun Yang , linux-mips@vger.kernel.org Cc: Ralf Baechle , "Maciej W. Rozycki" , YunQiang Su , Huacai Chen , WANG Xuerui , linux-kernel@vger.kernel.org, Xi Ruoyao , stable@vger.kernel.org Subject: [PATCH v2] mips: Call lose_fpu(0) before initializing fcr31 in mips_set_personality_nan Date: Sat, 27 Jan 2024 05:05:57 +0800 Message-ID: <20240126210557.12442-1-xry111@xry111.site> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If we still own the FPU after initializing fcr31, when we are preempted the dirty value in the FPU will be read out and stored into fcr31, clobbering our setting. This can cause an improper floating-point environment after execve(). For example: zsh% cat measure.c #include int main() { return fetestexcept(FE_INEXACT); } zsh% cc measure.c -o measure -lm zsh% echo $((1.0/3)) # raising FE_INEXACT 0.33333333333333331 zsh% while ./measure; do ; done (stopped in seconds) Call lose_fpu(0) before setting fcr31 to prevent this. Closes: https://lore.kernel.org/linux-mips/7a6aa1bbdbbe2e63ae96ff163fab0349f58f1b9e.camel@xry111.site/ Fixes: 9b26616c8d9d ("MIPS: Respect the ISA level in FCSR handling") Cc: stable@vger.kernel.org Signed-off-by: Xi Ruoyao --- v1 -> v2: Fix stable list address in Cc line. arch/mips/kernel/elf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/mips/kernel/elf.c b/arch/mips/kernel/elf.c index 5582a4ca1e9e..7aa2c2360ff6 100644 --- a/arch/mips/kernel/elf.c +++ b/arch/mips/kernel/elf.c @@ -11,6 +11,7 @@ #include #include +#include #ifdef CONFIG_MIPS_FP_SUPPORT @@ -309,6 +310,11 @@ void mips_set_personality_nan(struct arch_elf_state *state) struct cpuinfo_mips *c = &boot_cpu_data; struct task_struct *t = current; + /* Do this early so t->thread.fpu.fcr31 won't be clobbered in case + * we are preempted before the lose_fpu(0) in start_thread. + */ + lose_fpu(0); + t->thread.fpu.fcr31 = c->fpu_csr31; switch (state->nan_2008) { case 0: -- 2.43.0