From owner-svn-src-head@freebsd.org Tue Oct 17 15:39:39 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ECF9EE3D2F4; Tue, 17 Oct 2017 15:39:39 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id BA49671100; Tue, 17 Oct 2017 15:39:39 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v9HFdc3J002357; Tue, 17 Oct 2017 15:39:38 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v9HFdctF002356; Tue, 17 Oct 2017 15:39:38 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201710171539.v9HFdctF002356@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Tue, 17 Oct 2017 15:39:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r324689 - head/sys/dev/iscsi X-SVN-Group: head X-SVN-Commit-Author: avg X-SVN-Commit-Paths: head/sys/dev/iscsi X-SVN-Commit-Revision: 324689 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Oct 2017 15:39:40 -0000 Author: avg Date: Tue Oct 17 15:39:38 2017 New Revision: 324689 URL: https://svnweb.freebsd.org/changeset/base/324689 Log: iscsi: do not hold the global lock while tearing down a session It should be sufficient to hold the lock just for removing the session from the session list. Everything else should be covered by the session specific lock. On top of that, at present we can get a deadlock caused by waiting on the CAM SIM reference count while holding the global lock. A specific scenario involving ZFS is this: - concurrent termination of two sessions, S1 and S2 - session S1 completed all I/Os and sleeps in CAM waiting for device close by ZFS; - session S2 is also dead now, but can not forcefully complete outstanding requests by calling iscsi_session_cleanup() from iscsi_maintenance_thread_terminate(), since it can't get the same global sc_lock; - as soon as there are unfinished requests, ZFS can not do spa_config_enter() as writer, and so can not close the device for session S1; - deadlock. Reported by: Ben RUBSON Tested by: Ben RUBSON Reviewed by: mav, trasz MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D12652 Modified: head/sys/dev/iscsi/iscsi.c Modified: head/sys/dev/iscsi/iscsi.c ============================================================================== --- head/sys/dev/iscsi/iscsi.c Tue Oct 17 14:37:12 2017 (r324688) +++ head/sys/dev/iscsi/iscsi.c Tue Oct 17 15:39:38 2017 (r324689) @@ -434,6 +434,8 @@ iscsi_maintenance_thread_terminate(struct iscsi_sessio sc = is->is_softc; sx_xlock(&sc->sc_lock); + TAILQ_REMOVE(&sc->sc_sessions, is, is_next); + sx_xunlock(&sc->sc_lock); icl_conn_close(is->is_conn); callout_drain(&is->is_callout); @@ -465,8 +467,6 @@ iscsi_maintenance_thread_terminate(struct iscsi_sessio #ifdef ICL_KERNEL_PROXY cv_destroy(&is->is_login_cv); #endif - TAILQ_REMOVE(&sc->sc_sessions, is, is_next); - sx_xunlock(&sc->sc_lock); ISCSI_SESSION_DEBUG(is, "terminated"); free(is, M_ISCSI);