* [PATCH -mm] add a helper function to test if an object is on the stack
@ 2008-06-11 2:14 FUJITA Tomonori
2008-06-11 5:52 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: FUJITA Tomonori @ 2008-06-11 2:14 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel, tglx, FUJITA Tomonori
lib/debugobjects.c has a function to test if an object is on the
stack. The block layer and ide needs it (they need to avoid DMA
from/to stack buffers). This patch moves the function to
include/linux/sched.h so that everyone can use it.
lib/debugobjects.c uses current->stack but this patch uses a
task_stack_page() accessor, which is a preferable way to access to
stack.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
---
include/linux/sched.h | 7 +++++++
lib/debugobjects.c | 4 +---
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 4efb39b..799bbdd 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1978,6 +1978,13 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
#endif
+static inline int object_is_on_stack(void *obj)
+{
+ void *stack = task_stack_page(current);
+
+ return (obj >= stack) && (obj < (stack + THREAD_SIZE));
+}
+
extern void thread_info_cache_init(void);
#ifdef CONFIG_DEBUG_STACK_USAGE
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index a76a5e1..2afddde 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -231,15 +231,13 @@ debug_object_fixup(int (*fixup)(void *addr, enum debug_obj_state state),
static void debug_object_is_on_stack(void *addr, int onstack)
{
- void *stack = current->stack;
int is_on_stack;
static int limit;
if (limit > 4)
return;
- is_on_stack = (addr >= stack && addr < (stack + THREAD_SIZE));
-
+ is_on_stack = object_is_on_stack(addr);
if (is_on_stack == onstack)
return;
--
1.5.5.GIT
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH -mm] add a helper function to test if an object is on the stack
2008-06-11 2:14 [PATCH -mm] add a helper function to test if an object is on the stack FUJITA Tomonori
@ 2008-06-11 5:52 ` Andrew Morton
2008-06-12 5:18 ` FUJITA Tomonori
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2008-06-11 5:52 UTC (permalink / raw)
To: FUJITA Tomonori; +Cc: linux-kernel, tglx
On Wed, 11 Jun 2008 11:14:45 +0900 FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> wrote:
> lib/debugobjects.c has a function to test if an object is on the
> stack. The block layer and ide needs it (they need to avoid DMA
> from/to stack buffers). This patch moves the function to
> include/linux/sched.h so that everyone can use it.
>
> lib/debugobjects.c uses current->stack but this patch uses a
> task_stack_page() accessor, which is a preferable way to access to
> stack.
>
Seems reasonable.
> ---
> include/linux/sched.h | 7 +++++++
> lib/debugobjects.c | 4 +---
> 2 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 4efb39b..799bbdd 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1978,6 +1978,13 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
>
> #endif
>
> +static inline int object_is_on_stack(void *obj)
> +{
> + void *stack = task_stack_page(current);
Are we sure that this will work if !defined __HAVE_THREAD_FUNCTIONS?
> + return (obj >= stack) && (obj < (stack + THREAD_SIZE));
> +}
> +
> extern void thread_info_cache_init(void);
>
> #ifdef CONFIG_DEBUG_STACK_USAGE
> diff --git a/lib/debugobjects.c b/lib/debugobjects.c
> index a76a5e1..2afddde 100644
> --- a/lib/debugobjects.c
> +++ b/lib/debugobjects.c
> @@ -231,15 +231,13 @@ debug_object_fixup(int (*fixup)(void *addr, enum debug_obj_state state),
>
> static void debug_object_is_on_stack(void *addr, int onstack)
> {
> - void *stack = current->stack;
> int is_on_stack;
> static int limit;
>
> if (limit > 4)
> return;
>
> - is_on_stack = (addr >= stack && addr < (stack + THREAD_SIZE));
> -
> + is_on_stack = object_is_on_stack(addr);
> if (is_on_stack == onstack)
> return;
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH -mm] add a helper function to test if an object is on the stack
2008-06-11 5:52 ` Andrew Morton
@ 2008-06-12 5:18 ` FUJITA Tomonori
0 siblings, 0 replies; 3+ messages in thread
From: FUJITA Tomonori @ 2008-06-12 5:18 UTC (permalink / raw)
To: akpm; +Cc: fujita.tomonori, linux-kernel, tglx
On Tue, 10 Jun 2008 22:52:36 -0700
Andrew Morton <akpm@linux-foundation.org> wrote:
> On Wed, 11 Jun 2008 11:14:45 +0900 FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> wrote:
>
> > lib/debugobjects.c has a function to test if an object is on the
> > stack. The block layer and ide needs it (they need to avoid DMA
> > from/to stack buffers). This patch moves the function to
> > include/linux/sched.h so that everyone can use it.
> >
> > lib/debugobjects.c uses current->stack but this patch uses a
> > task_stack_page() accessor, which is a preferable way to access to
> > stack.
> >
>
> Seems reasonable.
>
> > ---
> > include/linux/sched.h | 7 +++++++
> > lib/debugobjects.c | 4 +---
> > 2 files changed, 8 insertions(+), 3 deletions(-)
> >
> > diff --git a/include/linux/sched.h b/include/linux/sched.h
> > index 4efb39b..799bbdd 100644
> > --- a/include/linux/sched.h
> > +++ b/include/linux/sched.h
> > @@ -1978,6 +1978,13 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
> >
> > #endif
> >
> > +static inline int object_is_on_stack(void *obj)
> > +{
> > + void *stack = task_stack_page(current);
>
> Are we sure that this will work if !defined __HAVE_THREAD_FUNCTIONS?
If !defined __HAVE_THREAD_FUNCTIONS, we use the following macro in
sched.h:
#define task_stack_page(task) ((task)->stack)
So it works.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-06-12 5:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-11 2:14 [PATCH -mm] add a helper function to test if an object is on the stack FUJITA Tomonori
2008-06-11 5:52 ` Andrew Morton
2008-06-12 5:18 ` FUJITA Tomonori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox