linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvmet: fix a wrong error status returned in error log page
@ 2019-08-31 18:50 amit.engel
  2019-09-04 13:14 ` Christoph Hellwig
  0 siblings, 1 reply; 11+ messages in thread
From: amit.engel @ 2019-08-31 18:50 UTC (permalink / raw)
  To: sagi, linux-nvme; +Cc: Amit

From: Amit <amit.engel@emc.com>

When the command data_len cannot hold all the controller errors,
we should simply return as much errors as we can fit
instead of failing the command.

Signed-off-by: Amit Engel <amit.engel@dell.com>
---
 drivers/nvme/target/admin-cmd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 51800a9ce9a9..f7753b8a485c 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -40,13 +40,16 @@ static void nvmet_execute_get_log_page_error(struct nvmet_req *req)
 	u16 status = NVME_SC_SUCCESS;
 	unsigned long flags;
 	off_t offset = 0;
+	size_t num_of_sgl_slots;
 	u64 slot;
 	u64 i;
 
+	num_of_sgl_slots = do_div(req->data_len, sizeof(struct nvme_error_slot));
+
 	spin_lock_irqsave(&ctrl->error_lock, flags);
 	slot = ctrl->err_counter % NVMET_ERROR_LOG_SLOTS;
 
-	for (i = 0; i < NVMET_ERROR_LOG_SLOTS; i++) {
+	for (i = 0; i < NVMET_ERROR_LOG_SLOTS && i < num_of_sgl_slots; i++) {
 		status = nvmet_copy_to_sgl(req, offset, &ctrl->slots[slot],
 				sizeof(struct nvme_error_slot));
 		if (status)
-- 
2.16.5


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] nvmet: fix a wrong error status returned in error log page
  2019-08-31 18:50 [PATCH] nvmet: fix a wrong error status returned in error log page amit.engel
@ 2019-09-04 13:14 ` Christoph Hellwig
  2019-09-04 14:05   ` Engel, Amit
  0 siblings, 1 reply; 11+ messages in thread
From: Christoph Hellwig @ 2019-09-04 13:14 UTC (permalink / raw)
  To: amit.engel; +Cc: sagi, linux-nvme

Sorry for dropping the ball earlier..

> +	num_of_sgl_slots = do_div(req->data_len, sizeof(struct nvme_error_slot));

I don't think this does what you think it does.  do_div has a reall
odd calling convention where it returns the result of the division
in the first argument (despite that not beeing passd by reference,
thanks to being implemented as a macro), and returns the remainder
in the actual return value.

But I think the fix might actually be as simple as:


diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 4dc12ea52f23..543fb2a0c005 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -37,7 +37,6 @@ static void nvmet_execute_get_log_page_noop(struct nvmet_req *req)
 static void nvmet_execute_get_log_page_error(struct nvmet_req *req)
 {
 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
-	u16 status = NVME_SC_SUCCESS;
 	unsigned long flags;
 	off_t offset = 0;
 	u64 slot;
@@ -47,9 +46,8 @@ static void nvmet_execute_get_log_page_error(struct nvmet_req *req)
 	slot = ctrl->err_counter % NVMET_ERROR_LOG_SLOTS;
 
 	for (i = 0; i < NVMET_ERROR_LOG_SLOTS; i++) {
-		status = nvmet_copy_to_sgl(req, offset, &ctrl->slots[slot],
-				sizeof(struct nvme_error_slot));
-		if (status)
+		if (nvmet_copy_to_sgl(req, offset, &ctrl->slots[slot],
+				sizeof(struct nvme_error_slot)))
 			break;
 
 		if (slot == 0)
@@ -59,7 +57,7 @@ static void nvmet_execute_get_log_page_error(struct nvmet_req *req)
 		offset += sizeof(struct nvme_error_slot);
 	}
 	spin_unlock_irqrestore(&ctrl->error_lock, flags);
-	nvmet_req_complete(req, status);
+	nvmet_req_complete(req, 0);
 }
 
 static u16 nvmet_get_smart_log_nsid(struct nvmet_req *req,

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* RE: [PATCH] nvmet: fix a wrong error status returned in error log page
  2019-09-04 13:14 ` Christoph Hellwig
@ 2019-09-04 14:05   ` Engel, Amit
  2019-09-04 15:19     ` Christoph Hellwig
  0 siblings, 1 reply; 11+ messages in thread
From: Engel, Amit @ 2019-09-04 14:05 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: sagi, linux-nvme

I agree that your proposal should work as well.

(BTW, we can simply use
num_of_sgl_slots = req->data_len/sizeof(struct nvme_error_slot)

How do you want to proceed?
Should I provide a patch according to your suggestion?

Thanks
Amit
-----Original Message-----
From: Christoph Hellwig <hch@infradead.org> 
Sent: Wednesday, September 4, 2019 4:15 PM
To: Engel, Amit
Cc: sagi@grimberg.me; linux-nvme@lists.infradead.org
Subject: Re: [PATCH] nvmet: fix a wrong error status returned in error log page


[EXTERNAL EMAIL] 

Sorry for dropping the ball earlier..

> +	num_of_sgl_slots = do_div(req->data_len, sizeof(struct 
> +nvme_error_slot));

I don't think this does what you think it does.  do_div has a reall odd calling convention where it returns the result of the division in the first argument (despite that not beeing passd by reference, thanks to being implemented as a macro), and returns the remainder in the actual return value.

But I think the fix might actually be as simple as:


diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c index 4dc12ea52f23..543fb2a0c005 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -37,7 +37,6 @@ static void nvmet_execute_get_log_page_noop(struct nvmet_req *req)  static void nvmet_execute_get_log_page_error(struct nvmet_req *req)  {
 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
-	u16 status = NVME_SC_SUCCESS;
 	unsigned long flags;
 	off_t offset = 0;
 	u64 slot;
@@ -47,9 +46,8 @@ static void nvmet_execute_get_log_page_error(struct nvmet_req *req)
 	slot = ctrl->err_counter % NVMET_ERROR_LOG_SLOTS;
 
 	for (i = 0; i < NVMET_ERROR_LOG_SLOTS; i++) {
-		status = nvmet_copy_to_sgl(req, offset, &ctrl->slots[slot],
-				sizeof(struct nvme_error_slot));
-		if (status)
+		if (nvmet_copy_to_sgl(req, offset, &ctrl->slots[slot],
+				sizeof(struct nvme_error_slot)))
 			break;
 
 		if (slot == 0)
@@ -59,7 +57,7 @@ static void nvmet_execute_get_log_page_error(struct nvmet_req *req)
 		offset += sizeof(struct nvme_error_slot);
 	}
 	spin_unlock_irqrestore(&ctrl->error_lock, flags);
-	nvmet_req_complete(req, status);
+	nvmet_req_complete(req, 0);
 }
 
 static u16 nvmet_get_smart_log_nsid(struct nvmet_req *req,

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] nvmet: fix a wrong error status returned in error log page
  2019-09-04 14:05   ` Engel, Amit
@ 2019-09-04 15:19     ` Christoph Hellwig
  2019-09-04 18:40       ` Engel, Amit
  0 siblings, 1 reply; 11+ messages in thread
From: Christoph Hellwig @ 2019-09-04 15:19 UTC (permalink / raw)
  To: Engel, Amit; +Cc: Christoph Hellwig, sagi, linux-nvme

On Wed, Sep 04, 2019 at 02:05:16PM +0000, Engel, Amit wrote:
> Should I provide a patch according to your suggestion?

Yes, please do.

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [PATCH] nvmet: fix a wrong error status returned in error log page
  2019-09-04 15:19     ` Christoph Hellwig
@ 2019-09-04 18:40       ` Engel, Amit
  2019-09-11 19:19         ` Engel, Amit
  0 siblings, 1 reply; 11+ messages in thread
From: Engel, Amit @ 2019-09-04 18:40 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: sagi, linux-nvme

Ok, Done

Thanks
Amit

-----Original Message-----
From: Christoph Hellwig <hch@infradead.org> 
Sent: Wednesday, September 4, 2019 6:20 PM
To: Engel, Amit
Cc: Christoph Hellwig; sagi@grimberg.me; linux-nvme@lists.infradead.org
Subject: Re: [PATCH] nvmet: fix a wrong error status returned in error log page


[EXTERNAL EMAIL] 

On Wed, Sep 04, 2019 at 02:05:16PM +0000, Engel, Amit wrote:
> Should I provide a patch according to your suggestion?

Yes, please do.

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [PATCH] nvmet: fix a wrong error status returned in error log page
  2019-09-04 18:40       ` Engel, Amit
@ 2019-09-11 19:19         ` Engel, Amit
  2019-09-11 19:44           ` Sagi Grimberg
  0 siblings, 1 reply; 11+ messages in thread
From: Engel, Amit @ 2019-09-11 19:19 UTC (permalink / raw)
  To: Christoph Hellwig, sagi; +Cc: linux-nvme

Hi Christoph/Sagi,

Any estimation when this patch will be pushed upstream officially?

Thanks
Amit

-----Original Message-----
From: Engel, Amit 
Sent: Wednesday, September 4, 2019 9:41 PM
To: 'Christoph Hellwig'
Cc: sagi@grimberg.me; linux-nvme@lists.infradead.org
Subject: RE: [PATCH] nvmet: fix a wrong error status returned in error log page

Ok, Done

Thanks
Amit

-----Original Message-----
From: Christoph Hellwig <hch@infradead.org> 
Sent: Wednesday, September 4, 2019 6:20 PM
To: Engel, Amit
Cc: Christoph Hellwig; sagi@grimberg.me; linux-nvme@lists.infradead.org
Subject: Re: [PATCH] nvmet: fix a wrong error status returned in error log page


[EXTERNAL EMAIL] 

On Wed, Sep 04, 2019 at 02:05:16PM +0000, Engel, Amit wrote:
> Should I provide a patch according to your suggestion?

Yes, please do.

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] nvmet: fix a wrong error status returned in error log page
  2019-09-11 19:19         ` Engel, Amit
@ 2019-09-11 19:44           ` Sagi Grimberg
  2019-09-12  5:32             ` Engel, Amit
  0 siblings, 1 reply; 11+ messages in thread
From: Sagi Grimberg @ 2019-09-11 19:44 UTC (permalink / raw)
  To: Engel, Amit, Christoph Hellwig; +Cc: linux-nvme

Didn't see a new patch from you Amit.

Can you resend?

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [PATCH] nvmet: fix a wrong error status returned in error log page
  2019-09-11 19:44           ` Sagi Grimberg
@ 2019-09-12  5:32             ` Engel, Amit
  0 siblings, 0 replies; 11+ messages in thread
From: Engel, Amit @ 2019-09-12  5:32 UTC (permalink / raw)
  To: Sagi Grimberg, Christoph Hellwig; +Cc: linux-nvme

Just resent that, please let me know in case you didn’t get it

Thanks
Amit

-----Original Message-----
From: Sagi Grimberg <sagi@grimberg.me> 
Sent: Wednesday, September 11, 2019 10:45 PM
To: Engel, Amit; Christoph Hellwig
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH] nvmet: fix a wrong error status returned in error log page


