File fix-sched-change-task_struct-state-v5.14.patch of Package lttng-modules

From: Michael Jeanson <mjeanson@efficios.com>
Date: Mon Jul 12 14:51:20 2021 -0400
Subject: fix: sched: Change task_struct::state (v5.14)
Git-commit: 69a619a93c6a8082ac198debaf5ea44621290211
References: bsc#1190361
Signed-off-by: Tony Jones <tonyj@suse.de>

    fix: sched: Change task_struct::state (v5.14)
    
    See upstream commit:
    
      commit 2f064a59a11ff9bc22e52e9678bc601404c7cb34
      Author: Peter Zijlstra <peterz@infradead.org>
      Date:   Fri Jun 11 10:28:17 2021 +0200
    
        sched: Change task_struct::state
    
        Change the type and name of task_struct::state. Drop the volatile and
        shrink it to an 'unsigned int'. Rename it in order to find all uses
        such that we can use READ_ONCE/WRITE_ONCE as appropriate.
    
    Change-Id: I3a379192d6b977753fe58d4f67833a78dd7a0a47
    Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
    Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

diff --git a/lttng-statedump-impl.c b/lttng-statedump-impl.c
index 3d9d1276..22d9cc61 100644
--- a/lttng-statedump-impl.c
+++ b/lttng-statedump-impl.c
@@ -26,7 +26,6 @@
 #include <linux/cpu.h>
 #include <linux/netdevice.h>
 #include <linux/inetdevice.h>
-#include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/swap.h>
 #include <linux/wait.h>
@@ -43,6 +42,7 @@
 #include <wrapper/genhd.h>
 #include <wrapper/file.h>
 #include <wrapper/fdtable.h>
+#include <wrapper/sched.h>
 
 #ifdef CONFIG_LTTNG_HAS_LIST_IRQ
 #include <linux/irq.h>
@@ -651,7 +651,7 @@ int lttng_enumerate_process_states(struct lttng_session *session)
 				status = LTTNG_ZOMBIE;
 			else if (p->exit_state == EXIT_DEAD)
 				status = LTTNG_DEAD;
-			else if (p->state == TASK_RUNNING) {
+			else if (lttng_task_is_running(p)) {
 				/* Is this a forked child that has not run yet? */
 				if (list_empty(&p->rt.run_list))
 					status = LTTNG_WAIT_FORK;
@@ -662,7 +662,7 @@ int lttng_enumerate_process_states(struct lttng_session *session)
 					 * was really running at this time.
 					 */
 					status = LTTNG_WAIT_CPU;
-			} else if (p->state &
+			} else if (lttng_get_task_state(p) &
 				(TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)) {
 				/* Task is waiting for something to complete */
 				status = LTTNG_WAIT;
diff --git a/wrapper/sched.h b/wrapper/sched.h
new file mode 100644
index 00000000..b4772a38
--- /dev/null
+++ b/wrapper/sched.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
+ *
+ * src/wrapper/kprobes.h
+ *
+ * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#ifndef _LTTNG_WRAPPER_SCHED_H
+#define _LTTNG_WRAPPER_SCHED_H
+
+#include <linux/sched.h>
+#include <lttng-kernel-version.h>
+
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,14,0))
+
+#define lttng_get_task_state(task)	READ_ONCE((task)->__state)
+#define lttng_task_is_running(task)	task_is_running(task)
+
+#else /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,14,0) */
+
+#define lttng_get_task_state(task)	((task)->state)
+#define lttng_task_is_running(task)	(lttng_get_task_state(task) == TASK_RUNNING)
+
+#endif /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,14,0) */
+
+#endif /* _LTTNG_WRAPPER_SCHED_H */
openSUSE Build Service is sponsored by