[PATCH V3 4/8] nvme: add sysfs attribute to change IO timeout per nvme controller

Mohamed Khalfella mkhalfella at purestorage.com
Tue Apr 28 10:23:10 PDT 2026


On Fri 2026-04-10 09:39:20 +0200, Maurizio Lombardi wrote:
> Currently, there is no method to adjust the timeout values on a
> per controller basis with nvme I/O queues.
> Add an io_timeout attribute to nvme so that different nvme controllers
> which may have different timeout requirements can have custom
> I/O timeouts set.
> 
> Signed-off-by: Maurizio Lombardi <mlombard at redhat.com>
Reviewed-by: Mohamed Khalfella <mkhalfella at purestorage.com>

> diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
> index 000c29bd1f1f..1e6a0eecb30e 100644
> --- a/drivers/nvme/host/sysfs.c
> +++ b/drivers/nvme/host/sysfs.c
> @@ -664,6 +664,52 @@ static ssize_t nvme_admin_timeout_store(struct device *dev,
>  static DEVICE_ATTR(admin_timeout, S_IRUGO | S_IWUSR,
>  	nvme_admin_timeout_show, nvme_admin_timeout_store);
>  
> +static ssize_t nvme_io_timeout_show(struct device *dev,
> +			struct device_attribute *attr, char *buf)
> +{
> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%u\n", jiffies_to_msecs(ctrl->io_timeout));
> +}
> +
> +static ssize_t nvme_io_timeout_store(struct device *dev,
> +			struct device_attribute *attr,
> +			const char *buf, size_t count)
> +{
> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> +	struct nvme_ns *ns;
> +	u32 timeout;
> +	int err;
> +
> +	/*
> +	 * Wait until the controller reaches the LIVE state
> +	 * to be sure that connect_q is properly initialized.
> +	 */
> +	if (!test_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags))
> +		return -EBUSY;
> +
> +	err = kstrtou32(buf, 10, &timeout);
> +	if (err || !timeout)
> +		return -EINVAL;
> +
> +	/* Take the namespaces_lock to avoid racing against nvme_alloc_ns() */
> +	mutex_lock(&ctrl->namespaces_lock);
> +
> +	ctrl->io_timeout = msecs_to_jiffies(timeout);
> +	list_for_each_entry(ns, &ctrl->namespaces, list)
> +		blk_queue_rq_timeout(ns->queue, ctrl->io_timeout);
> +
> +	if (ctrl->connect_q)
> +		blk_queue_rq_timeout(ctrl->connect_q, ctrl->io_timeout);
> +
> +	mutex_unlock(&ctrl->namespaces_lock);

ctrl->namespaces_lock is not needed to set timeout for ctrl->connect_q.
Maybe move mutex_unlock() up just after iterating on namespaces?



More information about the Linux-nvme mailing list