Skip to contentSkip to conversation

nvme/nvmet AEN and log page fixups v2

PATCH In review Christoph Hellwig 6 participants 43 messages May 30, 2018 – Jun 19, 2018

Subsystems (3)
lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

Hi all,

this series started as prep work for ANA, but has grown a lot.

The idea is to make the AEN handling in the target closer to what the standard says, and implement the changed namespaces list log page, which is required to clear the namespace attribute notice event.

One the host side this just makes sure we actually have the events we handle enabled using Set Features, and it fixes the handling of the namespace attribute notice event so that it actually does get cleared by issuing the log page.

Last but not last two block cleanups are thrown in so that we don't print a pointless message when we delete a namespaces, and also unexport the function printing said message as it should only be called from the core code.

Changes from v1:
- don't copy garbage when more then 1024 namespaces changed
- filter out duplicates in the changed namespace list log page
- use the proper define for the supported events to initialize OAES
- add the nvmet_aen_disabled helper from the ANA series
- allow the mandatory smart AENs in Set Features

author maintainer
#1 lore raw

PATCH 1/12 nvme.h: untangle AEN notice definitions

Stop including the event type in the definitions for the notice type.

---
 drivers/nvme/host/core.c | 30 ++++++++++++++++++------------
 include/linux/nvme.h     |  8 ++++++--
 2 files changed, 24 insertions(+), 14 deletions(-)
drivers/nvme/host/core.c +18 -12
index 2c4cf65641a6..86cb78653155 100644
@@ -3321,6 +3321,21 @@ static void nvme_fw_act_work(struct work_struct *work)
 	nvme_get_fw_slot_info(ctrl);
 }
 
+static void nvme_handle_aen_notice(struct nvme_ctrl *ctrl, u32 result)
+{
+	switch ((result & 0xff00) >> 8) {
+	case NVME_AER_NOTICE_NS_CHANGED:
+		dev_info(ctrl->device, "rescanning\n");
+		nvme_queue_scan(ctrl);
+		break;
+	case NVME_AER_NOTICE_FW_ACT_STARTING:
+		queue_work(nvme_wq, &ctrl->fw_act_work);
+		break;
+	default:
+		dev_warn(ctrl->device, "async event result %08x\n", result);
+	}
+}
+
 void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,
 		volatile union nvme_result *res)
 {
@@ -3330,6 +3345,9 @@ void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,
 		return;
 
 	switch (result & 0x7) {
+	case NVME_AER_NOTICE:
+		nvme_handle_aen_notice(ctrl, result);
+		break;
 	case NVME_AER_ERROR:
 	case NVME_AER_SMART:
 	case NVME_AER_CSS:
@@ -3339,18 +3357,6 @@ void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,
 	default:
 		break;
 	}
-
-	switch (result & 0xff07) {
-	case NVME_AER_NOTICE_NS_CHANGED:
-		dev_info(ctrl->device, "rescanning\n");
-		nvme_queue_scan(ctrl);
-		break;
-	case NVME_AER_NOTICE_FW_ACT_STARTING:
-		queue_work(nvme_wq, &ctrl->fw_act_work);
-		break;
-	default:
-		dev_warn(ctrl->device, "async event result %08x\n", result);
-	}
 	queue_work(nvme_wq, &ctrl->async_event_work);
 }
 EXPORT_SYMBOL_GPL(nvme_complete_async_event);
