All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrea Arcangeli <aarcange@redhat.com>
To: Nai Xia <nai.xia@gmail.com>
Cc: Hugh Dickins <hughd@google.com>, Mel Gorman <mgorman@suse.de>,
	Pawel Sikora <pluto@agmk.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, jpiszcz@lucidpixels.com, arekm@pld-linux.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mremap: enforce rmap src/dst vma ordering in case of vma_merge succeeding in copy_vma
Date: Fri, 18 Nov 2011 03:17:14 +0100	[thread overview]
Message-ID: <20111118021714.GP3306@redhat.com> (raw)
In-Reply-To: <CAPQyPG7MvO8Qw3jrOMShQcG5Z-RwbzpKnu-AheoS6aRYNhW14w@mail.gmail.com>

On Fri, Nov 18, 2011 at 09:42:05AM +0800, Nai Xia wrote:
> First of all, I believe that at the POSIX level, it's ok for
> truncate_inode_page()
> not scanning  COWed pages, since basically we does not provide any guarantee
> for privately mapped file pages for this behavior. But missing a file
> mapped pte after its
> cache page is already removed from the the page cache is a

I also exclude there is a case that would break, but it's safer to
keep things as is, in case somebody depends on segfault trapping.

> fundermental malfuntion for
> a shared mapping when some threads see the file cache page is gone
> while some thread
> is still r/w from/to it! No matter how short the gap between
> truncate_inode_page() and
> the second loop, this is wrong.

Truncate will destroy the info on disk too... so if somebody is
writing to a mapping which points beyond the end of the i_size
concurrently with truncate, the result is undefined. The write may
well reach the page but then the page is discared. Or you may get
SIGBUS before the write.

> Second, even if the we don't care about this POSIX flaw that may
> introduce, a pte can still
> missed by the second loop. mremap can happen serveral times during
> these non-atomic
> firstpass-trunc-secondpass operations, a proper events can happily
> make the wrong order
> for every scan, and miss them all -- That's just what in Hugh's mind
> in the post you just
> replied. Without lock and proper ordering( which patial mremap cannot provide),
> this *will* happen.

There won't be more than one mremap running concurrently from the same
process (we must enforce it by making sure anon_vma lock and
i_mmap_lock are both taken at least once in copy_vma, they're already
both taken in fork, they should already be taken in all common cases
in copy_vma so for all cases it's going to be a L1 exclusive cacheline
already). I don't exclude there may be some case that won't take the
locks in vma_adjust though, we should check it, if we decide to relay
on the double loop, but it'd be a simple addition if needed.

I'm more concerned about the pte pointing to the orphaned pagecache
that would materialize for a little while because of
unmap+truncate+unmap instead of unmap+unmap+truncate (but the latter
order is needed for the COWs).

> You may disagree with me and have that locking removed, and I am
> already have that
> one line patch prepared waiting fora bug bumpping up again, what a
> cheap patch submission!

