All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Arch-specific user pgtables ceiling
@ 2013-02-18 16:18 ` Catalin Marinas
  0 siblings, 0 replies; 14+ messages in thread
From: Catalin Marinas @ 2013-02-18 16:18 UTC (permalink / raw)
  To: Andrew Morton, Hugh Dickins, Russell King - ARM Linux
  Cc: linux-kernel, linux-mm, linux-arch

Following feedback on the previous patch to limit the free_pgtables()
ceiling, this series introduces a USER_PGTABLES_CEILING macro defaulting
to 0 and an ARM-specific definition to TASK_SIZE.

Catalin Marinas (1):
  arm: Set the page table freeing ceiling to TASK_SIZE

Hugh Dickins (1):
  mm: Allow arch code to control the user page table ceiling

 arch/arm/include/asm/pgtable.h |  7 +++++++
 fs/exec.c                      |  4 ++--
 include/asm-generic/pgtable.h  | 10 ++++++++++
 mm/mmap.c                      |  4 ++--
 4 files changed, 21 insertions(+), 4 deletions(-)


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 0/2] Arch-specific user pgtables ceiling
@ 2013-02-18 16:18 ` Catalin Marinas
  0 siblings, 0 replies; 14+ messages in thread
From: Catalin Marinas @ 2013-02-18 16:18 UTC (permalink / raw)
  To: Andrew Morton, Hugh Dickins, Russell King - ARM Linux
  Cc: linux-kernel, linux-mm, linux-arch

Following feedback on the previous patch to limit the free_pgtables()
ceiling, this series introduces a USER_PGTABLES_CEILING macro defaulting
to 0 and an ARM-specific definition to TASK_SIZE.

Catalin Marinas (1):
  arm: Set the page table freeing ceiling to TASK_SIZE

Hugh Dickins (1):
  mm: Allow arch code to control the user page table ceiling

 arch/arm/include/asm/pgtable.h |  7 +++++++
 fs/exec.c                      |  4 ++--
 include/asm-generic/pgtable.h  | 10 ++++++++++
 mm/mmap.c                      |  4 ++--
 4 files changed, 21 insertions(+), 4 deletions(-)

--
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>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/2] mm: Allow arch code to control the user page table ceiling
  2013-02-18 16:18 ` Catalin Marinas
@ 2013-02-18 16:18   ` Catalin Marinas
  -1 siblings, 0 replies; 14+ messages in thread
From: Catalin Marinas @ 2013-02-18 16:18 UTC (permalink / raw)
  To: Andrew Morton, Hugh Dickins, Russell King - ARM Linux
  Cc: linux-kernel, linux-mm, linux-arch

From: Hugh Dickins <hughd@google.com>

On architectures where a pgd entry may be shared between user and kernel
(ARM+LPAE), freeing page tables needs a ceiling other than 0. This patch
introduces a generic USER_PGTABLES_CEILING that arch code can override.

Signed-off-by: Hugh Dickins <hughd@google.com>
[catalin.marinas@arm.com: commit log; shift_arg_pages(), asm-generic/pgtables.h changes]
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 fs/exec.c                     |  4 ++--
 include/asm-generic/pgtable.h | 10 ++++++++++
 mm/mmap.c                     |  4 ++--
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 20df02c..547eaaa 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -613,7 +613,7 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
 		 * when the old and new regions overlap clear from new_end.
 		 */
 		free_pgd_range(&tlb, new_end, old_end, new_end,
-			vma->vm_next ? vma->vm_next->vm_start : 0);
+			vma->vm_next ? vma->vm_next->vm_start : USER_PGTABLES_CEILING);
 	} else {
 		/*
 		 * otherwise, clean from old_start; this is done to not touch
@@ -622,7 +622,7 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
 		 * for the others its just a little faster.
 		 */
 		free_pgd_range(&tlb, old_start, old_end, new_end,
-			vma->vm_next ? vma->vm_next->vm_start : 0);
+			vma->vm_next ? vma->vm_next->vm_start : USER_PGTABLES_CEILING);
 	}
 	tlb_finish_mmu(&tlb, new_end, old_end);
 
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
index 5cf680a..f50a87d 100644
--- a/include/asm-generic/pgtable.h
+++ b/include/asm-generic/pgtable.h
@@ -7,6 +7,16 @@
 #include <linux/mm_types.h>
 #include <linux/bug.h>
 
