Skip to contentSkip to conversation

ftrace: updates for tip

PATCH Superseded Steven Rostedt 5 participants 17 messages Feb 6, 2009

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover ftrace: updates for tip

Ingo,

The following patches are in:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git

branch: tip/devel

Steven Rostedt (4):
ftrace, x86: rename in_nmi variable
nmi: add generic nmi tracking state
ftrace: change function graph tracer to use new in_nmi
ring-buffer: use generic version of in_nmi

----

 arch/x86/Kconfig           |    2 +-
 arch/x86/kernel/ftrace.c   |   39 ++++++++++-----------------------------
 include/linux/ftrace_irq.h |    8 --------
 include/linux/hardirq.h    |   15 +++++++++++++++
 kernel/trace/ring_buffer.c |   43 +++++++++++++------------------------------
 5 files changed, 39 insertions(+), 68 deletions(-)
author maintainer
#1 lore raw

PATCH 1/4 ftrace, x86: rename in_nmi variable

From: Steven Rostedt <[email protected]>

Impact: clean up

The in_nmi variable in x86 arch ftrace.c is a misnomer. Andrew Morton pointed out that the in_nmi variable is incremented by all CPUS. It can be set when another CPU is running an NMI.

Since this is actually intentional, the fix is to rename it to what it really is: "nmi_running"

---
 arch/x86/kernel/ftrace.c |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)
arch/x86/kernel/ftrace.c +11 -11
index 4c68358..e3fad2e 100644
@@ -82,7 +82,7 @@ static unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
  * are the same as what exists.
  */
 
-static atomic_t in_nmi = ATOMIC_INIT(0);
+static atomic_t nmi_running = ATOMIC_INIT(0);
 static int mod_code_status;		/* holds return value of text write */
 static int mod_code_write;		/* set when NMI should do the write */
 static void *mod_code_ip;		/* holds the IP to write to */
@@ -115,8 +115,8 @@ static void ftrace_mod_code(void)
 
 void arch_ftrace_nmi_enter(void)
 {
-	atomic_inc(&in_nmi);
-	/* Must have in_nmi seen before reading write flag */
+	atomic_inc(&nmi_running);
+	/* Must have nmi_running seen before reading write flag */
 	smp_mb();
 	if (mod_code_write) {
 		ftrace_mod_code();
@@ -126,19 +126,19 @@ void arch_ftrace_nmi_enter(void)
 
 void arch_ftrace_nmi_exit(void)
 {
-	/* Finish all executions before clearing in_nmi */
+	/* Finish all executions before clearing nmi_running */
 	smp_wmb();
-	atomic_dec(&in_nmi);
+	atomic_dec(&nmi_running);
 }
 
 static void wait_for_nmi(void)
 {
-	if (!atomic_read(&in_nmi))
+	if (!atomic_read(&nmi_running))
 		return;
 
 	do {
 		cpu_relax();
-	} while(atomic_read(&in_nmi));
+	} while (atomic_read(&nmi_running));
 
 	nmi_wait_count++;
 }
@@ -374,16 +374,16 @@ int ftrace_disable_ftrace_graph_caller(void)
  * this page for dynamic ftrace. They have been
  * simplified to ignore all traces in NMI context.
  */
-static atomic_t in_nmi;
+static atomic_t nmi_running;
 
 void arch_ftrace_nmi_enter(void)
 {
-	atomic_inc(&in_nmi);
+	atomic_inc(&nmi_running);
 }
 
 void arch_ftrace_nmi_exit(void)
 {
-	atomic_dec(&in_nmi);
+	atomic_dec(&nmi_running);
 }
 
 #endif /* !CONFIG_DYNAMIC_FTRACE */
@@ -475,7 +475,7 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
 				&return_to_handler;
 
 	/* Nmi's are currently unsupported */
-	if (unlikely(atomic_read(&in_nmi)))
+	if (unlikely(atomic_read(&nmi_running)))
 		return;
 
 	if (unlikely(atomic_read(&current->tracing_graph_pause)))
Signature · 3 lines
1.5.6.5

-- 
author maintainer
#2 lore raw

PATCH 2/4 nmi: add generic nmi tracking state

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

This code adds an in_nmi() macro that uses the current tasks preempt count to track when it is in NMI context. Other parts of the kernel can use this to determine if the context is in NMI context or not.

This code was inspired by the -rt patch in_nmi version that was written by Peter Zijlstra.

---
 include/linux/hardirq.h |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
include/linux/hardirq.h +15 -0
index f832883..f3cf86e 100644
@@ -61,6 +61,12 @@
 #error PREEMPT_ACTIVE is too low!
 #endif
 
+#define NMI_OFFSET	(PREEMPT_ACTIVE << 1)
+
+#if NMI_OFFSET >= 0x80000000
+#error PREEMPT_ACTIVE too high!
+#endif
+
 #define hardirq_count()	(preempt_count() & HARDIRQ_MASK)
 #define softirq_count()	(preempt_count() & SOFTIRQ_MASK)
 #define irq_count()	(preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK))
@@ -73,6 +79,11 @@
 #define in_softirq()		(softirq_count())
 #define in_interrupt()		(irq_count())
 
+/*
+ * Are we in NMI context?
+ */
+#define in_nmi()	(preempt_count() & NMI_OFFSET)
+
 #if defined(CONFIG_PREEMPT)
 # define PREEMPT_INATOMIC_BASE kernel_locked()
 # define PREEMPT_CHECK_OFFSET 1
@@ -167,6 +178,8 @@ extern void irq_exit(void);
 #define nmi_enter()				\
 	do {					\
 		ftrace_nmi_enter();		\
+		BUG_ON(in_nmi());		\
+		add_preempt_count(NMI_OFFSET);	\
 		lockdep_off();			\
 		rcu_nmi_enter();		\
 		__irq_enter();			\
@@ -177,6 +190,8 @@ extern void irq_exit(void);
 		__irq_exit();			\
 		rcu_nmi_exit();			\
 		lockdep_on();			\
+		BUG_ON(!in_nmi());		\
+		sub_preempt_count(NMI_OFFSET);	\
 		ftrace_nmi_exit();		\
 	} while (0)
 
Signature · 3 lines
1.5.6.5

-- 
author maintainer
#15 lore raw

PATCH 3/4 ftrace: change function graph tracer to use new in_nmi

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

The function graph tracer piggy backed onto the dynamic ftracer to use the in_nmi custom code for dynamic tracing. The problem was (as Andrew Morton pointed out) it really only wanted to bail out if the context of the current CPU was in NMI context. But the dynamic ftrace in_nmi custom code was true if _any_ CPU happened to be in NMI context.

Now that we have a generic in_nmi interface, this patch changes the function graph code to use it instead of the dynamic ftarce custom code.

---
 arch/x86/Kconfig         |    2 +-
 arch/x86/kernel/ftrace.c |   21 +--------------------
 2 files changed, 2 insertions(+), 21 deletions(-)
arch/x86/Kconfig +1 -1
index 3da7121..0f47315 100644
@@ -34,7 +34,7 @@ config X86
 	select HAVE_FUNCTION_TRACER
 	select HAVE_FUNCTION_GRAPH_TRACER
 	select HAVE_FUNCTION_TRACE_MCOUNT_TEST
-	select HAVE_FTRACE_NMI_ENTER if DYNAMIC_FTRACE || FUNCTION_GRAPH_TRACER
+	select HAVE_FTRACE_NMI_ENTER if DYNAMIC_FTRACE
 	select HAVE_KVM
 	select HAVE_ARCH_KGDB
 	select HAVE_ARCH_TRACEHOOK
arch/x86/kernel/ftrace.c +1 -20
index e3fad2e..918073c 100644
@@ -367,25 +367,6 @@ int ftrace_disable_ftrace_graph_caller(void)
 	return ftrace_mod_jmp(ip, old_offset, new_offset);
 }
 
-#else /* CONFIG_DYNAMIC_FTRACE */
-
-/*
- * These functions are picked from those used on
- * this page for dynamic ftrace. They have been
- * simplified to ignore all traces in NMI context.
- */
-static atomic_t nmi_running;
-
-void arch_ftrace_nmi_enter(void)
-{
-	atomic_inc(&nmi_running);
-}
-
-void arch_ftrace_nmi_exit(void)
-{
-	atomic_dec(&nmi_running);
-}
-
 #endif /* !CONFIG_DYNAMIC_FTRACE */
 
 /* Add a function return address to the trace stack on thread info.*/
@@ -475,7 +456,7 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
 				&return_to_handler;
 
 	/* Nmi's are currently unsupported */
-	if (unlikely(atomic_read(&nmi_running)))
+	if (unlikely(in_nmi()))
 		return;
 
 	if (unlikely(atomic_read(&current->tracing_graph_pause)))
Signature · 3 lines
1.5.6.5

-- 
author maintainer
#16 lore raw

PATCH 4/4 ring-buffer: use generic version of in_nmi

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

Impact: clean up

Now that a generic in_nmi is available, this patch removes the special code in the ring_buffer and implements the in_nmi generic version instead.

With this change, I was also able to rename the "arch_ftrace_nmi_enter" back to "ftrace_nmi_enter" and remove the code from the ring buffer.

---
 arch/x86/kernel/ftrace.c   |    4 ++--
 include/linux/ftrace_irq.h |    8 --------
 kernel/trace/ring_buffer.c |   43 +++++++++++++------------------------------
 3 files changed, 15 insertions(+), 40 deletions(-)
arch/x86/kernel/ftrace.c +2 -2
index 918073c..d74d75e 100644
@@ -113,7 +113,7 @@ static void ftrace_mod_code(void)
 					     MCOUNT_INSN_SIZE);
 }
 
-void arch_ftrace_nmi_enter(void)
+void ftrace_nmi_enter(void)
 {
 	atomic_inc(&nmi_running);
 	/* Must have nmi_running seen before reading write flag */
@@ -124,7 +124,7 @@ void arch_ftrace_nmi_enter(void)
 	}
 }
 
-void arch_ftrace_nmi_exit(void)
+void ftrace_nmi_exit(void)
 {
 	/* Finish all executions before clearing nmi_running */
 	smp_wmb();
include/linux/ftrace_irq.h +0 -8
index 29de677..dca7bf8 100644
@@ -3,14 +3,6 @@
 
 
 #ifdef CONFIG_FTRACE_NMI_ENTER
-extern void arch_ftrace_nmi_enter(void);
-extern void arch_ftrace_nmi_exit(void);
-#else
-static inline void arch_ftrace_nmi_enter(void) { }
-static inline void arch_ftrace_nmi_exit(void) { }
-#endif
-
-#ifdef CONFIG_RING_BUFFER
 extern void ftrace_nmi_enter(void);
 extern void ftrace_nmi_exit(void);
 #else
kernel/trace/ring_buffer.c +13 -30

66 lines not on this page · raw message

Signature · 3 lines
1.5.6.5

-- 
#3 lore raw

Re: [PATCH 2/4] nmi: add generic nmi tracking state

In reply to Steven Rostedt
Quoted 54 lines · On Fri, 06 Feb 2009 01:53:54 -0500 Steven Rostedt <[email protected]> wrote:

From: Steven Rostedt <[email protected]>

This code adds an in_nmi() macro that uses the current tasks preempt count to track when it is in NMI context. Other parts of the kernel can use this to determine if the context is in NMI context or not.

This code was inspired by the -rt patch in_nmi version that was written by Peter Zijlstra.

---
 include/linux/hardirq.h |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
include/linux/hardirq.h +13 -0
index f832883..f3cf86e 100644
@@ -61,6 +61,12 @@
 #error PREEMPT_ACTIVE is too low!
 #endif
 
+#define NMI_OFFSET	(PREEMPT_ACTIVE << 1)
+
+#if NMI_OFFSET >= 0x80000000
+#error PREEMPT_ACTIVE too high!
+#endif
+
 #define hardirq_count()	(preempt_count() & HARDIRQ_MASK)
 #define softirq_count()	(preempt_count() & SOFTIRQ_MASK)
 #define irq_count()	(preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK))
@@ -73,6 +79,11 @@
 #define in_softirq()		(softirq_count())
 #define in_interrupt()		(irq_count())
 
+/*
+ * Are we in NMI context?
+ */
+#define in_nmi()	(preempt_count() & NMI_OFFSET)
+
 #if defined(CONFIG_PREEMPT)
 # define PREEMPT_INATOMIC_BASE kernel_locked()
 # define PREEMPT_CHECK_OFFSET 1
@@ -167,6 +178,8 @@ extern void irq_exit(void);
 #define nmi_enter()				\
 	do {					\
 		ftrace_nmi_enter();		\
+		BUG_ON(in_nmi());		\
+		add_preempt_count(NMI_OFFSET);	\
 		lockdep_off();			\
 		rcu_nmi_enter();		\
 		__irq_enter();			\

include/linux/hardirq.h extern void irq_exit(void); · line 197

Quoted 8 lines
include/linux/hardirq.h +2 -0
@@ -177,6 +190,8 @@ extern void irq_exit(void);
 		__irq_exit();			\
 		rcu_nmi_exit();			\
 		lockdep_on();			\
+		BUG_ON(!in_nmi());		\
+		sub_preempt_count(NMI_OFFSET);	\
 		ftrace_nmi_exit();		\
 	} while (0)
 

Well that was tidy.

We're sure that no present or future architecture will for some weird reason nest NMIs?

#7 lore raw

Re: [PATCH 2/4] nmi: add generic nmi tracking state

In reply to Steven Rostedt
Quoted 6 lines · Steven Rostedt

This code adds an in_nmi() macro that uses the current tasks preempt count to track when it is in NMI context. Other parts of the kernel can use this to determine if the context is in NMI context or not.

This code was inspired by the -rt patch in_nmi version that was written by Peter Zijlstra.

Which in turn I borrowed from Mathieu.

author maintainer
#4 lore raw

Re: [PATCH 2/4] nmi: add generic nmi tracking state

In reply to Andrew Morton
Quoted 30 lines · Andrew Morton
Quoted 19 lines
include/linux/hardirq.h +7 -0
+/*
+ * Are we in NMI context?
+ */
+#define in_nmi()	(preempt_count() & NMI_OFFSET)
+
 #if defined(CONFIG_PREEMPT)
 # define PREEMPT_INATOMIC_BASE kernel_locked()
 # define PREEMPT_CHECK_OFFSET 1
@@ -167,6 +178,8 @@ extern void irq_exit(void);
 #define nmi_enter()				\
 	do {					\
 		ftrace_nmi_enter();		\
+		BUG_ON(in_nmi());		\
+		add_preempt_count(NMI_OFFSET);	\
 		lockdep_off();			\
 		rcu_nmi_enter();		\
 		__irq_enter();			\

include/linux/hardirq.h extern void irq_exit(void); · line 197

Quoted 8 lines
include/linux/hardirq.h +2 -0
@@ -177,6 +190,8 @@ extern void irq_exit(void);
 		__irq_exit();			\
 		rcu_nmi_exit();			\
 		lockdep_on();			\
+		BUG_ON(!in_nmi());		\
+		sub_preempt_count(NMI_OFFSET);	\
 		ftrace_nmi_exit();		\
 	} while (0)
 

Well that was tidy.

Quoted 2 lines

We're sure that no present or future architecture will for some weird reason nest NMIs?

That would be fun to implement. Not the in_nmi code, but the handling of nested NMIs. How would you be able to save the state when the NMI occurred without being preempted by another NMI?

I think the arch that has nested NMIs will have many more issues to solve in the kernel than this one.

-- Steve

#8 lore raw

Re: [PATCH 2/4] nmi: add generic nmi tracking state

In reply to Peter Zijlstra
Quoted 10 lines · Peter Zijlstra
Quoted 6 lines · Steven Rostedt

This code adds an in_nmi() macro that uses the current tasks preempt count to track when it is in NMI context. Other parts of the kernel can use this to determine if the context is in NMI context or not.

This code was inspired by the -rt patch in_nmi version that was written by Peter Zijlstra.

Which in turn I borrowed from Mathieu.

Steve, could you please fix the attribution?

Ingo

author maintainer
#9 lore raw

Re: [PATCH 2/4] nmi: add generic nmi tracking state

Quoted 9 lines · Ingo Molnar
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Steven Rostedt

This code adds an in_nmi() macro that uses the current tasks preempt count to track when it is in NMI context. Other parts of the kernel can use this to determine if the context is in NMI context or not.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

This code was inspired by the -rt patch in_nmi version that was written by Peter Zijlstra.

Which in turn I borrowed from Mathieu.

Steve, could you please fix the attribution?

Is it OK to rebase the branch to do so?

-- Steve

#10 lore raw

Re: [PATCH 2/4] nmi: add generic nmi tracking state

Quoted 11 lines · Steven Rostedt
Quoted 9 lines · Ingo Molnar
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Steven Rostedt

This code adds an in_nmi() macro that uses the current tasks preempt count to track when it is in NMI context. Other parts of the kernel can use this to determine if the context is in NMI context or not.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

This code was inspired by the -rt patch in_nmi version that was written by Peter Zijlstra.

Which in turn I borrowed from Mathieu.

Steve, could you please fix the attribution?

Is it OK to rebase the branch to do so?

Sure, that's necessary.

And note that unless you base your tree against tip:tracing/ftrace i cannot do a straight pull anyway. (your trees are usually based against tip:master
- which brings in all other branches)

Ingo

author maintainer
#11 lore raw

Re: [PATCH 2/4] nmi: add generic nmi tracking state

Quoted 3 lines · Ingo Molnar
Quoted 1 line

Is it OK to rebase the branch to do so?

Sure, that's necessary.

OK, will do.

Quoted 4 lines

And note that unless you base your tree against tip:tracing/ftrace i cannot do a straight pull anyway. (your trees are usually based against tip:master
- which brings in all other branches)

Which is better for you? Should I base it off of tracing/ftrace instead? I just been using master to make sure I did not break anything else in your repo ;-)

