This patch adds a personality flag that requests hugetlb pages be used for
a processes stack.  It adds a helper function that chooses the proper ALIGN
macro based on tthe process personality and calls this function from
setup_arg_pages when aligning the stack address.

Signed-off-by: Andy Whitcroft <[EMAIL PROTECTED]>
Signed-off-by: Eric Munson <[EMAIL PROTECTED]>

---
Based on 2.6.26-rc8-mm1

Changes from V1:
Rebase to 2.6.26-rc8-mm1

 fs/exec.c                   |   15 ++++++++++++++-
 include/linux/hugetlb.h     |    3 +++
 include/linux/personality.h |    3 +++
 3 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index af9b29c..c99ba24 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -49,6 +49,7 @@
 #include <linux/tsacct_kern.h>
 #include <linux/cn_proc.h>
 #include <linux/audit.h>
+#include <linux/hugetlb.h>
 
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
@@ -155,6 +156,18 @@ exit:
        goto out;
 }
 
+static unsigned long personality_page_align(unsigned long addr)
+{
+       if (current->personality & HUGETLB_STACK)
+#ifdef CONFIG_STACK_GROWSUP
+               return HPAGE_ALIGN(addr);
+#else
+               return addr & HPAGE_MASK;
+#endif
+
+       return PAGE_ALIGN(addr);
+}
+
 #ifdef CONFIG_MMU
 
 static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
@@ -596,7 +609,7 @@ int setup_arg_pages(struct linux_binprm *bprm,
        bprm->p = vma->vm_end - stack_shift;
 #else
        stack_top = arch_align_stack(stack_top);
-       stack_top = PAGE_ALIGN(stack_top);
+       stack_top = personality_page_align(stack_top);
        stack_shift = vma->vm_end - stack_top;
 
        bprm->p -= stack_shift;
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 9a71d4c..eed37d7 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -95,6 +95,9 @@ static inline unsigned long hugetlb_total_pages(void)
 #ifndef HPAGE_MASK
 #define HPAGE_MASK     PAGE_MASK               /* Keep the compiler happy */
 #define HPAGE_SIZE     PAGE_SIZE
+
+/* to align the pointer to the (next) huge page boundary */
+#define HPAGE_ALIGN(addr)      ALIGN(addr, HPAGE_SIZE)
 #endif
 
 #endif /* !CONFIG_HUGETLB_PAGE */
diff --git a/include/linux/personality.h b/include/linux/personality.h
index a84e9ff..2bb0f95 100644
--- a/include/linux/personality.h
+++ b/include/linux/personality.h
@@ -22,6 +22,9 @@ extern int            __set_personality(unsigned long);
  * These occupy the top three bytes.
  */
 enum {
+       HUGETLB_STACK =         0x0020000,      /* Attempt to use hugetlb pages
+                                                * for the process stack
+                                                */
        ADDR_NO_RANDOMIZE =     0x0040000,      /* disable randomization of VA 
space */
        FDPIC_FUNCPTRS =        0x0080000,      /* userspace function ptrs 
point to descriptors
                                                 * (signal handling)
-- 
1.5.6.1

_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev

Reply via email to