From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 71AD23C65FD for ; Fri, 22 May 2026 09:56:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779443819; cv=none; b=BuKUVDGDu7uuKwKRgNm2zBS9bA8PrLk6tMFkQozkBy/v7MmYc982eXtnrVMJuN7yMhlpkk9MV5RndxovQWb7YtBQcWcxvBHgDOWGpJ91+Ei/t7AxIiPiaLhUwsZg/5cfWfQHfGl+FQNq2Z5Q+NAW2WnS+Ecnh8gb3j7Ii48O9bU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779443819; c=relaxed/simple; bh=rIbxm+X12keZqdi4mG1S8vXGOqwRa/TOAViAMLqxvMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DU9lVRoCyEhSs2P29+oxxb4lPM7NQM0Bns9UItRRAMGc7iYyXNgorK7AMrLv9tm/1CKzTe95OOmwae/PP7klV/lJIQfWqEJPiKNwMWnovmGFAUNG3PCWmiROWevx+aMXcTn9EEkCpvXBFS4ZuHJ2u/mUv5Phul4yfP3TwqKPtBY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=blaxcWEp; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="blaxcWEp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 793971F00A3D; Fri, 22 May 2026 09:56:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779443818; bh=/rlRShe3uK6rrgQZ4IrnyUDRenTqFqb/izOjWLnR3G0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=blaxcWEp8Alstxd06rVmlKQUcUEfXjfOvS3jgXpwpaE4e9xfGXyFa5HJ+dTS0Ftai G9Kp9lqTiCbGeSfL0R7ILUI8TW0PTHpuiFpADsTx3Xp2sf9smT+Z0rVEQReYIO/J0W DpcZbplzYDHfL1LKKtOyzbPYzCJNLrgJc0vD70XT6hapkiETHNzgeWeaK/iuMfn0qO gILQ6ErbVRhVG887QcuGdHF1IziYJ/N9KLRY8vP/FeqbLMIEPX+PDoduF7vDWbnIaK Pa0OT3OgqxRKL9Rz9vS61i5q+YCErQ2pd1OTg/V9rZcsUPhEXvyb8XAEG9bXJ8jlhV gFyLAN9bIPMYA== From: "Christophe Leroy (CS GROUP)" To: Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan Cc: "Christophe Leroy (CS GROUP)" , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 8/8] powerpc/signal: Use unsafe_copy_siginfo_to_user() Date: Fri, 22 May 2026 11:56:08 +0200 Message-ID: <4a8b361c988655ab008ee2b205bfb0b246e16cc2.1779441786.git.chleroy@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3199; i=chleroy@kernel.org; h=from:subject:message-id; bh=rIbxm+X12keZqdi4mG1S8vXGOqwRa/TOAViAMLqxvMw=; b=owGbwMvMwCV2d0KB2p7V54MZT6slMWQJaNi3dT5aZGE+kZFFcu+dtINx/070nHmlf5Yx+cut1 pqWbQvjO0pZGMS4GGTFFFmO/+feNaPrS2r+1F36MHNYmUCGMHBxCsBExOwY/kffWfFwtX6Xa2lY ekV9cO1DG+k/K1suyjquKdHOXenf842R4ZJV6af7ydvNOU8mnVfM6trX513zx3qKxh2LaXtzMuX m8wAA X-Developer-Key: i=chleroy@kernel.org; a=openpgp; fpr=10FFE6F8B390DE17ACC2632368A92FEB01B8DD78 Content-Transfer-Encoding: 8bit Use unsafe_copy_siginfo_to_user() in order to do the copy within the user access block. On an mpc 8321 (book3s/32) the improvment is about 5% on a process sending a signal to itself. Signed-off-by: Christophe Leroy (CS GROUP) --- arch/powerpc/kernel/signal_32.c | 18 +++++++++--------- arch/powerpc/kernel/signal_64.c | 5 +---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c index 6b1fbd95b07d..99a3efa874eb 100644 --- a/arch/powerpc/kernel/signal_32.c +++ b/arch/powerpc/kernel/signal_32.c @@ -716,12 +716,6 @@ static long restore_tm_user_regs(struct pt_regs *regs, struct mcontext __user *s } #endif -#ifdef CONFIG_PPC64 - -#define copy_siginfo_to_user copy_siginfo_to_user32 - -#endif /* CONFIG_PPC64 */ - /* * Set up a signal frame for a "real-time" signal handler * (one which gets siginfo). @@ -735,6 +729,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, struct pt_regs *regs = tsk->thread.regs; /* Save the thread's msr before get_tm_stackpointer() changes it */ unsigned long msr = regs->msr; + compat_siginfo_t uinfo; /* Set up Signal Frame */ frame = get_sigframe(ksig, tsk, sizeof(*frame), 1); @@ -744,6 +739,9 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, else prepare_save_user_regs(1); + if (IS_ENABLED(CONFIG_COMPAT)) + copy_siginfo_to_external32(&uinfo, &ksig->info); + scoped_user_rw_access_size(newsp, __SIGNAL_FRAMESIZE + 16 + sizeof(*frame), badframe) { struct mcontext __user *mctx; struct mcontext __user *tm_mctx = NULL; @@ -785,14 +783,16 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, asm("dcbst %y0; sync; icbi %y0; sync" :: "Z" (mctx->mc_pad[0])); } unsafe_put_sigset_t(&frame->uc.uc_sigmask, oldset, badframe); + if (IS_ENABLED(CONFIG_COMPAT)) + unsafe_copy_to_user(&frame->info, &uinfo, sizeof(frame->info), badframe); + else + unsafe_copy_siginfo_to_user((void __user *)&frame->info, &ksig->info, + badframe); /* create a stack frame for the caller of the handler */ unsafe_put_user(regs->gpr[1], newsp, badframe); } - if (copy_siginfo_to_user(&frame->info, &ksig->info)) - goto badframe; - regs->link = tramp; #ifdef CONFIG_PPC_FPU_REGS diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c index 67de29cf581a..fa18ac43eb2a 100644 --- a/arch/powerpc/kernel/signal_64.c +++ b/arch/powerpc/kernel/signal_64.c @@ -893,14 +893,11 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, } unsafe_copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set), badframe); + unsafe_copy_siginfo_to_user(&frame->info, &ksig->info, badframe); /* Allocate a dummy caller frame for the signal handler. */ unsafe_put_user(regs->gpr[1], newsp, badframe); } - /* Save the siginfo outside of the unsafe block. */ - if (copy_siginfo_to_user(&frame->info, &ksig->info)) - goto badframe; - /* Make sure signal handler doesn't get spurious FP exceptions */ tsk->thread.fp_state.fpscr = 0; -- 2.54.0