From nobody Mon Feb 9 15:09:59 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 96C6138A728 for ; Fri, 30 Jan 2026 22:36:39 +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=1769812602; cv=none; b=p8MCADw2APqsGMvliD3+ssi8HVaaIp2s1IuXcyx25b69jbd5ZFzJhcFH2Jc58KJs86CJ4MoMkka/oh99An/UbYBeaG1KiA41X5QIaNruq97CDm6nlQxMfEqGiQEI2Yk6ifm/829jgDpkTOdJTer3qhNJ1C02ezzQo44alcCdlyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769812602; c=relaxed/simple; bh=A3a9+lNSV5q/BViqrvDsILGTGgIv9R2feUK05w7o6HI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=imXpWh1eOnEIlAqRpsZ84ci4k53RMTlyOrVMN66v0GN/QlSLZFtLAWxqnYddOc01ewuV1BIlIOCPNvFfI0bmNu0bf3TEpPXaQm2F9WWdhFfr0yCsqHoXxoV+kfkD2T+SAWRMdM6yt97HkHfgbExNvMSgQj9nuTNmmaWfUhU0wKM= 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=fnsrmpXd; 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="fnsrmpXd" Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-1233b953bebso3581380c88.1 for ; Fri, 30 Jan 2026 14:36:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1769812597; x=1770417397; 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=uTBUoAOZYxgVE0n+ViXy9ucpXp3tnYCH0vZJ2uE2fAg=; b=fnsrmpXdcHvDTI7kcoxNTkY6VznpnBfOZzMduadPjpLphUP99OX+Ab1Fi6h/lSiJiQ q0KwFzUpetTsXT4Muq5lPDr8b3rRmTTMHgqwcNw0grLjX8Tf+Pta60ZY8nbjrWlUtbdT UTGqdW+Nv2z4M7UDVVBjYjNPw+E2zzOOUYNewsLeqC1TjzyOczx3H77dgSSmFmmzXosw VbJF3hsv+xBf9tm4Y1kJq6DmwdcFgnk/Jk5wOywlWFlgXR8/e2o+G1ulT7AlBI1arErH KXaw1Gl6HsQM8B7c+2FzX48xZJQ6zCRrCIABAJwPS4CMH9RMnNv+dZyT2WQth+l75fVJ zanw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769812597; x=1770417397; 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=uTBUoAOZYxgVE0n+ViXy9ucpXp3tnYCH0vZJ2uE2fAg=; b=V7I0bYKn37DXeCQ2G57olM+bq2jmNirCcBDf+PzwUWQyA5xFouVRrMU0j+jZ118Crp mt2jTQZ6i0fLZg94N2fbcOg7KgcQWSsnak0f97OAt1ycFWK+/h144YBGeLLcf69X/B3m Tzm0QUTHZC3AQurho7DJeUwVEHP4cogU6T9jQ3pR7QE2KdVdaTS26js6R0+thF92hppM CtphXIay7lqt0btwT8IfWnPiqCoBY4bWXnFBR9UewSh6eeFVleJjw+IYErd9AFn3qKM8 /gqzNTd1jKceYANNcutX8ltmSV139DRiBcjJuZ1g0r0Y4jXRdFOlIjbo+ObVMMPAqvhC M3pA== X-Forwarded-Encrypted: i=1; AJvYcCVZ1UBYFLoCABDvw0s9tvaDtOxGhPgfuEFtYJ4tMC8rGumCkW7E+9lh3aC89zwQMfM9/8mkm3LwQ/AoKTk=@vger.kernel.org X-Gm-Message-State: AOJu0Yyw/QqeoYNxd9MwXsvphvZ00LvOhX2k3lvq87zPB8FXbZFszu89 TiCNIoWKzVcrtSThLaxpsUFADZkLEJkiZXwOW6PDY3VxneZVRgnwBSwgzZgAXlsYo/Y= X-Gm-Gg: AZuq6aLDZgOkuEPzF5xqHzglxasmfldg65AMaelnVCmU7vk+XkUmtF1iP5fg+1tHdLB Q/aJidErboIbLOLBqkSuwqWzPlsuYCMSfMgXyO7sr0CKsu4NXVqmJ6RIWnur8uCs+gb9Zr4PADh MFEhjpeAiNZlBsFTkW9tsOFhqXv5eMm4/GCxWkeTHNe1zlSA+QS2bppfYHwC8TTmnptl0r8V6Uw GLR03Ef/vHhYYNuy1ImMUhHwEoj075w70aIVWV8Q6lLYjErBvWVnF56Ev0V7+mqSNSlfjz4XyHg r2qfzMkvjnZ9VpkCSTcBEiYbdVKBctA2eB2nzSq3j8gtdbq+eFs3didHQSFclOyFCYbjTkLYPV2 NsUt3y9eBJNmdFFTDcWiXGf7jqz1K9T/2JwcRCzjTIOKKJZFl6aCxuIHpecmaD54vWuJm0qMcvd /fCt5qc975d634HCxktyj8LF8jkTTpZq2U0A== X-Received: by 2002:a05:7022:6709:b0:11b:9386:7ed3 with SMTP id a92af1059eb24-125c10298e3mr2035531c88.48.1769812596583; Fri, 30 Jan 2026 14:36:36 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jan 2026 14:36:36 -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 14/14] nvme-fc: Hold inflight requests while in FENCING state Date: Fri, 30 Jan 2026 14:34:18 -0800 Message-ID: <20260130223531.2478849-15-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" 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 3a01aeb39081..122ebd7085b1 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -173,7 +173,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]; @@ -1822,7 +1822,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 @@ -1852,20 +1852,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_fenced_work(struct work_struct *work) @@ -1973,7 +1982,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 /* @@ -2106,16 +2116,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) @@ -2754,7 +2786,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); @@ -3223,7 +3256,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); @@ -3232,11 +3265,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