From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 CF05436A01A for ; Sun, 12 Jul 2026 02:25:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783823144; cv=none; b=unHPkUG6HxdX90XUVy8unpvea0ElMhb/El5jmCpUHrMhQnTo495bHUGRrI75Kv+NeKIE5GvQiYEn7sPc8VIlLVFGD45fwnpC0Dt4tqk11JcPug6TknqQ92eYac9/O6CC/hXC0LCVj9UX9HPW5ijMjw2gZ5NVsgnalnHGvXPJMJU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783823144; c=relaxed/simple; bh=CmhZXORdMTm+BqCDSpuEkk4GAsdEqEMYNb9KnFJtPdQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XMrui7jASUEC2UndfHv17CagLCqfr4+VdbrWdw5JZMyD4yIFnsuLxnrvcg+AcOcjBVxU4/6juGvLrhhxeEOPt/OqVml9+C3FJ1f3NW/jat1xs4Q9kn/OeGwr4Fw1HX/JrHReNU/DuMq1RnrYIpZ2eibLuP1nGUpv47xPh1ZunfE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=purestorage.com; spf=pass smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=Ezs8cnVV; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=pass 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="Ezs8cnVV" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-37df72c9984so3678794a91.3 for ; Sat, 11 Jul 2026 19:25:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1783823142; x=1784427942; 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:content-type; bh=1HnswPJ/Ga8FPm48i1AzqQaejGi0bjeeJj42xEdxHH0=; b=Ezs8cnVVPUFFJTjG638m5aoeWvwwmEUo6C2Evhn5qwLo7+iPnMJOtaXJty00T4a+EQ 2XhnNTC9YZl3xE235IUhYW6fHOWEnbfV4s/koT99d5iwQto8eC/eCF1rAHp7FmUGe5E/ UH/O3ogOHoBBLBgC3tuLigPkfYTLpv3k4fMIlAMdJXQL3mFEtMYe6H/RYWw20Msk78Pg 4rf40L0acNriN2UkVLEctwiUeMDMN+jQGrr9mfW46OZFnaWo14ZJI2YHyVEGLLHUgkT1 Qdxwvef6Zuz7bZnDs/FV2UxmGQnhy85Z5Nm3L7YRJzKs5AP2ODlrjr6VNRMxxECTxHB6 qk1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783823142; x=1784427942; 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:content-type; bh=1HnswPJ/Ga8FPm48i1AzqQaejGi0bjeeJj42xEdxHH0=; b=Ia6seyQpWR15zlW3+lrT0sZolFLdRtj6hN8mEdwnzYAQ9ebmQLR9lUTztsEu8/kpKi M6mJXYQvAqdEXSJnnYpLagdfI7CTkKUwI2w0QRy0/tkJvled2X8b/SeS8VB/1KbtFbp7 NJq8Nw3kwcLkyxH72tDb4ttzP77qjq01e6N/Ryz1uWhZjknkh6DDTqsyBPNULeLHDX6s 5ytMkri2CKQF8QJOjbWF7d1pzH2d+PuZcQbVRS4AZ8oqDoF2CXac1iojcMclDCjbccTt PcKSXGD5Ha0iyKaWXcMIA8gqQ3hvZkcxX4nLNIH3ccgu4NlrhazzsWqz0eT+OiEi4o7t cgxA== X-Forwarded-Encrypted: i=1; AHgh+RorKko67BmmRgrQssomDUwku5QGilQ0z7RP7v3tahuEiyfoBC8smPL+aWguy26bLlcTa/lG2bFVp+Rs1OE=@vger.kernel.org X-Gm-Message-State: AOJu0Yyi2PP+9vTphBei7Jr+K5nRU0Ya6cT0b8Ii2oEbMGvxVFZcSgN/ ksrJAEsAn9Jq1C7XU3M3PQDIXLC7TgDDtJx5SaG6lgS0bvk2XwszcE3It6s+C1CxysY= X-Gm-Gg: AfdE7cmiwsQ81fTAtRhDA5mhkSO3Xssh/n0iDM80IZjoal3MnbftPiLqGLkfH9QUx5v Npb5oqQkhR2vOwnHHv63Fj9N9BCUximzeZ9dhguv26DEQF0ImpAq7T3xODw1LGy2a9jzJyx1vRv vRQtbXTPP2GTg0LFq7aFAy23gnnHLGZ0BA1SF2A6qbLKKhbJ1/ky0Uhjf7duKPyb+iqFLRm5iPz GYAGIAgmdoPDnJi+lKUVK6X/OBfr5XliQ7BsEVFLWjTAcoL0uKUjdabO6KAROXBwSrcK8fT75cu KZG6chSJP8bfzhPf/FBcNfbfSEnAD185rXb50WHaekqiGvj6nhbkcgqCuzTxng15z+7GXgAYlop fbswZCIN5B+56pBX+mt2HwvNY5ts30112Jws7yBhvKc2QqRJUdyZeQOPLwgRcWMVSQJip+H75d2 qfrzID X-Received: by 2002:a17:90b:4c49:b0:37d:ee77:78ac with SMTP id 98e67ed59e1d1-38dc774cd5cmr3948680a91.19.1783823141858; Sat, 11 Jul 2026 19:25:41 -0700 (PDT) Received: from ceto.lan ([2607:fb90:9c20:2264::1c31]) by smtp.googlemail.com with ESMTPSA id 5a478bee46e88-3117462f5c7sm60704693eec.0.2026.07.11.19.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jul 2026 19:25:40 -0700 (PDT) From: Mohamed Khalfella To: Justin Tee , Naresh Gottumukkala , Paul Ely , Chaitanya Kulkarni , Christoph Hellwig , Jens Axboe , Keith Busch , Sagi Grimberg , James Smart , Hannes Reinecke , Randy Jennings , Dhaval Giani Cc: Aaron Dailey , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Mohamed Khalfella Subject: [PATCH v5 14/16] nvme-fc: Hold inflight requests while in FENCING state Date: Sat, 11 Jul 2026 19:23:35 -0700 Message-ID: <20260712022437.3743117-15-mkhalfella@purestorage.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260712022437.3743117-1-mkhalfella@purestorage.com> References: <20260712022437.3743117-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: 8bit 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 03b6c3649210..006b5a984dfe 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -172,7 +172,7 @@ struct nvme_fc_ctrl { struct kref ref; unsigned long flags; - u32 iocnt; + atomic_t iocnt; wait_queue_head_t ioabort_wait; 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 |= FCOP_FLAGS_TERMIO; - ctrl->iocnt++; + atomic_inc(&ctrl->iocnt); } spin_unlock_irqrestore(&ctrl->lock, flags); @@ -1853,20 +1853,29 @@ nvme_fc_abort_aen_ops(struct nvme_fc_ctrl *ctrl) } static inline void +__nvme_fc_fcpop_count_one_down(struct nvme_fc_ctrl *ctrl) +{ + if (atomic_dec_return(&ctrl->iocnt) == 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 = false; if (opstate == 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 = true; } spin_unlock_irqrestore(&ctrl->lock, flags); } + + return ret; } 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 = &op->cmd_iu.sqe; __le16 status = cpu_to_le16(NVME_SC_SUCCESS << 1); union nvme_result result; - bool terminate_assoc = true; + bool op_term, terminate_assoc = true; + enum nvme_ctrl_state state; int opstate; /* @@ -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 = FCOP_FLAGS_AEN; /* clear other flags */ nvme_fc_ctrl_put(ctrl); goto check_error; } - __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 = __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 = nvme_ctrl_state(&ctrl->ctrl); + if (terminate_assoc && + (state == NVME_CTRL_LIVE || state == 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); check_error: if (terminate_assoc) @@ -2747,7 +2779,8 @@ nvme_fc_start_fcp_op(struct nvme_fc_ctrl *ctrl, struct nvme_fc_queue *queue, * cmd with the csn was supposed to arrive. */ opstate = 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); 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) spin_lock_irqsave(&ctrl->lock, flags); set_bit(FCCTRL_TERMIO, &ctrl->flags); - ctrl->iocnt = 0; + atomic_set(&ctrl->iocnt, 0); spin_unlock_irqrestore(&ctrl->lock, flags); __nvme_fc_abort_outstanding_ios(ctrl, false); @@ -3232,11 +3265,19 @@ nvme_fc_delete_association(struct nvme_fc_ctrl *ctrl) nvme_fc_abort_aen_ops(ctrl); /* wait for all io that had to be aborted */ + wait_event(ctrl->ioabort_wait, atomic_read(&ctrl->iocnt) == 0); spin_lock_irq(&ctrl->lock); - wait_event_lock_irq(ctrl->ioabort_wait, ctrl->iocnt == 0, ctrl->lock); clear_bit(FCCTRL_TERMIO, &ctrl->flags); spin_unlock_irq(&ctrl->lock); + /* + * 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); /* -- 2.54.0