* [PATCH] x86_64: fix the check point in stack_overflow_check
@ 2008-11-23 1:51 jia zhang
2008-11-23 8:08 ` [PATCH] x86: clean up stack overflow debug check Ingo Molnar
0 siblings, 1 reply; 3+ messages in thread
From: jia zhang @ 2008-11-23 1:51 UTC (permalink / raw)
To: linux-kernel; +Cc: tglx, Ingo Molnar, hpa
stack_overflow_check() should consider the stack usage of pt_regs, and thus it could warn us in advance. Additionally, it looks a bit good that the warning time starts at INITIAL_JIFFIES.
Signed-off-by: jia zhang <jia.zhang2008@gmail.com>
---
Assume at the moment rsp get close to the check point before interrupt arrives.
When interrupt really happens, thread_info will be partly overrode.
arch/x86/kernel/irq_64.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
--- a/arch/x86/kernel/irq_64.c
+++ b/arch/x86/kernel/irq_64.c
@@ -29,11 +29,12 @@
static inline void stack_overflow_check(struct pt_regs *regs)
{
u64 curbase = (u64)task_stack_page(current);
- static unsigned long warned = -60*HZ;
+ static unsigned long warned = INITIAL_JIFFIES - 60*HZ;
if (regs->sp >= curbase && regs->sp <= curbase + THREAD_SIZE &&
- regs->sp < curbase + sizeof(struct thread_info) + 128 &&
- time_after(jiffies, warned + 60*HZ)) {
+ regs->sp < curbase + sizeof(struct thread_info) +
+ sizeof(struct pt_regs) + 128 &&
+ time_after(jiffies, warned + 60*HZ)) {
printk("do_IRQ: %s near stack overflow (cur:%Lx,sp:%lx)\n",
current->comm, curbase, regs->sp);
show_stack(NULL,NULL);
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH] x86: clean up stack overflow debug check
2008-11-23 1:51 [PATCH] x86_64: fix the check point in stack_overflow_check jia zhang
@ 2008-11-23 8:08 ` Ingo Molnar
0 siblings, 0 replies; 3+ messages in thread
From: Ingo Molnar @ 2008-11-23 8:08 UTC (permalink / raw)
To: jia zhang
Cc: linux-kernel, tglx, hpa, Arjan van de Ven, Alexander van Heukelum
* jia zhang <jia.zhang2008@gmail.com> wrote:
> stack_overflow_check() should consider the stack usage of pt_regs,
> and thus it could warn us in advance. Additionally, it looks a bit
> good that the warning time starts at INITIAL_JIFFIES.
>
> Signed-off-by: jia zhang <jia.zhang2008@gmail.com>
> ---
> Assume at the moment rsp get close to the check point before
> interrupt arrives. When interrupt really happens, thread_info will
> be partly overrode.
>
> arch/x86/kernel/irq_64.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> --- a/arch/x86/kernel/irq_64.c
> +++ b/arch/x86/kernel/irq_64.c
> @@ -29,11 +29,12 @@
> static inline void stack_overflow_check(struct pt_regs *regs)
> {
> u64 curbase = (u64)task_stack_page(current);
> - static unsigned long warned = -60*HZ;
> + static unsigned long warned = INITIAL_JIFFIES - 60*HZ;
>
> if (regs->sp >= curbase && regs->sp <= curbase + THREAD_SIZE &&
> - regs->sp < curbase + sizeof(struct thread_info) + 128 &&
> - time_after(jiffies, warned + 60*HZ)) {
> + regs->sp < curbase + sizeof(struct thread_info) +
> + sizeof(struct pt_regs) + 128 &&
> + time_after(jiffies, warned + 60*HZ)) {
> printk("do_IRQ: %s near stack overflow (cur:%Lx,sp:%lx)\n",
> current->comm, curbase, regs->sp);
> show_stack(NULL,NULL);
applied to tip/x86/debug, thanks! I also applied the clean up patch
below on top of your fix.
Ingo
----------------->
>From f377fa123d0ec621e8e361ecc3f2a8ee70e81a2e Mon Sep 17 00:00:00 2001
From: Ingo Molnar <mingo@elte.hu>
Date: Sun, 23 Nov 2008 09:02:26 +0100
Subject: [PATCH] x86: clean up stack overflow debug check
Impact: cleanup
Simplify the irq-sampled stack overflow debug check:
- eliminate an #idef
- use WARN_ONCE() to emit a single warning (all bets are off
after the first such warning anyway)
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
arch/x86/kernel/irq_64.c | 25 ++++++++++---------------
1 files changed, 10 insertions(+), 15 deletions(-)
diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
index b842fc8..1d3d0e7 100644
--- a/arch/x86/kernel/irq_64.c
+++ b/arch/x86/kernel/irq_64.c
@@ -18,7 +18,6 @@
#include <asm/idle.h>
#include <asm/smp.h>
-#ifdef CONFIG_DEBUG_STACKOVERFLOW
/*
* Probabilistic stack overflow check:
*
@@ -28,20 +27,18 @@
*/
static inline void stack_overflow_check(struct pt_regs *regs)
{
+#ifdef CONFIG_DEBUG_STACKOVERFLOW
u64 curbase = (u64)task_stack_page(current);
- static unsigned long warned = INITIAL_JIFFIES - 60*HZ;
-
- if (regs->sp >= curbase && regs->sp <= curbase + THREAD_SIZE &&
- regs->sp < curbase + sizeof(struct thread_info) +
- sizeof(struct pt_regs) + 128 &&
- time_after(jiffies, warned + 60*HZ)) {
- printk("do_IRQ: %s near stack overflow (cur:%Lx,sp:%lx)\n",
- current->comm, curbase, regs->sp);
- show_stack(NULL,NULL);
- warned = jiffies;
- }
-}
+
+ WARN_ONCE(regs->sp >= curbase &&
+ regs->sp <= curbase + THREAD_SIZE &&
+ regs->sp < curbase + sizeof(struct thread_info) +
+ sizeof(struct pt_regs) + 128,
+
+ "do_IRQ: %s near stack overflow (cur:%Lx,sp:%lx)\n",
+ current->comm, curbase, regs->sp);
#endif
+}
/*
* do_IRQ handles all normal device IRQ's (the special
@@ -61,9 +58,7 @@ asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
irq_enter();
irq = __get_cpu_var(vector_irq)[vector];
-#ifdef CONFIG_DEBUG_STACKOVERFLOW
stack_overflow_check(regs);
-#endif
desc = irq_to_desc(irq);
if (likely(desc))
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] x86_64: fix the check point in stack_overflow_check
@ 2008-11-22 9:10 jia zhang
0 siblings, 0 replies; 3+ messages in thread
From: jia zhang @ 2008-11-22 9:10 UTC (permalink / raw)
To: mingo; +Cc: linux-kernel
stack_overflow_check() should consider the stack usage of pt_regs, and thus it could warn us in advance. Additionally, it looks a bit good that the warning time starts at INITIAL_JIFFIES.
Signed-off-by: jia zhang <jia.zhang2008@gmail.com>
---
Assume at the moment rsp get close to the check point before interrupt arrives.
When interrupt really happens, thread_info will be partly overrode.
b/arch/x86/kernel/irq_64.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
--- a/arch/x86/kernel/irq_64.c
+++ b/arch/x86/kernel/irq_64.c
@@ -29,11 +29,12 @@
static inline void stack_overflow_check(struct pt_regs *regs)
{
u64 curbase = (u64)task_stack_page(current);
- static unsigned long warned = -60*HZ;
+ static unsigned long warned = INITIAL_JIFFIES - 60*HZ;
if (regs->sp >= curbase && regs->sp <= curbase + THREAD_SIZE &&
- regs->sp < curbase + sizeof(struct thread_info) + 128 &&
- time_after(jiffies, warned + 60*HZ)) {
+ regs->sp < curbase + sizeof(struct thread_info) +
+ sizeof(struct pt_regs) + 128 &&
+ time_after(jiffies, warned + 60*HZ)) {
printk("do_IRQ: %s near stack overflow (cur:%Lx,sp:%lx)\n",
current->comm, curbase, regs->sp);
show_stack(NULL,NULL);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-11-23 8:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-23 1:51 [PATCH] x86_64: fix the check point in stack_overflow_check jia zhang
2008-11-23 8:08 ` [PATCH] x86: clean up stack overflow debug check Ingo Molnar
-- strict thread matches above, loose matches on Subject: below --
2008-11-22 9:10 [PATCH] x86_64: fix the check point in stack_overflow_check jia zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox