All of lore.kernel.org
 help / color / mirror / Atom feed
* fully honor vdso_enabled [i386, sh; x86_64?]
@ 2007-02-22 20:31 John Reiser
  2007-02-28  9:11 ` Paul Mundt
  2007-02-28 15:13 ` Chuck Ebbert
  0 siblings, 2 replies; 4+ messages in thread
From: John Reiser @ 2007-02-22 20:31 UTC (permalink / raw)
  To: linux-kernel

Architectures such as i386, sh, x86_64 have a flag /proc/sys/vm/vdso_enabled
to choose whether the kernel should setup a process to use vdso after execve().
Informing the user code via AT_SYSINFO* is controlled by macro ARCH_DLINFO in
fs/binfmt_elf.c and include/asm-$ARCH/elf.h, but the vdso page is established
always via arch_setup_additonal_pages() called from load_elf_binary().
If vdso_enabled is off, then current code wastes kernel time during execve()
and fragments the address space unnecessarily.

This patch changes arch_setup_additonal_pages() to honor vdso_enabled.
For i386 it also allows the option of a fixed addresss to avoid
fragmenting the address space.  Compiles and runs on i386.
x86_64 [IA32 support] and sh maintainers also please comment.

For some related history, including interaction with exec-shield, see:
http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=229304
and also 207020 and 162797.


Signed-off-by: John Reiser <jreiser@BitWagon.com>

diff --git a/arch/i386/kernel/sysenter.c b/arch/i386/kernel/sysenter.c
index 13ca54a..f8c4d76 100644
--- a/arch/i386/kernel/sysenter.c
+++ b/arch/i386/kernel/sysenter.c
@@ -22,6 +22,8 @@
 #include <asm/msr.h>
 #include <asm/pgtable.h>
 #include <asm/unistd.h>
+#include <asm/a.out.h>
+#include <asm/mman.h>

 /*
  * Should the kernel map a VDSO page into processes and pass its
@@ -105,10 +107,25 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int exstack)
 {
 	struct mm_struct *mm = current->mm;
 	unsigned long addr;
+	unsigned long flags;
 	int ret;

+	switch (vdso_enabled) {
+	case 0:  /* none */
+		return 0;
+	default:
+	case 1:  /* vdso in random available page */
+		addr = 0ul;
+		flags = 0ul;
+		break;
+	case 2:  /* out of user's way */
+		addr = STACK_TOP;
+		flags = MAP_FIXED;
+		break;
+	}
+
 	down_write(&mm->mmap_sem);
