From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Jan Kara <jack@suse.cz>, Dave Chinner <dchinner@redhat.com>,
Jann Horn <jannh@google.com>, Christoph Hellwig <hch@lst.de>,
Oleg Nesterov <oleg@redhat.com>,
Kirill Shutemov <kirill@shutemov.name>,
"Theodore Ts'o" <tytso@mit.edu>,
Andrea Arcangeli <aarcange@redhat.com>,
Matthew Wilcox <willy@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
Dan Williams <dan.j.williams@intel.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-nvdimm@lists.01.org, linux-ext4@vger.kernel.org,
linux-xfs@vger.kernel.org, Eric Sandeen <sandeen@redhat.com>
Subject: Re: [PATCH 2/2] xfs: don't update mtime on COW faults
Date: Wed, 9 Sep 2020 23:06:26 -0700 [thread overview]
Message-ID: <20200910060626.GA7964@magnolia> (raw)
In-Reply-To: <alpine.LRH.2.02.2009051229180.542@file01.intranet.prod.int.rdu2.redhat.com>
On Sat, Sep 05, 2020 at 01:02:33PM -0400, Mikulas Patocka wrote:
>
>
> On Sat, 5 Sep 2020, Darrick J. Wong wrote:
>
> > On Sat, Sep 05, 2020 at 08:13:02AM -0400, Mikulas Patocka wrote:
> > > When running in a dax mode, if the user maps a page with MAP_PRIVATE and
> > > PROT_WRITE, the xfs filesystem would incorrectly update ctime and mtime
> > > when the user hits a COW fault.
> > >
> > > This breaks building of the Linux kernel.
> > > How to reproduce:
> > > 1. extract the Linux kernel tree on dax-mounted xfs filesystem
> > > 2. run make clean
> > > 3. run make -j12
> > > 4. run make -j12
> > > - at step 4, make would incorrectly rebuild the whole kernel (although it
> > > was already built in step 3).
> > >
> > > The reason for the breakage is that almost all object files depend on
> > > objtool. When we run objtool, it takes COW page fault on its .data
> > > section, and these faults will incorrectly update the timestamp of the
> > > objtool binary. The updated timestamp causes make to rebuild the whole
> > > tree.
> > >
> > > Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> > > Cc: stable@vger.kernel.org
> > >
> > > ---
> > > fs/xfs/xfs_file.c | 11 +++++++++--
> > > 1 file changed, 9 insertions(+), 2 deletions(-)
> > >
> > > Index: linux-2.6/fs/xfs/xfs_file.c
> > > ===================================================================
> > > --- linux-2.6.orig/fs/xfs/xfs_file.c 2020-09-05 10:01:42.000000000 +0200
> > > +++ linux-2.6/fs/xfs/xfs_file.c 2020-09-05 13:59:12.000000000 +0200
> > > @@ -1223,6 +1223,13 @@ __xfs_filemap_fault(
> > > return ret;
> > > }
> > >
> > > +static bool
> > > +xfs_is_write_fault(
> >
> > Call this xfs_is_shared_dax_write_fault, and throw in the IS_DAX() test?
> >
> > You might as well make it a static inline.
>
> Yes, it is possible. I'll send a second version.
>
> > > + struct vm_fault *vmf)
> > > +{
> > > + return vmf->flags & FAULT_FLAG_WRITE && vmf->vma->vm_flags & VM_SHARED;
> >
> > Also, is "shortcutting the normal fault path" the reason for ext2 and
> > xfs both being broken?
> >
> > /me puzzles over why write_fault is always true for page_mkwrite and
> > pfn_mkwrite, but not for fault and huge_fault...
> >
> > Also: Can you please turn this (checking for timestamp update behavior
> > wrt shared and private mapping write faults) into an fstest so we don't
> > mess this up again?
>
> I've written this program that tests it - you can integrate it into your
> testsuite.
I don't get it. You're a filesystem maintainer too, which means you're
a regular contributor. Do you:
(a) not use fstests? If you don't, I really hope you use something else
to QA hpfs.
(b) really think that it's my problem to integrate and submit your
regression tests for you?
> Mikulas
>
>
> #include <stdio.h>
and (c) what do you want me to do with a piece of code that has no
signoff tag, no copyright, and no license? This is your patch, and
therefore your responsibility to develop enough of an appropriate
regression test in a proper form that the rest of us can easily
determine we have the rights to contribute to it.
I don't have a problem with helping to tweak a properly licensed and
tagged test program into fstests, but this is a non-starter.
--D
> #include <stdlib.h>
> #include <unistd.h>
> #include <fcntl.h>
> #include <string.h>
> #include <sys/mman.h>
> #include <sys/stat.h>
>
> #define FILE_NAME "test.txt"
>
> static struct stat st1, st2;
>
> int main(void)
> {
> int h, r;
> char *map;
> unlink(FILE_NAME);
> h = creat(FILE_NAME, 0600);
> if (h == -1) perror("creat"), exit(1);
> r = write(h, "x", 1);
> if (r != 1) perror("write"), exit(1);
> if (close(h)) perror("close"), exit(1);
> h = open(FILE_NAME, O_RDWR);
> if (h == -1) perror("open"), exit(1);
>
> map = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE, h, 0);
> if (map == MAP_FAILED) perror("mmap"), exit(1);
> if (fstat(h, &st1)) perror("fstat"), exit(1);
> sleep(2);
> *map = 'y';
> if (fstat(h, &st2)) perror("fstat"), exit(1);
> if (memcmp(&st1, &st2, sizeof(struct stat))) fprintf(stderr, "BUG: COW fault changed time!\n"), exit(1);
> if (munmap(map, 4096)) perror("munmap"), exit(1);
>
> map = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, h, 0);
> if (map == MAP_FAILED) perror("mmap"), exit(1);
> if (fstat(h, &st1)) perror("fstat"), exit(1);
> sleep(2);
> *map = 'z';
> if (fstat(h, &st2)) perror("fstat"), exit(1);
> if (st1.st_mtime == st2.st_mtime) fprintf(stderr, "BUG: Shared fault did not change mtime!\n"), exit(1);
> if (st1.st_ctime == st2.st_ctime) fprintf(stderr, "BUG: Shared fault did not change ctime!\n"), exit(1);
> if (munmap(map, 4096)) perror("munmap"), exit(1);
>
> if (close(h)) perror("close"), exit(1);
> if (unlink(FILE_NAME)) perror("unlink"), exit(1);
> return 0;
> }
>
WARNING: multiple messages have this Message-ID (diff)
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Jan Kara <jack@suse.cz>, Dave Chinner <dchinner@redhat.com>,
Jann Horn <jannh@google.com>, Christoph Hellwig <hch@lst.de>,
Oleg Nesterov <oleg@redhat.com>,
Kirill Shutemov <kirill@shutemov.name>,
Theodore Ts'o <tytso@mit.edu>,
Andrea Arcangeli <aarcange@redhat.com>,
Matthew Wilcox <willy@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-nvdimm@lists.01.org, linux-ext4@vger.kernel.org,
linux-xfs@vger.kernel.org, Eric Sandeen <sandeen@redhat.com>
Subject: Re: [PATCH 2/2] xfs: don't update mtime on COW faults
Date: Wed, 9 Sep 2020 23:06:26 -0700 [thread overview]
Message-ID: <20200910060626.GA7964@magnolia> (raw)
In-Reply-To: <alpine.LRH.2.02.2009051229180.542@file01.intranet.prod.int.rdu2.redhat.com>
On Sat, Sep 05, 2020 at 01:02:33PM -0400, Mikulas Patocka wrote:
>
>
> On Sat, 5 Sep 2020, Darrick J. Wong wrote:
>
> > On Sat, Sep 05, 2020 at 08:13:02AM -0400, Mikulas Patocka wrote:
> > > When running in a dax mode, if the user maps a page with MAP_PRIVATE and
> > > PROT_WRITE, the xfs filesystem would incorrectly update ctime and mtime
> > > when the user hits a COW fault.
> > >
> > > This breaks building of the Linux kernel.
> > > How to reproduce:
> > > 1. extract the Linux kernel tree on dax-mounted xfs filesystem
> > > 2. run make clean
> > > 3. run make -j12
> > > 4. run make -j12
> > > - at step 4, make would incorrectly rebuild the whole kernel (although it
> > > was already built in step 3).
> > >
> > > The reason for the breakage is that almost all object files depend on
> > > objtool. When we run objtool, it takes COW page fault on its .data
> > > section, and these faults will incorrectly update the timestamp of the
> > > objtool binary. The updated timestamp causes make to rebuild the whole
> > > tree.
> > >
> > > Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> > > Cc: stable@vger.kernel.org
> > >
> > > ---
> > > fs/xfs/xfs_file.c | 11 +++++++++--
> > > 1 file changed, 9 insertions(+), 2 deletions(-)
> > >
> > > Index: linux-2.6/fs/xfs/xfs_file.c
> > > ===================================================================
> > > --- linux-2.6.orig/fs/xfs/xfs_file.c 2020-09-05 10:01:42.000000000 +0200
> > > +++ linux-2.6/fs/xfs/xfs_file.c 2020-09-05 13:59:12.000000000 +0200
> > > @@ -1223,6 +1223,13 @@ __xfs_filemap_fault(
> > > return ret;
> > > }
> > >
> > > +static bool
> > > +xfs_is_write_fault(
> >
> > Call this xfs_is_shared_dax_write_fault, and throw in the IS_DAX() test?
> >
> > You might as well make it a static inline.
>
> Yes, it is possible. I'll send a second version.
>
> > > + struct vm_fault *vmf)
> > > +{
> > > + return vmf->flags & FAULT_FLAG_WRITE && vmf->vma->vm_flags & VM_SHARED;
> >
> > Also, is "shortcutting the normal fault path" the reason for ext2 and
> > xfs both being broken?
> >
> > /me puzzles over why write_fault is always true for page_mkwrite and
> > pfn_mkwrite, but not for fault and huge_fault...
> >
> > Also: Can you please turn this (checking for timestamp update behavior
> > wrt shared and private mapping write faults) into an fstest so we don't
> > mess this up again?
>
> I've written this program that tests it - you can integrate it into your
> testsuite.
I don't get it. You're a filesystem maintainer too, which means you're
a regular contributor. Do you:
(a) not use fstests? If you don't, I really hope you use something else
to QA hpfs.
(b) really think that it's my problem to integrate and submit your
regression tests for you?
> Mikulas
>
>
> #include <stdio.h>
and (c) what do you want me to do with a piece of code that has no
signoff tag, no copyright, and no license? This is your patch, and
therefore your responsibility to develop enough of an appropriate
regression test in a proper form that the rest of us can easily
determine we have the rights to contribute to it.
I don't have a problem with helping to tweak a properly licensed and
tagged test program into fstests, but this is a non-starter.
--D
> #include <stdlib.h>
> #include <unistd.h>
> #include <fcntl.h>
> #include <string.h>
> #include <sys/mman.h>
> #include <sys/stat.h>
>
> #define FILE_NAME "test.txt"
>
> static struct stat st1, st2;
>
> int main(void)
> {
> int h, r;
> char *map;
> unlink(FILE_NAME);
> h = creat(FILE_NAME, 0600);
> if (h == -1) perror("creat"), exit(1);
> r = write(h, "x", 1);
> if (r != 1) perror("write"), exit(1);
> if (close(h)) perror("close"), exit(1);
> h = open(FILE_NAME, O_RDWR);
> if (h == -1) perror("open"), exit(1);
>
> map = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE, h, 0);
> if (map == MAP_FAILED) perror("mmap"), exit(1);
> if (fstat(h, &st1)) perror("fstat"), exit(1);
> sleep(2);
> *map = 'y';
> if (fstat(h, &st2)) perror("fstat"), exit(1);
> if (memcmp(&st1, &st2, sizeof(struct stat))) fprintf(stderr, "BUG: COW fault changed time!\n"), exit(1);
> if (munmap(map, 4096)) perror("munmap"), exit(1);
>
> map = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, h, 0);
> if (map == MAP_FAILED) perror("mmap"), exit(1);
> if (fstat(h, &st1)) perror("fstat"), exit(1);
> sleep(2);
> *map = 'z';
> if (fstat(h, &st2)) perror("fstat"), exit(1);
> if (st1.st_mtime == st2.st_mtime) fprintf(stderr, "BUG: Shared fault did not change mtime!\n"), exit(1);
> if (st1.st_ctime == st2.st_ctime) fprintf(stderr, "BUG: Shared fault did not change ctime!\n"), exit(1);
> if (munmap(map, 4096)) perror("munmap"), exit(1);
>
> if (close(h)) perror("close"), exit(1);
> if (unlink(FILE_NAME)) perror("unlink"), exit(1);
> return 0;
> }
>
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
next prev parent reply other threads:[~2020-09-10 6:09 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-03 19:24 a crash when running strace from persistent memory Mikulas Patocka
2020-09-03 19:24 ` Mikulas Patocka
2020-09-03 19:55 ` Linus Torvalds
2020-09-03 19:55 ` Linus Torvalds
2020-09-04 8:08 ` Mikulas Patocka
2020-09-04 8:08 ` Mikulas Patocka
2020-09-04 17:11 ` Linus Torvalds
2020-09-04 17:11 ` Linus Torvalds
2020-09-04 16:21 ` make misbehavior on ext2 in dax mode (was: a crash when running strace from persistent memory) Mikulas Patocka
2020-09-04 16:21 ` Mikulas Patocka
2020-09-05 12:11 ` Mikulas Patocka
2020-09-05 12:11 ` Mikulas Patocka
2020-09-05 12:12 ` [PATCH 1/2] ext2: don't update mtime on COW faults Mikulas Patocka
2020-09-05 12:12 ` Mikulas Patocka
2020-09-07 9:00 ` Jan Kara
2020-09-07 9:00 ` Jan Kara
2020-09-07 15:03 ` Sasha Levin
2020-09-05 12:13 ` [PATCH 2/2] xfs: " Mikulas Patocka
2020-09-05 12:13 ` Mikulas Patocka
2020-09-05 15:36 ` Darrick J. Wong
2020-09-05 15:36 ` Darrick J. Wong
2020-09-05 17:02 ` Mikulas Patocka
2020-09-05 17:02 ` Mikulas Patocka
2020-09-10 6:06 ` Darrick J. Wong [this message]
2020-09-10 6:06 ` Darrick J. Wong
2020-09-11 16:41 ` Mikulas Patocka
2020-09-11 16:41 ` Mikulas Patocka
2020-09-05 16:47 ` Linus Torvalds
2020-09-05 16:47 ` Linus Torvalds
2020-09-05 17:03 ` Linus Torvalds
2020-09-05 17:03 ` Linus Torvalds
2020-09-07 8:59 ` Jan Kara
2020-09-07 8:59 ` Jan Kara
2020-09-05 17:04 ` [PATCH 2/2 v2] " Mikulas Patocka
2020-09-05 17:04 ` Mikulas Patocka
2020-09-07 6:47 ` [PATCH 2/2] " Christoph Hellwig
2020-09-07 6:47 ` Christoph Hellwig
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=20200910060626.GA7964@magnolia \
--to=darrick.wong@oracle.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dan.j.williams@intel.com \
--cc=dchinner@redhat.com \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=kirill@shutemov.name \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nvdimm@lists.01.org \
--cc=linux-xfs@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=oleg@redhat.com \
--cc=sandeen@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=willy@infradead.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 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.