ftrace dispatch function broken on 2.6.5
Hi Philippe,
it seems since I-pipe commit b115c4094d734e19fa7a96be1bf3958b3d244b8b on the ipipe-3.18 branch:
Revert "ipipe: Register function tracer for direct and exclusive invocation"
This reverts commit e00888b4aae45d9b84698a62079dde14c9be5fd3.
We now have an I-pipe-compatible dispatching function for ftrace.
The ftrace dispatching function causes the following warning at boot on x86_32 with all warnings/debugs enabled:
[ 4.730812] I-pipe: head domain Xenomai registered. [ 4.737967] I-pipe: Detected illicit call from head domain 'Xenomai' [ 4.737967] into a regular Linux service
Because it calls preempt_disable(), which is not safe to be called form root domain, when runnning over 2.6.x on an architecture such as x86_32 which does not have IPIPE_HAVE_SAFE_THREAD_INFO.
Should we make the ftrace dispatching function really I-pipe compatible by calling ipipe_preempt_disable() in that case instead? or should we make the patch revert conditional to !IPIPE_LEGACY or IPIPE_HAVE_SAFE_THREAD_INFO (but that would make only the I-pipe tracer work in that case).
Regards.
Signature · 2 lines
Gilles. https://click-hack.org
Quoted 20 lines · Gilles Chanteperdrix
Hi Philippe,
it seems since I-pipe commit
b115c4094d734e19fa7a96be1bf3958b3d244b8bon the ipipe-3.18 branch:
Revert "ipipe: Register function tracer for direct and exclusive invocation"This reverts commit
e00888b4aae45d9b84698a62079dde14c9be5fd3.We now have an I-pipe-compatible dispatching function for ftrace.
The ftrace dispatching function causes the following warning at boot on
x86_32with all warnings/debugs enabled:[ 4.730812] I-pipe: head domain Xenomai registered. [ 4.737967] I-pipe: Detected illicit call from head domain 'Xenomai' [ 4.737967] into a regular Linux serviceBecause it calls
preempt_disable(), which is not safe to be called form root domain, when runnning over 2.6.x on an architecture such asx86_32which does not haveIPIPE_HAVE_SAFE_THREAD_INFO.
Quoted 6 lines
Should we make the ftrace dispatching function really I-pipe compatible by calling
ipipe_preempt_disable()in that case instead? or should we make the patch revert conditional to !IPIPE_LEGACY orIPIPE_HAVE_SAFE_THREAD_INFO(but that would make only the I-pipe tracer work in that case).
I would go for the change which has the lesser impact on the mainline code; that would be option #1.
Signature · 1 line
Philippe.
Quoted 28 lines · Philippe Gerum
Quoted 20 lines · Gilles Chanteperdrix
Hi Philippe,
it seems since I-pipe commit
b115c4094d734e19fa7a96be1bf3958b3d244b8bon the ipipe-3.18 branch:
Revert "ipipe: Register function tracer for direct and exclusive invocation"This reverts commit
e00888b4aae45d9b84698a62079dde14c9be5fd3.We now have an I-pipe-compatible dispatching function for ftrace.
The ftrace dispatching function causes the following warning at boot on
x86_32with all warnings/debugs enabled:[ 4.730812] I-pipe: head domain Xenomai registered. [ 4.737967] I-pipe: Detected illicit call from head domain 'Xenomai' [ 4.737967] into a regular Linux serviceBecause it calls
preempt_disable(), which is not safe to be called form root domain, when runnning over 2.6.x on an architecture such asx86_32which does not haveIPIPE_HAVE_SAFE_THREAD_INFO.Quoted 6 lines
Should we make the ftrace dispatching function really I-pipe compatible by calling
ipipe_preempt_disable()in that case instead? or should we make the patch revert conditional to !IPIPE_LEGACY orIPIPE_HAVE_SAFE_THREAD_INFO(but that would make only the I-pipe tracer work in that case).
Quoted 2 lines
I would go for the change which has the lesser impact on the mainline code; that would be option #1.
Ok. Something else. Commit fdb5d54d04b8c3b6b6a6ad7ac2b6248cf0b415e0:
ipipe: Avoid rescheduling from __ftrace_ops_list_func in illegal contexts
The ftrace callback dispatcher may be called with hard irqs disabled or even over the head domain. We cannot allow any rescheduling in that case, but also do not have: only non-urgent events are expected to be kicked-off from ftrace callbacks, and those will at latest be handled on the next Linux timer tick.
Added the following code to the ftrace dispatch function:
+#ifdef CONFIG_IPIPE
+ if (hard_irqs_disabled() || !__ipipe_root_p)
+ /*
+ * Nothing urgent to schedule here. At latest the timer tick + * will pick up whatever the tracing functions kicked off. + */
+ preempt_enable_no_resched_notrace();
+ else
+#endif
+ preempt_enable_notrace();
Should not this go to the generic definition of preempt_enable() ? I mean if in the !LEGACY case, it is now legal to call preempt_enable() over non root contexts or with hard irqs off, so, does it really make sense to fix all the preempt_enable() spots one by one?
Signature · 2 lines
Gilles. https://click-hack.org
Quoted 28 lines · Philippe Gerum
Quoted 20 lines · Gilles Chanteperdrix
Hi Philippe,
it seems since I-pipe commit
b115c4094d734e19fa7a96be1bf3958b3d244b8bon the ipipe-3.18 branch:
Revert "ipipe: Register function tracer for direct and exclusive invocation"This reverts commit
e00888b4aae45d9b84698a62079dde14c9be5fd3.We now have an I-pipe-compatible dispatching function for ftrace.
The ftrace dispatching function causes the following warning at boot on
x86_32with all warnings/debugs enabled:[ 4.730812] I-pipe: head domain Xenomai registered. [ 4.737967] I-pipe: Detected illicit call from head domain 'Xenomai' [ 4.737967] into a regular Linux serviceBecause it calls
preempt_disable(), which is not safe to be called form root domain, when runnning over 2.6.x on an architecture such asx86_32which does not haveIPIPE_HAVE_SAFE_THREAD_INFO.Quoted 6 lines
Should we make the ftrace dispatching function really I-pipe compatible by calling
ipipe_preempt_disable()in that case instead? or should we make the patch revert conditional to !IPIPE_LEGACY orIPIPE_HAVE_SAFE_THREAD_INFO(but that would make only the I-pipe tracer work in that case).
Quoted 2 lines
I would go for the change which has the lesser impact on the mainline code; that would be option #1.
Ok, now I get:
12.958818] I-pipe: Detected stalled head domain, probably caused by a bug.
[ 12.958818] A critical section may have been left unterminated.
I guess in the following sequence:
#define hard_preempt_disable() \
({ \
unsigned long __flags__; \
__flags__ = hard_local_irq_save(); \
if (__ipipe_root_p) \
preempt_disable(); \
__flags__; \
})preempt_disable() gets called with the head domain stalled, while current domain is root, and ipipe_root_only() treats this as an error.
Signature · 2 lines
Gilles. https://click-hack.org
Quoted 48 lines · Gilles Chanteperdrix
Quoted 28 lines · Philippe Gerum
Quoted 20 lines · Gilles Chanteperdrix
Hi Philippe,
it seems since I-pipe commit
b115c4094d734e19fa7a96be1bf3958b3d244b8bon the ipipe-3.18 branch:
Revert "ipipe: Register function tracer for direct and exclusive invocation"This reverts commit
e00888b4aae45d9b84698a62079dde14c9be5fd3.We now have an I-pipe-compatible dispatching function for ftrace.
The ftrace dispatching function causes the following warning at boot on
x86_32with all warnings/debugs enabled:[ 4.730812] I-pipe: head domain Xenomai registered. [ 4.737967] I-pipe: Detected illicit call from head domain 'Xenomai' [ 4.737967] into a regular Linux serviceBecause it calls
preempt_disable(), which is not safe to be called form root domain, when runnning over 2.6.x on an architecture such asx86_32which does not haveIPIPE_HAVE_SAFE_THREAD_INFO.Quoted 6 lines
Should we make the ftrace dispatching function really I-pipe compatible by calling
ipipe_preempt_disable()in that case instead? or should we make the patch revert conditional to !IPIPE_LEGACY orIPIPE_HAVE_SAFE_THREAD_INFO(but that would make only the I-pipe tracer work in that case).Quoted 2 lines
I would go for the change which has the lesser impact on the mainline code; that would be option #1.
Ok, now I get:
12.958818] I-pipe: Detected stalled head domain, probably caused by a bug.
[ 12.958818] A critical section may have been left unterminated.I guess in the following sequence:
#define hard_preempt_disable() \ ({ \ unsigned long __flags__; \ __flags__ = hard_local_irq_save(); \ if (__ipipe_root_p) \ preempt_disable(); \ __flags__; \ })
Quoted 3 lines
preempt_disable()gets called with the head domain stalled, while current domain is root, andipipe_root_only()treats this as an error.
So, I have disabled context checking around the call to preempt_disable(), see the following patch, but the tracer overhead becomes huge.
include/linux/ipipe_base.h +2 -0
@@ -311,6 +311,8 @@ static inline void __ipipe_report_cleanup(struct mm_struct *mm) { }static inline void __ipipe_init_taskinfo (struct task_struct *p) { } +#define hard_preempt_disable_notrace () ({ preempt_disable_notrace(); 0; }) +#define hard_preempt_enable_notrace (flags) ({ preempt_enable_notrace(); (void)(flags); })#define hard_preempt_disable () ({ preempt_disable(); 0; })#define hard_preempt_enable (flags) ({ preempt_enable(); (void)(flags); })
include/linux/preempt.h +44 -15
67 lines not on this page · raw message
kernel/trace/ftrace.c +35 -11
69 lines not on this page · raw message
Signature · 2 lines
Gilles. https://click-hack.org
Quoted 49 lines · Gilles Chanteperdrix
Quoted 48 lines · Gilles Chanteperdrix
Quoted 28 lines · Philippe Gerum
Quoted 20 lines · Gilles Chanteperdrix
Hi Philippe,
it seems since I-pipe commit
b115c4094d734e19fa7a96be1bf3958b3d244b8bon the ipipe-3.18 branch:
Revert "ipipe: Register function tracer for direct and exclusive invocation"This reverts commit
e00888b4aae45d9b84698a62079dde14c9be5fd3.We now have an I-pipe-compatible dispatching function for ftrace.
The ftrace dispatching function causes the following warning at boot on
x86_32with all warnings/debugs enabled:[ 4.730812] I-pipe: head domain Xenomai registered. [ 4.737967] I-pipe: Detected illicit call from head domain 'Xenomai' [ 4.737967] into a regular Linux serviceBecause it calls
preempt_disable(), which is not safe to be called form root domain, when runnning over 2.6.x on an architecture such asx86_32which does not haveIPIPE_HAVE_SAFE_THREAD_INFO.Quoted 6 lines
Should we make the ftrace dispatching function really I-pipe compatible by calling
ipipe_preempt_disable()in that case instead? or should we make the patch revert conditional to !IPIPE_LEGACY orIPIPE_HAVE_SAFE_THREAD_INFO(but that would make only the I-pipe tracer work in that case).Quoted 2 lines
I would go for the change which has the lesser impact on the mainline code; that would be option #1.
Ok, now I get:
12.958818] I-pipe: Detected stalled head domain, probably caused by a bug.
[ 12.958818] A critical section may have been left unterminated.I guess in the following sequence:
#define hard_preempt_disable() \ ({ \ unsigned long __flags__; \ __flags__ = hard_local_irq_save(); \ if (__ipipe_root_p) \ preempt_disable(); \ __flags__; \ })
Quoted 7 lines
Quoted 3 lines
preempt_disable()gets called with the head domain stalled, while current domain is root, andipipe_root_only()treats this as an error.So, I have disabled context checking around the call to
preempt_disable(), see the following patch, but the tracer overhead becomes huge.
We get a lot of recursion, this is the probable cause of the overhead.
Signature · 2 lines
Gilles. https://click-hack.org
Quoted 54 lines · Gilles Chanteperdrix
Quoted 53 lines · Gilles Chanteperdrix
Quoted 51 lines · Gilles Chanteperdrix
Quoted 28 lines · Philippe Gerum
Quoted 20 lines · Gilles Chanteperdrix
Hi Philippe,
it seems since I-pipe commit
b115c4094d734e19fa7a96be1bf3958b3d244b8bon the ipipe-3.18 branch:
Revert "ipipe: Register function tracer for direct and exclusive invocation"This reverts commit
e00888b4aae45d9b84698a62079dde14c9be5fd3.We now have an I-pipe-compatible dispatching function for ftrace.
The ftrace dispatching function causes the following warning at boot on
x86_32with all warnings/debugs enabled:[ 4.730812] I-pipe: head domain Xenomai registered. [ 4.737967] I-pipe: Detected illicit call from head domain 'Xenomai' [ 4.737967] into a regular Linux serviceBecause it calls
preempt_disable(), which is not safe to be called form root domain, when runnning over 2.6.x on an architecture such asx86_32which does not haveIPIPE_HAVE_SAFE_THREAD_INFO.Quoted 6 lines
Should we make the ftrace dispatching function really I-pipe compatible by calling
ipipe_preempt_disable()in that case instead? or should we make the patch revert conditional to !IPIPE_LEGACY orIPIPE_HAVE_SAFE_THREAD_INFO(but that would make only the I-pipe tracer work in that case).Quoted 2 lines
I would go for the change which has the lesser impact on the mainline code; that would be option #1.
Ok, now I get:
12.958818] I-pipe: Detected stalled head domain, probably caused by a bug.
[ 12.958818] A critical section may have been left unterminated.I guess in the following sequence:
#define hard_preempt_disable() \ ({ \ unsigned long __flags__; \ __flags__ = hard_local_irq_save(); \ if (__ipipe_root_p) \ preempt_disable(); \ __flags__; \ })
preempt_disable()gets called with the head domain stalled, while current domain is root, andipipe_root_only()treats this as an error.
Quoted 6 lines
Quoted 3 lines
So, I have disabled context checking around the call to
preempt_disable(), see the following patch, but the tracer overhead becomes huge.We get a lot of recursion, this is the probable cause of the overhead.
In summary: I think the shortest solution for now is to just revert b115c4094d734e19fa7a96be1bf3958b3d244b8b
Using ftrace with I-pipe currently does not work. First there is the problem of preempt_disable/preempt_enable with legacy, but there is also the problem of recursion: if ftrace gets called again (for instance if there is an irq) while in __ftrace_ops_list_func, recursion is detected and nothing gets recorded. To convince yourself that it does in fact, happen a lot, you can try the following patch:
kernel/trace/ftrace.c +8 -1
@@ -4894,9 +4894,16 @@ __ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,struct ftrace_ops *op;int bit; +if (ftrace_disabled) +return ; + bit =trace_test_and_set_recursion (TRACE_LIST_START ,TRACE_LIST_MAX ); -if (bit <0 ) +if (bit <0 ) { + ftrace_disabled =1 ; +printk ("Recursion at %pF/%pF\n" , (void *)ip, (void *)parent_ip); + ftrace_disabled =0 ;return ; + }/* * Some of the ops may be dynamically allocated,
To fix this, we would probably need some more bits in trace_test_and_set_recursion, and some instrumentation of the I-pipe core to detect the additional contexts (like say, "head domain in interrupt").
Signature · 2 lines
Gilles. https://click-hack.org
Quoted 53 lines · Gilles Chanteperdrix
Quoted 28 lines · Philippe Gerum
Quoted 20 lines · Gilles Chanteperdrix
Hi Philippe,
it seems since I-pipe commit
b115c4094d734e19fa7a96be1bf3958b3d244b8bon the ipipe-3.18 branch:
Revert "ipipe: Register function tracer for direct and exclusive invocation"This reverts commit
e00888b4aae45d9b84698a62079dde14c9be5fd3.We now have an I-pipe-compatible dispatching function for ftrace.
The ftrace dispatching function causes the following warning at boot on
x86_32with all warnings/debugs enabled:[ 4.730812] I-pipe: head domain Xenomai registered. [ 4.737967] I-pipe: Detected illicit call from head domain 'Xenomai' [ 4.737967] into a regular Linux serviceBecause it calls
preempt_disable(), which is not safe to be called form root domain, when runnning over 2.6.x on an architecture such asx86_32which does not haveIPIPE_HAVE_SAFE_THREAD_INFO.Quoted 6 lines
Should we make the ftrace dispatching function really I-pipe compatible by calling
ipipe_preempt_disable()in that case instead? or should we make the patch revert conditional to !IPIPE_LEGACY orIPIPE_HAVE_SAFE_THREAD_INFO(but that would make only the I-pipe tracer work in that case).Quoted 2 lines
I would go for the change which has the lesser impact on the mainline code; that would be option #1.
Ok. Something else. Commit
fdb5d54d04b8c3b6b6a6ad7ac2b6248cf0b415e0:
ipipe: Avoid rescheduling from__ftrace_ops_list_funcin illegal contextsThe ftrace callback dispatcher may be called with hard irqs disabled or even over the head domain. We cannot allow any rescheduling in that case, but also do not have: only non-urgent events are expected to be kicked-off from ftrace callbacks, and those will at latest be handled on the next Linux timer tick.
Added the following code to the ftrace dispatch function:
(quoted diff) +10
-0+#ifdef CONFIG_IPIPE + if (hard_irqs_disabled() || !__ipipe_root_p) + /* + * Nothing urgent to schedule here. At latest the timer tick + * will pick up whatever the tracing functions kicked off. + */ + preempt_enable_no_resched_notrace(); + else +#endif + preempt_enable_notrace();
Quoted 6 lines
Should not this go to the generic definition of
preempt_enable()? I mean if in the !LEGACY case, it is now legal to callpreempt_enable()over non root contexts or with hard irqs off, so, does it really make sense to fix all thepreempt_enable()spots one by one?
That would add a useless branch to hundreds of code paths, which can never run with hard irqs off and/or over the head domain. Besides, this might prevent the context check in schedule_debug() to run, papering over a bug. On the other end, specifically annotating the very few code spots affected by the pipeline, which must not reschedule after re-enabling preemption seems better maintenance-wise.
I would just use a specific annotation folding all the lengthy code block above into a single statement.
Signature · 1 line
Philippe.
Quoted 68 lines · Philippe Gerum
Quoted 53 lines · Gilles Chanteperdrix
Quoted 28 lines · Philippe Gerum
Quoted 20 lines · Gilles Chanteperdrix
Hi Philippe,
it seems since I-pipe commit
b115c4094d734e19fa7a96be1bf3958b3d244b8bon the ipipe-3.18 branch:
Revert "ipipe: Register function tracer for direct and exclusive invocation"This reverts commit
e00888b4aae45d9b84698a62079dde14c9be5fd3.We now have an I-pipe-compatible dispatching function for ftrace.
The ftrace dispatching function causes the following warning at boot on
x86_32with all warnings/debugs enabled:[ 4.730812] I-pipe: head domain Xenomai registered. [ 4.737967] I-pipe: Detected illicit call from head domain 'Xenomai' [ 4.737967] into a regular Linux serviceBecause it calls
preempt_disable(), which is not safe to be called form root domain, when runnning over 2.6.x on an architecture such asx86_32which does not haveIPIPE_HAVE_SAFE_THREAD_INFO.Quoted 6 lines
Should we make the ftrace dispatching function really I-pipe compatible by calling
ipipe_preempt_disable()in that case instead? or should we make the patch revert conditional to !IPIPE_LEGACY orIPIPE_HAVE_SAFE_THREAD_INFO(but that would make only the I-pipe tracer work in that case).Quoted 2 lines
I would go for the change which has the lesser impact on the mainline code; that would be option #1.
Ok. Something else. Commit
fdb5d54d04b8c3b6b6a6ad7ac2b6248cf0b415e0:
ipipe: Avoid rescheduling from__ftrace_ops_list_funcin illegal contextsThe ftrace callback dispatcher may be called with hard irqs disabled or even over the head domain. We cannot allow any rescheduling in that case, but also do not have: only non-urgent events are expected to be kicked-off from ftrace callbacks, and those will at latest be handled on the next Linux timer tick.
Added the following code to the ftrace dispatch function:
(quoted diff) +10
-0+#ifdef CONFIG_IPIPE + if (hard_irqs_disabled() || !__ipipe_root_p) + /* + * Nothing urgent to schedule here. At latest the timer tick + * will pick up whatever the tracing functions kicked off. + */ + preempt_enable_no_resched_notrace(); + else +#endif + preempt_enable_notrace();Quoted 6 lines
Should not this go to the generic definition of
preempt_enable()? I mean if in the !LEGACY case, it is now legal to callpreempt_enable()over non root contexts or with hard irqs off, so, does it really make sense to fix all thepreempt_enable()spots one by one?That would add a useless branch to hundreds of code paths, which can never run with hard irqs off and/or over the head domain. Besides, this might prevent the context check in
schedule_debug()to run, papering over a bug. On the other end, specifically annotating the very few code spots affected by the pipeline, which must not reschedule after re-enabling preemption seems better maintenance-wise.
Quoted 2 lines
I would just use a specific annotation folding all the lengthy code block above into a single statement.
Yeah, well, the above code does not work anyway. See other mails about ftrace.
Signature · 2 lines
Gilles. https://click-hack.org
Quoted 69 lines · Gilles Chanteperdrix
Quoted 68 lines · Philippe Gerum
Quoted 53 lines · Gilles Chanteperdrix
Quoted 28 lines · Philippe Gerum
Quoted 20 lines · Gilles Chanteperdrix
Hi Philippe,
it seems since I-pipe commit
b115c4094d734e19fa7a96be1bf3958b3d244b8bon the ipipe-3.18 branch:
Revert "ipipe: Register function tracer for direct and exclusive invocation"This reverts commit
e00888b4aae45d9b84698a62079dde14c9be5fd3.We now have an I-pipe-compatible dispatching function for ftrace.
The ftrace dispatching function causes the following warning at boot on
x86_32with all warnings/debugs enabled:[ 4.730812] I-pipe: head domain Xenomai registered. [ 4.737967] I-pipe: Detected illicit call from head domain 'Xenomai' [ 4.737967] into a regular Linux serviceBecause it calls
preempt_disable(), which is not safe to be called form root domain, when runnning over 2.6.x on an architecture such asx86_32which does not haveIPIPE_HAVE_SAFE_THREAD_INFO.Quoted 6 lines
Should we make the ftrace dispatching function really I-pipe compatible by calling
ipipe_preempt_disable()in that case instead? or should we make the patch revert conditional to !IPIPE_LEGACY orIPIPE_HAVE_SAFE_THREAD_INFO(but that would make only the I-pipe tracer work in that case).Quoted 2 lines
I would go for the change which has the lesser impact on the mainline code; that would be option #1.
Ok. Something else. Commit
fdb5d54d04b8c3b6b6a6ad7ac2b6248cf0b415e0:
ipipe: Avoid rescheduling from__ftrace_ops_list_funcin illegal contextsThe ftrace callback dispatcher may be called with hard irqs disabled or even over the head domain. We cannot allow any rescheduling in that case, but also do not have: only non-urgent events are expected to be kicked-off from ftrace callbacks, and those will at latest be handled on the next Linux timer tick.
Added the following code to the ftrace dispatch function:
(quoted diff) +10
-0+#ifdef CONFIG_IPIPE + if (hard_irqs_disabled() || !__ipipe_root_p) + /* + * Nothing urgent to schedule here. At latest the timer tick + * will pick up whatever the tracing functions kicked off. + */ + preempt_enable_no_resched_notrace(); + else +#endif + preempt_enable_notrace();Quoted 6 lines
Should not this go to the generic definition of
preempt_enable()? I mean if in the !LEGACY case, it is now legal to callpreempt_enable()over non root contexts or with hard irqs off, so, does it really make sense to fix all thepreempt_enable()spots one by one?That would add a useless branch to hundreds of code paths, which can never run with hard irqs off and/or over the head domain. Besides, this might prevent the context check in
schedule_debug()to run, papering over a bug. On the other end, specifically annotating the very few code spots affected by the pipeline, which must not reschedule after re-enabling preemption seems better maintenance-wise.
Quoted 6 lines
Quoted 2 lines
I would just use a specific annotation folding all the lengthy code block above into a single statement.
Yeah, well, the above code does not work anyway. See other mails about ftrace.
I saw them, I'm discussing about reducing the impact of the pipeline changes on the vanilla kernel in general, keeping the corner cases annotated.
Signature · 1 line
Philippe.