All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <matthew@wil.cx>
To: Hugh Dickins <hugh@veritas.com>
Cc: Andrew Morton <akpm@osdl.org>,
	linux-kernel@vger.kernel.org, parisc-linux@parisc-linux.org
Subject: Re: [PATCH 3/9] mm: parisc pte atomicity
Date: Sat, 22 Oct 2005 10:33:30 -0600	[thread overview]
Message-ID: <20051022163330.GD3364@parisc-linux.org> (raw)
In-Reply-To: <Pine.LNX.4.61.0510221722260.18047@goblin.wat.veritas.com>

On Sat, Oct 22, 2005 at 05:23:27PM +0100, Hugh Dickins wrote:
> There's a worrying function translation_exists in parisc cacheflush.h,
> unaffected by split ptlock since flush_dcache_page is using it on some
> other mm, without any relevant lock.  Oh well, make it a slightly more
> robust by factoring the pfn check within it.  And it looked liable to
> confuse a camouflaged swap or file entry with a good pte: fix that too.

I have to say I really don't understand VM at all.  cc'ing the
parisc-linux list in case anyone there has a better understanding than I
do.

> Signed-off-by: Hugh Dickins <hugh@veritas.com>
> ---
> 
>  arch/parisc/kernel/cache.c      |   24 +++++++++---------------
>  include/asm-parisc/cacheflush.h |   35 +++++++++++++++++++----------------
>  2 files changed, 28 insertions(+), 31 deletions(-)
> 
> --- mm2/arch/parisc/kernel/cache.c	2005-03-02 07:38:56.000000000 +0000
> +++ mm3/arch/parisc/kernel/cache.c	2005-10-22 14:06:30.000000000 +0100
> @@ -266,7 +266,6 @@ void flush_dcache_page(struct page *page
>  	unsigned long offset;
>  	unsigned long addr;
>  	pgoff_t pgoff;
> -	pte_t *pte;
>  	unsigned long pfn = page_to_pfn(page);
>  
>  
> @@ -297,21 +296,16 @@ void flush_dcache_page(struct page *page
>  		 * taking a page fault if the pte doesn't exist.
>  		 * This is just for speed.  If the page translation
>  		 * isn't there, there's no point exciting the
> -		 * nadtlb handler into a nullification frenzy */
> -
> -
> -  		if(!(pte = translation_exists(mpnt, addr)))
> -			continue;
> -
> -		/* make sure we really have this page: the private
> +		 * nadtlb handler into a nullification frenzy.
> +		 *
> +		 * Make sure we really have this page: the private
>  		 * mappings may cover this area but have COW'd this
> -		 * particular page */
> -		if(pte_pfn(*pte) != pfn)
> -  			continue;
> -
> -		__flush_cache_page(mpnt, addr);
> -
> -		break;
> +		 * particular page.
> +		 */
> +  		if (translation_exists(mpnt, addr, pfn)) {
> +			__flush_cache_page(mpnt, addr);
> +			break;
> +		}
>  	}
>  	flush_dcache_mmap_unlock(mapping);
>  }
> --- mm2/include/asm-parisc/cacheflush.h	2005-10-11 12:07:49.000000000 +0100
> +++ mm3/include/asm-parisc/cacheflush.h	2005-10-22 14:06:30.000000000 +0100
> @@ -100,30 +100,34 @@ static inline void flush_cache_range(str
>  
>  /* Simple function to work out if we have an existing address translation
>   * for a user space vma. */
> -static inline pte_t *__translation_exists(struct mm_struct *mm,
> -					  unsigned long addr)
> +static inline int translation_exists(struct vm_area_struct *vma,
> +				unsigned long addr, unsigned long pfn)
>  {
> -	pgd_t *pgd = pgd_offset(mm, addr);
> +	pgd_t *pgd = pgd_offset(vma->vm_mm, addr);
>  	pmd_t *pmd;
> -	pte_t *pte;
> +	pte_t pte;
>  
>  	if(pgd_none(*pgd))
> -		return NULL;
> +		return 0;
>  
>  	pmd = pmd_offset(pgd, addr);
>  	if(pmd_none(*pmd) || pmd_bad(*pmd))
> -		return NULL;
> +		return 0;
>  
> -	pte = pte_offset_map(pmd, addr);
> +	/* We cannot take the pte lock here: flush_cache_page is usually
> +	 * called with pte lock already held.  Whereas flush_dcache_page
> +	 * takes flush_dcache_mmap_lock, which is lower in the hierarchy:
> +	 * the vma itself is secure, but the pte might come or go racily.
> +	 */
> +	pte = *pte_offset_map(pmd, addr);
> +	/* But pte_unmap() does nothing on this architecture */
> +
> +	/* Filter out coincidental file entries and swap entries */
> +	if (!(pte_val(pte) & (_PAGE_FLUSH|_PAGE_PRESENT)))
> +		return 0;
>  
> -	/* The PA flush mappings show up as pte_none, but they're
> -	 * valid none the less */
> -	if(pte_none(*pte) && ((pte_val(*pte) & _PAGE_FLUSH) == 0))
> -		return NULL;
> -	return pte;
> +	return pte_pfn(pte) == pfn;
>  }
> -#define	translation_exists(vma, addr)	__translation_exists((vma)->vm_mm, addr)
> -
>  
>  /* Private function to flush a page from the cache of a non-current
>   * process.  cr25 contains the Page Directory of the current user
> @@ -175,9 +179,8 @@ flush_cache_page(struct vm_area_struct *
>  {
>  	BUG_ON(!vma->vm_mm->context);
>  
> -	if(likely(translation_exists(vma, vmaddr)))
> +	if (likely(translation_exists(vma, vmaddr, pfn)))
>  		__flush_cache_page(vma, vmaddr);
>  
>  }
>  #endif
> -

  parent reply	other threads:[~2005-10-22 16:33 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-22 16:18 [PATCH 0/9] mm: page fault scalability Hugh Dickins
2005-10-22 16:19 ` [PATCH 1/9] mm: i386 sh sh64 ready for split ptlock Hugh Dickins
2005-10-22 18:24   ` Paul Mundt
2005-10-22 16:22 ` [PATCH 2/9] mm: arm " Hugh Dickins
2005-10-22 17:02   ` Russell King
2005-10-23  8:27     ` Hugh Dickins
2005-10-25  2:45     ` Nicolas Pitre
2005-10-25  6:31       ` Hugh Dickins
2005-10-25 14:55         ` Nicolas Pitre
2005-10-25  7:55       ` Russell King
2005-10-25 15:00         ` Nicolas Pitre
2005-10-26  0:20           ` Russell King
2005-10-26  1:26             ` Nicolas Pitre
2005-10-31 22:19             ` Jesper Juhl
2005-10-31 22:27               ` Russell King
2005-10-31 22:34                 ` Jesper Juhl
2005-10-31 22:50                   ` Russell King
2005-10-22 16:23 ` [PATCH 3/9] mm: parisc pte atomicity Hugh Dickins
2005-10-22 16:33   ` [parisc-linux] " Matthew Wilcox
2005-10-22 16:33   ` Matthew Wilcox [this message]
2005-10-22 17:08     ` James Bottomley
2005-10-22 17:08     ` James Bottomley
2005-10-23  9:02       ` Hugh Dickins
2005-10-23  9:02       ` Hugh Dickins
2005-10-23 15:05         ` James Bottomley
2005-10-24  4:36           ` Hugh Dickins
2005-10-24 14:56             ` James Bottomley
2005-10-24 16:49               ` Hugh Dickins
2005-10-24 16:49               ` Hugh Dickins
2005-10-24 14:56             ` James Bottomley
2005-10-24  4:36           ` Hugh Dickins
2005-10-22 16:24 ` [PATCH 4/9] mm: cris v32 mmu_context_lock Hugh Dickins
2005-10-22 16:25 ` [PATCH 5/9] mm: uml pte atomicity Hugh Dickins
2005-10-22 16:27 ` [PATCH 6/9] mm: uml kill unused Hugh Dickins
2005-10-22 19:23   ` Jeff Dike
2005-10-22 16:29 ` [PATCH 7/9] mm: split page table lock Hugh Dickins
2005-10-23 16:54   ` Nikita Danilov
2005-10-23 21:27   ` Andrew Morton
2005-10-23 22:22     ` Andrew Morton
2005-10-24  3:38       ` Hugh Dickins
2005-10-24  4:16         ` Andrew Morton
2005-10-24  4:58           ` Hugh Dickins
2005-10-24  3:09     ` Hugh Dickins
2005-10-23 21:49   ` Andrew Morton
2005-10-24  3:12     ` Hugh Dickins
2005-10-22 16:30 ` [PATCH 8/9] mm: fix rss and mmlist locking Hugh Dickins
2005-10-22 16:31 ` [PATCH 9/9] mm: update comments to pte lock Hugh Dickins
2005-10-23  7:49 ` [PATCH 6/9 take 2] mm: uml kill unused Hugh Dickins

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=20051022163330.GD3364@parisc-linux.org \
    --to=matthew@wil.cx \
    --cc=akpm@osdl.org \
    --cc=hugh@veritas.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=parisc-linux@parisc-linux.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.