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>] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 30 May 2018 11:24:41 -0400 (EDT)
From:   Mikulas Patocka <mpatocka@...hat.com>
To:     Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>, Matthew Wilcox <matthew@....cx>
cc:     linux-kernel@...r.kernel.org
Subject: [PATCH] semaphore: use raw_spin_lock_irq instead of
 raw_spin_lock_irqsave

The sleeping functions down, down_interruptible, down_killable and
down_timeout can't be called with interrupts disabled, so we don't have to
save and restore interrupt flag.

This patch avoids the costly pushf and popf instructions on the semaphore
path.

Signed-off-by: Mikulas Patocka <mpatocka@...hat.com>

---
 kernel/locking/semaphore.c |   21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

Index: linux-2.6/kernel/locking/semaphore.c
===================================================================
--- linux-2.6.orig/kernel/locking/semaphore.c	2017-06-03 00:22:44.000000000 +0200
+++ linux-2.6/kernel/locking/semaphore.c	2018-05-30 14:46:35.000000000 +0200
@@ -53,14 +53,12 @@ static noinline void __up(struct semapho
  */
 void down(struct semaphore *sem)
 {
-	unsigned long flags;
-
-	raw_spin_lock_irqsave(&sem->lock, flags);
+	raw_spin_lock_irq(&sem->lock);
 	if (likely(sem->count > 0))
 		sem->count--;
 	else
 		__down(sem);
-	raw_spin_unlock_irqrestore(&sem->lock, flags);
+	raw_spin_unlock_irq(&sem->lock);
 }
 EXPORT_SYMBOL(down);
 
@@ -75,15 +73,14 @@ EXPORT_SYMBOL(down);
  */
 int down_interruptible(struct semaphore *sem)
 {
-	unsigned long flags;
 	int result = 0;
 
-	raw_spin_lock_irqsave(&sem->lock, flags);
+	raw_spin_lock_irq(&sem->lock);
 	if (likely(sem->count > 0))
 		sem->count--;
 	else
 		result = __down_interruptible(sem);
-	raw_spin_unlock_irqrestore(&sem->lock, flags);
+	raw_spin_unlock_irq(&sem->lock);
 
 	return result;
 }
@@ -101,15 +98,14 @@ EXPORT_SYMBOL(down_interruptible);
  */
 int down_killable(struct semaphore *sem)
 {
-	unsigned long flags;
 	int result = 0;
 
-	raw_spin_lock_irqsave(&sem->lock, flags);
+	raw_spin_lock_irq(&sem->lock);
 	if (likely(sem->count > 0))
 		sem->count--;
 	else
 		result = __down_killable(sem);
-	raw_spin_unlock_irqrestore(&sem->lock, flags);
+	raw_spin_unlock_irq(&sem->lock);
 
 	return result;
 }
@@ -155,15 +151,14 @@ EXPORT_SYMBOL(down_trylock);
  */
 int down_timeout(struct semaphore *sem, long timeout)
 {
-	unsigned long flags;
 	int result = 0;
 
-	raw_spin_lock_irqsave(&sem->lock, flags);
+	raw_spin_lock_irq(&sem->lock);
 	if (likely(sem->count > 0))
 		sem->count--;
 	else
 		result = __down_timeout(sem, timeout);
-	raw_spin_unlock_irqrestore(&sem->lock, flags);
+	raw_spin_unlock_irq(&sem->lock);
 
 	return result;
 }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