Blame SOURCES/rhbz2022849.patch

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