nvme: small fixes reported by smatch
Subsystems (2)
cover nvme: small fixes reported by smatch
Fix a number of small things reported by smatch on the nvme driver
Javier Gonz?lez (3):
nvme: do not check for ns on rw path
nvme: compare NQN string with right size
nvme: fix eui_show() print format
drivers/nvme/host/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/3 nvme: do not check for ns on rw path
On the rw path, the ns is assumed to be set. However, a check is still done, inherited from the time the code resided at nvme_queue_rq().
Eliminate this check, which also eliminates a smatch complain for not doing proper NULL checks on ns.
--- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/core.c +1 -1
@@ -472,7 +472,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,* unless this namespace is formated such that the metadata can be * stripped/generated by the controller with PRACT=1. */ -if (ns && ns->ms && +if (ns->ms && (!ns->pi_type || ns->ms !=sizeof (struct t10_pi_tuple )) && !blk_integrity_rq (req) && !blk_rq_is_passthrough (req))return BLK_STS_NOTSUPP ;
Signature · 1 line
2.7.4
PATCH 2/3 nvme: compare NQN string with right size
In reply to Javier GonzálezCompare subnqns using NVMF_NQN_SIZE as it is < 256
--- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/core.c +1 -1
@@ -1743,7 +1743,7 @@ static void nvme_init_subnqn(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) nqnlen =strnlen (id->subnqn,NVMF_NQN_SIZE );if (nqnlen >0 && nqnlen <NVMF_NQN_SIZE ) { -strcpy (ctrl->subnqn, id->subnqn); +strncpy (ctrl->subnqn, id->subnqn,NVMF_NQN_SIZE );return ; }
Signature · 1 line
2.7.4
PATCH 3/3 nvme: fix eui_show() print format
In reply to Javier González--- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/core.c +1 -1
@@ -2108,7 +2108,7 @@ static ssize_t eui_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -return sprintf (buf,"%8phd\n" , ns->eui); +return sprintf (buf,"%8phD\n" , ns->eui); } static DEVICE_ATTR(eui, S_IRUGO, eui_show, NULL);
Signature · 1 line
2.7.4
Christoph Hellwig
maintainerRe: [PATCH 1/3] nvme: do not check for ns on rw path
In reply to Javier Gonzálezdrivers/nvme/host/core.c static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, · line 478
Quoted 5 lines
drivers/nvme/host/core.c +1
-1-if (ns && ns->ms && +if (ns->ms && (!ns->pi_type || ns->ms !=sizeof (struct t10_pi_tuple )) && !blk_integrity_rq (req) && !blk_rq_is_passthrough (req))return BLK_STS_NOTSUPP ;
blk_rq_is_passthrough also can't be true here.
How about:
if (ns->ms && !blk_integrity_rq(req) && (!ns->pi_type || ns->ms != sizeof(struct t10_pi_tuple))) return BLK_STS_NOTSUPP;
Although I have to admit I don't really understand what this check is even trying to do. It basically checks for a namespace that has a format with metadata that is not T10 protection information and then rejects all I/O to it. Why are we even creating a block device node for such a thing?
Christoph Hellwig
maintainerRe: [PATCH 2/3] nvme: compare NQN string with right size
In reply to Javier GonzálezQuoted 12 lines · Javier Gonz?lez
Compare subnqns using
NVMF_NQN_SIZEas it is < 256Signed-off-by Javier Gonz?lez <javier at cnexlabs.com>--- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/nvme/host/core.c +0
-0
drivers/nvme/host/core.c static void nvme_init_subnqn(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) · line 1748
Quoted 7 lines
drivers/nvme/host/core.c +1
-1@@ -1743,7 +1743,7 @@ static void nvme_init_subnqn(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) nqnlen =strnlen (id->subnqn,NVMF_NQN_SIZE );if (nqnlen >0 && nqnlen <NVMF_NQN_SIZE ) { -strcpy (ctrl->subnqn, id->subnqn); +strncpy (ctrl->subnqn, id->subnqn,NVMF_NQN_SIZE );return ; }
This isn't a compare, but a copy. Except for that it looks ok to me.
Christoph Hellwig
maintainerRe: [PATCH 3/3] nvme: fix eui_show() print format
In reply to Javier GonzálezQuoted 10 lines · Javier Gonz?lez
Signed-off-by Javier Gonz?lez <javier at cnexlabs.com>--- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/nvme/host/core.c +0
-0
drivers/nvme/host/core.c static ssize_t eui_show(struct device *dev, struct device_attribute *attr, · line 2113
Quoted 7 lines
drivers/nvme/host/core.c +1
-1@@ -2108,7 +2108,7 @@ static ssize_t eui_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -return sprintf (buf,"%8phd\n" , ns->eui); +return sprintf (buf,"%8phD\n" , ns->eui); } static DEVICE_ATTR(eui, S_IRUGO, eui_show, NULL);
This looks correct. I wonder what the old code printed - does someone have a device with an EUI-64 at hand to quickly cross check what we did before?
Re: [PATCH 2/3] nvme: compare NQN string with right size
In reply to Christoph HellwigQuoted 16 lines · Christoph Hellwig
Quoted 13 lines · Javier Gonz?lez
Compare subnqns using
NVMF_NQN_SIZEas it is < 256Signed-off-by Javier Gonz?lez <javier at cnexlabs.com>---
drivers/nvme/host/core.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/nvme/host/core.c +0
-0@@ -1743,7 +1743,7 @@ static void nvme_init_subnqn(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
Quoted 8 lines
drivers/nvme/host/core.c static void nvme_init_subnqn(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) · line 1748
Quoted 6 lines
drivers/nvme/host/core.c +1
-1nqnlen =strnlen (id->subnqn,NVMF_NQN_SIZE );if (nqnlen >0 && nqnlen <NVMF_NQN_SIZE ) { -strcpy (ctrl->subnqn, id->subnqn); +strncpy (ctrl->subnqn, id->subnqn,NVMF_NQN_SIZE );return ; }This isn't a compare, but a copy. Except for that it looks ok to me.
True. Can you change the message when picking it up?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.infradead.org/pipermail/linux-nvme/attachments/20171103/621572ad/attachment.sig>
Re: [PATCH 1/3] nvme: do not check for ns on rw path
In reply to Christoph HellwigQuoted 10 lines · Christoph Hellwig
Quoted 6 lines
drivers/nvme/host/core.c +1
-1- if (ns && ns->ms && + if (ns->ms &&(!ns->pi_type || ns->ms != sizeof(struct t10_pi_tuple)) && !blk_integrity_rq(req) && !blk_rq_is_passthrough(req)) return BLK_STS_NOTSUPP;
blk_rq_is_passthroughalso can't be true here.
Quoted 6 lines
How about:
if (ns->ms && !blk_integrity_rq(req) && (!ns->pi_type || ns->ms != sizeof(struct t10_pi_tuple))) return BLK_STS_NOTSUPP;
Sure.
Quoted 5 lines
Although I have to admit I don't really understand what this check is even trying to do. It basically checks for a namespace that has a format with metadata that is not T10 protection information and then rejects all I/O to it. Why are we even creating a block device node for such a thing?
Looking at the history (i) the check has changed location and (ii) some checks have been added through time. So it looks like leftovers from here and there.
If we end up not needing these checks at all here, you can just fix it all in the same commit. Just wanted to get rid of sparse/smatch complains...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.infradead.org/pipermail/linux-nvme/attachments/20171103/bc8c9674/attachment.sig>
Re: [PATCH 1/3] nvme: do not check for ns on rw path
In reply to Christoph HellwigQuoted 14 lines · Christoph Hellwig
drivers/nvme/host/core.c static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, · line 478
Quoted 5 lines
drivers/nvme/host/core.c +1
-1-if (ns && ns->ms && +if (ns->ms && (!ns->pi_type || ns->ms !=sizeof (struct t10_pi_tuple )) && !blk_integrity_rq (req) && !blk_rq_is_passthrough (req))return BLK_STS_NOTSUPP ;
blk_rq_is_passthroughalso can't be true here.How about:
if (ns->ms && !blk_integrity_rq(req) && (!ns->pi_type || ns->ms != sizeof(struct t10_pi_tuple))) return BLK_STS_NOTSUPP;
Quoted 5 lines
Although I have to admit I don't really understand what this check is even trying to do. It basically checks for a namespace that has a format with metadata that is not T10 protection information and then rejects all I/O to it. Why are we even creating a block device node for such a thing?
If the namespace has metadata, but the request doesn't have a metadata payload attached to it for whatever reason, we can't construct the command for that format. We also can't have the controller strip/generate the payload with PRACT bit set if it's not a T10 format, so we just fail the command.
Keith Busch
Reviewed-byRe: [PATCH 3/3] nvme: fix eui_show() print format
In reply to Christoph HellwigQuoted 6 lines · Christoph Hellwig
Quoted 5 lines · Javier Gonz�lez
Signed-off-by Javier Gonz�lez <[email protected]>--- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
drivers/nvme/host/core.c static ssize_t eui_show(struct device *dev, struct device_attribute *attr, · line 2113
Quoted 12 lines
drivers/nvme/host/core.c +1
-1@@ -2108,7 +2108,7 @@ static ssize_t eui_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -return sprintf (buf,"%8phd\n" , ns->eui); +return sprintf (buf,"%8phD\n" , ns->eui); } static DEVICE_ATTR(eui, S_IRUGO, eui_show, NULL);This looks correct. I wonder what the old code printed - does someone have a device with an EUI-64 at hand to quickly cross check what we did before?
It just prints the same as the 'ph' format, which would look like this:
01 02 03 04 05 06 07 08
The change will make it look like this:
01-02-03-04-05-06-07-08
I think that was the original intention.
Re: [PATCH 3/3] nvme: fix eui_show() print format
In reply to Christoph HellwigQuoted 2 lines · Christoph Hellwig
Quoted 1 line · On Fri, Nov 03, 2017 at 11:02:50AM +0100, Javier Gonz=E1lez wrote:
Signed-off-by Javier Gonz=E1lez <[email protected]>
[]
Quoted 1 line
drivers/nvme/host/core.c
Quoted 1 line
drivers/nvme/host/core.c +0
-0
[]
Quoted 1 line
drivers/nvme/host/core.c static ssize_t eui_show(struct device *dev, struc=
Quoted 1 line
drivers/nvme/host/core.c +0
-0@@ -2108,7 +2108,7 @@ static ssize_t eui_show(struct device *dev, struc=
t device_attribute *attr,
Quoted 9 lines
drivers/nvme/host/core.c static ssize_t eui_show(struct device *dev, struct device_attribute *attr, · line 2113
Quoted 7 lines
drivers/nvme/host/core.c +1
-1char *buf) { struct nvme_ns *ns =3D nvme_get_ns_from_dev(dev); -return sprintf (buf,"%8phd\n" , ns->eui); +return sprintf (buf,"%8phD\n" , ns->eui); } static DEVICE_ATTR(eui, S_IRUGO, eui_show, NULL);=
Quoted 3 lines
This looks correct. I wonder what the old code printed - does someone have a device with an EUI-64 at hand to quickly cross check what we did before?
It uses spaces between bytes and not dashes.
The code has been this way a couple years now.
I think this proposal, while it might fix an
unintentional output style, could also be an API
and could cause user breakage if changed.
Perhaps this should just become
%8ph
without D
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 1/3] nvme: do not check for ns on rw path
In reply to Keith BuschQuoted 5 lines · Keith Busch
If the namespace has metadata, but the request doesn't have a metadata payload attached to it for whatever reason, we can't construct the command for that format. We also can't have the controller strip/generate the payload with PRACT bit set if it's not a T10 format, so we just fail the command.
The only metadata payload a READ or WRITE request can have is a protection information one. For a namespace formatted with protection information bio_integrity_prep as called from blk_mq_make_request will ensure we always have metadata attached.
If a namespace is formatted with non-PI metadata we will never have metadata attached to the bio/request and should not even present the namespace to the kernel.
Re: [PATCH 3/3] nvme: fix eui_show() print format
In reply to Joe PerchesQuoted 29 lines · Joe Perches
Quoted 2 lines · Christoph Hellwig
Quoted 1 line · Javier Gonz?lez
Signed-off-by Javier Gonz?lez <javier at cnexlabs.com>[]
Quoted 1 line
drivers/nvme/host/core.c
Quoted 1 line
drivers/nvme/host/core.c +0
-0[]
Quoted 4 lines
Quoted 4 lines
drivers/nvme/host/core.c +0
-0@@ -2108,7 +2108,7 @@ static ssize_t eui_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev);Quoted 8 lines
drivers/nvme/host/core.c static ssize_t eui_show(struct device *dev, struct device_attribute *attr, · line 2113
Quoted 4 lines
drivers/nvme/host/core.c +1
-1-return sprintf (buf,"%8phd\n" , ns->eui); +return sprintf (buf,"%8phD\n" , ns->eui); } static DEVICE_ATTR(eui, S_IRUGO, eui_show, NULL);This looks correct. I wonder what the old code printed - does someone have a device with an EUI-64 at hand to quickly cross check what we did before?
It uses spaces between bytes and not dashes.
The code has been this way a couple years now.
I think this proposal, while it might fix an
unintentional output style, could also be an API
and could cause user breakage if changed.
Quoted 5 lines
Perhaps this should just become
%8phwithout D
That would be ok with me.
Javier.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.infradead.org/pipermail/linux-nvme/attachments/20171104/47095145/attachment.sig>
Re: [PATCH 1/3] nvme: do not check for ns on rw path
In reply to Christoph HellwigQuoted 7 lines · Christoph Hellwig
Quoted 5 lines · Keith Busch
If the namespace has metadata, but the request doesn't have a metadata payload attached to it for whatever reason, we can't construct the command for that format. We also can't have the controller strip/generate the payload with PRACT bit set if it's not a T10 format, so we just fail the command.
Quoted 8 lines
The only metadata payload a READ or WRITE request can have is a protection information one. For a namespace formatted with protection information
bio_integrity_prepas called fromblk_mq_make_requestwill ensure we always have metadata attached.If a namespace is formatted with non-PI metadata we will never have metadata attached to the bio/request and should not even present the namespace to the kernel.
That's not quite right. For non-PI metadata formats, we use the 'nop_profile', which gets the metadata buffer allocated so we can safely use a metadata formatted namespace. There's no in-kernel user of the allocated payload, but we still need the metadata buffer in order to use the namespace at all.
Christoph Hellwig
maintainerRe: [PATCH 1/3] nvme: do not check for ns on rw path
Quoted 5 lines · Keith Busch
That's not quite right. For non-PI metadata formats, we use the '
nop_profile', which gets the metadata buffer allocated so we can safely use a metadata formatted namespace. There's no in-kernel user of the allocated payload, but we still need the metadata buffer in order to use the namespace at all.
You're right. But that means we will indeed always have a matching integrity payload here and the check should not be needed.
Are you fine with turning it into something like:
if (WARN_ON_ONCE(ns->ms && !blk_integrity_rq(req))) return BLK_STS_IOERR;
?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 1/3] nvme: do not check for ns on rw path
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Keith Busch
That's not quite right. For non-PI metadata formats, we use the '
nop_profile', which gets the metadata buffer allocated so we can safely use a metadata formatted namespace. There's no in-kernel user of the allocated payload, but we still need the metadata buffer in order to use the namespace at all.You're right. But that means we will indeed always have a matching integrity payload here and the check should not be needed.
Quoted 6 lines
Are you fine with turning it into something like:
if (WARN_ON_ONCE(ns->ms && !blk_integrity_rq(req))) return BLK_STS_IOERR;?
Yes, that looks fine. You're right that we are not supposed to be able to get into this path for read/write since the driver sets the capacity to 0 if a metadata format doesn't have integrity support, so hitting this warning would indicate something has gone wrong.
Christoph Hellwig
maintainerRe: [PATCH 3/3] nvme: fix eui_show() print format
In reply to Javier GonzálezQuoted 7 lines · Javier Gonz?lez
Quoted 5 lines
Perhaps this should just become
%8phwithout D
That would be ok with me.
Can you resend a patch for that?
Re: [PATCH 3/3] nvme: fix eui_show() print format
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Javier Gonz?lez
Quoted 2 lines
Perhaps this should just become
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
%8phwithout D
That would be ok with me.
Can you resend a patch for that?
Sure. I?ll send it tomorrow together with the copy fix with the right commit message.
Javier