From: Ross Zwisler <ross.zwisler-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
To: rdodgen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-ext4-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
tytso-3s7WtUTddSA@public.gmane.org,
Randy Dodgen <dodgen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
linux-nvdimm-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org
Subject: Re: [PATCH v2] Fix ext4 fault handling when mounted with -o dax,ro
Date: Wed, 23 Aug 2017 10:38:26 -0600 [thread overview]
Message-ID: <20170823163826.GB25999@linux.intel.com> (raw)
In-Reply-To: <bea6897723e5bf09d893b2ca40263a894a284a5a.1503459187.git.dodgen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
On Tue, Aug 22, 2017 at 08:37:04PM -0700, rdodgen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:
> From: Randy Dodgen <dodgen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
>
> 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).
>
> Signed-off-by: Randy Dodgen <dodgen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
> ---
>
> I'm resending for some DMARC-proofing (thanks Ted for the explanation), a
> missing Signed-off-by, and some extra cc's. Oops!
>
> 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;
> + }
This works in my setup, though the logic could be simpler.
For all fault sizes you can rely on the fact that a COW write will happen when
we have FAULT_FLAG_WRITE but not VM_SHARED. This is the logic that we use to
know to set up vmf->cow_page() in do_fault() by calling do_cow_fault(), and in
finish_fault().
I think your test can then just become:
write = (vmf->flags & FAULT_FLAG_WRITE) &&
(vmf->vma->vm_flags & VM_SHARED);
With some appropriate commenting.
You can then let the DAX fault handlers worry about validating the fault size
and splitting the PMD on fallback.
I'll let someone with more ext4-fu comment on whether it is okay to skip the
journal entry when doing a COW fault. This must be handled in ext4 for the
non-DAX case, but I don't see any more checks for VM_SHARED or
FAULT_FLAG_WRITE in fs/ext4, so maybe there is a better way?
- Ross
next prev parent reply other threads:[~2017-08-23 16:38 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
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
[not found] ` <bea6897723e5bf09d893b2ca40263a894a284a5a.1503459187.git.dodgen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2017-08-23 16:38 ` Ross Zwisler [this message]
2017-08-23 20:11 ` Randy Dodgen
2017-08-23 21:26 ` [PATCH v3] " rdodgen
[not found] ` <416a465a9fbe1d27085883dbf652c115cd195697.1503523424.git.dodgen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2017-08-24 14:45 ` Jan Kara
2017-08-24 15:11 ` Ross Zwisler
2017-08-24 16:01 ` Christoph Hellwig
[not found] ` <20170824160144.GA14287-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2017-08-24 20:57 ` Theodore Ts'o
2017-08-25 7:28 ` Christoph Hellwig
2017-08-29 21:20 ` Christoph Hellwig
[not found] ` <20170829212002.GA2154-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2017-08-29 21:37 ` Ross Zwisler
[not found] ` <20170829213721.GA27686-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
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-30 10:59 ` Eryu Guan
[not found] ` <20170830105930.GE27835-+7p9VZFSOIEFmhoHi+V13ACJwEvxM/w9@public.gmane.org>
2017-08-31 4:01 ` Ross Zwisler
2017-08-31 4:09 ` [fstests v2] " Ross Zwisler
[not found] ` <20170829223715.26507-1-ross.zwisler-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-08-30 14:51 ` [fstests PATCH] " Christoph Hellwig
[not found] ` <20170830145103.GA10163-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2017-08-31 4:02 ` Ross Zwisler
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170823163826.GB25999@linux.intel.com \
--to=ross.zwisler-vuqaysv1563yd54fqh9/ca@public.gmane.org \
--cc=dodgen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=linux-ext4-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-nvdimm-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org \
--cc=rdodgen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=tytso-3s7WtUTddSA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).