Browse Source

lightnvm: pblk: prevent gc kicks when gc is not operational

GC can be kicked after it has been shut down when closing the last
line during exit, resulting in accesses to freed structures.

Make sure that GC is not triggered while it is not operational.
Also make sure that GC won't be re-activated during exit when
running on another processor by using timer_del_sync.

Signed-off-by: Hans Holmberg <hans.holmberg@cnexlabs.com>
Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Hans Holmberg 7 years ago
parent
commit
3e3a5b8ebd
2 changed files with 6 additions and 4 deletions
  1. 5 4
      drivers/lightnvm/pblk-gc.c
  2. 1 0
      drivers/lightnvm/pblk-init.c

+ 5 - 4
drivers/lightnvm/pblk-gc.c

@@ -478,10 +478,10 @@ void pblk_gc_should_start(struct pblk *pblk)
 {
 {
 	struct pblk_gc *gc = &pblk->gc;
 	struct pblk_gc *gc = &pblk->gc;
 
 
-	if (gc->gc_enabled && !gc->gc_active)
+	if (gc->gc_enabled && !gc->gc_active) {
 		pblk_gc_start(pblk);
 		pblk_gc_start(pblk);
-
-	pblk_gc_kick(pblk);
+		pblk_gc_kick(pblk);
+	}
 }
 }
 
 
 /*
 /*
@@ -620,7 +620,8 @@ void pblk_gc_exit(struct pblk *pblk)
 	flush_workqueue(gc->gc_reader_wq);
 	flush_workqueue(gc->gc_reader_wq);
 	flush_workqueue(gc->gc_line_reader_wq);
 	flush_workqueue(gc->gc_line_reader_wq);
 
 
-	del_timer(&gc->gc_timer);
+	gc->gc_enabled = 0;
+	del_timer_sync(&gc->gc_timer);
 	pblk_gc_stop(pblk, 1);
 	pblk_gc_stop(pblk, 1);
 
 
 	if (gc->gc_ts)
 	if (gc->gc_ts)

+ 1 - 0
drivers/lightnvm/pblk-init.c

@@ -931,6 +931,7 @@ static void *pblk_init(struct nvm_tgt_dev *dev, struct gendisk *tdisk,
 	pblk->dev = dev;
 	pblk->dev = dev;
 	pblk->disk = tdisk;
 	pblk->disk = tdisk;
 	pblk->state = PBLK_STATE_RUNNING;
 	pblk->state = PBLK_STATE_RUNNING;
+	pblk->gc.gc_enabled = 0;
 
 
 	spin_lock_init(&pblk->trans_lock);
 	spin_lock_init(&pblk->trans_lock);
 	spin_lock_init(&pblk->lock);
 	spin_lock_init(&pblk->lock);