nvmet: Fix discover log page when offsets are used
Subsystems (2)
PATCH 1/1 nvmet: Fix discover log page when offsets are used
The nvme target hadn't been taking the Get Log Page offset parameter into consideration, and so has been returning corrupting logs pages when offsets are used. Since many tools, including nvme-cli, split the log request to 4k, we've been breaking discovery log responses when more than 3 subsystems exist.
Fix the log page by internally generating the entire discovery log page and copying only the requested bytes into the user buffer.
--- drivers/nvme/target/admin-cmd.c | 10 +++++++ drivers/nvme/target/discovery.c | 63 +++++++++++++++++++++++++---------------- drivers/nvme/target/nvmet.h | 1 + 3 files changed, 50 insertions(+), 24 deletions(-)
drivers/nvme/target/admin-cmd.c +10 -0
@@ -24,6 +24,16 @@ u32 nvmet_get_log_page_len(struct nvme_command *cmd)return len; } +u64 nvmet_get_log_page_offset (struct nvme_command *cmd) +{ +u64 offset =le32_to_cpu (cmd->get_log_page.lpou); + + offset <<=32 ; + offset +=le32_to_cpu (cmd->get_log_page.lpol); + +return offset; +} +static void nvmet_execute_get_log_page_noop (struct nvmet_req *req) {nvmet_req_complete (req,nvmet_zero_sgl (req,0 , req->data_len));
drivers/nvme/target/discovery.c +39 -24
100 lines not on this page · raw message
drivers/nvme/target/nvmet.h +1 -0
@@ -428,6 +428,7 @@ u16 nvmet_copy_from_sgl(struct nvmet_req *req, off_t off, void *buf,u16 nvmet_zero_sgl (struct nvmet_req *req,off_t off,size_t len);u32 nvmet_get_log_page_len (struct nvme_command *cmd); +u64 nvmet_get_log_page_offset (struct nvme_command *cmd);extern struct list_head *nvmet_ports; void nvmet_port_disc_changed(struct nvmet_port *port,
Signature · 1 line
2.14.4
Keith Busch
maintainerPATCH 1/1 nvmet: Fix discover log page when offsets are used
drivers/nvme/target/discovery.c static void nvmet_execute_get_disc_log_page(struct nvmet_req *req) · line 177
Quoted 13 lines · Keith Busch
drivers/nvme/target/discovery.c +4
-2@@ -149,36 +168,33 @@ static void nvmet_execute_get_disc_log_page(struct nvmet_req *req)* If host provided data len is less than the header size, only the * number of bytes requested by host will be sent to host. */ - hdr =kzalloc (alloc_len,GFP_KERNEL ); -if (!hdr) { +down_read (&nvmet_config_sem); + alloc_len =sizeof (*hdr) + entry_size *discovery_log_entries (req); + buffer =kzalloc (alloc_len,GFP_KERNEL ); +if (!buffer) { status =NVME_SC_INTERNAL ; goto out; }
There's an error here not unlocking the target control rw-semaphore on allocation failure. Going to send a v2 in 5 seconds, so please disregard this one.
PATCH 1/1 nvmet: Fix discover log page when offsets are used
In reply to Keith BuschQuoted 9 lines · Keith Busch
The nvme target hadn't been taking the Get Log Page offset parameter into consideration, and so has been returning corrupting logs pages when offsets are used. Since many tools, including nvme-cli, split the log request to 4k, we've been breaking discovery log responses when more than 3 subsystems exist.
Fix the log page by internally generating the entire discovery log page and copying only the requested bytes into the user buffer.
Quoted 9 lines
Cc Hannes Reinecke <hare at suse.de>Signed-off-by Keith Busch <keith.busch at intel.com>--- drivers/nvme/target/admin-cmd.c | 10 +++++++ drivers/nvme/target/discovery.c | 63 +++++++++++++++++++++++++---------------- drivers/nvme/target/nvmet.h | 1 + 3 files changed, 50 insertions(+), 24 deletions(-)
Looks good.
-- james
PATCH 1/1 nvmet: Fix discover log page when offsets are used
Quoted 23 lines · James Smart
Quoted 9 lines · Keith Busch
The nvme target hadn't been taking the Get Log Page offset parameter into consideration, and so has been returning corrupting logs pages when offsets are used. Since many tools, including nvme-cli, split the log request to 4k, we've been breaking discovery log responses when more than 3 subsystems exist.
Fix the log page by internally generating the entire discovery log page and copying only the requested bytes into the user buffer.
Quoted 10 lines
Cc Hannes Reinecke <hare at suse.de>Signed-off-by Keith Busch <keith.busch at intel.com>---
?drivers/nvme/target/admin-cmd.c| 10 +++++++ ?drivers/nvme/target/discovery.c| 63
+++++++++++++++++++++++++----------------
?drivers/nvme/target/nvmet.h???? |? 1 +
? 3 files changed, 50 insertions(+), 24 deletions(-)
Quoted 7 lines
Reviewed-by ? James Smart? <james.smart at broadcom.com>Looks good.
-- james
?excepting the locking issue :)
-- james