+/*
+ * On almost all architectures and configurations, 0 can be used as the
+ * upper ceiling to free_pgtables(): on many architectures it has the same
+ * effect as using TASK_SIZE.  However, there is one configuration which
+ * must impose a more careful limit, to avoid freeing kernel pgtables.
+ */
+#ifndef USER_PGTABLES_CEILING
+#define USER_PGTABLES_CEILING	0UL
+#endif
+
 #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
 extern int ptep_set_access_flags(struct vm_area_struct *vma,
 				 unsigned long address, pte_t *ptep,
diff --git a/mm/mmap.c b/mm/mmap.c
index d1e4124..e262710 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2262,7 +2262,7 @@ static void unmap_region(struct mm_struct *mm,
 	update_hiwater_rss(mm);
 	unmap_vmas(&tlb, vma, start, end);
 	free_pgtables(&tlb, vma, prev ? prev->vm_end : FIRST_USER_ADDRESS,
-				 next ? next->vm_start : 0);
+				 next ? next->vm_start : USER_PGTABLES_CEILING);
 	tlb_finish_mmu(&tlb, start, end);
 }
 
@@ -2640,7 +2640,7 @@ void exit_mmap(struct mm_struct *mm)
 	/* Use -1 here to ensure all VMAs in the mm are unmapped */
 	unmap_vmas(&tlb, vma, 0, -1);
 
-	free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
+	free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING);
 	tlb_finish_mmu(&tlb, 0, -1);
 
 	/*

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 1/2] mm: Allow arch code to control the user page table ceiling
@ 2013-02-18 16:18   ` Catalin Marinas
  0 siblings, 0 replies; 14+ messages in thread
From: Catalin Marinas @ 2013-02-18 16:18 UTC (permalink / raw)
  To: Andrew Morton, Hugh Dickins, Russell King - ARM Linux
  Cc: linux-kernel, linux-mm, linux-arch

From: Hugh Dickins <hughd@google.com>

On architectures where a pgd entry may be shared between user and kernel
(ARM+LPAE), freeing page tables needs a ceiling other than 0. This patch
introduces a generic USER_PGTABLES_CEILING that arch code can override.

Signed-off-by: Hugh Dickins <hughd@google.com>
[catalin.marinas@arm.com: commit log; shift_arg_pages(), asm-generic/pgtables.h changes]
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 fs/exec.c                     |  4 ++--
 include/asm-generic/pgtable.h | 10 ++++++++++
 mm/mmap.c                     |  4 ++--
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 20df02c..547eaaa 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -613,7 +613,7 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
 		 * when the old and new regions overlap clear from new_end.
 		 */
 		free_pgd_range(&tlb, new_end, old_end, new_end,
-			vma->vm_next ? vma->vm_next->vm_start : 0);
+			vma->vm_next ? vma->vm_next->vm_start : USER_PGTABLES_CEILING);
 	} else {
 		/*
 		 * otherwise, clean from old_start; this is done to not touch
@@ -622,7 +622,7 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
 		 * for the others its just a little faster.
 		 */
 		free_pgd_range(&tlb, old_start, old_end, new_end,
-			vma->vm_next ? vma->vm_next->vm_start : 0);
+			vma->vm_next ? vma->vm_next->vm_start : USER_PGTABLES_CEILING);
 	}
 	tlb_finish_mmu(&tlb, new_end, old_end);
 
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
index 5cf680a..f50a87d 100644
--- a/include/asm-generic/pgtable.h
+++ b/include/asm-generic/pgtable.h
@@ -7,6 +7,16 @@
 #include <linux/mm_types.h>
 #include <linux/bug.h>
 
+/*
+ * On almost all architectures and configurations, 0 can be used as the
+ * upper ceiling to free_pgtables(): on many architectures it has the same
+ * effect as using TASK_SIZE.  However, there is one configuration which
+ * must impose a more careful limit, to avoid freeing kernel pgtables.
+ */
+#ifndef USER_PGTABLES_CEILING
+#define USER_PGTABLES_CEILING	0UL
+#endif
+
 #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
 extern int ptep_set_access_flags(struct vm_area_struct *vma,
 				 unsigned long address, pte_t *ptep,
diff --git a/mm/mmap.c b/mm/mmap.c
index d1e4124..e262710 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2262,7 +2262,7 @@ static void unmap_region(struct mm_struct *mm,
 	update_hiwater_rss(mm);
 	unmap_vmas(&tlb, vma, start, end);
 	free_pgtables(&tlb, vma, prev ? prev->vm_end : FIRST_USER_ADDRESS,
-				 next ? next->vm_start : 0);
+				 next ? next->vm_start : USER_PGTABLES_CEILING);
 	tlb_finish_mmu(&tlb, start, end);
 }
 
@@ -2640,7 +2640,7 @@ void exit_mmap(struct mm_struct *mm)
 	/* Use -1 here to ensure all VMAs in the mm are unmapped */
 	unmap_vmas(&tlb, vma, 0, -1);
 
