From: Andrew Morton <akpm@linux-foundation.org>
To: Nick Piggin <npiggin@suse.de>
Cc: Hugh Dickins <hugh@veritas.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linux Memory Management List <linux-mm@kvack.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [patch] mm: dirty page tracking race fix
Date: Tue, 19 Aug 2008 02:11:55 -0700 [thread overview]
Message-ID: <20080819021155.3d92b193.akpm@linux-foundation.org> (raw)
In-Reply-To: <20080818053821.GA3011@wotan.suse.de>
On Mon, 18 Aug 2008 07:38:21 +0200 Nick Piggin <npiggin@suse.de> wrote:
> There is a race with dirty page accounting where a page may not properly
> be accounted for.
>
> clear_page_dirty_for_io() calls page_mkclean; then TestClearPageDirty.
>
> page_mkclean walks the rmaps for that page, and for each one it cleans and
> write protects the pte if it was dirty. It uses page_check_address to find the
> pte. That function has a shortcut to avoid the ptl if the pte is not
> present. Unfortunately, the pte can be switched to not-present then back to
> present by other code while holding the page table lock -- this should not
> be a signal for page_mkclean to ignore that pte, because it may be dirty.
>
> For example, powerpc64's set_pte_at will clear a previously present pte before
> setting it to the desired value. There may also be other code in core mm or
> in arch which do similar things.
>
> The consequence of the bug is loss of data integrity due to msync, and loss
> of dirty page accounting accuracy. XIP's __xip_unmap could easily also be
> unreliable (depending on the exact XIP locking scheme), which can lead to data
> corruption.
>
> Fix this by having an option to always take ptl to check the pte in
> page_check_address.
>
> It's possible to retain this optimization for page_referenced and
> try_to_unmap.
Is it also possible to retain it for
/**
* page_mapped_in_vma - check whether a page is really mapped in a VMA
* @page: the page to test
* @vma: the VMA to test
*
* Returns 1 if the page is mapped into the page tables of the VMA, 0
* if the page is not mapped into the page tables of this VMA. Only
* valid for normal file or anonymous VMAs.
*/
static int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma)
{
unsigned long address;
pte_t *pte;
spinlock_t *ptl;
address = vma_address(page, vma);
if (address == -EFAULT) /* out of vma range */
return 0;
pte = page_check_address(page, vma->vm_mm, address, &ptl);
if (!pte) /* the page is not in this mm */
return 0;
pte_unmap_unlock(pte, ptl);
return 1;
}
?
WARNING: multiple messages have this Message-ID (diff)
From: Andrew Morton <akpm@linux-foundation.org>
To: Nick Piggin <npiggin@suse.de>
Cc: Hugh Dickins <hugh@veritas.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linux Memory Management List <linux-mm@kvack.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [patch] mm: dirty page tracking race fix
Date: Tue, 19 Aug 2008 02:11:55 -0700 [thread overview]
Message-ID: <20080819021155.3d92b193.akpm@linux-foundation.org> (raw)
In-Reply-To: <20080818053821.GA3011@wotan.suse.de>
On Mon, 18 Aug 2008 07:38:21 +0200 Nick Piggin <npiggin@suse.de> wrote:
> There is a race with dirty page accounting where a page may not properly
> be accounted for.
>
> clear_page_dirty_for_io() calls page_mkclean; then TestClearPageDirty.
>
> page_mkclean walks the rmaps for that page, and for each one it cleans and
> write protects the pte if it was dirty. It uses page_check_address to find the
> pte. That function has a shortcut to avoid the ptl if the pte is not
> present. Unfortunately, the pte can be switched to not-present then back to
> present by other code while holding the page table lock -- this should not
> be a signal for page_mkclean to ignore that pte, because it may be dirty.
>
> For example, powerpc64's set_pte_at will clear a previously present pte before
> setting it to the desired value. There may also be other code in core mm or
> in arch which do similar things.
>
> The consequence of the bug is loss of data integrity due to msync, and loss
> of dirty page accounting accuracy. XIP's __xip_unmap could easily also be
> unreliable (depending on the exact XIP locking scheme), which can lead to data
> corruption.
>
> Fix this by having an option to always take ptl to check the pte in
> page_check_address.
>
> It's possible to retain this optimization for page_referenced and
> try_to_unmap.
Is it also possible to retain it for
/**
* page_mapped_in_vma - check whether a page is really mapped in a VMA
* @page: the page to test
* @vma: the VMA to test
*
* Returns 1 if the page is mapped into the page tables of the VMA, 0
* if the page is not mapped into the page tables of this VMA. Only
* valid for normal file or anonymous VMAs.
*/
static int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma)
{
unsigned long address;
pte_t *pte;
spinlock_t *ptl;
address = vma_address(page, vma);
if (address == -EFAULT) /* out of vma range */
return 0;
pte = page_check_address(page, vma->vm_mm, address, &ptl);
if (!pte) /* the page is not in this mm */
return 0;
pte_unmap_unlock(pte, ptl);
return 1;
}
?
--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2008-08-19 9:12 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-18 5:38 [patch] mm: dirty page tracking race fix Nick Piggin
2008-08-18 5:38 ` Nick Piggin
2008-08-18 5:44 ` [patch] mm: xip fix fault vs sparse page invalidate race Nick Piggin
2008-08-18 5:44 ` Nick Piggin
2008-08-18 6:03 ` [patch] mm: xip/ext2 fix block allocation race Nick Piggin
2008-08-18 6:03 ` Nick Piggin
2008-08-18 10:51 ` Carsten Otte
2008-08-18 10:51 ` Carsten Otte
2008-08-18 10:50 ` [patch] mm: xip fix fault vs sparse page invalidate race Carsten Otte
2008-08-18 10:50 ` Carsten Otte
2008-08-18 7:49 ` [patch] mm: dirty page tracking race fix Peter Zijlstra
2008-08-18 7:49 ` Peter Zijlstra
2008-08-18 8:03 ` Nick Piggin
2008-08-18 8:03 ` Nick Piggin
2008-08-18 8:07 ` Peter Zijlstra
2008-08-18 8:07 ` Peter Zijlstra
2008-08-18 8:12 ` Nick Piggin
2008-08-18 8:12 ` Nick Piggin
2008-08-19 9:11 ` Andrew Morton [this message]
2008-08-19 9:11 ` Andrew Morton
2008-08-19 10:19 ` Nick Piggin
2008-08-19 10:19 ` Nick Piggin
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=20080819021155.3d92b193.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=a.p.zijlstra@chello.nl \
--cc=hugh@veritas.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=npiggin@suse.de \
--cc=torvalds@linux-foundation.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.