From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-12 21:14:12
Hi all,
These here patches are the result of Mathieu and Steve trying to get commit
865e63b04e9b2 ("tracing: Add back in rcu_irq_enter/exit_irqson() for rcuidle
tracepoints") reverted again.
One of the things discovered is that tracing MUST NOT happen before nmi_enter()
or after nmi_exit(). Audit results of the previous version are still valid.
Changes since -v1:
- Added tags
- Changed #4; changed nmi_enter() to use __preempt_count_add() vs
marking preempt_count_add() notrace.
- Changed #5; confusion on which functions are notrace due to Makefile
- Added #9; remove limitation on the perf-function-trace coupling
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-12 21:14:05
Effectively revert commit 865e63b04e9b2 ("tracing: Add back in
rcu_irq_enter/exit_irqson() for rcuidle tracepoints") now that we've
taught perf how to deal with not having an RCU context provided.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/tracepoint.h | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-12 21:14:08
The functions do in fact use local_irq_{save,restore}() and can
therefore be used when IRQs are in fact disabled. Worse, they are
already used in places where IRQs are disabled, leading to great
confusion when reading the code.
Rename them to fix this confusion.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/rcupdate.h | 4 ++--
include/linux/rcutiny.h | 4 ++--
include/linux/rcutree.h | 4 ++--
include/linux/tracepoint.h | 4 ++--
kernel/cpu_pm.c | 4 ++--
kernel/rcu/tree.c | 8 ++++----
kernel/trace/trace.c | 4 ++--
7 files changed, 16 insertions(+), 16 deletions(-)
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-12 21:14:08
To facilitate tracers that need RCU, add some helpers to wrap the
magic required.
The problem is that we can call into tracers (trace events and
function tracing) while RCU isn't watching and this can happen from
any context, including NMI.
It is this latter that is causing most of the trouble; we must make
sure in_nmi() returns true before we land in anything tracing,
otherwise we cannot recover.
These helpers are macros because of header-hell; they're placed here
because of the proximity to nmi_{enter,exit{().
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/hardirq.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-12 21:14:16
Since rcu_is_watching() is notrace (and needs to be, as it can be
called from the tracers), make sure everything it in turn calls is
notrace too.
To that effect, mark rcu_dynticks_curr_cpu_in_eqs() inline, which
implies notrace, as the function is tiny.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/rcu/tree.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-12 21:14:18
If we call into a tracer before in_nmi() becomes true, the tracer can
no longer detect it is called from NMI context and behave correctly.
Therefore change nmi_{enter,exit}() to use __preempt_count_{add,sub}()
as the normal preempt_count_{add,sub}() have a (desired) function
trace entry.
This fixes a potential issue with current code; AFAICT when the
function-tracer has stack-tracing enabled __trace_stack() will
malfunction when it hits the preempt_count_add() function entry from
NMI context.
Suggested-by: Steven Rostedt (VMware) <redacted>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/hardirq.h | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-12 21:14:21
Since perf is now able to deal with !rcu_is_watching() contexts,
remove the restraint.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/trace/trace_event_perf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-12 21:14:22
Replace the opencoded (and incomplete) RCU manipulations with the new
helpers to ensure a regular RCU context when calling into
__ftrace_trace_stack().
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/trace/trace.c | 19 +++----------------
1 file changed, 3 insertions(+), 16 deletions(-)
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-12 21:14:27
Add a few comments to do_nmi() as a result of the audit.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
arch/x86/kernel/nmi.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
@@ -529,11 +529,14 @@ do_nmi(struct pt_regs *regs, long error_*continuetousetheNMIstack.*/if(unlikely(is_debug_stack(regs->sp))){-debug_stack_set_zero();+debug_stack_set_zero();/* notrace due to Makefile */this_cpu_write(update_debug_stack,1);}#endif+/*+*Itisimportantthatnotracinghappensbeforenmi_enter()!+*/nmi_enter();inc_irq_stat(__nmi_count);
@@ -542,10 +545,13 @@ do_nmi(struct pt_regs *regs, long error_default_do_nmi(regs);nmi_exit();+/*+*Notracingafternmi_exit()!+*/#ifdef CONFIG_X86_64if(unlikely(this_cpu_read(update_debug_stack))){-debug_stack_reset();+debug_stack_reset();/* notrace due to Makefile */this_cpu_write(update_debug_stack,0);}#endif
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-12 21:14:31
The tracepoint interface will stop providing regular RCU context; make
sure we do it ourselves, since perf makes use of regular RCU protected
data.
Suggested-by: Steven Rostedt (VMware) <redacted>
Suggested-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/events/core.c | 5 +++++
1 file changed, 5 insertions(+)
From: Joel Fernandes <hidden> Date: 2020-02-12 22:38:21
On Wed, Feb 12, 2020 at 10:01:41PM +0100, Peter Zijlstra wrote:
quoted hunk
Since rcu_is_watching() is notrace (and needs to be, as it can be
called from the tracers), make sure everything it in turn calls is
notrace too.
To that effect, mark rcu_dynticks_curr_cpu_in_eqs() inline, which
implies notrace, as the function is tiny.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/rcu/tree.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
I think there are ways to turn off function inlining, such as gcc's:
-fkeep-inline-functions
And just to be sure weird compilers (clang *cough*) don't screw this up,
could we make it static inline notrace?
Build tested it on the tip tree on top of your patch:
---8<-----------------------
From: Joel Fernandes <hidden> Date: 2020-02-12 22:38:46
On Wed, Feb 12, 2020 at 10:01:40PM +0100, Peter Zijlstra wrote:
The functions do in fact use local_irq_{save,restore}() and can
therefore be used when IRQs are in fact disabled. Worse, they are
already used in places where IRQs are disabled, leading to great
confusion when reading the code.
Rename them to fix this confusion.
Reviewed-by: Joel Fernandes (Google) <redacted>
thanks,
- Joel
From: Joel Fernandes <hidden> Date: 2020-02-12 23:20:08
On Wed, Feb 12, 2020 at 10:01:42PM +0100, Peter Zijlstra wrote:
quoted hunk
To facilitate tracers that need RCU, add some helpers to wrap the
magic required.
The problem is that we can call into tracers (trace events and
function tracing) while RCU isn't watching and this can happen from
any context, including NMI.
It is this latter that is causing most of the trouble; we must make
sure in_nmi() returns true before we land in anything tracing,
otherwise we cannot recover.
These helpers are macros because of header-hell; they're placed here
because of the proximity to nmi_{enter,exit{().
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/hardirq.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
I think this can be simplified. You don't need to rely on in_nmi() here. I
believe for NMI's, you can just call rcu_irq_enter_irqsave() and that should
be sufficient to get RCU watching. Paul can correct me if I'm wrong, but I am
pretty sure that would work.
In fact, I think a better naming for rcu_irq_enter_irqsave() pair could be
(in the first patch):
rcu_ensure_watching_begin();
rcu_ensure_watching_end();
thanks,
- Joel
From: Joel Fernandes <hidden> Date: 2020-02-12 23:27:04
On Wed, Feb 12, 2020 at 10:01:42PM +0100, Peter Zijlstra wrote:
quoted hunk
To facilitate tracers that need RCU, add some helpers to wrap the
magic required.
The problem is that we can call into tracers (trace events and
function tracing) while RCU isn't watching and this can happen from
any context, including NMI.
It is this latter that is causing most of the trouble; we must make
sure in_nmi() returns true before we land in anything tracing,
otherwise we cannot recover.
These helpers are macros because of header-hell; they're placed here
because of the proximity to nmi_{enter,exit{().
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/hardirq.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
Since rcu_irq_enter_irqsave can be called from a tracer context, should those
be marked with notrace as well? AFAICS, there's no notrace marking on them.
thanks,
- Joel
From: Joel Fernandes <hidden> Date: 2020-02-12 23:28:45
On Wed, Feb 12, 2020 at 10:01:45PM +0100, Peter Zijlstra wrote:
quoted hunk
The tracepoint interface will stop providing regular RCU context; make
sure we do it ourselves, since perf makes use of regular RCU protected
data.
Suggested-by: Steven Rostedt (VMware) <redacted>
Suggested-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/events/core.c | 5 +++++
1 file changed, 5 insertions(+)
From: Steven Rostedt <rostedt@goodmis.org> Date: 2020-02-13 01:41:32
On Wed, 12 Feb 2020 17:38:18 -0500
Joel Fernandes [off-list ref] wrote:
I think there are ways to turn off function inlining, such as gcc's:
-fkeep-inline-functions
And just to be sure weird compilers (clang *cough*) don't screw this up,
could we make it static inline notrace?
inline is defined as notrace, so not needed.
I did that because of surprises when functions marked as inline
suddenly became non inlined and traced, which caused issues with
function tracing (before I finally got recursion protection working).
But even then, I figured, if something is inlined and gcc actually
inlines it, it wont be traced. For consistency, if something is marked
inline, it should not be traced.
-- Steve
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-13 08:27:58
On Wed, Feb 12, 2020 at 06:20:05PM -0500, Joel Fernandes wrote:
On Wed, Feb 12, 2020 at 10:01:42PM +0100, Peter Zijlstra wrote:
quoted
+#define trace_rcu_enter() \+({ \+ unsigned long state = 0; \+ if (!rcu_is_watching()) { \+ if (in_nmi()) { \+ state = __TR_NMI; \+ rcu_nmi_enter(); \+ } else { \+ state = __TR_IRQ; \+ rcu_irq_enter_irqsave(); \
I think this can be simplified. You don't need to rely on in_nmi() here. I
believe for NMI's, you can just call rcu_irq_enter_irqsave() and that should
be sufficient to get RCU watching. Paul can correct me if I'm wrong, but I am
pretty sure that would work.
In fact, I think a better naming for rcu_irq_enter_irqsave() pair could be
(in the first patch):
rcu_ensure_watching_begin();
rcu_ensure_watching_end();
So I hadn't looked deeply into rcu_irq_enter(), it seems to call
rcu_nmi_enter_common(), but with @irq=true.
What exactly is the purpose of that @irq argument, and how much will it
hurt to lie there? Will it come apart if we have @irq != !in_nmi()
for example?
There is a comment in there that says ->dynticks_nmi_nesting ought to be
odd only if we're in NMI. The only place that seems to care is
rcu_nmi_exit_common(), and that does indeed do something different for
IRQs vs NMIs.
So I don't think we can blindly unify this. But perhaps Paul sees a way?
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-13 08:28:44
On Wed, Feb 12, 2020 at 06:27:02PM -0500, Joel Fernandes wrote:
On Wed, Feb 12, 2020 at 10:01:42PM +0100, Peter Zijlstra wrote:
quoted
+#define trace_rcu_enter() \+({ \+ unsigned long state = 0; \+ if (!rcu_is_watching()) { \+ if (in_nmi()) { \+ state = __TR_NMI; \+ rcu_nmi_enter(); \+ } else { \+ state = __TR_IRQ; \+ rcu_irq_enter_irqsave(); \
Since rcu_irq_enter_irqsave can be called from a tracer context, should those
be marked with notrace as well? AFAICS, there's no notrace marking on them.
It should work, these functions are re-entrant (as are IRQs / NMIs) and
Steve wants to be able to trace RCU itself.
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-13 08:30:13
On Wed, Feb 12, 2020 at 06:28:30PM -0500, Joel Fernandes wrote:
On Wed, Feb 12, 2020 at 10:01:45PM +0100, Peter Zijlstra wrote:
quoted
The tracepoint interface will stop providing regular RCU context; make
sure we do it ourselves, since perf makes use of regular RCU protected
data.
Suggested-by: Steven Rostedt (VMware) <redacted>
Suggested-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/events/core.c | 5 +++++
1 file changed, 5 insertions(+)
The flags are not needed I guess, if you agree on not using in_nmi() in
trace_rcu_enter().
Even then we need to store the state: 'didn't do nothing' vs 'did call
rcu_needs_to_wake_up_and_pay_attention_noaw'. That is, we only need to
do something (expensive!) when !rcu_is_watching().
From: Joel Fernandes <hidden> Date: 2020-02-13 13:31:15
On Thu, Feb 13, 2020 at 09:27:16AM +0100, Peter Zijlstra wrote:
On Wed, Feb 12, 2020 at 06:20:05PM -0500, Joel Fernandes wrote:
quoted
On Wed, Feb 12, 2020 at 10:01:42PM +0100, Peter Zijlstra wrote:
quoted
quoted
+#define trace_rcu_enter() \+({ \+ unsigned long state = 0; \+ if (!rcu_is_watching()) { \+ if (in_nmi()) { \+ state = __TR_NMI; \+ rcu_nmi_enter(); \+ } else { \+ state = __TR_IRQ; \+ rcu_irq_enter_irqsave(); \
I think this can be simplified. You don't need to rely on in_nmi() here. I
believe for NMI's, you can just call rcu_irq_enter_irqsave() and that should
be sufficient to get RCU watching. Paul can correct me if I'm wrong, but I am
pretty sure that would work.
In fact, I think a better naming for rcu_irq_enter_irqsave() pair could be
(in the first patch):
rcu_ensure_watching_begin();
rcu_ensure_watching_end();
So I hadn't looked deeply into rcu_irq_enter(), it seems to call
rcu_nmi_enter_common(), but with @irq=true.
What exactly is the purpose of that @irq argument, and how much will it
hurt to lie there? Will it come apart if we have @irq != !in_nmi()
for example?
At least rcu_dynticks_task_exit() and rcu_cleanup_after_idle() seem to be
safe regardless of IRQ or NMI. If they are safe either way, we should
probably get look into removing @irq. But I'm not fully sure and looking
forward to Paul's thought on that.. I would love for us to simplify that as
well if possible.
There is a comment in there that says ->dynticks_nmi_nesting ought to be
odd only if we're in NMI. The only place that seems to care is
rcu_nmi_exit_common(), and that does indeed do something different for
IRQs vs NMIs.
I know a bit about the counters. I had previously unified it and it passed
RCU torture testing etc. (Didn't get merge as Paul wanted it done slightly
done differently) : https://lore.kernel.org/patchwork/patch/1120022/ . I am
planning to get back to finishing that soon.
About the comment on dynticks_nmi_nesting and counters, you mean this comment
right? The odd value of '1' is just to catch the outer most handler. We need
to enter/exit the EQS (extended QS) state only from the outermost handler. I
believe that would work regardless whether it is NMI and IRQ that are
nesting. If IRQs could nest within other IRQs in Linux, then that could also
very well have used the odd/ even trick.
/*
* If idle from RCU viewpoint, atomically increment ->dynticks
* to mark non-idle and increment ->dynticks_nmi_nesting by one.
* Otherwise, increment ->dynticks_nmi_nesting by two. This means
* if ->dynticks_nmi_nesting is equal to one, we are guaranteed
* to be in the outermost NMI handler that interrupted an RCU-idle
* period (observation due to Andy Lutomirski).
*/
thanks,
- Joel
From: "Paul E. McKenney" <paulmck@kernel.org> Date: 2020-02-13 13:51:42
On Thu, Feb 13, 2020 at 09:27:16AM +0100, Peter Zijlstra wrote:
On Wed, Feb 12, 2020 at 06:20:05PM -0500, Joel Fernandes wrote:
quoted
On Wed, Feb 12, 2020 at 10:01:42PM +0100, Peter Zijlstra wrote:
quoted
quoted
+#define trace_rcu_enter() \+({ \+ unsigned long state = 0; \+ if (!rcu_is_watching()) { \+ if (in_nmi()) { \+ state = __TR_NMI; \+ rcu_nmi_enter(); \+ } else { \+ state = __TR_IRQ; \+ rcu_irq_enter_irqsave(); \
I think this can be simplified. You don't need to rely on in_nmi() here. I
believe for NMI's, you can just call rcu_irq_enter_irqsave() and that should
be sufficient to get RCU watching. Paul can correct me if I'm wrong, but I am
pretty sure that would work.
In fact, I think a better naming for rcu_irq_enter_irqsave() pair could be
(in the first patch):
rcu_ensure_watching_begin();
rcu_ensure_watching_end();
So I hadn't looked deeply into rcu_irq_enter(), it seems to call
rcu_nmi_enter_common(), but with @irq=true.
What exactly is the purpose of that @irq argument, and how much will it
hurt to lie there? Will it come apart if we have @irq != !in_nmi()
for example?
There is a comment in there that says ->dynticks_nmi_nesting ought to be
odd only if we're in NMI. The only place that seems to care is
rcu_nmi_exit_common(), and that does indeed do something different for
IRQs vs NMIs.
So I don't think we can blindly unify this. But perhaps Paul sees a way?
The reason for the irq argument is to avoid invoking
rcu_prepare_for_idle() and rcu_dynticks_task_enter() from NMI context
from rcu_nmi_exit_common(). Similarly, we need to avoid invoking
rcu_dynticks_task_exit() and rcu_cleanup_after_idle() from NMI context
from rcu_nmi_enter_common().
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
Thanx, Paul
From: Joel Fernandes <hidden> Date: 2020-02-13 14:25:22
On Wed, Feb 12, 2020 at 8:41 PM Steven Rostedt [off-list ref] wrote:
On Wed, 12 Feb 2020 17:38:18 -0500
Joel Fernandes [off-list ref] wrote:
quoted
I think there are ways to turn off function inlining, such as gcc's:
-fkeep-inline-functions
And just to be sure weird compilers (clang *cough*) don't screw this up,
could we make it static inline notrace?
inline is defined as notrace, so not needed.
I did that because of surprises when functions marked as inline
suddenly became non inlined and traced, which caused issues with
function tracing (before I finally got recursion protection working).
But even then, I figured, if something is inlined and gcc actually
inlines it, it wont be traced. For consistency, if something is marked
inline, it should not be traced.
Ah I see it, thanks for the clarification Steve! That looks like a
good idea. I withdraw my previous comment.
- Joel
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-13 16:40:57
On Thu, Feb 13, 2020 at 05:51:38AM -0800, Paul E. McKenney wrote:
The reason for the irq argument is to avoid invoking
rcu_prepare_for_idle() and rcu_dynticks_task_enter() from NMI context
from rcu_nmi_exit_common(). Similarly, we need to avoid invoking
rcu_dynticks_task_exit() and rcu_cleanup_after_idle() from NMI context
from rcu_nmi_enter_common().
Aaah, I see. I didn't grep hard enough earlier today (I only found
stubs). Yes, those take locks, we mustn't call them from NMI context.
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
From: Joel Fernandes <hidden> Date: 2020-02-13 18:38:28
On Thu, Feb 13, 2020 at 09:29:51AM +0100, Peter Zijlstra wrote:
On Wed, Feb 12, 2020 at 06:28:30PM -0500, Joel Fernandes wrote:
quoted
On Wed, Feb 12, 2020 at 10:01:45PM +0100, Peter Zijlstra wrote:
quoted
The tracepoint interface will stop providing regular RCU context; make
sure we do it ourselves, since perf makes use of regular RCU protected
data.
Suggested-by: Steven Rostedt (VMware) <redacted>
Suggested-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/events/core.c | 5 +++++
1 file changed, 5 insertions(+)
The flags are not needed I guess, if you agree on not using in_nmi() in
trace_rcu_enter().
Even then we need to store the state: 'didn't do nothing' vs 'did call
rcu_needs_to_wake_up_and_pay_attention_noaw'. That is, we only need to
do something (expensive!) when !rcu_is_watching().
You are right, that sounds good. I was talking to Paul and we chatted that if
in_nmi() is safe (which I believe it is as we are not calling RCU before you
update the preempt counts), then in RCU we can replace the @irq with
!in_nmi() and simplify that code. Then we can simplify this bit as well
(keep rcu_flags but only call rcu_irq_enter_irqsave() instead of
rcu_nmi_enter(). May be you can do the RCU internal bits in your v3 or should
those be separate patches? Whatever Paul and you want to do.
thanks,
- Joel
- Joel
From: Joel Fernandes <hidden> Date: 2020-02-13 18:39:17
On Thu, Feb 13, 2020 at 09:28:14AM +0100, Peter Zijlstra wrote:
On Wed, Feb 12, 2020 at 06:27:02PM -0500, Joel Fernandes wrote:
quoted
On Wed, Feb 12, 2020 at 10:01:42PM +0100, Peter Zijlstra wrote:
quoted
quoted
+#define trace_rcu_enter() \+({ \+ unsigned long state = 0; \+ if (!rcu_is_watching()) { \+ if (in_nmi()) { \+ state = __TR_NMI; \+ rcu_nmi_enter(); \+ } else { \+ state = __TR_IRQ; \+ rcu_irq_enter_irqsave(); \
Since rcu_irq_enter_irqsave can be called from a tracer context, should those
be marked with notrace as well? AFAICS, there's no notrace marking on them.
It should work, these functions are re-entrant (as are IRQs / NMIs) and
Steve wants to be able to trace RCU itself.
Hoping there are no recursion scenarios possible, but that sounds good to me. thanks,
- Joel
From: "Paul E. McKenney" <paulmck@kernel.org> Date: 2020-02-13 18:56:16
On Thu, Feb 13, 2020 at 05:40:31PM +0100, Peter Zijlstra wrote:
On Thu, Feb 13, 2020 at 05:51:38AM -0800, Paul E. McKenney wrote:
quoted
The reason for the irq argument is to avoid invoking
rcu_prepare_for_idle() and rcu_dynticks_task_enter() from NMI context
from rcu_nmi_exit_common(). Similarly, we need to avoid invoking
rcu_dynticks_task_exit() and rcu_cleanup_after_idle() from NMI context
from rcu_nmi_enter_common().
Aaah, I see. I didn't grep hard enough earlier today (I only found
stubs). Yes, those take locks, we mustn't call them from NMI context.
Been there, done that...
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
Thanx, Paul
------------------------------------------------------------------------
From: Joel Fernandes <hidden> Date: 2020-02-13 20:44:48
On Thu, Feb 13, 2020 at 10:56:12AM -0800, Paul E. McKenney wrote:
[...]
quoted
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
---8<-----------------------
From: "Paul E. McKenney" <paulmck@kernel.org> Date: 2020-02-13 20:54:46
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
On Thu, Feb 13, 2020 at 10:56:12AM -0800, Paul E. McKenney wrote:
[...]
quoted
quoted
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
My compiler complained about the static and the __always_inline, so I
fixed those. But please help me out on adding the NOKPROBE_SYMBOL()
to rcu_nmi_exit(). What bad thing happens if we leave this on only
rcu_nmi_enter()?
Thanx, Paul
From: Joel Fernandes <hidden> Date: 2020-02-13 21:19:34
On Thu, Feb 13, 2020 at 12:54:42PM -0800, Paul E. McKenney wrote:
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
On Thu, Feb 13, 2020 at 10:56:12AM -0800, Paul E. McKenney wrote:
[...]
quoted
quoted
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
My compiler complained about the static and the __always_inline, so I
fixed those. But please help me out on adding the NOKPROBE_SYMBOL()
to rcu_nmi_exit(). What bad thing happens if we leave this on only
rcu_nmi_enter()?
It seemed odd to me we were not allowing kprobe on the rcu_nmi_enter() but
allowing it on exit (from a code reading standpoint) so my reaction was to
add it to both, but we could probably keep that as a separate
patch/discussion since it is slightly unrelated to the patch.. Sorry to
confuse the topic.
thanks,
- Joel
From: Steven Rostedt <rostedt@goodmis.org> Date: 2020-02-13 21:38:34
[ Added Masami ]
On Thu, 13 Feb 2020 16:19:30 -0500
Joel Fernandes [off-list ref] wrote:
On Thu, Feb 13, 2020 at 12:54:42PM -0800, Paul E. McKenney wrote:
quoted
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
On Thu, Feb 13, 2020 at 10:56:12AM -0800, Paul E. McKenney wrote:
[...]
quoted
quoted
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
My compiler complained about the static and the __always_inline, so I
fixed those. But please help me out on adding the NOKPROBE_SYMBOL()
to rcu_nmi_exit(). What bad thing happens if we leave this on only
rcu_nmi_enter()?
It seemed odd to me we were not allowing kprobe on the rcu_nmi_enter() but
allowing it on exit (from a code reading standpoint) so my reaction was to
add it to both, but we could probably keep that as a separate
patch/discussion since it is slightly unrelated to the patch.. Sorry to
confuse the topic.
rcu_nmi_enter() was marked NOKPROBE or other reasons. See commit
c13324a505c77 ("x86/kprobes: Prohibit probing on functions before
kprobe_int3_handler()")
The issue was that we must not allow anything in do_int3() call kprobe
code before kprobe_int3_handler() is called. Because ist_enter() (in
do_int3()) calls rcu_nmi_enter() it had to be marked NOKPROBE. It had
nothing to do with it being RCU nor NMI, but because it was simply
called in do_int3().
Thus, there's no reason to make rcu_nmi_exit() NOKPROBE. But a commont
to why rcu_nmi_enter() would probably be useful, like below:
-- Steve
From: "Paul E. McKenney" <paulmck@kernel.org> Date: 2020-02-13 21:49:03
On Thu, Feb 13, 2020 at 04:19:30PM -0500, Joel Fernandes wrote:
On Thu, Feb 13, 2020 at 12:54:42PM -0800, Paul E. McKenney wrote:
quoted
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
On Thu, Feb 13, 2020 at 10:56:12AM -0800, Paul E. McKenney wrote:
[...]
quoted
quoted
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
My compiler complained about the static and the __always_inline, so I
fixed those. But please help me out on adding the NOKPROBE_SYMBOL()
to rcu_nmi_exit(). What bad thing happens if we leave this on only
rcu_nmi_enter()?
It seemed odd to me we were not allowing kprobe on the rcu_nmi_enter() but
allowing it on exit (from a code reading standpoint) so my reaction was to
add it to both, but we could probably keep that as a separate
patch/discussion since it is slightly unrelated to the patch.. Sorry to
confuse the topic.
Actually and perhaps unusually, I was not being sarcastic, but was instead
asking a serious question. Is the current code correct? Should the
current NOKPROBE_SYMBOL() be removed? Should the other NOKPROBE_SYMBOL()
be added? Something else? And either way, why?
Thanx, Paul
From: "Paul E. McKenney" <paulmck@kernel.org> Date: 2020-02-13 21:50:07
On Thu, Feb 13, 2020 at 04:38:25PM -0500, Steven Rostedt wrote:
[ Added Masami ]
On Thu, 13 Feb 2020 16:19:30 -0500
Joel Fernandes [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 12:54:42PM -0800, Paul E. McKenney wrote:
quoted
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
On Thu, Feb 13, 2020 at 10:56:12AM -0800, Paul E. McKenney wrote:
[...]
quoted
quoted
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
My compiler complained about the static and the __always_inline, so I
fixed those. But please help me out on adding the NOKPROBE_SYMBOL()
to rcu_nmi_exit(). What bad thing happens if we leave this on only
rcu_nmi_enter()?
It seemed odd to me we were not allowing kprobe on the rcu_nmi_enter() but
allowing it on exit (from a code reading standpoint) so my reaction was to
add it to both, but we could probably keep that as a separate
patch/discussion since it is slightly unrelated to the patch.. Sorry to
confuse the topic.
rcu_nmi_enter() was marked NOKPROBE or other reasons. See commit
c13324a505c77 ("x86/kprobes: Prohibit probing on functions before
kprobe_int3_handler()")
The issue was that we must not allow anything in do_int3() call kprobe
code before kprobe_int3_handler() is called. Because ist_enter() (in
do_int3()) calls rcu_nmi_enter() it had to be marked NOKPROBE. It had
nothing to do with it being RCU nor NMI, but because it was simply
called in do_int3().
Thus, there's no reason to make rcu_nmi_exit() NOKPROBE. But a commont
to why rcu_nmi_enter() would probably be useful, like below:
Thank you, Steve! Could I please have your Signed-off-by for this?
Thanx, Paul
From: Steven Rostedt <rostedt@goodmis.org> Date: 2020-02-13 22:04:56
On Thu, 13 Feb 2020 13:50:04 -0800
"Paul E. McKenney" [off-list ref] wrote:
On Thu, Feb 13, 2020 at 04:38:25PM -0500, Steven Rostedt wrote:
quoted
[ Added Masami ]
On Thu, 13 Feb 2020 16:19:30 -0500
Joel Fernandes [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 12:54:42PM -0800, Paul E. McKenney wrote:
quoted
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
On Thu, Feb 13, 2020 at 10:56:12AM -0800, Paul E. McKenney wrote:
[...]
quoted
quoted
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
My compiler complained about the static and the __always_inline, so I
fixed those. But please help me out on adding the NOKPROBE_SYMBOL()
to rcu_nmi_exit(). What bad thing happens if we leave this on only
rcu_nmi_enter()?
It seemed odd to me we were not allowing kprobe on the rcu_nmi_enter() but
allowing it on exit (from a code reading standpoint) so my reaction was to
add it to both, but we could probably keep that as a separate
patch/discussion since it is slightly unrelated to the patch.. Sorry to
confuse the topic.
rcu_nmi_enter() was marked NOKPROBE or other reasons. See commit
c13324a505c77 ("x86/kprobes: Prohibit probing on functions before
kprobe_int3_handler()")
The issue was that we must not allow anything in do_int3() call kprobe
code before kprobe_int3_handler() is called. Because ist_enter() (in
do_int3()) calls rcu_nmi_enter() it had to be marked NOKPROBE. It had
nothing to do with it being RCU nor NMI, but because it was simply
called in do_int3().
Thus, there's no reason to make rcu_nmi_exit() NOKPROBE. But a commont
to why rcu_nmi_enter() would probably be useful, like below:
Thank you, Steve! Could I please have your Signed-off-by for this?
Sure, but it was untested ;-)
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
I'd like a Reviewed-by from Masami though.
-- Steve
From: "Paul E. McKenney" <paulmck@kernel.org> Date: 2020-02-13 22:39:23
On Thu, Feb 13, 2020 at 05:04:51PM -0500, Steven Rostedt wrote:
On Thu, 13 Feb 2020 13:50:04 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 04:38:25PM -0500, Steven Rostedt wrote:
quoted
[ Added Masami ]
On Thu, 13 Feb 2020 16:19:30 -0500
Joel Fernandes [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 12:54:42PM -0800, Paul E. McKenney wrote:
quoted
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
On Thu, Feb 13, 2020 at 10:56:12AM -0800, Paul E. McKenney wrote:
[...]
quoted
quoted
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
My compiler complained about the static and the __always_inline, so I
fixed those. But please help me out on adding the NOKPROBE_SYMBOL()
to rcu_nmi_exit(). What bad thing happens if we leave this on only
rcu_nmi_enter()?
It seemed odd to me we were not allowing kprobe on the rcu_nmi_enter() but
allowing it on exit (from a code reading standpoint) so my reaction was to
add it to both, but we could probably keep that as a separate
patch/discussion since it is slightly unrelated to the patch.. Sorry to
confuse the topic.
rcu_nmi_enter() was marked NOKPROBE or other reasons. See commit
c13324a505c77 ("x86/kprobes: Prohibit probing on functions before
kprobe_int3_handler()")
The issue was that we must not allow anything in do_int3() call kprobe
code before kprobe_int3_handler() is called. Because ist_enter() (in
do_int3()) calls rcu_nmi_enter() it had to be marked NOKPROBE. It had
nothing to do with it being RCU nor NMI, but because it was simply
called in do_int3().
Thus, there's no reason to make rcu_nmi_exit() NOKPROBE. But a commont
to why rcu_nmi_enter() would probably be useful, like below:
Thank you, Steve! Could I please have your Signed-off-by for this?
Sure, but it was untested ;-)
No problem! I will fire up rcutorture on it. ;-)
But experience indicates that you cannot even make a joke around here.
There is probably already someone out there somewhere building a
comment-checker based on deep semantic analysis and machine learning. :-/
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
I'd like a Reviewed-by from Masami though.
Sounds good! Masami, would you be willing to review?
Thanx, Paul
From: Joel Fernandes <hidden> Date: 2020-02-13 22:58:57
On Thu, Feb 13, 2020 at 01:48:59PM -0800, Paul E. McKenney wrote:
On Thu, Feb 13, 2020 at 04:19:30PM -0500, Joel Fernandes wrote:
quoted
On Thu, Feb 13, 2020 at 12:54:42PM -0800, Paul E. McKenney wrote:
quoted
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
On Thu, Feb 13, 2020 at 10:56:12AM -0800, Paul E. McKenney wrote:
[...]
quoted
quoted
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
My compiler complained about the static and the __always_inline, so I
fixed those. But please help me out on adding the NOKPROBE_SYMBOL()
to rcu_nmi_exit(). What bad thing happens if we leave this on only
rcu_nmi_enter()?
It seemed odd to me we were not allowing kprobe on the rcu_nmi_enter() but
allowing it on exit (from a code reading standpoint) so my reaction was to
add it to both, but we could probably keep that as a separate
patch/discussion since it is slightly unrelated to the patch.. Sorry to
confuse the topic.
Actually and perhaps unusually, I was not being sarcastic, but was instead
asking a serious question. Is the current code correct? Should the
current NOKPROBE_SYMBOL() be removed? Should the other NOKPROBE_SYMBOL()
be added? Something else? And either way, why?
Oh ok, it was a fair question. Seems Steve nailed it, only the
rcu_nmi_enter() needs NOKPROBE, although as you mentioned in the other
thread, it would be good to get Masami's eyes on it since he introduced the
NOKPROBE.
thanks,
- Joel
From: Steven Rostedt <rostedt@goodmis.org> Date: 2020-02-13 23:56:08
On Thu, 13 Feb 2020 17:58:53 -0500
Joel Fernandes [off-list ref] wrote:
Oh ok, it was a fair question. Seems Steve nailed it, only the
rcu_nmi_enter() needs NOKPROBE, although as you mentioned in the other
thread, it would be good to get Masami's eyes on it since he introduced the
NOKPROBE.
Note, I did go and verify that the issue still exists, and the NOKPROBE
looks to still be needed. But as you stated, because Masami added the
NOKPROBE I'd feel more comfortable with him looking over my explanation.
-- Steve
Since perf is now able to deal with !rcu_is_watching() contexts,
remove the restraint.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/trace/trace_event_perf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Since perf is now able to deal with !rcu_is_watching() contexts,
remove the restraint.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/trace/trace_event_perf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
On Thu, 13 Feb 2020 14:39:18 -0800
"Paul E. McKenney" [off-list ref] wrote:
On Thu, Feb 13, 2020 at 05:04:51PM -0500, Steven Rostedt wrote:
quoted
On Thu, 13 Feb 2020 13:50:04 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 04:38:25PM -0500, Steven Rostedt wrote:
quoted
[ Added Masami ]
On Thu, 13 Feb 2020 16:19:30 -0500
Joel Fernandes [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 12:54:42PM -0800, Paul E. McKenney wrote:
quoted
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
On Thu, Feb 13, 2020 at 10:56:12AM -0800, Paul E. McKenney wrote:
[...]
quoted
quoted
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
My compiler complained about the static and the __always_inline, so I
fixed those. But please help me out on adding the NOKPROBE_SYMBOL()
to rcu_nmi_exit(). What bad thing happens if we leave this on only
rcu_nmi_enter()?
It seemed odd to me we were not allowing kprobe on the rcu_nmi_enter() but
allowing it on exit (from a code reading standpoint) so my reaction was to
add it to both, but we could probably keep that as a separate
patch/discussion since it is slightly unrelated to the patch.. Sorry to
confuse the topic.
rcu_nmi_enter() was marked NOKPROBE or other reasons. See commit
c13324a505c77 ("x86/kprobes: Prohibit probing on functions before
kprobe_int3_handler()")
The issue was that we must not allow anything in do_int3() call kprobe
code before kprobe_int3_handler() is called. Because ist_enter() (in
do_int3()) calls rcu_nmi_enter() it had to be marked NOKPROBE. It had
nothing to do with it being RCU nor NMI, but because it was simply
called in do_int3().
Thus, there's no reason to make rcu_nmi_exit() NOKPROBE. But a commont
to why rcu_nmi_enter() would probably be useful, like below:
Thank you, Steve! Could I please have your Signed-off-by for this?
Sure, but it was untested ;-)
No problem! I will fire up rcutorture on it. ;-)
But experience indicates that you cannot even make a joke around here.
There is probably already someone out there somewhere building a
comment-checker based on deep semantic analysis and machine learning. :-/
quoted
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
I'd like a Reviewed-by from Masami though.
Sounds good! Masami, would you be willing to review?
Yes, the functions before calling kprobe_int3_handler() must not
be kprobed. It can cause an infinite recursive int3 trapping.
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Thank you!
--
Masami Hiramatsu [off-list ref]
From: Kim Phillips <hidden> Date: 2020-02-14 20:38:20
On 2/12/20 3:01 PM, Peter Zijlstra wrote:
quoted hunk
Since perf is now able to deal with !rcu_is_watching() contexts,
remove the restraint.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/trace/trace_event_perf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Steven Rostedt <rostedt@goodmis.org> Date: 2020-02-14 22:48:50
On Fri, 14 Feb 2020 14:38:14 -0600
Kim Phillips [off-list ref] wrote:
On 2/12/20 3:01 PM, Peter Zijlstra wrote:
quoted
Since perf is now able to deal with !rcu_is_watching() contexts,
remove the restraint.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/trace/trace_event_perf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -477,7 +477,7 @@ static int perf_ftrace_function_register{structftrace_ops*ops=&event->ftrace_ops;-ops->flags=FTRACE_OPS_FL_RCU;+ops->flags=0;ops->func=perf_ftrace_function_call;ops->private=(void*)(unsignedlong)nr_cpu_ids;
If this is the last user of the flag, should all remaining
FTRACE_OPS_FL_RCU references be removed, too?
Let's wait till Peter's patches goes through a merge cycle or two. I
want to make sure there's no other RCU issues that pop up before we
remove this infrastructure.
-- Steve
From: "Paul E. McKenney" <paulmck@kernel.org> Date: 2020-02-15 17:13:46
On Fri, Feb 14, 2020 at 03:19:06PM +0900, Masami Hiramatsu wrote:
On Thu, 13 Feb 2020 14:39:18 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 05:04:51PM -0500, Steven Rostedt wrote:
quoted
On Thu, 13 Feb 2020 13:50:04 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 04:38:25PM -0500, Steven Rostedt wrote:
quoted
[ Added Masami ]
On Thu, 13 Feb 2020 16:19:30 -0500
Joel Fernandes [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 12:54:42PM -0800, Paul E. McKenney wrote:
quoted
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
On Thu, Feb 13, 2020 at 10:56:12AM -0800, Paul E. McKenney wrote:
[...]
quoted
quoted
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
My compiler complained about the static and the __always_inline, so I
fixed those. But please help me out on adding the NOKPROBE_SYMBOL()
to rcu_nmi_exit(). What bad thing happens if we leave this on only
rcu_nmi_enter()?
It seemed odd to me we were not allowing kprobe on the rcu_nmi_enter() but
allowing it on exit (from a code reading standpoint) so my reaction was to
add it to both, but we could probably keep that as a separate
patch/discussion since it is slightly unrelated to the patch.. Sorry to
confuse the topic.
rcu_nmi_enter() was marked NOKPROBE or other reasons. See commit
c13324a505c77 ("x86/kprobes: Prohibit probing on functions before
kprobe_int3_handler()")
The issue was that we must not allow anything in do_int3() call kprobe
code before kprobe_int3_handler() is called. Because ist_enter() (in
do_int3()) calls rcu_nmi_enter() it had to be marked NOKPROBE. It had
nothing to do with it being RCU nor NMI, but because it was simply
called in do_int3().
Thus, there's no reason to make rcu_nmi_exit() NOKPROBE. But a commont
to why rcu_nmi_enter() would probably be useful, like below:
Thank you, Steve! Could I please have your Signed-off-by for this?
Sure, but it was untested ;-)
No problem! I will fire up rcutorture on it. ;-)
But experience indicates that you cannot even make a joke around here.
There is probably already someone out there somewhere building a
comment-checker based on deep semantic analysis and machine learning. :-/
quoted
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
I'd like a Reviewed-by from Masami though.
Sounds good! Masami, would you be willing to review?
Yes, the functions before calling kprobe_int3_handler() must not
be kprobed. It can cause an infinite recursive int3 trapping.
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Thank you both!
Like this?
Thanx, Paul
------------------------------------------------------------------------
commit 1817fdc8f4e4bd18c76305c9b937fb0dccbb1583
Author: Steven Rostedt [off-list ref]
Date: Sat Feb 15 06:54:50 2020 -0800
rcu: Provide comment for NOKPROBE() on rcu_nmi_enter()
The rcu_nmi_enter() function was marked NOKPROBE() by commit
c13324a505c77 ("x86/kprobes: Prohibit probing on functions before
kprobe_int3_handler()") because the do_int3() call kprobe code must
not be invoked before kprobe_int3_handler() is called. It turns out
that ist_enter() (in do_int3()) calls rcu_nmi_enter(), hence the
marking NOKPROBE() being added to rcu_nmi_enter().
This commit therefore adds a comment documenting this line of reasoning.
Signed-off-by: Steven Rostedt [off-list ref]
Reviewed-by: Masami Hiramatsu [off-list ref]
Signed-off-by: Paul E. McKenney [off-list ref]
On Sat, 15 Feb 2020 06:59:34 -0800
"Paul E. McKenney" [off-list ref] wrote:
On Fri, Feb 14, 2020 at 03:19:06PM +0900, Masami Hiramatsu wrote:
quoted
On Thu, 13 Feb 2020 14:39:18 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 05:04:51PM -0500, Steven Rostedt wrote:
quoted
On Thu, 13 Feb 2020 13:50:04 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 04:38:25PM -0500, Steven Rostedt wrote:
quoted
[ Added Masami ]
On Thu, 13 Feb 2020 16:19:30 -0500
Joel Fernandes [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 12:54:42PM -0800, Paul E. McKenney wrote:
quoted
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
On Thu, Feb 13, 2020 at 10:56:12AM -0800, Paul E. McKenney wrote:
[...]
quoted
quoted
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
My compiler complained about the static and the __always_inline, so I
fixed those. But please help me out on adding the NOKPROBE_SYMBOL()
to rcu_nmi_exit(). What bad thing happens if we leave this on only
rcu_nmi_enter()?
It seemed odd to me we were not allowing kprobe on the rcu_nmi_enter() but
allowing it on exit (from a code reading standpoint) so my reaction was to
add it to both, but we could probably keep that as a separate
patch/discussion since it is slightly unrelated to the patch.. Sorry to
confuse the topic.
rcu_nmi_enter() was marked NOKPROBE or other reasons. See commit
c13324a505c77 ("x86/kprobes: Prohibit probing on functions before
kprobe_int3_handler()")
The issue was that we must not allow anything in do_int3() call kprobe
code before kprobe_int3_handler() is called. Because ist_enter() (in
do_int3()) calls rcu_nmi_enter() it had to be marked NOKPROBE. It had
nothing to do with it being RCU nor NMI, but because it was simply
called in do_int3().
Thus, there's no reason to make rcu_nmi_exit() NOKPROBE. But a commont
to why rcu_nmi_enter() would probably be useful, like below:
Thank you, Steve! Could I please have your Signed-off-by for this?
Sure, but it was untested ;-)
No problem! I will fire up rcutorture on it. ;-)
But experience indicates that you cannot even make a joke around here.
There is probably already someone out there somewhere building a
comment-checker based on deep semantic analysis and machine learning. :-/
quoted
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
I'd like a Reviewed-by from Masami though.
Sounds good! Masami, would you be willing to review?
Yes, the functions before calling kprobe_int3_handler() must not
be kprobed. It can cause an infinite recursive int3 trapping.
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Thank you both!
Like this?
Thanx, Paul
This is good to me.
BTW, if you consider the x86 specific code is in the generic file,
we can move NOKPROBE_SYMBOL() in arch/x86/kernel/traps.c.
(Sorry, I've hit this idea right now)
Thank you,
quoted hunk
------------------------------------------------------------------------
commit 1817fdc8f4e4bd18c76305c9b937fb0dccbb1583
Author: Steven Rostedt [off-list ref]
Date: Sat Feb 15 06:54:50 2020 -0800
rcu: Provide comment for NOKPROBE() on rcu_nmi_enter()
The rcu_nmi_enter() function was marked NOKPROBE() by commit
c13324a505c77 ("x86/kprobes: Prohibit probing on functions before
kprobe_int3_handler()") because the do_int3() call kprobe code must
not be invoked before kprobe_int3_handler() is called. It turns out
that ist_enter() (in do_int3()) calls rcu_nmi_enter(), hence the
marking NOKPROBE() being added to rcu_nmi_enter().
This commit therefore adds a comment documenting this line of reasoning.
Signed-off-by: Steven Rostedt [off-list ref]
Reviewed-by: Masami Hiramatsu [off-list ref]
Signed-off-by: Paul E. McKenney [off-list ref]
From: "Paul E. McKenney" <paulmck@kernel.org> Date: 2020-02-17 16:31:15
On Mon, Feb 17, 2020 at 05:55:19PM +0900, Masami Hiramatsu wrote:
On Sat, 15 Feb 2020 06:59:34 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
On Fri, Feb 14, 2020 at 03:19:06PM +0900, Masami Hiramatsu wrote:
quoted
On Thu, 13 Feb 2020 14:39:18 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 05:04:51PM -0500, Steven Rostedt wrote:
quoted
On Thu, 13 Feb 2020 13:50:04 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 04:38:25PM -0500, Steven Rostedt wrote:
quoted
[ Added Masami ]
On Thu, 13 Feb 2020 16:19:30 -0500
Joel Fernandes [off-list ref] wrote:
quoted
On Thu, Feb 13, 2020 at 12:54:42PM -0800, Paul E. McKenney wrote:
quoted
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
On Thu, Feb 13, 2020 at 10:56:12AM -0800, Paul E. McKenney wrote:
[...]
quoted
quoted
quoted
It might well be that I could make these functions be NMI-safe, but
rcu_prepare_for_idle() in particular would be a bit ugly at best.
So, before looking into that, I have a question. Given these proposed
changes, will rcu_nmi_exit_common() and rcu_nmi_enter_common() be able
to just use in_nmi()?
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
So something like this, then? This is untested, probably doesn't even
build, and could use some careful review from both Peter and Steve,
at least. As in the below is the second version of the patch, the first
having been missing a couple of important "!" characters.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
My compiler complained about the static and the __always_inline, so I
fixed those. But please help me out on adding the NOKPROBE_SYMBOL()
to rcu_nmi_exit(). What bad thing happens if we leave this on only
rcu_nmi_enter()?
It seemed odd to me we were not allowing kprobe on the rcu_nmi_enter() but
allowing it on exit (from a code reading standpoint) so my reaction was to
add it to both, but we could probably keep that as a separate
patch/discussion since it is slightly unrelated to the patch.. Sorry to
confuse the topic.
rcu_nmi_enter() was marked NOKPROBE or other reasons. See commit
c13324a505c77 ("x86/kprobes: Prohibit probing on functions before
kprobe_int3_handler()")
The issue was that we must not allow anything in do_int3() call kprobe
code before kprobe_int3_handler() is called. Because ist_enter() (in
do_int3()) calls rcu_nmi_enter() it had to be marked NOKPROBE. It had
nothing to do with it being RCU nor NMI, but because it was simply
called in do_int3().
Thus, there's no reason to make rcu_nmi_exit() NOKPROBE. But a commont
to why rcu_nmi_enter() would probably be useful, like below:
Thank you, Steve! Could I please have your Signed-off-by for this?
Sure, but it was untested ;-)
No problem! I will fire up rcutorture on it. ;-)
But experience indicates that you cannot even make a joke around here.
There is probably already someone out there somewhere building a
comment-checker based on deep semantic analysis and machine learning. :-/
quoted
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
I'd like a Reviewed-by from Masami though.
Sounds good! Masami, would you be willing to review?
Yes, the functions before calling kprobe_int3_handler() must not
be kprobed. It can cause an infinite recursive int3 trapping.
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Thank you both!
Like this?
Thanx, Paul
This is good to me.
Thank you for looking it over! (I already have your
BTW, if you consider the x86 specific code is in the generic file,
we can move NOKPROBE_SYMBOL() in arch/x86/kernel/traps.c.
(Sorry, I've hit this idea right now)
Might this affect other architectures with NMIs and probe-like things?
If so, it might make sense to leave it where it is.
Thanx, Paul
Thank you,
quoted
------------------------------------------------------------------------
commit 1817fdc8f4e4bd18c76305c9b937fb0dccbb1583
Author: Steven Rostedt [off-list ref]
Date: Sat Feb 15 06:54:50 2020 -0800
rcu: Provide comment for NOKPROBE() on rcu_nmi_enter()
The rcu_nmi_enter() function was marked NOKPROBE() by commit
c13324a505c77 ("x86/kprobes: Prohibit probing on functions before
kprobe_int3_handler()") because the do_int3() call kprobe code must
not be invoked before kprobe_int3_handler() is called. It turns out
that ist_enter() (in do_int3()) calls rcu_nmi_enter(), hence the
marking NOKPROBE() being added to rcu_nmi_enter().
This commit therefore adds a comment documenting this line of reasoning.
Signed-off-by: Steven Rostedt [off-list ref]
Reviewed-by: Masami Hiramatsu [off-list ref]
Signed-off-by: Paul E. McKenney [off-list ref]
On Mon, 17 Feb 2020 08:31:12 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
BTW, if you consider the x86 specific code is in the generic file,
we can move NOKPROBE_SYMBOL() in arch/x86/kernel/traps.c.
(Sorry, I've hit this idea right now)
Might this affect other architectures with NMIs and probe-like things?
If so, it might make sense to leave it where it is.
Yes, git grep shows that arm64 is using rcu_nmi_enter() in
debug_exception_enter().
OK, let's keep it, but maybe it is good to update the comment for
arm64 too. What about following?
+/*
+ * All functions in do_int3() on x86, do_debug_exception() on arm64 must be
+ * marked NOKPROBE before kprobes handler is called.
+ * ist_enter() on x86 and debug_exception_enter() on arm64 which is called
+ * before kprobes handle happens to call rcu_nmi_enter() which means
+ * that rcu_nmi_enter() must be marked NOKRPOBE.
+ */
Thank you,
--
Masami Hiramatsu [off-list ref]
From: "Paul E. McKenney" <paulmck@kernel.org> Date: 2020-02-18 16:12:34
On Tue, Feb 18, 2020 at 01:33:35PM +0900, Masami Hiramatsu wrote:
On Mon, 17 Feb 2020 08:31:12 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
quoted
BTW, if you consider the x86 specific code is in the generic file,
we can move NOKPROBE_SYMBOL() in arch/x86/kernel/traps.c.
(Sorry, I've hit this idea right now)
Might this affect other architectures with NMIs and probe-like things?
If so, it might make sense to leave it where it is.
Yes, git grep shows that arm64 is using rcu_nmi_enter() in
debug_exception_enter().
OK, let's keep it, but maybe it is good to update the comment for
arm64 too. What about following?
+/*
+ * All functions in do_int3() on x86, do_debug_exception() on arm64 must be
+ * marked NOKPROBE before kprobes handler is called.
+ * ist_enter() on x86 and debug_exception_enter() on arm64 which is called
+ * before kprobes handle happens to call rcu_nmi_enter() which means
+ * that rcu_nmi_enter() must be marked NOKRPOBE.
+ */
Would it work to describe the general problem, then give x86 details
as a specific example, as follows?
/*
* On some architectures, certain exceptions prohibit use of kprobes until
* the exception code path reaches a certain point. For example, on x86 all
* functions called by do_int3() must be marked NOKPROBE. However, once
* kprobe_int3_handler() is called, kprobing is permitted. Specifically,
* ist_enter() is called in do_int3() before kprobe_int3_handle().
* Furthermore, ist_enter() calls rcu_nmi_enter(), which means that
* rcu_nmi_enter() must be marked NOKRPOBE.
*/
That way, I don't feel like I need to update the commment each time
a new architecture adds this capability. ;-)
Thanx, Paul
----- On Feb 18, 2020, at 11:12 AM, paulmck paulmck@kernel.org wrote:
On Tue, Feb 18, 2020 at 01:33:35PM +0900, Masami Hiramatsu wrote:
quoted
On Mon, 17 Feb 2020 08:31:12 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
quoted
BTW, if you consider the x86 specific code is in the generic file,
we can move NOKPROBE_SYMBOL() in arch/x86/kernel/traps.c.
(Sorry, I've hit this idea right now)
Might this affect other architectures with NMIs and probe-like things?
If so, it might make sense to leave it where it is.
Yes, git grep shows that arm64 is using rcu_nmi_enter() in
debug_exception_enter().
OK, let's keep it, but maybe it is good to update the comment for
arm64 too. What about following?
+/*
+ * All functions in do_int3() on x86, do_debug_exception() on arm64 must be
+ * marked NOKPROBE before kprobes handler is called.
+ * ist_enter() on x86 and debug_exception_enter() on arm64 which is called
+ * before kprobes handle happens to call rcu_nmi_enter() which means
+ * that rcu_nmi_enter() must be marked NOKRPOBE.
+ */
Would it work to describe the general problem, then give x86 details
as a specific example, as follows?
/*
* On some architectures, certain exceptions prohibit use of kprobes until
* the exception code path reaches a certain point. For example, on x86 all
* functions called by do_int3() must be marked NOKPROBE. However, once
* kprobe_int3_handler() is called, kprobing is permitted. Specifically,
* ist_enter() is called in do_int3() before kprobe_int3_handle().
* Furthermore, ist_enter() calls rcu_nmi_enter(), which means that
* rcu_nmi_enter() must be marked NOKRPOBE.
*/
That way, I don't feel like I need to update the commment each time
a new architecture adds this capability. ;-)
I suspect this kind of comment would belong in a new
Documentation/features/kprobes/annotations.txt or something
similar. You might want to look at other "features" files to see
the expected layout.
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
From: Steven Rostedt <rostedt@goodmis.org> Date: 2020-02-18 16:35:08
On Tue, 18 Feb 2020 08:12:31 -0800
"Paul E. McKenney" [off-list ref] wrote:
Would it work to describe the general problem, then give x86 details
as a specific example, as follows?
/*
* On some architectures, certain exceptions prohibit use of kprobes until
* the exception code path reaches a certain point. For example, on x86 all
* functions called by do_int3() must be marked NOKPROBE. However, once
* kprobe_int3_handler() is called, kprobing is permitted. Specifically,
* ist_enter() is called in do_int3() before kprobe_int3_handle().
* Furthermore, ist_enter() calls rcu_nmi_enter(), which means that
* rcu_nmi_enter() must be marked NOKRPOBE.
*/
That way, I don't feel like I need to update the commment each time
a new architecture adds this capability. ;-)
I don't think this is going to be an issue for other archs, as they
don't have an IST.
-- Steve
From: Steven Rostedt <rostedt@goodmis.org> Date: 2020-02-18 17:46:13
On Tue, 18 Feb 2020 13:33:35 +0900
Masami Hiramatsu [off-list ref] wrote:
On Mon, 17 Feb 2020 08:31:12 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
quoted
BTW, if you consider the x86 specific code is in the generic file,
we can move NOKPROBE_SYMBOL() in arch/x86/kernel/traps.c.
(Sorry, I've hit this idea right now)
Might this affect other architectures with NMIs and probe-like things?
If so, it might make sense to leave it where it is.
Yes, git grep shows that arm64 is using rcu_nmi_enter() in
debug_exception_enter().
OK, let's keep it, but maybe it is good to update the comment for
arm64 too. What about following?
+/*
+ * All functions in do_int3() on x86, do_debug_exception() on arm64 must be
+ * marked NOKPROBE before kprobes handler is called.
+ * ist_enter() on x86 and debug_exception_enter() on arm64 which is called
+ * before kprobes handle happens to call rcu_nmi_enter() which means
+ * that rcu_nmi_enter() must be marked NOKRPOBE.
+ */
Ah, why don't we just say...
/*
* All functions called in the breakpoint trap handler (e.g. do_int3()
* on x86), must not allow kprobes until the kprobe breakpoint handler
* is called, otherwise it can cause an infinite recursion.
* On some archs, rcu_nmi_enter() is called in the breakpoint handler
* before the kprobe breakpoint handler is called, thus it must be
* marked as NOKPROBE.
*/
And that way we don't make this an arch specific comment.
-- Steve
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-18 20:07:38
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
quoted
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
@@ -651,25 +653,15 @@ static __always_inline void rcu_nmi_exit_common(bool irq) trace_rcu_dyntick(TPS("Startirq"), rdp->dynticks_nmi_nesting, 0, atomic_read(&rdp->dynticks)); WRITE_ONCE(rdp->dynticks_nmi_nesting, 0); /* Avoid store tearing. */- if (irq)+ if (!in_nmi()) rcu_prepare_for_idle(); rcu_dynticks_eqs_enter();- if (irq)+ if (!in_nmi()) rcu_dynticks_task_enter(); }
Boris and me have been going over the #MC code (and finding loads of
'interesting' code) and ran into ist_enter(), whish has the following
code:
/*
* We might have interrupted pretty much anything. In
* fact, if we're a machine check, we can even interrupt
* NMI processing. We don't want in_nmi() to return true,
* but we need to notify RCU.
*/
rcu_nmi_enter();
Which, to me, sounds all sorts of broken. The IST (be it #DB or #MC) can
happen while we're holding all sorts of locks. This must be an NMI-like
context.
From: "Paul E. McKenney" <paulmck@kernel.org> Date: 2020-02-18 20:17:32
On Tue, Feb 18, 2020 at 08:58:31PM +0100, Peter Zijlstra wrote:
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
quoted
quoted
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
quoted
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
@@ -651,25 +653,15 @@ static __always_inline void rcu_nmi_exit_common(bool irq) trace_rcu_dyntick(TPS("Startirq"), rdp->dynticks_nmi_nesting, 0, atomic_read(&rdp->dynticks)); WRITE_ONCE(rdp->dynticks_nmi_nesting, 0); /* Avoid store tearing. */- if (irq)+ if (!in_nmi()) rcu_prepare_for_idle(); rcu_dynticks_eqs_enter();- if (irq)+ if (!in_nmi()) rcu_dynticks_task_enter(); }
Boris and me have been going over the #MC code (and finding loads of
'interesting' code) and ran into ist_enter(), whish has the following
code:
/*
* We might have interrupted pretty much anything. In
* fact, if we're a machine check, we can even interrupt
* NMI processing. We don't want in_nmi() to return true,
* but we need to notify RCU.
*/
rcu_nmi_enter();
Which, to me, sounds all sorts of broken. The IST (be it #DB or #MC) can
happen while we're holding all sorts of locks. This must be an NMI-like
context.
Ouch! Looks like I need to hold off on getting rid of the "irq"
parameters if in_nmi() isn't going to be accurate.
Thanx, Paul
From: "Paul E. McKenney" <paulmck@kernel.org> Date: 2020-02-18 20:18:09
On Tue, Feb 18, 2020 at 12:46:09PM -0500, Steven Rostedt wrote:
On Tue, 18 Feb 2020 13:33:35 +0900
Masami Hiramatsu [off-list ref] wrote:
quoted
On Mon, 17 Feb 2020 08:31:12 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
quoted
BTW, if you consider the x86 specific code is in the generic file,
we can move NOKPROBE_SYMBOL() in arch/x86/kernel/traps.c.
(Sorry, I've hit this idea right now)
Might this affect other architectures with NMIs and probe-like things?
If so, it might make sense to leave it where it is.
Yes, git grep shows that arm64 is using rcu_nmi_enter() in
debug_exception_enter().
OK, let's keep it, but maybe it is good to update the comment for
arm64 too. What about following?
+/*
+ * All functions in do_int3() on x86, do_debug_exception() on arm64 must be
+ * marked NOKPROBE before kprobes handler is called.
+ * ist_enter() on x86 and debug_exception_enter() on arm64 which is called
+ * before kprobes handle happens to call rcu_nmi_enter() which means
+ * that rcu_nmi_enter() must be marked NOKRPOBE.
+ */
Ah, why don't we just say...
/*
* All functions called in the breakpoint trap handler (e.g. do_int3()
* on x86), must not allow kprobes until the kprobe breakpoint handler
* is called, otherwise it can cause an infinite recursion.
* On some archs, rcu_nmi_enter() is called in the breakpoint handler
* before the kprobe breakpoint handler is called, thus it must be
* marked as NOKPROBE.
*/
And that way we don't make this an arch specific comment.
That looks good to me. Masami, does this work for you?
Thanx, Paul
From: Peter Zijlstra <peterz@infradead.org> Date: 2020-02-18 20:40:43
On Tue, Feb 18, 2020 at 12:17:28PM -0800, Paul E. McKenney wrote:
On Tue, Feb 18, 2020 at 08:58:31PM +0100, Peter Zijlstra wrote:
quoted
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
quoted
quoted
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
quoted
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
@@ -651,25 +653,15 @@ static __always_inline void rcu_nmi_exit_common(bool irq) trace_rcu_dyntick(TPS("Startirq"), rdp->dynticks_nmi_nesting, 0, atomic_read(&rdp->dynticks)); WRITE_ONCE(rdp->dynticks_nmi_nesting, 0); /* Avoid store tearing. */- if (irq)+ if (!in_nmi()) rcu_prepare_for_idle(); rcu_dynticks_eqs_enter();- if (irq)+ if (!in_nmi()) rcu_dynticks_task_enter(); }
Boris and me have been going over the #MC code (and finding loads of
'interesting' code) and ran into ist_enter(), whish has the following
code:
/*
* We might have interrupted pretty much anything. In
* fact, if we're a machine check, we can even interrupt
* NMI processing. We don't want in_nmi() to return true,
* but we need to notify RCU.
*/
rcu_nmi_enter();
Which, to me, sounds all sorts of broken. The IST (be it #DB or #MC) can
happen while we're holding all sorts of locks. This must be an NMI-like
context.
Ouch! Looks like I need to hold off on getting rid of the "irq"
parameters if in_nmi() isn't going to be accurate.
I'm currently trying to twist my brain around all this, because I
suspect it's all completely broken one way or another.
But yes, we definitely need to fix this before your patch goes in.
From: "Paul E. McKenney" <paulmck@kernel.org> Date: 2020-02-18 21:39:28
On Tue, Feb 18, 2020 at 09:40:21PM +0100, Peter Zijlstra wrote:
On Tue, Feb 18, 2020 at 12:17:28PM -0800, Paul E. McKenney wrote:
quoted
On Tue, Feb 18, 2020 at 08:58:31PM +0100, Peter Zijlstra wrote:
quoted
On Thu, Feb 13, 2020 at 03:44:44PM -0500, Joel Fernandes wrote:
quoted
quoted
quoted
That _should_ already be the case today. That is, if we end up in a
tracer and in_nmi() is unreliable we're already screwed anyway.
quoted
I removed the static from rcu_nmi_enter()/exit() as it is called from
outside, that makes it build now. Updated below is Paul's diff. I also added
NOKPROBE_SYMBOL() to rcu_nmi_exit() to match rcu_nmi_enter() since it seemed
asymmetric.
@@ -651,25 +653,15 @@ static __always_inline void rcu_nmi_exit_common(bool irq) trace_rcu_dyntick(TPS("Startirq"), rdp->dynticks_nmi_nesting, 0, atomic_read(&rdp->dynticks)); WRITE_ONCE(rdp->dynticks_nmi_nesting, 0); /* Avoid store tearing. */- if (irq)+ if (!in_nmi()) rcu_prepare_for_idle(); rcu_dynticks_eqs_enter();- if (irq)+ if (!in_nmi()) rcu_dynticks_task_enter(); }
Boris and me have been going over the #MC code (and finding loads of
'interesting' code) and ran into ist_enter(), whish has the following
code:
/*
* We might have interrupted pretty much anything. In
* fact, if we're a machine check, we can even interrupt
* NMI processing. We don't want in_nmi() to return true,
* but we need to notify RCU.
*/
rcu_nmi_enter();
Which, to me, sounds all sorts of broken. The IST (be it #DB or #MC) can
happen while we're holding all sorts of locks. This must be an NMI-like
context.
Ouch! Looks like I need to hold off on getting rid of the "irq"
parameters if in_nmi() isn't going to be accurate.
I'm currently trying to twist my brain around all this, because I
suspect it's all completely broken one way or another.
But yes, we definitely need to fix this before your patch goes in.
OK. I will drop it later today, but leave tag in_nmi.2020.02.18a
pointing at it for future reference.
Thanx, Paul
On Tue, 18 Feb 2020 12:18:06 -0800
"Paul E. McKenney" [off-list ref] wrote:
On Tue, Feb 18, 2020 at 12:46:09PM -0500, Steven Rostedt wrote:
quoted
On Tue, 18 Feb 2020 13:33:35 +0900
Masami Hiramatsu [off-list ref] wrote:
quoted
On Mon, 17 Feb 2020 08:31:12 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
quoted
BTW, if you consider the x86 specific code is in the generic file,
we can move NOKPROBE_SYMBOL() in arch/x86/kernel/traps.c.
(Sorry, I've hit this idea right now)
Might this affect other architectures with NMIs and probe-like things?
If so, it might make sense to leave it where it is.
Yes, git grep shows that arm64 is using rcu_nmi_enter() in
debug_exception_enter().
OK, let's keep it, but maybe it is good to update the comment for
arm64 too. What about following?
+/*
+ * All functions in do_int3() on x86, do_debug_exception() on arm64 must be
+ * marked NOKPROBE before kprobes handler is called.
+ * ist_enter() on x86 and debug_exception_enter() on arm64 which is called
+ * before kprobes handle happens to call rcu_nmi_enter() which means
+ * that rcu_nmi_enter() must be marked NOKRPOBE.
+ */
Ah, why don't we just say...
/*
* All functions called in the breakpoint trap handler (e.g. do_int3()
* on x86), must not allow kprobes until the kprobe breakpoint handler
* is called, otherwise it can cause an infinite recursion.
* On some archs, rcu_nmi_enter() is called in the breakpoint handler
* before the kprobe breakpoint handler is called, thus it must be
* marked as NOKPROBE.
*/
And that way we don't make this an arch specific comment.
That looks good to me. Masami, does this work for you?
Yes, that looks good to me too :)
Thank you!
--
Masami Hiramatsu [off-list ref]
From: Thomas Gleixner <hidden> Date: 2020-03-06 00:42:47
Steven Rostedt [off-list ref] writes:
rcu_nmi_enter() was marked NOKPROBE or other reasons. See commit
Very well said: OR other reasons. I assume you meant 'for' but ...
c13324a505c77 ("x86/kprobes: Prohibit probing on functions before
kprobe_int3_handler()")
The issue was that we must not allow anything in do_int3() call kprobe
code before kprobe_int3_handler() is called. Because ist_enter() (in
do_int3()) calls rcu_nmi_enter() it had to be marked NOKPROBE. It had
nothing to do with it being RCU nor NMI, but because it was simply
called in do_int3().
Thus, there's no reason to make rcu_nmi_exit() NOKPROBE. But a commont
to why rcu_nmi_enter() would probably be useful, like below:
... this is really wrong.
While the int3 issue was the reason why it was marked NOKPROBE, fact is
that aside of int3 problem (which is probably true for any other
architecture using breakpoints for patching) any probe _before_ RCU is
watching and _after_ RCU stopped watching is broken. Same applies for
BPF and tracepoints which call into BPF or other nonsense.
Can we please stop claiming that instrumentation can touch anything it
wants and just admit that anything outside RCU covered regions is
off-limits for instrumentation? Same applies for entry code and critical
exceptions/traps.
There is a reason why the tracer can't trace itself and there are very
valid reasons to limit the instrumentation ability in other places.
It's nice to be able to see into 'everything' but for 99.9999% of the
cases the coverage of these things is absolutely irrelevant.
Yes I know, "Correctness first" is this old school thing for grumpy old
greybeards who are still stuck in the 90's. "Features first" is the new
mantra. I deal with that every day by mopping up the mess it creates.
Thanks,
tglx
Hi,
On Wed, 19 Feb 2020 11:45:10 +0900
Masami Hiramatsu [off-list ref] wrote:
On Tue, 18 Feb 2020 12:18:06 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
On Tue, Feb 18, 2020 at 12:46:09PM -0500, Steven Rostedt wrote:
quoted
On Tue, 18 Feb 2020 13:33:35 +0900
Masami Hiramatsu [off-list ref] wrote:
quoted
On Mon, 17 Feb 2020 08:31:12 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
quoted
BTW, if you consider the x86 specific code is in the generic file,
we can move NOKPROBE_SYMBOL() in arch/x86/kernel/traps.c.
(Sorry, I've hit this idea right now)
Might this affect other architectures with NMIs and probe-like things?
If so, it might make sense to leave it where it is.
Yes, git grep shows that arm64 is using rcu_nmi_enter() in
debug_exception_enter().
OK, let's keep it, but maybe it is good to update the comment for
arm64 too. What about following?
+/*
+ * All functions in do_int3() on x86, do_debug_exception() on arm64 must be
+ * marked NOKPROBE before kprobes handler is called.
+ * ist_enter() on x86 and debug_exception_enter() on arm64 which is called
+ * before kprobes handle happens to call rcu_nmi_enter() which means
+ * that rcu_nmi_enter() must be marked NOKRPOBE.
+ */
Ah, why don't we just say...
/*
* All functions called in the breakpoint trap handler (e.g. do_int3()
* on x86), must not allow kprobes until the kprobe breakpoint handler
* is called, otherwise it can cause an infinite recursion.
* On some archs, rcu_nmi_enter() is called in the breakpoint handler
* before the kprobe breakpoint handler is called, thus it must be
* marked as NOKPROBE.
*/
And that way we don't make this an arch specific comment.
That looks good to me. Masami, does this work for you?
From: Joel Fernandes <hidden> Date: 2020-03-06 18:47:07
On Sat, Mar 07, 2020 at 03:01:49AM +0900, Masami Hiramatsu wrote:
Hi,
On Wed, 19 Feb 2020 11:45:10 +0900
Masami Hiramatsu [off-list ref] wrote:
quoted
On Tue, 18 Feb 2020 12:18:06 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
On Tue, Feb 18, 2020 at 12:46:09PM -0500, Steven Rostedt wrote:
quoted
On Tue, 18 Feb 2020 13:33:35 +0900
Masami Hiramatsu [off-list ref] wrote:
quoted
On Mon, 17 Feb 2020 08:31:12 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
quoted
BTW, if you consider the x86 specific code is in the generic file,
we can move NOKPROBE_SYMBOL() in arch/x86/kernel/traps.c.
(Sorry, I've hit this idea right now)
Might this affect other architectures with NMIs and probe-like things?
If so, it might make sense to leave it where it is.
Yes, git grep shows that arm64 is using rcu_nmi_enter() in
debug_exception_enter().
OK, let's keep it, but maybe it is good to update the comment for
arm64 too. What about following?
+/*
+ * All functions in do_int3() on x86, do_debug_exception() on arm64 must be
+ * marked NOKPROBE before kprobes handler is called.
+ * ist_enter() on x86 and debug_exception_enter() on arm64 which is called
+ * before kprobes handle happens to call rcu_nmi_enter() which means
+ * that rcu_nmi_enter() must be marked NOKRPOBE.
+ */
Ah, why don't we just say...
/*
* All functions called in the breakpoint trap handler (e.g. do_int3()
* on x86), must not allow kprobes until the kprobe breakpoint handler
* is called, otherwise it can cause an infinite recursion.
* On some archs, rcu_nmi_enter() is called in the breakpoint handler
* before the kprobe breakpoint handler is called, thus it must be
* marked as NOKPROBE.
*/
And that way we don't make this an arch specific comment.
That looks good to me. Masami, does this work for you?
Yes, that looks good to me too :)
Aha! So then I'm glad I brought it up ;-) OCDs pay off these days :-D
thanks,
- Joel
From: Joel Fernandes <hidden> Date: 2020-03-06 19:11:58
On Sat, Mar 07, 2020 at 03:01:49AM +0900, Masami Hiramatsu wrote:
Hi,
On Wed, 19 Feb 2020 11:45:10 +0900
Masami Hiramatsu [off-list ref] wrote:
quoted
On Tue, 18 Feb 2020 12:18:06 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
On Tue, Feb 18, 2020 at 12:46:09PM -0500, Steven Rostedt wrote:
quoted
On Tue, 18 Feb 2020 13:33:35 +0900
Masami Hiramatsu [off-list ref] wrote:
quoted
On Mon, 17 Feb 2020 08:31:12 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
quoted
BTW, if you consider the x86 specific code is in the generic file,
we can move NOKPROBE_SYMBOL() in arch/x86/kernel/traps.c.
(Sorry, I've hit this idea right now)
Might this affect other architectures with NMIs and probe-like things?
If so, it might make sense to leave it where it is.
Yes, git grep shows that arm64 is using rcu_nmi_enter() in
debug_exception_enter().
OK, let's keep it, but maybe it is good to update the comment for
arm64 too. What about following?
+/*
+ * All functions in do_int3() on x86, do_debug_exception() on arm64 must be
+ * marked NOKPROBE before kprobes handler is called.
+ * ist_enter() on x86 and debug_exception_enter() on arm64 which is called
+ * before kprobes handle happens to call rcu_nmi_enter() which means
+ * that rcu_nmi_enter() must be marked NOKRPOBE.
+ */
Ah, why don't we just say...
/*
* All functions called in the breakpoint trap handler (e.g. do_int3()
* on x86), must not allow kprobes until the kprobe breakpoint handler
* is called, otherwise it can cause an infinite recursion.
* On some archs, rcu_nmi_enter() is called in the breakpoint handler
* before the kprobe breakpoint handler is called, thus it must be
* marked as NOKPROBE.
*/
And that way we don't make this an arch specific comment.
That looks good to me. Masami, does this work for you?
Makes sense, I am curious though why you thought before that the breakpoint
recursion was not possible *after* kprobe_int3_handler(). In the below thread
you said it is to be marked only for functions *before*
kprobe_int3_handler(). Was there a reason?
https://lore.kernel.org/lkml/154998793571.31052.11301258949601150994.stgit@devbox/
thanks,
- Joel
On Fri, 6 Mar 2020 14:11:51 -0500
Joel Fernandes [off-list ref] wrote:
On Sat, Mar 07, 2020 at 03:01:49AM +0900, Masami Hiramatsu wrote:
quoted
Hi,
On Wed, 19 Feb 2020 11:45:10 +0900
Masami Hiramatsu [off-list ref] wrote:
quoted
On Tue, 18 Feb 2020 12:18:06 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
On Tue, Feb 18, 2020 at 12:46:09PM -0500, Steven Rostedt wrote:
quoted
On Tue, 18 Feb 2020 13:33:35 +0900
Masami Hiramatsu [off-list ref] wrote:
quoted
On Mon, 17 Feb 2020 08:31:12 -0800
"Paul E. McKenney" [off-list ref] wrote:
quoted
quoted
BTW, if you consider the x86 specific code is in the generic file,
we can move NOKPROBE_SYMBOL() in arch/x86/kernel/traps.c.
(Sorry, I've hit this idea right now)
Might this affect other architectures with NMIs and probe-like things?
If so, it might make sense to leave it where it is.
Yes, git grep shows that arm64 is using rcu_nmi_enter() in
debug_exception_enter().
OK, let's keep it, but maybe it is good to update the comment for
arm64 too. What about following?
+/*
+ * All functions in do_int3() on x86, do_debug_exception() on arm64 must be
+ * marked NOKPROBE before kprobes handler is called.
+ * ist_enter() on x86 and debug_exception_enter() on arm64 which is called
+ * before kprobes handle happens to call rcu_nmi_enter() which means
+ * that rcu_nmi_enter() must be marked NOKRPOBE.
+ */
Ah, why don't we just say...
/*
* All functions called in the breakpoint trap handler (e.g. do_int3()
* on x86), must not allow kprobes until the kprobe breakpoint handler
* is called, otherwise it can cause an infinite recursion.
* On some archs, rcu_nmi_enter() is called in the breakpoint handler
* before the kprobe breakpoint handler is called, thus it must be
* marked as NOKPROBE.
*/
And that way we don't make this an arch specific comment.
That looks good to me. Masami, does this work for you?
Makes sense, I am curious though why you thought before that the breakpoint
recursion was not possible *after* kprobe_int3_handler(). In the below thread
you said it is to be marked only for functions *before*
kprobe_int3_handler(). Was there a reason?
https://lore.kernel.org/lkml/154998793571.31052.11301258949601150994.stgit@devbox/
Sorry, that was my simple mistake. When I tested the rcu_nmi_exit(), I forgot
to disable optprobe. So whole the do_int3() was not hit... (I had to think
deeper why the hit count of the probe was not incremented at that point.)
This time, I set 0 to the /proc/sys/debug/kprobes_optimization, and confirmed
this bug.
Thank you,
--
Masami Hiramatsu [off-list ref]