From owner-svn-src-head@freebsd.org Mon Apr 24 12:52:44 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 07EF0D4C0E2; Mon, 24 Apr 2017 12:52:44 +0000 (UTC) (envelope-from mav@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 AF690E6F; Mon, 24 Apr 2017 12:52:43 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v3OCqgaR067947; Mon, 24 Apr 2017 12:52:42 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v3OCqgPH067946; Mon, 24 Apr 2017 12:52:42 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201704241252.v3OCqgPH067946@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 24 Apr 2017 12:52:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r317370 - head/sys/cam/ctl X-SVN-Group: head 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: Mon, 24 Apr 2017 12:52:44 -0000 Author: mav Date: Mon Apr 24 12:52:42 2017 New Revision: 317370 URL: https://svnweb.freebsd.org/changeset/base/317370 Log: Change ctl_free_lun() locking. This fixes potential callout_drain() sleep under non-sleepable lock. PR: 218167 MFC after: 2 weeks Modified: head/sys/cam/ctl/ctl.c Modified: head/sys/cam/ctl/ctl.c ============================================================================== --- head/sys/cam/ctl/ctl.c Mon Apr 24 12:44:04 2017 (r317369) +++ head/sys/cam/ctl/ctl.c Mon Apr 24 12:52:42 2017 (r317370) @@ -4731,18 +4731,20 @@ ctl_free_lun(struct ctl_lun *lun) struct ctl_lun *nlun; int i; - mtx_assert(&softc->ctl_lock, MA_OWNED); + KASSERT(TAILQ_EMPTY(&lun->ooa_queue), + ("Freeing a LUN %p with outstanding I/O!\n", lun)); + mtx_lock(&softc->ctl_lock); STAILQ_REMOVE(&softc->lun_list, lun, ctl_lun, links); - ctl_clear_mask(softc->ctl_lun_mask, lun->lun); - softc->ctl_luns[lun->lun] = NULL; - - if (!TAILQ_EMPTY(&lun->ooa_queue)) - panic("Freeing a LUN %p with outstanding I/O!!\n", lun); - softc->num_luns--; + STAILQ_FOREACH(nlun, &softc->lun_list, links) { + mtx_lock(&nlun->lun_lock); + ctl_est_ua_all(nlun, -1, CTL_UA_LUN_CHANGE); + mtx_unlock(&nlun->lun_lock); + } + mtx_unlock(&softc->ctl_lock); /* * Tell the backend to free resources, if this LUN has a backend. @@ -4752,7 +4754,6 @@ ctl_free_lun(struct ctl_lun *lun) lun->ie_reportcnt = UINT32_MAX; callout_drain(&lun->ie_callout); - ctl_tpc_lun_shutdown(lun); mtx_destroy(&lun->lun_lock); free(lun->lun_devid, M_CTL); @@ -4765,12 +4766,6 @@ ctl_free_lun(struct ctl_lun *lun) if (lun->flags & CTL_LUN_MALLOCED) free(lun, M_CTL); - STAILQ_FOREACH(nlun, &softc->lun_list, links) { - mtx_lock(&nlun->lun_lock); - ctl_est_ua_all(nlun, -1, CTL_UA_LUN_CHANGE); - mtx_unlock(&nlun->lun_lock); - } - return (0); } @@ -5027,9 +5022,7 @@ ctl_invalidate_lun(struct ctl_be_lun *be */ if (TAILQ_EMPTY(&lun->ooa_queue)) { mtx_unlock(&lun->lun_lock); - mtx_lock(&softc->ctl_lock); ctl_free_lun(lun); - mtx_unlock(&softc->ctl_lock); } else mtx_unlock(&lun->lun_lock); @@ -13068,9 +13061,7 @@ ctl_process_done(union ctl_io *io) if ((lun->flags & CTL_LUN_INVALID) && TAILQ_EMPTY(&lun->ooa_queue)) { mtx_unlock(&lun->lun_lock); - mtx_lock(&softc->ctl_lock); ctl_free_lun(lun); - mtx_unlock(&softc->ctl_lock); } else mtx_unlock(&lun->lun_lock);