Skip to content

Commit 8a825d2

Browse files
guixinliu1995keithbusch
authored andcommitted
nvme: check ns's volatile write cache not present
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 <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 1d81143 commit 8a825d2

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

drivers/nvme/host/core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct nvme_ns_info {
4343
bool is_ready;
4444
bool is_removed;
4545
bool is_rotational;
46+
bool no_vwc;
4647
};
4748

4849
unsigned int admin_timeout = 60;
@@ -1617,6 +1618,7 @@ static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl,
16171618
info->is_readonly = id->nsattr & NVME_NS_ATTR_RO;
16181619
info->is_ready = id->nstat & NVME_NSTAT_NRDY;
16191620
info->is_rotational = id->nsfeat & NVME_NS_ROTATIONAL;
1621+
info->no_vwc = id->nsfeat & NVME_NS_VWC_NOT_PRESENT;
16201622
}
16211623
kfree(id);
16221624
return ret;
@@ -2159,7 +2161,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
21592161
ns->head->ids.csi == NVME_CSI_ZNS)
21602162
nvme_update_zone_info(ns, &lim, &zi);
21612163

2162-
if (ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT)
2164+
if ((ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT) && !info->no_vwc)
21632165
lim.features |= BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA;
21642166
else
21652167
lim.features &= ~(BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA);

include/linux/nvme.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ enum {
564564
NVME_NS_FLBAS_META_EXT = 0x10,
565565
NVME_NS_NMIC_SHARED = 1 << 0,
566566
NVME_NS_ROTATIONAL = 1 << 4,
567+
NVME_NS_VWC_NOT_PRESENT = 1 << 5,
567568
NVME_LBAF_RP_BEST = 0,
568569
NVME_LBAF_RP_BETTER = 1,
569570
NVME_LBAF_RP_GOOD = 2,

0 commit comments

Comments
 (0)