Skip to contentSkip to conversation

nvme: fix write_stream_granularity initialization

PATCH Applied Caleb Sander Mateos 3 participants 3 messages May 6, 2025 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: fix write_stream_granularity initialization

write_stream_granularity is set to max(info->runs, U32_MAX), which means that any RUNS value less than 2 ** 32 becomes U32_MAX, and any larger value is silently truncated to an unsigned int.

Use min() instead to provide the correct semantics, capping RUNS values at U32_MAX.

Fixes 30b5f20bb2dd ("nvme: register fdp parameters with the block layer")
---
 drivers/nvme/host/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/core.c +1 -1
index 52331a14bce1..a9fb8cd54420 100644
@@ -2390,11 +2390,11 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
 	if (!nvme_init_integrity(ns->head, &lim, info))
 		capacity = 0;
 
 	lim.max_write_streams = ns->head->nr_plids;
 	if (lim.max_write_streams)
-		lim.write_stream_granularity = max(info->runs, U32_MAX);
+		lim.write_stream_granularity = min(info->runs, U32_MAX);
 	else
 		lim.write_stream_granularity = 0;
 
 	ret = queue_limits_commit_update(ns->disk->queue, &lim);
 	if (ret) {
Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Caleb Sander Mateos

write_stream_granularity is set to max(info->runs, U32_MAX), which means that any RUNS value less than 2 ** 32 becomes U32_MAX, and any larger value is silently truncated to an unsigned int.

Use min() instead to provide the correct semantics, capping RUNS values at U32_MAX.

Fixes 30b5f20bb2dd ("nvme: register fdp parameters with the block layer")

Looks good

maintainer Applied
#2 lore raw
In reply to Caleb Sander Mateos
Quoted 8 lines · Caleb Sander Mateos

write_stream_granularity is set to max(info->runs, U32_MAX), which means that any RUNS value less than 2 ** 32 becomes U32_MAX, and any larger value is silently truncated to an unsigned int.

Use min() instead to provide the correct semantics, capping RUNS values at U32_MAX.

[...]

Applied, thanks!

[1/1] nvme: fix write_stream_granularity initialization

      commit: 86b6e0bd1a69efd0ed408997e0adfb85df96a0c7

Best regards,

Signature · 1 line
Jens Axboe