Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Guixin Liu <kanie@linux.alibaba.com>
To: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
	Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	Nilay Shroff <nilay@linux.ibm.com>,
	Daniel Wagner <dwagner@suse.de>, Hannes Reinecke <hare@suse.de>
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH 3/4] nvmet-fc: clear the DMA address of the fod that failed mapping
Date: Tue,  1 Dec 2026 19:53:44 +0800	[thread overview]
Message-ID: <20261201115345.2349875-4-kanie@linux.alibaba.com> (raw)
In-Reply-To: <20261201115345.2349875-1-kanie@linux.alibaba.com>

When fc_dma_map_single() fails for one fod, nvmet_fc_prep_fcp_iodlist()
unmaps the preceding entries and clears their rspdma, but leaves the
DMA error value in the failing fod itself. The queue is still set up,
and nvmet_fc_destroy_fcp_iodlist() walks the whole fod array, so the
non-zero error value passes the "if (fod->rspdma)" check and is handed
to dma_unmap_single().

Clear rspdma on the failing fod as well.

Fixes: c53432030d86 ("nvme-fabrics: Add target support for FC transport")
Cc: stable@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---

Reproduced in a QEMU/KVM guest with nvme-fcloop and a test kernel
built with CONFIG_DMA_API_DEBUG=y. A TEST-ONLY injection in the test
tree (not part of this patch) fails the DMA mapping of the 4th fod in
nvmet_fc_prep_fcp_iodlist(). Because fcloop registers the target port
with dev=NULL, which turns the fc_dma_* wrappers into no-ops, the
injection also passes a real device with a 64-bit dma_mask so the
bogus unmap reaches the DMA API.

Unpatched: disconnect frees the queue and dma_unmap_single() is called
with DMA_MAPPING_ERROR; DMA-API reports "device driver tries to free
an invalid DMA memory address" (check_unmap). Patched, same injection:
the failing fod's rspdma is 0 at destroy time and error_count stays 0.
The connection stays live and IO passes in both cases, as the failing
fod is only removed from the free list.

Regression without the injection: fcloop connect, IO and disconnect
pass with no DMA-API errors.
 drivers/nvme/target/fc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index 4f4b30f5df573..42f8b17dee07b 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -635,6 +635,7 @@ nvmet_fc_prep_fcp_iodlist(struct nvmet_fc_tgtport *tgtport,
 		fod->rspdma = fc_dma_map_single(tgtport->dev, &fod->rspiubuf,
 					sizeof(fod->rspiubuf), DMA_TO_DEVICE);
 		if (fc_dma_mapping_error(tgtport->dev, fod->rspdma)) {
+			fod->rspdma = 0;
 			list_del(&fod->fcp_list);
 			for (fod--, i--; i >= 0; fod--, i--) {
 				fc_dma_unmap_single(tgtport->dev, fod->rspdma,
-- 
2.43.7



  parent reply	other threads:[~2026-12-01 11:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 11:53 [PATCH 0/4] nvme: small fixes from a drivers/nvme audit Guixin Liu
2026-12-01 11:53 ` [PATCH 1/4] nvme: guard nvme_strlen() against all-space strings Guixin Liu
2026-12-02  6:32   ` Christoph Hellwig
2026-12-01 11:53 ` [PATCH 2/4] nvme: trace the Set Features Save bit from the right position Guixin Liu
2026-12-02  6:32   ` Christoph Hellwig
2026-12-01 11:53 ` Guixin Liu [this message]
2026-12-02  6:32   ` [PATCH 3/4] nvmet-fc: clear the DMA address of the fod that failed mapping Christoph Hellwig
2026-12-01 11:53 ` [PATCH 4/4] nvme-fcloop: initialize port structures before publishing them Guixin Liu
2026-12-02  6:33   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201115345.2349875-4-kanie@linux.alibaba.com \
    --to=kanie@linux.alibaba.com \
    --cc=axboe@kernel.dk \
    --cc=dwagner@suse.de \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=nilay@linux.ibm.com \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox