From nobody Thu Apr 2 15:41:43 2026 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 B8A5319CC0C for ; Sat, 28 Mar 2026 00:46:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774658776; cv=none; b=W4CAL47RplyY+n124fvXY5q72uf6S2Pa7cpDdVQBUm9kvCUesQJUsXJqC9nJ1sakCXfPGpxtz0lKgvg1RFTDKak1BvZMjW9MqTUC3oZ6SMOzxfcvQZvjHjc5uURDDB4yoqjtLQU/4U574ThSMBa9KKWz8E7KvcxtFQHkIrvQFBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774658776; c=relaxed/simple; bh=3+7rQnJk3Fb22evFyq39aviaS6XhWklwj+LajYtJcjs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XL68ATGg32ry1n7PyicxWJbz2FchzwlvaqE4vvNX+CArlSauAooFTqxdLSsC0q5WwrqKa4gsm6vpLi8EBvzw8ma6VC0p5SYTyXYGrS2Gg5t4HAUkNhtM1+sZqGduIhf10SnFLQkBDTrnnkR0/sYc8z1V8Aplj0RfGOmUntLSMUs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=YEIP0vS+; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="YEIP0vS+" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2b04d051664so22887005ad.0 for ; Fri, 27 Mar 2026 17:46:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1774658772; x=1775263572; 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=DRU+bZBKSxxT2z3L8VYfITXheQuE4BxzAm+ofkPTK8s=; b=YEIP0vS+XFvAoDFJ6zuXuzi4xGsPttZ36Q8NEfEyjfdNi7lrLJKu4AWWUo0QVFzE48 w0OHarzpZeVXHN4Mlla6qlydkocJsQjeNJmfvkzADh921mueh3JQbDsIfTVrckhz+ox1 xpcfC4+9UZ+04OdvoN39qP6/zPY8jZy+0964pJQZ3Y/m+MuvthDTnVTsXTSAdGEdt7te rZHr2cePj92gRjlJSbiKLOlH9JDSIwwghe8MhPnQDML4GBATmI/HVmPrGkFSwXaol8Ig nBVpTJ803V8uCgd1wfcJ21t2fbVbr7uqnpsWT/eSRy2H13blBDpyETLDuJzGGW6KR33R NHgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774658772; x=1775263572; 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=DRU+bZBKSxxT2z3L8VYfITXheQuE4BxzAm+ofkPTK8s=; b=PYUqCiIy4/mGnzMxyb9yZOkgX9hawRJ5A78ud9UdrbUXnmC8pL2dtYHup4rTSBLWbE UPMHtJZuxXttteQFX6kPh+emzKesS5ckyxOxunDEWmZtL3uwH/BCGbK61YuvY739MxdC RwiJULUWSojvLwBRh/134FspMIIEweABuPHoynmcsWYPgFHBJ+N/49uJLOsR34o9PDoS VZfgoOE4t9Bt1qPQz3LRtgZliW3X3caiQwxgBc4YO46Zz5+TJr1tP42uL4tAOprl1Kuc kO1KlifBY/QMgjRWe1hiNnxmkA+QgDZsviGHFfo9HN4vc/yO3c1ppl7WOy19h1cPZCUl JkWw== X-Forwarded-Encrypted: i=1; AJvYcCWP/vNcaNUDJVFtaW+OohAvKnOuZ5p36hGtsz/gawx0KcH7/2bfnHYEWTeOeekIpApDxzDa8wVGAUeUPmI=@vger.kernel.org X-Gm-Message-State: AOJu0YzGeAqEi41IArnnW/7BJZQ485R/itU/a0jCxMaalhmS10GHC7yY sBSrh5p13oJ3k9NiwRihuigoRAOv9nxraYvbdLlVUMMiThUA1t/t0NfFwlnxMPY2u5w= X-Gm-Gg: ATEYQzwqOdf0dv4Afs+MQrPUwZeTJ1rRUCKKsrRE6EYVVeuB2mLsNGfXdtCWEi2Iu+V oyVNa25eaq5ErjI8xYw07bYwGq+aCIiPxzTX/l+RrcjgFiu7DN382iQdlAM8deHs8VYw23AnE0R eaACE0fjNizht8twod4Dyb5u8x/ICG3ZBAsm+xbFRWiuEpYRBndHw8Yb2UMNZHmDzx3KsEKBf15 hcU16WaY80yG/UABmS5pYQ7oNCT0bAqlhK7zxgh13xMMS75guQXh4o23L0ndBVpp5dXqz9xYhtg ep+fpV849M2TXJgwZ7/bj8Xz9Zl74LhJeMXN/rei8hRCrPZgXDwoiHMV9NusSYaJUrgTbyciPC9 0EAaD2sr40IHIlmWfSmAWjxvveyJQMjHXBgIuZPfQ/AuN6Ss84dAy5I++MwJN87gIo/K1hrsux9 ddszJJ7Ac= X-Received: by 2002:a17:903:984:b0:2b0:58a8:5f9b with SMTP id d9443c01a7336-2b0cdd2137emr47738495ad.49.1774658771480; Fri, 27 Mar 2026 17:46:11 -0700 (PDT) Received: from ceto ([2601:640:8202:6fb0::9c63]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-2b242683064sm5342705ad.33.2026.03.27.17.46.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2026 17:46:11 -0700 (PDT) From: Mohamed Khalfella To: Justin Tee , Naresh Gottumukkala , Paul Ely , Chaitanya Kulkarni , Jens Axboe , Keith Busch , Sagi Grimberg , James Smart , Hannes Reinecke Cc: Aaron Dailey , Randy Jennings , Dhaval Giani , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Mohamed Khalfella Subject: [PATCH v4 14/15] nvme-fc: Hold inflight requests while in FENCING state Date: Fri, 27 Mar 2026 17:43:45 -0700 Message-ID: <20260328004518.1729186-15-mkhalfella@purestorage.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260328004518.1729186-1-mkhalfella@purestorage.com> References: <20260328004518.1729186-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" While in FENCING state, aborted inflight IOs should be held until fencing is done. Update nvme_fc_fcpio_done() to not complete aborted requests or requests with transport errors. These held requests will be canceled in nvme_fc_delete_association() after fencing is done. nvme_fc_fcpio_done() avoids racing with canceling aborted requests by making sure we complete successful requests before waking up the waiting thread. Signed-off-by: Mohamed Khalfella Signed-off-by: James Smart --- drivers/nvme/host/fc.c | 61 +++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c index 9f6b95415f25..eea5a90d936b 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -172,7 +172,7 @@ struct nvme_fc_ctrl { =20 struct kref ref; unsigned long flags; - u32 iocnt; + atomic_t iocnt; wait_queue_head_t ioabort_wait; =20 struct nvme_fc_fcp_op aen_ops[NVME_NR_AEN_COMMANDS]; @@ -1823,7 +1823,7 @@ __nvme_fc_abort_op(struct nvme_fc_ctrl *ctrl, struct = nvme_fc_fcp_op *op) atomic_set(&op->state, opstate); else if (test_bit(FCCTRL_TERMIO, &ctrl->flags)) { op->flags |=3D FCOP_FLAGS_TERMIO; - ctrl->iocnt++; + atomic_inc(&ctrl->iocnt); } spin_unlock_irqrestore(&ctrl->lock, flags); =20 @@ -1853,20 +1853,29 @@ nvme_fc_abort_aen_ops(struct nvme_fc_ctrl *ctrl) } =20 static inline void +__nvme_fc_fcpop_count_one_down(struct nvme_fc_ctrl *ctrl) +{ + if (atomic_dec_return(&ctrl->iocnt) =3D=3D 0) + wake_up(&ctrl->ioabort_wait); +} + +static inline bool __nvme_fc_fcpop_chk_teardowns(struct nvme_fc_ctrl *ctrl, struct nvme_fc_fcp_op *op, int opstate) { unsigned long flags; + bool ret =3D false; =20 if (opstate =3D=3D FCPOP_STATE_ABORTED) { spin_lock_irqsave(&ctrl->lock, flags); if (test_bit(FCCTRL_TERMIO, &ctrl->flags) && op->flags & FCOP_FLAGS_TERMIO) { - if (!--ctrl->iocnt) - wake_up(&ctrl->ioabort_wait); + ret =3D true; } spin_unlock_irqrestore(&ctrl->lock, flags); } + + return ret; } =20 static void nvme_fc_fencing_work(struct work_struct *work) @@ -1966,7 +1975,8 @@ nvme_fc_fcpio_done(struct nvmefc_fcp_req *req) struct nvme_command *sqe =3D &op->cmd_iu.sqe; __le16 status =3D cpu_to_le16(NVME_SC_SUCCESS << 1); union nvme_result result; - bool terminate_assoc =3D true; + bool op_term, terminate_assoc =3D true; + enum nvme_ctrl_state state; int opstate; =20 /* @@ -2099,16 +2109,38 @@ nvme_fc_fcpio_done(struct nvmefc_fcp_req *req) done: if (op->flags & FCOP_FLAGS_AEN) { nvme_complete_async_event(&queue->ctrl->ctrl, status, &result); - __nvme_fc_fcpop_chk_teardowns(ctrl, op, opstate); + if (__nvme_fc_fcpop_chk_teardowns(ctrl, op, opstate)) + __nvme_fc_fcpop_count_one_down(ctrl); atomic_set(&op->state, FCPOP_STATE_IDLE); op->flags =3D FCOP_FLAGS_AEN; /* clear other flags */ nvme_fc_ctrl_put(ctrl); goto check_error; } =20 - __nvme_fc_fcpop_chk_teardowns(ctrl, op, opstate); + /* + * We can not access op after the request is completed because it can + * be reused immediately. At the same time we want to wakeup the thread + * waiting for ongoing IOs _after_ requests are completed. This is + * necessary because that thread will start canceling inflight IOs + * and we want to avoid request completion racing with cancellation. + */ + op_term =3D __nvme_fc_fcpop_chk_teardowns(ctrl, op, opstate); + + /* + * If we are going to terminate associations and the controller is + * LIVE or FENCING, then do not complete this request now. Let error + * recovery cancel this request when it is safe to do so. + */ + state =3D nvme_ctrl_state(&ctrl->ctrl); + if (terminate_assoc && + (state =3D=3D NVME_CTRL_LIVE || state =3D=3D NVME_CTRL_FENCING)) + goto check_op_term; + if (!nvme_try_complete_req(rq, status, result)) nvme_fc_complete_rq(rq); +check_op_term: + if (op_term) + __nvme_fc_fcpop_count_one_down(ctrl); =20 check_error: if (terminate_assoc) @@ -2747,7 +2779,8 @@ nvme_fc_start_fcp_op(struct nvme_fc_ctrl *ctrl, struc= t nvme_fc_queue *queue, * cmd with the csn was supposed to arrive. */ opstate =3D atomic_xchg(&op->state, FCPOP_STATE_COMPLETE); - __nvme_fc_fcpop_chk_teardowns(ctrl, op, opstate); + if (__nvme_fc_fcpop_chk_teardowns(ctrl, op, opstate)) + __nvme_fc_fcpop_count_one_down(ctrl); =20 if (!(op->flags & FCOP_FLAGS_AEN)) { nvme_fc_unmap_data(ctrl, op->rq, op); @@ -3216,7 +3249,7 @@ nvme_fc_delete_association(struct nvme_fc_ctrl *ctrl) =20 spin_lock_irqsave(&ctrl->lock, flags); set_bit(FCCTRL_TERMIO, &ctrl->flags); - ctrl->iocnt =3D 0; + atomic_set(&ctrl->iocnt, 0); spin_unlock_irqrestore(&ctrl->lock, flags); =20 __nvme_fc_abort_outstanding_ios(ctrl, false); @@ -3225,11 +3258,19 @@ nvme_fc_delete_association(struct nvme_fc_ctrl *ctr= l) nvme_fc_abort_aen_ops(ctrl); =20 /* wait for all io that had to be aborted */ + wait_event(ctrl->ioabort_wait, atomic_read(&ctrl->iocnt) =3D=3D 0); spin_lock_irq(&ctrl->lock); - wait_event_lock_irq(ctrl->ioabort_wait, ctrl->iocnt =3D=3D 0, ctrl->lock); clear_bit(FCCTRL_TERMIO, &ctrl->flags); spin_unlock_irq(&ctrl->lock); =20 + /* + * At this point all inflight requests have been successfully + * aborted. Now it is safe to cancel all requests we decided + * not to complete in nvme_fc_fcpio_done(). + */ + nvme_cancel_tagset(&ctrl->ctrl); + nvme_cancel_admin_tagset(&ctrl->ctrl); + nvme_fc_term_aen_ops(ctrl); =20 /* --=20 2.52.0