All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] signal: Skip the altstack update when not needed
@ 2021-12-10 22:55 Chang S. Bae
  2021-12-13 21:25 ` Thomas Gleixner
  2021-12-14 21:12 ` [tip: sched/urgent] " tip-bot2 for Chang S. Bae
  0 siblings, 2 replies; 4+ messages in thread
From: Chang S. Bae @ 2021-12-10 22:55 UTC (permalink / raw)
  To: linux-kernel; +Cc: tglx, dave.hansen, ebiederm, oleg, bp, x86, chang.seok.bae

== Background ==

Support for large, "dynamic" fpstates was recently merged.  This
included code to ensure that sigaltstacks are sufficiently sized for
these large states.  A new lock was added to remove races between
enabling large features and setting up sigaltstacks.

== Problem ==

The new lock (sigaltstack_lock()) is acquired in the sigreturn path
before restoring the old sigaltstack.  Unfortunately, contention on the
new lock causes a measurable signal handling performance regression [1].
However, the common case is that no *changes* are made to the
sigaltstack state at sigreturn.

== Solution ==

do_sigaltstack() acquires sigaltstack_lock() and is used for both
sys_sigaltstack() and restoring the sigaltstack in sys_sigreturn().
Check for changes to the sigaltstack before taking the lock.  If no
changes were made, return before acquiring the lock.

This removes lock contention from the common-case sigreturn path.

Reported-by: kernel test robot <oliver.sang@intel.com>
[1] https://lore.kernel.org/lkml/20211207012128.GA16074@xsang-OptiPlex-9020/
Fixes: 3aac3ebea08f ("x86/signal: Implement sigaltstack size validation")
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
---
Changes from v1:
* Rewrite the changelog. (Dave Hansen)
* Add the code comment. (Dave Hansen)
---
 kernel/signal.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/kernel/signal.c b/kernel/signal.c
index a629b11bf3e0..dfcee3888b00 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -4185,6 +4185,15 @@ do_sigaltstack (const stack_t *ss, stack_t *oss, unsigned long sp,
 				ss_mode != 0))
 			return -EINVAL;
 
