public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] NOMMU: Optimise away the {dac_,}mmap_min_addr tests
@ 2009-12-16 23:55 David Howells
  2009-12-16 23:56 ` [PATCH 2/6] NOMMU: Provide per-task stack usage through /proc for NOMMU David Howells
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: David Howells @ 2009-12-16 23:55 UTC (permalink / raw)
  To: torvalds, akpm
  Cc: dhowells, vapier, lethal, linux-kernel, uclinux-dev,
	David Howells, Eric Paris

In NOMMU mode clamp dac_mmap_min_addr to zero to cause the tests on it to be
skipped by the compiler.  We do this as the minimum mmap address doesn't make
any sense in NOMMU mode.

mmap_min_addr and round_hint_to_min() can be discarded entirely in NOMMU mode.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Eric Paris <eparis@redhat.com>
---

 include/linux/security.h |    7 +++++++
 kernel/sysctl.c          |    2 ++
 mm/Kconfig               |    1 +
 security/Makefile        |    3 ++-
 4 files changed, 12 insertions(+), 1 deletions(-)


diff --git a/include/linux/security.h b/include/linux/security.h
index 466cbad..2c627d3 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -95,8 +95,13 @@ struct seq_file;
 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
 extern int cap_netlink_recv(struct sk_buff *skb, int cap);
 
+#ifdef CONFIG_MMU
 extern unsigned long mmap_min_addr;
 extern unsigned long dac_mmap_min_addr;
+#else
+#define dac_mmap_min_addr	0UL
+#endif
+
 /*
  * Values used in the task_security_ops calls
  */
@@ -121,6 +126,7 @@ struct request_sock;
 #define LSM_UNSAFE_PTRACE	2
 #define LSM_UNSAFE_PTRACE_CAP	4
 
+#ifdef CONFIG_MMU
 /*
  * If a hint addr is less than mmap_min_addr change hint to be as
  * low as possible but still greater than mmap_min_addr
@@ -135,6 +141,7 @@ static inline unsigned long round_hint_to_min(unsigned long hint)
 }
 extern int mmap_min_addr_handler(struct ctl_table *table, int write,
 				 void __user *buffer, size_t *lenp, loff_t *ppos);
+#endif
 
 #ifdef CONFIG_SECURITY
 
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 45e4bef..856a24e 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1214,6 +1214,7 @@ static struct ctl_table vm_table[] = {
 		.proc_handler	= proc_dointvec_jiffies,
 	},
 #endif
+#ifdef CONFIG_MMU
 	{
 		.procname	= "mmap_min_addr",
 		.data		= &dac_mmap_min_addr,
@@ -1221,6 +1222,7 @@ static struct ctl_table vm_table[] = {
 		.mode		= 0644,
 		.proc_handler	= mmap_min_addr_handler,
 	},
+#endif
 #ifdef CONFIG_NUMA
 	{
 		.procname	= "numa_zonelist_order",
diff --git a/mm/Kconfig b/mm/Kconfig
index 43ea8c3..ee9f3e0 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -221,6 +221,7 @@ config KSM
 
 config DEFAULT_MMAP_MIN_ADDR
         int "Low address space to protect from user allocation"
+	depends on MMU
         default 4096
         help
 	  This is the portion of low virtual memory which should be protected
diff --git a/security/Makefile b/security/Makefile
index bb44e35..da20a19 100644
--- a/security/Makefile
+++ b/security/Makefile
@@ -8,7 +8,8 @@ subdir-$(CONFIG_SECURITY_SMACK)		+= smack
 subdir-$(CONFIG_SECURITY_TOMOYO)        += tomoyo
 
 # always enable default capabilities
-obj-y		+= commoncap.o min_addr.o
+obj-y					+= commoncap.o
+obj-$(CONFIG_MMU)			+= min_addr.o
 
 # Object file lists
 obj-$(CONFIG_SECURITY)			+= security.o capability.o


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

* [PATCH 2/6] NOMMU: Provide per-task stack usage through /proc for NOMMU
  2009-12-16 23:55 [PATCH 1/6] NOMMU: Optimise away the {dac_,}mmap_min_addr tests David Howells
@ 2009-12-16 23:56 ` David Howells
  2009-12-17  7:21   ` Stefani Seibold
  2009-12-16 23:56 ` [PATCH 3/6] FDPIC: Respect PT_GNU_STACK exec protection markings when creating NOMMU stack David Howells
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: David Howells @ 2009-12-16 23:56 UTC (permalink / raw)
  To: torvalds, akpm
  Cc: dhowells, vapier, lethal, linux-kernel, uclinux-dev,
	David Howells, Mike Frysinger, Stefani Seibold, Paul Mundt,
	Robin Getz

