All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Konopko <igor.j.konopko@intel.com>
To: mb@lightnvm.io, javier@javigon.com, hans.holmberg@cnexlabs.com
Cc: linux-block@vger.kernel.org, igor.j.konopko@intel.com
Subject: [PATCH v2 16/16] lightnvm: track inflight target creations
Date: Fri, 22 Mar 2019 15:48:43 +0100	[thread overview]
Message-ID: <20190322144843.9602-17-igor.j.konopko@intel.com> (raw)
In-Reply-To: <20190322144843.9602-1-igor.j.konopko@intel.com>

This patch adds a counter, which is responsible for tracking inflight
target creations.

When creation process is still in progress, target is not yet on
targets list. This causes a chance for removing whole lightnvm
subsystem by calling nvm_unregister() in the meantime and finally by
causing kernel panic inside target init function.

With this patch we are able to track such a scenarios and wait with
completing nvm_unregister() and freeing memory until target creation
will be completed.

Signed-off-by: Igor Konopko <igor.j.konopko@intel.com>
---
 drivers/lightnvm/core.c  | 19 ++++++++++++++++++-
 include/linux/lightnvm.h |  2 ++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index c01f83b..1edb9d8 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -1083,6 +1083,7 @@ static int nvm_core_init(struct nvm_dev *dev)
 	INIT_LIST_HEAD(&dev->targets);
 	mutex_init(&dev->mlock);
 	spin_lock_init(&dev->lock);
+	dev->create_inflight = 0;
 
 	ret = nvm_register_map(dev);
 	if (ret)
@@ -1180,6 +1181,11 @@ void nvm_unregister(struct nvm_dev *dev)
 	struct nvm_target *t, *tmp;
 
 	mutex_lock(&dev->mlock);
+	while (dev->create_inflight > 0) {
+		mutex_unlock(&dev->mlock);
+		io_schedule();
+		mutex_lock(&dev->mlock);
+	}
 	list_for_each_entry_safe(t, tmp, &dev->targets, list) {
 		if (t->dev->parent != dev)
 			continue;
@@ -1198,6 +1204,7 @@ EXPORT_SYMBOL(nvm_unregister);
 static int __nvm_configure_create(struct nvm_ioctl_create *create)
 {
 	struct nvm_dev *dev;
+	int ret;
 
 	down_write(&nvm_lock);
 	dev = nvm_find_nvm_dev(create->dev);
@@ -1208,7 +1215,17 @@ static int __nvm_configure_create(struct nvm_ioctl_create *create)
 		return -EINVAL;
 	}
 
-	return nvm_create_tgt(dev, create);
+	mutex_lock(&dev->mlock);
+	dev->create_inflight++;
+	mutex_unlock(&dev->mlock);
+
+	ret = nvm_create_tgt(dev, create);
+
+	mutex_lock(&dev->mlock);
+	dev->create_inflight--;
+	mutex_unlock(&dev->mlock);
+
+	return ret;
 }
 
 static long nvm_ioctl_info(struct file *file, void __user *arg)
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index d3b0270..e462d1d 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -428,6 +428,8 @@ struct nvm_dev {
 	char name[DISK_NAME_LEN];
 	void *private_data;
 
+	int create_inflight;
+
 	void *rmap;
 
 	struct mutex mlock;
-- 
2.9.5


      parent reply	other threads:[~2019-03-22 14:53 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-22 14:48 [PATCH v2 00/16] lightnvm: next set of improvements for 5.2 Igor Konopko
2019-03-22 14:48 ` [PATCH v2 01/16] lightnvm: pblk: warn when there are opened chunks Igor Konopko
2019-03-25 11:32   ` Matias Bjørling
2019-03-22 14:48 ` [PATCH v2 02/16] lightnvm: pblk: IO path reorganization Igor Konopko
2019-03-25  5:55   ` Javier González
2019-03-22 14:48 ` [PATCH v2 03/16] lightnvm: pblk: simplify partial read path Igor Konopko
2019-03-22 14:48 ` [PATCH v2 04/16] lightnvm: pblk: OOB recovery for closed chunks fix Igor Konopko
2019-03-25  6:02   ` Javier González
2019-03-25 11:12     ` Igor Konopko
2019-03-22 14:48 ` [PATCH v2 05/16] lightnvm: pblk: propagate errors when reading meta Igor Konopko
2019-03-22 14:48 ` [PATCH v2 06/16] lightnvm: pblk: recover only written metadata Igor Konopko
2019-03-22 14:48 ` [PATCH v2 07/16] lightnvm: pblk: wait for inflight IOs in recovery Igor Konopko
2019-03-25  6:18   ` Javier González
2019-03-25 11:17     ` Igor Konopko
2019-03-22 14:48 ` [PATCH v2 08/16] lightnvm: pblk: remove internal IO timeout Igor Konopko
2019-03-22 14:48 ` [PATCH v2 09/16] lightnvm: pblk: fix spin_unlock order Igor Konopko
2019-03-25 11:09   ` Matias Bjørling
2019-03-22 14:48 ` [PATCH v2 10/16] lightnvm: pblk: kick writer on write recovery path Igor Konopko
2019-03-25 11:13   ` Matias Bjørling
2019-03-22 14:48 ` [PATCH v2 11/16] lightnvm: pblk: fix update line wp in OOB recovery Igor Konopko
2019-03-25 11:18   ` Matias Bjørling
2019-03-22 14:48 ` [PATCH v2 12/16] lightnvm: pblk: do not read OOB from emeta region Igor Konopko
2019-03-25  6:23   ` Javier González
2019-03-25 11:17     ` Igor Konopko
2019-03-22 14:48 ` [PATCH v2 13/16] lightnvm: pblk: store multiple copies of smeta Igor Konopko
2019-03-25  6:31   ` Javier González
2019-03-22 14:48 ` [PATCH v2 14/16] lightnvm: pblk: GC error handling Igor Konopko
2019-03-25 11:29   ` Matias Bjørling
2019-03-22 14:48 ` [PATCH v2 15/16] lightnvm: pblk: use nvm_rq_to_ppa_list() Igor Konopko
2019-03-22 14:48 ` Igor Konopko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190322144843.9602-17-igor.j.konopko@intel.com \
    --to=igor.j.konopko@intel.com \
    --cc=hans.holmberg@cnexlabs.com \
    --cc=javier@javigon.com \
    --cc=linux-block@vger.kernel.org \
    --cc=mb@lightnvm.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.