Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp112060yba; Wed, 3 Apr 2019 05:36:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJcY4v6cujylD5tHMKa8/TTjXaO10wo/qJG40dHMsph6DknMzlYAT8p89umfEZm4xMzli6 X-Received: by 2002:a17:902:4681:: with SMTP id p1mr74303383pld.42.1554295005258; Wed, 03 Apr 2019 05:36:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554295005; cv=none; d=google.com; s=arc-20160816; b=ufm+P2BxMdkAajFsLDkW5VUZmOPE5aW0q1aPR1gqrNWv2tcrU3yYbkMRq6LRdBllmF IP3LlvKHOITND6islImLdI7TN/Jie+H5zUeCMGBiYxaTh5lhh3ZucQ+a7blggecApXeB Qbu9BUPJXE1DuDUyk4djUN9f/ujVB0CBKlWIjMbQy0XWs4TqSybPn+ujIA6IhgFF6ud5 8KT0bVMZ/YHEBXi07oZ9gTbtco7DbGKbj/ApY4DBALDb1t+z+KvQTQPwx0/HO/78mcs/ ZU+Or6AF+FeMqzK5o83og6ak2qH8UoMg6gYVHeUZkaPqfv4K2pLXMbKfDhV46ws/fs7J rm2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:mime-version:references:in-reply-to :message-id:date:subject:cc:from:dkim-signature; bh=JRqXds9ZAZm0HBSHKnSoHAwcXr7kzVx6HWdB7I8dzJE=; b=lB/Mq41z4gRL0jNKEDIlgZMBYu3XrlBQCam/iajN3xHwgJJmzXN1Jyb/n/Gpi/TXKT rbxVsNFmR0mv6EXiWu1P9Vi04L0P3pr/8/zDRY7oidQnppzC7WFUrgbBE05BBKHewow9 WlM4INmQsHutCjKSKnWUomjQ0M1faXRZPXp2QY5IPy4f+7YpyWdUzdnyXvOLFBrQLRxH WDhSlUm+RFw/C0U0SfHiJOjwPFK01obiz1BWmhrn+Z2kcKaS3th4k7tJMvZ6FHieQ7Pd AcYdfIxdJJyUsJXzZGj2VlCa/wrmOtAQ7ogaZ/WFs10wZsIaS/b0HIp0hqrhjWH6nDfg qRzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@amazon.de header.s=amazon201209 header.b=MEixlOLQ; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id be7si7236637plb.266.2019.04.03.05.36.29; Wed, 03 Apr 2019 05:36:45 -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=fail header.i=@amazon.de header.s=amazon201209 header.b=MEixlOLQ; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726360AbfDCMfv (ORCPT + 99 others); Wed, 3 Apr 2019 08:35:51 -0400 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:9305 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726155AbfDCMfv (ORCPT ); Wed, 3 Apr 2019 08:35:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1554294949; x=1585830949; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=JRqXds9ZAZm0HBSHKnSoHAwcXr7kzVx6HWdB7I8dzJE=; b=MEixlOLQfjTeH+Ib6UcO492ESNoI8RaY/iTmGMyy8Q0OM7uhr52OgtZI XXowfDC48W17wDo1598PJstoU9qWdWn2sSK9rDfbVFq0avPi2ldK+HL5G H4cnerIcmq/kkXWWQHIEeHgPL6MOhdmxpUk/BDhCvZ1fITsHEI062vUIw w=; X-IronPort-AV: E=Sophos;i="5.60,304,1549929600"; d="scan'208";a="669117285" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1a-715bee71.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 03 Apr 2019 12:35:48 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1a-715bee71.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id x33CZgx9028922 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Wed, 3 Apr 2019 12:35:45 GMT Received: from EX13D18EUA002.ant.amazon.com (10.43.165.184) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 3 Apr 2019 12:35:44 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D18EUA002.ant.amazon.com (10.43.165.184) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 3 Apr 2019 12:35:44 +0000 Received: from dev-dsk-mheyne-60001.pdx1.corp.amazon.com (10.184.85.242) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 3 Apr 2019 12:35:43 +0000 Received: by dev-dsk-mheyne-60001.pdx1.corp.amazon.com (Postfix, from userid 5466572) id EE04A29784; Wed, 3 Apr 2019 12:35:42 +0000 (UTC) From: Maximilian Heyne CC: David Woodhouse , Amit Shah , Maximilian Heyne , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , James Smart , , Subject: [PATCH v2 2/2] nvme: add sysfs controls for io and admin timeouts Date: Wed, 3 Apr 2019 12:35:06 +0000 Message-ID: <20190403123506.122904-3-mheyne@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190403123506.122904-1-mheyne@amazon.de> References: <20190403123506.122904-1-mheyne@amazon.de> MIME-Version: 1.0 Content-Type: text/plain To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add two sysfs files for reading and updating the admin and io timeouts of individual NVMe controllers. The controller must be in the LIVE or ADMIN_ONLY state for this to work so that setting timeouts doesn't race with the creation or deletion of tagset, admin_tagset, admin_q and connect_q of nvme_ctrl. Original-patch-by: Milan Pandurov Signed-off-by: Maximilian Heyne --- v2: - rework setting timeouts to work with all relevant nvme drivers - add check for state LIVE to not race with controller creation/deletion drivers/nvme/host/core.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index d0530bf7a677..51f359d78f17 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2768,6 +2768,116 @@ static ssize_t nvme_sysfs_rescan(struct device *dev, } static DEVICE_ATTR(rescan_controller, S_IWUSR, NULL, nvme_sysfs_rescan); +static int nvme_set_io_timeout(struct nvme_ctrl *ctrl, unsigned int timeout) +{ + struct nvme_ns *ns; + unsigned long flags; + int ret = -EBUSY; + + spin_lock_irqsave(&ctrl->lock, flags); + if (ctrl->state == NVME_CTRL_LIVE) { + ctrl->io_timeout = timeout; + if (ctrl->tagset) + ctrl->tagset->timeout = timeout; + if (ctrl->connect_q) + blk_queue_rq_timeout(ctrl->connect_q, timeout); + + down_write(&ctrl->namespaces_rwsem); + list_for_each_entry(ns, &ctrl->namespaces, list) { + blk_queue_rq_timeout(ns->queue, timeout); + } + up_write(&ctrl->namespaces_rwsem); + ret = 0; + } + spin_unlock_irqrestore(&ctrl->lock, flags); + return ret; +} + +static int nvme_set_admin_timeout(struct nvme_ctrl *ctrl, unsigned int timeout) +{ + unsigned long flags; + int ret = -EBUSY; + + spin_lock_irqsave(&ctrl->lock, flags); + if (ctrl->state == NVME_CTRL_LIVE || + ctrl->state == NVME_CTRL_ADMIN_ONLY) { + ctrl->admin_timeout = timeout; + ctrl->admin_tagset->timeout = timeout; + blk_queue_rq_timeout(ctrl->admin_q, timeout); + ret = 0; + } + spin_unlock_irqrestore(&ctrl->lock, flags); + return ret; +} + +static ssize_t io_timeout_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); + + return scnprintf(buf, PAGE_SIZE, "%u\n", ctrl->io_timeout / HZ); +} + +static ssize_t io_timeout_store(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); + unsigned int timeout; + int ret; + + ret = kstrtouint(buf, 10u, &timeout); + if (ret == -EINVAL) { + dev_warn(ctrl->dev, "Error parsing timeout value.\n"); + return ret; + } + if (ret == -ERANGE || timeout == 0 || timeout > UINT_MAX / HZ) { + dev_warn(ctrl->dev, + "Timeout value out of range (0 < timeout <= %u).\n", + UINT_MAX / HZ); + return -ERANGE; + } + ret = nvme_set_io_timeout(ctrl, timeout * HZ); + if (ret < 0) + return ret; + return count; +} +static DEVICE_ATTR_RW(io_timeout); + +static ssize_t admin_timeout_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); + + return scnprintf(buf, PAGE_SIZE, "%u\n", ctrl->admin_timeout / HZ); +} + +static ssize_t admin_timeout_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); + unsigned int timeout; + int ret; + + ret = kstrtouint(buf, 10u, &timeout); + if (ret == -EINVAL) { + dev_warn(ctrl->dev, "Error parsing timeout value.\n"); + return ret; + } + if (ret == -ERANGE || timeout == 0 || timeout > UINT_MAX / HZ) { + dev_warn(ctrl->dev, + "Timeout value out of range (0 < timeout <= %u).\n", + UINT_MAX / HZ); + return -ERANGE; + } + ret = nvme_set_admin_timeout(ctrl, timeout * HZ); + if (ret < 0) + return ret; + return count; +} +static DEVICE_ATTR_RW(admin_timeout); + static inline struct nvme_ns_head *dev_to_ns_head(struct device *dev) { struct gendisk *disk = dev_to_disk(dev); @@ -3008,6 +3118,8 @@ static struct attribute *nvme_dev_attrs[] = { &dev_attr_address.attr, &dev_attr_state.attr, &dev_attr_numa_node.attr, + &dev_attr_io_timeout.attr, + &dev_attr_admin_timeout.attr, NULL }; -- 2.16.5 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich Ust-ID: DE 289 237 879 Eingetragen am Amtsgericht Charlottenburg HRB 149173 B