[PATCH] dax: fix deadlock in __dax_fault

From: Ross Zwisler
Date: Wed Sep 23 2015 - 16:40:28 EST


Fix the deadlock exposed by xfstests generic/075. Here is the sequence
that was causing us to deadlock:

1) enter __dax_fault()
2) page = find_get_page() gives us a page, so skip
i_mmap_lock_write(mapping)
3) if (!buffer_mapped(&bh) && !buffer_unwritten(&bh) && !vmf->cow_page)
passes, enter this block
4) if (vmf->flags & FAULT_FLAG_WRITE) fails, so do the else case and
i_mmap_unlock_write(mapping);
return dax_load_hole(mapping, page, vmf);

This causes us to up_write() a semaphore that we weren't holding.

The up_write() on a semaphore we didn't down_write() happens twice in
a row, and then the next time we try and i_mmap_lock_write(), we hang.

Signed-off-by: Ross Zwisler <ross.zwisler@xxxxxxxxxxxxxxx>
Reported-by: Dave Chinner <david@xxxxxxxxxxxxx>
---
fs/dax.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/dax.c b/fs/dax.c
index 7ae6df7..df1b0ac 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -405,7 +405,8 @@ int __dax_fault(struct vm_area_struct *vma, struct vm_fault *vmf,
if (error)
goto unlock;
} else {
- i_mmap_unlock_write(mapping);
+ if (!page)
+ i_mmap_unlock_write(mapping);
return dax_load_hole(mapping, page, vmf);
}
}
--
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/