From nobody Thu Apr 2 23:54:48 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 380C42BEC30 for ; Sat, 14 Feb 2026 04:28:33 +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=1771043320; cv=none; b=J3MI1v5GRAhgDPcC7SXrHOD3zQotCHcnFpE18xB8+v7ZTjxrXc1oLMBivrg2IQN5qs3gtyjXpD7MPOyWqXoMWxWzgR8ehlRQZNm+Blbja2k/c/8rCqhksalzNBMG8GDx70kSGbv8dTAPL453p4ueJl10QDHkeRl0tegT/ALcm2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771043320; c=relaxed/simple; bh=ESD4NgMJyYwcLca5Bppkico1E2KSIPGqq/sBl6nuGlE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BtfSw964F4aq5nHgntd3bK4ORWaWH5HLpO3qCbYBzVdPRDtnipIewkTLjthET/AdefI9HKRICMZ9fFlnHBvzEZ2yKbd9gqmZ96ZRW2NqonDLRGP9bhxlrQo2F0PsmksKLLcwFRYN0bycVOTG82rR3iU3gXqc45s2npKTNlvNlJ4= 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=Y9jUKH2Y; 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="Y9jUKH2Y" Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-124a635476fso2000845c88.0 for ; Fri, 13 Feb 2026 20:28:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1771043313; x=1771648113; 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=fq5iuFqiPF/Ft8LgP12Pou/FFdH+onXHL70j0HtoixQ=; b=Y9jUKH2YPz147uBV2ouqTAdj4gCF7SFktBN7pqFmKKMYX7ascWEy7/r1V60EgqbyJA 7c1LgdxZzQm8YSYajyefJTwdZhnHZjGLIhhnp9HXpxsFsa5UXM5HE/pXl2aZ7QnKhV06 IFvHS9n1bOh1JcAzB5vvC/KY2zf5ryTkIxicXOEHlrzeVmUdZ/T8iqKqr5ON4VT1GPYI n8P4U0J4SU+rge8YNFeD5H5xGgQq+dan0/e2LOJVLDybkQyUdikL9u/+4SzDFvxacqNG e30Rw1LO18lt9IShibBTdq4X5crM1g5xa5RvdaQtnpz2RXwowbSCDeNF/l4We+sF6RTk 5HGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771043313; x=1771648113; 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=fq5iuFqiPF/Ft8LgP12Pou/FFdH+onXHL70j0HtoixQ=; b=bDEvACjbvdT2Ox4VMDv2Qqw7Gs2xyCIFsUqOQAdOrGKUuC4akxxu2XpQAC1DUuDNhM ny25Tg8bdrpayfpBEMjwk0nJARQYNt80WMWFm/BU26KYYgyWswnwhFthYfvXN11Mhi+N BGlJ7Vhux62CyWNs8T4ffwpImxZhxygN+kcPpElZ2nuQ2fQevyrznswKOzBOC5hgg0fh Q3nN1oDgHebRpHLhgL408TFXl0+ZMAL9J6chaYx8vvqt/qWGjWA6Xv1l6SAbbe+oW7Te rPZwyAmc8lA6xby1Rwa5WavvooZex/grSEy+YaBpgbrjChN4GViOEzWkyxIjo6x04pQY k/1g== X-Forwarded-Encrypted: i=1; AJvYcCXjg8epIZ3eor81l0oAJEyY5s4sM+b1Guz5tvenedYQ2W81I9NflOea/zycubYacxbv5oPqjmoiGe3ylnM=@vger.kernel.org X-Gm-Message-State: AOJu0YzUWyV49fJNNg8PVMHeKqNR8Y62T/UMWJGYJU/FbuEDDo7ZaCem 6j9SLBfIX+h3NXU66Tn24ULtChFgB/s5QhvY7ZTtTiOor6aYvPgJuQqmov1LZY6KoKw= X-Gm-Gg: AZuq6aJKmhCEN4CQMsXlcb/5UbdpH4MFqJvW3Gg9/QHibzq6M+Y0V9J1lKHVn/oFb+x sna+focWX5O1S7cUNdTg35MBzB/YGMtygACoZ02KwIIcuXUG/gPtBays9sPn5lnHLSvQJQwnuKm Ktxa8NLbyaB1RaG0TQqz5GQ5FU108Fzmh20HfemtJ/MpoxfXHOcONtfFQ/pOvKGRakdwU/yln4S v+4WVytSL1TkzKVQJJeFcwtsuKLoI3nwIpAn+sbI2NBgrS9/EYnWuBvly7zoyHEBlQM5BlMZPV7 A5ghmL8DavliYLTvk9IuFQ2QQ9QXPC72pFzJa+Q9i8UlgeYod2unVOwOjjXtkrS8nJK8eQrq58o b1bS2Pr7Jw1ZxzHCxWYVeMKmBRZd8pzACjk8MMagaLIpQV7IpcDp0MvG877pnkGRITLekI36jDS 03NSvmLPqVtYNvIeTZONZJm2E3n6/6aPuNT3T+6l07pMukzQ== X-Received: by 2002:a05:7022:f102:b0:11d:f0d3:c5da with SMTP id a92af1059eb24-1273ae66557mr1331974c88.43.1771043312566; Fri, 13 Feb 2026 20:28:32 -0800 (PST) Received: from apollo.purestorage.com ([208.88.152.253]) by smtp.googlemail.com with ESMTPSA id a92af1059eb24-12742cbc900sm1021042c88.14.2026.02.13.20.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Feb 2026 20:28:32 -0800 (PST) From: Mohamed Khalfella To: Justin Tee , Naresh Gottumukkala , Paul Ely , Chaitanya Kulkarni , Christoph Hellwig , 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 v3 14/21] nvme-fc: Hold inflight requests while in FENCING state Date: Fri, 13 Feb 2026 20:25:15 -0800 Message-ID: <20260214042753.4073668-15-mkhalfella@purestorage.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260214042753.4073668-1-mkhalfella@purestorage.com> References: <20260214042753.4073668-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 --- 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 6ebabfb7e76d..e605dd3f4a40 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) @@ -1969,7 +1978,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 /* @@ -2102,16 +2112,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) @@ -2750,7 +2782,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); @@ -3219,7 +3252,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); @@ -3228,11 +3261,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