Rotational storage support
Subsystems (2)
v3 cover Rotational storage support
From: Keith Busch <[email protected]>
The first part gets nvme-target up to 2.1 specification requirements. There were a few identifiactions, logs and a property that nvm e2.1 requires.
The patch from Matias attempts to query the command set independent identify, but this version has changed to do that only if the controller's reported nvme version is 2.0 or greater.
Keith Busch (9):
nvmet: implement id ns for nvm command set
nvmet: implement active command set ns list
nvmet: implement supported log pages
nvmet: implement supported features log
nvmet: implement crto property
nvmet: declare 2.1 version compliance
nvmet: implement endurance grous
nvmet: implement rotational media information log
nvmet: support for csi identify ns
Matias Bjørling (2):
nvme: make independent ns identify default
nvme: add rotational support
drivers/nvme/host/core.c | 14 +- drivers/nvme/target/admin-cmd.c | 240 +++++++++++++++++++++++++++++- drivers/nvme/target/fabrics-cmd.c | 3 + drivers/nvme/target/nvmet.h | 2 +- include/linux/nvme.h | 48 +++++- 5 files changed, 295 insertions(+), 12 deletions(-)
Signature · 1 line
2.43.5
PATCH v3 1/11 nvmet: implement id ns for nvm command set
From: Keith Busch <[email protected]>
Nothing to report here, but it's a mandatory identification for nvme 2.1.
--- drivers/nvme/target/admin-cmd.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/nvme/target/admin-cmd.c +16 -2
@@ -685,6 +685,20 @@ static void nvmet_execute_identify_ctrl_nvm(struct nvmet_req *req) nvmet_zero_sgl(req, 0, sizeof(struct nvme_id_ctrl_nvm))); } +static void nvme_execute_identify_ns_nvm (struct nvmet_req *req) +{ +u16 status; + + status =nvmet_req_find_ns (req); +if (status) + goto out; + + status =nvmet_copy_to_sgl (req,0 ,ZERO_PAGE (0 ), +NVME_IDENTIFY_DATA_SIZE ); +out: +nvmet_req_complete (req, status); +} +static void nvmet_execute_identify (struct nvmet_req *req) {if (!nvmet_check_transfer_len (req,NVME_IDENTIFY_DATA_SIZE ))
@@ -706,8 +720,8 @@ static void nvmet_execute_identify(struct nvmet_req *req)case NVME_ID_CNS_CS_NS :switch (req->cmd->identify.csi) {case NVME_CSI_NVM : -/* Not supported */ -break ; +nvme_execute_identify_ns_nvm (req); +return ;case NVME_CSI_ZNS :if (IS_ENABLED (CONFIG_BLK_DEV_ZONED )) {nvmet_execute_identify_ns_zns (req);
Signature · 1 line
2.43.5
Re: [PATCHv3 01/11] nvmet: implement id ns for nvm command set
Quoted 6 lines · Keith Busch
From: Keith Busch<[email protected]>
Nothing to report here, but it's a mandatory identification for nvme 2.1.
Signed-off-by Keith Busch<[email protected]>
Looks good.
-ck
Christoph Hellwig
maintainerRe: [PATCHv3 01/11] nvmet: implement id ns for nvm command set
In reply to Keith BuschQuoted 4 lines · Keith Busch
From: Keith Busch <[email protected]>
Nothing to report here, but it's a mandatory identification for nvme 2.1.
Yeah, as of 2.1 the only field is LBSTM which we don't support.
Quoted 14 lines
Signed-off-by Keith Busch <[email protected]>--- drivers/nvme/target/admin-cmd.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)drivers/nvme/target/admin-cmd.c +0
-0@@ -685,6 +685,20 @@ static void nvmet_execute_identify_ctrl_nvm(struct nvmet_req *req) nvmet_zero_sgl(req, 0, sizeof(struct nvme_id_ctrl_nvm))); }
drivers/nvme/target/admin-cmd.c static void nvmet_execute_identify_ctrl_nvm(struct nvmet_req *req) · line 697
Quoted 10 lines
drivers/nvme/target/admin-cmd.c +10
-0+static void nvme_execute_identify_ns_nvm (struct nvmet_req *req) +{ +u16 status; + + status =nvmet_req_find_ns (req); +if (status) + goto out; + + status =nvmet_copy_to_sgl (req,0 ,ZERO_PAGE (0 ), +NVME_IDENTIFY_DATA_SIZE );
Does this also need a check for the magic all-Fs nsid, which I think is not supported for the I/O command set specific identify namespace? (see the code іn the zns version)
Keith Busch
maintainerRe: [PATCHv3 01/11] nvmet: implement id ns for nvm command set
Quoted 15 lines · Christoph Hellwig
drivers/nvme/target/admin-cmd.c static void nvmet_execute_identify_ctrl_nvm(struct nvmet_req *req) · line 697
Quoted 10 lines · Keith Busch
drivers/nvme/target/admin-cmd.c +10
-0+static void nvme_execute_identify_ns_nvm (struct nvmet_req *req) +{ +u16 status; + + status =nvmet_req_find_ns (req); +if (status) + goto out; + + status =nvmet_copy_to_sgl (req,0 ,ZERO_PAGE (0 ), +NVME_IDENTIFY_DATA_SIZE );Does this also need a check for the magic all-Fs nsid, which I think is not supported for the I/O command set specific identify namespace? (see the code іn the zns version)
If the command provides the broadcast NSID, nvmet_req_find_ns() will fail, and target will return an error.
Since you mention it, it seems I've neglected the nvmet_req_find_ns() BUG for the failure case used in an rcu context.
PATCH v3 2/11 nvmet: implement active command set ns list
In reply to Keith BuschFrom: Keith Busch <[email protected]>
This is required for nvme 2.1 for targets that support multiple command sets. We support NVM and ZNS, so are required to support this identification.
--- drivers/nvme/target/admin-cmd.c | 9 +++++++-- include/linux/nvme.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/nvme/target/admin-cmd.c +7 -2
@@ -576,7 +576,7 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req)nvmet_req_complete (req, status); } -static void nvmet_execute_identify_nslist (struct nvmet_req *req) +static void nvmet_execute_identify_nslist (struct nvmet_req *req,bool match_css) {static const int buf_size =NVME_IDENTIFY_DATA_SIZE ;struct nvmet_ctrl *ctrl = req->sq->ctrl;
@@ -606,6 +606,8 @@ static void nvmet_execute_identify_nslist(struct nvmet_req *req)xa_for_each (&ctrl->subsys->namespaces, idx, ns) {if (ns->nsid <= min_nsid)continue ; +if (match_css && req->ns->csi != req->cmd->identify.csi) +continue ; list[i++] =cpu_to_le32 (ns->nsid);if (i == buf_size /sizeof (__le32))break ;
@@ -712,7 +714,7 @@ static void nvmet_execute_identify(struct nvmet_req *req)nvmet_execute_identify_ctrl (req);return ;case NVME_ID_CNS_NS_ACTIVE_LIST : -nvmet_execute_identify_nslist (req); +nvmet_execute_identify_nslist (req, false);return ;case NVME_ID_CNS_NS_DESC_LIST :nvmet_execute_identify_desclist (req);
@@ -743,6 +745,9 @@ static void nvmet_execute_identify(struct nvmet_req *req)break ; }break ; +case NVME_ID_CNS_NS_ACTIVE_LIST_CS : +nvmet_execute_identify_nslist (req, true); +return ; } pr_debug("unhandled identify cns %d on qid %d\n",
include/linux/nvme.h +1 -0
@@ -522,6 +522,7 @@ enum {NVME_ID_CNS_NS_DESC_LIST =0x03 ,NVME_ID_CNS_CS_NS =0x05 ,NVME_ID_CNS_CS_CTRL =0x06 , +NVME_ID_CNS_NS_ACTIVE_LIST_CS =0x07 ,NVME_ID_CNS_NS_CS_INDEP =0x08 ,NVME_ID_CNS_NS_PRESENT_LIST =0x10 , NVME_ID_CNS_NS_PRESENT = 0x11,
Signature · 1 line
2.43.5
Re: [PATCHv3 02/11] nvmet: implement active command set ns list
Quoted 7 lines · Keith Busch
From: Keith Busch<[email protected]>
This is required for nvme 2.1 for targets that support multiple command sets. We support NVM and ZNS, so are required to support this identification.
Signed-off-by Keith Busch<[email protected]>
Looks good.
-ck
Re: [PATCHv3 02/11] nvmet: implement active command set ns list
In reply to Keith BuschLooks good:
PATCH v3 3/11 nvmet: implement supported log pages
In reply to Keith BuschFrom: Keith Busch <[email protected]>
This log is required for nvme 2.1.
--- drivers/nvme/target/admin-cmd.c | 29 +++++++++++++++++++++++++++++ include/linux/nvme.h | 1 + 2 files changed, 30 insertions(+)
drivers/nvme/target/admin-cmd.c +29 -0
@@ -71,6 +71,33 @@ static void nvmet_execute_get_log_page_error(struct nvmet_req *req)nvmet_req_complete (req,0 ); } +static void nvmet_execute_get_supported_log_pages (struct nvmet_req *req) +{ +__le32 *logs; +u16 status; + + logs =kzalloc (1024 ,GFP_KERNEL ); +if (!logs) { + status =NVME_SC_INTERNAL ; + goto out; + } + + logs[NVME_LOG_SUPPORTED ] =cpu_to_le32 (1 ); + logs[NVME_LOG_ERROR ] =cpu_to_le32 (1 ); + logs[NVME_LOG_SMART ] =cpu_to_le32 (1 ); + logs[NVME_LOG_FW_SLOT ] =cpu_to_le32 (1 ); + logs[NVME_LOG_CHANGED_NS ] =cpu_to_le32 (1 ); + logs[NVME_LOG_CMD_EFFECTS ] =cpu_to_le32 (1 ); + logs[NVME_LOG_ENDURANCE_GROUP ] =cpu_to_le32 (1 ); + logs[NVME_LOG_ANA ] =cpu_to_le32 (1 ); + logs[NVME_LOG_RMI ] =cpu_to_le32 (1 ); + + status =nvmet_copy_to_sgl (req,0 , logs,1024 ); +kfree (logs); +out: +nvmet_req_complete (req,0 ); +} +static u16 nvmet_get_smart_log_nsid (struct nvmet_req *req,struct nvme_smart_log *slog) {
@@ -323,6 +350,8 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req)return ;switch (req->cmd->get_log_page.lid) { +case NVME_LOG_SUPPORTED : +return nvmet_execute_get_supported_log_pages (req);case NVME_LOG_ERROR :return nvmet_execute_get_log_page_error (req);case NVME_LOG_SMART :
include/linux/nvme.h +1 -0
@@ -1245,6 +1245,7 @@ enum {NVME_FEAT_WRITE_PROTECT =0x84 ,NVME_FEAT_VENDOR_START =0xC0 ,NVME_FEAT_VENDOR_END =0xFF , +NVME_LOG_SUPPORTED =0x00 ,NVME_LOG_ERROR =0x01 ,NVME_LOG_SMART =0x02 , NVME_LOG_FW_SLOT = 0x03,
Signature · 1 line
2.43.5
Re: [PATCHv3 03/11] nvmet: implement supported log pages
drivers/nvme/target/admin-cmd.c static void nvmet_execute_get_log_page_error(struct nvmet_req *req) · line 98
Quoted 4 lines · Keith Busch
drivers/nvme/target/admin-cmd.c +4
-0+ status =nvmet_copy_to_sgl (req,0 , logs,1024 ); +kfree (logs); +out: +nvmet_req_complete (req,0 );
Shouldn't this be: nvmet_req_complete(req, status)?
Re: [PATCHv3 03/11] nvmet: implement supported log pages
In reply to Keith BuschQuoted 28 lines · Keith Busch
From: Keith Busch<[email protected]>
This log is required for nvme 2.1.
Signed-off-by Keith Busch<[email protected]>--- drivers/nvme/target/admin-cmd.c | 29 +++++++++++++++++++++++++++++ include/linux/nvme.h | 1 + 2 files changed, 30 insertions(+)drivers/nvme/target/admin-cmd.c +10
-0@@ -71,6 +71,33 @@ static void nvmet_execute_get_log_page_error(struct nvmet_req *req)nvmet_req_complete (req,0 ); } +static void nvmet_execute_get_supported_log_pages (struct nvmet_req *req) +{ +__le32 *logs; +u16 status; + + logs =kzalloc (1024 ,GFP_KERNEL ); +if (!logs) { + status =NVME_SC_INTERNAL ; + goto out; + }
drivers/nvme/target/admin-cmd.c static void nvmet_execute_get_log_page_error(struct nvmet_req *req) · line 93
Quoted 10 lines
drivers/nvme/target/admin-cmd.c +10
-0+ + logs[NVME_LOG_SUPPORTED ] =cpu_to_le32 (1 ); + logs[NVME_LOG_ERROR ] =cpu_to_le32 (1 ); + logs[NVME_LOG_SMART ] =cpu_to_le32 (1 ); + logs[NVME_LOG_FW_SLOT ] =cpu_to_le32 (1 ); + logs[NVME_LOG_CHANGED_NS ] =cpu_to_le32 (1 ); + logs[NVME_LOG_CMD_EFFECTS ] =cpu_to_le32 (1 ); + logs[NVME_LOG_ENDURANCE_GROUP ] =cpu_to_le32 (1 ); + logs[NVME_LOG_ANA ] =cpu_to_le32 (1 ); + logs[NVME_LOG_RMI ] =cpu_to_le32 (1 );
based on what we have in nvmet_get_cmd_effects_nvm() how about :-
logs[NVME_LOG_SUPPORTED] =
logs[NVME_LOG_ERROR] =
logs[NVME_LOG_SMART] =
logs[NVME_LOG_FW_SLOT] =
logs[NVME_LOG_CHANGED_NS] =
logs[NVME_LOG_CMD_EFFECTS] =
logs[NVME_LOG_ENDURANCE_GROUP] =
logs[NVME_LOG_ANA] =
logs[NVME_LOG_RMI] =
cpu_to_le32(1);if you don't like please ignore this comment.
Looks good.
-ck
Re: [PATCHv3 03/11] nvmet: implement supported log pages
Quoted 54 lines · Chaitanya Kulkarni
Quoted 29 lines · Keith Busch
From: Keith Busch<[email protected]>
This log is required for nvme 2.1.
Signed-off-by Keith Busch<[email protected]>---
drivers/nvme/target/admin-cmd.c| 29 +++++++++++++++++++++++++++++ include/linux/nvme.h | 1 +2 files changed, 30 insertions(+)drivers/nvme/target/admin-cmd.c +10
-0@@ -71,6 +71,33 @@ static void nvmet_execute_get_log_page_error(struct nvmet_req *req) nvmet_req_complete(req, 0); } +static void nvmet_execute_get_supported_log_pages (struct nvmet_req *req) +{ + __le32 *logs; + u16 status; + + logs = kzalloc(1024, GFP_KERNEL); + if (!logs) { + status = NVME_SC_INTERNAL; + goto out; + }drivers/nvme/target/admin-cmd.c static void nvmet_execute_get_log_page_error(struct · line 93
Quoted 10 lines
drivers/nvme/target/admin-cmd.c +10
-0+ + logs[NVME_LOG_SUPPORTED] = cpu_to_le32(1); + logs[NVME_LOG_ERROR] = cpu_to_le32(1); + logs[NVME_LOG_SMART] = cpu_to_le32(1); + logs[NVME_LOG_FW_SLOT] = cpu_to_le32(1); + logs[NVME_LOG_CHANGED_NS] = cpu_to_le32(1); + logs[NVME_LOG_CMD_EFFECTS] = cpu_to_le32(1); + logs[NVME_LOG_ENDURANCE_GROUP] = cpu_to_le32(1); + logs[NVME_LOG_ANA] = cpu_to_le32(1); + logs[NVME_LOG_RMI] = cpu_to_le32(1);based on what we have in
nvmet_get_cmd_effects_nvm()how about :-logs[NVME_LOG_SUPPORTED] =
logs[NVME_LOG_ERROR] =
logs[NVME_LOG_SMART] =
logs[NVME_LOG_FW_SLOT] =
logs[NVME_LOG_CHANGED_NS] =
logs[NVME_LOG_CMD_EFFECTS] =
logs[NVME_LOG_ENDURANCE_GROUP] =
logs[NVME_LOG_ANA] =
logs[NVME_LOG_RMI] =
cpu_to_le32(1);
Quoted 8 lines
if you don't like please ignore this comment.
Looks good.
Reviewed-by Chaitanya Kulkarni <[email protected]>-ck
with the status fix for nvmet_req_compelete() ofcourse ...
-ck
Re: [PATCHv3 03/11] nvmet: implement supported log pages
In reply to Keith BuschLooks good modulo passing on the status as noted by Kanchan:
PATCH v3 4/11 nvmet: implement supported features log
In reply to Keith BuschFrom: Keith Busch <[email protected]>
This log is required for nvme 2.1.
--- drivers/nvme/target/admin-cmd.c | 25 +++++++++++++++++++++++++ include/linux/nvme.h | 1 + 2 files changed, 26 insertions(+)
drivers/nvme/target/admin-cmd.c +25 -0
@@ -344,6 +344,29 @@ static void nvmet_execute_get_log_page_ana(struct nvmet_req *req)nvmet_req_complete (req, status); } +static void nvmet_execute_get_log_page_features (struct nvmet_req *req) +{ +__le32 *features; +u16 status; + + features =kzalloc (1024 ,GFP_KERNEL ); +if (!features) { + status =NVME_SC_INTERNAL ; + goto out; + } + + features[NVME_FEAT_NUM_QUEUES ] =cpu_to_le32 (1 <<21 |1 ); + features[NVME_FEAT_KATO ] =cpu_to_le32 (1 <<21 |1 ); + features[NVME_FEAT_ASYNC_EVENT ] =cpu_to_le32 (1 <<21 |1 ); + features[NVME_FEAT_HOST_ID ] =cpu_to_le32 (1 <<21 |1 ); + features[NVME_FEAT_WRITE_PROTECT ] =cpu_to_le32 (1 <<20 |1 ); + + status =nvmet_copy_to_sgl (req,0 , features,1024 ); +kfree (features); +out: +nvmet_req_complete (req, status); +} +static void nvmet_execute_get_log_page (struct nvmet_req *req) {if (!nvmet_check_transfer_len (req,nvmet_get_log_page_len (req->cmd)))
@@ -369,6 +392,8 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req)return nvmet_execute_get_log_cmd_effects_ns (req);case NVME_LOG_ANA :return nvmet_execute_get_log_page_ana (req); +case NVME_LOG_FEATURES : +return nvmet_execute_get_log_page_features (req); }pr_debug ("unhandled lid %d on qid %d\n" , req->cmd->get_log_page.lid, req->sq->qid);
include/linux/nvme.h +1 -0
@@ -1256,6 +1256,7 @@ enum {NVME_LOG_TELEMETRY_CTRL =0x08 ,NVME_LOG_ENDURANCE_GROUP =0x09 ,NVME_LOG_ANA =0x0c , +NVME_LOG_FEATURES =0x12 ,NVME_LOG_DISC =0x70 ,NVME_LOG_RESERVATION =0x80 , NVME_FWACT_REPL = (0 << 3),
Signature · 1 line
2.43.5
Re: [PATCHv3 04/11] nvmet: implement supported features log
Quoted 5 lines · Keith Busch
From: Keith Busch<[email protected]>
This log is required for nvme 2.1.
Signed-off-by Keith Busch<[email protected]>
Looks good.
-ck
Christoph Hellwig
maintainerRe: [PATCHv3 04/11] nvmet: implement supported features log
In reply to Keith BuschQuoted 15 lines · Keith Busch
From: Keith Busch <[email protected]>
This log is required for nvme 2.1.
Signed-off-by Keith Busch <[email protected]>--- drivers/nvme/target/admin-cmd.c | 25 +++++++++++++++++++++++++ include/linux/nvme.h | 1 + 2 files changed, 26 insertions(+)drivers/nvme/target/admin-cmd.c +0
-0
drivers/nvme/target/admin-cmd.c static void nvmet_execute_get_log_page_ana(struct nvmet_req *req) · line 352
Quoted 9 lines
drivers/nvme/target/admin-cmd.c +6
-0@@ -344,6 +344,29 @@ static void nvmet_execute_get_log_page_ana(struct nvmet_req *req)nvmet_req_complete (req, status); } +static void nvmet_execute_get_log_page_features (struct nvmet_req *req) +{ +__le32 *features; +u16 status; + + features =kzalloc (1024 ,GFP_KERNEL );
The magic number here is a bit weird. Maybe add a
#define NVME_FEAT_MAX 256
and then make this ΝVME_FEAT_MAX * sizeof(*features)?
Same below.
drivers/nvme/target/admin-cmd.c static void nvmet_execute_get_log_page_ana(struct nvmet_req *req) · line 362
Quoted 10 lines
drivers/nvme/target/admin-cmd.c +10
-0+if (!features) { + status =NVME_SC_INTERNAL ; + goto out; + } + + features[NVME_FEAT_NUM_QUEUES ] =cpu_to_le32 (1 <<21 |1 ); + features[NVME_FEAT_KATO ] =cpu_to_le32 (1 <<21 |1 ); + features[NVME_FEAT_ASYNC_EVENT ] =cpu_to_le32 (1 <<21 |1 ); + features[NVME_FEAT_HOST_ID ] =cpu_to_le32 (1 <<21 |1 ); + features[NVME_FEAT_WRITE_PROTECT ] =cpu_to_le32 (1 <<20 |1 );
And having names for the bits / scopes would be kinda nice as well. (maybe same for the logs in the last patch)
Otherwise this looks good to me.
PATCH v3 5/11 nvmet: implement crto property
In reply to Keith BuschFrom: Keith Busch <[email protected]>
This property is required for nvme 2.1. The target only supports ready with media, so this is just the same value as CAP.TO.
--- drivers/nvme/target/fabrics-cmd.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/nvme/target/fabrics-cmd.c +3 -0
@@ -64,6 +64,9 @@ static void nvmet_execute_prop_get(struct nvmet_req *req)case NVME_REG_CSTS : val = ctrl->csts;break ; +case NVME_REG_CRTO : + val =NVME_CAP_TIMEOUT (ctrl->csts); +break ;default : status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ;break ;
Signature · 1 line
2.43.5
Re: [PATCHv3 05/11] nvmet: implement crto property
Looks good:
PATCH v3 6/11 nvmet: declare 2.1 version compliance
In reply to Keith BuschFrom: Keith Busch <[email protected]>
The target driver implements all the mandatory logs, identifications, features, and properties up to nvme sepcification 2.1.
--- drivers/nvme/target/nvmet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/nvmet.h +1 -1
@@ -21,7 +21,7 @@#include <linux/radix-tree.h> #include <linux/t10-pi.h> -#define NVMET_DEFAULT_VS NVME_VS(1, 3, 0) +#define NVMET_DEFAULT_VS NVME_VS(2, 1, 0)#define NVMET_ASYNC_EVENTS 4#define NVMET_ERROR_LOG_SLOTS 128
Signature · 1 line
2.43.5
Re: [PATCHv3 06/11] nvmet: declare 2.1 version compliance
Quoted 7 lines · Keith Busch
From: Keith Busch<[email protected]>
The target driver implements all the mandatory logs, identifications, features, and properties up to nvme sepcification 2.1.
Signed-off-by Keith Busch<[email protected]>---
Looks good.
-ck
Re: [PATCHv3 06/11] nvmet: declare 2.1 version compliance
In reply to Keith BuschQuoted 4 lines · Keith Busch
From: Keith Busch <[email protected]>
The target driver implements all the mandatory logs, identifications, features, and properties up to nvme sepcification 2.1.
Looks good:
Most unrelated question: do we need a min/max supported version for nvmet_subsys_attr_version_store?
Re: [PATCHv3 06/11] nvmet: declare 2.1 version compliance
Quoted 6 lines · Christoph Hellwig
Quoted 4 lines · Keith Busch
From: Keith Busch <[email protected]>
The target driver implements all the mandatory logs, identifications, features, and properties up to nvme sepcification 2.1.
Quoted 8 lines
Looks good:
Reviewed-by Christoph Hellwig <[email protected]>Most unrelated question: do we need a min/max supported version for
nvmet_subsys_attr_version_store?
By allowing user to set the min and max version it can definitely help configure target version that is compliant with the host version, e.g. if host only supports 1.3.0 then by setting max version to 1.3.0 in the target subsystem will not execute any functionality that is added in this series that belongs to only 2.1.0 version.
Is there any other reason ?
-ck
PATCH v3 7/11 nvmet: implement endurance groups
In reply to Keith BuschFrom: Keith Busch <[email protected]>
Most of the returned information is just stubbed data. The target must support these in order to report rotational media. Since this driver doesn't know any better, each namespace is its own endurance group with the engid value matching the nsid.
--- drivers/nvme/host/core.c | 1 + drivers/nvme/target/admin-cmd.c | 85 +++++++++++++++++++++++++++++++++ include/linux/nvme.h | 29 ++++++++++- 3 files changed, 113 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +1 -0
@@ -5006,6 +5006,7 @@ static inline void _nvme_check_size(void)BUILD_BUG_ON (sizeof (struct nvme_id_ctrl_nvm ) !=NVME_IDENTIFY_DATA_SIZE );BUILD_BUG_ON (sizeof (struct nvme_lba_range_type ) !=64 );BUILD_BUG_ON (sizeof (struct nvme_smart_log ) !=512 ); +BUILD_BUG_ON (sizeof (struct nvme_endurance_group_log ) !=512 );BUILD_BUG_ON (sizeof (struct nvme_dbbuf ) !=64 );BUILD_BUG_ON (sizeof (struct nvme_directive_cmd ) !=64 );BUILD_BUG_ON (sizeof (struct nvme_feat_host_behavior ) !=512 );
drivers/nvme/target/admin-cmd.c +85 -0
121 lines not on this page · raw message
include/linux/nvme.h +27 -2
@@ -327,7 +327,8 @@ struct nvme_id_ctrl {__le32 sanicap;__le32 hmminds;__le16 hmmaxd; -__u8 rsvd338[4 ]; +__le16 nvmsetidmax; +__le16 endgidmax;__u8 anatt;__u8 anacap;__le32 anagrpmax;
@@ -531,6 +532,7 @@ enum {NVME_ID_CNS_SCNDRY_CTRL_LIST =0x15 ,NVME_ID_CNS_NS_GRANULARITY =0x16 ,NVME_ID_CNS_UUID_LIST =0x17 , + NVME_ID_CNS_ENDGRP_LIST = 0x19, }; enum {
@@ -618,6 +620,28 @@ enum { NVME_NIDT_CSI = 0x04, }; +struct nvme_endurance_group_log { +__u8 egcw; +__u8 egfeat; +__u8 rsvd2; +__u8 avsp; +__u8 avspt; +__u8 pused; +__le16 did; +__u8 rsvd8[24 ]; +__u8 ee[16 ]; +__u8 dur[16 ]; +__u8 duw[16 ]; +__u8 muw[16 ]; +__u8 hrc[16 ]; +__u8 hwc[16 ]; +__u8 mdie[16 ]; +__u8 neile[16 ]; +__u8 tegcap[16 ]; +__u8 uegcap[16 ]; +__u8 rsvd192[320 ]; +}; +struct nvme_smart_log {__u8 critical_warning;__u8 temperature[2 ];
@@ -1284,7 +1308,8 @@ struct nvme_identify {__u8 cns;__u8 rsvd3;__le16 ctrlid; -__u8 rsvd11[3 ]; +__le16 cnssid; +__u8 rsvd11;__u8 csi;__u32 rsvd12[4 ]; };
Signature · 1 line
2.43.5
Re: [PATCHv3 07/11] nvmet: implement endurance groups
Quoted 8 lines · Keith Busch
From: Keith Busch<[email protected]>
Most of the returned information is just stubbed data. The target must support these in order to report rotational media. Since this driver doesn't know any better, each namespace is its own endurance group with the engid value matching the nsid.
Signed-off-by Keith Busch<[email protected]>
Looks good.
-ck
Christoph Hellwig
maintainerRe: [PATCHv3 07/11] nvmet: implement endurance groups
In reply to Keith Buschdrivers/nvme/target/admin-cmd.c static u32 nvmet_format_ana_group(struct nvmet_req *req, u32 grpid, · line 310
Quoted 9 lines · Keith Busch
drivers/nvme/target/admin-cmd.c +9
-0+static void nvmet_execute_get_log_page_endgrp (struct nvmet_req *req) +{ +u64 host_reads, host_writes, data_units_read, data_units_written; +struct nvme_endurance_group_log *log; +u16 status; + + req->cmd->common.nsid =cpu_to_le32 ((u32 ) +le16_to_cpu (req->cmd->get_log_page.lsi)); + status =nvmet_req_find_ns (req);
I think this would be a good place to point out that we "emulate" one endurance group per namespace, as the code only make sense with that in mind.
As far as I can tell cpu_to_* does all the normal implicit integer conversions, so the case here and the ones further down should not be needed.
drivers/nvme/target/admin-cmd.c static u32 nvmet_format_ana_group(struct nvmet_req *req, u32 grpid, · line 328
Quoted 6 lines
drivers/nvme/target/admin-cmd.c +6
-0+ host_reads =part_stat_read (req->ns->bdev, ios[READ ]); + data_units_read = +DIV_ROUND_UP (part_stat_read (req->ns->bdev, sectors[READ ]),1000 ); + host_writes =part_stat_read (req->ns->bdev, ios[WRITE ]); + data_units_written = +DIV_ROUND_UP (part_stat_read (req->ns->bdev, sectors[WRITE ]),1000 );
Overly long lines, but IMHO this would read nicer anyway if the round is done later, e.g.:
sectors_written = part_stat_read(req->ns->bdev, sectors[WRITE]); ... put_unaligned_le64(DIV_ROUND_UP(sectors_written, 1000), &log->dur[0]);
drivers/nvme/target/admin-cmd.c static void nvmet_execute_identify_ns(struct nvmet_req *req) · line 706
Quoted 8 lines
drivers/nvme/target/admin-cmd.c +8
-0+xa_for_each (&ctrl->subsys->namespaces, idx, ns) { +if (ns->nsid <= min_endgid) +continue ; + + list[i++] =cpu_to_le16 ((u16 )ns->nsid); +if (i == buf_size /sizeof (__le16)) +break ; + }
No really important, but this could use xas_for_each for avoid doing a full lookup on every iteration.
PATCH v3 8/11 nvmet: implement rotational media information log
In reply to Keith BuschFrom: Keith Busch <[email protected]>
Most of the information is stubbed. Supporting these commands is a requirement for supporting rotational media.
--- drivers/nvme/host/core.c | 1 + drivers/nvme/target/admin-cmd.c | 42 +++++++++++++++++++++++++++++++++ include/linux/nvme.h | 15 +++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +1 -0
@@ -5007,6 +5007,7 @@ static inline void _nvme_check_size(void)BUILD_BUG_ON (sizeof (struct nvme_lba_range_type ) !=64 );BUILD_BUG_ON (sizeof (struct nvme_smart_log ) !=512 );BUILD_BUG_ON (sizeof (struct nvme_endurance_group_log ) !=512 ); +BUILD_BUG_ON (sizeof (struct nvme_rotational_media_log ) !=512 );BUILD_BUG_ON (sizeof (struct nvme_dbbuf ) !=64 );BUILD_BUG_ON (sizeof (struct nvme_directive_cmd ) !=64 );BUILD_BUG_ON (sizeof (struct nvme_feat_host_behavior ) !=512 );
drivers/nvme/target/admin-cmd.c +42 -0
54 lines not on this page · raw message
include/linux/nvme.h +14 -1
@@ -642,6 +642,18 @@ struct nvme_endurance_group_log {__u8 rsvd192[320 ]; }; +struct nvme_rotational_media_log { +__le16 endgid; +__le16 numa; +__le16 nrs; +__u8 rsvd6[2 ]; +__le32 spinc; +__le32 fspinc; +__le32 ldc; +__le32 fldc; +__u8 rsvd24[488 ]; +}; +struct nvme_smart_log {__u8 critical_warning;__u8 temperature[2 ];
@@ -1281,6 +1293,7 @@ enum {NVME_LOG_ENDURANCE_GROUP =0x09 ,NVME_LOG_ANA =0x0c ,NVME_LOG_FEATURES =0x12 , +NVME_LOG_RMI =0x16 ,NVME_LOG_DISC =0x70 ,NVME_LOG_RESERVATION =0x80 , NVME_FWACT_REPL = (0 << 3),
@@ -1417,7 +1430,7 @@ struct nvme_get_log_page_command {__u8 lsp;/* upper 4 bits reserved */ __le16 numdl;__le16 numdu; -__u16 rsvd11; +__le16 lsi; union { struct { __le32 lpol;
Signature · 1 line
2.43.5
Re: [PATCHv3 08/11] nvmet: implement rotational media information log
Looks good modulo the spurious casts mentioned before:
PATCH v3 9/11 nvmet: support for csi identify ns
In reply to Keith BuschFrom: Keith Busch <[email protected]>
Implements reporting the I/O Command Set Independent Identify Namespace command.
--- drivers/nvme/target/admin-cmd.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/nvme/target/admin-cmd.c +32 -0
@@ -879,6 +879,35 @@ static void nvme_execute_identify_ns_nvm(struct nvmet_req *req)nvmet_req_complete (req, status); } +static void nvmet_execute_id_cs_indep (struct nvmet_req *req) +{ +struct nvme_id_ns_cs_indep *id; +u16 status; + + status =nvmet_req_find_ns (req); +if (status) + goto out; + + id =kzalloc (sizeof (*id),GFP_KERNEL ); +if (!id) { + status =NVME_SC_INTERNAL ; + goto out; + } + + id->nstat =NVME_NSTAT_NRDY ; + id->anagrpid = req->ns->anagrpid; + id->nmic =NVME_NS_NMIC_SHARED ; +if (req->ns->readonly) + id->nsattr |=NVME_NS_ATTR_RO ; +if (req->ns->bdev && !bdev_nonrot (req->ns->bdev)) + id->nsfeat |=NVME_NS_ROTATIONAL ; + + status =nvmet_copy_to_sgl (req,0 , id,sizeof (*id)); +kfree (id); +out: +nvmet_req_complete (req, status); +} +static void nvmet_execute_identify (struct nvmet_req *req) {if (!nvmet_check_transfer_len (req,NVME_IDENTIFY_DATA_SIZE ))
@@ -926,6 +955,9 @@ static void nvmet_execute_identify(struct nvmet_req *req)case NVME_ID_CNS_NS_ACTIVE_LIST_CS :nvmet_execute_identify_nslist (req, true);return ; +case NVME_ID_CNS_NS_CS_INDEP : +nvmet_execute_id_cs_indep (req); +return ;case NVME_ID_CNS_ENDGRP_LIST :nvmet_execute_identify_endgrp_list (req);return ;
Signature · 1 line
2.43.5
Re: [PATCHv3 09/11] nvmet: support for csi identify ns
Quoted 25 lines · Keith Busch
From: Keith Busch <[email protected]>
Implements reporting the I/O Command Set Independent Identify Namespace command.
Signed-off-by Keith Busch <[email protected]>--- drivers/nvme/target/admin-cmd.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)drivers/nvme/target/admin-cmd.c +7
-0@@ -879,6 +879,35 @@ static void nvme_execute_identify_ns_nvm(struct nvmet_req *req)nvmet_req_complete (req, status); } +static void nvmet_execute_id_cs_indep (struct nvmet_req *req) +{ +struct nvme_id_ns_cs_indep *id; +u16 status; + + status =nvmet_req_find_ns (req); +if (status)
drivers/nvme/target/admin-cmd.c static void nvme_execute_identify_ns_nvm(struct nvmet_req *req) · line 898
Quoted 10 lines
drivers/nvme/target/admin-cmd.c +10
-0+ goto out; + + id =kzalloc (sizeof (*id),GFP_KERNEL ); +if (!id) { + status =NVME_SC_INTERNAL ; + goto out; + } + + id->nstat =NVME_NSTAT_NRDY ; + id->anagrpid = req->ns->anagrpid;
Should use cpu_to_le32(req->ns->anagrpid) here.
drivers/nvme/target/admin-cmd.c static void nvme_execute_identify_ns_nvm(struct nvmet_req *req) · line 899
Quoted 1 line
drivers/nvme/target/admin-cmd.c +1
-0+ id->nmic =NVME_NS_NMIC_SHARED ;
Nit, id->nmic |= NVME_NS_NMIC_SHARED;
Best Regards,
Guixin Liu
Quoted 10 lines
drivers/nvme/target/admin-cmd.c +10
-0+if (req->ns->readonly) + id->nsattr |=NVME_NS_ATTR_RO ; +if (req->ns->bdev && !bdev_nonrot (req->ns->bdev)) + id->nsfeat |=NVME_NS_ROTATIONAL ; + + status =nvmet_copy_to_sgl (req,0 , id,sizeof (*id)); +kfree (id); +out: +nvmet_req_complete (req, status); +}
PATCH v3 10/11 nvme: make independent ns identify default
In reply to Keith BuschFrom: Matias Bjørling <[email protected]>
The NVMe 2.0 specification adds an independent identify namespace data structure that contains generic attributes that apply to all namespace types. Some attributes carry over from the NVM command set identify namespace data structure, and others are new.
Currently, the data structure only considered when CRIMS is enabled or when the namespace type is key-value.
However, the independent namespace data structure is mandatory for devices that implement features from the 2.0+ specification. Therefore, we can check this data structure first. If unavailable, retrieve the generic attributes from the NVM command set identify namespace data structure.
--- drivers/nvme/host/core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/nvme/host/core.c +3 -4
@@ -3988,7 +3988,7 @@ static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid) {struct nvme_ns_info info = { .nsid = nsid };struct nvme_ns *ns; -int ret; +int ret =1 ;if (nvme_identify_ns_descs (ctrl, &info))return ;
@@ -4004,10 +4004,9 @@ static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid)* data structure to find all the generic information that is needed to * set up a namespace. If not fall back to the legacy version. */ -if ((ctrl->cap &NVME_CAP_CRMS_CRIMS ) || - (info.ids.csi !=NVME_CSI_NVM && info.ids.csi !=NVME_CSI_ZNS )) +if (ctrl->vs >=NVME_VS (2 ,0 ,0 )) ret =nvme_ns_info_from_id_cs_indep (ctrl, &info); -else +if (ret >0 ) ret =nvme_ns_info_from_identify (ctrl, &info);if (info.is_removed)
Signature · 1 line
2.43.5
Keith Busch
maintainerRe: [PATCHv3 10/11] nvme: make independent ns identify default
drivers/nvme/host/core.c static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid) · line 4008
Quoted 8 lines · Keith Busch
drivers/nvme/host/core.c +1
-2@@ -4004,10 +4004,9 @@ static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid)* data structure to find all the generic information that is needed to * set up a namespace. If not fall back to the legacy version. */ -if ((ctrl->cap &NVME_CAP_CRMS_CRIMS ) || - (info.ids.csi !=NVME_CSI_NVM && info.ids.csi !=NVME_CSI_ZNS )) +if (ctrl->vs >=NVME_VS (2 ,0 ,0 )) ret =nvme_ns_info_from_id_cs_indep (ctrl, &info);
This should probably retain the previous conditions and just OR in the 2.0 check instead. I already made the change in my local branch, it looks like this:
if ((ctrl->cap & NVME_CAP_CRMS_CRIMS) || (info.ids.csi != NVME_CSI_NVM && info.ids.csi != NVME_CSI_ZNS) || ctrl->vs >= NVME_VS(2, 0, 0))
Re: [PATCHv3 10/11] nvme: make independent ns identify default
In reply to Keith BuschQuoted 6 lines · Keith Busch
From: Matias Bjørling <[email protected]>
The NVMe 2.0 specification adds an independent identify namespace data structure that contains generic attributes that apply to all namespace types. Some attributes carry over from the NVM command set identify namespace data structure, and others are new.
The subject could probably use a little ammending, e.g.
"use command set independent identify namespace if available"
Otherwise looks good:
PATCH v3 11/11 nvme: add rotational support
In reply to Keith BuschFrom: Matias Bjørling <[email protected]>
Rotational devices, such as hard-drives, can be detected using the rotational bit in the namespace independent identify namespace data structure. Make the bit visible to the block layer through the rotational queue setting.
Note that rotational devices typically can be used to generate random entropy, the device is therefore also added as a block device that adds entropy.
--- drivers/nvme/host/core.c | 5 +++++ include/linux/nvme.h | 1 + 2 files changed, 6 insertions(+)
drivers/nvme/host/core.c +5 -0
@@ -42,6 +42,7 @@ struct nvme_ns_info {bool is_readonly;bool is_ready;bool is_removed; +bool is_rotational; };unsigned int admin_timeout =60 ;
@@ -1615,6 +1616,7 @@ static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl, info->is_shared = id->nmic &NVME_NS_NMIC_SHARED ; info->is_readonly = id->nsattr &NVME_NS_ATTR_RO ; info->is_ready = id->nstat &NVME_NSTAT_NRDY ; + info->is_rotational = id->nsfeat &NVME_NS_ROTATIONAL ; }kfree (id);return ret;
@@ -2162,6 +2164,9 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,else lim.features &= ~(BLK_FEAT_WRITE_CACHE |BLK_FEAT_FUA ); +if (info->is_rotational) + lim.features |=BLK_FEAT_ROTATIONAL |BLK_FEAT_ADD_RANDOM ; +/* * Register a metadata profile for PI, or the plain non-integrity NVMe * metadata masquerading as Type 0 if supported, otherwise reject block
include/linux/nvme.h +1 -0
@@ -563,6 +563,7 @@ enum {NVME_NS_FLBAS_LBA_SHIFT =1 ,NVME_NS_FLBAS_META_EXT =0x10 ,NVME_NS_NMIC_SHARED =1 <<0 , +NVME_NS_ROTATIONAL =1 <<4 ,NVME_LBAF_RP_BEST =0 ,NVME_LBAF_RP_BETTER =1 , NVME_LBAF_RP_GOOD = 2,
Signature · 1 line
2.43.5
Re: [PATCHv3 11/11] nvme: add rotational support
Looks good:
Re: [PATCHv3 11/11] nvme: add rotational support
In reply to Keith BuschQuoted 7 lines · Keith Busch
From: Matias Bjørling<[email protected]>
Rotational devices, such as hard-drives, can be detected using the rotational bit in the namespace independent identify namespace data structure. Make the bit visible to the block layer through the rotational queue setting.
Quoted 7 lines
Note that rotational devices typically can be used to generate random entropy, the device is therefore also added as a block device that adds entropy.
Signed-off-by Matias Bjørling<[email protected]>Reviewed-by Martin K. Petersen<[email protected]>Signed-off-by Keith Busch<[email protected]>
Looks good.
-ck
Re: [PATCHv3 11/11] nvme: add rotational support
In reply to Keith BuschQuoted 40 lines · Keith Busch
From: Matias Bjørling <[email protected]>
Rotational devices, such as hard-drives, can be detected using the rotational bit in the namespace independent identify namespace data structure. Make the bit visible to the block layer through the rotational queue setting.
Note that rotational devices typically can be used to generate random entropy, the device is therefore also added as a block device that adds entropy.
Signed-off-by Matias Bjørling <[email protected]>Reviewed-by Martin K. Petersen <[email protected]>Signed-off-by Keith Busch <[email protected]>--- drivers/nvme/host/core.c | 5 +++++ include/linux/nvme.h | 1 + 2 files changed, 6 insertions(+)drivers/nvme/host/core.c +2
-0@@ -42,6 +42,7 @@ struct nvme_ns_info {bool is_readonly;bool is_ready;bool is_removed; +bool is_rotational; };unsigned int admin_timeout =60 ;@@ -1615,6 +1616,7 @@ static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl, info->is_shared = id->nmic &NVME_NS_NMIC_SHARED ; info->is_readonly = id->nsattr &NVME_NS_ATTR_RO ; info->is_ready = id->nstat &NVME_NSTAT_NRDY ; + info->is_rotational = id->nsfeat &NVME_NS_ROTATIONAL ; }kfree (id);return ret;
drivers/nvme/host/core.c static int nvme_update_ns_info_block(struct nvme_ns *ns, · line 2169
Quoted 6 lines
drivers/nvme/host/core.c +3
-0@@ -2162,6 +2164,9 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,else lim.features &= ~(BLK_FEAT_WRITE_CACHE |BLK_FEAT_FUA ); +if (info->is_rotational) + lim.features |=BLK_FEAT_ROTATIONAL |BLK_FEAT_ADD_RANDOM ; +
May I pose a question, what does BLK_FEAT_ADD_RANDOM do?
I see the scsi call add_disk_randomness() in scsi_end_request() if request_queue has
BLK_FEAT_ADD_RANDOM flag, but I dont see any calls in the patchset.
Best Regards,
Guixin Liu
Quoted 15 lines
drivers/nvme/host/core.c +0
-0/* * Register a metadata profile for PI, or the plain non-integrity NVMe * metadata masquerading as Type 0 if supported, otherwise reject block include/linux/nvme.h +1
-0@@ -563,6 +563,7 @@ enum {NVME_NS_FLBAS_LBA_SHIFT =1 ,NVME_NS_FLBAS_META_EXT =0x10 ,NVME_NS_NMIC_SHARED =1 <<0 , +NVME_NS_ROTATIONAL =1 <<4 ,NVME_LBAF_RP_BEST =0 ,NVME_LBAF_RP_BETTER =1 , NVME_LBAF_RP_GOOD = 2,
Christoph Hellwig
maintainerRe: [PATCHv3 11/11] nvme: add rotational support
Quoted 1 line · Guixin Liu
May I pose a question, what does
BLK_FEAT_ADD_RANDOMdo?
Nothing.
Quoted 2 lines
I see the scsi call
add_disk_randomness()inscsi_end_request()ifrequest_queuehas
Yes.
Quoted 2 lines
BLK_FEAT_ADD_RANDOMflag, but I dont see any calls in the patchset.
I actually pointed that out last round and thought it got fixed, should have noticed it wasn't this time around. The flag really should be dropped.
Keith Busch
maintainerRe: [PATCHv3 11/11] nvme: add rotational support
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Guixin Liu
BLK_FEAT_ADD_RANDOMflag, but I dont see any calls in the patchset.I actually pointed that out last round and thought it got fixed, should have noticed it wasn't this time around. The flag really should be dropped.
My bad, I applied the RFC patch here, but it was already fixed it in subsequent version.
I'm fixing up the remaining stuff from the review comments. Will spin a new version shortly.