[EXTERNAL EMAIL] 

Didn't see a new patch from you Amit.

Can you resend?
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] nvmet: fix a wrong error status returned in error log page
  2019-09-12  5:29 amit.engel
  2019-09-12 12:09 ` Christoph Hellwig
@ 2019-09-12 15:50 ` Sagi Grimberg
  1 sibling, 0 replies; 11+ messages in thread
From: Sagi Grimberg @ 2019-09-12 15:50 UTC (permalink / raw)
  To: amit.engel, linux-nvme

Applied to nvme-5.4

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] nvmet: fix a wrong error status returned in error log page
  2019-09-12  5:29 amit.engel
@ 2019-09-12 12:09 ` Christoph Hellwig
  2019-09-12 15:50 ` Sagi Grimberg
  1 sibling, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2019-09-12 12:09 UTC (permalink / raw)
  To: amit.engel; +Cc: sagi, linux-nvme

On Thu, Sep 12, 2019 at 08:29:39AM +0300, amit.engel@dell.com wrote:
> From: Amit <amit.engel@emc.com>
> 
> When the command data_len cannot hold all the controller errors,
> we should simply return as much errors as we can fit
> instead of failing the command.
> 
> Signed-off-by: Amit Engel <amit.engel@dell.com>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] nvmet: fix a wrong error status returned in error log page
@ 2019-09-12  5:29 amit.engel
  2019-09-12 12:09 ` Christoph Hellwig
  2019-09-12 15:50 ` Sagi Grimberg
  0 siblings, 2 replies; 11+ messages in thread
