* [PATCH] NOMMU: add [stack] label to per-process maps output
@ 2009-12-15 23:55 Mike Frysinger
2009-12-16 8:54 ` David Howells
2009-12-16 16:59 ` David Howells
0 siblings, 2 replies; 9+ messages in thread
From: Mike Frysinger @ 2009-12-15 23:55 UTC (permalink / raw)
To: uclinux-dev, David Howells, David McCullough, Greg Ungerer,
Paul Mundt
Cc: uclinux-dist-devel, linux-kernel
Add support to the NOMMU per-process proc maps file to show which mapping
is the stack. This is largely based on the MMU code.
root:/> cat /proc/self/maps
02064000-02067ccc rw-p 0004d000 00:01 22 /bin/busybox
0206e000-0206f35c rw-p 00006000 00:01 295 /lib/ld-uClibc.so.0
025f0000-025f6f0c r-xs 00000000 00:01 295 /lib/ld-uClibc.so.0
02680000-026ba6b0 r-xs 00000000 00:01 297 /lib/libc.so.0
02700000-0274d384 r-xs 00000000 00:01 22 /bin/busybox
02816000-02817000 rw-p 00000000 00:00 0
02848000-0284c0d8 rw-p 00000000 00:00 0
02860000-02880000 rw-p 00000000 00:00 0 [stack]
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
it'd be cool if the global /proc/maps could display something like
[stack/<pid>], but i can't quite divine how to get a mm_struct out
of a vm_region without having to walk the entire process list.
fs/proc/task_nommu.c | 20 ++++++++++++++++----
1 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
index 5d9fd64..283b5c0 100644
--- a/fs/proc/task_nommu.c
+++ b/fs/proc/task_nommu.c
@@ -121,11 +121,20 @@ int task_statm(struct mm_struct *mm, int *shared, int *text,
return size;
}
+static void pad_len_spaces(struct seq_file *m, int len)
+{
+ len = 25 + sizeof(void*) * 6 - len;
+ if (len < 1)
+ len = 1;
+ seq_printf(m, "%*c", len, ' ');
+}
+
/*
* display a single VMA to a sequenced file
*/
static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
{
+ struct mm_struct *mm = vma->vm_mm;
unsigned long ino = 0;
struct file *file;
dev_t dev = 0;
@@ -154,11 +163,14 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
MAJOR(dev), MINOR(dev), ino, &len);
if (file) {
- len = 25 + sizeof(void *) * 6 - len;
- if (len < 1)
- len = 1;
- seq_printf(m, "%*c", len, ' ');
+ pad_len_spaces(m, len);
seq_path(m, &file->f_path, "");
+ } else if (mm) {
+ if (vma->vm_start <= mm->start_brk &&
+ vma->vm_end >= mm->brk) {
+ pad_len_spaces(m, len);
+ seq_puts(m, "[stack]");
+ }
}
seq_putc(m, '\n');
--
1.6.5.5
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] NOMMU: add [stack] label to per-process maps output
2009-12-15 23:55 [PATCH] NOMMU: add [stack] label to per-process maps output Mike Frysinger
@ 2009-12-16 8:54 ` David Howells
2009-12-16 16:59 ` David Howells
1 sibling, 0 replies; 9+ messages in thread
From: David Howells @ 2009-12-16 8:54 UTC (permalink / raw)
To: Mike Frysinger
Cc: dhowells, uclinux-dev, David McCullough, Greg Ungerer, Paul Mundt,
uclinux-dist-devel, linux-kernel
Mike Frysinger <vapier@gentoo.org> wrote:
> it'd be cool if the global /proc/maps could display something like
> [stack/<pid>], but i can't quite divine how to get a mm_struct out
> of a vm_region without having to walk the entire process list.
Tricky. vm_regions can be shared between multiple mm_structs, although in the
case of the stack, they're probably not. Furthermore, there's no interface to
mmap() to say the region you're allocating belongs to a particular PID (and
with userspace created threads, you have to create the stack _before_ calling
clone()).
That said, you could add a 'creator pid' to the vm_region. This could be set
firstly by mmap() to current->pid, and then overridden by clone() for the
stack VMA. It would be approximate, but probably a good approximation. You
probably don't actually need a back pointer, just an integer PID.
David
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] NOMMU: add [stack] label to per-process maps output
2009-12-15 23:55 [PATCH] NOMMU: add [stack] label to per-process maps output Mike Frysinger
2009-12-16 8:54 ` David Howells
@ 2009-12-16 16:59 ` David Howells
2009-12-16 19:36 ` [uClinux-dev] " Mike Frysinger
` (4 more replies)
1 sibling, 5 replies; 9+ messages in thread
From: David Howells @ 2009-12-16 16:59 UTC (permalink / raw)
To: Mike Frysinger
Cc: dhowells, uclinux-dev, David McCullough, Greg Ungerer, Paul Mundt,
uclinux-dist-devel, linux-kernel
Mike Frysinger <vapier@gentoo.org> wrote:
> + if (vma->vm_start <= mm->start_brk &&
> + vma->vm_end >= mm->brk) {
Hmmm... That ought to involve mm->start_stack somewhere... (Or, more
probably, task->stack_start:-/)
David
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [uClinux-dev] Re: [PATCH] NOMMU: add [stack] label to per-process maps output
2009-12-16 16:59 ` David Howells
@ 2009-12-16 19:36 ` Mike Frysinger
2009-12-17 22:49 ` Mike Frysinger
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Mike Frysinger @ 2009-12-16 19:36 UTC (permalink / raw)
To: uClinux development list
Cc: linux-kernel, Greg Ungerer, uclinux-dist-devel, David McCullough
On Wed, Dec 16, 2009 at 11:59, David Howells wrote:
> Mike Frysinger wrote:
>
>> + if (vma->vm_start <= mm->start_brk &&
>> + vma->vm_end >= mm->brk) {
>
> Hmmm... That ought to involve mm->start_stack somewhere... (Or, more
> probably, task->stack_start:-/)
in practice, it's probably always the same result, but you're right of
course. when i looked through the elf_fdpic code, i looked at the
start_brk mmap() and missed the later start_stack assignment later on.
-mike
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [uClinux-dev] Re: [PATCH] NOMMU: add [stack] label to per-process maps output
2009-12-16 16:59 ` David Howells
2009-12-16 19:36 ` [uClinux-dev] " Mike Frysinger
@ 2009-12-17 22:49 ` Mike Frysinger
2009-12-17 23:27 ` David Howells
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Mike Frysinger @ 2009-12-17 22:49 UTC (permalink / raw)
To: uClinux development list
Cc: linux-kernel, Greg Ungerer, uclinux-dist-devel, David McCullough
On Wed, Dec 16, 2009 at 11:59, David Howells wrote:
> Mike Frysinger wrote:
>> + if (vma->vm_start <= mm->start_brk &&
>> + vma->vm_end >= mm->brk) {
>
> Hmmm... That ought to involve mm->start_stack somewhere... (Or, more
> probably, task->stack_start:-/)
with MMU, the [heap] (i.e. brk) and [stack] are different mappings.
under NOMMU, they're the same mapping, except that no one uses the brk
and the "heap" is really all of dynamic kernel memory. so we have to
avoid the brk/[heap] check and simply copy over the [stack] one:
} else if (mm) {
if (vma->vm_start <= mm->start_stack &&
vma->vm_end >= mm->start_stack) {
pad_len_spaces(m, len);
seq_puts(m, "[stack]");
}
}
the semi-annoying thing is that FLAT combines a whole lot of stuff
(including the stack) into the same mapping giving us the output:
root:/> cat /proc/155/maps
029f0000-029f9000 rwxp 00000000 00:00 0 [stack]
but i guess this is no worse than the current ?
-mike
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [uClinux-dev] Re: [PATCH] NOMMU: add [stack] label to per-process maps output
2009-12-16 16:59 ` David Howells
2009-12-16 19:36 ` [uClinux-dev] " Mike Frysinger
2009-12-17 22:49 ` Mike Frysinger
@ 2009-12-17 23:27 ` David Howells
2009-12-21 14:35 ` [PATCH v2] " Mike Frysinger
2009-12-22 15:58 ` David Howells
4 siblings, 0 replies; 9+ messages in thread
From: David Howells @ 2009-12-17 23:27 UTC (permalink / raw)
To: uClinux development list
Cc: dhowells, uclinux-dist-devel, linux-kernel, David McCullough,
Greg Ungerer
Mike Frysinger <vapier.adi@gmail.com> wrote:
> but i guess this is no worse than the current ?
Indeed.
David
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] NOMMU: add [stack] label to per-process maps output
2009-12-16 16:59 ` David Howells
` (2 preceding siblings ...)
2009-12-17 23:27 ` David Howells
@ 2009-12-21 14:35 ` Mike Frysinger
2009-12-22 15:58 ` David Howells
4 siblings, 0 replies; 9+ messages in thread
From: Mike Frysinger @ 2009-12-21 14:35 UTC (permalink / raw)
To: uclinux-dev, David Howells, David McCullough, Greg Ungerer,
Paul Mundt
Cc: linux-kernel, uclinux-dist-devel
Add support to the NOMMU per-process proc maps file to show which mapping
is the stack. This is largely based on the MMU code.
For FDPIC, we now get:
root:/> cat /proc/self/maps
02064000-02067ccc rw-p 0004d000 00:01 22 /bin/busybox
0206e000-0206f35c rw-p 00006000 00:01 295 /lib/ld-uClibc.so.0
025f0000-025f6f0c r-xs 00000000 00:01 295 /lib/ld-uClibc.so.0
02680000-026ba6b0 r-xs 00000000 00:01 297 /lib/libc.so.0
02700000-0274d384 r-xs 00000000 00:01 22 /bin/busybox
02816000-02817000 rw-p 00000000 00:00 0
02848000-0284c0d8 rw-p 00000000 00:00 0
02860000-02880000 rw-p 00000000 00:00 0 [stack]
The semi-downside here is that for FLAT, we get:
root:/> cat /proc/155/maps
029f0000-029f9000 rwxp 00000000 00:00 0 [stack]
The reason being that FLAT combines a whole lot of stuff into one map
(including the stack). But this isn't any worse than the current output
(which is nothing), so screw it.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
v2
- use start_stack rather than brk to find the mapping
fs/proc/task_nommu.c | 20 ++++++++++++++++----
1 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
index 5d9fd64..11827c0 100644
--- a/fs/proc/task_nommu.c
+++ b/fs/proc/task_nommu.c
@@ -121,11 +121,20 @@ int task_statm(struct mm_struct *mm, int *shared, int *text,
return size;
}
+static void pad_len_spaces(struct seq_file *m, int len)
+{
+ len = 25 + sizeof(void*) * 6 - len;
+ if (len < 1)
+ len = 1;
+ seq_printf(m, "%*c", len, ' ');
+}
+
/*
* display a single VMA to a sequenced file
*/
static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
{
+ struct mm_struct *mm = vma->vm_mm;
unsigned long ino = 0;
struct file *file;
dev_t dev = 0;
@@ -154,11 +163,14 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
MAJOR(dev), MINOR(dev), ino, &len);
if (file) {
- len = 25 + sizeof(void *) * 6 - len;
- if (len < 1)
- len = 1;
- seq_printf(m, "%*c", len, ' ');
+ pad_len_spaces(m, len);
seq_path(m, &file->f_path, "");
+ } else if (mm) {
+ if (vma->vm_start <= mm->start_stack &&
+ vma->vm_end >= mm->start_stack) {
+ pad_len_spaces(m, len);
+ seq_puts(m, "[stack]");
+ }
}
seq_putc(m, '\n');
--
1.6.5.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2] NOMMU: add [stack] label to per-process maps output
2009-12-16 16:59 ` David Howells
` (3 preceding siblings ...)
2009-12-21 14:35 ` [PATCH v2] " Mike Frysinger
@ 2009-12-22 15:58 ` David Howells
2010-05-24 5:35 ` Mike Frysinger
4 siblings, 1 reply; 9+ messages in thread
From: David Howells @ 2009-12-22 15:58 UTC (permalink / raw)
To: Mike Frysinger
Cc: dhowells, uclinux-dev, David McCullough, Greg Ungerer, Paul Mundt,
linux-kernel, uclinux-dist-devel
Okay. I've adjusted the desciption of the patch a little (see attached).
David
---
From: Mike Frysinger <vapier@gentoo.org>
Subject: [PATCH] NOMMU: Add '[stack]' label to /proc/pid/maps output
Add support to the NOMMU /proc/pid/maps file to show which mapping is the stack
of the original thread after execve. This is largely based on the MMU code.
Subsidiary thread stacks are not indicated.
For FDPIC, we now get:
root:/> cat /proc/self/maps
02064000-02067ccc rw-p 0004d000 00:01 22 /bin/busybox
0206e000-0206f35c rw-p 00006000 00:01 295 /lib/ld-uClibc.so.0
025f0000-025f6f0c r-xs 00000000 00:01 295 /lib/ld-uClibc.so.0
02680000-026ba6b0 r-xs 00000000 00:01 297 /lib/libc.so.0
02700000-0274d384 r-xs 00000000 00:01 22 /bin/busybox
02816000-02817000 rw-p 00000000 00:00 0
02848000-0284c0d8 rw-p 00000000 00:00 0
02860000-02880000 rw-p 00000000 00:00 0 [stack]
The semi-downside here is that for FLAT, we get:
root:/> cat /proc/155/maps
029f0000-029f9000 rwxp 00000000 00:00 0 [stack]
The reason being that FLAT combines a whole lot of stuff into one map
(including the stack). But this isn't any worse than the current output (which
is nothing), so screw it.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/proc/task_nommu.c | 20 ++++++++++++++++----
1 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
index 5d9fd64..11827c0 100644
--- a/fs/proc/task_nommu.c
+++ b/fs/proc/task_nommu.c
@@ -121,11 +121,20 @@ int task_statm(struct mm_struct *mm, int *shared, int *text,
return size;
}
+static void pad_len_spaces(struct seq_file *m, int len)
+{
+ len = 25 + sizeof(void*) * 6 - len;
+ if (len < 1)
+ len = 1;
+ seq_printf(m, "%*c", len, ' ');
+}
+
/*
* display a single VMA to a sequenced file
*/
static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
{
+ struct mm_struct *mm = vma->vm_mm;
unsigned long ino = 0;
struct file *file;
dev_t dev = 0;
@@ -154,11 +163,14 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
MAJOR(dev), MINOR(dev), ino, &len);
if (file) {
- len = 25 + sizeof(void *) * 6 - len;
- if (len < 1)
- len = 1;
- seq_printf(m, "%*c", len, ' ');
+ pad_len_spaces(m, len);
seq_path(m, &file->f_path, "");
+ } else if (mm) {
+ if (vma->vm_start <= mm->start_stack &&
+ vma->vm_end >= mm->start_stack) {
+ pad_len_spaces(m, len);
+ seq_puts(m, "[stack]");
+ }
}
seq_putc(m, '\n');
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2] NOMMU: add [stack] label to per-process maps output
2009-12-22 15:58 ` David Howells
@ 2010-05-24 5:35 ` Mike Frysinger
0 siblings, 0 replies; 9+ messages in thread
From: Mike Frysinger @ 2010-05-24 5:35 UTC (permalink / raw)
To: David Howells
Cc: uclinux-dev, David McCullough, Greg Ungerer, Paul Mundt,
linux-kernel, uclinux-dist-devel
[-- Attachment #1: Type: Text/Plain, Size: 554 bytes --]
On Tuesday 22 December 2009 10:58:10 David Howells wrote:
> Okay. I've adjusted the desciption of the patch a little (see attached).
>
> David
> ---
> From: Mike Frysinger <vapier@gentoo.org>
> Subject: [PATCH] NOMMU: Add '[stack]' label to /proc/pid/maps output
>
> Add support to the NOMMU /proc/pid/maps file to show which mapping is the
> stack of the original thread after execve. This is largely based on the
> MMU code. Subsidiary thread stacks are not indicated.
was there something holding this back from being merged ?
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-05-24 5:35 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-15 23:55 [PATCH] NOMMU: add [stack] label to per-process maps output Mike Frysinger
2009-12-16 8:54 ` David Howells
2009-12-16 16:59 ` David Howells
2009-12-16 19:36 ` [uClinux-dev] " Mike Frysinger
2009-12-17 22:49 ` Mike Frysinger
2009-12-17 23:27 ` David Howells
2009-12-21 14:35 ` [PATCH v2] " Mike Frysinger
2009-12-22 15:58 ` David Howells
2010-05-24 5:35 ` Mike Frysinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).