All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix ext4 fault handling when mounted with -o dax,ro
@ 2017-08-22 22:24 Randy Dodgen
  2017-08-23  3:37   ` rdodgen
  0 siblings, 1 reply; 44+ messages in thread
From: Randy Dodgen @ 2017-08-22 22:24 UTC (permalink / raw)
  To: tytso, linux-ext4; +Cc: Randy Dodgen

If an ext4 filesystem is mounted with both the DAX and read-only
options, executables on that filesystem will fail to start (claiming
'Segmentation fault') due to the fault handler returning
VM_FAULT_SIGBUS.

This is due to the DAX fault handler (see ext4_dax_huge_fault)
attempting to write to the journal when FAULT_FLAG_WRITE is set. This is
the wrong behavior for write faults which will lead to a COW page; in
particular, this fails for readonly mounts.

This changes replicates some check from dax_iomap_fault to more
precisely reason about when a journal-write is needed.

It might be the case that this could be better handled in
ext4_iomap_begin / ext4_iomap_end (called via iomap_ops inside
dax_iomap_fault). These is some overlap already (e.g. grabbing journal
handles).
---
 fs/ext4/file.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 0d7cf0cc9b87..d512fb85a3e3 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -279,7 +279,31 @@ static int ext4_dax_huge_fault(struct vm_fault *vmf,
 	handle_t *handle = NULL;
 	struct inode *inode = file_inode(vmf->vma->vm_file);
 	struct super_block *sb = inode->i_sb;
-	bool write = vmf->flags & FAULT_FLAG_WRITE;
+	bool write;
+
+	/*
+	 * We have to distinguish real writes from writes which will result in a
+	 * COW page
+	 * - COW writes need to fall-back to installing PTEs. See
+	 *   dax_iomap_pmd_fault.
+	 * - COW writes should *not* poke the journal (the file will not be
+	 *   changed). Doing so would cause unintended failures when mounted
+	 *   read-only.
+	 */
+	if (pe_size == PE_SIZE_PTE) {
+		/* See dax_iomap_pte_fault. */
+		write = (vmf->flags & FAULT_FLAG_WRITE) && !vmf->cow_page;
+	} else if (pe_size == PE_SIZE_PMD) {
+		/* See dax_iomap_pmd_fault. */
+		write = vmf->flags & FAULT_FLAG_WRITE;
+		if (write && !(vmf->vma->vm_flags & VM_SHARED)) {
+			split_huge_pmd(vmf->vma, vmf->pmd, vmf->address);
+			count_vm_event(THP_FAULT_FALLBACK);
+			return VM_FAULT_FALLBACK;
+		}
+	} else {
+		return VM_FAULT_FALLBACK;
+	}
 
 	if (write) {
 		sb_start_pagefault(sb);
-- 
2.14.1.480.gb18f417b89-goog

^ permalink raw reply related	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2017-08-31 13:09 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-22 22:24 [PATCH] Fix ext4 fault handling when mounted with -o dax,ro Randy Dodgen
2017-08-23  3:37 ` [PATCH v2] " rdodgen
2017-08-23  3:37   ` rdodgen
2017-08-23 16:38   ` Ross Zwisler
2017-08-23 16:38     ` Ross Zwisler
2017-08-23 20:11     ` Randy Dodgen
2017-08-23 20:11       ` Randy Dodgen
2017-08-23 21:26       ` [PATCH v3] " rdodgen
2017-08-23 21:26         ` rdodgen
2017-08-24 14:45         ` Jan Kara
2017-08-24 14:45           ` Jan Kara
2017-08-24 15:11         ` Ross Zwisler
2017-08-24 15:11           ` Ross Zwisler
2017-08-24 16:01         ` Christoph Hellwig
2017-08-24 16:01           ` Christoph Hellwig
2017-08-24 20:57           ` Theodore Ts'o
2017-08-24 20:57             ` Theodore Ts'o
2017-08-25  7:28             ` Christoph Hellwig
2017-08-25  7:28               ` Christoph Hellwig
2017-08-29 21:20           ` Christoph Hellwig
2017-08-29 21:20             ` Christoph Hellwig
2017-08-29 21:37             ` Ross Zwisler
2017-08-29 21:37               ` Ross Zwisler
2017-08-29 22:07               ` Randy Dodgen
2017-08-29 22:07                 ` Randy Dodgen
2017-08-29 22:37               ` [fstests PATCH] generic: add test for executables on read-only DAX mounts Ross Zwisler
2017-08-29 22:37                 ` Ross Zwisler
2017-08-30 10:59                 ` Eryu Guan
2017-08-30 10:59                   ` Eryu Guan
2017-08-31  4:01                   ` Ross Zwisler
2017-08-31  4:01                     ` Ross Zwisler
2017-08-31  4:01                     ` Ross Zwisler
2017-08-31  4:09                   ` [fstests v2] " Ross Zwisler
2017-08-31  4:09                     ` Ross Zwisler
2017-08-30 14:51                 ` [fstests PATCH] " Christoph Hellwig
2017-08-30 14:51                   ` Christoph Hellwig
2017-08-30 14:51                   ` Christoph Hellwig
2017-08-31  4:02                   ` Ross Zwisler
2017-08-31  4:02                     ` Ross Zwisler
2017-08-31  4:02                     ` Ross Zwisler
2017-08-31 13:09                     ` Christoph Hellwig
2017-08-31 13:09                       ` Christoph Hellwig
2017-08-24 19:26         ` [PATCH v3] Fix ext4 fault handling when mounted with -o dax,ro Theodore Ts'o
2017-08-24 19:26           ` Theodore Ts'o

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.