]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
nvme: set max_hw_wzeroes_unmap_sectors if device supports DEAC bit
authorZhang Yi <yi.zhang@huawei.com>
Thu, 19 Jun 2025 11:17:59 +0000 (19:17 +0800)
committerChristian Brauner <brauner@kernel.org>
Mon, 23 Jun 2025 10:45:13 +0000 (12:45 +0200)
When the device supports the Write Zeroes command and the DEAC bit, it
indicates that the deallocate bit in the Write Zeroes command is
supported, and the bytes read from a deallocated logical block are
zeroes. This means the device supports unmap Write Zeroes operation, so
set the max_hw_wzeroes_unmap_sectors to max_write_zeroes_sectors on the
device's queue limit.

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Link: https://lore.kernel.org/20250619111806.3546162-3-yi.zhang@huaweicloud.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Martin K. Petersen" <martin.petersen@oracle.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
drivers/nvme/host/core.c

index 92697f98c601d4b89a1681bdfa1adca45e86af4a..90af4a15b6960b85d74d31ca6332d819ebb4986e 100644 (file)
@@ -2420,22 +2420,24 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
        else
                lim.write_stream_granularity = 0;
 
-       ret = queue_limits_commit_update(ns->disk->queue, &lim);
-       if (ret) {
-               blk_mq_unfreeze_queue(ns->disk->queue, memflags);
-               goto out;
-       }
-
-       set_capacity_and_notify(ns->disk, capacity);
-
        /*
         * Only set the DEAC bit if the device guarantees that reads from
         * deallocated data return zeroes.  While the DEAC bit does not
         * require that, it must be a no-op if reads from deallocated data
         * do not return zeroes.
         */
-       if ((id->dlfeat & 0x7) == 0x1 && (id->dlfeat & (1 << 3)))
+       if ((id->dlfeat & 0x7) == 0x1 && (id->dlfeat & (1 << 3))) {
                ns->head->features |= NVME_NS_DEAC;
+               lim.max_hw_wzeroes_unmap_sectors = lim.max_write_zeroes_sectors;
+       }
+
+       ret = queue_limits_commit_update(ns->disk->queue, &lim);
+       if (ret) {
+               blk_mq_unfreeze_queue(ns->disk->queue, memflags);
+               goto out;
+       }
+
+       set_capacity_and_notify(ns->disk, capacity);
        set_disk_ro(ns->disk, nvme_ns_is_readonly(ns, info));
        set_bit(NVME_NS_READY, &ns->flags);
        blk_mq_unfreeze_queue(ns->disk->queue, memflags);