Skip to contentSkip to conversation

nvme/nvmet AEN and log page fixups

PATCH In review Christoph Hellwig 6 participants 46 messages May 26, 2018 – Jun 5, 2018

Subsystems (4)
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.

author maintainer
#1 lore raw

PATCH 1/14 block: unexport check_disk_size_change

Only used in block_dev.c and the partitions code, and it should remain that way..

---
 fs/block_dev.c | 1 -
 1 file changed, 1 deletion(-)
fs/block_dev.c +0 -1
index 7ec920e27065..771ddfa29dc9 100644
@@ -1342,7 +1342,6 @@ void check_disk_size_change(struct gendisk *disk, struct block_device *bdev)
 			flush_disk(bdev, false);
 	}
 }
-EXPORT_SYMBOL(check_disk_size_change);
 
 /**
  * revalidate_disk - wrapper for lower-level driver's revalidate_disk call-back
Signature · 1 line
2.17.0
Reviewed-by on v1 1/14
#2 lore raw

Re: [PATCH 01/14] block: unexport check_disk_size_change

Looks good,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author maintainer
#3 lore raw

PATCH 2/14 block: don't print a message when the device went away

In reply to Christoph Hellwig

The information about a size change in this case just creates confusion.

---
 block/partition-generic.c |  4 ++--
 fs/block_dev.c            | 14 +++++++++-----
 include/linux/fs.h        |  2 +-
 3 files changed, 12 insertions(+), 8 deletions(-)
block/partition-generic.c +2 -2
index db57cced9b98..9fe4816a1289 100644
@@ -518,7 +518,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
 
 	if (disk->fops->revalidate_disk)
 		disk->fops->revalidate_disk(disk);
-	check_disk_size_change(disk, bdev);
+	check_disk_size_change(disk, bdev, true);
 	bdev->bd_invalidated = 0;
 	if (!get_capacity(disk) || !(state = check_partition(disk, bdev)))
 		return 0;
@@ -643,7 +643,7 @@ int invalidate_partitions(struct gendisk *disk, struct block_device *bdev)
 		return res;
 
 	set_capacity(disk, 0);
-	check_disk_size_change(disk, bdev);
+	check_disk_size_change(disk, bdev, false);
 	bdev->bd_invalidated = 0;
 	/* tell userspace that the media / partition table may have changed */
 	kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
fs/block_dev.c +9 -5
index 771ddfa29dc9..81c57c14fae8 100644
@@ -1322,21 +1322,25 @@ static void flush_disk(struct block_device *bdev, bool kill_dirty)
  * check_disk_size_change - checks for disk size change and adjusts bdev size.
  * @disk: struct gendisk to check
  * @bdev: struct bdev to adjust.
+ * @verbose: if %true log a message about a size change if there is any
  *
  * This routine checks to see if the bdev size does not match the disk size
  * and adjusts it if it differs. When shrinking the bdev size, its all caches
  * are freed.
  */