Make it possible to get the per-task stack usage through /proc on a NOMMU
system.  The MMU-mode routine can't be used because walk_page_range() doesn't
work on NOMMU.

It can be tested to show the stack usages of non-kernel-thread processes:

	# grep "Stack usage:" /proc/*/status | grep -v "0 kB"
	/proc/1/status:Stack usage:     2 kB
	/proc/57/status:Stack usage:    3 kB
	/proc/58/status:Stack usage:    1 kB
	/proc/59/status:Stack usage:    3 kB
	/proc/60/status:Stack usage:    5 kB
	/proc/self/status:Stack usage:  1 kB

I've only tested it with ELF-FDPIC, though it should work with FLAT too.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Cc: Stefani Seibold <stefani@seibold.net>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: Robin Getz <rgetz@blackfin.uclinux.org>
---

 fs/proc/array.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)


diff --git a/fs/proc/array.c b/fs/proc/array.c
index 4badde1..c67251e 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -387,8 +387,7 @@ static inline unsigned long get_stack_usage_in_bytes(struct vm_area_struct *vma,
 	return ss.usage;
 }
 
-static inline void task_show_stack_usage(struct seq_file *m,
-						struct task_struct *task)
+static void task_show_stack_usage(struct seq_file *m, struct task_struct *task)
 {
 	struct vm_area_struct	*vma;
 	struct mm_struct	*mm = get_task_mm(task);
@@ -404,9 +403,24 @@ static inline void task_show_stack_usage(struct seq_file *m,
 		mmput(mm);
 	}
 }
-#else
+#else /* CONFIG_MMU */
+/*
+ * Calculate the size of a NOMMU process's stack
+ */
 static void task_show_stack_usage(struct seq_file *m, struct task_struct *task)
 {
+	unsigned long sp, base, usage;
+
+	base = task->stack_start;
+	sp = KSTK_ESP(task);
+
+#ifdef CONFIG_STACK_GROWSUP
+	usage = sp - base;
+#else
+	usage = base - sp;
+#endif
+
+	seq_printf(m, "Stack usage:\t%lu kB\n", (usage + 1023) >> 10);
 }
 #endif		/* CONFIG_MMU */
 


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

* [PATCH 3/6] FDPIC: Respect PT_GNU_STACK exec protection markings when creating NOMMU stack
  2009-12-16 23:55 [PATCH 1/6] NOMMU: Optimise away the {dac_,}mmap_min_addr tests David Howells
  2009-12-16 23:56 ` [PATCH 2/6] NOMMU: Provide per-task stack usage through /proc for NOMMU David Howells
@ 2009-12-16 23:56 ` David Howells
  2009-12-16 23:56 ` [PATCH 4/6] NOMMU: Avoiding duplicate icache flushes of shared maps David Howells
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: David Howells @ 2009-12-16 23:56 UTC (permalink / raw)
  To: torvalds, akpm
  Cc: dhowells, vapier, lethal, linux-kernel, uclinux-dev,
	Mike Frysinger, David Howells

From: Mike Frysinger <vapier@gentoo.org>

The current code will load the stack size and protection markings, but then
only use the markings in the MMU code path.  The NOMMU code path always passes
PROT_EXEC to the mmap() call.  While this doesn't matter to most people whilst
the code is running, it will cause a pointless icache flush when starting every
FDPIC application.  Typically this icache flush will be of a region on the
order of 128KB in size, or may be the entire icache, depending on the
facilities available on the CPU.

In the case where the arch default behaviour seems to be desired
(EXSTACK_DEFAULT), we probe VM_STACK_FLAGS for VM_EXEC to determine whether we
should be setting PROT_EXEC or not.

For arches that support an MPU (Memory Protection Unit - an MMU without the
virtual mapping capability), setting PROT_EXEC or not will make an important
difference.

It should be noted that this change also affects the executability of the brk
region, since ELF-FDPIC has that share with the stack.  However, this is
probably irrelevant as NOMMU programs aren't likely to use the brk region,
preferring instead allocation via mmap().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 arch/blackfin/include/asm/page.h |    5 +++++
 arch/frv/include/asm/page.h      |    2 --
 fs/binfmt_elf_fdpic.c            |   13 +++++++++++--
 3 files changed, 16 insertions(+), 4 deletions(-)


diff --git a/arch/blackfin/include/asm/page.h b/arch/blackfin/include/asm/page.h
index 944a07c..1d04e40 100644
--- a/arch/blackfin/include/asm/page.h
+++ b/arch/blackfin/include/asm/page.h
@@ -10,4 +10,9 @@
 #include <asm-generic/page.h>
 #define MAP_NR(addr) (((unsigned long)(addr)-PAGE_OFFSET) >> PAGE_SHIFT)
 
+#define VM_DATA_DEFAULT_FLAGS \
+	(VM_READ | VM_WRITE | \
+	((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
+		 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
+
 #endif
diff --git a/arch/frv/include/asm/page.h b/arch/frv/include/asm/page.h
index 25c6a50..8c97068 100644
--- a/arch/frv/include/asm/page.h
+++ b/arch/frv/include/asm/page.h
@@ -63,12 +63,10 @@ extern unsigned long max_pfn;
 #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
 
 
-#ifdef CONFIG_MMU
 #define VM_DATA_DEFAULT_FLAGS \
 	(VM_READ | VM_WRITE | \
 	((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
 		 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
-#endif
 
 #endif /* __ASSEMBLY__ */
 
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index 7b05538..5a3ec95 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -171,6 +171,9 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm,
 #ifdef ELF_FDPIC_PLAT_INIT
 	unsigned long dynaddr;
 #endif
+#ifndef CONFIG_MMU
+	unsigned long stack_prot;
+#endif
 	struct file *interpreter = NULL; /* to shut gcc up */
 	char *interpreter_name = NULL;
 	int executable_stack;
@@ -316,6 +319,8 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm,
 	 * defunct, deceased, etc. after this point we have to exit via
 	 * error_kill */
 	set_personality(PER_LINUX_FDPIC);
+	if (elf_read_implies_exec(&exec_params.hdr, executable_stack))
+		current->personality |= READ_IMPLIES_EXEC;
 	set_binfmt(&elf_fdpic_format);
 
 	current->mm->start_code = 0;
@@ -377,9 +382,13 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm,
 	if (stack_size < PAGE_SIZE * 2)
 		stack_size = PAGE_SIZE * 2;
 
+	stack_prot = PROT_READ | PROT_WRITE;
+	if (executable_stack == EXSTACK_ENABLE_X ||
+	    (executable_stack == EXSTACK_DEFAULT && VM_STACK_FLAGS & VM_EXEC))
+		stack_prot |= PROT_EXEC;
+
 	down_write(&current->mm->mmap_sem);
-	current->mm->start_brk = do_mmap(NULL, 0, stack_size,
-					 PROT_READ | PROT_WRITE | PROT_EXEC,
+	current->mm->start_brk = do_mmap(NULL, 0, stack_size, stack_prot,
 					 MAP_PRIVATE | MAP_ANONYMOUS |
 					 MAP_UNINITIALIZED | MAP_GROWSDOWN,
 					 0);


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

* [PATCH 4/6] NOMMU: Avoiding duplicate icache flushes of shared maps
  2009-12-16 23:55 [PATCH 1/6] NOMMU: Optimise away the {dac_,}mmap_min_addr tests David Howells
  2009-12-16 23:56 ` [PATCH 2/6] NOMMU: Provide per-task stack usage through /proc for NOMMU David Howells
  2009-12-16 23:56 ` [PATCH 3/6] FDPIC: Respect PT_GNU_STACK exec protection markings when creating NOMMU stack David Howells
@ 2009-12-16 23:56 ` David Howells
  2009-12-16 23:56 ` [PATCH 5/6] NOMMU: Use copy_*_user_page() in access_process_vm() David Howells
  2009-12-16 23:56 ` [PATCH 6/6] NOMMU: ramfs: Drop unused local var David Howells
  4 siblings, 0 replies; 7+ messages in thread
