From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E925B17BB21; Sun, 7 Sep 2025 20:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757276937; cv=none; b=NztSNJEn8dzwWvXhZeMxmr03CH8vQOSiw0q7l+cA7DdEcKyrEODt+o2oCbW0OHv+mqi0hAZ9/MAe7DTXpOYmB0+8BrMkNPaXGoMEmv7pwWOBBAo+xFNidc7Gf11vQF/h27e3Ze2nUK9C/LdoF7VQM+3VrBfUEMxuQR7DdD+Nm4k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757276937; c=relaxed/simple; bh=vZFkYEAuGYBu7J/8dw77mjys2+qlyHn8pu92zRu4l7I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qk/nuUSWGoJlUv3VD+ZPxnQoJxHPw08Y7AIu9edeek/PYByvfYMQDuulWEEvnT81XihwiZZ8JNSPc1lEjYhQ5SFKx5DmM+sYQaA2IYEPMT5NNL0gwFxi6gKXpLeVyX8ob80AcollicnC/Ewv+7oXrpswFOfLBSDtadah1ZeHMok= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qWomrR0W; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="qWomrR0W" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70AEAC4CEF0; Sun, 7 Sep 2025 20:28:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1757276936; bh=vZFkYEAuGYBu7J/8dw77mjys2+qlyHn8pu92zRu4l7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qWomrR0WQyYixMG37IDj2gso0vksQ7yZWHP/T1iHTNUJmOQG4uWGTWMvhQe9LM6uU 4dLSYBVPOegSGrOObs8Rq/ecrwWt7IV8hwZMwHnk/x7+2StWC6mUcBnc1jFMZ40DaS u2OrtSiNypgIj/G6CLOMS/TaZesRC9QUv57+ZAQY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hanlu Li , Huacai Chen , Sasha Levin Subject: [PATCH 6.12 008/175] LoongArch: Save LBT before FPU in setup_sigcontext() Date: Sun, 7 Sep 2025 21:56:43 +0200 Message-ID: <20250907195615.089193645@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250907195614.892725141@linuxfoundation.org> References: <20250907195614.892725141@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Huacai Chen [ Upstream commit 112ca94f6c3b3e0b2002a240de43c487a33e0234 ] Now if preemption happens between protected_save_fpu_context() and protected_save_lbt_context(), FTOP context is lost. Because FTOP is saved by protected_save_lbt_context() but protected_save_fpu_context() disables TM before that. So save LBT before FPU in setup_sigcontext() to avoid this potential risk. Signed-off-by: Hanlu Li Signed-off-by: Huacai Chen Signed-off-by: Sasha Levin --- arch/loongarch/kernel/signal.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/loongarch/kernel/signal.c b/arch/loongarch/kernel/signal.c index 4740cb5b23889..c9f7ca778364e 100644 --- a/arch/loongarch/kernel/signal.c +++ b/arch/loongarch/kernel/signal.c @@ -677,6 +677,11 @@ static int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, for (i = 1; i < 32; i++) err |= __put_user(regs->regs[i], &sc->sc_regs[i]); +#ifdef CONFIG_CPU_HAS_LBT + if (extctx->lbt.addr) + err |= protected_save_lbt_context(extctx); +#endif + if (extctx->lasx.addr) err |= protected_save_lasx_context(extctx); else if (extctx->lsx.addr) @@ -684,11 +689,6 @@ static int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, else if (extctx->fpu.addr) err |= protected_save_fpu_context(extctx); -#ifdef CONFIG_CPU_HAS_LBT - if (extctx->lbt.addr) - err |= protected_save_lbt_context(extctx); -#endif - /* Set the "end" magic */ info = (struct sctx_info *)extctx->end.addr; err |= __put_user(0, &info->magic); -- 2.50.1