include/linux/nvme.h +6 -2
index 4112e2bd747f..c37103a4ad38 100644
@@ -436,10 +436,14 @@ enum {
 enum {
 	NVME_AER_ERROR			= 0,
 	NVME_AER_SMART			= 1,
+	NVME_AER_NOTICE			= 2,
 	NVME_AER_CSS			= 6,
 	NVME_AER_VS			= 7,
-	NVME_AER_NOTICE_NS_CHANGED	= 0x0002,
-	NVME_AER_NOTICE_FW_ACT_STARTING = 0x0102,
+};
+
+enum {
+	NVME_AER_NOTICE_NS_CHANGED	= 0x00,
+	NVME_AER_NOTICE_FW_ACT_STARTING = 0x01,
 };
 
 struct nvme_lba_range_type {
Signature · 1 line
2.17.0
Reviewed-by on v1 1/12
#3 lore raw

Re: [PATCH 01/12] nvme.h: untangle AEN notice definitions

In reply to Christoph Hellwig
Quoted 9 lines · On Wed, 30 May 2018 18:45:49 +0200 Christoph Hellwig <[email protected]> wrote:

Stop including the event type in the definitions for the notice type.

---
 drivers/nvme/host/core.c | 30 ++++++++++++++++++------------
 include/linux/nvme.h     |  8 ++++++--
 2 files changed, 24 insertions(+), 14 deletions(-)

Cheers,

Hannes

Reviewed-by on v1 1/12
#4 lore raw

Re: [PATCH 01/12] nvme.h: untangle AEN notice definitions

In reply to Christoph Hellwig
Quoted 9 lines · On Wed, 30 May 2018 18:45:49 +0200 Christoph Hellwig <[email protected]> wrote:

Stop including the event type in the definitions for the notice type.

---
 drivers/nvme/host/core.c | 30 ++++++++++++++++++------------
 include/linux/nvme.h     |  8 ++++++--
 2 files changed, 24 insertions(+), 14 deletions(-)

Cheers,

Hannes

author maintainer
#5 lore raw

PATCH 2/12 nvme.h: add the changed namespace list log

In reply to Christoph Hellwig
---
 include/linux/nvme.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/nvme.h +3 -0
index c37103a4ad38..7ce0f3cf4409 100644
@@ -751,6 +751,7 @@ enum {
 	NVME_LOG_ERROR		= 0x01,
 	NVME_LOG_SMART		= 0x02,
 	NVME_LOG_FW_SLOT	= 0x03,
+	NVME_LOG_CHANGED_NS	= 0x04,
 	NVME_LOG_CMD_EFFECTS	= 0x05,
 	NVME_LOG_DISC		= 0x70,
 	NVME_LOG_RESERVATION	= 0x80,
@@ -759,6 +760,8 @@ enum {
 	NVME_FWACT_ACTV		= (2 << 3),
 };
 
+#define NVME_MAX_CHANGED_NAMESPACES	1024
+
 struct nvme_identify {
 	__u8			opcode;
 	__u8			flags;
Signature · 1 line
2.17.0
author maintainer
#8 lore raw

PATCH 3/12 nvme.h: add AER configuration symbols

In reply to Christoph Hellwig

From: Hannes Reinecke <[email protected]>

---
 include/linux/nvme.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/nvme.h +5 -0
index 7ce0f3cf4409..2950ce957656 100644
@@ -446,6 +446,11 @@ enum {
 	NVME_AER_NOTICE_FW_ACT_STARTING = 0x01,
 };
 
+enum {
+	NVME_AEN_CFG_NS_ATTR		= 1 << 8,
+	NVME_AEN_CFG_FW_ACT		= 1 << 9,
+};
+
 struct nvme_lba_range_type {
 	__u8			type;
 	__u8			attributes;
Signature · 1 line
2.17.0
author maintainer
#10 lore raw

PATCH 4/12 nvmet: add a new nvmet_zero_sgl helper

In reply to Christoph Hellwig

Zeroes the SGL in the payload.

---
 drivers/nvme/target/core.c  | 7 +++++++
 drivers/nvme/target/nvmet.h | 1 +
 2 files changed, 8 insertions(+)
drivers/nvme/target/core.c +7 -0
index 800aaf96ddcd..55c4bc693aa2 100644
@@ -57,6 +57,13 @@ u16 nvmet_copy_from_sgl(struct nvmet_req *req, off_t off, void *buf, size_t len)
 	return 0;
 }
 
+u16 nvmet_zero_sgl(struct nvmet_req *req, off_t off, size_t len)
+{
+	if (sg_zero_buffer(req->sg, req->sg_cnt, len, off) != len)
+		return NVME_SC_SGL_INVALID_DATA | NVME_SC_DNR;
+	return 0;
+}
+
 static unsigned int nvmet_max_nsid(struct nvmet_subsys *subsys)
 {
 	struct nvmet_ns *ns;
drivers/nvme/target/nvmet.h +1 -0
index 32ebffcf464c..768abe203298 100644
@@ -330,6 +330,7 @@ u16 nvmet_copy_to_sgl(struct nvmet_req *req, off_t off, const void *buf,
 		size_t len);
 u16 nvmet_copy_from_sgl(struct nvmet_req *req, off_t off, void *buf,
 		size_t len);
+u16 nvmet_zero_sgl(struct nvmet_req *req, off_t off, size_t len);
 
 u32 nvmet_get_log_page_len(struct nvme_command *cmd);
 
Signature · 1 line
2.17.0
maintainer Reviewed-by on v1 4/12
#11 lore raw

Re: [PATCH 04/12] nvmet: add a new nvmet_zero_sgl helper

Quoted 2 lines

+u16 nvmet_zero_sgl(struct nvmet_req *req, off_t off, size_t len)

Would personally prefer nvmet_clear_sgl, but not hard headed on it,

Reviewed-by on v1 4/12
#12 lore raw

Re: [PATCH 04/12] nvmet: add a new nvmet_zero_sgl helper

In reply to Christoph Hellwig
Quoted 9 lines · On Wed, 30 May 2018 18:45:52 +0200 Christoph Hellwig <[email protected]> wrote:

Zeroes the SGL in the payload.

---
 drivers/nvme/target/core.c  | 7 +++++++
 drivers/nvme/target/nvmet.h | 1 +
 2 files changed, 8 insertions(+)

Cheers,

Hannes

author maintainer
#13 lore raw

PATCH 5/12 nvmet: split log page implementation

In reply to Christoph Hellwig

Remove the common code to allocate a buffer and copy it into the SGL. Instead the two no-op implementations just zero the SGL directly, and the smart log allocates a buffer on its own. This prepares for the more elaborate ANA log page.

---
 drivers/nvme/target/admin-cmd.c | 99 ++++++++++++---------------------
 1 file changed, 36 insertions(+), 63 deletions(-)
drivers/nvme/target/admin-cmd.c +36 -63
index 7f906e4ccc96..678a393f01de 100644
@@ -32,6 +32,11 @@ u32 nvmet_get_log_page_len(struct nvme_command *cmd)
 	return len;
 }
 
+static void nvmet_execute_get_log_page_noop(struct nvmet_req *req)
+{
+	nvmet_req_complete(req, nvmet_zero_sgl(req, 0, req->data_len));
+}
+
 static u16 nvmet_get_smart_log_nsid(struct nvmet_req *req,
 		struct nvme_smart_log *slog)
 {
@@ -97,74 +102,26 @@ static u16 nvmet_get_smart_log_all(struct nvmet_req *req,
 	return NVME_SC_SUCCESS;
 }
 
-static u16 nvmet_get_smart_log(struct nvmet_req *req,
-		struct nvme_smart_log *slog)
-{
-	u16 status;
-
-	WARN_ON(req == NULL || slog == NULL);
-	if (req->cmd->get_log_page.nsid == cpu_to_le32(NVME_NSID_ALL))
-		status = nvmet_get_smart_log_all(req, slog);
-	else
-		status = nvmet_get_smart_log_nsid(req, slog);
-	return status;
-}
-
-static void nvmet_execute_get_log_page(struct nvmet_req *req)
+static void nvmet_execute_get_log_page_smart(struct nvmet_req *req)
 {
-	struct nvme_smart_log *smart_log;
-	size_t data_len = nvmet_get_log_page_len(req->cmd);
-	void *buf;
-	u16 status = 0;
+	struct nvme_smart_log *log;
+	u16 status = NVME_SC_INTERNAL;
 
-	buf = kzalloc(data_len, GFP_KERNEL);
-	if (!buf) {
-		status = NVME_SC_INTERNAL;
+	if (req->data_len != sizeof(*log))
 		goto out;
-	}
 
-	switch (req->cmd->get_log_page.lid) {
-	case NVME_LOG_ERROR:
-		/*
-		 * We currently never set the More bit in the status field,
-		 * so all error log entries are invalid and can be zeroed out.
-		 * This is called a minum viable implementation (TM) of this
-		 * mandatory log page.
-		 */
-		break;
-	case NVME_LOG_SMART:
-		/*
-		 * XXX: fill out actual smart log
-		 *
-		 * We might have a hard time coming up with useful values for
-		 * many of the fields, and even when we have useful data
-		 * available (e.g. units or commands read/written) those aren't
-		 * persistent over power loss.
-		 */
-		if (data_len != sizeof(*smart_log)) {
-			status = NVME_SC_INTERNAL;
-			goto err;
-		}
-		smart_log = buf;
-		status = nvmet_get_smart_log(req, smart_log);
-		if (status)
-			goto err;
-		break;
-	case NVME_LOG_FW_SLOT:
-		/*
-		 * We only support a single firmware slot which always is
-		 * active, so we can zero out the whole firmware slot log and
-		 * still claim to fully implement this mandatory log page.
-		 */
-		break;
-	default:
-		BUG();
-	}
+	log = kzalloc(sizeof(*log), GFP_KERNEL);
+	if (!log)
+		goto out;
 
-	status = nvmet_copy_to_sgl(req, 0, buf, data_len);
+	if (req->cmd->get_log_page.nsid == cpu_to_le32(NVME_NSID_ALL))
+		status = nvmet_get_smart_log_all(req, log);
+	else
+		status = nvmet_get_smart_log_nsid(req, log);
+	if (status)
+		goto out;
 
-err:
-	kfree(buf);
+	status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log));
 out:
 	nvmet_req_complete(req, status);
 }
@@ -572,9 +529,25 @@ u16 nvmet_parse_admin_cmd(struct nvmet_req *req)
 
 		switch (cmd->get_log_page.lid) {
 		case NVME_LOG_ERROR:
+			/*
+			 * We currently never set the More bit in the status
+			 * field, so all error log entries are invalid and can
+			 * be zeroed out.  This is called a minum viable
+			 * implementation (TM) of this mandatory log page.
+			 */
+			req->execute = nvmet_execute_get_log_page_noop;
+			return 0;
 		case NVME_LOG_SMART:
+			req->execute = nvmet_execute_get_log_page_smart;
+			return 0;
 		case NVME_LOG_FW_SLOT:
-			req->execute = nvmet_execute_get_log_page;
+			/*
+			 * We only support a single firmware slot which always
+			 * is active, so we can zero out the whole firmware slot
+			 * log and still claim to fully implement this mandatory
+			 * log page.
+			 */
+			req->execute = nvmet_execute_get_log_page_noop;
 			return 0;
 		}
 		break;
Signature · 1 line
2.17.0
Reviewed-by on v1 5/12
#15 lore raw

Re: [PATCH 05/12] nvmet: split log page implementation

In reply to Christoph Hellwig
Quoted 5 lines · On Wed, 30 May 2018 18:45:53 +0200 Christoph Hellwig <[email protected]> wrote:

Remove the common code to allocate a buffer and copy it into the SGL. Instead the two no-op implementations just zero the SGL directly, and the smart log allocates a buffer on its own. This prepares for the more elaborate ANA log page.

Quoted 7 lines
---
 drivers/nvme/target/admin-cmd.c | 99

++++++++++++--------------------- 1 file changed, 36 insertions(+), 63 deletions(-)

Cheers,

Hannes

author maintainer
#16 lore raw

PATCH 6/12 nvmet: implement the changed namespaces log

In reply to Christoph Hellwig

Just keep a per-controller buffer of changed namespaces and copy it out in the get log page implementation.

---
 drivers/nvme/target/admin-cmd.c | 26 +++++++++++++++++
 drivers/nvme/target/core.c      | 50 +++++++++++++++++++++++++++------
 drivers/nvme/target/nvmet.h     |  3 ++
 3 files changed, 70 insertions(+), 9 deletions(-)
drivers/nvme/target/admin-cmd.c +26 -0
index 678a393f01de..453d76db1647 100644
@@ -126,6 +126,29 @@ static void nvmet_execute_get_log_page_smart(struct nvmet_req *req)
 	nvmet_req_complete(req, status);
 }
 
+static void nvmet_execute_get_log_changed_ns(struct nvmet_req *req)
+{
+	struct nvmet_ctrl *ctrl = req->sq->ctrl;
+	u16 status = NVME_SC_INTERNAL;
+	size_t len;
+
+	if (req->data_len != NVME_MAX_CHANGED_NAMESPACES * sizeof(__le32))
+		goto out;
+
+	mutex_lock(&ctrl->lock);
+	if (ctrl->nr_changed_ns == U32_MAX)
+		len = sizeof(__le32);
+	else
+		len = ctrl->nr_changed_ns * sizeof(__le32);
+	status = nvmet_copy_to_sgl(req, 0, ctrl->changed_ns_list, len);
+	if (!status)
+		status = nvmet_zero_sgl(req, len, req->data_len - len);
+	ctrl->nr_changed_ns = 0;
+	mutex_unlock(&ctrl->lock);
+out:
+	nvmet_req_complete(req, status);
+}
+
 static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
 {
 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
@@ -549,6 +572,9 @@ u16 nvmet_parse_admin_cmd(struct nvmet_req *req)
 			 */
 			req->execute = nvmet_execute_get_log_page_noop;
 			return 0;
+		case NVME_LOG_CHANGED_NS:
+			req->execute = nvmet_execute_get_log_changed_ns;
+			return 0;
 		}
 		break;
 	case nvme_admin_identify:
drivers/nvme/target/core.c +41 -9

102 lines not on this page · raw message

drivers/nvme/target/nvmet.h +3 -0
index 768abe203298..8cdc1e550396 100644
@@ -135,6 +135,9 @@ struct nvmet_ctrl {
 
 	const struct nvmet_fabrics_ops *ops;
 
+	__le32			*changed_ns_list;
+	u32			nr_changed_ns;
+
 	char			subsysnqn[NVMF_NQN_FIELD_LEN];
 	char			hostnqn[NVMF_NQN_FIELD_LEN];
 };
Signature · 1 line
2.17.0
#17 lore raw

Re: [PATCH 06/12] nvmet: implement the changed namespaces log

Quoted 5 lines · Christoph Hellwig

Just keep a per-controller buffer of changed namespaces and copy it out in the get log page implementation.

Signed-off-by Christoph Hellwig <hch at lst.de>

---

[...]

drivers/nvme/target/core.c static void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type, · line 150

Quoted 4 lines
drivers/nvme/target/core.c +4 -0
+static void nvmet_add_to_changed_ns_log(struct nvmet_ctrl *ctrl, __le32 nsid)
+{
+	mutex_lock(&ctrl->lock);
+	if (ctrl->nr_changed_ns < NVME_MAX_CHANGED_NAMESPACES) {

Minor nitpick here: if ctrlr->nr_changed_ns is exactly NVME_MAX_CHANGED_NAMESPACES and the new nsid is already in the list, this will skip down to the 0xffffffff case below, even though it could have just left the list as-is.

I don't know if this is a problem in practice; reporting 0xffffffff is probably always safe, since the host will presumably treat that as "rescan everything".

drivers/nvme/target/core.c static void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type, · line 163

Quoted 13 lines
drivers/nvme/target/core.c +13 -0
+		u32 i;
+
+		for (i = 0; i < ctrl->nr_changed_ns; i++)
+			if (ctrl->changed_ns_list[i] == nsid)
+				goto out_unlock;
+		ctrl->changed_ns_list[ctrl->nr_changed_ns++] = nsid;
+	} else if (ctrl->nr_changed_ns == NVME_MAX_CHANGED_NAMESPACES) {
+		ctrl->changed_ns_list[0] = cpu_to_le32(0xffffffff);
+		ctrl->nr_changed_ns = U32_MAX;
+	}
+out_unlock:
+	mutex_unlock(&ctrl->lock);
+}

Thanks,
-- Daniel

author maintainer
#18 lore raw

Re: [PATCH 06/12] nvmet: implement the changed namespaces log

Quoted 8 lines · Daniel Verkamp

Minor nitpick here: if ctrlr->nr_changed_ns is exactly NVME_MAX_CHANGED_NAMESPACES and the new nsid is already in the list, this will skip down to the 0xffffffff case below, even though it could have just left the list as-is.

I don't know if this is a problem in practice; reporting 0xffffffff is probably always safe, since the host will presumably treat that as "rescan everything".

It probably doesn't matter, but it turns doing this propely actually looks cleaner as well:

---

Quoted 1 line

From d4baf4068220a90ecf67309d01ece5d0aadd952e Mon Sep 17 00:00:00 2001

From: Christoph Hellwig <[email protected]>
Date: Fri, 25 May 2018 17:16:09 +0200
Subject: nvmet: implement the changed namespaces log

Just keep a per-controller buffer of changed namespaces and copy it out in the get log page implementation.

---
 drivers/nvme/target/admin-cmd.c | 26 +++++++++++++++
 drivers/nvme/target/core.c      | 56 +++++++++++++++++++++++++++------
 drivers/nvme/target/nvmet.h     |  3 ++
 3 files changed, 76 insertions(+), 9 deletions(-)
drivers/nvme/target/admin-cmd.c +26 -0
index 25b4e4ea69c8..7677b7b188ea 100644
@@ -126,6 +126,29 @@ static void nvmet_execute_get_log_page_smart(struct nvmet_req *req)
 	nvmet_req_complete(req, status);
 }
 
+static void nvmet_execute_get_log_changed_ns(struct nvmet_req *req)
+{
+	struct nvmet_ctrl *ctrl = req->sq->ctrl;
+	u16 status = NVME_SC_INTERNAL;
+	size_t len;
+
+	if (req->data_len != NVME_MAX_CHANGED_NAMESPACES * sizeof(__le32))
+		goto out;
+
+	mutex_lock(&ctrl->lock);
+	if (ctrl->nr_changed_ns == U32_MAX)
+		len = sizeof(__le32);
+	else
+		len = ctrl->nr_changed_ns * sizeof(__le32);
+	status = nvmet_copy_to_sgl(req, 0, ctrl->changed_ns_list, len);
+	if (!status)
+		status = nvmet_zero_sgl(req, len, req->data_len - len);
+	ctrl->nr_changed_ns = 0;
+	mutex_unlock(&ctrl->lock);
+out:
+	nvmet_req_complete(req, status);
+}
+
 static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
 {
 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
@@ -546,6 +569,9 @@ u16 nvmet_parse_admin_cmd(struct nvmet_req *req)
 			 */
 			req->execute = nvmet_execute_get_log_page_noop;
 			return 0;
+		case NVME_LOG_CHANGED_NS:
+			req->execute = nvmet_execute_get_log_changed_ns;
+			return 0;
 		}
 		break;
 	case nvme_admin_identify:
drivers/nvme/target/core.c +47 -9

108 lines not on this page · raw message

drivers/nvme/target/nvmet.h +3 -0
index 768abe203298..8cdc1e550396 100644
@@ -135,6 +135,9 @@ struct nvmet_ctrl {
 
 	const struct nvmet_fabrics_ops *ops;
 
+	__le32			*changed_ns_list;
+	u32			nr_changed_ns;
+
 	char			subsysnqn[NVMF_NQN_FIELD_LEN];
 	char			hostnqn[NVMF_NQN_FIELD_LEN];
 };
Signature · 1 line
2.17.0
Reviewed-by
#19 lore raw

Re: [PATCH 06/12] nvmet: implement the changed namespaces log

Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Daniel Verkamp

Minor nitpick here: if ctrlr->nr_changed_ns is exactly NVME_MAX_CHANGED_NAMESPACES and the new nsid is already in the list, this will skip down to the 0xffffffff case below, even though it could have just left the list as-is.

I don't know if this is a problem in practice; reporting 0xffffffff is probably always safe, since the host will presumably treat that as "rescan everything".

Quoted 8 lines

It probably doesn't matter, but it turns doing this propely actually looks cleaner as well:

---
From d4baf4068220a90ecf67309d01ece5d0aadd952e Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <[email protected]>
Date: Fri, 25 May 2018 17:16:09 +0200
Subject: nvmet: implement the changed namespaces log

Agreed, this version looks good to me:

Thanks,
-- Daniel

Reviewed-by on v1 6/12
#21 lore raw

Re: [PATCH 06/12] nvmet: implement the changed namespaces log

In reply to Christoph Hellwig
Quoted 10 lines · On Wed, 30 May 2018 18:45:54 +0200 Christoph Hellwig <[email protected]> wrote:

Just keep a per-controller buffer of changed namespaces and copy it out in the get log page implementation.

---
 drivers/nvme/target/admin-cmd.c | 26 +++++++++++++++++
 drivers/nvme/target/core.c      | 50

+++++++++++++++++++++++++++------ drivers/nvme/target/nvmet.h |
3 ++ 3 files changed, 70 insertions(+), 9 deletions(-)

Cheers,

Hannes

author maintainer
#22 lore raw

PATCH 7/12 nvmet: Add AEN configuration support

In reply to Christoph Hellwig

AEN configuration via the 'Get Features' and 'Set Features' admin command is mandatory, so we should be implemeting handling for it.

[hch: use WRITE_ONCE, check for invalid values]
---
 drivers/nvme/target/admin-cmd.c | 15 +++++++++++++--
 drivers/nvme/target/core.c      |  3 +++
 drivers/nvme/target/nvmet.h     | 16 ++++++++++++++++
 3 files changed, 32 insertions(+), 2 deletions(-)
drivers/nvme/target/admin-cmd.c +13 -2
index 453d76db1647..4e269a8c8dbe 100644
@@ -189,7 +189,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
 	id->ver = cpu_to_le32(ctrl->subsys->ver);
 
 	/* XXX: figure out what to do about RTD3R/RTD3 */
-	id->oaes = cpu_to_le32(1 << 8);
+	id->oaes = cpu_to_le32(NVMET_AEN_CFG_OPTIONAL);
 	id->ctratt = cpu_to_le32(1 << 0);
 
 	id->oacs = 0;
@@ -441,6 +441,16 @@ static void nvmet_execute_set_features(struct nvmet_req *req)
 		req->sq->ctrl->kato = DIV_ROUND_UP(val32, 1000);
 		nvmet_set_result(req, req->sq->ctrl->kato);
 		break;
+	case NVME_FEAT_ASYNC_EVENT:
+		val32 = le32_to_cpu(req->cmd->common.cdw10[1]);
+		if (val32 & ~NVMET_AEN_CFG_ALL) {
+			status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
+			break;
+		}
+
+		WRITE_ONCE(req->sq->ctrl->aen_enabled, val32);
+		nvmet_set_result(req, val32);
+		break;
 	case NVME_FEAT_HOST_ID:
 		status = NVME_SC_CMD_SEQ_ERROR | NVME_SC_DNR;
 		break;
@@ -479,9 +489,10 @@ static void nvmet_execute_get_features(struct nvmet_req *req)
 		break;
 	case NVME_FEAT_WRITE_ATOMIC:
 		break;
+#endif
 	case NVME_FEAT_ASYNC_EVENT:
+		nvmet_set_result(req, READ_ONCE(req->sq->ctrl->aen_enabled));
 		break;
-#endif
 	case NVME_FEAT_VOLATILE_WC:
 		nvmet_set_result(req, 1);
 		break;
drivers/nvme/target/core.c +3 -0
index 99fcff757608..b2da65aec8b7 100644
@@ -168,6 +168,8 @@ static void nvmet_ns_changed(struct nvmet_subsys *subsys, u32 nsid)
 
 	list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
 		nvmet_add_to_changed_ns_log(ctrl, cpu_to_le32(nsid));
+		if (!(READ_ONCE(ctrl->aen_enabled) & NVME_AEN_CFG_NS_ATTR))
+			continue;
 		nvmet_add_async_event(ctrl, NVME_AER_TYPE_NOTICE,
 				NVME_AER_NOTICE_NS_CHANGED,
 				NVME_LOG_CHANGED_NS);
@@ -855,6 +857,7 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
 
 	kref_init(&ctrl->ref);
 	ctrl->subsys = subsys;
+	WRITE_ONCE(ctrl->aen_enabled, NVMET_AEN_CFG_OPTIONAL);
 
 	ctrl->changed_ns_list = kmalloc_array(NVME_MAX_CHANGED_NAMESPACES,
 			sizeof(__le32), GFP_KERNEL);
drivers/nvme/target/nvmet.h +16 -0
index 8cdc1e550396..f4d16d9b3582 100644
@@ -30,6 +30,21 @@
 #define NVMET_ASYNC_EVENTS		4
 #define NVMET_ERROR_LOG_SLOTS		128
 
+
+/*
+ * Supported optional AENs:
+ */
+#define NVMET_AEN_CFG_OPTIONAL \
+	NVME_AEN_CFG_NS_ATTR
+
+/*
+ * Plus mandatory SMART AENs (we'll never send them, but allow enabling them):
+ */
+#define NVMET_AEN_CFG_ALL \
+	(NVME_SMART_CRIT_SPARE | NVME_SMART_CRIT_TEMPERATURE | \
+	 NVME_SMART_CRIT_RELIABILITY | NVME_SMART_CRIT_MEDIA | \
+	 NVME_SMART_CRIT_VOLATILE_MEMORY | NVMET_AEN_CFG_OPTIONAL)
+
 /* Helper Macros when NVMe error is NVME_SC_CONNECT_INVALID_PARAM
  * The 16 bit shift is to set IATTR bit to 1, which means offending
  * offset starts in the data section of connect()
@@ -123,6 +138,7 @@ struct nvmet_ctrl {
 	u16			cntlid;
 	u32			kato;
 
+	u32			aen_enabled;
 	struct nvmet_req	*async_event_cmds[NVMET_ASYNC_EVENTS];
 	unsigned int		nr_async_event_cmds;
 	struct list_head	async_events;
Signature · 1 line
2.17.0
author maintainer
#24 lore raw

PATCH 8/12 nvmet: mask pending AERs

In reply to Christoph Hellwig

Per section 5.2 of the NVMe 1.3 spec:

"When the controller posts a completion queue entry for an outstanding Asynchronous Event Request command and thus reports an asynchronous event, subsequent events of that event type are automatically masked by the controller until the host clears that event. An event is cleared by reading the log page associated with that event using the Get Log Page command (see section 5.14)."

Signed-off-by Christoph Hellwig <hch at lst.de>
---
 drivers/nvme/target/admin-cmd.c | 1 +
 drivers/nvme/target/core.c      | 9 ++++++++-
 drivers/nvme/target/nvmet.h     | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)
drivers/nvme/target/admin-cmd.c +1 -0
index 4e269a8c8dbe..abf191ee00af 100644
@@ -144,6 +144,7 @@ static void nvmet_execute_get_log_changed_ns(struct nvmet_req *req)
 	if (!status)
 		status = nvmet_zero_sgl(req, len, req->data_len - len);
 	ctrl->nr_changed_ns = 0;
+	clear_bit(NVME_AEN_CFG_NS_ATTR, &ctrl->aen_masked);
 	mutex_unlock(&ctrl->lock);
 out:
 	nvmet_req_complete(req, status);
drivers/nvme/target/core.c +8 -1
index b2da65aec8b7..8e6432b1abed 100644
@@ -144,6 +144,13 @@ static void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type,
 	schedule_work(&ctrl->async_event_work);
 }
 
+static bool nvmet_aen_disabled(struct nvmet_ctrl *ctrl, u32 aen)
+{
+	if (!(READ_ONCE(ctrl->aen_enabled) & aen))
+		return true;
+	return test_and_set_bit(aen, &ctrl->aen_masked);
+}
+
 static void nvmet_add_to_changed_ns_log(struct nvmet_ctrl *ctrl, __le32 nsid)
 {
 	mutex_lock(&ctrl->lock);
@@ -168,7 +175,7 @@ static void nvmet_ns_changed(struct nvmet_subsys *subsys, u32 nsid)
 
 	list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
 		nvmet_add_to_changed_ns_log(ctrl, cpu_to_le32(nsid));
-		if (!(READ_ONCE(ctrl->aen_enabled) & NVME_AEN_CFG_NS_ATTR))
+		if (nvmet_aen_disabled(ctrl, NVME_AEN_CFG_NS_ATTR))
 			continue;
 		nvmet_add_async_event(ctrl, NVME_AER_TYPE_NOTICE,
 				NVME_AER_NOTICE_NS_CHANGED,
drivers/nvme/target/nvmet.h +1 -0
index f4d16d9b3582..480dfe10fad9 100644
@@ -139,6 +139,7 @@ struct nvmet_ctrl {
 	u32			kato;
 
 	u32			aen_enabled;
+	unsigned long		aen_masked;
 	struct nvmet_req	*async_event_cmds[NVMET_ASYNC_EVENTS];
 	unsigned int		nr_async_event_cmds;
 	struct list_head	async_events;
Signature · 1 line
2.17.0
maintainer
#25 lore raw

PATCH 8/12 nvmet: mask pending AERs

Reviewed-by Sagi Grimberg <sagi at grimberg.me>
#26 lore raw

PATCH 8/12 nvmet: mask pending AERs

In reply to Christoph Hellwig
Quoted 9 lines · On Wed, 30 May 2018 18:45:56 +0200 Christoph Hellwig <[email protected]> wrote:

Per section 5.2 of the NVMe 1.3 spec:

"When the controller posts a completion queue entry for an
outstanding Asynchronous Event Request command and thus reports an asynchronous event, subsequent events of that event type are automatically masked by the controller until the host clears that event. An event is cleared by reading the log page associated with that event using the Get Log Page command (see section 5.14)."

Quoted 7 lines
Signed-off-by Christoph Hellwig <hch at lst.de>
---
 drivers/nvme/target/admin-cmd.c | 1 +
 drivers/nvme/target/core.c      | 9 ++++++++-
 drivers/nvme/target/nvmet.h     | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)
Reviewed-by Hannes Reinecke <hare at suse.com>

Cheers,

Hannes

#27 lore raw

PATCH 8/12 nvmet: mask pending AERs

In reply to Christoph Hellwig
Quoted 9 lines · Christoph Hellwig

Per section 5.2 of the NVMe 1.3 spec:

"When the controller posts a completion queue entry for an outstanding Asynchronous Event Request command and thus reports an asynchronous event, subsequent events of that event type are automatically masked by the controller until the host clears that event. An event is cleared by reading the log page associated with that event using the Get Log Page command (see section 5.14)."

Quoted 7 lines
Signed-off-by Christoph Hellwig <hch at lst.de>
---
  drivers/nvme/target/admin-cmd.c | 1 +
  drivers/nvme/target/core.c      | 9 ++++++++-
  drivers/nvme/target/nvmet.h     | 1 +
  3 files changed, 10 insertions(+), 1 deletion(-)

Hi Christoph,

There is a backwards compatibility issue with this patch.
I tested the latest nvme target with an older initiator that doesn't use the changed namespaces list log to clear ns data changed AENs. The target doesn't send the second NS_CHANGED event because the NVME_AEN_CFG_NS_ATTR bit is not clear.
I have a simple fix that clear the bit also at nvmet_execute_identify_ctrl().

What do you think? is there a better way to solve it?

Regards,
Israel

author maintainer
#28 lore raw

PATCH 8/12 nvmet: mask pending AERs

Quoted 9 lines · Israel Rukshin

There is a backwards compatibility issue with this patch.
I tested the latest nvme target with an older initiator that doesn't use the changed namespaces list log to clear ns data changed AENs. The target doesn't send the second NS_CHANGED event because the NVME_AEN_CFG_NS_ATTR bit is not clear.
I have a simple fix that clear the bit also at nvmet_execute_identify_ctrl().

What do you think? is there a better way to solve it?

No. Clearing it in nvmet_execute_identify_ctrl is bogus. The problem is that the old target did not comply with the spec.

Note that the old host code would have had the same problem with other non-Linux targets. So the only fix is to backport the host fix to older kernels.

#29 lore raw

PATCH 8/12 nvmet: mask pending AERs

Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Israel Rukshin

There is a backwards compatibility issue with this patch.
I tested the latest nvme target with an older initiator that doesn't use the changed namespaces list log to clear ns data changed AENs. The target doesn't send the second NS_CHANGED event because the NVME_AEN_CFG_NS_ATTR bit is not clear.
I have a simple fix that clear the bit also at nvmet_execute_identify_ctrl().

Quoted 8 lines
Quoted 1 line

What do you think? is there a better way to solve it?

No. Clearing it in nvmet_execute_identify_ctrl is bogus. The problem is that the old target did not comply with the spec.

Note that the old host code would have had the same problem with other non-Linux targets. So the only fix is to backport the host fix to older kernels.

Bummer.
This is not an easy task, I guess, for distros or other SW packeges out there...
Currently all of them can't work with upstream target :(

Quoted 6 lines

_______________________________________________
Linux-nvme mailing list
Linux-nvme at lists.infradead.org
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.infradead.org%2Fmailman%2Flistinfo%2Flinux-nvme&data=02%7C01%7Cmaxg%40mellanox.com%7C87641b7377204e36819d08d5d1001a4f%7Ca652971c7d2e4d9ba6a4d149256f461b%7C0%7C1%7C636644720741147578&sdata=Su8lJHUseHLMB3jwnX9wMe3nhD%2B9E6%2BcyYI71Hri8xs%3D&reserved=0

author maintainer
#30 lore raw

PATCH 8/12 nvmet: mask pending AERs

Quoted 3 lines · Max Gurtovoy

This is not an easy task, I guess, for distros or other SW packeges out there...
Currently all of them can't work with upstream target :(

You'll just need to rescan manually.

maintainer
#31 lore raw

PATCH 8/12 nvmet: mask pending AERs

In reply to Christoph Hellwig
Quoted 9 lines
Quoted 9 lines

There is a backwards compatibility issue with this patch.
I tested the latest nvme target with an older initiator that doesn't use the changed namespaces list log to clear ns data changed AENs. The target doesn't send the second NS_CHANGED event because the NVME_AEN_CFG_NS_ATTR bit is not clear.
I have a simple fix that clear the bit also at nvmet_execute_identify_ctrl().

Quoted 8 lines
Quoted 1 line

What do you think? is there a better way to solve it?

No. Clearing it in nvmet_execute_identify_ctrl is bogus. The problem is that the old target did not comply with the spec.

Note that the old host code would have had the same problem with other non-Linux targets. So the only fix is to backport the host fix to older kernels.

Fully agree, that is the only solution we have for just this kind of compat changes.

author maintainer
#32 lore raw

PATCH 9/12 nvme: submit AEN event configuration on startup

In reply to Christoph Hellwig

From: Hannes Reinecke <[email protected]>

We should register for AEN events; some law-abiding targets might not be sending us AENs otherwise.

---
 drivers/nvme/host/core.c | 17 +++++++++++++++++
 drivers/nvme/host/nvme.h |  1 +
 2 files changed, 18 insertions(+)
drivers/nvme/host/core.c +17 -0
index 86cb78653155..c0bc76d98194 100644
@@ -1030,6 +1030,21 @@ int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count)
 }
 EXPORT_SYMBOL_GPL(nvme_set_queue_count);
 
+#define NVME_AEN_SUPPORTED \
+	(NVME_AEN_CFG_NS_ATTR | NVME_AEN_CFG_FW_ACT)
+
+static void nvme_enable_aen(struct nvme_ctrl *ctrl)
+{
+	u32 result;
+	int status;
+
+	status = nvme_set_features(ctrl, NVME_FEAT_ASYNC_EVENT,
+			ctrl->oaes & NVME_AEN_SUPPORTED, NULL, 0, &result);
+	if (status)
+		dev_warn(ctrl->device, "Failed to configure AEN (cfg %x)\n",
+			 ctrl->oaes & NVME_AEN_SUPPORTED);
+}
+
 static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
 {
 	struct nvme_user_io io;
@@ -2347,6 +2362,7 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
 
 	ctrl->oacs = le16_to_cpu(id->oacs);
 	ctrl->oncs = le16_to_cpup(&id->oncs);
+	ctrl->oaes = le32_to_cpu(id->oaes);
 	atomic_set(&ctrl->abort_limit, id->acl + 1);
 	ctrl->vwc = id->vwc;
 	ctrl->cntlid = le16_to_cpup(&id->cntlid);
@@ -3379,6 +3395,7 @@ void nvme_start_ctrl(struct nvme_ctrl *ctrl)
 
 	if (ctrl->queue_count > 1) {
 		nvme_queue_scan(ctrl);
+		nvme_enable_aen(ctrl);
 		queue_work(nvme_wq, &ctrl->async_event_work);
 		nvme_start_queues(ctrl);
 	}
drivers/nvme/host/nvme.h +1 -0
index ec6e4acc4d48..dcf9e9592c1a 100644
@@ -176,6 +176,7 @@ struct nvme_ctrl {
 	u16 kas;
 	u8 npss;
 	u8 apsta;
+	u32 oaes;
 	u32 aen_result;
 	unsigned int shutdown_timeout;
 	unsigned int kato;
Signature · 1 line
2.17.0
author maintainer
#34 lore raw

PATCH 10/12 nvme: mark nvme_queue_scan static

In reply to Christoph Hellwig

And move it toward the top of the file to avoid a forward declaration.

---
 drivers/nvme/host/core.c | 19 +++++++++----------
 drivers/nvme/host/nvme.h |  1 -
 2 files changed, 9 insertions(+), 11 deletions(-)
drivers/nvme/host/core.c +9 -10
index c0bc76d98194..06cd04dcffbc 100644
@@ -100,6 +100,15 @@ static struct class *nvme_subsys_class;
 static void nvme_ns_remove(struct nvme_ns *ns);
 static int nvme_revalidate_disk(struct gendisk *disk);
 
+static void nvme_queue_scan(struct nvme_ctrl *ctrl)
+{
+	/*
+	 * Only new queue scan work when admin and IO queues are both alive
+	 */
+	if (ctrl->state == NVME_CTRL_LIVE)
+		queue_work(nvme_wq, &ctrl->scan_work);
+}
+
 int nvme_reset_ctrl(struct nvme_ctrl *ctrl)
 {
 	if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING))
