diff options
author | Jeff Moyer <jmoyer@redhat.com> | 2017-12-13 16:33:09 -0500 |
---|---|---|
committer | Dan Williams <dan.j.williams@intel.com> | 2018-01-19 20:01:29 -0500 |
commit | d08cd5e0eb632eef7819ba911c09d89a767f2d0c (patch) | |
tree | c68a2d91c3265b0b3752618db864180c4f0bcc17 | |
parent | ed07c4338dd5ceadb5ffed0a5be03488ac54f5d2 (diff) |
libnvdimm, btt: fix uninitialized err_lock
When a sector mode namespace is initially created, the arena's err_lock
is not initialized. If, on the other hand, the namespace already
exists, the mutex is initialized. To fix the issue, I moved the mutex
initialization into the arena_alloc, which is called by both
discover_arenas and create_arenas.
This was discovered on an older kernel where mutex_trylock checks the
count to determine whether the lock is held. Because the data structure
is kzalloc-d, that count was 0 (held), and I/O to the device would hang
forever waiting for the lock to be released (see btt_write_pg, for
example). Current kernels have a different mutex implementation that
checks for a non-null owner, and so this doesn't show up as a problem.
If that lock were ever contended, it might cause issues, but you'd have
to be really unlucky, I think.
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
-rw-r--r-- | drivers/nvdimm/btt.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c index e949e3302af4..5860f99113c6 100644 --- a/drivers/nvdimm/btt.c +++ b/drivers/nvdimm/btt.c | |||
@@ -630,6 +630,7 @@ static struct arena_info *alloc_arena(struct btt *btt, size_t size, | |||
630 | return NULL; | 630 | return NULL; |
631 | arena->nd_btt = btt->nd_btt; | 631 | arena->nd_btt = btt->nd_btt; |
632 | arena->sector_size = btt->sector_size; | 632 | arena->sector_size = btt->sector_size; |
633 | mutex_init(&arena->err_lock); | ||
633 | 634 | ||
634 | if (!size) | 635 | if (!size) |
635 | return arena; | 636 | return arena; |
@@ -758,7 +759,6 @@ static int discover_arenas(struct btt *btt) | |||
758 | arena->external_lba_start = cur_nlba; | 759 | arena->external_lba_start = cur_nlba; |
759 | parse_arena_meta(arena, super, cur_off); | 760 | parse_arena_meta(arena, super, cur_off); |
760 | 761 | ||
761 | mutex_init(&arena->err_lock); | ||
762 | ret = btt_freelist_init(arena); | 762 | ret = btt_freelist_init(arena); |
763 | if (ret) | 763 | if (ret) |
764 | goto out; | 764 | goto out; |