linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: dirk.behme@googlemail.com (Dirk Behme)
To: linux-arm-kernel@lists.infradead.org
Subject: Kernel related (?) user space crash at ARM11 MPCore
Date: Wed, 23 Sep 2009 08:03:42 +0200	[thread overview]
Message-ID: <4AB9BA3E.20602@googlemail.com> (raw)
In-Reply-To: <1253639843.14049.95.camel@pc1117.cambridge.arm.com>

Catalin Marinas wrote:
> On Tue, 2009-09-22 at 11:19 +0100, Catalin Marinas wrote:
>> Yet another idea - add a generic flush_cache_range_for_mprotect()
>> function with a specific implementation for ARM (called via
>> change_protection).

Catalin and Russell: First many thanks for all the discussion and help 
about this!

> The patch below looks like the best option in my opinion but requires
> some generic kernel changes (minimal though). The patch contains the
> ARM-specific code as well but can be split in two for pushing upstream.
> 
> Apart from this patch, I ran some lmbench tests and my workaround

If you talk about "workaround", do you mean patch below or patch in

http://lists.arm.linux.org.uk/lurker/message/20090817.172516.3100340a.en.html

?

> affects mmap tests quite a lot because of the read-implies-exec forcing
> flush_cache_range() in several places. Russell's patch 

Is Russell's patch available publically somewhere? Sorry if I missed it.

Many thanks

Dirk

> for adding cache
> flushing during CoW (either coherent_kernel_range or flush_dcache_page)
> slows the fork() tests a bit but the lmbench tests are relatively small
> and don't cause a lot of page CoW. This may be different for something
> like apache.
 >