@@ -3214,16 +3223,6 @@ static void nvme_scan_work(struct work_struct *work)
 	kfree(id);
 }
 
-void nvme_queue_scan(struct nvme_ctrl *ctrl)
-{
-	/*
-	 * Only new queue scan work when admin and IO queues are both alive
-	 */
-	if (ctrl->state == NVME_CTRL_LIVE)
-		queue_work(nvme_wq, &ctrl->scan_work);
-}
-EXPORT_SYMBOL_GPL(nvme_queue_scan);
-
 /*
  * This function iterates the namespace list unlocked to allow recovery from
  * controller failure. It is up to the caller to ensure the namespace list is
drivers/nvme/host/nvme.h +0 -1
index dcf9e9592c1a..11681278fdf6 100644
@@ -395,7 +395,6 @@ void nvme_stop_ctrl(struct nvme_ctrl *ctrl);
 void nvme_put_ctrl(struct nvme_ctrl *ctrl);
 int nvme_init_identify(struct nvme_ctrl *ctrl);
 
-void nvme_queue_scan(struct nvme_ctrl *ctrl);
 void nvme_remove_namespaces(struct nvme_ctrl *ctrl);
 
 int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,
Signature · 1 line
2.17.0
Reviewed-by on v1 10/12
#36 lore raw

Re: [PATCH 10/12] nvme: mark nvme_queue_scan static

In reply to Christoph Hellwig
Quoted 9 lines · On Wed, 30 May 2018 18:45:58 +0200 Christoph Hellwig <[email protected]> wrote:

And move it toward the top of the file to avoid a forward declaration.

---
 drivers/nvme/host/core.c | 19 +++++++++----------
 drivers/nvme/host/nvme.h |  1 -
 2 files changed, 9 insertions(+), 11 deletions(-)

Cheers,

Hannes

author maintainer
#37 lore raw

PATCH 11/12 nvme: use the changed namespaces list log to clear ns data changed AENs

In reply to Christoph Hellwig

Per section 5.2 we need to issue the corresponding log page to clear an AEN, so for a namespace data changed AEN we need to read the changed namespace list log. And once we read that log anyway we might as well use it to optimize the rescan.

---
 drivers/nvme/host/core.c | 51 ++++++++++++++++++++++++++++++++++++----
 drivers/nvme/host/nvme.h |  2 ++
 2 files changed, 49 insertions(+), 4 deletions(-)
drivers/nvme/host/core.c +47 -4
index 06cd04dcffbc..1ae77428a1a5 100644
@@ -3194,6 +3194,42 @@ static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl, unsigned nn)
 	nvme_remove_invalid_namespaces(ctrl, nn);
 }
 
+static bool nvme_scan_changed_ns_log(struct nvme_ctrl *ctrl)
+{
+	size_t log_size = NVME_MAX_CHANGED_NAMESPACES * sizeof(__le32);
+	__le32 *log;
+	int error, i;
+	bool ret = false;
+
+	log = kzalloc(log_size, GFP_KERNEL);
+	if (!log)
+		return false;
+
+	error = nvme_get_log(ctrl, NVME_LOG_CHANGED_NS, log, log_size);
+	if (error) {
+		dev_warn(ctrl->device,
+			"reading changed ns log failed: %d\n", error);
+		goto out_free_log;
+	}
+
+	if (log[0] == cpu_to_le32(0xffffffff))
+		goto out_free_log;
+
+	for (i = 0; i < NVME_MAX_CHANGED_NAMESPACES; i++) {
+		u32 nsid = le32_to_cpu(log[i]);
+
+		if (nsid == 0)
+			break;
+		dev_info(ctrl->device, "rescanning namespace %d.\n", nsid);
+		nvme_validate_ns(ctrl, nsid);
+	}
+	ret = true;
+
+out_free_log:
+	kfree(log);
+	return ret;
+}
+
 static void nvme_scan_work(struct work_struct *work)
 {
 	struct nvme_ctrl *ctrl =
@@ -3206,6 +3242,12 @@ static void nvme_scan_work(struct work_struct *work)
 
 	WARN_ON_ONCE(!ctrl->tagset);
 
+	if (test_and_clear_bit(EVENT_NS_CHANGED, &ctrl->events)) {
+		if (nvme_scan_changed_ns_log(ctrl))
+			goto out_sort_namespaces;
+		dev_info(ctrl->device, "rescanning namespaces.\n");
+	}
+
 	if (nvme_identify_ctrl(ctrl, &id))
 		return;
 
@@ -3213,14 +3255,15 @@ static void nvme_scan_work(struct work_struct *work)
 	if (ctrl->vs >= NVME_VS(1, 1, 0) &&
 	    !(ctrl->quirks & NVME_QUIRK_IDENTIFY_CNS)) {
 		if (!nvme_scan_ns_list(ctrl, nn))
-			goto done;
+			goto out_free_id;
 	}
 	nvme_scan_ns_sequential(ctrl, nn);
- done:
+out_free_id:
+	kfree(id);
+out_sort_namespaces:
 	down_write(&ctrl->namespaces_rwsem);
 	list_sort(NULL, &ctrl->namespaces, ns_cmp);
 	up_write(&ctrl->namespaces_rwsem);
-	kfree(id);
 }
 
 /*
@@ -3340,7 +3383,7 @@ static void nvme_handle_aen_notice(struct nvme_ctrl *ctrl, u32 result)
 {
 	switch ((result & 0xff00) >> 8) {
 	case NVME_AER_NOTICE_NS_CHANGED:
-		dev_info(ctrl->device, "rescanning\n");
+		set_bit(EVENT_NS_CHANGED, &ctrl->events);
 		nvme_queue_scan(ctrl);
 		break;
 	case NVME_AER_NOTICE_FW_ACT_STARTING:
drivers/nvme/host/nvme.h +2 -0
index 11681278fdf6..07e8bfe705c6 100644
@@ -189,6 +189,8 @@ struct nvme_ctrl {
 	struct delayed_work ka_work;
 	struct nvme_command ka_cmd;
 	struct work_struct fw_act_work;
+#define EVENT_NS_CHANGED		(1 << 0)
+	unsigned long events;
 
 	/* Power saving configuration */
 	u64 ps_max_latency_us;