+		/*
+		 * Return before taking any locks if no actual
+		 * sigaltstack changes were requested.
+		 */
+		if (t->sas_ss_sp == (unsigned long)ss_sp &&
+		    t->sas_ss_size == ss_size &&
+		    t->sas_ss_flags == ss_flags)
+			return 0;
+
 		sigaltstack_lock();
 		if (ss_mode == SS_DISABLE) {
 			ss_size = 0;
-- 
2.17.1


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

* Re: [PATCH v2] signal: Skip the altstack update when not needed
  2021-12-10 22:55 [PATCH v2] signal: Skip the altstack update when not needed Chang S. Bae
@ 2021-12-13 21:25 ` Thomas Gleixner
  2021-12-14  1:01   ` Bae, Chang Seok
  2021-12-14 21:12 ` [tip: sched/urgent] " tip-bot2 for Chang S. Bae
  1 sibling, 1 reply; 4+ messages in thread
From: Thomas Gleixner @ 2021-12-13 21:25 UTC (permalink / raw)
  To: Chang S. Bae, linux-kernel
  Cc: dave.hansen, ebiederm, oleg, bp, x86, chang.seok.bae

On Fri, Dec 10 2021 at 14:55, Chang S. Bae wrote:
> do_sigaltstack() acquires sigaltstack_lock() and is used for both
> sys_sigaltstack() and restoring the sigaltstack in sys_sigreturn().
> Check for changes to the sigaltstack before taking the lock.  If no
> changes were made, return before acquiring the lock.
>
> This removes lock contention from the common-case sigreturn path.
>
> Reported-by: kernel test robot <oliver.sang@intel.com>
> [1] https://lore.kernel.org/lkml/20211207012128.GA16074@xsang-OptiPlex-9020/
> Fixes: 3aac3ebea08f ("x86/signal: Implement sigaltstack size validation")
> Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>

Reviewed-by: Thomas Gleixner <tglx@linutronix.de>

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

* Re: [PATCH v2] signal: Skip the altstack update when not needed
  2021-12-13 21:25 ` Thomas Gleixner
@ 2021-12-14  1:01   ` Bae, Chang Seok
  0 siblings, 0 replies; 4+ messages in thread
From: Bae, Chang Seok @ 2021-12-14  1:01 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, dave.hansen, ebiederm, oleg, bp, x86

On Dec 13, 2021, at 13:25, Thomas Gleixner <tglx@linutronix.de> wrote:
> 
> Reviewed-by: Thomas Gleixner <tglx@linutronix.de>

Thanks!
Chang

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

* [tip: sched/urgent] signal: Skip the altstack update when not needed
  2021-12-10 22:55 [PATCH v2] signal: Skip the altstack update when not needed Chang S. Bae
  2021-12-13 21:25 ` Thomas Gleixner
@ 2021-12-14 21:12 ` tip-bot2 for Chang S. Bae
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Chang S. Bae @ 2021-12-14 21:12 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: kernel test robot, Chang S. Bae, Dave Hansen, Thomas Gleixner,
	x86, linux-kernel

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     6c3118c32129b4197999a8928ba776bcabd0f5c4
Gitweb:        https://git.kernel.org/tip/6c3118c32129b4197999a8928ba776bcabd0f5c4
Author:        Chang S. Bae <chang.seok.bae@intel.com>
AuthorDate:    Fri, 10 Dec 2021 14:55:03 -08:00
Committer:     Dave Hansen <dave.hansen@linux.intel.com>
CommitterDate: Tue, 14 Dec 2021 13:08:36 -08:00

signal: Skip the altstack update when not needed

== Background ==

Support for large, "dynamic" fpstates was recently merged.  This
included code to ensure that sigaltstacks are sufficiently sized for
these large states.  A new lock was added to remove races between
enabling large features and setting up sigaltstacks.

== Problem ==

The new lock (sigaltstack_lock()) is acquired in the sigreturn path
before restoring the old sigaltstack.  Unfortunately, contention on the
new lock causes a measurable signal handling performance regression [1].
However, the common case is that no *changes* are made to the
sigaltstack state at sigreturn.

== Solution ==

do_sigaltstack() acquires sigaltstack_lock() and is used for both
sys_sigaltstack() and restoring the sigaltstack in sys_sigreturn().
Check for changes to the sigaltstack before taking the lock.  If no
changes were made, return before acquiring the lock.

This removes lock contention from the common-case sigreturn path.

[1] https://lore.kernel.org/lkml/20211207012128.GA16074@xsang-OptiPlex-9020/

Fixes: 3aac3ebea08f ("x86/signal: Implement sigaltstack size validation")
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20211210225503.12734-1-chang.seok.bae@intel.com
---
 kernel/signal.c |  9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/kernel/signal.c b/kernel/signal.c
index a629b11..dfcee38 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -4185,6 +4185,15 @@ do_sigaltstack (const stack_t *ss, stack_t *oss, unsigned long sp,
 				ss_mode != 0))
 			return -EINVAL;
 
+		/*
+		 * Return before taking any locks if no actual
+		 * sigaltstack changes were requested.
+		 */
+		if (t->sas_ss_sp == (unsigned long)ss_sp &&
+		    t->sas_ss_size == ss_size &&
+		    t->sas_ss_flags == ss_flags)
+			return 0;
+
 		sigaltstack_lock();
 		if (ss_mode == SS_DISABLE) {
 			ss_size = 0;

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

end of thread, other threads:[~2021-12-14 21:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-10 22:55 [PATCH v2] signal: Skip the altstack update when not needed Chang S. Bae
2021-12-13 21:25 ` Thomas Gleixner
2021-12-14  1:01   ` Bae, Chang Seok
2021-12-14 21:12 ` [tip: sched/urgent] " tip-bot2 for Chang S. Bae

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.