trace: Fix preempt_enable_no_resched() abuse [Linux 3.16.72]

This Linux kernel change "trace: Fix preempt_enable_no_resched() abuse" is included in the Linux 3.16.72 release. This change is authored by Peter Zijlstra <peterz [at]> on Tue Apr 23 22:03:18 2019 +0200. The commit for this change in Linux stable tree is ab4c96f (patch) which is from upstream commit d6097c9. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream d6097c9.

trace: Fix preempt_enable_no_resched() abuse

commit d6097c9e4454adf1f8f2c9547c2fa6060d55d952 upstream.

Unless the very next line is schedule(), or implies it, one must not use
preempt_enable_no_resched(). It can cause a preemption to go missing and
thereby cause arbitrary delays, breaking the PREEMPT=y invariant.

Link:[email protected]

Cc: Waiman Long <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: the arch/x86 maintainers <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Cc: Tim Chen <[email protected]>
Cc: huang ying <[email protected]>
Cc: Roman Gushchin <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Daniel Borkmann <[email protected]>
Fixes: 2c2d7329d8af ("tracing/ftrace: use preempt_enable_no_resched_notrace in ring_buffer_time_stamp()")
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>

There are 2 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 kernel/trace/ring_buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 107e8ce..89d99cc 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -729,7 +729,7 @@ u64 ring_buffer_time_stamp(struct ring_buffer *buffer, int cpu)

    time = rb_time_stamp(buffer);
-   preempt_enable_no_resched_notrace();
+   preempt_enable_notrace();

    return time;

Leave a Reply

Your email address will not be published. Required fields are marked *