Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3976027yba; Tue, 7 May 2019 10:02:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPnJK9ofoRO4Amfl8kBJDNRM59ZmHCoByGzNAsLebv/XyOo2Yet3oIdB4f7k3I5Q/yGDOo X-Received: by 2002:a17:902:d708:: with SMTP id w8mr41180953ply.231.1557248520526; Tue, 07 May 2019 10:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557248520; cv=none; d=google.com; s=arc-20160816; b=tdStOur/wZmVx0CWII7f6kEwBkQjdhmPSC1FQjRWJvbGsHRH+grShk04pTYZZX0JAI NKb85eMbxB0gUx/we+W1yUyLz8pHf4RA415+UzPj/Hb+DS+4mdVJ/dHvkWSkPdrjvGkN xHAX2o2zSgvmVRYHY7Un5cCka6jDn4reU9biR/YZbytxGniens4ACbXapuIqsjz3VFzK MbejAUP/FdNWOatCL7UsZzjLXOCcMCFU0qO559VTKH+94TaQI5SoUkPXKQCKb/yIlbum buVOdxWquzVm1aQH1ks2ozq/oUDa60XxZ0oftlAgMls+q+qYPQ4Da8O86T7mEyv9Jm9G IQ9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=k+izu/4NAQhuOqK71jybIxMy36M1jkAicxA/bCcXC8o=; b=IhFbnTwHI9BCaf0U8k0YcG6a1Rf7ksCZUsJXK4ponuvUa51WqdxaUzr7lHk0/1Ux8u ifMCoMSlHlMYsB3UdGtgVcYwfV6cQz2E9lENfyKkO1MGe+supfB8SnN7jMEvYviJArv5 uLU63zCqQ396bn1BMkcDi+3Z8ancY+aBjkqDp7ibrbupU8I2/LV6Oft1/JBOjvPVebac tDooZNv76k43I5UkDfrwiylDhIDRW+RigTN3k8RzOPiimPchAapAYpBZH70X+cWOxrtn jX0Z1Fq3dOsJblKkxzXYSXESqL+3QL6tMGVKYeK3i+m0VQC9XwNzw54EFFzBp34wlBCZ 9lXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=daC1FLv2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si18614360pgv.475.2019.05.07.10.01.43; Tue, 07 May 2019 10:02:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=daC1FLv2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727365AbfEGQ7N (ORCPT + 99 others); Tue, 7 May 2019 12:59:13 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:38100 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727030AbfEGQ7M (ORCPT ); Tue, 7 May 2019 12:59:12 -0400 Received: by mail-pl1-f194.google.com with SMTP id a59so8472563pla.5 for ; Tue, 07 May 2019 09:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=k+izu/4NAQhuOqK71jybIxMy36M1jkAicxA/bCcXC8o=; b=daC1FLv2qV7ms0f53DCm1/ESSLNjYad3dx8z6Fn434ELLWYMBC20Hkv7lmiq7Ee1rw XXUSOqq0NSHXS+dhuIJCsdMpRnRt9mEZANysxRA9Lu1CQVN9vszHr7ZPGTTKEgo8ic00 LeijExqB3ExTY1paGiidgFW3UcGWt9g+OeBSk4JkhRVGUppPNrIvzM4IJzgg4ffDBh4N wZt9wx4hAWD5fnxYyiJ0cIzifyQYSEOk6cNXfmXn0OczjiHpC5AAlsUxpctbMaNWiYQR RszKsujhBEtW8fzcO8tkFE87HA7PO8x6vulSDjxCh6Z69lGuQY86lumxgT2+yIemv1fR efYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=k+izu/4NAQhuOqK71jybIxMy36M1jkAicxA/bCcXC8o=; b=ZrwlbnsqzHRmGViKH4+pYaFbMkIPz/LaVbns5KMat/1KR0XFJNDTlEFxW9By2mhj/N gVq67mT4F+yCnJ9i428Yut2qkBFDmTsDeft0uiIl+R4s6fjRTqAljf6KFOjYh1Hj8Zy3 ubHhXEO0QtFGEc2Z5tT845D51leS/e6VIaGAWxJKkKj83VXeaax2w9E8p2KVj8c+G04M gNIx6vFmZWH3GRLwTIfM0YvQBmstVeKQd7SCpoiEl62TZfj7SdBT7FOWU3qgJO0hejSq ehBs7xdGZiH57wD5AbvBL/7AxduP8Z4nWVokaYkYimalEOAYX6Nlxhyq9gpDXT7hkD68 uRmg== X-Gm-Message-State: APjAAAWczAp7DnP5gm3s6F5Sij37eeXkF6jZKdVGwGIrQhY0hCasjZhn vWZzycADfsdGBkMjTj70kas= X-Received: by 2002:a17:902:822:: with SMTP id 31mr40550818plk.41.1557248351802; Tue, 07 May 2019 09:59:11 -0700 (PDT) Received: from mita-MS-7A45.lan ([240f:34:212d:1:1b24:991b:df50:ea3f]) by smtp.gmail.com with ESMTPSA id r12sm18140093pfn.144.2019.05.07.09.59.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 May 2019 09:59:10 -0700 (PDT) From: Akinobu Mita To: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Akinobu Mita , Johannes Berg , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Minwoo Im Subject: [PATCH v2 7/7] nvme-pci: trigger device coredump on command timeout Date: Wed, 8 May 2019 01:58:34 +0900 Message-Id: <1557248314-4238-8-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1557248314-4238-1-git-send-email-akinobu.mita@gmail.com> References: <1557248314-4238-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This enables the nvme driver to trigger a device coredump when command timeout occurs, and it helps diagnose and debug issues. This can be tested with fail_io_timeout fault injection. # echo 1 > /sys/kernel/debug/fail_io_timeout/probability # echo 1 > /sys/kernel/debug/fail_io_timeout/times # echo 1 > /sys/block/nvme0n1/io-timeout-fail # dd if=/dev/nvme0n1 of=/dev/null Cc: Johannes Berg Cc: Keith Busch Cc: Jens Axboe Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Minwoo Im Signed-off-by: Akinobu Mita --- - Make coredump procedure into two phases (before resetting controller and after resetting as soon as admin queue is available). drivers/nvme/host/pci.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 4684a86..4ff918f 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -87,9 +87,12 @@ MODULE_PARM_DESC(poll_queues, "Number of queues to use for polled IO."); struct nvme_dev; struct nvme_queue; -static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown); +static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown, bool dump); static bool __nvme_disable_io_queues(struct nvme_dev *dev, u8 opcode); +static int nvme_coredump_prologue(struct nvme_dev *dev); +static void nvme_coredump_epilogue(struct nvme_dev *dev); + /* * Represents an NVM Express device. Each nvme_dev is a PCI function. */ @@ -1289,7 +1292,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved) */ if (nvme_should_reset(dev, csts)) { nvme_warn_reset(dev, csts); - nvme_dev_disable(dev, false); + nvme_dev_disable(dev, false, true); nvme_reset_ctrl(&dev->ctrl); return BLK_EH_DONE; } @@ -1316,7 +1319,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved) dev_warn_ratelimited(dev->ctrl.device, "I/O %d QID %d timeout, disable controller\n", req->tag, nvmeq->qid); - nvme_dev_disable(dev, false); + nvme_dev_disable(dev, false, true); nvme_req(req)->flags |= NVME_REQ_CANCELLED; return BLK_EH_DONE; default: @@ -1332,7 +1335,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved) dev_warn(dev->ctrl.device, "I/O %d QID %d timeout, reset controller\n", req->tag, nvmeq->qid); - nvme_dev_disable(dev, false); + nvme_dev_disable(dev, false, true); nvme_reset_ctrl(&dev->ctrl); nvme_req(req)->flags |= NVME_REQ_CANCELLED; @@ -2399,7 +2402,7 @@ static void nvme_pci_disable(struct nvme_dev *dev) } } -static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown) +static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown, bool dump) { bool dead = true; struct pci_dev *pdev = to_pci_dev(dev->dev); @@ -2424,6 +2427,9 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown) nvme_wait_freeze_timeout(&dev->ctrl, NVME_IO_TIMEOUT); } + if (dump) + nvme_coredump_prologue(dev); + nvme_stop_queues(&dev->ctrl); if (!dead && dev->ctrl.queue_count > 0) { @@ -2491,7 +2497,7 @@ static void nvme_remove_dead_ctrl(struct nvme_dev *dev, int status) dev_warn(dev->ctrl.device, "Removing after probe failure status: %d\n", status); nvme_get_ctrl(&dev->ctrl); - nvme_dev_disable(dev, false); + nvme_dev_disable(dev, false, false); nvme_kill_queues(&dev->ctrl); if (!queue_work(nvme_wq, &dev->remove_work)) nvme_put_ctrl(&dev->ctrl); @@ -2513,7 +2519,7 @@ static void nvme_reset_work(struct work_struct *work) * moving on. */ if (dev->ctrl.ctrl_config & NVME_CC_ENABLE) - nvme_dev_disable(dev, false); + nvme_dev_disable(dev, false, false); mutex_lock(&dev->shutdown_lock); result = nvme_pci_enable(dev); @@ -2550,6 +2556,8 @@ static void nvme_reset_work(struct work_struct *work) if (result) goto out; + nvme_coredump_epilogue(dev); + if (dev->ctrl.oacs & NVME_CTRL_OACS_SEC_SUPP) { if (!dev->ctrl.opal_dev) dev->ctrl.opal_dev = @@ -2612,6 +2620,7 @@ static void nvme_reset_work(struct work_struct *work) out_unlock: mutex_unlock(&dev->shutdown_lock); out: + nvme_coredump_epilogue(dev); nvme_remove_dead_ctrl(dev, result); } @@ -2802,7 +2811,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) static void nvme_reset_prepare(struct pci_dev *pdev) { struct nvme_dev *dev = pci_get_drvdata(pdev); - nvme_dev_disable(dev, false); + nvme_dev_disable(dev, false, false); } static void nvme_reset_done(struct pci_dev *pdev) @@ -2814,7 +2823,7 @@ static void nvme_reset_done(struct pci_dev *pdev) static void nvme_shutdown(struct pci_dev *pdev) { struct nvme_dev *dev = pci_get_drvdata(pdev); - nvme_dev_disable(dev, true); + nvme_dev_disable(dev, true, false); } /* @@ -2831,14 +2840,14 @@ static void nvme_remove(struct pci_dev *pdev) if (!pci_device_is_present(pdev)) { nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_DEAD); - nvme_dev_disable(dev, true); + nvme_dev_disable(dev, true, false); nvme_dev_remove_admin(dev); } flush_work(&dev->ctrl.reset_work); nvme_stop_ctrl(&dev->ctrl); nvme_remove_namespaces(&dev->ctrl); - nvme_dev_disable(dev, true); + nvme_dev_disable(dev, true, false); nvme_release_cmb(dev); nvme_free_host_mem(dev); nvme_dev_remove_admin(dev); @@ -2855,7 +2864,7 @@ static int nvme_suspend(struct device *dev) struct pci_dev *pdev = to_pci_dev(dev); struct nvme_dev *ndev = pci_get_drvdata(pdev); - nvme_dev_disable(ndev, true); + nvme_dev_disable(ndev, true, false); return 0; } @@ -3307,7 +3316,7 @@ static pci_ers_result_t nvme_error_detected(struct pci_dev *pdev, case pci_channel_io_frozen: dev_warn(dev->ctrl.device, "frozen state error detected, reset controller\n"); - nvme_dev_disable(dev, false); + nvme_dev_disable(dev, false, false); return PCI_ERS_RESULT_NEED_RESET; case pci_channel_io_perm_failure: dev_warn(dev->ctrl.device, -- 2.7.4