-	free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
+	free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING);
 	tlb_finish_mmu(&tlb, 0, -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>

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/2] arm: Set the page table freeing ceiling to TASK_SIZE
  2013-02-18 16:18 ` Catalin Marinas
@ 2013-02-18 16:18   ` Catalin Marinas
  -1 siblings, 0 replies; 14+ messages in thread
From: Catalin Marinas @ 2013-02-18 16:18 UTC (permalink / raw)
  To: Andrew Morton, Hugh Dickins, Russell King - ARM Linux
  Cc: linux-kernel, linux-mm, linux-arch

ARM processors with LPAE enabled use 3 levels of page tables, with an
entry in the top level (pgd) covering 1GB of virtual space. Because of
the branch relocation limitations on ARM, the loadable modules are
mapped 16MB below PAGE_OFFSET, making the corresponding 1GB pgd shared
between kernel modules and user space.

If free_pgtables() is called with the default ceiling 0,
free_pgd_range() (and subsequently called functions) also frees the page
table shared between user space and kernel modules (which is normally
handled by the ARM-specific pgd_free() function). This patch changes
defines the ARM USER_PGTABLES_CEILING to TASK_SIZE.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Hugh Dickins <hughd@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 arch/arm/include/asm/pgtable.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
index c094749..8f06ee5 100644
--- a/arch/arm/include/asm/pgtable.h
+++ b/arch/arm/include/asm/pgtable.h
@@ -61,6 +61,13 @@ extern void __pgd_error(const char *file, int line, pgd_t);
 #define FIRST_USER_ADDRESS	PAGE_SIZE
 
 /*
+ * Use TASK_SIZE as the ceiling argument for free_pgtables() and
+ * free_pgd_range() to avoid freeing the modules pmd when LPAE is enabled (pmd
+ * page shared between user and kernel).
+ */
+#define USER_PGTABLES_CEILING	TASK_SIZE
+
+/*
  * The pgprot_* and protection_map entries will be fixed up in runtime
  * to include the cachable and bufferable bits based on memory policy,
  * as well as any architecture dependent bits like global/ASID and SMP

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/2] arm: Set the page table freeing ceiling to TASK_SIZE
@ 2013-02-18 16:18   ` Catalin Marinas
  0 siblings, 0 replies; 14+ messages in thread
From: Catalin Marinas @ 2013-02-18 16:18 UTC (permalink / raw)
  To: Andrew Morton, Hugh Dickins, Russell King - ARM Linux
  Cc: linux-kernel, linux-mm, linux-arch

ARM processors with LPAE enabled use 3 levels of page tables, with an
entry in the top level (pgd) covering 1GB of virtual space. Because of
the branch relocation limitations on ARM, the loadable modules are
mapped 16MB below PAGE_OFFSET, making the corresponding 1GB pgd shared
between kernel modules and user space.

If free_pgtables() is called with the default ceiling 0,
free_pgd_range() (and subsequently called functions) also frees the page
table shared between user space and kernel modules (which is normally
handled by the ARM-specific pgd_free() function). This patch changes
defines the ARM USER_PGTABLES_CEILING to TASK_SIZE.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Hugh Dickins <hughd@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 arch/arm/include/asm/pgtable.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
index c094749..8f06ee5 100644
--- a/arch/arm/include/asm/pgtable.h
+++ b/arch/arm/include/asm/pgtable.h
@@ -61,6 +61,13 @@ extern void __pgd_error(const char *file, int line, pgd_t);
 #define FIRST_USER_ADDRESS	PAGE_SIZE
 
 /*
+ * Use TASK_SIZE as the ceiling argument for free_pgtables() and
+ * free_pgd_range() to avoid freeing the modules pmd when LPAE is enabled (pmd
+ * page shared between user and kernel).
+ */
+#define USER_PGTABLES_CEILING	TASK_SIZE
+
+/*
  * The pgprot_* and protection_map entries will be fixed up in runtime
  * to include the cachable and bufferable bits based on memory policy,
  * as well as any architecture dependent bits like global/ASID and SMP

--
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>

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] mm: Allow arch code to control the user page table ceiling
  2013-02-18 16:18   ` Catalin Marinas
@ 2013-02-19 18:08     ` Hugh Dickins
  -1 siblings, 0 replies; 14+ messages in thread
From: Hugh Dickins @ 2013-02-19 18:08 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Andrew Morton, Russell King - ARM Linux, linux-kernel, linux-mm,
	linux-arch

On Mon, 18 Feb 2013, Catalin Marinas wrote:

> From: Hugh Dickins <hughd@google.com>

You're being generous to me :)
Thanks for doing most of the work, yes, this looks fine.
BUt I'd have expected a Cc stable below: see comment on 2/2.

Hugh

> 
> On architectures where a pgd entry may be shared between user and kernel
> (ARM+LPAE), freeing page tables needs a ceiling other than 0. This patch
> introduces a generic USER_PGTABLES_CEILING that arch code can override.
> 
> Signed-off-by: Hugh Dickins <hughd@google.com>
> [catalin.marinas@arm.com: commit log; shift_arg_pages(), asm-generic/pgtables.h changes]
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> ---
>  fs/exec.c                     |  4 ++--
>  include/asm-generic/pgtable.h | 10 ++++++++++
>  mm/mmap.c                     |  4 ++--
>  3 files changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/exec.c b/fs/exec.c
> index 20df02c..547eaaa 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -613,7 +613,7 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
>  		 * when the old and new regions overlap clear from new_end.
>  		 */
>  		free_pgd_range(&tlb, new_end, old_end, new_end,
> -			vma->vm_next ? vma->vm_next->vm_start : 0);
> +			vma->vm_next ? vma->vm_next->vm_start : USER_PGTABLES_CEILING);
>  	} else {
>  		/*
>  		 * otherwise, clean from old_start; this is done to not touch
> @@ -622,7 +622,7 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
>  		 * for the others its just a little faster.
>  		 */
>  		free_pgd_range(&tlb, old_start, old_end, new_end,
> -			vma->vm_next ? vma->vm_next->vm_start : 0);
> +			vma->vm_next ? vma->vm_next->vm_start : USER_PGTABLES_CEILING);
>  	}
>  	tlb_finish_mmu(&tlb, new_end, old_end);
>  
> diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
> index 5cf680a..f50a87d 100644
> --- a/include/asm-generic/pgtable.h
> +++ b/include/asm-generic/pgtable.h
> @@ -7,6 +7,16 @@
>  #include <linux/mm_types.h>
>  #include <linux/bug.h>
>  
> +/*
> + * On almost all architectures and configurations, 0 can be used as the
> + * upper ceiling to free_pgtables(): on many architectures it has the same
> + * effect as using TASK_SIZE.  However, there is one configuration which
> + * must impose a more careful limit, to avoid freeing kernel pgtables.
> + */
> +#ifndef USER_PGTABLES_CEILING
> +#define USER_PGTABLES_CEILING	0UL
> +#endif
> +
>  #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
>  extern int ptep_set_access_flags(struct vm_area_struct *vma,
>  				 unsigned long address, pte_t *ptep,
> diff --git a/mm/mmap.c b/mm/mmap.c
> index d1e4124..e262710 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2262,7 +2262,7 @@ static void unmap_region(struct mm_struct *mm,
>  	update_hiwater_rss(mm);
>  	unmap_vmas(&tlb, vma, start, end);
>  	free_pgtables(&tlb, vma, prev ? prev->vm_end : FIRST_USER_ADDRESS,
> -				 next ? next->vm_start : 0);
> +				 next ? next->vm_start : USER_PGTABLES_CEILING);
>  	tlb_finish_mmu(&tlb, start, end);
>  }
>  
> @@ -2640,7 +2640,7 @@ void exit_mmap(struct mm_struct *mm)
>  	/* Use -1 here to ensure all VMAs in the mm are unmapped */
>  	unmap_vmas(&tlb, vma, 0, -1);
>  
> -	free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
> +	free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING);
>  	tlb_finish_mmu(&tlb, 0, -1);
>  
>  	/*
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] mm: Allow arch code to control the user page table ceiling
@ 2013-02-19 18:08     ` Hugh Dickins
  0 siblings, 0 replies; 14+ messages in thread
From: Hugh Dickins @ 2013-02-19 18:08 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Andrew Morton, Russell King - ARM Linux, linux-kernel, linux-mm,
	linux-arch

On Mon, 18 Feb 2013, Catalin Marinas wrote:

> From: Hugh Dickins <hughd@google.com>

You're being generous to me :)
Thanks for doing most of the work, yes, this looks fine.
BUt I'd have expected a Cc stable below: see comment on 2/2.

Hugh

> 
> On architectures where a pgd entry may be shared between user and kernel
> (ARM+LPAE), freeing page tables needs a ceiling other than 0. This patch
> introduces a generic USER_PGTABLES_CEILING that arch code can override.
> 
> Signed-off-by: Hugh Dickins <hughd@google.com>
> [catalin.marinas@arm.com: commit log; shift_arg_pages(), asm-generic/pgtables.h changes]
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> ---
>  fs/exec.c                     |  4 ++--
>  include/asm-generic/pgtable.h | 10 ++++++++++
>  mm/mmap.c                     |  4 ++--
>  3 files changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/exec.c b/fs/exec.c
> index 20df02c..547eaaa 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -613,7 +613,7 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
>  		 * when the old and new regions overlap clear from new_end.
>  		 */
>  		free_pgd_range(&tlb, new_end, old_end, new_end,
> -			vma->vm_next ? vma->vm_next->vm_start : 0);
> +			vma->vm_next ? vma->vm_next->vm_start : USER_PGTABLES_CEILING);
>  	} else {
>  		/*
>  		 * otherwise, clean from old_start; this is done to not touch
> @@ -622,7 +622,7 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
>  		 * for the others its just a little faster.
>  		 */
>  		free_pgd_range(&tlb, old_start, old_end, new_end,
> -			vma->vm_next ? vma->vm_next->vm_start : 0);
> +			vma->vm_next ? vma->vm_next->vm_start : USER_PGTABLES_CEILING);
>  	}
>  	tlb_finish_mmu(&tlb, new_end, old_end);
>  
> diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
> index 5cf680a..f50a87d 100644
> --- a/include/asm-generic/pgtable.h
> +++ b/include/asm-generic/pgtable.h
> @@ -7,6 +7,16 @@
>  #include <linux/mm_types.h>
>  #include <linux/bug.h>
>  
> +/*
> + * On almost all architectures and configurations, 0 can be used as the
> + * upper ceiling to free_pgtables(): on many architectures it has the same
> + * effect as using TASK_SIZE.  However, there is one configuration which
> + * must impose a more careful limit, to avoid freeing kernel pgtables.
> + */
> +#ifndef USER_PGTABLES_CEILING
> +#define USER_PGTABLES_CEILING	0UL
> +#endif
> +
>  #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
>  extern int ptep_set_access_flags(struct vm_area_struct *vma,
>  				 unsigned long address, pte_t *ptep,
> diff --git a/mm/mmap.c b/mm/mmap.c
> index d1e4124..e262710 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2262,7 +2262,7 @@ static void unmap_region(struct mm_struct *mm,
>  	update_hiwater_rss(mm);
>  	unmap_vmas(&tlb, vma, start, end);
>  	free_pgtables(&tlb, vma, prev ? prev->vm_end : FIRST_USER_ADDRESS,
> -				 next ? next->vm_start : 0);
> +				 next ? next->vm_start : USER_PGTABLES_CEILING);
>  	tlb_finish_mmu(&tlb, start, end);
>  }
>  
> @@ -2640,7 +2640,7 @@ void exit_mmap(struct mm_struct *mm)
>  	/* Use -1 here to ensure all VMAs in the mm are unmapped */
>  	unmap_vmas(&tlb, vma, 0, -1);
>  
> -	free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
> +	free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING);
>  	tlb_finish_mmu(&tlb, 0, -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>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] arm: Set the page table freeing ceiling to TASK_SIZE
  2013-02-18 16:18   ` Catalin Marinas
@ 2013-02-19 18:20     ` Hugh Dickins
  -1 siblings, 0 replies; 14+ messages in thread
