nvme: check PI size if metadata size or below
PATCH 1/1 nvme: check PI size if metadata size or below
The PI is the first bytes or last bytes of the metadata. So its size is not equal to hte metadata size only but below also.
--- drivers/nvme/host/ioctl.c | 4 ++-- drivers/nvme/host/nvme.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/nvme/host/ioctl.c +2 -2
@@ -232,8 +232,8 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio) length = (io.nblocks +1 ) << ns->head->lba_shift; -if ((io.control &NVME_RW_PRINFO_PRACT ) && - (ns->head->ms == ns->head->pi_size)) { +if (io.control &NVME_RW_PRINFO_PRACT && + ns->head->ms >= ns->head->pi_size) {/* * Protection information is stripped/inserted by the * controller.
drivers/nvme/host/nvme.h +1 -1
@@ -542,7 +542,7 @@ struct nvme_ns {/* NVMe ns supports metadata actions by the controller (generate/strip) */ static inline bool nvme_ns_has_pi (struct nvme_ns_head *head) { -return head->pi_type && head->ms == head->pi_size; +return head->pi_type && head->ms >= head->pi_size; }struct nvme_ctrl_ops {
Signature · 1 line
2.45.2
Keith Busch
maintainerQuoted 12 lines · Tokunori Ikegami
drivers/nvme/host/ioctl.c +2
-2-if ((io.control &NVME_RW_PRINFO_PRACT ) && - (ns->head->ms == ns->head->pi_size)) { +if (io.control &NVME_RW_PRINFO_PRACT && + ns->head->ms >= ns->head->pi_size) {/* * Protection information is stripped/inserted by the * controller. drivers/nvme/host/nvme.h +0
-0
drivers/nvme/host/nvme.h struct nvme_ns { · line 546
Quoted 6 lines
drivers/nvme/host/nvme.h +1
-1@@ -542,7 +542,7 @@ struct nvme_ns {/* NVMe ns supports metadata actions by the controller (generate/strip) */ static inline bool nvme_ns_has_pi (struct nvme_ns_head *head) { -return head->pi_type && head->ms == head->pi_size; +return head->pi_type && head->ms >= head->pi_size; }
It would have been nice if PRACT worked this way, but spec says it doesn't. The control bit is a no-op if Metadata Size does not equal the PI size, which is what these checks are looking for, so we can't take this.
The existing function nvme_configure_metadata() code checks as same as below but is this checking case only okay?
static void nvme_configure_metadata(struct nvme_ctrl *ctrl, struct nvme_ns_head *head, struct nvme_id_ns *id, struct nvme_id_ns_nvm *nvm, struct nvme_ns_info *info) {
...
if (head->pi_size && head->ms >= head->pi_size) head->pi_type = id->dps & NVME_NS_DPS_PI_MASK;
Quoted 23 lines · Keith Busch
Quoted 12 lines · Tokunori Ikegami
drivers/nvme/host/ioctl.c +2
-2-if ((io.control &NVME_RW_PRINFO_PRACT ) && - (ns->head->ms == ns->head->pi_size)) { +if (io.control &NVME_RW_PRINFO_PRACT && + ns->head->ms >= ns->head->pi_size) {/* * Protection information is stripped/inserted by the * controller. drivers/nvme/host/nvme.h +0
-0drivers/nvme/host/nvme.h struct nvme_ns { · line 546
Quoted 6 lines
drivers/nvme/host/nvme.h +1
-1@@ -542,7 +542,7 @@ struct nvme_ns {/* NVMe ns supports metadata actions by the controller (generate/strip) */ static inline bool nvme_ns_has_pi (struct nvme_ns_head *head) { -return head->pi_type && head->ms == head->pi_size; +return head->pi_type && head->ms >= head->pi_size; }It would have been nice if PRACT worked this way, but spec says it doesn't. The control bit is a no-op if Metadata Size does not equal the PI size, which is what these checks are looking for, so we can't take this.
Keith Busch
maintainerQuoted 8 lines · Tokunori Ikegami
The existing function
nvme_configure_metadata()code checks as same as below but is this checking case only okay?static void nvme_configure_metadata(struct
nvme_ctrl*ctrl, structnvme_ns_head*head, structnvme_id_ns*id, structnvme_id_ns_nvm*nvm, structnvme_ns_info*info) {
Quoted 4 lines
...
if (
head->pi_size&&head->ms>=head->pi_size)head->pi_type=id->dps&NVME_NS_DPS_PI_MASK;
This is merely checking if the metadata is sufficient to do PI. Nothing to do with usage of PRACT, which is what you're changing.
I see. Thanks for your explanation. To make sure let me confirm again below.
The nvme_ns_has_pi changed does not use PRACT as mentioned but still is it not okay to change the function only also? (I could understand as nvme_submit_io() uses PRACT then it does not work correctly as mentioned.)
Quoted 15 lines · Keith Busch
Quoted 8 lines · Tokunori Ikegami
The existing function
nvme_configure_metadata()code checks as same as below but is this checking case only okay?static void nvme_configure_metadata(struct
nvme_ctrl*ctrl,
structnvme_ns_head*head, structnvme_id_ns*id, structnvme_id_ns_nvm*nvm, structnvme_ns_info*info)
{Quoted 4 lines
...
if (
head->pi_size&&head->ms>=head->pi_size)head->pi_type=id->dps&NVME_NS_DPS_PI_MASK;This is merely checking if the metadata is sufficient to do PI. Nothing to do with usage of PRACT, which is what you're changing.
Keith Busch
maintainerQuoted 4 lines · Tokunori Ikegami
I see. Thanks for your explanation. To make sure let me confirm again below. The
nvme_ns_has_pichanged does not use PRACT as mentioned but still is it not okay to change the function only also? (I could understand asnvme_submit_io()uses PRACT then it does not work correctly as mentioned.)
The function name could be better. It's just reporting if the namespace format supports inserting/stripping metadata, such that the host doesn't need to provide it.
Thanks for your confirmation. Just sent the v3 patch to change only nvme_ns_has_pi(). Thank you.
Quoted 8 lines · Keith Busch
Quoted 4 lines · Tokunori Ikegami
I see. Thanks for your explanation. To make sure let me confirm again below. The
nvme_ns_has_pichanged does not use PRACT as mentioned but still is it not okay to change the function only also? (I could understand asnvme_submit_io()uses PRACT then it does not work correctly as mentioned.)The function name could be better. It's just reporting if the namespace format supports inserting/stripping metadata, such that the host doesn't need to provide it.