From nobody Mon Feb 9 18:59:54 2026 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B46C38A711 for ; Fri, 30 Jan 2026 22:36:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769812598; cv=none; b=WFBPPPeGFRcjDWEwifMnikifVSWw541+dAKx3h7P9hSOy280sfWIxMn1h3rqOLtVU9CzA/NuZ1i8I4whRdFLmWsCKf1mlRFsTJrjKN9+326yL5wjHzc98I5qSneZTpcsCSP4qNZIOBH9xkyvL9IqWBYk0jyIrCPMyjPwygkBqCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769812598; c=relaxed/simple; bh=KgdNhX+eTsfBJ/zKhAov0VGkz5Hffh5D9AH/hpozRPw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GRg7eeNb6s3Tvs2oqzhNbCG+VXjJNwB5u/Gon7p7SWX16cPla9xuanO5Smut4qFLHGWAOHhzT2otMJnn40VttVaBsobrbJlTR87eheQn+YAaFfnyeebNx0vHIwVdi6ZVSwMiSxDlJXXHnIhoPV+BsE+gV4yzKvSff4UoeLakx9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=QvkHPuer; arc=none smtp.client-ip=74.125.82.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="QvkHPuer" Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-1233c155a42so4518901c88.1 for ; Fri, 30 Jan 2026 14:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1769812591; x=1770417391; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UYqxizsivYL+kINzdcPOhMPZJZrAVTcG/K2aY25NvUc=; b=QvkHPuer1cxjtHq+jra8EUV/nO2qVh0Ee1P/jXaKk5T4yTBXodW7BoO45OLkBEb0NI 99+cbe6XQR9Vst24udXQ8F50UjMqq889J4C0LaY+/0ApjaEG0Fby4LBBb/zWxFuICQuB uYOI5N/CcYzYBAPMSbXvPpUuwmZLCpsNWfCGquFUkrTrASQP011GEBVA+ckstrOLtkFq XNq0SX5Mo09p0+oT5Kiw5dX2PZUxAGo6zO3ZPsdjs/mJOU9Mu2RuN/pDHvfHYuhgBWEj Fe/+t//vSY9wFBJeCbNSQL14XJmx3b18UVJlhKCUsBRzmMh+B4Pk+S2r+5MwmLQMhxE+ LLKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769812591; x=1770417391; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UYqxizsivYL+kINzdcPOhMPZJZrAVTcG/K2aY25NvUc=; b=Y3RaWtvBTL9IWpK18SqDBHT2x5nMiaMNDUAQiTymbSNaesAmCP8wxyQUiT/WNXVTq6 2VibS0sMy6OyoGDjFW/XDK+AVptkp4CXIF5cW+z5NUrpkf4pXC0oUKLmfAqT9r9caHKS 0IInDZSE9wnWMVNfuf5vuB/Cr6mcYffF7hVAFEQ0DcIdbs5PIVR0Tnspot/SvQP4nwlv BuwN4NWYxqtfFmkPId0O7k1yLw5hUv3CELfdemNnVWpUH/SZGH50jXFNPx8g6oYZUkkO /ihWLSDxkBXJ5CTIHAqHQIxG9ADL+br1sKLCoD1W3W58VpLePOE6RY6pO80HY7bQkvet aijw== X-Forwarded-Encrypted: i=1; AJvYcCVPgHpEdjaZQ7YIzq+OK/R+4a99h4F2aFMfh3+udGLm7stOumvfpMnuNl0UMcyu/484PKZcPSm6Oock0cc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5J6yLKUVitb6zeGs8RAY6ZwpXidsiNPLWBcwVxlMwe78xlk57 IRvE2LB58kumW9QGkOetIPx45YN4vtdMFBX/GuTbWGKx1e/w+m87eXlAKl/XS+gTAas= X-Gm-Gg: AZuq6aKPAb3Hmqmy5fwGoV0+DVPvwQVIENmf1LEgLPdYTsRzRvl2tPv4tCh5VLoD+RQ MoBQOFhIQwJbbtufOmOqpSzXSGI/rhMQCvsffFLJilYIpFqGite7nTBK44U4xgMDotS4WlpDzTz qZUvyCTI/kd+pdS9GYRjhGCG0t2VwtyvU3hP+ICSrdWcwoy8C9jl2RlurU69TCYkWlE2JFAu4QY YuUc0f6KrI7gp8bSj3neQK8LdqTf8odCjx82PCrw0VMFN1hvGp2lgeq76BTQKQZREyzqcmsgPbO 5iY6EaEHDaeJA09MCaJ/Jzl6onj2rLnrtEt7aLCTVFSwyLdAB9ynYIBPiCUS6j1DxZbMmkXSye4 fOTrVgaoB4WLlwr4ee3fGlHzJle6TBzENb/MWgPm5C6yJ5uzeTJKjKLAQ2Ull2FW3UnBGTlCZS9 Pc0lhj3/kJ2/my+iOveInQ2uc+ecmPq2rA9w== X-Received: by 2002:a05:7022:226:b0:122:a2:ffcd with SMTP id a92af1059eb24-125c0feb1f8mr2186268c88.23.1769812591032; Fri, 30 Jan 2026 14:36:31 -0800 (PST) Received: from apollo.purestorage.com ([208.88.152.253]) by smtp.googlemail.com with ESMTPSA id a92af1059eb24-124a9d6b906sm13161717c88.4.2026.01.30.14.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jan 2026 14:36:30 -0800 (PST) From: Mohamed Khalfella To: Justin Tee , Naresh Gottumukkala , Paul Ely , Chaitanya Kulkarni , Christoph Hellwig , Jens Axboe , Keith Busch , Sagi Grimberg Cc: Aaron Dailey , Randy Jennings , Dhaval Giani , Hannes Reinecke , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Mohamed Khalfella Subject: [PATCH v2 08/14] nvme: Implement cross-controller reset recovery Date: Fri, 30 Jan 2026 14:34:12 -0800 Message-ID: <20260130223531.2478849-9-mkhalfella@purestorage.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260130223531.2478849-1-mkhalfella@purestorage.com> References: <20260130223531.2478849-1-mkhalfella@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A host that has more than one path connecting to an nvme subsystem typically has an nvme controller associated with every path. This is mostly applicable to nvmeof. If one path goes down, inflight IOs on that path should not be retried immediately on another path because this could lead to data corruption as described in TP4129. TP8028 defines cross-controller reset mechanism that can be used by host to terminate IOs on the failed path using one of the remaining healthy paths. Only after IOs are terminated, or long enough time passes as defined by TP4129, inflight IOs should be retried on another path. Implement core cross-controller reset shared logic to be used by the transports. Signed-off-by: Mohamed Khalfella --- drivers/nvme/host/constants.c | 1 + drivers/nvme/host/core.c | 129 ++++++++++++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 9 +++ 3 files changed, 139 insertions(+) diff --git a/drivers/nvme/host/constants.c b/drivers/nvme/host/constants.c index dc90df9e13a2..f679efd5110e 100644 --- a/drivers/nvme/host/constants.c +++ b/drivers/nvme/host/constants.c @@ -46,6 +46,7 @@ static const char * const nvme_admin_ops[] =3D { [nvme_admin_virtual_mgmt] =3D "Virtual Management", [nvme_admin_nvme_mi_send] =3D "NVMe Send MI", [nvme_admin_nvme_mi_recv] =3D "NVMe Receive MI", + [nvme_admin_cross_ctrl_reset] =3D "Cross Controller Reset", [nvme_admin_dbbuf] =3D "Doorbell Buffer Config", [nvme_admin_format_nvm] =3D "Format NVM", [nvme_admin_security_send] =3D "Security Send", diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 3e1e02822dd4..13e0775d56b4 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -554,6 +554,134 @@ void nvme_cancel_admin_tagset(struct nvme_ctrl *ctrl) } EXPORT_SYMBOL_GPL(nvme_cancel_admin_tagset); =20 +static struct nvme_ctrl *nvme_find_ctrl_ccr(struct nvme_ctrl *ictrl, + u32 min_cntlid) +{ + struct nvme_subsystem *subsys =3D ictrl->subsys; + struct nvme_ctrl *sctrl; + unsigned long flags; + + mutex_lock(&nvme_subsystems_lock); + list_for_each_entry(sctrl, &subsys->ctrls, subsys_entry) { + if (sctrl->cntlid < min_cntlid) + continue; + + if (atomic_dec_if_positive(&sctrl->ccr_limit) < 0) + continue; + + spin_lock_irqsave(&sctrl->lock, flags); + if (sctrl->state !=3D NVME_CTRL_LIVE) { + spin_unlock_irqrestore(&sctrl->lock, flags); + atomic_inc(&sctrl->ccr_limit); + continue; + } + + /* + * We got a good candidate source controller that is locked and + * LIVE. However, no guarantee sctrl will not be deleted after + * sctrl->lock is released. Get a ref of both sctrl and admin_q + * so they do not disappear until we are done with them. + */ + WARN_ON_ONCE(!blk_get_queue(sctrl->admin_q)); + nvme_get_ctrl(sctrl); + spin_unlock_irqrestore(&sctrl->lock, flags); + goto found; + } + sctrl =3D NULL; +found: + mutex_unlock(&nvme_subsystems_lock); + return sctrl; +} + +static void nvme_put_ctrl_ccr(struct nvme_ctrl *sctrl) +{ + atomic_inc(&sctrl->ccr_limit); + blk_put_queue(sctrl->admin_q); + nvme_put_ctrl(sctrl); +} + +static int nvme_issue_wait_ccr(struct nvme_ctrl *sctrl, struct nvme_ctrl *= ictrl) +{ + struct nvme_ccr_entry ccr =3D { }; + union nvme_result res =3D { 0 }; + struct nvme_command c =3D { }; + unsigned long flags, tmo; + int ret =3D 0; + u32 result; + + init_completion(&ccr.complete); + ccr.ictrl =3D ictrl; + + spin_lock_irqsave(&sctrl->lock, flags); + list_add_tail(&ccr.list, &sctrl->ccr_list); + spin_unlock_irqrestore(&sctrl->lock, flags); + + c.ccr.opcode =3D nvme_admin_cross_ctrl_reset; + c.ccr.ciu =3D ictrl->ciu; + c.ccr.icid =3D cpu_to_le16(ictrl->cntlid); + c.ccr.cirn =3D cpu_to_le64(ictrl->cirn); + ret =3D __nvme_submit_sync_cmd(sctrl->admin_q, &c, &res, + NULL, 0, NVME_QID_ANY, 0); + if (ret) + goto out; + + result =3D le32_to_cpu(res.u32); + if (result & 0x01) /* Immediate Reset Successful */ + goto out; + + tmo =3D msecs_to_jiffies(max(ictrl->cqt, ictrl->kato * 1000)); + if (!wait_for_completion_timeout(&ccr.complete, tmo)) { + ret =3D -ETIMEDOUT; + goto out; + } + + if (ccr.ccrs !=3D NVME_CCR_STATUS_SUCCESS) + ret =3D -EREMOTEIO; +out: + spin_lock_irqsave(&sctrl->lock, flags); + list_del(&ccr.list); + spin_unlock_irqrestore(&sctrl->lock, flags); + return ret; +} + +unsigned long nvme_fence_ctrl(struct nvme_ctrl *ictrl) +{ + unsigned long deadline, now, timeout; + struct nvme_ctrl *sctrl; + u32 min_cntlid =3D 0; + int ret; + + timeout =3D nvme_fence_timeout_ms(ictrl); + dev_info(ictrl->device, "attempting CCR, timeout %lums\n", timeout); + + now =3D jiffies; + deadline =3D now + msecs_to_jiffies(timeout); + while (time_before(now, deadline)) { + sctrl =3D nvme_find_ctrl_ccr(ictrl, min_cntlid); + if (!sctrl) { + /* CCR failed, switch to time-based recovery */ + return deadline - now; + } + + ret =3D nvme_issue_wait_ccr(sctrl, ictrl); + if (!ret) { + dev_info(ictrl->device, "CCR succeeded using %s\n", + dev_name(sctrl->device)); + nvme_put_ctrl_ccr(sctrl); + return 0; + } + + /* CCR failed, try another path */ + min_cntlid =3D sctrl->cntlid + 1; + nvme_put_ctrl_ccr(sctrl); + now =3D jiffies; + } + + dev_info(ictrl->device, "CCR reached timeout, call it done\n"); + return 0; +} +EXPORT_SYMBOL_GPL(nvme_fence_ctrl); + bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, enum nvme_ctrl_state new_state) { @@ -5119,6 +5247,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct dev= ice *dev, =20 mutex_init(&ctrl->scan_lock); INIT_LIST_HEAD(&ctrl->namespaces); + INIT_LIST_HEAD(&ctrl->ccr_list); xa_init(&ctrl->cels); ctrl->dev =3D dev; ctrl->ops =3D ops; diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 00866bbc66f3..fa18f580d76a 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -279,6 +279,13 @@ enum nvme_ctrl_flags { NVME_CTRL_FROZEN =3D 6, }; =20 +struct nvme_ccr_entry { + struct list_head list; + struct completion complete; + struct nvme_ctrl *ictrl; + u8 ccrs; +}; + struct nvme_ctrl { bool comp_seen; bool identified; @@ -296,6 +303,7 @@ struct nvme_ctrl { struct blk_mq_tag_set *tagset; struct blk_mq_tag_set *admin_tagset; struct list_head namespaces; + struct list_head ccr_list; struct mutex namespaces_lock; struct srcu_struct srcu; struct device ctrl_device; @@ -814,6 +822,7 @@ blk_status_t nvme_host_path_error(struct request *req); bool nvme_cancel_request(struct request *req, void *data); void nvme_cancel_tagset(struct nvme_ctrl *ctrl); void nvme_cancel_admin_tagset(struct nvme_ctrl *ctrl); +unsigned long nvme_fence_ctrl(struct nvme_ctrl *ctrl); bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, enum nvme_ctrl_state new_state); int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown); --=20 2.52.0