From: Hugh Dickins @ 2013-02-19 18:20 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Andrew Morton, Russell King - ARM Linux, linux-kernel, linux-mm,
	linux-arch

On Mon, 18 Feb 2013, Catalin Marinas wrote:

> ARM processors with LPAE enabled use 3 levels of page tables, with an
> entry in the top level (pgd) covering 1GB of virtual space. Because of
> the branch relocation limitations on ARM, the loadable modules are
> mapped 16MB below PAGE_OFFSET, making the corresponding 1GB pgd shared
> between kernel modules and user space.
> 
> If free_pgtables() is called with the default ceiling 0,
> free_pgd_range() (and subsequently called functions) also frees the page
> table shared between user space and kernel modules (which is normally
> handled by the ARM-specific pgd_free() function). This patch changes
> defines the ARM USER_PGTABLES_CEILING to TASK_SIZE.

I don't have an ARM to test on, so I won't ack or nack this,
but I am a little worried or puzzled.

I thought CONFIG_ARM_LPAE came in v3.3: so I would expect these
patches to need "Cc: stable@vger.kernel.org" for porting back there.

But then, did v3.3..v3.8 have the appropriate arch/arm code to handle
the freeing of the user+kernel pgd?  I'm not asserting that it could
not, but when doing the similar arch/x86 thing, I had to make changes
down there, so it's not necessarily something that works automatically.

