git: f16383d44d4e - stable/13 - linuxkpi: Add down_read_killable()

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Tue, 29 Nov 2022 10:39:07 UTC
The branch stable/13 has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=f16383d44d4e3dc0c71d292279eadcaf6f312923

commit f16383d44d4e3dc0c71d292279eadcaf6f312923
Author:     Jake Freeland <jfree@FreeBSD.org>
AuthorDate: 2022-09-20 17:35:19 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-11-29 10:09:31 +0000

    linuxkpi: Add down_read_killable()
    
    Reviewed by:    hselasky
    Differential Revision:  https://reviews.freebsd.org/D36528
    Sponsored by:   Google, Inc. (GSoC 2022)
    
    (cherry picked from commit f0b0f28f35e79d8777f4ba89d5065d3665b43866)
---
 sys/compat/linuxkpi/common/include/linux/rwsem.h |  2 ++
 sys/compat/linuxkpi/common/src/linux_lock.c      | 13 +++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/rwsem.h b/sys/compat/linuxkpi/common/include/linux/rwsem.h
index fc3580bc186e..a08668ed6e1e 100644
--- a/sys/compat/linuxkpi/common/include/linux/rwsem.h
+++ b/sys/compat/linuxkpi/common/include/linux/rwsem.h
@@ -46,6 +46,7 @@ struct rw_semaphore {
 #define	down_read(_rw)			sx_slock(&(_rw)->sx)
 #define	up_read(_rw)			sx_sunlock(&(_rw)->sx)
 #define	down_read_trylock(_rw)		!!sx_try_slock(&(_rw)->sx)
+#define	down_read_killable(_rw)		linux_down_read_killable(_rw)
 #define	down_write_trylock(_rw)		!!sx_try_xlock(&(_rw)->sx)
 #define	down_write_killable(_rw)	linux_down_write_killable(_rw)
 #define	downgrade_write(_rw)		sx_downgrade(&(_rw)->sx)
@@ -80,6 +81,7 @@ linux_init_rwsem(struct rw_semaphore *rw, const char *name)
 	sx_init_flags(&rw->sx, name, SX_NOWITNESS);
 }
 
+extern int linux_down_read_killable(struct rw_semaphore *);
 extern int linux_down_write_killable(struct rw_semaphore *);
 
 #endif					/* _LINUXKPI_LINUX_RWSEM_H_ */
diff --git a/sys/compat/linuxkpi/common/src/linux_lock.c b/sys/compat/linuxkpi/common/src/linux_lock.c
index b04a7738d036..0e9a2fecaf7d 100644
--- a/sys/compat/linuxkpi/common/src/linux_lock.c
+++ b/sys/compat/linuxkpi/common/src/linux_lock.c
@@ -159,6 +159,19 @@ linux_mutex_lock_interruptible(mutex_t *m)
 	return (error);
 }
 
+int
+linux_down_read_killable(struct rw_semaphore *rw)
+{
+	int error;
+
+	error = -sx_slock_sig(&rw->sx);
+	if (error != 0) {
+		linux_schedule_save_interrupt_value(current, error);
+		error = -EINTR;
+	}
+	return (error);
+}
+
 int
 linux_down_write_killable(struct rw_semaphore *rw)
 {