-	addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
+	addr = get_unmapped_area(NULL, addr, PAGE_SIZE, 0, flags);
 	if (IS_ERR_VALUE(addr)) {
 		ret = addr;
 		goto up_fail;
diff --git a/arch/sh/kernel/vsyscall/vsyscall.c b/arch/sh/kernel/vsyscall/vsyscall.c
index 7b0f66f..2b789fb 100644
--- a/arch/sh/kernel/vsyscall/vsyscall.c
+++ b/arch/sh/kernel/vsyscall/vsyscall.c
@@ -64,6 +64,9 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,
 	unsigned long addr;
 	int ret;

+	if (!vdso_enabled)
+		return 0;
+
 	down_write(&mm->mmap_sem);
 	addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
 	if (IS_ERR_VALUE(addr)) {
diff --git a/include/asm-i386/a.out.h b/include/asm-i386/a.out.h
index ab17bb8..9894f73 100644
--- a/include/asm-i386/a.out.h
+++ b/include/asm-i386/a.out.h
@@ -19,7 +19,7 @@ struct exec

 #ifdef __KERNEL__

-#define STACK_TOP	TASK_SIZE
+#define STACK_TOP	(TASK_SIZE - PAGE_SIZE)  /* 1 page optional for vdso */

 #endif

-- 


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

* Re: fully honor vdso_enabled [i386, sh; x86_64?]
  2007-02-22 20:31 fully honor vdso_enabled [i386, sh; x86_64?] John Reiser
@ 2007-02-28  9:11 ` Paul Mundt
  2007-02-28 21:40   ` Andrew Morton
  2007-02-28 15:13 ` Chuck Ebbert
  1 sibling, 1 reply; 4+ messages in thread
From: Paul Mundt @ 2007-02-28  9:11 UTC (permalink / raw)
  To: John Reiser; +Cc: linux-kernel, Andrew Morton

On Thu, Feb 22, 2007 at 12:31:20PM -0800, John Reiser wrote:
> This patch changes arch_setup_additonal_pages() to honor vdso_enabled.
> For i386 it also allows the option of a fixed addresss to avoid
> fragmenting the address space.  Compiles and runs on i386.
> x86_64 [IA32 support] and sh maintainers also please comment.
> 
We didn't actually have the sysctl entry wired up on SH, but once that's
done, this patch works fine there too.

Andrew, do you want a separate patch for the vdso_enabled sysctl or
is it more convenient through my git tree?

Acked-by: Paul Mundt <lethal@linux-sh.org>

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

* Re: fully honor vdso_enabled [i386, sh; x86_64?]
  2007-02-22 20:31 fully honor vdso_enabled [i386, sh; x86_64?] John Reiser
  2007-02-28  9:11 ` Paul Mundt
@ 2007-02-28 15:13 ` Chuck Ebbert
  1 sibling, 0 replies; 4+ messages in thread
From: Chuck Ebbert @ 2007-02-28 15:13 UTC (permalink / raw)
  To: John Reiser; +Cc: linux-kernel, Andi Kleen, Ingo Molnar

[adding Andi and Ingo]

John Reiser wrote:
> Architectures such as i386, sh, x86_64 have a flag /proc/sys/vm/vdso_enabled
> to choose whether the kernel should setup a process to use vdso after execve().
> Informing the user code via AT_SYSINFO* is controlled by macro ARCH_DLINFO in
> fs/binfmt_elf.c and include/asm-$ARCH/elf.h, but the vdso page is established
> always via arch_setup_additonal_pages() called from load_elf_binary().
> If vdso_enabled is off, then current code wastes kernel time during execve()
> and fragments the address space unnecessarily.
> 
> This patch changes arch_setup_additonal_pages() to honor vdso_enabled.
> For i386 it also allows the option of a fixed addresss to avoid
> fragmenting the address space.  Compiles and runs on i386.
> x86_64 [IA32 support] and sh maintainers also please comment.
> 
> For some related history, including interaction with exec-shield, see:
> http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=229304
> and also 207020 and 162797.
> 
> 
> Signed-off-by: John Reiser <jreiser@BitWagon.com>
> 
> diff --git a/arch/i386/kernel/sysenter.c b/arch/i386/kernel/sysenter.c
> index 13ca54a..f8c4d76 100644
> --- a/arch/i386/kernel/sysenter.c
> +++ b/arch/i386/kernel/sysenter.c
> @@ -22,6 +22,8 @@
>  #include <asm/msr.h>
>  #include <asm/pgtable.h>
>  #include <asm/unistd.h>
> +#include <asm/a.out.h>
> +#include <asm/mman.h>
> 
>  /*
>   * Should the kernel map a VDSO page into processes and pass its
> @@ -105,10 +107,25 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int exstack)
>  {
>  	struct mm_struct *mm = current->mm;
>  	unsigned long addr;
> +	unsigned long flags;
>  	int ret;
> 
> +	switch (vdso_enabled) {
> +	case 0:  /* none */
> +		return 0;
> +	default:
> +	case 1:  /* vdso in random available page */
> +		addr = 0ul;
> +		flags = 0ul;
> +		break;
> +	case 2:  /* out of user's way */
> +		addr = STACK_TOP;
> +		flags = MAP_FIXED;
> +		break;
> +	}
> +
>  	down_write(&mm->mmap_sem);
> -	addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
> +	addr = get_unmapped_area(NULL, addr, PAGE_SIZE, 0, flags);
>  	if (IS_ERR_VALUE(addr)) {
>  		ret = addr;
>  		goto up_fail;
> diff --git a/arch/sh/kernel/vsyscall/vsyscall.c b/arch/sh/kernel/vsyscall/vsyscall.c
> index 7b0f66f..2b789fb 100644
> --- a/arch/sh/kernel/vsyscall/vsyscall.c
> +++ b/arch/sh/kernel/vsyscall/vsyscall.c
> @@ -64,6 +64,9 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,
>  	unsigned long addr;
>  	int ret;
> 
> +	if (!vdso_enabled)
> +		return 0;
> +
>  	down_write(&mm->mmap_sem);
>  	addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
>  	if (IS_ERR_VALUE(addr)) {
> diff --git a/include/asm-i386/a.out.h b/include/asm-i386/a.out.h
> index ab17bb8..9894f73 100644
> --- a/include/asm-i386/a.out.h
> +++ b/include/asm-i386/a.out.h
> @@ -19,7 +19,7 @@ struct exec
> 
>  #ifdef __KERNEL__
> 
> -#define STACK_TOP	TASK_SIZE
> +#define STACK_TOP	(TASK_SIZE - PAGE_SIZE)  /* 1 page optional for vdso */
> 
>  #endif
> 


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

* Re: fully honor vdso_enabled [i386, sh; x86_64?]
  2007-02-28  9:11 ` Paul Mundt
@ 2007-02-28 21:40   ` Andrew Morton
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2007-02-28 21:40 UTC (permalink / raw)
  To: Paul Mundt; +Cc: John Reiser, linux-kernel

On Wed, 28 Feb 2007 18:11:11 +0900
Paul Mundt <lethal@linux-sh.org> wrote:

> On Thu, Feb 22, 2007 at 12:31:20PM -0800, John Reiser wrote:
> > This patch changes arch_setup_additonal_pages() to honor vdso_enabled.
> > For i386 it also allows the option of a fixed addresss to avoid
> > fragmenting the address space.  Compiles and runs on i386.
> > x86_64 [IA32 support] and sh maintainers also please comment.
> > 
> We didn't actually have the sysctl entry wired up on SH, but once that's
> done, this patch works fine there too.
> 
> Andrew, do you want a separate patch for the vdso_enabled sysctl or
> is it more convenient through my git tree?
> 

If it's an sh-only thing then through your tree is fine, thanks.

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

end of thread, other threads:[~2007-02-28 21:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-22 20:31 fully honor vdso_enabled [i386, sh; x86_64?] John Reiser
2007-02-28  9:11 ` Paul Mundt
2007-02-28 21:40   ` Andrew Morton
2007-02-28 15:13 ` Chuck Ebbert

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.