-void check_disk_size_change(struct gendisk *disk, struct block_device *bdev)
+void check_disk_size_change(struct gendisk *disk, struct block_device *bdev,
+		bool verbose)
 {
 	loff_t disk_size, bdev_size;
 
 	disk_size = (loff_t)get_capacity(disk) << 9;
 	bdev_size = i_size_read(bdev->bd_inode);
 	if (disk_size != bdev_size) {
-		printk(KERN_INFO
-		       "%s: detected capacity change from %lld to %lld\n",
-		       disk->disk_name, bdev_size, disk_size);
+		if (verbose) {
+			printk(KERN_INFO
+			       "%s: detected capacity change from %lld to %lld\n",
+			       disk->disk_name, bdev_size, disk_size);
+		}
 		i_size_write(bdev->bd_inode, disk_size);
 		if (bdev_size > disk_size)
 			flush_disk(bdev, false);
@@ -1363,7 +1367,7 @@ int revalidate_disk(struct gendisk *disk)
 		return ret;
 
 	mutex_lock(&bdev->bd_mutex);
-	check_disk_size_change(disk, bdev);
+	check_disk_size_change(disk, bdev, ret == 0);
 	bdev->bd_invalidated = 0;
 	mutex_unlock(&bdev->bd_mutex);
 	bdput(bdev);
include/linux/fs.h +1 -1
index 760d8da1b6c7..d8d4831af9ff 100644
@@ -2570,7 +2570,7 @@ extern bool is_bad_inode(struct inode *);
 
 #ifdef CONFIG_BLOCK
 extern void check_disk_size_change(struct gendisk *disk,
-				   struct block_device *bdev);
+		struct block_device *bdev, bool verbose);
 extern int revalidate_disk(struct gendisk *);
 extern int check_disk_change(struct block_device *);
 extern int __invalidate_device(struct block_device *, bool);
Signature · 1 line
2.17.0
Reviewed-by on v1 2/14
#4 lore raw

Re: [PATCH 02/14] block: don't print a message when the device went away

Looks good,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author maintainer
#5 lore raw

PATCH 3/14 nvme.h: untangle AEN notice definitions

In reply to Christoph Hellwig

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 3/14
#6 lore raw

Re: [PATCH 03/14] nvme.h: untangle AEN notice definitions

Looks good,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author maintainer
#7 lore raw

PATCH 4/14 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
Reviewed-by on v1 4/14
#8 lore raw

Re: [PATCH 04/14] nvme.h: add the changed namespace list log

Looks good,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author maintainer
#9 lore raw

PATCH 5/14 nvme.h: add AER configuration symbols

In reply to Christoph Hellwig

From: Hannes Reinecke <[email protected]>

[hch: split from a larger patch]
---
 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
Reviewed-by on v1 5/14
#10 lore raw

Re: [PATCH 05/14] nvme.h: add AER configuration symbols

Looks good,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author maintainer
#11 lore raw

PATCH 6/14 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 2d09afcfe505..a4e14eb15d4e 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
Reviewed-by on v1 6/14
#12 lore raw

Re: [PATCH 06/14] nvmet: add a new nvmet_zero_sgl helper

Don't we already have this? Or is it a re-send? It looks so awefully familiar to me...

Anyways,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author maintainer
#13 lore raw

Re: [PATCH 06/14] nvmet: add a new nvmet_zero_sgl helper

Quoted 1 line · Johannes Thumshirn

Don't we already have this? Or is it a re-send? It looks so awefully familiar to me...

It was part of my ANA series, like many changes in this series.

author maintainer
#14 lore raw

PATCH 7/14 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 b2ba95b2eef7..e96bb02c4f2c 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);
 }
@@ -566,9 +523,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 7/14
#15 lore raw

Re: [PATCH 07/14] nvmet: split log page implementation

Looks good,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author maintainer
#16 lore raw

PATCH 8/14 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 | 23 +++++++++++++++++
 drivers/nvme/target/core.c      | 44 ++++++++++++++++++++++++++-------
 drivers/nvme/target/nvmet.h     |  3 +++
 3 files changed, 61 insertions(+), 9 deletions(-)
drivers/nvme/target/admin-cmd.c +23 -0
index e96bb02c4f2c..82d521f60a43 100644
@@ -126,6 +126,26 @@ 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);
+	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;
@@ -543,6 +563,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 +35 -9

96 lines not on this page · raw message

drivers/nvme/target/nvmet.h +3 -0
index a4e14eb15d4e..bcd88b5c9d99 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 on v1 8/14
#17 lore raw

Re: [PATCH 08/14] nvmet: implement the changed namespaces log

As a side note, what happens if more than 1024 Namespaces are changed (apart from setting the 1st element to 0xffffffff and zeroing out the rest)?

The Spec is pretty silent in this regard.

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author maintainer
#18 lore raw

Re: [PATCH 08/14] nvmet: implement the changed namespaces log

Quoted 7 lines · Johannes Thumshirn

As a side note, what happens if more than 1024 Namespaces are changed (apart from setting the 1st element to 0xffffffff and zeroing out the rest)?

The Spec is pretty silent in this regard.

The spec is completly clear on this:

Quoted 1 line

From 5.14.1.4:

"If more than 1024 namespaces have changed attributes since the last time the
log page was read, the first entry in the log page shall be set to FFFFFFFFh and the remainder of the list shall be zero-filled."

Once we don't know what changed we'll have to do a full rescan using Identify.

#19 lore raw

Re: [PATCH 08/14] nvmet: implement the changed namespaces log

Quoted 11 lines · Christoph Hellwig
Quoted 7 lines · Johannes Thumshirn

As a side note, what happens if more than 1024 Namespaces are changed (apart from setting the 1st element to 0xffffffff and zeroing out the rest)?

The Spec is pretty silent in this regard.

The spec is completly clear on this:

Quoted 8 lines

From 5.14.1.4:

"If more than 1024 namespaces have changed attributes since the last time the
log page was read, the first entry in the log page shall be set to FFFFFFFFh and the remainder of the list shall be zero-filled."

Once we don't know what changed we'll have to do a full rescan using Identify.

The "full rescan" part was what I couldn't read out of the spec.

Thanks,
Johannes

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author maintainer
#20 lore raw

Re: [PATCH 08/14] nvmet: implement the changed namespaces log

Quoted 1 line · Johannes Thumshirn

The "full rescan" part was what I couldn't read out of the spec.

The spec part is: something changed (AEN + some content in the log page)
+ too much changed (all-f first entry). The rest is host policy, but except for the full scan I can't think of anything else useful.

#21 lore raw

RE: [PATCH 08/14] nvmet: implement the changed namespaces log

In reply to Christoph Hellwig

[...]

Quoted 1 line

+static void nvmet_add_to_changed_ns_log(struct nvmet_ctrl *ctrl, u32 nsi=

d)

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

Quoted 8 lines
drivers/nvme/target/core.c +8 -0
+{
+	mutex_lock(&ctrl->lock);
+	if (ctrl->nr_changed_ns < NVME_MAX_CHANGED_NAMESPACES) {
+		ctrl->changed_ns_list[ctrl->nr_changed_ns++] =3D
+			cpu_to_le32(nsid);
+	} else if (ctrl->nr_changed_ns =3D=3D NVME_MAX_CHANGED_NAMESPACES) {
+		ctrl->changed_ns_list[0] =3D cpu_to_le32(0xffffffff);
+	}

Unless I'm missing it happening somewhere else, the list-full case that set= s element 0 to 0xffffffff should also explicitly zero out the rest of the l= ist to satisfy the "remainder of the list shall be zero-filled" wording in = the spec, since the other changed_ns_list entries will be filled with non-z= ero NSIDs when we get here.

-- Daniel

author maintainer
#22 lore raw

Re: [PATCH 08/14] nvmet: implement the changed namespaces log

Quoted 5 lines · Daniel

Review

Quoted 3 lines
(quoted diff) +3 -0
+	} else if (ctrl->nr_changed_ns == NVME_MAX_CHANGED_NAMESPACES) {
+		ctrl->changed_ns_list[0] = cpu_to_le32(0xffffffff);
+	}

Unless I'm missing it happening somewhere else, the list-full case that sets element 0 to 0xffffffff should also explicitly zero out the rest of the list to satisfy the "remainder of the list shall be zero-filled" wording in the spec, since the other changed_ns_list entries will be filled with non-zero NSIDs when we get here.

True. We actually zero out unused elements already, but that doesn't catch the ctrl->nr_changed_ns == NVME_MAX_CHANGED_NAMESPACES special case. This relative patch should fix it:

drivers/nvme/target/admin-cmd.c +4 -1
index d7b6293e830b..7b69c348d608 100644
@@ -136,7 +136,10 @@ static void nvmet_execute_get_log_changed_ns(struct nvmet_req *req)
 		goto out;
 
 	mutex_lock(&ctrl->lock);
-	len = ctrl->nr_changed_ns * sizeof(__le32);
+	if (ctrl->nr_changed_ns == NVME_MAX_CHANGED_NAMESPACES)
+		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);
#23 lore raw

Re: [PATCH 08/14] nvmet: implement the changed namespaces log

Quoted 18 lines · Christoph Hellwig
Quoted 5 lines · Daniel

Review