From: David Howells @ 2009-12-16 23:56 UTC (permalink / raw)
  To: torvalds, akpm
  Cc: dhowells, vapier, lethal, linux-kernel, uclinux-dev,
	David Howells, Mike Frysinger

From: Mike Frysinger <vapier.adi@gmail.com>

When working with FDPIC, there are many shared mappings of read-only code
regions between applications (the C library, applet packages like busybox,
etc.), but the current do_mmap_pgoff() function will issue an icache flush
whenever a VMA is added to an MM instead of only doing it when the map is
initially created.

The flush can instead be done when a region is first mmapped PROT_EXEC.  Note
that we may not rely on the first mapping of a region being executable - it's
possible for it to be PROT_READ only, so we have to remember whether we've
flushed the region or not, and then flush the entire region when a bit of it is
made executable.

However, this also affects the brk area.  That will no longer be executable.
We can mprotect() it to PROT_EXEC on MPU-mode kernels, but for NOMMU mode
kernels, when it increases the brk allocation, making sys_brk() flush the extra
from the icache should suffice.  The brk area probably isn't used by NOMMU
programs since the brk area can only use up the leavings from the stack
allocation, where the stack allocation is larger than requested.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---

 include/linux/mm_types.h |    2 ++
 mm/nommu.c               |   11 ++++++++---
 2 files changed, 10 insertions(+), 3 deletions(-)


diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 84a524a..84d020b 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -123,6 +123,8 @@ struct vm_region {
 	struct file	*vm_file;	/* the backing file or NULL */
 
 	atomic_t	vm_usage;	/* region usage count */
+	bool		vm_icache_flushed : 1; /* true if the icache has been flushed for
+						* this region */
 };
 
 /*
diff --git a/mm/nommu.c b/mm/nommu.c
index 8687973..db52886 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -432,6 +432,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
 	/*
 	 * Ok, looks good - let it rip.
 	 */
+	flush_icache_range(mm->brk, brk);
 	return mm->brk = brk;
 }
 
@@ -1353,10 +1354,14 @@ unsigned long do_mmap_pgoff(struct file *file,
 share:
 	add_vma_to_mm(current->mm, vma);
 
-	up_write(&nommu_region_sem);
+	/* we flush the region from the icache only when the first executable
+	 * mapping of it is made  */
+	if (vma->vm_flags & VM_EXEC && !region->vm_icache_flushed) {
+		flush_icache_range(region->vm_start, region->vm_end);
+		region->vm_icache_flushed = true;
+	}
 
-	if (prot & PROT_EXEC)
-		flush_icache_range(result, result + len);
+	up_write(&nommu_region_sem);
 
 	kleave(" = %lx", result);
 	return result;


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

* [PATCH 5/6] NOMMU: Use copy_*_user_page() in access_process_vm()
  2009-12-16 23:55 [PATCH 1/6] NOMMU: Optimise away the {dac_,}mmap_min_addr tests David Howells
                   ` (2 preceding siblings ...)
  2009-12-16 23:56 ` [PATCH 4/6] NOMMU: Avoiding duplicate icache flushes of shared maps David Howells
@ 2009-12-16 23:56 ` David Howells
  2009-12-16 23:56 ` [PATCH 6/6] NOMMU: ramfs: Drop unused local var David Howells
  4 siblings, 0 replies; 7+ messages in thread
From: David Howells @ 2009-12-16 23:56 UTC (permalink / raw)
  To: torvalds, akpm
  Cc: dhowells, vapier, lethal, linux-kernel, uclinux-dev, Jie Zhang,
	Mike Frysinger, David Howells, David McCullough, Paul Mundt,
	Greg Ungerer

From: Jie Zhang <jie.zhang@analog.com>

The MMU code uses the copy_*_user_page() variants in access_process_vm()
rather than copy_*_user() as the former includes an icache flush.  This is
important when doing things like setting software breakpoints with gdb.
So switch the NOMMU code over to do the same.

This patch makes the reasonable assumption that copy_from_user_page() won't
fail - which is probably fine, as we've checked the VMA from which we're
copying is usable, and the copy is not allowed to cross VMAs.  The one case
where it might go wrong is if the VMA is a device rather than RAM, and that
device returns an error which - in which case rubbish will be returned rather
than EIO.

Signed-off-by: Jie Zhang <jie.zhang@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: David McCullough <david_mccullough@mcafee.com>
Acked-by: Paul Mundt <lethal@linux-sh.org>
Acked-by: Greg Ungerer <gerg@uclinux.org>
---

 mm/nommu.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)


diff --git a/mm/nommu.c b/mm/nommu.c
index db52886..1e1ecb2 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1896,9 +1896,11 @@ int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, in
 
 		/* only read or write mappings where it is permitted */
 		if (write && vma->vm_flags & VM_MAYWRITE)
-			len -= copy_to_user((void *) addr, buf, len);
+			copy_to_user_page(vma, NULL, addr,
+					 (void *) addr, buf, len);
 		else if (!write && vma->vm_flags & VM_MAYREAD)
