diff mbox series

[03/13] lightnvm: pblk: Fix put line back behaviour

Message ID 20190227171442.11853-4-igor.j.konopko@intel.com (mailing list archive)
State New, archived
Headers show
Series lightnvm: bugfixes and improvements | expand

Commit Message

Igor Konopko Feb. 27, 2019, 5:14 p.m. UTC
In current implementation of pblk_put_line_back behaviour
there are two cases which are not handled.

First one is the race condition with __pblk_map_invalidate in
which function we check for line state, which might be closed,
but still not added to any list and thus explode in list_move_tail.
This is due to lack of locking both gc_lock and line lock
in pblk_put_line_back current implementation.

The second issue is that when we are in that function, line
is not on any list and pblk_line_gc_list might hit the same
gc group and thus not return any move_list. Then our line
will stuck forever unassigned to any list. Simply resetting
gc_list to none will fix that.

Signed-off-by: Igor Konopko <igor.j.konopko@intel.com>
---
 drivers/lightnvm/pblk-gc.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Comments

Hans Holmberg March 1, 2019, 1:27 p.m. UTC | #1
Looks good.

Reviewed-by: Hans Holmberg <hans.holmberg@cnexlabs.com>

On Wed, Feb 27, 2019 at 6:17 PM Igor Konopko <igor.j.konopko@intel.com> wrote:
>
> In current implementation of pblk_put_line_back behaviour
> there are two cases which are not handled.
>
> First one is the race condition with __pblk_map_invalidate in
> which function we check for line state, which might be closed,
> but still not added to any list and thus explode in list_move_tail.
> This is due to lack of locking both gc_lock and line lock
> in pblk_put_line_back current implementation.
>
> The second issue is that when we are in that function, line
> is not on any list and pblk_line_gc_list might hit the same
> gc group and thus not return any move_list. Then our line
> will stuck forever unassigned to any list. Simply resetting
> gc_list to none will fix that.
>
> Signed-off-by: Igor Konopko <igor.j.konopko@intel.com>
> ---
>  drivers/lightnvm/pblk-gc.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/lightnvm/pblk-gc.c b/drivers/lightnvm/pblk-gc.c
> index 31fc1339faa8..511ed0d5333c 100644
> --- a/drivers/lightnvm/pblk-gc.c
> +++ b/drivers/lightnvm/pblk-gc.c
> @@ -64,19 +64,23 @@ static void pblk_put_line_back(struct pblk *pblk, struct pblk_line *line)
>         struct pblk_line_mgmt *l_mg = &pblk->l_mg;
>         struct list_head *move_list;
>
> +       spin_lock(&l_mg->gc_lock);
>         spin_lock(&line->lock);
>         WARN_ON(line->state != PBLK_LINESTATE_GC);
>         line->state = PBLK_LINESTATE_CLOSED;
>         trace_pblk_line_state(pblk_disk_name(pblk), line->id,
>                                         line->state);
> +
> +       /* We need to reset gc_group in order to ensure that
> +        * pblk_line_gc_list will return proper move_list
> +        * since right now current line is not on any of the
> +        * gc lists.
> +        */
> +       line->gc_group = PBLK_LINEGC_NONE;
>         move_list = pblk_line_gc_list(pblk, line);
>         spin_unlock(&line->lock);
> -
> -       if (move_list) {
> -               spin_lock(&l_mg->gc_lock);
> -               list_add_tail(&line->list, move_list);
> -               spin_unlock(&l_mg->gc_lock);
> -       }
> +       list_add_tail(&line->list, move_list);
> +       spin_unlock(&l_mg->gc_lock);
>  }
>
>  static void pblk_gc_line_ws(struct work_struct *work)
> --
> 2.17.1
>
Javier González March 4, 2019, 7:22 a.m. UTC | #2
> On 27 Feb 2019, at 18.14, Igor Konopko <igor.j.konopko@intel.com> wrote:
> 
> In current implementation of pblk_put_line_back behaviour
> there are two cases which are not handled.
> 
> First one is the race condition with __pblk_map_invalidate in
> which function we check for line state, which might be closed,
> but still not added to any list and thus explode in list_move_tail.
> This is due to lack of locking both gc_lock and line lock
> in pblk_put_line_back current implementation.
> 
> The second issue is that when we are in that function, line
> is not on any list and pblk_line_gc_list might hit the same
> gc group and thus not return any move_list. Then our line
> will stuck forever unassigned to any list. Simply resetting
> gc_list to none will fix that.
> 
> Signed-off-by: Igor Konopko <igor.j.konopko@intel.com>
> ---
> drivers/lightnvm/pblk-gc.c | 16 ++++++++++------
> 1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/lightnvm/pblk-gc.c b/drivers/lightnvm/pblk-gc.c
> index 31fc1339faa8..511ed0d5333c 100644
> --- a/drivers/lightnvm/pblk-gc.c
> +++ b/drivers/lightnvm/pblk-gc.c
> @@ -64,19 +64,23 @@ static void pblk_put_line_back(struct pblk *pblk, struct pblk_line *line)
> 	struct pblk_line_mgmt *l_mg = &pblk->l_mg;
> 	struct list_head *move_list;
> 
> +	spin_lock(&l_mg->gc_lock);
> 	spin_lock(&line->lock);
> 	WARN_ON(line->state != PBLK_LINESTATE_GC);
> 	line->state = PBLK_LINESTATE_CLOSED;
> 	trace_pblk_line_state(pblk_disk_name(pblk), line->id,
> 					line->state);
> +
> +	/* We need to reset gc_group in order to ensure that
> +	 * pblk_line_gc_list will return proper move_list
> +	 * since right now current line is not on any of the
> +	 * gc lists.
> +	 */
> +	line->gc_group = PBLK_LINEGC_NONE;
> 	move_list = pblk_line_gc_list(pblk, line);
> 	spin_unlock(&line->lock);
> -
> -	if (move_list) {
> -		spin_lock(&l_mg->gc_lock);
> -		list_add_tail(&line->list, move_list);
> -		spin_unlock(&l_mg->gc_lock);
> -	}
> +	list_add_tail(&line->list, move_list);
> +	spin_unlock(&l_mg->gc_lock);
> }
> 
> static void pblk_gc_line_ws(struct work_struct *work)
> --
> 2.17.1