Well I'm not yet sure it's good idea to remove the i_mmap_mutex, or if
we should just add the anon_vma lock in mremap and add the i_mmap_lock
in fork (to avoid the orphaned pagecache left mapped in the child
which already may happen unless there's some i_mmap_lock belonging to
the same inode taken after copy_page_range returns until we return to
userland and child can run, and I don't think we can relay on the
order of the prio tree in fork. Fork is safe for anon pages because
there we can relay on the order of the same_anon_vma list.

I think clearing up if this orphaned pagecache is dangerous would be a
good start. If too complex we just add the i_mmap_lock around
copy_page_range in fork if vma->vm_file is set. If you instead think
we can deal with the orphaned pagecache we can add a dummy lock/unlock
of i_mmap_mutex in copy_vma vma_merge succeeding case (short critical
section and not common common case) and remove the i_mmap_mutex around
move_page_tables (common case) overall speeding up mremap and not
degrading fork.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: Andrea Arcangeli <aarcange@redhat.com>
To: Nai Xia <nai.xia@gmail.com>
Cc: Hugh Dickins <hughd@google.com>, Mel Gorman <mgorman@suse.de>,
	Pawel Sikora <pluto@agmk.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, jpiszcz@lucidpixels.com, arekm@pld-linux.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mremap: enforce rmap src/dst vma ordering in case of vma_merge succeeding in copy_vma
Date: Fri, 18 Nov 2011 03:17:14 +0100	[thread overview]
Message-ID: <20111118021714.GP3306@redhat.com> (raw)
In-Reply-To: <CAPQyPG7MvO8Qw3jrOMShQcG5Z-RwbzpKnu-AheoS6aRYNhW14w@mail.gmail.com>

On Fri, Nov 18, 2011 at 09:42:05AM +0800, Nai Xia wrote:
> First of all, I believe that at the POSIX level, it's ok for
> truncate_inode_page()
> not scanning  COWed pages, since basically we does not provide any guarantee
> for privately mapped file pages for this behavior. But missing a file
> mapped pte after its
> cache page is already removed from the the page cache is a

I also exclude there is a case that would break, but it's safer to
keep things as is, in case somebody depends on segfault trapping.

> fundermental malfuntion for
> a shared mapping when some threads see the file cache page is gone
> while some thread
> is still r/w from/to it! No matter how short the gap between
> truncate_inode_page() and
> the second loop, this is wrong.

Truncate will destroy the info on disk too... so if somebody is
writing to a mapping which points beyond the end of the i_size
concurrently with truncate, the result is undefined. The write may
well reach the page but then the page is discared. Or you may get
SIGBUS before the write.

> Second, even if the we don't care about this POSIX flaw that may
> introduce, a pte can still
> missed by the second loop. mremap can happen serveral times during
> these non-atomic
> firstpass-trunc-secondpass operations, a proper events can happily
> make the wrong order
> for every scan, and miss them all -- That's just what in Hugh's mind
> in the post you just
> replied. Without lock and proper ordering( which patial mremap cannot provide),
> this *will* happen.

There won't be more than one mremap running concurrently from the same
process (we must enforce it by making sure anon_vma lock and
i_mmap_lock are both taken at least once in copy_vma, they're already
both taken in fork, they should already be taken in all common cases
in copy_vma so for all cases it's going to be a L1 exclusive cacheline
already). I don't exclude there may be some case that won't take the
locks in vma_adjust though, we should check it, if we decide to relay
on the double loop, but it'd be a simple addition if needed.

I'm more concerned about the pte pointing to the orphaned pagecache
that would materialize for a little while because of
unmap+truncate+unmap instead of unmap+unmap+truncate (but the latter
order is needed for the COWs).

> You may disagree with me and have that locking removed, and I am
> already have that
> one line patch prepared waiting fora bug bumpping up again, what a
> cheap patch submission!

Well I'm not yet sure it's good idea to remove the i_mmap_mutex, or if
we should just add the anon_vma lock in mremap and add the i_mmap_lock
in fork (to avoid the orphaned pagecache left mapped in the child
which already may happen unless there's some i_mmap_lock belonging to
the same inode taken after copy_page_range returns until we return to
userland and child can run, and I don't think we can relay on the
order of the prio tree in fork. Fork is safe for anon pages because
there we can relay on the order of the same_anon_vma list.

I think clearing up if this orphaned pagecache is dangerous would be a
good start. If too complex we just add the i_mmap_lock around
copy_page_range in fork if vma->vm_file is set. If you instead think
we can deal with the orphaned pagecache we can add a dummy lock/unlock
of i_mmap_mutex in copy_vma vma_merge succeeding case (short critical
section and not common common case) and remove the i_mmap_mutex around
move_page_tables (common case) overall speeding up mremap and not
degrading fork.

  reply	other threads:[~2011-11-18  2:17 UTC|newest]

Thread overview: 137+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-12 18:12 kernel 3.0: BUG: soft lockup: find_get_pages+0x51/0x110 Paweł Sikora
2011-10-13 23:16 ` Hugh Dickins
2011-10-13 23:30   ` Hugh Dickins
2011-10-13 23:30     ` Hugh Dickins
2011-10-16 16:11     ` Christoph Hellwig
2011-10-16 16:11       ` Christoph Hellwig
2011-10-16 23:54     ` Andrea Arcangeli
2011-10-16 23:54       ` Andrea Arcangeli
2011-10-17 18:51       ` Hugh Dickins
2011-10-17 18:51         ` Hugh Dickins
2011-10-17 22:05         ` Andrea Arcangeli
2011-10-17 22:05           ` Andrea Arcangeli
2011-10-19  7:43         ` Mel Gorman
2011-10-19  7:43           ` Mel Gorman
2011-10-19 13:39           ` Linus Torvalds
2011-10-19 13:39             ` Linus Torvalds
2011-10-19 19:42             ` Hugh Dickins
2011-10-19 19:42               ` Hugh Dickins
2011-10-20  6:30               ` Paweł Sikora
2011-10-20  6:30                 ` Paweł Sikora
2011-10-20  6:51                 ` Linus Torvalds
2011-10-20  6:51                   ` Linus Torvalds
2011-10-21  6:54                 ` Nai Xia
2011-10-21  6:54                   ` Nai Xia
2011-10-21  7:35                   ` Pawel Sikora
2011-10-21  7:35                     ` Pawel Sikora
2011-10-20 12:51               ` Nai Xia
2011-10-20 12:51                 ` Nai Xia
2011-10-20 18:36                 ` Hugh Dickins
2011-10-21  6:22                   ` Nai Xia
2011-10-21  6:22                     ` Nai Xia
2011-10-21  8:07                     ` Pawel Sikora
2011-10-21  8:07                       ` Pawel Sikora
2011-10-21  9:07                       ` Nai Xia
2011-10-21  9:07                         ` Nai Xia
2011-10-21 21:36                         ` Paweł Sikora
2011-10-21 21:36                           ` Paweł Sikora
2011-10-22  6:21                           ` Nai Xia
2011-10-22  6:21                             ` Nai Xia
2011-10-22 16:42                             ` Paweł Sikora
2011-10-22 16:42                               ` Paweł Sikora
     [not found]                               ` <CAPQyPG5HJKTo8AEy_khdJeciTgtNQepK6XLcpzvPF8PYS0V-Lw@mail.gmail.com>
2011-10-25  7:33                                 ` Pawel Sikora
2011-10-20  9:11       ` Nai Xia
2011-10-20  9:11         ` Nai Xia
2011-10-21 15:56         ` Mel Gorman
2011-10-21 15:56           ` Mel Gorman
2011-10-21 17:21           ` Nai Xia
2011-10-21 17:21             ` Nai Xia
2011-10-21 17:41           ` Andrea Arcangeli
2011-10-21 17:41             ` Andrea Arcangeli
2011-10-21 22:50             ` Andrea Arcangeli
2011-10-21 22:50               ` Andrea Arcangeli
2011-10-22  5:52               ` Nai Xia
2011-10-22  5:52                 ` Nai Xia
2011-10-31 17:14                 ` Andrea Arcangeli
2011-10-31 17:14                   ` Andrea Arcangeli
2011-10-31 17:27                   ` [PATCH] mremap: enforce rmap src/dst vma ordering in case of vma_merge succeeding in copy_vma Andrea Arcangeli
2011-10-31 17:27                     ` Andrea Arcangeli
2011-11-01 12:07                     ` Mel Gorman
2011-11-01 12:07                       ` Mel Gorman
2011-11-01 14:35                     ` Nai Xia
2011-11-01 14:35                       ` Nai Xia
2011-11-04  7:31                     ` Hugh Dickins
2011-11-04  7:31                       ` Hugh Dickins
2011-11-04 14:34                       ` Nai Xia
2011-11-04 14:34                         ` Nai Xia
2011-11-04 15:59                         ` Pawel Sikora
2011-11-04 15:59                           ` Pawel Sikora
2011-11-05  2:21                           ` Nai Xia
2011-11-05  2:21                             ` Nai Xia
2011-11-04 19:16                         ` Hugh Dickins
2011-11-04 20:54                           ` Andrea Arcangeli
2011-11-04 20:54                             ` Andrea Arcangeli
2011-11-05  0:09                             ` Nai Xia
2011-11-05  0:09                               ` Nai Xia
2011-11-05  2:21                               ` Hugh Dickins
2011-11-05  3:07                                 ` Andrea Arcangeli
2011-11-05  3:07                                   ` Andrea Arcangeli
2011-11-05 17:06                                 ` Andrea Arcangeli
2011-11-05 17:06                                   ` Andrea Arcangeli
2011-12-08  3:24                                   ` David Rientjes
2011-12-08  3:24                                     ` David Rientjes
2011-12-08 12:42                                     ` Andrea Arcangeli
2011-12-08 12:42                                       ` Andrea Arcangeli
2011-12-09  0:08                                   ` Andrew Morton
2011-12-09  0:08                                     ` Andrew Morton
2011-12-09  1:55                                     ` Andrea Arcangeli
2011-12-09  1:55                                       ` Andrea Arcangeli
2011-11-04 23:56                       ` Andrea Arcangeli
2011-11-04 23:56                         ` Andrea Arcangeli
2011-11-05  0:21                         ` Nai Xia
2011-11-05  0:21                           ` Nai Xia
2011-11-05  0:59                           ` Nai Xia
2011-11-05  0:59                             ` Nai Xia
2011-11-05  1:33                           ` Andrea Arcangeli
2011-11-05  1:33                             ` Andrea Arcangeli
2011-11-05  2:00                             ` Nai Xia
2011-11-05  2:00                               ` Nai Xia
2011-11-07 13:14                               ` Mel Gorman
2011-11-07 13:14                                 ` Mel Gorman
2011-11-07 15:42                                 ` Andrea Arcangeli
2011-11-07 15:42                                   ` Andrea Arcangeli
2011-11-07 16:28                                   ` Mel Gorman
2011-11-07 16:28                                     ` Mel Gorman
2011-11-09  1:25                                     ` Andrea Arcangeli
2011-11-09  1:25                                       ` Andrea Arcangeli
2011-11-11  9:14                                       ` Nai Xia
2011-11-11  9:14                                         ` Nai Xia
2011-11-16 14:00                                       ` Andrea Arcangeli
2011-11-16 14:00                                         ` Andrea Arcangeli
2011-11-17  0:16                                         ` Hugh Dickins
2011-11-17  0:16                                           ` Hugh Dickins
2011-11-17  2:49                                           ` Nai Xia
2011-11-17  2:49                                             ` Nai Xia
2011-11-17  6:21                                           ` Nai Xia
2011-11-17  6:21                                             ` Nai Xia
2011-11-17 18:42                                           ` Andrea Arcangeli
2011-11-17 18:42                                             ` Andrea Arcangeli
2011-11-18  1:42                                             ` Nai Xia
2011-11-18  1:42                                               ` Nai Xia
2011-11-18  2:17                                               ` Andrea Arcangeli [this message]
2011-11-18  2:17                                                 ` Andrea Arcangeli
2011-11-19  9:15                                                 ` Nai Xia
2011-11-19  9:15                                                   ` Nai Xia
2011-10-22  5:07             ` kernel 3.0: BUG: soft lockup: find_get_pages+0x51/0x110 Nai Xia
2011-10-22  5:07               ` Nai Xia
2011-10-31 16:34               ` Andrea Arcangeli
2011-10-31 16:34                 ` Andrea Arcangeli
2011-10-16 22:37   ` Linus Torvalds
2011-10-16 22:37     ` Linus Torvalds
2011-10-17  3:02     ` Hugh Dickins
2011-10-17  3:02       ` Hugh Dickins
2011-10-17  3:09       ` Linus Torvalds
2011-10-17  3:09         ` Linus Torvalds
2011-10-18 19:17   ` Paweł Sikora
2011-10-19  7:30   ` Mel Gorman
2011-10-21 12:44     ` Mel Gorman

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=20111118021714.GP3306@redhat.com \
    --to=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=arekm@pld-linux.org \
    --cc=hughd@google.com \
    --cc=jpiszcz@lucidpixels.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=nai.xia@gmail.com \
    --cc=pluto@agmk.net \
    /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.