Blame SOURCES/rhbz2022849.patch

2464b2
commit 0bd97a8061c2ebbe792da8b662c5d19b2f1af02c
2464b2
Author: William Cohen <wcohen@redhat.com>
2464b2
Date:   Mon Sep 13 21:32:38 2021 -0400
2464b2
2464b2
    Use task_state tapset function to avoid task_struct changes
2464b2
    
2464b2
    The Linux 5.14 kernel's task_struct changed the state field to
2464b2
    __state.  The task_state tapset function selects the appropriate
2464b2
    version.  Make the scheduler.stp tapset and schedtimes.stp example use
2464b2
    the task_state function rather than directly trying to access the
2464b2
    task_struct state field (and get it wrong for newer kernels).
2464b2
2464b2
diff --git a/tapset/linux/scheduler.stp b/tapset/linux/scheduler.stp
2464b2
index 7338e9008..4667ab53a 100644
2464b2
--- a/tapset/linux/scheduler.stp
2464b2
+++ b/tapset/linux/scheduler.stp
2464b2
@@ -138,7 +138,7 @@ probe scheduler.ctxswitch = kernel.trace("sched_switch") !,
2464b2
 		prev_tid = $prev_p->pid
2464b2
 		prev_task = $prev_p
2464b2
 		prev_task_name = task_execname($prev_p)
2464b2
-		prevtsk_state = $prev_p->state
2464b2
+		prevtsk_state = task_state($prev_p)
2464b2
 	}
2464b2
 	else {
2464b2
 		prev_priority = $prev->prio
2464b2
@@ -146,7 +146,7 @@ probe scheduler.ctxswitch = kernel.trace("sched_switch") !,
2464b2
 		prev_tid = $prev->pid
2464b2
 		prev_task = $prev
2464b2
 		prev_task_name = task_execname($prev)
2464b2
-		prevtsk_state = $prev->state
2464b2
+		prevtsk_state = task_state($prev)
2464b2
 	}
2464b2
 
2464b2
 	if (@defined($next)) {
2464b2
@@ -155,7 +155,7 @@ probe scheduler.ctxswitch = kernel.trace("sched_switch") !,
2464b2
 		next_tid = $next->pid
2464b2
 		next_task = $next
2464b2
 		next_task_name = task_execname($next)
2464b2
-		nexttsk_state = $next->state
2464b2
+		nexttsk_state = task_state($next)
2464b2
 	}
2464b2
 	else if (@defined($next_p)) {
2464b2
 		next_priority = $next_p->prio
2464b2
@@ -163,7 +163,7 @@ probe scheduler.ctxswitch = kernel.trace("sched_switch") !,
2464b2
 		next_tid = $next_p->pid
2464b2
 		next_task = $next_p
2464b2
 		next_task_name = task_execname($next_p)
2464b2
-		nexttsk_state = $next_p->state
2464b2
+		nexttsk_state = task_state($next_p)
2464b2
 	}
2464b2
 	else {
2464b2
 		next_priority = $new->prio
2464b2
@@ -171,7 +171,7 @@ probe scheduler.ctxswitch = kernel.trace("sched_switch") !,
2464b2
 		next_tid = $new->pid
2464b2
 		next_task = $new
2464b2
 		next_task_name = task_execname($new)
2464b2
-		nexttsk_state = $new->state
2464b2
+		nexttsk_state = task_state($new)
2464b2
 	}
2464b2
 }
2464b2
 
2464b2
diff --git a/testsuite/systemtap.examples/process/schedtimes.stp b/testsuite/systemtap.examples/process/schedtimes.stp
2464b2
index 4e422c893..ee1053045 100755
2464b2
--- a/testsuite/systemtap.examples/process/schedtimes.stp
2464b2
+++ b/testsuite/systemtap.examples/process/schedtimes.stp
2464b2
@@ -99,7 +99,7 @@ probe kernel.trace("sched_switch")
2464b2
   // Task $prev is scheduled off this cpu
