Commit f493af37 authored by Christoph Hellwig's avatar Christoph Hellwig

nvme: don't rely on the changed namespace list log

Don't optimize our namespace rescan based on the changed namespace list
log page as userspace might have changed the content through reading
it.
Suggested-by: default avatarKeith Busch <keith.busch@linux.intel.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarKeith Busch <keith.busch@linux.intel.com>
Reviewed-by: default avatarHannes Reinecke <hare@suse.com>
parent c42d7a30
...@@ -3197,40 +3197,28 @@ static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl, unsigned nn) ...@@ -3197,40 +3197,28 @@ static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl, unsigned nn)
nvme_remove_invalid_namespaces(ctrl, nn); nvme_remove_invalid_namespaces(ctrl, nn);
} }
static bool nvme_scan_changed_ns_log(struct nvme_ctrl *ctrl) static void nvme_clear_changed_ns_log(struct nvme_ctrl *ctrl)
{ {
size_t log_size = NVME_MAX_CHANGED_NAMESPACES * sizeof(__le32); size_t log_size = NVME_MAX_CHANGED_NAMESPACES * sizeof(__le32);
__le32 *log; __le32 *log;
int error, i; int error;
bool ret = false;
log = kzalloc(log_size, GFP_KERNEL); log = kzalloc(log_size, GFP_KERNEL);
if (!log) if (!log)
return false; return;
/*
* We need to read the log to clear the AEN, but we don't want to rely
* on it for the changed namespace information as userspace could have
* raced with us in reading the log page, which could cause us to miss
* updates.
*/
error = nvme_get_log(ctrl, NVME_LOG_CHANGED_NS, log, log_size); error = nvme_get_log(ctrl, NVME_LOG_CHANGED_NS, log, log_size);
if (error) { if (error)
dev_warn(ctrl->device, dev_warn(ctrl->device,
"reading changed ns log failed: %d\n", error); "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); kfree(log);
return ret;
} }
static void nvme_scan_work(struct work_struct *work) static void nvme_scan_work(struct work_struct *work)
...@@ -3246,9 +3234,8 @@ static void nvme_scan_work(struct work_struct *work) ...@@ -3246,9 +3234,8 @@ static void nvme_scan_work(struct work_struct *work)
WARN_ON_ONCE(!ctrl->tagset); WARN_ON_ONCE(!ctrl->tagset);
if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) { if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) {
if (nvme_scan_changed_ns_log(ctrl))
goto out_sort_namespaces;
dev_info(ctrl->device, "rescanning namespaces.\n"); dev_info(ctrl->device, "rescanning namespaces.\n");
nvme_clear_changed_ns_log(ctrl);
} }
if (nvme_identify_ctrl(ctrl, &id)) if (nvme_identify_ctrl(ctrl, &id))
...@@ -3263,7 +3250,6 @@ static void nvme_scan_work(struct work_struct *work) ...@@ -3263,7 +3250,6 @@ static void nvme_scan_work(struct work_struct *work)
nvme_scan_ns_sequential(ctrl, nn); nvme_scan_ns_sequential(ctrl, nn);
out_free_id: out_free_id:
kfree(id); kfree(id);
out_sort_namespaces:
down_write(&ctrl->namespaces_rwsem); down_write(&ctrl->namespaces_rwsem);
list_sort(NULL, &ctrl->namespaces, ns_cmp); list_sort(NULL, &ctrl->namespaces, ns_cmp);
up_write(&ctrl->namespaces_rwsem); up_write(&ctrl->namespaces_rwsem);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment