Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d08cd5e0 authored by Jeff Moyer's avatar Jeff Moyer Committed by Dan Williams
Browse files

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: default avatarJeff Moyer <jmoyer@redhat.com>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent ed07c433
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -630,6 +630,7 @@ static struct arena_info *alloc_arena(struct btt *btt, size_t size,
		return NULL;
		return NULL;
	arena->nd_btt = btt->nd_btt;
	arena->nd_btt = btt->nd_btt;
	arena->sector_size = btt->sector_size;
	arena->sector_size = btt->sector_size;
	mutex_init(&arena->err_lock);


	if (!size)
	if (!size)
		return arena;
		return arena;
@@ -758,7 +759,6 @@ static int discover_arenas(struct btt *btt)
		arena->external_lba_start = cur_nlba;
		arena->external_lba_start = cur_nlba;
		parse_arena_meta(arena, super, cur_off);
		parse_arena_meta(arena, super, cur_off);


		mutex_init(&arena->err_lock);
		ret = btt_freelist_init(arena);
		ret = btt_freelist_init(arena);
		if (ret)
		if (ret)
			goto out;
			goto out;