[PATCH 3/4] nvmet-fc: clear the DMA address of the fod that failed mapping
Guixin Liu
kanie at linux.alibaba.com
Tue Dec 1 03:53:44 PST 2026
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 at vger.kernel.org
Signed-off-by: Guixin Liu <kanie at 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
More information about the Linux-nvme
mailing list