linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Feiner <pfeiner@google.com>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Cyrill Gorcunov <gorcunov@openvz.org>,
	Pavel Emelyanov <xemul@parallels.com>,
	Jamie Liu <jamieliu@google.com>, Hugh Dickins <hughd@google.com>,
	Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Magnus Damm <damm@opensource.se>
Subject: Re: [PATCH] mm: softdirty: write protect PTEs created for read faults after VM_SOFTDIRTY cleared
Date: Thu, 21 Aug 2014 15:37:37 -0400	[thread overview]
Message-ID: <20140821193737.GC16042@google.com> (raw)
In-Reply-To: <20140820234543.GA7987@node.dhcp.inet.fi>

On Thu, Aug 21, 2014 at 02:45:43AM +0300, Kirill A. Shutemov wrote:
> On Wed, Aug 20, 2014 at 05:46:22PM -0400, Peter Feiner wrote:
> It basically means VM_SOFTDIRTY require writenotify on the vma.
> 
> What about patch below? Untested. And it seems it'll introduce bug similar
> to bug fixed by c9d0bf241451, *but* IIUC we have it already in mprotect()
> code path.
> 
> I'll look more careful tomorrow.
> 
> Not-signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> 
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index dfc791c42d64..67d509a15969 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -851,8 +851,9 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
>                         if (type == CLEAR_REFS_MAPPED && !vma->vm_file)
>                                 continue;
>                         if (type == CLEAR_REFS_SOFT_DIRTY) {
> -                               if (vma->vm_flags & VM_SOFTDIRTY)
> -                                       vma->vm_flags &= ~VM_SOFTDIRTY;
> +                               vma->vm_flags &= ~VM_SOFTDIRTY;
> +                               vma->vm_page_prot = vm_get_page_prot(
> +                                               vma->vm_flags & ~VM_SHARED);
>                         }
>                         walk_page_range(vma->vm_start, vma->vm_end,
>                                         &clear_refs_walk);
> -- 
>  Kirill A. Shutemov

Thanks Kirill, I prefer your approach. I'll send a v2.

I believe you're right about c9d0bf241451. It seems like passing the old & new
pgprot through pgprot_modify would handle the problem. Furthermore, as you
suggest, mprotect_fixup should use pgprot_modify when it turns write
notification on.  I think a patch like this is in order:

Not-signed-off-by: Peter Feiner <pfeiner@google.com>

diff --git a/mm/mmap.c b/mm/mmap.c
index c1f2ea4..86f89a1 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1611,18 +1611,15 @@ munmap_back:
 	}
 
 	if (vma_wants_writenotify(vma)) {
-		pgprot_t pprot = vma->vm_page_prot;
-
 		/* Can vma->vm_page_prot have changed??
 		 *
 		 * Answer: Yes, drivers may have changed it in their
 		 *         f_op->mmap method.
 		 *
-		 * Ensures that vmas marked as uncached stay that way.
+		 * Ensures that vmas marked with special bits stay that way.
 		 */
-		vma->vm_page_prot = vm_get_page_prot(vm_flags & ~VM_SHARED);
-		if (pgprot_val(pprot) == pgprot_val(pgprot_noncached(pprot)))
-			vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+		vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
+		                        vm_get_page_prot(vm_flags & ~VM_SHARED);
 	}
 
 	vma_link(mm, vma, prev, rb_link, rb_parent);
diff --git a/mm/mprotect.c b/mm/mprotect.c
index c43d557..6826313 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -324,7 +324,8 @@ success:
 					  vm_get_page_prot(newflags));
 
 	if (vma_wants_writenotify(vma)) {
-		vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
+		vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
+		                       vm_get_page_prot(newflags & ~VM_SHARED));
 		dirty_accountable = 1;
 	}
 

  reply	other threads:[~2014-08-21 19:37 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-20 21:46 [PATCH] mm: softdirty: write protect PTEs created for read faults after VM_SOFTDIRTY cleared Peter Feiner
2014-08-20 23:45 ` Kirill A. Shutemov
2014-08-21 19:37   ` Peter Feiner [this message]
2014-08-21 20:51     ` Cyrill Gorcunov
2014-08-21 21:39       ` Kirill A. Shutemov
2014-08-21 21:46         ` Peter Feiner
2014-08-21 21:51           ` Kirill A. Shutemov
2014-08-21 22:50             ` Peter Feiner
2014-08-22  6:33               ` Cyrill Gorcunov
2014-08-23 22:11 ` [PATCH v2 0/3] softdirty fix and write notification cleanup Peter Feiner
2014-08-23 22:11   ` [PATCH v2 1/3] mm: softdirty: enable write notifications on VMAs after VM_SOFTDIRTY cleared Peter Feiner
2014-08-23 23:00     ` Kirill A. Shutemov
2014-08-23 23:15       ` Peter Feiner
2014-08-23 23:50       ` Kirill A. Shutemov
2014-08-24  0:55         ` Peter Feiner
2014-08-23 22:12   ` [PATCH v2 2/3] mm: mprotect: preserve special page protection bits Peter Feiner
2014-08-23 22:12   ` [PATCH v2 3/3] mm: mmap: cleanup code that preserves special vm_page_prot bits Peter Feiner
2014-08-24  1:43 ` [PATCH v3] mm: softdirty: enable write notifications on VMAs after VM_SOFTDIRTY cleared Peter Feiner
2014-08-24  7:59   ` Kirill A. Shutemov
2014-08-24 19:22     ` Cyrill Gorcunov
2014-08-24 14:41 ` [PATCH v4] " Peter Feiner
2014-08-25  3:34 ` [PATCH v5] " Peter Feiner
2014-08-26  4:45   ` Hugh Dickins
2014-08-26  6:49     ` Cyrill Gorcunov
2014-08-26 14:04       ` Kirill A. Shutemov
2014-08-26 14:19         ` Cyrill Gorcunov
2014-08-26 14:56           ` Kirill A. Shutemov
2014-08-26 15:18             ` Cyrill Gorcunov
2014-08-26 15:43               ` Kirill A. Shutemov
2014-08-26 15:53                 ` Cyrill Gorcunov
2014-08-27 23:12                   ` Hugh Dickins
2014-08-28  6:31                     ` Cyrill Gorcunov
2014-08-27 21:55       ` Hugh Dickins
2014-09-04 16:43     ` Peter Feiner
2014-09-07 21:31       ` Peter Feiner
2014-09-07 23:01 ` [PATCH v6] " Peter Feiner

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=20140821193737.GC16042@google.com \
    --to=pfeiner@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=damm@opensource.se \
    --cc=gorcunov@openvz.org \
    --cc=hughd@google.com \
    --cc=jamieliu@google.com \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=n-horiguchi@ah.jp.nec.com \
    --cc=xemul@parallels.com \
    /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).