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

Submitted by Kirill Tkhai on May 22, 2020, 5:03 p.m.

Details

Message ID 159016699927.337057.1867512600050399577.stgit@localhost.localdomain
State New
Series "Introduce down_read_killable()"
Headers show

Commit Message

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

Patch hide | download patch | download mbox

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
  */