Commit 44cdbdc6 authored by Javier González's avatar Javier González Committed by Jens Axboe

lightnvm: pblk: fix race on sysfs line state

pblk exposes a sysfs interface that represents its internal state. Part
of this state is the map bitmap for the current open line, which should
be protected by the line lock to avoid a race when freeing the line
metadata. Currently, it is not.

This patch makes sure that the line state is consistent and NULL
bitmap pointers are not dereferenced.
Signed-off-by: default avatarJavier González <javier@cnexlabs.com>
Signed-off-by: default avatarMatias Bjørling <mb@lightnvm.io>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 02a1520d
...@@ -1611,13 +1611,14 @@ struct pblk_line *pblk_line_replace_data(struct pblk *pblk) ...@@ -1611,13 +1611,14 @@ struct pblk_line *pblk_line_replace_data(struct pblk *pblk)
struct pblk_line *cur, *new = NULL; struct pblk_line *cur, *new = NULL;
unsigned int left_seblks; unsigned int left_seblks;
cur = l_mg->data_line;
new = l_mg->data_next; new = l_mg->data_next;
if (!new) if (!new)
goto out; goto out;
l_mg->data_line = new;
spin_lock(&l_mg->free_lock); spin_lock(&l_mg->free_lock);
cur = l_mg->data_line;
l_mg->data_line = new;
pblk_line_setup_metadata(new, l_mg, &pblk->lm); pblk_line_setup_metadata(new, l_mg, &pblk->lm);
spin_unlock(&l_mg->free_lock); spin_unlock(&l_mg->free_lock);
......
...@@ -263,8 +263,14 @@ static ssize_t pblk_sysfs_lines(struct pblk *pblk, char *page) ...@@ -263,8 +263,14 @@ static ssize_t pblk_sysfs_lines(struct pblk *pblk, char *page)
sec_in_line = l_mg->data_line->sec_in_line; sec_in_line = l_mg->data_line->sec_in_line;
meta_weight = bitmap_weight(&l_mg->meta_bitmap, meta_weight = bitmap_weight(&l_mg->meta_bitmap,
PBLK_DATA_LINES); PBLK_DATA_LINES);
map_weight = bitmap_weight(l_mg->data_line->map_bitmap,
spin_lock(&l_mg->data_line->lock);
if (l_mg->data_line->map_bitmap)
map_weight = bitmap_weight(l_mg->data_line->map_bitmap,
lm->sec_per_line); lm->sec_per_line);
else
map_weight = 0;
spin_unlock(&l_mg->data_line->lock);
} }
spin_unlock(&l_mg->free_lock); spin_unlock(&l_mg->free_lock);
......
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