[Devel] [PATCH RH7 6/6] locking/rwsem: Add down_read_killable()

Kirill Tkhai ktkhai at virtuozzo.com
Fri May 22 20:03:19 MSK 2020


ms commit 76f8507f7a64

Similar to down_read() and down_write_killable(),
add killable version of down_read(), based on
__down_read_killable() function, added in previous
patches.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz at infradead.org>
Cc: Linus Torvalds <torvalds at linux-foundation.org>
Cc: Peter Zijlstra <peterz at infradead.org>
Cc: Thomas Gleixner <tglx at linutronix.de>
Cc: arnd at arndb.de
Cc: avagin at virtuozzo.com
Cc: davem at davemloft.net
Cc: fenghua.yu at intel.com
Cc: gorcunov at virtuozzo.com
Cc: heiko.carstens at de.ibm.com
Cc: hpa at zytor.com
Cc: ink at jurassic.park.msu.ru
Cc: mattst88 at gmail.com
Cc: rientjes at google.com
Cc: rth at twiddle.net
Cc: schwidefsky at de.ibm.com
Cc: tony.luck at intel.com
Cc: viro at zeniv.linux.org.uk
Link: http://lkml.kernel.org/r/150670119884.23930.2585570605960763239.stgit@localhost.localdomain
Signed-off-by: Ingo Molnar <mingo at kernel.org>
---
 include/linux/rwsem.h |    1 +
 kernel/rwsem.c        |   16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
index 56c930b825c7..151d65e4b897 100644
--- a/include/linux/rwsem.h
+++ b/include/linux/rwsem.h
@@ -133,6 +133,7 @@ static inline int rwsem_is_contended(struct rw_semaphore *sem)
  * lock for reading
  */
 extern void down_read(struct rw_semaphore *sem);
+extern int __must_check down_read_killable(struct rw_semaphore *sem);
 
 /*
  * trylock for reading -- returns 1 if successful, 0 if contention
diff --git a/kernel/rwsem.c b/kernel/rwsem.c
index e35f38a86a21..e6c66e527453 100644
--- a/kernel/rwsem.c
+++ b/kernel/rwsem.c
@@ -27,6 +27,22 @@ void __sched down_read(struct rw_semaphore *sem)
 
 EXPORT_SYMBOL(down_read);
 
+int __sched down_read_killable(struct rw_semaphore *sem)
+{
+	might_sleep();
+	rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_);
+
+	if (LOCK_CONTENDED_RETURN(sem, __down_read_trylock, __down_read_killable)) {
+		rwsem_release(&sem->dep_map, 1, _RET_IP_);
+		return -EINTR;
+	}
+
+	rwsem_set_reader_owned(sem);
+	return 0;
+}
+
+EXPORT_SYMBOL(down_read_killable);
+
 /*
  * trylock for reading -- returns 1 if successful, 0 if contention
  */




More information about the Devel mailing list