]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
nvme: check ns's volatile write cache not present
authorGuixin Liu <kanie@linux.alibaba.com>
Mon, 4 Nov 2024 08:55:00 +0000 (16:55 +0800)
committerKeith Busch <kbusch@kernel.org>
Mon, 11 Nov 2024 17:49:50 +0000 (09:49 -0800)
When the VWC of a namespace does not exist, the BLK_FEAT_WRITE_CACHE
flag should not be set when registering the block device, regardless
of whether the controller supports VWC.

Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
drivers/nvme/host/core.c
include/linux/nvme.h

index 6f51dde7de6ce1feb9748c351ffa40c504d3f70b..e119ba0f8ab8bae9e62936948df5662e7bb1e42f 100644 (file)
@@ -43,6 +43,7 @@ struct nvme_ns_info {
        bool is_ready;
        bool is_removed;
        bool is_rotational;
+       bool no_vwc;
 };
 
 unsigned int admin_timeout = 60;
@@ -1617,6 +1618,7 @@ static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl,
                info->is_readonly = id->nsattr & NVME_NS_ATTR_RO;
                info->is_ready = id->nstat & NVME_NSTAT_NRDY;
                info->is_rotational = id->nsfeat & NVME_NS_ROTATIONAL;
+               info->no_vwc = id->nsfeat & NVME_NS_VWC_NOT_PRESENT;
        }
        kfree(id);
        return ret;
@@ -2159,7 +2161,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
            ns->head->ids.csi == NVME_CSI_ZNS)
                nvme_update_zone_info(ns, &lim, &zi);
 
-       if (ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT)
+       if ((ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT) && !info->no_vwc)
                lim.features |= BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA;
        else
                lim.features &= ~(BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA);
index c136d64c7d73d05653629467681faa0a68ee2380..0a6e22038ce361e678326d16677045c2b9b6fcc5 100644 (file)
@@ -564,6 +564,7 @@ enum {
        NVME_NS_FLBAS_META_EXT  = 0x10,
        NVME_NS_NMIC_SHARED     = 1 << 0,
        NVME_NS_ROTATIONAL      = 1 << 4,
+       NVME_NS_VWC_NOT_PRESENT = 1 << 5,
        NVME_LBAF_RP_BEST       = 0,
        NVME_LBAF_RP_BETTER     = 1,
        NVME_LBAF_RP_GOOD       = 2,