From owner-svn-src-stable-11@freebsd.org Thu Feb 1 16:45:09 2018 Return-Path: Delivered-To: svn-src-stable-11@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 E3A4BEDD0EA; Thu, 1 Feb 2018 16:45:08 +0000 (UTC) (envelope-from mav@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 95E377689C; Thu, 1 Feb 2018 16:45:08 +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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 90D0B7972; Thu, 1 Feb 2018 16:45:08 +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 w11Gj8es026113; Thu, 1 Feb 2018 16:45:08 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w11Gj862026112; Thu, 1 Feb 2018 16:45:08 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201802011645.w11Gj862026112@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Thu, 1 Feb 2018 16:45:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r328684 - stable/11/sys/dev/nvme X-SVN-Group: stable-11 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: stable/11/sys/dev/nvme X-SVN-Commit-Revision: 328684 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Feb 2018 16:45:09 -0000 Author: mav Date: Thu Feb 1 16:45:08 2018 New Revision: 328684 URL: https://svnweb.freebsd.org/changeset/base/328684 Log: MFC r322443 (by nwhitehorn): Move NVME controller shutdown from being called as part of module unloading to being called through the newbus DEVICE_SHUTDOWN() path. This ensures that the NVME controller gets shut down before the device and bus disappear and prevents data corruption on shutdown on at least Samsung EVO 960 SSDs. PR: kern/211852 Modified: stable/11/sys/dev/nvme/nvme.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/nvme/nvme.c ============================================================================== --- stable/11/sys/dev/nvme/nvme.c Thu Feb 1 16:44:19 2018 (r328683) +++ stable/11/sys/dev/nvme/nvme.c Thu Feb 1 16:45:08 2018 (r328684) @@ -58,6 +58,7 @@ MALLOC_DEFINE(M_NVME, "nvme", "nvme(4) memory allocati static int nvme_probe(device_t); static int nvme_attach(device_t); static int nvme_detach(device_t); +static int nvme_shutdown(device_t); static int nvme_modevent(module_t mod, int type, void *arg); static devclass_t nvme_devclass; @@ -67,6 +68,7 @@ static device_method_t nvme_pci_methods[] = { DEVMETHOD(device_probe, nvme_probe), DEVMETHOD(device_attach, nvme_attach), DEVMETHOD(device_detach, nvme_detach), + DEVMETHOD(device_shutdown, nvme_shutdown), { 0, 0 } }; @@ -180,22 +182,15 @@ nvme_unload(void) { } -static void -nvme_shutdown(void) +static int +nvme_shutdown(device_t dev) { - device_t *devlist; struct nvme_controller *ctrlr; - int dev, devcount; - if (devclass_get_devices(nvme_devclass, &devlist, &devcount)) - return; + ctrlr = DEVICE2SOFTC(dev); + nvme_ctrlr_shutdown(ctrlr); - for (dev = 0; dev < devcount; dev++) { - ctrlr = DEVICE2SOFTC(devlist[dev]); - nvme_ctrlr_shutdown(ctrlr); - } - - free(devlist, M_TEMP); + return (0); } static int @@ -208,9 +203,6 @@ nvme_modevent(module_t mod, int type, void *arg) break; case MOD_UNLOAD: nvme_unload(); - break; - case MOD_SHUTDOWN: - nvme_shutdown(); break; default: break;