Signature · 1 line
2.17.0
Reviewed-by on v1 11/12
#39 lore raw

Re: [PATCH 11/12] nvme: use the changed namespaces list log to clear ns data changed AENs

In reply to Christoph Hellwig
Quoted 11 lines · On Wed, 30 May 2018 18:45:59 +0200 Christoph Hellwig <[email protected]> wrote:

Per section 5.2 we need to issue the corresponding log page to clear an AEN, so for a namespace data changed AEN we need to read the changed namespace list log. And once we read that log anyway we might as well use it to optimize the rescan.

---
 drivers/nvme/host/core.c | 51

++++++++++++++++++++++++++++++++++++---- drivers/nvme/host/nvme.h | 2 ++ 2 files changed, 49 insertions(+), 4 deletions(-)

Cheers,

Hannes

author maintainer
#40 lore raw

PATCH 12/12 nvme: limit warnings from nvme_identify_ns

In reply to Christoph Hellwig

When rescanning namespaces after an AEN we will issue Identify Namespace comands to namespaces that have gone away, so don't warn for this specific case.

---
 drivers/nvme/host/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +3 -1
index 1ae77428a1a5..7ad3cfc9d4e1 100644
@@ -984,7 +984,9 @@ static struct nvme_id_ns *nvme_identify_ns(struct nvme_ctrl *ctrl,
 
 	error = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id));
 	if (error) {
-		dev_warn(ctrl->device, "Identify namespace failed\n");
+		/* don't warn on a namespace that has gone away */
+		if (error < 0 || ((error & ~NVME_SC_DNR) != NVME_SC_INVALID_NS))
+			dev_warn(ctrl->device, "Identify namespace failed\n");
 		kfree(id);
 		return NULL;
 	}
Signature · 1 line
2.17.0
Reviewed-by on v1 12/12
#42 lore raw

Re: [PATCH 12/12] nvme: limit warnings from nvme_identify_ns

In reply to Christoph Hellwig
Quoted 10 lines · On Wed, 30 May 2018 18:46:00 +0200 Christoph Hellwig <[email protected]> wrote:

When rescanning namespaces after an AEN we will issue Identify Namespace comands to namespaces that have gone away, so don't warn for this specific case.

---
 drivers/nvme/host/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Cheers,

Hannes