I can set up a branch called tip/ftrace/devel that will be based off of tracing/ftrace, and keep tip/devel off of tip/master. This will let you know which repo my post is based off of. I'll also add it to the subject.

-- Steve

#12 lore raw

Re: [PATCH 2/4] nmi: add generic nmi tracking state

Quoted 9 lines · Steven Rostedt
Quoted 3 lines · Ingo Molnar
Quoted 1 line

Is it OK to rebase the branch to do so?

Sure, that's necessary.

OK, will do.

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

And note that unless you base your tree against tip:tracing/ftrace i cannot do a straight pull anyway. (your trees are usually based against tip:master
- which brings in all other branches)

Which is better for you? Should I base it off of tracing/ftrace instead? I just been using master to make sure I did not break anything else in your repo ;-)

I'll resolve conflicts, no need to worry about that - so it would be nice if you could base it on tracing/ftrace (or tracing/core). You can test-merge your branch against tip/master and see whether there's any conflict.

Quoted 3 lines

I can set up a branch called tip/ftrace/devel that will be based off of tracing/ftrace, and keep tip/devel off of tip/master. This will let you know which repo my post is based off of. I'll also add it to the subject.

ok, that will work - thanks!

Ingo

#13 lore raw

Re: [PATCH 2/4] nmi: add generic nmi tracking state