Quoted 3 lines
(quoted diff) +3 -0
+	} else if (ctrl->nr_changed_ns == NVME_MAX_CHANGED_NAMESPACES) {
+		ctrl->changed_ns_list[0] = cpu_to_le32(0xffffffff);
+	}

Unless I'm missing it happening somewhere else, the list-full case that sets element 0 to 0xffffffff should also explicitly zero out the rest of the list to satisfy the "remainder of the list shall be zero-filled" wording in the spec, since the other changed_ns_list entries will be filled with non-zero NSIDs when we get here.

True. We actually zero out unused elements already, but that doesn't catch the ctrl->nr_changed_ns == NVME_MAX_CHANGED_NAMESPACES special case. This relative patch should fix it:

drivers/nvme/target/admin-cmd.c +0 -0
index d7b6293e830b..7b69c348d608 100644
@@ -136,7 +136,10 @@ static void nvmet_execute_get_log_changed_ns(struct nvmet_req *req)
 		goto out;

drivers/nvme/target/admin-cmd.c static void nvmet_execute_get_log_changed_ns(struct nvmet_req *req) · line 145

Quoted 10 lines
drivers/nvme/target/admin-cmd.c +4 -1
 
 	mutex_lock(&ctrl->lock);
-	len = ctrl->nr_changed_ns * sizeof(__le32);
+	if (ctrl->nr_changed_ns == NVME_MAX_CHANGED_NAMESPACES)
+		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);

I'm not sure that's quite right; if nr_changed_ns == NVME_MAX_CHANGED_NAMESPACES but we haven't overflowed (in other words, the list has exactly NVME_MAX_CHANGED_NAMESPACES NSIDs), this will still only copy over the first entry.

I think it needs a:

	&& ctrlr->changed_ns_list[0] == cpu_to_le32(0xffffffff)

in the NVME_MAX_CHANGED_NAMESPACES condition to make it fully correct.

Thanks,
-- Daniel

author maintainer
#24 lore raw

PATCH 9/14 nvmet: Add AEN configuration support

In reply to Christoph Hellwig

From: Hannes Reinecke <[email protected]>

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 | 13 ++++++++++++-
 drivers/nvme/target/core.c      |  3 +++
 drivers/nvme/target/nvmet.h     |  3 +++
 3 files changed, 18 insertions(+), 1 deletion(-)
drivers/nvme/target/admin-cmd.c +12 -1
index 82d521f60a43..20d9ce5064f8 100644
@@ -432,6 +432,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_SUPPORTED) {
+			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;
@@ -470,9 +480,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 424ad41af980..53e2386b73cf 100644
@@ -162,6 +162,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, 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);
@@ -849,6 +851,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_SUPPORTED);
 
 	ctrl->changed_ns_list = kmalloc_array(NVME_MAX_CHANGED_NAMESPACES,
 			sizeof(__le32), GFP_KERNEL);
drivers/nvme/target/nvmet.h +3 -0
index bcd88b5c9d99..50c8300ea572 100644
@@ -30,6 +30,8 @@
 #define NVMET_ASYNC_EVENTS		4
 #define NVMET_ERROR_LOG_SLOTS		128
 
+#define NVMET_AEN_SUPPORTED	NVME_AEN_CFG_NS_ATTR
+
 /* 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 +125,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
Reviewed-by on v1 9/14
#25 lore raw

Re: [PATCH 09/14] nvmet: Add AEN configuration support

Looks good,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
#26 lore raw

RE: [PATCH 09/14] nvmet: Add AEN configuration support

In reply to Christoph Hellwig

[...]

Quoted 6 lines
drivers/nvme/target/admin- renamed from drivers/nvme/target/admin-cmd.c +0 -0

cmd.c
index 82d521f60a43..20d9ce5064f8 100644

drivers/nvme/target/admin-cmd.c static void nvmet_execute_set_features(struct · line 440

Quoted 9 lines
drivers/nvme/target/admin-cmd.c +5 -0
@@ -432,6 +432,16 @@ static void nvmet_execute_set_features(struct
 nvmet_req *req)
 		req->sq->ctrl->kato =3D DIV_ROUND_UP(val32, 1000);
 		nvmet_set_result(req, req->sq->ctrl->kato);
 		break;
+		val32 =3D le32_to_cpu(req->cmd->common.cdw10[1]);
+		if (val32 & ~NVMET_AEN_SUPPORTED) {
+			status =3D NVME_SC_INVALID_FIELD | NVME_SC_DNR;
+			break;
+		}

This looks overly restrictive - a host sending a Set Features with e.g. the=
health critical warning bits set in CDW11 will get a failure. As far as I= can tell, this isn't allowed by the spec; Set Features - Asynchronous Eve=
nt Configuration and the health log page have been mandatory since NVMe 1.0= , and presumably support for the corresponding health log page related AER = bits is also mandatory (these were the only bits available in NVMe 1.0). I=
think it should be fine to just allow the user to set any (valid) combinat=
ion of bits here, while still only triggering the NS Changed notification.

Thanks,
-- Daniel

author maintainer
#27 lore raw

Re: [PATCH 09/14] nvmet: Add AEN configuration support

Quoted 1 line · Daniel

This looks overly restrictive - a host sending a Set Features with e.g. the health critical warning bits set in CDW11 will get a failure. As far as I can tell, this isn't allowed by the spec; Set Features - Asynchronous Event Configuration and the health log page have been mandatory since NVMe 1.0, and presumably support for the corresponding health log page related AER bits is also mandatory (these were the only bits available in NVMe 1.0).

Agreed so far.

Quoted 1 line

I think it should be fine to just allow the user to set any (valid) combination of bits here, while still only triggering the NS Changed notification.

Disagreeing here. Catching completely bogus bits that the hosts sets is important.

#28 lore raw

RE: [PATCH 09/14] nvmet: Add AEN configuration support

Quoted 5 lines

-----Original Message-----
From: Christoph Hellwig [mailto:[email protected]]
Sent: Tuesday, May 29, 2018 10:30 AM
To: Verkamp, Daniel <[email protected]>
Cc: Christoph Hellwig <[email protected]>; [email protected]; Jens =

Axboe

Quoted 7 lines

<[email protected]>; [email protected]; Hannes Reinecke <[email protected]>; Sagi Grimberg <[email protected]>; Busch, Keith <[email protected]>; Hannes Reinecke <[email protected]>
Subject: Re: [PATCH 09/14] nvmet: Add AEN configuration support =20

Quoted 1 line · Daniel

This looks overly restrictive - a host sending a Set Features with e.g.=

the health

Quoted 1 line

critical warning bits set in CDW11 will get a failure. As far as I can t=

ell, this isn't

Quoted 1 line

allowed by the spec; Set Features - Asynchronous Event Configuration and=

the

Quoted 1 line

health log page have been mandatory since NVMe 1.0, and presumably suppor=

t

Quoted 1 line

for the corresponding health log page related AER bits is also mandatory =

(these

Quoted 5 lines

were the only bits available in NVMe 1.0). =20
Agreed so far.
=20

Quoted 1 line

I think it should be fine to just allow the user to set any (valid) com=

bination of

Quoted 4 lines

bits here, while still only triggering the NS Changed notification. =20
Disagreeing here. Catching completely bogus bits that the hosts sets is important.

Sorry, I should have been clearer - I agree with your position here. Only = bits that are valid should be allowed, so for example it is fine to fail co= mmands that set reserved bits, or optional bits that have a mechanism to in= dicate they are not supported, like Telemetry (which has an associated bit = in Identify controller data - LPA). My note above was really just about th= e health warning bits, which by my reading are not optional.

Thanks,
-- Daniel

author maintainer
#29 lore raw

Re: [PATCH 09/14] nvmet: Add AEN configuration support

Quoted 1 line · Daniel

Sorry, I should have been clearer - I agree with your position here. Only bits that are valid should be allowed, so for example it is fine to fail commands that set reserved bits, or optional bits that have a mechanism to indicate they are not supported, like Telemetry (which has an associated bit in Identify controller data - LPA). My note above was really just about the health warning bits, which by my reading are not optional.

Yes, I think your reading is right and we should not fail those bits. I'll fix it for the next version.

author maintainer
#30 lore raw

PATCH 10/14 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)."

---
 drivers/nvme/target/admin-cmd.c | 1 +
 drivers/nvme/target/core.c      | 2 ++
 drivers/nvme/target/nvmet.h     | 1 +
 3 files changed, 4 insertions(+)
drivers/nvme/target/admin-cmd.c +1 -0
index 20d9ce5064f8..d7b6293e830b 100644
@@ -141,6 +141,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 +2 -0
index 53e2386b73cf..932bdc46cd5c 100644
@@ -164,6 +164,8 @@ static void nvmet_ns_changed(struct nvmet_subsys *subsys, u32 nsid)
 		nvmet_add_to_changed_ns_log(ctrl, nsid);
 		if (!(READ_ONCE(ctrl->aen_enabled) & NVME_AEN_CFG_NS_ATTR))
 			continue;
+		if (test_and_set_bit(NVME_AEN_CFG_NS_ATTR, &ctrl->aen_masked))
+			continue;
 		nvmet_add_async_event(ctrl, NVME_AER_TYPE_NOTICE,
 				NVME_AER_NOTICE_NS_CHANGED,
 				NVME_LOG_CHANGED_NS);
drivers/nvme/target/nvmet.h +1 -0
index 50c8300ea572..e63ab3c0c655 100644
@@ -126,6 +126,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
Reviewed-by on v1 10/14
#31 lore raw

Re: [PATCH 10/14] nvmet: mask pending AERs

Looks good,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author maintainer
#32 lore raw

PATCH 11/14 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.

[hch: slight cleanups]
---
 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
Reviewed-by on v1 11/14
#33 lore raw

Re: [PATCH 11/14] nvme: submit AEN event configuration on startup

Looks good,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author maintainer
#34 lore raw

PATCH 12/14 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 12/14
#35 lore raw

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

Looks good,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author maintainer
#36 lore raw

PATCH 13/14 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
#37 lore raw

RE: [PATCH 13/14] nvme: use the changed namespaces list log to clear ns data changed AENs

Reading the spec it looks like ns log is alternate approach:

"Namespace Attribute Changed: The Identify Namespace data structure for one=
or more namespaces, as well as the Namespace List returned when the Identi=
fy command is issued with the CNS field set to 02h, have changed. Host soft= ware may use this event as an indication that it should read the Identify N= amespace data structures for each namespace to determine what has changed.

Alternatively, host software may request the Changed Namespace List (Log Id= entifier 04h) to determine which namespaces in this controller have changed=
Identify Namespace information since the last time the log page was read."

My question is: Does the target needs to implement log page 04h as this is = an optional log page and the text above suggests its used in alternate way?

If target is not required to implement, then I guess your change should sti= ll work because if log page 04h fails, it fails back to rescan. Correct? I think you can optimize this by checking the "Log Page Identifier" field i= n your result and accordingly setting EVENT_NS_CHANGED. I assume target wou= ld clear this if log page 04h is not supported.

"23:16 Log Page Identifier: Indicates the log page associated with the=
asynchronous event. This log page needs to be read by the host to clear th=
e event"

Regards,
~Sriram

-----Original Message-----
From: Linux-nvme <[email protected]> On Behalf Of Chri= stoph Hellwig
Sent: Saturday, May 26, 2018 3:58 PM
To: [email protected]
Cc: Jens Axboe <[email protected]>; Keith Busch <[email protected]>; linu= [email protected]; Sagi Grimberg <[email protected]>; Hannes Reinecke = <[email protected]>
Subject: [PATCH 13/14] nvme: use the changed namespaces list log to clear n= s data changed AENs

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 opt=
imize 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 index 06cd= renamed from drivers/nvme/host/core.c +0 -0

04dcffbc..1ae77428a1a5 100644

drivers/nvme/host/core.c +0 -0
@@ -3194,6 +3194,42 @@ static void nvme_scan_ns_sequential(struct nvme_ctrl=
 *ctrl, unsigned nn)
 	nvme_remove_invalid_namespaces(ctrl, nn);  }

=20
+static bool nvme_scan_changed_ns_log(struct nvme_ctrl *ctrl) {
+ size_t log_size =3D NVME_MAX_CHANGED_NAMESPACES * sizeof(__le32);
+ __le32 *log;
+ int error, i;
+ bool ret =3D false;
+
+ log =3D kzalloc(log_size, GFP_KERNEL);
+ if (!log)
+ return false;
+
+ error =3D 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] =3D=3D cpu_to_le32(0xffffffff))
+ goto out_free_log;
+
+ for (i =3D 0; i < NVME_MAX_CHANGED_NAMESPACES; i++) {
+ u32 nsid =3D le32_to_cpu(log[i]);
+
+ if (nsid =3D=3D 0)
+ break;
+ dev_info(ctrl->device, "rescanning namespace %d.\n", nsid);
+ nvme_validate_ns(ctrl, nsid);
+ }
+ ret =3D true;
+
+out_free_log:
+ kfree(log);
+ return ret;
+}
+
static void nvme_scan_work(struct work_struct *work) {
struct nvme_ctrl *ctrl =3D
@@ -3206,6 +3242,12 @@ static void nvme_scan_work(struct work_struct *work) =20
WARN_ON_ONCE(!ctrl->tagset);
=20
+ 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;
=20
@@ -3213,14 +3255,15 @@ static void nvme_scan_work(struct work_struct *work= )
if (ctrl->vs >=3D 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);
}
=20
/*
@@ -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 index 1168= renamed from drivers/nvme/host/nvme.h +0 -0

1278fdf6..07e8bfe705c6 100644

drivers/nvme/host/nvme.h +2 -0
@@ -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;

=20
/* Power saving configuration */
u64 ps_max_latency_us;
--
2.17.0

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

author maintainer
#38 lore raw

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

Quoted 7 lines · Sriram

Reading the spec it looks like ns log is alternate approach:

"Namespace Attribute Changed: The Identify Namespace data structure for one or more namespaces, as well as the Namespace List returned when the Identify command is issued with the CNS field set to 02h, have changed. Host software may use this event as an indication that it should read the Identify Namespace data structures for each namespace to determine what has changed.

Alternatively, host software may request the Changed Namespace List (Log Identifier 04h) to determine which namespaces in this controller have changed Identify Namespace information since the last time the log page was read."

My question is: Does the target needs to implement log page 04h as this is an optional log page and the text above suggests its used in alternate way?

Section 5.2 clearly states that each AER comes with a log page to clear it, and the above does not contain any language to explicitly override it. So my reading of the spec is that to clear the event you need to read the log page, but to find out what has changed you might issue Identify commands instead.

Quoted 1 line

If target is not required to implement, then I guess your change should still work because if log page 04h fails, it fails back to rescan. Correct?

Independ of what the spec actually requires, the code tries to robust as possible and falls back to doing the manual scan.

Quoted 1 line

I think you can optimize this by checking the "Log Page Identifier" field in your result and accordingly setting EVENT_NS_CHANGED. I assume target would clear this if log page 04h is not supported.

