* [PATCH v2] guard page for stacks that grow upwards
@ 2010-08-24 18:44 ` Luck, Tony
0 siblings, 0 replies; 5+ messages in thread
From: Luck, Tony @ 2010-08-24 18:44 UTC (permalink / raw)
To: Linus Torvalds; +Cc: linux-kernel, linux-parisc, linux-ia64
pa-risc and ia64 have stacks that grow upwards. Check that
they do not run into other mappings. By making VM_GROWSUP
0x0 on architectures that do not ever use it, we can avoid
some unpleasant #ifdefs in check_stack_guard_page().
Signed-off-by: Tony Luck <tony.luck@intel.com>
---
Built, booted & tested on ia64
Built for x86_64 (but not booted or tested)
pa-risc - untested
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 709f672..77e6336 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -78,7 +78,11 @@ extern unsigned int kobjsize(const void *objp);
#define VM_MAYSHARE 0x00000080
#define VM_GROWSDOWN 0x00000100 /* general info on the segment */
+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
#define VM_GROWSUP 0x00000200
+#else
+#define VM_GROWSUP 0x00000000
+#endif
#define VM_PFNMAP 0x00000400 /* Page-ranges managed without "struct page", just pure PFN */
#define VM_DENYWRITE 0x00000800 /* ETXTBSY on write attempts.. */
@@ -1330,8 +1334,10 @@ unsigned long ra_submit(struct file_ra_state *ra,
/* Do stack extension */
extern int expand_stack(struct vm_area_struct *vma, unsigned long address);
-#ifdef CONFIG_IA64
+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
extern int expand_upwards(struct vm_area_struct *vma, unsigned long address);
+#else
+#define expand_upwards(vma, address)
#endif
extern int expand_stack_downwards(struct vm_area_struct *vma,
unsigned long address);
diff --git a/mm/memory.c b/mm/memory.c
index 2ed2267..6b2ab10 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2760,11 +2760,9 @@ out_release:
}
/*
- * This is like a special single-page "expand_downwards()",
- * except we must first make sure that 'address-PAGE_SIZE'
+ * This is like a special single-page "expand_{down|up}wards()",
+ * except we must first make sure that 'address{-|+}PAGE_SIZE'
* doesn't hit another vma.
- *
- * The "find_vma()" will do the right thing even if we wrap
*/
static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
{
@@ -2783,6 +2781,15 @@ static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned lo
expand_stack(vma, address - PAGE_SIZE);
}
+ if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
+ struct vm_area_struct *next = vma->vm_next;
+
+ /* As VM_GROWSDOWN but s/below/above/ */
+ if (next && next->vm_start == address + PAGE_SIZE)
+ return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
+
+ expand_upwards(vma, address + PAGE_SIZE);
+ }
return 0;
}
diff --git a/mm/mmap.c b/mm/mmap.c
index 331e51a..6128dc8 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1716,9 +1716,6 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
* PA-RISC uses this for its stack; IA64 for its Register Backing Store.
* vma is the last one with address > vma->vm_end. Have to extend vma.
*/
-#ifndef CONFIG_IA64
-static
-#endif
int expand_upwards(struct vm_area_struct *vma, unsigned long address)
{
int error;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2] guard page for stacks that grow upwards
@ 2010-08-24 18:44 ` Luck, Tony
0 siblings, 0 replies; 5+ messages in thread
From: Luck, Tony @ 2010-08-24 18:44 UTC (permalink / raw)
To: Linus Torvalds; +Cc: linux-kernel, linux-parisc, linux-ia64
pa-risc and ia64 have stacks that grow upwards. Check that
they do not run into other mappings. By making VM_GROWSUP
0x0 on architectures that do not ever use it, we can avoid
some unpleasant #ifdefs in check_stack_guard_page().
Signed-off-by: Tony Luck <tony.luck@intel.com>
---
Built, booted & tested on ia64
Built for x86_64 (but not booted or tested)
pa-risc - untested
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 709f672..77e6336 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -78,7 +78,11 @@ extern unsigned int kobjsize(const void *objp);
#define VM_MAYSHARE 0x00000080
#define VM_GROWSDOWN 0x00000100 /* general info on the segment */
+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
#define VM_GROWSUP 0x00000200
+#else
+#define VM_GROWSUP 0x00000000
+#endif
#define VM_PFNMAP 0x00000400 /* Page-ranges managed without "struct page", just pure PFN */
#define VM_DENYWRITE 0x00000800 /* ETXTBSY on write attempts.. */
@@ -1330,8 +1334,10 @@ unsigned long ra_submit(struct file_ra_state *ra,
/* Do stack extension */
extern int expand_stack(struct vm_area_struct *vma, unsigned long address);
-#ifdef CONFIG_IA64
+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
extern int expand_upwards(struct vm_area_struct *vma, unsigned long address);
+#else
+#define expand_upwards(vma, address)
#endif
extern int expand_stack_downwards(struct vm_area_struct *vma,
unsigned long address);
diff --git a/mm/memory.c b/mm/memory.c
index 2ed2267..6b2ab10 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2760,11 +2760,9 @@ out_release:
}
/*
- * This is like a special single-page "expand_downwards()",
- * except we must first make sure that 'address-PAGE_SIZE'
+ * This is like a special single-page "expand_{down|up}wards()",
+ * except we must first make sure that 'address{-|+}PAGE_SIZE'
* doesn't hit another vma.
- *
- * The "find_vma()" will do the right thing even if we wrap
*/
static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
{
@@ -2783,6 +2781,15 @@ static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned lo
expand_stack(vma, address - PAGE_SIZE);
}
+ if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE = vma->vm_end) {
+ struct vm_area_struct *next = vma->vm_next;
+
+ /* As VM_GROWSDOWN but s/below/above/ */
+ if (next && next->vm_start = address + PAGE_SIZE)
+ return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
+
+ expand_upwards(vma, address + PAGE_SIZE);
+ }
return 0;
}
diff --git a/mm/mmap.c b/mm/mmap.c
index 331e51a..6128dc8 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1716,9 +1716,6 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
* PA-RISC uses this for its stack; IA64 for its Register Backing Store.
* vma is the last one with address > vma->vm_end. Have to extend vma.
*/
-#ifndef CONFIG_IA64
-static
-#endif
int expand_upwards(struct vm_area_struct *vma, unsigned long address)
{
int error;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] guard page for stacks that grow upwards
2010-08-24 18:44 ` Luck, Tony
@ 2010-08-24 20:19 ` Linus Torvalds
-1 siblings, 0 replies; 5+ messages in thread
From: Linus Torvalds @ 2010-08-24 20:19 UTC (permalink / raw)
To: Luck, Tony
Cc: linux-kernel, linux-parisc, linux-ia64, John David Anglin, Kyle McMartin
On Tue, Aug 24, 2010 at 11:44 AM, Luck, Tony <tony.luck@intel.com> wrote:
>
> Built, booted & tested on ia64
> Built for x86_64 (but not booted or tested)
> pa-risc - untested
Ok, applied. I do think we could do the "VM_GROWSDOWN = 0" trick for
PA-RISC (so that the code for the growsdown case would be compiled
away there), but that definitely needs somebody who actually cares
specifically about PA-RISC.
Adding the people who have signed off on parisc-specific patches in
recent memory to the cc. Maybe somebody could be convinced to care.
Linus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] guard page for stacks that grow upwards
@ 2010-08-24 20:19 ` Linus Torvalds
0 siblings, 0 replies; 5+ messages in thread
From: Linus Torvalds @ 2010-08-24 20:19 UTC (permalink / raw)
To: Luck, Tony
Cc: linux-kernel, linux-parisc, linux-ia64, John David Anglin, Kyle McMartin
On Tue, Aug 24, 2010 at 11:44 AM, Luck, Tony <tony.luck@intel.com> wrote:
>
> Built, booted & tested on ia64
> Built for x86_64 (but not booted or tested)
> pa-risc - untested
Ok, applied. I do think we could do the "VM_GROWSDOWN = 0" trick for
PA-RISC (so that the code for the growsdown case would be compiled
away there), but that definitely needs somebody who actually cares
specifically about PA-RISC.
Adding the people who have signed off on parisc-specific patches in
recent memory to the cc. Maybe somebody could be convinced to care.
Linus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] guard page for stacks that grow upwards
2010-08-24 20:19 ` Linus Torvalds
(?)
@ 2010-08-24 20:32 ` James Bottomley
-1 siblings, 0 replies; 5+ messages in thread
From: James Bottomley @ 2010-08-24 20:32 UTC (permalink / raw)
To: Linus Torvalds
Cc: Luck, Tony, linux-kernel, linux-parisc, linux-ia64,
John David Anglin, Kyle McMartin
On Tue, 2010-08-24 at 13:19 -0700, Linus Torvalds wrote:
> On Tue, Aug 24, 2010 at 11:44 AM, Luck, Tony <tony.luck@intel.com> wrote:
> >
> > Built, booted & tested on ia64
> > Built for x86_64 (but not booted or tested)
> > pa-risc - untested
>
> Ok, applied. I do think we could do the "VM_GROWSDOWN = 0" trick for
> PA-RISC (so that the code for the growsdown case would be compiled
> away there), but that definitely needs somebody who actually cares
> specifically about PA-RISC.
I can try it ... I was just getting ready to try the -rc2 kernel on our
cupertino test ring anyway.
James
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-08-24 20:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-24 18:44 [PATCH v2] guard page for stacks that grow upwards Luck, Tony
2010-08-24 18:44 ` Luck, Tony
2010-08-24 20:19 ` Linus Torvalds
2010-08-24 20:19 ` Linus Torvalds
2010-08-24 20:32 ` James Bottomley
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.