In reply to Ingo Molnar
Quoted 21 lines · Ingo Molnar
Quoted 18 lines · Steven Rostedt
Quoted 15 lines · Ingo Molnar
Quoted 10 lines · Peter Zijlstra
Quoted 6 lines · Steven Rostedt

This code adds an in_nmi() macro that uses the current tasks preempt count to track when it is in NMI context. Other parts of the kernel can use this to determine if the context is in NMI context or not.

This code was inspired by the -rt patch in_nmi version that was written by Peter Zijlstra.

Which in turn I borrowed from Mathieu.

Steve, could you please fix the attribution?

Quoted 7 lines
Quoted 1 line

Is it OK to rebase the branch to do so?

Sure, that's necessary.

And note that unless you base your tree against tip:tracing/ftrace i cannot do a straight pull anyway. (your trees are usually based against tip:master
- which brings in all other branches)

Oh really? I always base my tracing patches against tip/master, assuming tracing/ftrace is about always quickly merged into master.
But the opposite is not necessarily true, I guess you don't merge master into tracing/ftrace so quickly to not break the history right? And I guess it's better to catch bugs if each individual topics is not too quickly synced against tip/master.

Quoted 1 line

Ingo

#14 lore raw

Re: [PATCH 2/4] nmi: add generic nmi tracking state

Quoted 31 lines · Frederic Weisbecker
Quoted 21 lines · Ingo Molnar
Quoted 18 lines · Steven Rostedt
Quoted 15 lines · Ingo Molnar
Quoted 10 lines · Peter Zijlstra
Quoted 6 lines · Steven Rostedt

This code adds an in_nmi() macro that uses the current tasks preempt count to track when it is in NMI context. Other parts of the kernel can use this to determine if the context is in NMI context or not.

This code was inspired by the -rt patch in_nmi version that was written by Peter Zijlstra.

Which in turn I borrowed from Mathieu.

Steve, could you please fix the attribution?

Quoted 7 lines
Quoted 1 line

Is it OK to rebase the branch to do so?

Sure, that's necessary.

And note that unless you base your tree against tip:tracing/ftrace i cannot do a straight pull anyway. (your trees are usually based against tip:master
- which brings in all other branches)

Quoted 6 lines

Oh really? I always base my tracing patches against tip/master, assuming tracing/ftrace is about always quickly merged into master. But the opposite is not necessarily true, I guess you don't merge master into tracing/ftrace so quickly to not break the history right? And I guess it's better to catch bugs if each individual topics is not too quickly synced against tip/master.

email submissions are perfectly OK against tip:master - please keep doing it that way. It is Git pull requests (which Steve is sending) that should be against pure topics.

Ingo

#5 lore raw

Re: [PATCH 2/4] nmi: add generic nmi tracking state

In reply to Steven Rostedt
Quoted 32 lines · On Fri, 6 Feb 2009 08:25:52 -0500 (EST) Steven Rostedt <[email protected]>…
Quoted 30 lines · Andrew Morton
Quoted 19 lines
include/linux/hardirq.h +7 -0
+/*
+ * Are we in NMI context?
+ */
+#define in_nmi()	(preempt_count() & NMI_OFFSET)
+
 #if defined(CONFIG_PREEMPT)
 # define PREEMPT_INATOMIC_BASE kernel_locked()
 # define PREEMPT_CHECK_OFFSET 1
@@ -167,6 +178,8 @@ extern void irq_exit(void);
 #define nmi_enter()				\
 	do {					\
 		ftrace_nmi_enter();		\
+		BUG_ON(in_nmi());		\
+		add_preempt_count(NMI_OFFSET);	\
 		lockdep_off();			\
 		rcu_nmi_enter();		\
 		__irq_enter();			\

include/linux/hardirq.h extern void irq_exit(void); · line 197

Quoted 8 lines
include/linux/hardirq.h +2 -0
@@ -177,6 +190,8 @@ extern void irq_exit(void);
 		__irq_exit();			\
 		rcu_nmi_exit();			\
 		lockdep_on();			\
+		BUG_ON(!in_nmi());		\
+		sub_preempt_count(NMI_OFFSET);	\
 		ftrace_nmi_exit();		\
 	} while (0)
 

Well that was tidy.

Quoted 6 lines
Quoted 2 lines

We're sure that no present or future architecture will for some weird reason nest NMIs?

That would be fun to implement. Not the in_nmi code, but the handling of nested NMIs. How would you be able to save the state when the NMI occurred without being preempted by another NMI?

Like with normal interrupts?

As long as the number of sources is finite, nested NMIs could work OK.

Quoted 2 lines

I think the arch that has nested NMIs will have many more issues to solve in the kernel than this one.

I have a vague memory that x86 can do this.

<googles a bit>

What's all this about?
https://www.x86-64.org/pipermail/discuss/2005-October/007010.html
http://kerneltrap.org/index.php?q=mailarchive/linux-kernel/2008/2/12/830704/thread

I expect that even if it is possible, we can live without it.

And if I'm wrong, it'll be easy to accommodate by adding a new counter into the task_struct or thread_struct.

Does your above implementation make in_interrupt() return true if in_nmi()? I think it doesn't, but should?

author maintainer
#6 lore raw

Re: [PATCH 2/4] nmi: add generic nmi tracking state

Quoted 6 lines · Andrew Morton
Quoted 4 lines

That would be fun to implement. Not the in_nmi code, but the handling of nested NMIs. How would you be able to save the state when the NMI occurred without being preempted by another NMI?

Like with normal interrupts?

Normal interrupts can enable interrupts again, while in the handler, as well as disable them.

Quoted 2 lines

As long as the number of sources is finite, nested NMIs could work OK.

I guess you would need a mechanism to enable and disable NMIs.

Quoted 10 lines
Quoted 3 lines

I think the arch that has nested NMIs will have many more issues to solve in the kernel than this one.

I have a vague memory that x86 can do this.

<googles a bit>

What's all this about?
https://www.x86-64.org/pipermail/discuss/2005-October/007010.html

Yuck, masking Non Maskable Interrupts?

Quoted 1 line

http://kerneltrap.org/index.php?q=mailarchive/linux-kernel/2008/2/12/830704/thread

It looks like it calls nmi_exit, so the code would dec it.

Quoted 5 lines

I expect that even if it is possible, we can live without it.

And if I'm wrong, it'll be easy to accommodate by adding a new counter into the task_struct or thread_struct.

Yeah, the bug on would trigger as soon as we do that, and we could easily update the code when that time comes.

Quoted 3 lines

Does your above implementation make in_interrupt() return true if in_nmi()? I think it doesn't, but should?

The "in_nmi()" is set when we do nmi_enter, and nmi_enter also calls irq_enter which makes in_interrupt() true. I thought adding the in_nmi condition to in_interrupt would be redundant.

-- Steve