[RHEL7,COMMIT] locking/rwsem: Add down_read_killable()

Submitted by Konstantin Khorenko on May 25, 2020, 2:56 p.m.

Details

Message ID 202005251456.04PEu12E005329@finist-ce7.sw.ru
State New
Series "Introduce down_read_killable()"
Headers show

Commit Message

Konstantin Khorenko May 25, 2020, 2:56 p.m.
The commit is pushed to "branch-rh7-3.10.0-1127.8.2.vz7.161.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.8.2.vz7.161.1
------>
commit 47c6116485df34b5caa5d322b0cb519c483045e8
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Mon May 25 17:56:00 2020 +0300

    locking/rwsem: Add down_read_killable()
    
    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>
    
    =====================
    Patchset description:
    
    This ports support for down_read_killable(),
    which is a prerequisite for pernet_ops_rwsem.
    
    https://jira.sw.ru/browse/PSBM-104158
---
 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 56c930b825c7f..151d65e4b897d 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 e35f38a86a216..e6c66e527453a 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
  */