From owner-svn-src-all@freebsd.org Tue May 15 22:22:11 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 98D71ED799D; Tue, 15 May 2018 22:22:11 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4710384C38; Tue, 15 May 2018 22:22:11 +0000 (UTC) (envelope-from imp@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 29B701196D; Tue, 15 May 2018 22:22:11 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w4FMMBhq036323; Tue, 15 May 2018 22:22:11 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w4FMMAxI036320; Tue, 15 May 2018 22:22:10 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201805152222.w4FMMAxI036320@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Tue, 15 May 2018 22:22:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r333651 - in head/sys/cam: ata mmc nvme X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: in head/sys/cam: ata mmc nvme X-SVN-Commit-Revision: 333651 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 May 2018 22:22:11 -0000 Author: imp Date: Tue May 15 22:22:10 2018 New Revision: 333651 URL: https://svnweb.freebsd.org/changeset/base/333651 Log: Hold the reference count until the CCB is released When a disk disappears and the periph is invalidated, any I/Os that are pending with the controller can cause a crash when they complete. Move to holding the softc reference count taken in dastart() until the I/O is complete rather than only until xpt_action() returns. (This approach was suggested by Ken Merry.) This extends the method used in da to ada, nda, and mda. Sponsored by: Netflix Submitted by: Chuck Silvers Modified: head/sys/cam/ata/ata_da.c head/sys/cam/mmc/mmc_da.c head/sys/cam/nvme/nvme_da.c Modified: head/sys/cam/ata/ata_da.c ============================================================================== --- head/sys/cam/ata/ata_da.c Tue May 15 21:54:59 2018 (r333650) +++ head/sys/cam/ata/ata_da.c Tue May 15 22:22:10 2018 (r333651) @@ -2458,7 +2458,6 @@ out: cam_periph_unlock(periph); xpt_action(start_ccb); cam_periph_lock(periph); - softc->refcount--; /* May have more work to do, so ensure we stay scheduled */ adaschedule(periph); @@ -2856,10 +2855,13 @@ adadone(struct cam_periph *periph, union ccb *done_ccb * We need to call cam_iosched before we call biodone so that we * don't measure any activity that happens in the completion * routine, which in the case of sendfile can be quite - * extensive. + * extensive. Release the periph refcount taken in adastart() + * for each CCB. */ cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb); xpt_release_ccb(done_ccb); + KASSERT(softc->refcount >= 1, ("adadone softc %p refcount %d", softc, softc->refcount)); + softc->refcount--; if (state == ADA_CCB_TRIM) { TAILQ_HEAD(, bio) queue; struct bio *bp1; Modified: head/sys/cam/mmc/mmc_da.c ============================================================================== --- head/sys/cam/mmc/mmc_da.c Tue May 15 21:54:59 2018 (r333650) +++ head/sys/cam/mmc/mmc_da.c Tue May 15 22:22:10 2018 (r333651) @@ -1357,7 +1357,6 @@ sddastart(struct cam_periph *periph, union ccb *start_ cam_periph_unlock(periph); xpt_action(start_ccb); cam_periph_lock(periph); - softc->refcount--; /* May have more work to do, so ensure we stay scheduled */ sddaschedule(periph); @@ -1418,6 +1417,11 @@ sddadone(struct cam_periph *periph, union ccb *done_cc softc->outstanding_cmds--; xpt_release_ccb(done_ccb); + /* + * Release the periph refcount taken in mdastart() for each CCB. + */ + KASSERT(softc->refcount >= 1, ("mdadone softc %p refcount %d", softc, softc->refcount)); + softc->refcount--; biodone(bp); } Modified: head/sys/cam/nvme/nvme_da.c ============================================================================== --- head/sys/cam/nvme/nvme_da.c Tue May 15 21:54:59 2018 (r333650) +++ head/sys/cam/nvme/nvme_da.c Tue May 15 22:22:10 2018 (r333651) @@ -990,7 +990,6 @@ out: cam_periph_unlock(periph); xpt_action(start_ccb); cam_periph_lock(periph); - softc->refcount--; /* May have more work to do, so ensure we stay scheduled */ ndaschedule(periph); @@ -1101,6 +1100,11 @@ ndadone(struct cam_periph *periph, union ccb *done_ccb biodone(bp2); } } + /* + * Release the periph refcount taken in mdastart() for each CCB. + */ + KASSERT(softc->refcount >= 1, ("ndadone softc %p refcount %d", softc, softc->refcount)); + softc->refcount--; return; } case NDA_CCB_DUMP: