From owner-svn-src-all@freebsd.org Mon Sep 2 17:11:33 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 73656E3595; Mon, 2 Sep 2019 17:11:33 +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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46Mc7T1fGsz42c3; Mon, 2 Sep 2019 17:11:33 +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 1AE8A1D4A7; Mon, 2 Sep 2019 17:11:33 +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 x82HBWvT096349; Mon, 2 Sep 2019 17:11:32 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x82HBWi1096348; Mon, 2 Sep 2019 17:11:32 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201909021711.x82HBWi1096348@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Mon, 2 Sep 2019 17:11:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351706 - head/sys/dev/nvme X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sys/dev/nvme X-SVN-Commit-Revision: 351706 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.29 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: Mon, 02 Sep 2019 17:11:33 -0000 Author: imp Date: Mon Sep 2 17:11:32 2019 New Revision: 351706 URL: https://svnweb.freebsd.org/changeset/base/351706 Log: In nvme_completion_poll, add a sanity check to make sure that we complete the polling within a second. Panic if we don't. All the commands that use this interface should typically complete within a few tens to hundreds of microseconds. Panic rather than return ETIMEDOUT because if the command somehow does later complete, it will randomly corrupt memory. Also, it helps to get a traceback from where the unexpected failure happens, rather than an infinite loop. Modified: head/sys/dev/nvme/nvme_private.h Modified: head/sys/dev/nvme/nvme_private.h ============================================================================== --- head/sys/dev/nvme/nvme_private.h Mon Sep 2 17:11:27 2019 (r351705) +++ head/sys/dev/nvme/nvme_private.h Mon Sep 2 17:11:32 2019 (r351706) @@ -446,12 +446,24 @@ int nvme_attach(device_t dev); int nvme_shutdown(device_t dev); int nvme_detach(device_t dev); +/* + * Wait for a command to complete using the nvme_completion_poll_cb. + * Used in limited contexts where the caller knows it's OK to block + * briefly while the command runs. The ISR will run the callback which + * will set status->done to true.usually within microseconds. A 1s + * pause means something is seriously AFU and we should panic to + * provide the proper context to diagnose. + */ static __inline void nvme_completion_poll(struct nvme_completion_poll_status *status) { - while (!atomic_load_acq_int(&status->done)) + int sanity = hz * 1; + + while (!atomic_load_acq_int(&status->done) && --sanity > 0) pause("nvme", 1); + if (sanity <= 0) + panic("NVME polled command failed to complete within 1s."); } static __inline void