lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250212160734.527199-1-colin.i.king@gmail.com>
Date: Wed, 12 Feb 2025 16:07:34 +0000
From: Colin Ian King <colin.i.king@...il.com>
To: Thomas Gleixner <tglx@...utronix.de>,
	Peter Zijlstra <peterz@...radead.org>
Cc: kernel-janitors@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH][next] signal: improve performance of tgkill and do_rt_tgsigqueueinfo

Adding an unlikely() hint on a couple of unlikely error return
paths improves run-time performance of tgkill and do_rt_tgsigqueueinfo.

Benchmarking on an i9-12900 shows an improvement of ~5% on a tgkill
on a process and ~3% improvement on sigqueue. Results based on running
20 tests and taking geometric mean of number of calls per second. Used
signal number 0 to check if process exists.

Signed-off-by: Colin Ian King <colin.i.king@...il.com>
---
 kernel/signal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index 081f19a24506..4ae848ce3a7a 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -4165,7 +4165,7 @@ static int do_tkill(pid_t tgid, pid_t pid, int sig)
 SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid_t, pid, int, sig)
 {
 	/* This is only valid for single tasks */
-	if (pid <= 0 || tgid <= 0)
+	if (unlikely(pid <= 0 || tgid <= 0))
 		return -EINVAL;
 
 	return do_tkill(tgid, pid, sig);
@@ -4233,7 +4233,7 @@ COMPAT_SYSCALL_DEFINE3(rt_sigqueueinfo,
 static int do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig, kernel_siginfo_t *info)
 {
 	/* This is only valid for single tasks */
-	if (pid <= 0 || tgid <= 0)
+	if (unlikely(pid <= 0 || tgid <= 0))
 		return -EINVAL;
 
 	/* Not even root can pretend to send signals from the kernel.
-- 
2.47.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