This comes back from the time where GC was single threaded - I left out
this when reimplementing the locking. Good catch.

Please, add a fixes tag for this to be back ported.

Reviewed-by: Javier González <javier@javigon.com>
diff mbox series

Patch

diff --git a/drivers/lightnvm/pblk-gc.c b/drivers/lightnvm/pblk-gc.c
index 31fc1339faa8..511ed0d5333c 100644
--- a/drivers/lightnvm/pblk-gc.c
+++ b/drivers/lightnvm/pblk-gc.c
@@ -64,19 +64,23 @@  static void pblk_put_line_back(struct pblk *pblk, struct pblk_line *line)
 	struct pblk_line_mgmt *l_mg = &pblk->l_mg;
 	struct list_head *move_list;
 
+	spin_lock(&l_mg->gc_lock);
 	spin_lock(&line->lock);
 	WARN_ON(line->state != PBLK_LINESTATE_GC);
 	line->state = PBLK_LINESTATE_CLOSED;
 	trace_pblk_line_state(pblk_disk_name(pblk), line->id,
 					line->state);
+
+	/* We need to reset gc_group in order to ensure that
+	 * pblk_line_gc_list will return proper move_list
+	 * since right now current line is not on any of the
+	 * gc lists.
+	 */
+	line->gc_group = PBLK_LINEGC_NONE;
 	move_list = pblk_line_gc_list(pblk, line);
 	spin_unlock(&line->lock);
-
-	if (move_list) {
-		spin_lock(&l_mg->gc_lock);
-		list_add_tail(&line->list, move_list);
-		spin_unlock(&l_mg->gc_lock);
-	}
+	list_add_tail(&line->list, move_list);
+	spin_unlock(&l_mg->gc_lock);
 }
 
 static void pblk_gc_line_ws(struct work_struct *work)