We can try that, but I'm not sure what it is going to buy us.

#39 lore raw

RE: [PATCH 13/14] nvme: use the changed namespaces list log to clear ns data changed AENs

Section 5.2:

Asynchronous events are grouped into event types. The event type information is indicated in Dword 0 of the completion queue entry for the Asynchronous Event Request command. 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 (refer to section 5.14).

The event is cleared by reading the log page associated with that event ... I don't know how the event can be cleared if the associated log page is not supported (the masking of subsequent events of that type would turn it into a one-shot). Interesting however, in the list (that reports "the following event types are defined"), there are several of the defined events missing. Looks like an ECN opportunity to flush out that list of defined event types.

In addition, how is this bit set:

95:92 M Optional Asynchronous Events Supported (OAES): This field indicates the optional asynchronous events supported by the controller. A controller shall not send optional asynchronous events before they are enabled by host software.

Bits 31:10 are reserved.
Bit 9 is set to '1' if the controller supports sending Firmware Activation Notices. If cleared to '0', then the controller does not support the Firmware Activation Notices event.

Bit 8 is set to '1' if the controller supports sending Namespace Attribute Notices and the associated Changed Namespace List log page. If cleared to '0', then the controller does not support the Namespace Attribute Notices event nor the associated Changed Namespace List log page. Bits 7:0 are reserved.

Not sure how you set that bit if you support the AEN but not the log page.

Fred

-----Original Message-----
From: Christoph Hellwig <[email protected]>
Sent: Saturday, May 26, 2018 8:22 AM
To: Popuri, Sriram <[email protected]>
Cc: Christoph Hellwig <[email protected]>; [email protected]; Knight, Frederick <[email protected]>; Jens Axboe <[email protected]>; Keith Busch <[email protected]>; [email protected]; Sagi Grimberg <[email protected]>; Hannes Reinecke <[email protected]>
Subject: Re: [PATCH 13/14] nvme: use the changed namespaces list log to clear ns data changed AENs

Quoted 7 lines · Sriram

Reading the spec it looks like ns log is alternate approach:

"Namespace Attribute Changed: The Identify Namespace data structure for one or more namespaces, as well as the Namespace List returned when the Identify command is issued with the CNS field set to 02h, have changed. Host software may use this event as an indication that it should read the Identify Namespace data structures for each namespace to determine what has changed.

Alternatively, host software may request the Changed Namespace List (Log Identifier 04h) to determine which namespaces in this controller have changed Identify Namespace information since the last time the log page was read."

My question is: Does the target needs to implement log page 04h as this is an optional log page and the text above suggests its used in alternate way?

Section 5.2 clearly states that each AER comes with a log page to clear it, and the above does not contain any language to explicitly override it. So my reading of the spec is that to clear the event you need to read the log page, but to find out what has changed you might issue Identify commands instead.

Quoted 1 line

If target is not required to implement, then I guess your change should still work because if log page 04h fails, it fails back to rescan. Correct?

Independ of what the spec actually requires, the code tries to robust as possible and falls back to doing the manual scan.

Quoted 1 line

I think you can optimize this by checking the "Log Page Identifier" field in your result and accordingly setting EVENT_NS_CHANGED. I assume target would clear this if log page 04h is not supported.

We can try that, but I'm not sure what it is going to buy us.

Reviewed-by on v1 13/14
#40 lore raw

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

In reply to Christoph Hellwig

Looks good,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
#41 lore raw

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

In reply to Christoph Hellwig
Quoted 6 lines · 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.

I'm a little concerned about this. Userspace might be reading the same log page. Since the contents of the page may change each time its read, it's possible the driver will see only a subset of changed namespaces at the point it gets to read the log page, missing a chance to revalidate others.

author maintainer
#42 lore raw

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

Quoted 5 lines · Keith Busch
Quoted 5 lines

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.

Quoted 7 lines
Quoted 1 line

I'm a little concerned about this. Userspace might be reading the same log page. Since the contents of the page may change each time its read, it's possible the driver will see only a subset of changed namespaces at the point it gets to read the log page, missing a chance to revalidate others.

I agree with the concern, but I don't think it really is uniqueue here. We allow userspace to send all kind sof harmful commands, even queue for queue creation and deletion.

But let's assume we don't want to use the list due to this concern:
we'd still have to read the log page, as per the NVMe spec the only think clearing a pending AEN is reading the associated log page. We'd then need to still do the full scan using identify. Is this what we want? If you think this is important for reliability we could just ignore the log page.

#43 lore raw

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

Quoted 6 lines · Christoph Hellwig

But let's assume we don't want to use the list due to this concern:
we'd still have to read the log page, as per the NVMe spec the only think clearing a pending AEN is reading the associated log page. We'd then need to still do the full scan using identify. Is this what we want? If you think this is important for reliability we could just ignore the log page.

That sounds good. Let's have the driver read the log page to re-arm the event as you've done, but don't rely on the contents for namespace enumeration.

The rest of your series looks good to me.

author maintainer
#44 lore raw

PATCH 14/14 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 14/14
#45 lore raw

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

Looks good,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850