2464b2
   if (task_targeted($prev)) {
2464b2
     pid = $prev->pid
2464b2
-    state = $prev->state
2464b2
+    state = task_state($prev)
2464b2
     update_times(pid, timestamp())
2464b2
 
2464b2
     if (state > 0) {
2464b2
2464b2
commit a29f65d5750f6379afeca99c5d641598ff638517
2464b2
Author: Stan Cox <scox@redhat.com>
2464b2
Date:   Sun Jul 18 21:32:51 2021 -0400
2464b2
2464b2
    PR28079: Adapt to kernel 5.14 task_struct.__state change
2464b2
    
2464b2
    Use signal_wake_up_state for the 5.14 kernel which changed volatile long state to unsigned int __state.
2464b2
2464b2
diff --git a/buildrun.cxx b/buildrun.cxx
2464b2
index a1332a687..ae27ddea4 100644
2464b2
--- a/buildrun.cxx
2464b2
+++ b/buildrun.cxx
2464b2
@@ -523,3 +523,4 @@ compile_pass (systemtap_session& s)
2464b2
   output_autoconf(s, o, cs, "autoconf-lockdown-kernel.c", "STAPCONF_LOCKDOWN_KERNEL", NULL);
2464b2
+  output_autoconf(s, o, cs, "autoconf-task-state.c", "STAPCONF_TASK_STATE", NULL);
2464b2
   
2464b2
   // used by runtime/linux/netfilter.c
2464b2
   output_exportconf(s, o2, "nf_register_hook", "STAPCONF_NF_REGISTER_HOOK");
2464b2
diff --git a/runtime/linux/autoconf-task-state.c b/runtime/linux/autoconf-task-state.c
2464b2
new file mode 100644
2464b2
index 000000000..27a1d7c13
2464b2
--- /dev/null
2464b2
+++ b/runtime/linux/autoconf-task-state.c
2464b2
@@ -0,0 +1,18 @@
2464b2
+/*
2464b2
+ * Is this a kernel prior to the following kernel commit:
2464b2
+ *
2464b2
+ * commit	2f064a59a11ff9bc22e52e9678bc601404c7cb34
2464b2
+ * Author:	Peter Zijlstra <peterz@infradead.org>
2464b2
+ * Date:	2021-06-11 10:28:17 +0200
2464b2
+ *
2464b2
+ * sched: Change task_struct::state
2464b2
+ * Change the type and name of task_struct::state. Drop the volatile and
2464b2
+ * shrink it to an 'unsigned int'. Rename it in order to find all uses
2464b2
+ * such that we can use READ_ONCE/WRITE_ONCE as appropriate.
2464b2
+ */
2464b2
+
2464b2
+#include <linux/sched.h>
2464b2
+
2464b2
+unsigned int bar (struct task_struct *foo) { 
2464b2
+  return (foo->state = 0); 
2464b2
+}
2464b2
diff --git a/runtime/stp_utrace.c b/runtime/stp_utrace.c
2464b2
index ff8c5549d..d63e6366c 100644
2464b2
--- a/runtime/stp_utrace.c
2464b2
+++ b/runtime/stp_utrace.c
2464b2
@@ -33,9 +33,12 @@
2464b2
 #if defined(__set_task_state)
2464b2
 #define __stp_set_task_state(tsk, state_value)		\
2464b2
 	__set_task_state((tsk), (state_value))
2464b2
-#else
2464b2
+#elif defined(STAPCONF_TASK_STATE)
2464b2
 #define __stp_set_task_state(tsk, state_value)		\
2464b2
 	do { (tsk)->state = (state_value); } while (0)
2464b2
+#else
2464b2
+#define __stp_set_task_state(tsk, state_value)		\
2464b2
+	signal_wake_up_state((tsk), (state_value))
2464b2
 #endif
2464b2
 
2464b2
 // For now, disable the task_work_queue on non-RT kernels.
2464b2
@@ -1263,7 +1266,7 @@ static void utrace_wakeup(struct task_struct *target, struct utrace *utrace)
2464b2
 	spin_lock_irq(&target->sighand->siglock);
2464b2
 	if (target->signal->flags & SIGNAL_STOP_STOPPED ||
2464b2
 	    target->signal->group_stop_count)
2464b2
-		target->state = TASK_STOPPED;
2464b2
+	        __stp_set_task_state(target, TASK_STOPPED);
2464b2
 	else
2464b2
 		stp_wake_up_state(target, __TASK_TRACED);
2464b2
 	spin_unlock_irq(&target->sighand->siglock);