Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Apr 2021 19:04:01 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 0d4d5e9fe0c6 - stable/13 - iscsi: Kick threads out of iscsi_ioctl() during unload.
Message-ID:  <202104261904.13QJ413n080349@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by jhb:

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

commit 0d4d5e9fe0c684a5aeda62638d7b29b0f10009cd
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2021-04-12 20:56:16 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2021-04-26 19:02:21 +0000

    iscsi: Kick threads out of iscsi_ioctl() during unload.
    
    iscsid can be sleeping in iscsi_ioctl() causing the destroy_dev() to
    sleep forever if iscsi.ko is unloaded while iscsid is running.
    
    Reported by:    Jithesh Arakkan @ Chelsio
    Sponsored by:   Chelsio Communications
    
    (cherry picked from commit 89df484739efe93b52da467f35255ae538bb946b)
---
 sys/dev/iscsi/iscsi.c | 11 +++++++++++
 sys/dev/iscsi/iscsi.h |  1 +
 2 files changed, 12 insertions(+)

diff --git a/sys/dev/iscsi/iscsi.c b/sys/dev/iscsi/iscsi.c
index 4367f780d84b..13a35c371c40 100644
--- a/sys/dev/iscsi/iscsi.c
+++ b/sys/dev/iscsi/iscsi.c
@@ -1333,6 +1333,11 @@ iscsi_ioctl_daemon_wait(struct iscsi_softc *sc,
 		}
 
 		if (is == NULL) {
+			if (sc->sc_unloading) {
+				sx_sunlock(&sc->sc_lock);
+				return (ENXIO);
+			}
+
 			/*
 			 * No session requires attention from iscsid(8); wait.
 			 */
@@ -2560,6 +2565,12 @@ static int
 iscsi_unload(void)
 {
 
+	/* Awaken any threads asleep in iscsi_ioctl(). */
+	sx_xlock(&sc->sc_lock);
+	sc->sc_unloading = true;
+	cv_signal(&sc->sc_cv);
+	sx_xunlock(&sc->sc_lock);
+
 	if (sc->sc_cdev != NULL) {
 		ISCSI_DEBUG("removing device node");
 		destroy_dev(sc->sc_cdev);
diff --git a/sys/dev/iscsi/iscsi.h b/sys/dev/iscsi/iscsi.h
index 80ac9d877107..793b7529c7c0 100644
--- a/sys/dev/iscsi/iscsi.h
+++ b/sys/dev/iscsi/iscsi.h
@@ -132,6 +132,7 @@ struct iscsi_softc {
 	TAILQ_HEAD(, iscsi_session)	sc_sessions;
 	struct cv			sc_cv;
 	unsigned int			sc_last_session_id;
+	bool				sc_unloading;
 	eventhandler_tag		sc_shutdown_pre_eh;
 	eventhandler_tag		sc_shutdown_post_eh;
 };



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202104261904.13QJ413n080349>