nvmet: fix data_len to 0 for bdev-backed write_zeroes
Subsystems (2)
PATCH 1/1 nvmet: fix data_len to 0 for bdev-backed write_zeroes
The WRITE ZEROES command has no data transfer so that we need to initialize the struct (nvmet_req *req)->data_len to 0x0. While (nvmet_req *req)->transfer_len is initialized in nvmet_req_init(), data_len will be initialized by nowhere which might cause the failure with status code NVME_SC_SGL_INVALID_DATA | NVME_SC_DNR randomly. It's because nvmet_req_execute() checks like:
if (unlikely(req->data_len != req->transfer_len)) {
req->error_loc = offsetof(struct nvme_common_command, dptr);
nvmet_req_complete(req, NVME_SC_SGL_INVALID_DATA | NVME_SC_DNR);
} else
req->execute(req);This patch fixes req->data_len not to be a randomly assigned by initializing it to 0x0 when preparing the command in nvmet_bdev_parse_io_cmd().
nvmet_file_parse_io_cmd() which is for file-backed I/O has already initialized the data_len field to 0x0, though.
--- drivers/nvme/target/io-cmd-bdev.c | 1 + 1 file changed, 1 insertion(+)
drivers/nvme/target/io-cmd-bdev.c +1 -0
@@ -293,6 +293,7 @@ u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req)return 0 ;case nvme_cmd_write_zeroes: req->execute = nvmet_bdev_execute_write_zeroes; + req->data_len =0 ;return 0 ;default : pr_err("unhandled cmd %d on qid %d\n", cmd->common.opcode,
Signature · 1 line
2.21.0
Sagi Grimberg
maintainerPATCH 1/1 nvmet: fix data_len to 0 for bdev-backed write_zeroes
Is this a regression? IIRC write-zeros used to work...
PATCH 1/1 nvmet: fix data_len to 0 for bdev-backed write_zeroes
Quoted 1 line · Sagi Grimberg
Is this a regression? IIRC write-zeros used to work...
Hi Sagi,
The following outputs are a looping basic tests with a single command:
(I think you can find the commands will easily be failed.)
root at target:~# nvme list-subsys
nvme-subsys0 - NQN=nqn.2014.08.org.nvmexpress:80861af4foo QEMU NVMe Ctrl
\
+- nvme0 pcie 0000:00:04.0 live
nvme-subsys1 - NQN=test
\
+- nvme1 loop live
root at target:~# nvme write-zeroes /dev/nvme1n1 NVME Write Zeroes Success
root at target:~# nvme write-zeroes /dev/nvme1n1 NVME Write Zeroes Success
root at target:~# nvme write-zeroes /dev/nvme1n1 NVME Write Zeroes Success
root at target:~# nvme write-zeroes /dev/nvme1n1 NVMe status: Unknown(0x600f)
root at target:~# nvme write-zeroes /dev/nvme1n1 NVME Write Zeroes Success
root at target:~#
The write-zeroes command has been requested with SLBA 0 and NLB 0 as a default options. This might happen with status code 0x600f which is NVME_SC_SGL_INVALID_DATA | NVME_SC_DNR which happened due to:
req->data_len != req->transfer_len
The transfer_len is always 0x0 for write-zeroes, but data-len is never initialized in this case.
Please correct me if I'm wrong here.
Thanks,
PATCH 1/1 nvmet: fix data_len to 0 for bdev-backed write_zeroes
In reply to Minwoo ImThanks for the fix.
Quoted 40 lines · Minwoo Im
The WRITE ZEROES command has no data transfer so that we need to initialize the struct (
nvmet_req*req)->data_len to0x0. While (nvmet_req*req)->transfer_len is initialized innvmet_req_init(),data_lenwill be initialized by nowhere which might cause the failure with status codeNVME_SC_SGL_INVALID_DATA|NVME_SC_DNRrandomly. It's becausenvmet_req_execute()checks like:if (unlikely(req->data_len != req->transfer_len)) { req->error_loc = offsetof(struct nvme_common_command, dptr); nvmet_req_complete(req, NVME_SC_SGL_INVALID_DATA | NVME_SC_DNR); } else req->execute(req);This patch fixes
req->data_lennot to be a randomly assigned by initializing it to0x0when preparing the command innvmet_bdev_parse_io_cmd().
nvmet_file_parse_io_cmd()which is for file-backed I/O has already initialized thedata_lenfield to0x0, though.Cc Christoph Hellwig <hch at lst.de>Cc Sagi Grimberg <sagi at grimberg.me>Cc Chaitanya Kulkarni <Chaitanya.Kulkarni at wdc.com>Signed-off-by Minwoo Im <minwoo.im.dev at gmail.com>--- drivers/nvme/target/io-cmd-bdev.c | 1 + 1 file changed, 1 insertion(+)drivers/nvme/target/io-cmd-bdev.c +1
-0@@ -293,6 +293,7 @@ u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req)return 0 ;case nvme_cmd_write_zeroes: req->execute = nvmet_bdev_execute_write_zeroes; + req->data_len =0 ;return 0 ;default : pr_err("unhandled cmd %d on qid %d\n", cmd->common.opcode,
Christoph Hellwig
maintainerPATCH 1/1 nvmet: fix data_len to 0 for bdev-backed write_zeroes
In reply to Minwoo ImLooks good,