From nobody Fri Jan 21 02:26:52 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 7D5521968F06; Fri, 21 Jan 2022 02:26:55 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jg3DG2kXkz4nkk; Fri, 21 Jan 2022 02:26:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642732014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=m9rP0ARv7gg6Wb8O5aD6m4Jh8UAqHANEUbm5OvzXOJw=; b=U0gWVLA/hHpZ67PIy5JwfijzbetzmN6aDFIRkJEgo1DR1yAhOa6rk2yanbuXh09apeHs6l cOKwAi+YhpqQajwm2FMZU3esvZbmY3JgB3ZsRsNv5CElHkqfp6M4xkcFguKrQTu7mCnyqg vElp/5tnuzuVRAM7uLP1zxfz821xGYZPSajwr+Y4DQ6sEa8sRpIS0Ia4aMOvvoTzJKVVny NekCdB/L3kASP3whUhteMZYgG6FI/0tLleBDamtbbefnh94SYpMrbd1VO2tjTqB4yfgL+L tPnFj7FjCGei7xOSbfJBIHqVDQurMsfnYXfLmUp6dI3U9MQXHS5jibeHHU5KTQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BF6C113A67; Fri, 21 Jan 2022 02:26:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20L2QqtH001234; Fri, 21 Jan 2022 02:26:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20L2Qq9g001233; Fri, 21 Jan 2022 02:26:52 GMT (envelope-from git) Date: Fri, 21 Jan 2022 02:26:52 GMT Message-Id: <202201210226.20L2Qq9g001233@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 7144882ae15c - stable/13 - nvme: Add sanity check for phase on startup. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 7144882ae15c235aa999c034eeacf6e5eda5152e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642732014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=m9rP0ARv7gg6Wb8O5aD6m4Jh8UAqHANEUbm5OvzXOJw=; b=Q0g2SgLk9hX8LLWvvhEm2MojEjtG2Fhqd6boTHcrS/xisvu+wEyAgaxVev217xwU3w2Wj4 YAsJg/1aZa8jvaFhT2BUExUKCiDwNZYSJFpuFzZpG+Vq3GFJwzgHMlSYYZa9vDO64APhZx e8R/j2L09uHpjBcdLVZgUt8sNZqpVYfNRpquJX2Nsfh9yn74bCXSVDCON1Uy1v7Qa4sMgv L5V2sbS03F95cMDrt8deUd8k7Hh7vCykdqQVKWUrCnGd+3lbfS11UeY4ngVKUifAAcuH/P keZU96sPyv+/3ffugiHllN5FYtiasc8ah+cr23XaXhaq6OnuPpnIbe5IuEIrRg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642732014; a=rsa-sha256; cv=none; b=yfEWKJ3YJZw+gFgr7LZghXmZJ6nBDcX72ULIuN9BPMoYlLr1xIx8ErGbqumX/AGr5s+nwk edx/fKSLZpxleRCbEnL8EasfgM74jBabFPKO2SSEap+84pbfyIezDaFNF15nS+ExBpEdU9 SoLMU//hhO3RD2hGkjxHa8rlRn56zLvR+Q+jUc4rYoGEJTiFQXNiV9XKLAFdhmaohCsrLw 4cj5JTTUwpiXHd/GmvEs9zfo5KMZk1Om1YmJXZRl8ccR+1WtFiyYe8OAAPlXNq86gJZEeC RmzRymwBFtqvC/KuX+MMJzJwEVl7AfKUELduAWLnL5SOG7atuTxwfs66TT/h/g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=7144882ae15c235aa999c034eeacf6e5eda5152e commit 7144882ae15c235aa999c034eeacf6e5eda5152e Author: Warner Losh AuthorDate: 2021-09-29 03:11:17 +0000 Commit: Alexander Motin CommitDate: 2022-01-21 02:07:30 +0000 nvme: Add sanity check for phase on startup. The proper phase for the qpiar right after reset in the first interrupt is 1. For it, make sure that we're not still in phase 0. This is an illegal state to be processing interrupts and indicates that we've failed to properly protect against a race between initializing our state and processing interrupts. Modify stat resetting code so it resets the number of interrpts to 1 instead of 0 so we don't trigger a false positive panic. Sponsored by: Netflix Reviewed by: cperciva, mav (prior version) Differential Revision: https://reviews.freebsd.org/D32211 (cherry picked from commit 7d5eebe0f4a0f2aa5c8c7dfdd1a9ce1513849da8) --- sys/dev/nvme/nvme_qpair.c | 21 ++++++++++++++++++--- sys/dev/nvme/nvme_sysctl.c | 7 ++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/sys/dev/nvme/nvme_qpair.c b/sys/dev/nvme/nvme_qpair.c index 6ee5fa9d4c30..827054efd48e 100644 --- a/sys/dev/nvme/nvme_qpair.c +++ b/sys/dev/nvme/nvme_qpair.c @@ -536,16 +536,31 @@ nvme_qpair_process_completions(struct nvme_qpair *qpair) int done = 0; bool in_panic = dumping || SCHEDULER_STOPPED(); - qpair->num_intr_handler_calls++; - /* * qpair is not enabled, likely because a controller reset is is in * progress. Ignore the interrupt - any I/O that was associated with - * this interrupt will get retried when the reset is complete. + * this interrupt will get retried when the reset is complete. Any + * pending completions for when we're in startup will be completed + * as soon as initialization is complete and we start sending commands + * to the device. */ if (qpair->recovery_state != RECOVERY_NONE) return (false); + /* + * Sanity check initialization. After we reset the hardware, the phase + * is defined to be 1. So if we get here with zero prior calls and the + * phase is 0, it means that we've lost a race between the + * initialization and the ISR running. With the phase wrong, we'll + * process a bunch of completions that aren't really completions leading + * to a KASSERT below. + */ + KASSERT(!(qpair->num_intr_handler_calls == 0 && qpair->phase == 0), + ("%s: Phase wrong for first interrupt call.", + device_get_nameunit(qpair->ctrlr->dev))); + + qpair->num_intr_handler_calls++; + bus_dmamap_sync(qpair->dma_tag, qpair->queuemem_map, BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); /* diff --git a/sys/dev/nvme/nvme_sysctl.c b/sys/dev/nvme/nvme_sysctl.c index bbf9a40ee7fe..1f1e1ce4a628 100644 --- a/sys/dev/nvme/nvme_sysctl.c +++ b/sys/dev/nvme/nvme_sysctl.c @@ -155,8 +155,13 @@ static void nvme_qpair_reset_stats(struct nvme_qpair *qpair) { + /* + * Reset the values. Due to sanity checks in + * nvme_qpair_process_completions, we reset the number of interrupt + * calls to 1. + */ qpair->num_cmds = 0; - qpair->num_intr_handler_calls = 0; + qpair->num_intr_handler_calls = 1; qpair->num_retries = 0; qpair->num_failures = 0; }