-			len -= copy_from_user(buf, (void *) addr, len);
+			copy_from_user_page(vma, NULL, addr,
+					    buf, (void *) addr, len);
 		else
 			len = 0;
 	} else {


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

* [PATCH 6/6] NOMMU: ramfs: Drop unused local var
  2009-12-16 23:55 [PATCH 1/6] NOMMU: Optimise away the {dac_,}mmap_min_addr tests David Howells
                   ` (3 preceding siblings ...)
  2009-12-16 23:56 ` [PATCH 5/6] NOMMU: Use copy_*_user_page() in access_process_vm() David Howells
@ 2009-12-16 23:56 ` David Howells
  4 siblings, 0 replies; 7+ messages in thread
From: David Howells @ 2009-12-16 23:56 UTC (permalink / raw)
  To: torvalds, akpm
  Cc: dhowells, vapier, lethal, linux-kernel, uclinux-dev,
	Mike Frysinger, David Howells

From: Mike Frysinger <vapier@gentoo.org>

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/ramfs/file-nommu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)


diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c
index 32fae40..2efc571 100644
--- a/fs/ramfs/file-nommu.c
+++ b/fs/ramfs/file-nommu.c
@@ -60,7 +60,7 @@ const struct inode_operations ramfs_file_inode_operations = {
  */
 int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize)
 {
-	unsigned long npages, xpages, loop, limit;
+	unsigned long npages, xpages, loop;
 	struct page *pages;
 	unsigned order;
 	void *data;


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

* Re: [PATCH 2/6] NOMMU: Provide per-task stack usage through /proc for NOMMU
  2009-12-16 23:56 ` [PATCH 2/6] NOMMU: Provide per-task stack usage through /proc for NOMMU David Howells
@ 2009-12-17  7:21   ` Stefani Seibold
  0 siblings, 0 replies; 7+ messages in thread
From: Stefani Seibold @ 2009-12-17  7:21 UTC (permalink / raw)
  To: David Howells
  Cc: torvalds, akpm, vapier, lethal, linux-kernel, uclinux-dev,
	Robin Getz

Am Mittwoch, den 16.12.2009, 23:56 +0000 schrieb David Howells:
> Make it possible to get the per-task stack usage through /proc on a NOMMU
> system.  The MMU-mode routine can't be used because walk_page_range() doesn't
> work on NOMMU.
> 
> It can be tested to show the stack usages of non-kernel-thread processes:
> 
> 	# grep "Stack usage:" /proc/*/status | grep -v "0 kB"
> 	/proc/1/status:Stack usage:     2 kB
> 	/proc/57/status:Stack usage:    3 kB
> 	/proc/58/status:Stack usage:    1 kB
> 	/proc/59/status:Stack usage:    3 kB
> 	/proc/60/status:Stack usage:    5 kB
> 	/proc/self/status:Stack usage:  1 kB
> 
> I've only tested it with ELF-FDPIC, though it should work with FLAT too.
> 
> Signed-off-by: David Howells <dhowells@redhat.com>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> Cc: Stefani Seibold <stefani@seibold.net>
> Cc: Paul Mundt <lethal@linux-sh.org>
> Cc: Robin Getz <rgetz@blackfin.uclinux.org>

Acked-by: stefani@seibold.net

> ---
> 
>  fs/proc/array.c |   20 +++++++++++++++++---
>  1 files changed, 17 insertions(+), 3 deletions(-)
> 
> 
> diff --git a/fs/proc/array.c b/fs/proc/array.c
> index 4badde1..c67251e 100644
> --- a/fs/proc/array.c
> +++ b/fs/proc/array.c
> @@ -387,8 +387,7 @@ static inline unsigned long get_stack_usage_in_bytes(struct vm_area_struct *vma,
>  	return ss.usage;
>  }
>  
> -static inline void task_show_stack_usage(struct seq_file *m,
> -						struct task_struct *task)
> +static void task_show_stack_usage(struct seq_file *m, struct task_struct *task)
>  {
>  	struct vm_area_struct	*vma;
>  	struct mm_struct	*mm = get_task_mm(task);
> @@ -404,9 +403,24 @@ static inline void task_show_stack_usage(struct seq_file *m,
>  		mmput(mm);
>  	}
>  }
> -#else
> +#else /* CONFIG_MMU */
> +/*
> + * Calculate the size of a NOMMU process's stack
> + */
>  static void task_show_stack_usage(struct seq_file *m, struct task_struct *task)
>  {
> +	unsigned long sp, base, usage;
> +
> +	base = task->stack_start;
> +	sp = KSTK_ESP(task);
> +
> +#ifdef CONFIG_STACK_GROWSUP
> +	usage = sp - base;
> +#else
> +	usage = base - sp;
> +#endif
> +
> +	seq_printf(m, "Stack usage:\t%lu kB\n", (usage + 1023) >> 10);
>  }
>  #endif		/* CONFIG_MMU */
>  
> 



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

end of thread, other threads:[~2009-12-17  7:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-16 23:55 [PATCH 1/6] NOMMU: Optimise away the {dac_,}mmap_min_addr tests David Howells
2009-12-16 23:56 ` [PATCH 2/6] NOMMU: Provide per-task stack usage through /proc for NOMMU David Howells
2009-12-17  7:21   ` Stefani Seibold
2009-12-16 23:56 ` [PATCH 3/6] FDPIC: Respect PT_GNU_STACK exec protection markings when creating NOMMU stack David Howells
2009-12-16 23:56 ` [PATCH 4/6] NOMMU: Avoiding duplicate icache flushes of shared maps David Howells
2009-12-16 23:56 ` [PATCH 5/6] NOMMU: Use copy_*_user_page() in access_process_vm() David Howells
2009-12-16 23:56 ` [PATCH 6/6] NOMMU: ramfs: Drop unused local var David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox