nvmet: fix nvmet_execute_write_zeroes function
Subsystems (3)
PATCH v2 1/1 nvmet: fix nvmet_execute_write_zeroes function
When trying to issue write_zeroes command against TARGET with a 4K block size, it ends up hitting the following condition at __blkdev_issue_zeroout:
if ((sector | nr_sects) & bs_mask)
return -EINVAL;
Causing the command to always fail.
Considering we need to add 1 to get the correct block count, that addition needs to be performed in the native format, so we moved the +1 to within le16_to_cpu prior to converting to 512b.
--- drivers/nvme/target/io-cmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/target/io-cmd.c +2 -2
@@ -173,8 +173,8 @@ static void nvmet_execute_write_zeroes(struct nvmet_req *req) sector =le64_to_cpu (write_zeroes->slba) << (req->ns->blksize_shift -9 ); - nr_sector = (((sector_t )le16_to_cpu (write_zeroes->length)) << - (req->ns->blksize_shift -9 )) +1 ; + nr_sector = (((sector_t )le16_to_cpu (write_zeroes->length +1 )) << + (req->ns->blksize_shift -9 ));if (__blkdev_issue_zeroout (req->ns->bdev, sector, nr_sector,GFP_KERNEL , &bio,0 ))
Signature · 1 line
2.7.4
Quoted 21 lines · Rodrigo R. Galvao
When trying to issue
write_zeroescommand against TARGET with a 4K block size, it ends up hitting the following condition at__blkdev_issue_zeroout:if ((sector |
nr_sects) &bs_mask)
return-EINVAL;Causing the command to always fail.
Considering we need to add 1 to get the correct block count, that addition needs to be performed in the native format, so we moved the +1 to withinle16_to_cpuprior to converting to 512b.Signed-off-by Rodrigo R. Galvao <[email protected]>--- drivers/nvme/target/io-cmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/nvme/target/io-cmd.c +0
-0
drivers/nvme/target/io-cmd.c static void nvmet_execute_write_zeroes(struct nvmet_req *req) · line 177
Quoted 7 lines
drivers/nvme/target/io-cmd.c +2
-2@@ -173,8 +173,8 @@ static void nvmet_execute_write_zeroes(struct nvmet_req *req) sector =le64_to_cpu (write_zeroes->slba) << (req->ns->blksize_shift -9 ); - nr_sector = (((sector_t )le16_to_cpu (write_zeroes->length)) << - (req->ns->blksize_shift -9 )) +1 ; + nr_sector = (((sector_t )le16_to_cpu (write_zeroes->length +1 )) << + (req->ns->blksize_shift -9 ));
I'm terribly sorry, but the +1 actually needs to be outside the le16_to_cpu. The above will work on little-endian machines, but not big.
Quoted 2 lines
I'm terribly sorry, but the +1 actually needs to be outside the
le16_to_cpu. The above will work on little-endian machines, but not big.
No problem at all. Thank you for helping on this.
I'm going to send a V3 with this change.
Signature · 2 lines
Rodrigo R. Galv?o Intern - Linux Technology Center - IBM
PATCH v2 1/1 nvmet: fix nvmet_execute_write_zeroes function
In reply to Rodrigo R. GalvaoHi "Rodrigo R. Galvao".
[This is an automated email]
This commit has been processed by the -stable helper bot and determined to be a high probability candidate for -stable trees. (score: 6.9916)
The bot has tested the following trees: v4.15.15, v4.14.32, v4.9.92, v4.4.126,
v4.15.15: Build OK!
v4.14.32: Build OK!
v4.9.92: Failed to apply! Possible dependencies:
d262920998c8: ("nvmet: add support for the Write Zeroes command") 78ce3daa7d70: ("nvmet: fix byte swap in nvmet_execute_write_zeroes")
d262920998c8: ("nvmet: add support for the Write Zeroes command")
v4.4.126: Failed to apply! Possible dependencies:
d262920998c8: ("nvmet: add support for the Write Zeroes command")
a07b4970f464: ("nvmet: add a generic NVMe target") 78ce3daa7d70: ("nvmet: fix byte swap in nvmet_execute_write_zeroes")
d262920998c8: ("nvmet: add support for the Write Zeroes command")
a07b4970f464: ("nvmet: add a generic NVMe target")
Please let us know if you'd like to have this patch included in a stable tree.
--
Thanks.
Sasha
PATCH v2 1/1 nvmet: fix nvmet_execute_write_zeroes function
Quoted 6 lines · Sasha Levin
[This is an automated email]
This commit has been processed by the -stable helper bot and determined to be a high probability candidate for -stable trees. (score: 6.9916)
The bot has tested the following trees: v4.15.15, v4.14.32, v4.9.92, v4.4.126,
Nice! Good bot. :)
Quoted 15 lines
v4.15.15: Build OK!
v4.14.32: Build OK!
v4.9.92: Failed to apply! Possible dependencies:
d262920998c8: ("nvmet: add support for the Write Zeroes command")78ce3daa7d70: ("nvmet: fix byte swap innvmet_execute_write_zeroes")
d262920998c8: ("nvmet: add support for the Write Zeroes command")v4.4.126: Failed to apply! Possible dependencies:
d262920998c8: ("nvmet: add support for the Write Zeroes command")
a07b4970f464: ("nvmet: add a generic NVMe target")78ce3daa7d70: ("nvmet: fix byte swap innvmet_execute_write_zeroes")
d262920998c8: ("nvmet: add support for the Write Zeroes command")
a07b4970f464: ("nvmet: add a generic NVMe target")
Quoted 1 line
Please let us know if you'd like to have this patch included in a stable tree.
Yes, please! 4.14+