From: amit.engel @ 2019-09-12  5:29 UTC (permalink / raw)
  To: sagi, linux-nvme; +Cc: Amit

From: Amit <amit.engel@emc.com>

When the command data_len cannot hold all the controller errors,
we should simply return as much errors as we can fit
instead of failing the command.

Signed-off-by: Amit Engel <amit.engel@dell.com>
---
 drivers/nvme/target/admin-cmd.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 51800a9ce9a9..831a062d27cb 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -37,7 +37,6 @@ static void nvmet_execute_get_log_page_noop(struct nvmet_req *req)
 static void nvmet_execute_get_log_page_error(struct nvmet_req *req)
 {
 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
-	u16 status = NVME_SC_SUCCESS;
 	unsigned long flags;
 	off_t offset = 0;
 	u64 slot;
@@ -47,9 +46,8 @@ static void nvmet_execute_get_log_page_error(struct nvmet_req *req)
 	slot = ctrl->err_counter % NVMET_ERROR_LOG_SLOTS;
 
 	for (i = 0; i < NVMET_ERROR_LOG_SLOTS; i++) {
-		status = nvmet_copy_to_sgl(req, offset, &ctrl->slots[slot],
-				sizeof(struct nvme_error_slot));
-		if (status)
+		if (nvmet_copy_to_sgl(req, offset, &ctrl->slots[slot],
+				sizeof(struct nvme_error_slot)))
 			break;
 
 		if (slot == 0)
@@ -59,7 +57,7 @@ static void nvmet_execute_get_log_page_error(struct nvmet_req *req)
 		offset += sizeof(struct nvme_error_slot);
 	}
 	spin_unlock_irqrestore(&ctrl->error_lock, flags);
-	nvmet_req_complete(req, status);
+	nvmet_req_complete(req, 0);
 }
 
 static u16 nvmet_get_smart_log_nsid(struct nvmet_req *req,
-- 
2.16.5


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-09-12 15:50 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-31 18:50 [PATCH] nvmet: fix a wrong error status returned in error log page amit.engel
2019-09-04 13:14 ` Christoph Hellwig
2019-09-04 14:05   ` Engel, Amit
2019-09-04 15:19     ` Christoph Hellwig
2019-09-04 18:40       ` Engel, Amit
2019-09-11 19:19         ` Engel, Amit
2019-09-11 19:44           ` Sagi Grimberg
2019-09-12  5:32             ` Engel, Amit
2019-09-12  5:29 amit.engel
2019-09-12 12:09 ` Christoph Hellwig
2019-09-12 15:50 ` Sagi Grimberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).