> Add generic flush_prot_range() and ARM-specific implementation
> 
> From: Catalin Marinas <catalin.marinas@arm.com>
> 
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> ---
>  arch/arm/include/asm/cacheflush.h |    3 +++
>  arch/arm/mm/cache-v6.S            |   20 ++++++++++++++++++--
>  arch/arm/mm/cache-v7.S            |   19 +++++++++++++++++--
>  arch/arm/mm/flush.c               |   19 +++++++++++++++++++
>  include/linux/highmem.h           |    8 ++++++++
>  mm/hugetlb.c                      |    2 +-
>  mm/mprotect.c                     |    2 +-
>  7 files changed, 67 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
> index 91aec14..d53832b 100644
> --- a/arch/arm/include/asm/cacheflush.h
> +++ b/arch/arm/include/asm/cacheflush.h
> @@ -391,12 +391,15 @@ flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
>  	}
>  }
>  #else
> +#define ARCH_HAS_FLUSH_PROT_RANGE
>  extern void flush_cache_mm(struct mm_struct *mm);
>  extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
>  extern void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn);
>  extern void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
>  				unsigned long uaddr, void *kaddr,
>  				unsigned long len, int write);
> +extern void flush_prot_range(struct vm_area_struct *vma, unsigned long start,
> +			     unsigned long end);
>  #endif
>  
>  #define flush_cache_dup_mm(mm) flush_cache_mm(mm)
> diff --git a/arch/arm/mm/cache-v6.S b/arch/arm/mm/cache-v6.S
> index 8364f6c..7baa6ce 100644
> --- a/arch/arm/mm/cache-v6.S
> +++ b/arch/arm/mm/cache-v6.S
> @@ -12,6 +12,7 @@
>  #include <linux/linkage.h>
>  #include <linux/init.h>
>  #include <asm/assembler.h>
> +#include <asm/unwind.h>
>  
>  #include "proc-macros.S"
>  
> @@ -129,11 +130,13 @@ ENTRY(v6_coherent_kern_range)
>   *	- the Icache does not read data from the write buffer
>   */
>  ENTRY(v6_coherent_user_range)
> -
> + UNWIND(.fnstart		)
>  #ifdef HARVARD_CACHE
>  	bic	r0, r0, #CACHE_LINE_SIZE - 1
> -1:	mcr	p15, 0, r0, c7, c10, 1		@ clean D line
> +1:
> + USER(	mcr	p15, 0, r0, c7, c10, 1	)	@ clean D line
>  	add	r0, r0, #CACHE_LINE_SIZE
> +2:
>  	cmp	r0, r1
>  	blo	1b
>  #endif
> @@ -151,6 +154,19 @@ ENTRY(v6_coherent_user_range)
>  	mov	pc, lr
>  
>  /*
> + * Fault handling for the cache operation above. If the virtual address in r0
> + * isn't mapped, just try the next page.
> + */
> +9001:
> +	mov	r0, r0, lsr #12
> +	mov	r0, r0, lsl #12
> +	add	r0, r0, #4096
> +	b	2b
> + UNWIND(.fnend		)
> +ENDPROC(v6_coherent_user_range)
> +ENDPROC(v6_coherent_kern_range)
> +
> +/*
>   *	v6_flush_kern_dcache_page(kaddr)
>   *
>   *	Ensure that the data held in the page kaddr is written back
> diff --git a/arch/arm/mm/cache-v7.S b/arch/arm/mm/cache-v7.S
> index 29e6904..4b733d1 100644
> --- a/arch/arm/mm/cache-v7.S
> +++ b/arch/arm/mm/cache-v7.S
> @@ -13,6 +13,7 @@
>  #include <linux/linkage.h>
>  #include <linux/init.h>
>  #include <asm/assembler.h>
> +#include <asm/unwind.h>
>  
>  #include "proc-macros.S"
>  
> @@ -153,13 +154,16 @@ ENTRY(v7_coherent_kern_range)
>   *	- the Icache does not read data from the write buffer
>   */
>  ENTRY(v7_coherent_user_range)
> + UNWIND(.fnstart		)
>  	dcache_line_size r2, r3
>  	sub	r3, r2, #1
>  	bic	r0, r0, r3
> -1:	mcr	p15, 0, r0, c7, c11, 1		@ clean D line to the point of unification
> +1:
> + USER(	mcr	p15, 0, r0, c7, c11, 1	)	@ clean D line to the point of unification
>  	dsb
> -	mcr	p15, 0, r0, c7, c5, 1		@ invalidate I line
> + USER(	mcr	p15, 0, r0, c7, c5, 1	)	@ invalidate I line
>  	add	r0, r0, r2
> +2:
>  	cmp	r0, r1
>  	blo	1b
>  	mov	r0, #0
> @@ -167,6 +171,17 @@ ENTRY(v7_coherent_user_range)
>  	dsb
>  	isb
>  	mov	pc, lr
> +
> +/*
> + * Fault handling for the cache operation above. If the virtual address in r0
> + * isn't mapped, just try the next page.
> + */
> +9001:
> +	mov	r0, r0, lsr #12
> +	mov	r0, r0, lsl #12
> +	add	r0, r0, #4096
> +	b	2b
> + UNWIND(.fnend		)
>  ENDPROC(v7_coherent_kern_range)
>  ENDPROC(v7_coherent_user_range)
>  
> diff --git a/arch/arm/mm/flush.c b/arch/arm/mm/flush.c
> index 73b886e..ed07f4d 100644
> --- a/arch/arm/mm/flush.c
> +++ b/arch/arm/mm/flush.c
> @@ -87,6 +87,25 @@ void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned
>  	}
>  }
>  
> +void flush_prot_range(struct vm_area_struct *vma, unsigned long start,
> +		      unsigned long end)
> +{
> +	if (cache_is_vipt_nonaliasing()) {
> +		if (vma->vm_flags & VM_EXEC) {
> +			/*
> +			 * Increment the task's preempt_count so that
> +			 * in_atomic() is true and do_page_fault() does not
> +			 * try to map pages in. If a page isn't mapped yet, it
> +			 * will be ignored.
> +			 */
> +			inc_preempt_count();
> +			flush_cache_user_range(vma, start, end);
> +			dec_preempt_count();
> +		}
> +	} else
> +		flush_cache_range(vma, start, end);
> +}
> +
>  void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn)
>  {
>  	if (cache_is_vivt()) {
> diff --git a/include/linux/highmem.h b/include/linux/highmem.h
> index 13875ce..067e67d 100644
> --- a/include/linux/highmem.h
> +++ b/include/linux/highmem.h
> @@ -19,6 +19,14 @@ static inline void flush_kernel_dcache_page(struct page *page)
>  }
>  #endif
>  
> +#ifndef ARCH_HAS_FLUSH_PROT_RANGE
> +static inline void flush_prot_range(struct vm_area_struct *vma,
> +				    unsigned long start, unsigned long end)
> +{
> +	flush_cache_range(vma, start, end);
> +}
> +#endif
> +
>  #ifdef CONFIG_HIGHMEM
>  
>  #include <asm/highmem.h>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 6058b53..7ce4f57 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -2213,7 +2213,7 @@ void hugetlb_change_protection(struct vm_area_struct *vma,
>  	struct hstate *h = hstate_vma(vma);
>  
>  	BUG_ON(address >= end);
> -	flush_cache_range(vma, address, end);
> +	flush_prot_range(vma, address, end);
>  
>  	spin_lock(&vma->vm_file->f_mapping->i_mmap_lock);
>  	spin_lock(&mm->page_table_lock);
> diff --git a/mm/mprotect.c b/mm/mprotect.c
> index fded06f..a6b7616 100644
> --- a/mm/mprotect.c
> +++ b/mm/mprotect.c
> @@ -123,7 +123,7 @@ static void change_protection(struct vm_area_struct *vma,
>  
>  	BUG_ON(addr >= end);
>  	pgd = pgd_offset(mm, addr);
> -	flush_cache_range(vma, addr, end);
> +	flush_prot_range(vma, addr, end);
>  	do {
>  		next = pgd_addr_end(addr, end);
>  		if (pgd_none_or_clear_bad(pgd))
> 
> 

  reply	other threads:[~2009-09-23  6:03 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4A7AEEB6.5060903@googlemail.com>
     [not found] ` <1250184014.14019.40.camel@pc1117.cambridge.arm.com>
     [not found]   ` <1250501311.9858.24.camel@pc1117.cambridge.arm.com>
     [not found]     ` <20090817140422.GA10764@n2100.arm.linux.org.uk>
2009-08-29 12:27       ` Kernel related (?) user space crash at ARM11 MPCore Catalin Marinas
2009-08-31  8:30         ` Catalin Marinas
2009-09-07 15:29           ` Catalin Marinas
2009-09-07 15:56             ` Dirk Behme
2009-09-07 16:43               ` Catalin Marinas
2009-09-07 17:31             ` Mikael Pettersson
2009-09-07 21:40               ` Catalin Marinas
2009-09-03 11:58         ` Dirk Behme
     [not found]       ` <1250529916.11185.80.camel@pc1117.cambridge.arm.com>
     [not found]         ` <20090919224022.GA738@n2100.arm.linux.org.uk>
     [not found]           ` <1253435940.498.15.camel@pc1117.cambridge.arm.com>
2009-09-20  9:31             ` Russell King - ARM Linux
2009-09-20 19:02               ` Russell King - ARM Linux
2009-09-20 22:46                 ` Catalin Marinas
2009-09-21  8:31                   ` Jamie Lokier
2009-09-21  8:41                     ` Russell King - ARM Linux
2009-09-21  9:41                       ` Jamie Lokier
2009-09-21 10:08                         ` Catalin Marinas
2009-09-21  8:49                     ` Catalin Marinas
2009-09-21  8:54                       ` Russell King - ARM Linux
2009-09-21  9:44                         ` Catalin Marinas
2009-09-21 10:07                           ` Russell King - ARM Linux
2009-09-21 10:42                             ` Catalin Marinas
2009-09-21 20:10                             ` Jamie Lokier
2009-09-21 21:26                               ` Russell King - ARM Linux
2009-09-21 22:14                                 ` Catalin Marinas
2009-09-21 22:25                                 ` Jamie Lokier
2009-09-22  8:43                                   ` Catalin Marinas
2009-09-21 21:58                               ` Catalin Marinas
2009-09-21 22:12                                 ` Jamie Lokier
2009-09-21 22:31                                   ` Russell King - ARM Linux
2009-09-21 22:34                                   ` Catalin Marinas
2009-09-21 21:38                             ` Russell King - ARM Linux
2009-09-21 22:28                               ` Catalin Marinas
2009-09-21 22:37                                 ` Jamie Lokier
2009-09-21 22:33                               ` Jamie Lokier
2009-09-22  9:21                                 ` Catalin Marinas
2009-09-22 10:19                               ` Catalin Marinas
2009-09-22 17:17                                 ` Catalin Marinas
2009-09-23  6:03                                   ` Dirk Behme [this message]
2009-09-23  9:13                                     ` Catalin Marinas
2009-09-23 10:38                                       ` Catalin Marinas
2009-09-23 12:12                                         ` Mikael Pettersson
2009-09-23 12:42                                           ` Russell King - ARM Linux
2009-09-23 12:51                                             ` Catalin Marinas
2009-09-23 12:55                                               ` Catalin Marinas
2009-10-15 14:57                             ` Russell King - ARM Linux
2009-10-15 15:20                               ` Catalin Marinas
2009-10-15 15:28                                 ` Russell King - ARM Linux
2009-10-15 15:56                                   ` Catalin Marinas
2009-10-20 11:39                                     ` Catalin Marinas
2009-10-25 13:39                                       ` Russell King - ARM Linux
2009-10-26 18:40                                         ` Catalin Marinas
2009-10-25 14:48                                       ` Russell King - ARM Linux
2009-10-26 18:45                                         ` Catalin Marinas
2009-10-26 19:17                                           ` Russell King - ARM Linux
2009-10-15 15:48                                 ` Dirk Behme
2009-10-15 15:53                                   ` Catalin Marinas
2009-10-25 13:04                                 ` Russell King - ARM Linux
2009-10-26 18:18                                   ` Catalin Marinas
2009-09-20 22:02               ` Catalin Marinas
2009-09-22  5:44                 ` Shilimkar, Santosh
2009-09-22  9:01                   ` Catalin Marinas
2009-09-22  9:34                     ` Shilimkar, Santosh
     [not found] ` <1249981883.27150.14.camel@pc1117.cambridge.arm.com>
     [not found]   ` <4A818CBC.8040000@googlemail.com>
     [not found]     ` <1250006770.30628.1.camel@pc1117.cambridge.arm.com>
     [not found]       ` <4A819C54.3080606@googlemail.com>
     [not found]         ` <1250009043.30628.9.camel@pc1117.cambridge.arm.com>
     [not found]           ` <87ab25vazg.fsf@brigitte.kvy.fi>
     [not found]             ` <1250080338.20332.32.camel@pc1117.cambridge.arm.com>
     [not found]               ` <87k518yc8a.fsf@brigitte.kvy.fi>
2009-09-11  9:21                 ` smsc911x.c driver and SMP (was Re: Kernel related (?) user space crash at ARM11 MPCore) Catalin Marinas
2009-09-11 12:55                   ` Bill Gatliff
2009-09-11 13:00                     ` Catalin Marinas
2009-09-11 15:20                       ` Bill Gatliff
2009-09-11 16:06                         ` Catalin Marinas
2009-10-06  6:12                           ` smsc911x.c driver and SMP Antti P Miettinen
2010-08-31  0:07                             ` Shinya Kuribayashi
2010-08-31  6:22                               ` Antti P Miettinen
2010-08-31  9:10                                 ` Shinya Kuribayashi
2010-08-31  8:33                               ` Catalin Marinas
2010-08-31  8:42                                 ` Shinya Kuribayashi

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=4AB9BA3E.20602@googlemail.com \
    --to=dirk.behme@googlemail.com \
    --cc=linux-arm-kernel@lists.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 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).