Skip to contentSkip to conversation

nvmet: fix nvmet_execute_write_zeroes function

PATCH Superseded Rodrigo R. Galvao 3 participants 5 messages Apr 2, 2018 – Apr 5, 2018

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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.

Signed-off-by Rodrigo R. Galvao <rosattig at linux.vnet.ibm.com>
---
 drivers/nvme/target/io-cmd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/target/io-cmd.c +2 -2
index 28bbdff..5292bc3 100644
@@ -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
#1 lore raw
Quoted 21 lines · Rodrigo R. Galvao

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 +0 -0
index 28bbdff..5292bc3 100644

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.

#2 lore raw
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
#3 lore raw

PATCH v2 1/1 nvmet: fix nvmet_execute_write_zeroes function

In reply to Rodrigo R. Galvao

Hi "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

#4 lore raw

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 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")

Quoted 1 line

Please let us know if you'd like to have this patch included in a stable tree.

Yes, please! 4.14+