Skip to contentSkip to conversation

filemap_fault can lose errors

PATCH Matthew Wilcox 2 participants 2 messages Sep 11, 2019

Subsystems (3)
lore
Share & tools
lore

Matthew Wilcox

author maintainer
#0 lore raw

If we encounter an error on a page, we can lose the error if we've dropped the mmap_sem while we wait for the I/O. That can result in taking the fault multiple times, and retrying the read multiple times. Spotted by inspection.

Fixes 6b4c9f446981 ("filemap: drop the mmap_sem for all blocking operations")
mm/filemap.c +4 -2
index d0cf700bf201..37bd4aedfccf 100644
@@ -2615,6 +2615,8 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
 		if (!PageUptodate(page))
 			error = -EIO;
 	}
+	if (error < 0)
+		ret |= VM_FAULT_SIGBUS;
 	if (fpin)
 		goto out_retry;
 	put_page(page);
@@ -2622,9 +2624,9 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
 	if (!error || error == AOP_TRUNCATED_PAGE)
 		goto retry_find;
 
-	/* Things didn't work out. Return zero to tell the mm layer so. */
+	/* Things didn't work out. */
 	shrink_readahead_size_eio(file, ra);
-	return VM_FAULT_SIGBUS;
+	return ret;
 
 out_retry:
 	/*
#1 lore raw
Quoted 5 lines · Matthew Wilcox

If we encounter an error on a page, we can lose the error if we've dropped the mmap_sem while we wait for the I/O. That can result in taking the fault multiple times, and retrying the read multiple times. Spotted by inspection.

But does the patch make any difference?

Looking into x86 code, VM_FAULT_RETRY makes it retry the fault or return to userspace before it checks for VM_FAULT_SIGBUS bit.

Signature · 1 line
 Kirill A. Shutemov