All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] fortify: add branch hints on unlikely fortify_panic paths
@ 2025-06-25 16:12 Colin Ian King
  2025-06-27  0:14 ` kernel test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Colin Ian King @ 2025-06-25 16:12 UTC (permalink / raw)
  To: Kees Cook, linux-hardening; +Cc: kernel-janitors, linux-kernel

Analysis with gcov while running the stress-ng urandom stressor
shows that there are a couple of fortify panic paths that are highly
unlikely to be executed for well-behaving code. Adding appropriate
branch hints improves the stress-ng urandom stressor my a small
but statistically measureable amount. Ran 100 x 1 minute tests and
measured the stressor bogo-op rates on a Debian based Intel(R)
Core(TM) Ultra 9 285K with a 6.15 kernel with turbo disabled to
reduce jitter.

Results based on a Geometic Mean of 100 tests:

Without patch: 50512.95 bogo-ops/sec
With patch:    50819.58 bogo-ops/sec

%Std.Deviation of ~0.18%, so low jitter in results, improvement of ~0.6%

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 include/linux/fortify-string.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h
index e4ce1cae03bf..2ab8cb641d70 100644
--- a/include/linux/fortify-string.h
+++ b/include/linux/fortify-string.h
@@ -593,9 +593,9 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_size_t size,
 	 * (The SIZE_MAX test is to optimize away checks where the buffer
 	 * lengths are unknown.)
 	 */
-	if (p_size != SIZE_MAX && p_size < size)
+	if (unlikely(p_size != SIZE_MAX && p_size < size))
 		fortify_panic(func, FORTIFY_WRITE, p_size, size, true);
-	else if (q_size != SIZE_MAX && q_size < size)
+	else if (unlikely(q_size != SIZE_MAX && q_size < size))
 		fortify_panic(func, FORTIFY_READ, p_size, size, true);
 
 	/*
-- 
2.50.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-06-27 16:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-25 16:12 [PATCH][next] fortify: add branch hints on unlikely fortify_panic paths Colin Ian King
2025-06-27  0:14 ` kernel test robot
2025-06-27  1:05 ` kernel test robot
2025-06-27 16:36 ` Kees Cook
2025-06-27 16:47   ` Colin King (gmail)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.