NVMe Atomic Write fixes
v2 cover NVMe Atomic Write fixes
v2: 1/2 - Change wording of patch subject and description
2/2 - Rather than setting a controllers atomic write size to 512b if it doesn't
match the subsystem atomic write size, if a controllers atomic write size is greater than he subsystem atomic write size, reject to probe.
This patch set includes 2 fixes for NVMe Atomic Writes that are reproducable when CMIC.MCTRS (multi-controller support) is set:
PATCH 1/2 - nvme: multipath: enable BLK_FEAT_ATOMIC_WRITES for multipathing PATCH 2/2 - nvme: all namespaces in a subsystem must adhere to a common atomic write size
QEMU v10.0 can be used to reproduce and validate the fixes.
nvme: multipath: enable BLK_FEAT_ATOMIC_WRITES for multipathing
--------------------------------------------------------------------------
- Include BLK_FEAT_ATOMIC_WRITES feature when allocating multipath disk (nvme_mpath_alloc_disk).
QEMU Config
===========
-device nvme,id=nvme-ctrl-0,serial=nvme-1,atomic.dn=off,atomic.awun=31,atomic.awupf=15 \
-drive file=/dev/nullb2,if=none,id=nvm-1 \
-device nvme-ns,drive=nvm-1,bus=nvme-ctrl-0,nsid=1 \
-device nvme,id=nvme-ctrl-1,serial=nvme-2,atomic.dn=off,atomic.awun=31,atomic.awupf=7 \
-drive file=/dev/nullb3,if=none,id=nvm-2 \
-device nvme-ns,drive=nvm-2,bus=nvme-ctrl-1,nsid=2 \
-device nvme,id=nvme-ctrl-2,serial=nvme-3,atomic.dn=off,atomic.awun=127,atomic.awupf=63 \
-drive file=/dev/nullb4,if=none,id=nvm-3 \
-device nvme-ns,drive=nvm-3,bus=nvme-ctrl-2 \Before
======
[root@localhost ~]# nvme id-ctrl /dev/nvme1n1 | grep cmic
cmic : 0x2
[root@localhost ~]# nvme id-ctrl /dev/nvme1n1 | grep awupf
awupf : 63
[root@localhost ~]# nvme id-ns /dev/nvme1n1 | grep nawupf nawupf : 0
[root@localhost ~]# cat /sys/block/nvme1n1/queue/atomic_write_max_bytes 0
[root@localhost ~]#
AFTER
=====
[root@localhost ~]# nvme id-ctrl /dev/nvme1n1 | grep cmic
cmic : 0x2
[root@localhost ~]# nvme id-ctrl /dev/nvme1n1 | grep awupf
awupf : 63
[root@localhost ~]# nvme id-ns /dev/nvme1n1 | grep nawupf nawupf : 0
[root@localhost ~]# cat /sys/block/nvme1n1/queue/atomic_write_max_bytes 32768
[root@localhost ~]#
nvme: all namespaces in a subsystem must adhere to a common atomic write size
------------------------------------------------------------------------------
- Replace awupf field in nvme_subsystem struct with atomic_bs. The atomic_bs value with awupf or nawupf. (nvme_update_disk_info)
- When a namespace is added, the atomic write size (from awupf or nawupf) is checked with subsys->atomic_bs. If they don't match, the atomic write size is set to 512 (1U << head->lba_shift) and a message in logged. (nvme_update_disk_info)
QEMU Config
===========
-device nvme-subsys,id=subsys0 \
-device nvme,serial=deadbeef,id=nvme0,subsys=subsys0,atomic.dn=off,atomic.awun=31,atomic.awupf=15 \
-drive id=ns1,file=/dev/nullb1,if=none \
-device nvme-ns,drive=ns1,bus=nvme0,nsid=1,zoned=false,shared=false \
-device nvme,serial=deadbeef,id=nvme1,subsys=subsys0,atomic.dn=off,atomic.awun=63,atomic.awupf=31 \
-drive id=ns2,file=/dev/nullb2,if=none \
-device nvme-ns,drive=ns2,bus=nvme1,nsid=2,zoned=false,shared=false \BEFORE
======
[root@localhost ~]# nvme id-ctrl /dev/nvme0n1 | grep cmic
cmic : 0x2
[root@localhost ~]# nvme id-ctrl /dev/nvme0n1 | grep awupf
awupf : 15
[root@localhost ~]# nvme id-ns /dev/nvme0n1 | grep nawupf nawupf : 0
[root@localhost ~]# cat /sys/block/nvme0n1/queue/atomic_write_max_bytes 8192
[root@localhost ~]# nvme id-ctrl /dev/nvme0n2 | grep cmic
cmic : 0x2
[root@localhost ~]# nvme id-ctrl /dev/nvme0n2 | grep awupf
awupf : 31
[root@localhost ~]# nvme id-ns /dev/nvme0n2 | grep nawupf nawupf : 0
[root@localhost ~]# cat /sys/block/nvme0n2/queue/atomic_write_max_bytes 8192
[root@localhost ~]#
AFTER
=====
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 40G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 39G 0 part └─ol-root 252:0 0 39G 0 lvm / sr0 11:0 1 1024M 0 rom nvme1n2 259:1 0 250G 0 disk
[root@localhost ~]# sh testxx.sh nvme1n2
+ nvme id-ctrl /dev/nvme1n2
+ grep cmic
cmic : 0x2
+ nvme id-ctrl /dev/nvme1n2
+ grep awupf
awupf : 15
+ nvme id-ns /dev/nvme1n2
+ grep nawupf
nawupf : 0
+ cat /sys/block/nvme1n2/queue/atomic_write_max_bytes 8192
Console output:
[ 2.849583] nvme1c0n1: Inconsistent Atomic Write Size: Subsystem=8192 bytes, Controller/Namespace=16384 bytes
Signature · 1 line
2.43.5
PATCH v2 1/2 nvme: multipath: enable BLK_FEAT_ATOMIC_WRITES for multipathing
A change to QEMU resulted in all nvme controllers (single and multi-controller subsystems) to have its CMIC.MCTRS bit set which indicates the subsystem supports multiple controllers and it is possible a namespace can be shared between those multiple controllers in a multipathed configuration.
When a namespace of a CMIC.MCTRS enabled subsystem is allocated, a multipath node is created. The queue limits for this node are inherited from the namespace being allocated. When inheriting queue limits, the features being inherited need to be specified. The atomic write feature (BLK_FEAT_ATOMIC_WRITES) was not specified so the atomic queue limits were not inherited by the multipath disk node which resulted in the sysfs atomic write attributes being zeroed. The fix is to include BLK_FEAT_ATOMIC_WRITES in the list of features to be inherited.
--- drivers/nvme/host/multipath.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/multipath.c +2 -1
@@ -638,7 +638,8 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)blk_set_stacking_limits (&lim); lim.dma_alignment =3 ; - lim.features |=BLK_FEAT_IO_STAT |BLK_FEAT_NOWAIT |BLK_FEAT_POLL ; + lim.features |=BLK_FEAT_IO_STAT |BLK_FEAT_NOWAIT | +BLK_FEAT_POLL |BLK_FEAT_ATOMIC_WRITES ;if (head->ids.csi ==NVME_CSI_ZNS ) lim.features |=BLK_FEAT_ZONED ;
Signature · 1 line
2.43.5
PATCH v2 2/2 nvme: all namespaces in a subsystem must adhere to a common atomic write size
In reply to Alan AdamsonThe first namespace configured in a subsystem sets the subsystem's atomic write size based on its AWUPF or NAWUPF. Subsequent namespaces must have an atomic write size (per their AWUPF or NAWUPF) less than or equal to the subsystem's atomic write size, or their probing will be rejected.
--- drivers/nvme/host/core.c | 25 ++++++++++++++++++++++--- drivers/nvme/host/nvme.h | 3 ++- 2 files changed, 24 insertions(+), 4 deletions(-)
drivers/nvme/host/core.c +22 -3
@@ -2059,7 +2059,20 @@ static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id,if (id->nsfeat &NVME_NS_FEAT_ATOMICS && id->nawupf) atomic_bs = (1 +le16_to_cpu (id->nawupf)) * bs;else - atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs; + atomic_bs = (1 + ns->ctrl->awupf) * bs; + +/* +* Set subsystem atomic bs. +*/ +if (ns->ctrl->subsys->atomic_bs) { +if (atomic_bs > ns->ctrl->subsys->atomic_bs) { +pr_err_ratelimited ("%s: Inconsistent Atomic Write Size: Subsystem=%d bytes, Controller/Namespace=%d bytes\n" , + ns->disk ? ns->disk->disk_name :"?" , + ns->ctrl->subsys->atomic_bs, + atomic_bs); + } + }else + ns->ctrl->subsys->atomic_bs = atomic_bs;nvme_update_atomic_write_disk_info (ns, id, lim, bs, atomic_bs); }
@@ -2201,6 +2214,13 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,nvme_set_chunk_sectors (ns, id, &lim);if (!nvme_update_disk_info (ns, id, &lim)) capacity =0 ; + +if (lim.atomic_write_hw_max > ns->ctrl->subsys->atomic_bs) { +blk_mq_unfreeze_queue (ns->disk->queue, memflags); + ret = -ENXIO ; + goto out; + } +nvme_config_discard (ns, &lim);if (IS_ENABLED (CONFIG_BLK_DEV_ZONED ) && ns->head->ids.csi ==NVME_CSI_ZNS )
@@ -3031,7 +3051,6 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)kfree (subsys);return -EINVAL ; } - subsys->awupf =le16_to_cpu (id->awupf);nvme_mpath_default_iopolicy (subsys); subsys->dev.class = &nvme_subsys_class;
@@ -3441,7 +3460,7 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)dev_pm_qos_expose_latency_tolerance (ctrl->device); else if (!ctrl->apst_enabled && prev_apst_enabled)dev_pm_qos_hide_latency_tolerance (ctrl->device); - + ctrl->awupf =le16_to_cpu (id->awupf); out_free:kfree (id);return ret;
drivers/nvme/host/nvme.h +2 -1
@@ -410,6 +410,7 @@ struct nvme_ctrl {enum nvme_ctrl_type cntrltype;enum nvme_dctype dctype; +u16 awupf; };static inline enum nvme_ctrl_state nvme_ctrl_state (struct nvme_ctrl *ctrl)
@@ -442,11 +443,11 @@ struct nvme_subsystem {u8 cmic;enum nvme_subsys_type subtype;u16 vendor_id; -u16 awupf;/* 0's based awupf value. */ struct ida ns_ida;#ifdef CONFIG_NVME_MULTIPATH enum nvme_iopolicy iopolicy;#endif +u32 atomic_bs; };/*
Signature · 1 line
2.43.5
Christoph Hellwig
maintainerRe: [PATCH v2 2/2] nvme: all namespaces in a subsystem must adhere to a common atomic write size
drivers/nvme/host/core.c static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id, · line 2072
Quoted 9 lines · Alan Adamson
drivers/nvme/host/core.c +9
-0+/* +* Set subsystem atomic bs. +*/ +if (ns->ctrl->subsys->atomic_bs) { +if (atomic_bs > ns->ctrl->subsys->atomic_bs) { +pr_err_ratelimited ("%s: Inconsistent Atomic Write Size: Subsystem=%d bytes, Controller/Namespace=%d bytes\n" , + ns->disk ? ns->disk->disk_name :"?" , + ns->ctrl->subsys->atomic_bs, + atomic_bs);
Maybe mentioned that the controlled is not added as well here?
drivers/nvme/host/core.c static int nvme_update_ns_info_block(struct nvme_ns *ns, · line 2222
Quoted 5 lines
drivers/nvme/host/core.c +5
-0+if (lim.atomic_write_hw_max > ns->ctrl->subsys->atomic_bs) { +blk_mq_unfreeze_queue (ns->disk->queue, memflags); + ret = -ENXIO ; + goto out; + }
And add a comment here explaining the check?
Otherwise this looks good.