And does the ARM !LPAE case work correctly (not leaking page tables
at any level) with this change from 0 to TASK_SIZE?  Again, I'm not
asserting that it does not, but your commit description doesn't give
enough confidence that you've tried that.

Perhaps you have some other patches to arch/arm, that of course I
wouldn't have noticed, which make this all work together; and it's
accepted that CONFIG_ARM_LPAE is broken on v3.3..v3.8, and too
much risk to backport it all for -stable.

Maybe all I'm asking for is a more reassuring commit description.

Hugh

> 
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> ---
>  arch/arm/include/asm/pgtable.h | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
> index c094749..8f06ee5 100644
> --- a/arch/arm/include/asm/pgtable.h
> +++ b/arch/arm/include/asm/pgtable.h
> @@ -61,6 +61,13 @@ extern void __pgd_error(const char *file, int line, pgd_t);
>  #define FIRST_USER_ADDRESS	PAGE_SIZE
>  
>  /*
> + * Use TASK_SIZE as the ceiling argument for free_pgtables() and
> + * free_pgd_range() to avoid freeing the modules pmd when LPAE is enabled (pmd
> + * page shared between user and kernel).
> + */
> +#define USER_PGTABLES_CEILING	TASK_SIZE
> +
> +/*
>   * The pgprot_* and protection_map entries will be fixed up in runtime
>   * to include the cachable and bufferable bits based on memory policy,
>   * as well as any architecture dependent bits like global/ASID and SMP

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] arm: Set the page table freeing ceiling to TASK_SIZE
@ 2013-02-19 18:20     ` Hugh Dickins
  0 siblings, 0 replies; 14+ messages in thread
From: Hugh Dickins @ 2013-02-19 18:20 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Andrew Morton, Russell King - ARM Linux, linux-kernel, linux-mm,
	linux-arch

On Mon, 18 Feb 2013, Catalin Marinas wrote:

> ARM processors with LPAE enabled use 3 levels of page tables, with an
> entry in the top level (pgd) covering 1GB of virtual space. Because of
> the branch relocation limitations on ARM, the loadable modules are
> mapped 16MB below PAGE_OFFSET, making the corresponding 1GB pgd shared
> between kernel modules and user space.
> 
> If free_pgtables() is called with the default ceiling 0,
> free_pgd_range() (and subsequently called functions) also frees the page
> table shared between user space and kernel modules (which is normally
> handled by the ARM-specific pgd_free() function). This patch changes
> defines the ARM USER_PGTABLES_CEILING to TASK_SIZE.

I don't have an ARM to test on, so I won't ack or nack this,
but I am a little worried or puzzled.

I thought CONFIG_ARM_LPAE came in v3.3: so I would expect these
patches to need "Cc: stable@vger.kernel.org" for porting back there.

But then, did v3.3..v3.8 have the appropriate arch/arm code to handle
the freeing of the user+kernel pgd?  I'm not asserting that it could
not, but when doing the similar arch/x86 thing, I had to make changes
down there, so it's not necessarily something that works automatically.

And does the ARM !LPAE case work correctly (not leaking page tables
at any level) with this change from 0 to TASK_SIZE?  Again, I'm not
asserting that it does not, but your commit description doesn't give
enough confidence that you've tried that.

Perhaps you have some other patches to arch/arm, that of course I
wouldn't have noticed, which make this all work together; and it's
accepted that CONFIG_ARM_LPAE is broken on v3.3..v3.8, and too
much risk to backport it all for -stable.

Maybe all I'm asking for is a more reassuring commit description.

Hugh

> 
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Russell King <linux@arm.linux.org.uk>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> ---
>  arch/arm/include/asm/pgtable.h | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
> index c094749..8f06ee5 100644
> --- a/arch/arm/include/asm/pgtable.h
> +++ b/arch/arm/include/asm/pgtable.h
> @@ -61,6 +61,13 @@ extern void __pgd_error(const char *file, int line, pgd_t);
>  #define FIRST_USER_ADDRESS	PAGE_SIZE
>  
>  /*
> + * Use TASK_SIZE as the ceiling argument for free_pgtables() and
> + * free_pgd_range() to avoid freeing the modules pmd when LPAE is enabled (pmd
> + * page shared between user and kernel).
> + */
> +#define USER_PGTABLES_CEILING	TASK_SIZE
> +
> +/*
>   * The pgprot_* and protection_map entries will be fixed up in runtime
>   * to include the cachable and bufferable bits based on memory policy,
>   * as well as any architecture dependent bits like global/ASID and SMP

--
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>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] mm: Allow arch code to control the user page table ceiling
  2013-02-19 18:08     ` Hugh Dickins
@ 2013-02-19 22:33       ` Catalin Marinas
  -1 siblings, 0 replies; 14+ messages in thread
From: Catalin Marinas @ 2013-02-19 22:33 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Andrew Morton, Russell King - ARM Linux, linux-kernel, linux-mm,
	linux-arch

On Tue, Feb 19, 2013 at 06:08:12PM +0000, Hugh Dickins wrote:
> On Mon, 18 Feb 2013, Catalin Marinas wrote:
> 
> > From: Hugh Dickins <hughd@google.com>
> 
> You're being generous to me :)

OTOH, there are better chances to get the patch upstream ;)

> Thanks for doing most of the work, yes, this looks fine.
> BUt I'd have expected a Cc stable below: see comment on 2/2.

Yes, I will add cc stable. When I post patches for review I usually
avoid cc'ing stable since Git has the habit of actually sending the
email to stable@vger.kernel.org (and I want it to email the other people
on cc).

Thanks.

-- 
Catalin

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] mm: Allow arch code to control the user page table ceiling
@ 2013-02-19 22:33       ` Catalin Marinas
  0 siblings, 0 replies; 14+ messages in thread
From: Catalin Marinas @ 2013-02-19 22:33 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Andrew Morton, Russell King - ARM Linux, linux-kernel, linux-mm,
	linux-arch

On Tue, Feb 19, 2013 at 06:08:12PM +0000, Hugh Dickins wrote:
> On Mon, 18 Feb 2013, Catalin Marinas wrote:
> 
> > From: Hugh Dickins <hughd@google.com>
> 
> You're being generous to me :)

OTOH, there are better chances to get the patch upstream ;)

> Thanks for doing most of the work, yes, this looks fine.
> BUt I'd have expected a Cc stable below: see comment on 2/2.

Yes, I will add cc stable. When I post patches for review I usually
avoid cc'ing stable since Git has the habit of actually sending the
email to stable@vger.kernel.org (and I want it to email the other people
on cc).

Thanks.

-- 
Catalin

--
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>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] arm: Set the page table freeing ceiling to TASK_SIZE
  2013-02-19 18:20     ` Hugh Dickins
@ 2013-02-19 22:55       ` Catalin Marinas
  -1 siblings, 0 replies; 14+ messages in thread
From: Catalin Marinas @ 2013-02-19 22:55 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Andrew Morton, Russell King - ARM Linux, linux-kernel, linux-mm,
	linux-arch

Hugh,

On Tue, Feb 19, 2013 at 06:20:50PM +0000, Hugh Dickins wrote:
> On Mon, 18 Feb 2013, Catalin Marinas wrote:
> 
> > ARM processors with LPAE enabled use 3 levels of page tables, with an
> > entry in the top level (pgd) covering 1GB of virtual space. Because of
> > the branch relocation limitations on ARM, the loadable modules are
> > mapped 16MB below PAGE_OFFSET, making the corresponding 1GB pgd shared
> > between kernel modules and user space.
> > 
> > If free_pgtables() is called with the default ceiling 0,
> > free_pgd_range() (and subsequently called functions) also frees the page
> > table shared between user space and kernel modules (which is normally
> > handled by the ARM-specific pgd_free() function). This patch changes
> > defines the ARM USER_PGTABLES_CEILING to TASK_SIZE.
> 
> I don't have an ARM to test on, so I won't ack or nack this,
> but I am a little worried or puzzled.
> 
> I thought CONFIG_ARM_LPAE came in v3.3: so I would expect these
> patches to need "Cc: stable@vger.kernel.org" for porting back there.

Yes, I'll add this.

> But then, did v3.3..v3.8 have the appropriate arch/arm code to handle
> the freeing of the user+kernel pgd?  I'm not asserting that it could
> not, but when doing the similar arch/x86 thing, I had to make changes
> down there, so it's not necessarily something that works automatically.

Unfortunately it doesn't have any code to handle this, though it is
relatively hard to trigger the problem. The pgd entry shared between
user and kernel on ARM is used for loadable modules and kmap. It
triggers for example if we get an interrupt handled by a loadable module
during a task exit. The rest of the kernel pgd is fine as PAGE_OFFSET is
an entirely new pgd entry.

I had a workaround for arch/arm only but after discussions with rmk, we
decided that ceiling is the mode elegant solution.

> And does the ARM !LPAE case work correctly (not leaking page tables
> at any level) with this change from 0 to TASK_SIZE?  Again, I'm not
> asserting that it does not, but your commit description doesn't give
> enough confidence that you've tried that.

In the ARM !LPAE case, we only have two levels of page tables and the
pmd pages are allocated by pgd_alloc() and freed in pgd_free(). The next
pte level is not shared between user and kernel (actually for module
space and kmap below PAGE_OFFSET we don't even allocate new ptes, just
point the pmd to the existing kernel pte).

I'll add more information to the commit message.

> Perhaps you have some other patches to arch/arm, that of course I
> wouldn't have noticed, which make this all work together; and it's
> accepted that CONFIG_ARM_LPAE is broken on v3.3..v3.8, and too
> much risk to backport it all for -stable.

I think it makes sense to backport to v3.3 as we don't have any other
ARM patches addressing this. The shared pgd entry with LPAE is handled
explicitly in pgd_free() (I've done this from the beginning as a
precaution, though the condition never triggered because of the 0
ceiling).

> Maybe all I'm asking for is a more reassuring commit description.

I agree. I'm also waiting for rmk's ack.

Thanks.

-- 
Catalin

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] arm: Set the page table freeing ceiling to TASK_SIZE
@ 2013-02-19 22:55       ` Catalin Marinas
  0 siblings, 0 replies; 14+ messages in thread
From: Catalin Marinas @ 2013-02-19 22:55 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Andrew Morton, Russell King - ARM Linux, linux-kernel, linux-mm,
	linux-arch

Hugh,

On Tue, Feb 19, 2013 at 06:20:50PM +0000, Hugh Dickins wrote:
> On Mon, 18 Feb 2013, Catalin Marinas wrote:
> 
> > ARM processors with LPAE enabled use 3 levels of page tables, with an
> > entry in the top level (pgd) covering 1GB of virtual space. Because of
> > the branch relocation limitations on ARM, the loadable modules are
> > mapped 16MB below PAGE_OFFSET, making the corresponding 1GB pgd shared
> > between kernel modules and user space.
> > 
> > If free_pgtables() is called with the default ceiling 0,
> > free_pgd_range() (and subsequently called functions) also frees the page
> > table shared between user space and kernel modules (which is normally
> > handled by the ARM-specific pgd_free() function). This patch changes
> > defines the ARM USER_PGTABLES_CEILING to TASK_SIZE.
> 
> I don't have an ARM to test on, so I won't ack or nack this,
> but I am a little worried or puzzled.
> 
> I thought CONFIG_ARM_LPAE came in v3.3: so I would expect these
> patches to need "Cc: stable@vger.kernel.org" for porting back there.

Yes, I'll add this.

> But then, did v3.3..v3.8 have the appropriate arch/arm code to handle
> the freeing of the user+kernel pgd?  I'm not asserting that it could
> not, but when doing the similar arch/x86 thing, I had to make changes
> down there, so it's not necessarily something that works automatically.

Unfortunately it doesn't have any code to handle this, though it is
relatively hard to trigger the problem. The pgd entry shared between
user and kernel on ARM is used for loadable modules and kmap. It
triggers for example if we get an interrupt handled by a loadable module
during a task exit. The rest of the kernel pgd is fine as PAGE_OFFSET is
an entirely new pgd entry.

I had a workaround for arch/arm only but after discussions with rmk, we
decided that ceiling is the mode elegant solution.

> And does the ARM !LPAE case work correctly (not leaking page tables
> at any level) with this change from 0 to TASK_SIZE?  Again, I'm not
> asserting that it does not, but your commit description doesn't give
> enough confidence that you've tried that.

In the ARM !LPAE case, we only have two levels of page tables and the
pmd pages are allocated by pgd_alloc() and freed in pgd_free(). The next
pte level is not shared between user and kernel (actually for module
space and kmap below PAGE_OFFSET we don't even allocate new ptes, just
point the pmd to the existing kernel pte).

I'll add more information to the commit message.

> Perhaps you have some other patches to arch/arm, that of course I
> wouldn't have noticed, which make this all work together; and it's
> accepted that CONFIG_ARM_LPAE is broken on v3.3..v3.8, and too
> much risk to backport it all for -stable.

I think it makes sense to backport to v3.3 as we don't have any other
ARM patches addressing this. The shared pgd entry with LPAE is handled
explicitly in pgd_free() (I've done this from the beginning as a
precaution, though the condition never triggered because of the 0
ceiling).

> Maybe all I'm asking for is a more reassuring commit description.

I agree. I'm also waiting for rmk's ack.

Thanks.

-- 
Catalin

--
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>

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-02-19 22:56 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-18 16:18 [PATCH 0/2] Arch-specific user pgtables ceiling Catalin Marinas
2013-02-18 16:18 ` Catalin Marinas
2013-02-18 16:18 ` [PATCH 1/2] mm: Allow arch code to control the user page table ceiling Catalin Marinas
2013-02-18 16:18   ` Catalin Marinas
2013-02-19 18:08   ` Hugh Dickins
2013-02-19 18:08     ` Hugh Dickins
2013-02-19 22:33     ` Catalin Marinas
2013-02-19 22:33       ` Catalin Marinas
2013-02-18 16:18 ` [PATCH 2/2] arm: Set the page table freeing ceiling to TASK_SIZE Catalin Marinas
2013-02-18 16:18   ` Catalin Marinas
2013-02-19 18:20   ` Hugh Dickins
2013-02-19 18:20     ` Hugh Dickins
2013-02-19 22:55     ` Catalin Marinas
2013-02-19 22:55       ` Catalin Marinas

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.