Blame SOURCES/pid_link.patch

4f469b
4f469b
From: Masayoshi Mizuma <m mizuma jp fujitsu com>
4f469b
4f469b
On 4.19 and newer kernel, gcore command fails as following:
4f469b
 
4f469b
===========================================================
4f469b
    gcore: invalid structure size: pid_link
4f469b
           FILE: libgcore/gcore_coredump_table.c  LINE: 423  FUNCTION: pid_alive()
4f469b
4f469b
    [./crash] error trace: 7f4a7a6762b8 => 7f4a7a676e0f => 53b391 => 53b316
4f469b
4f469b
      53b316: SIZE_verify.part.31+70
4f469b
      53b391: SIZE_verify+49
4f469b
4f469b
    gcore: invalid structure size: pid_link
4f469b
           FILE: libgcore/gcore_coredump_table.c  LINE: 423  FUNCTION: pid_alive()
4f469b
4f469b
    Failed.
4f469b
===========================================================
4f469b
4f469b
That is because struct pid_link is removed and struct pid array is added to
4f469b
struct signal_struct by commit 2c4704756cab ("pids: Move the pgrp and session
4f469b
pid pointers from task_struct to signal_struct").
4f469b
4f469b
Get the pointer of struct pid from task_struct->thread_pid or
4f469b
signal_struct->pids[] to fix the failure.
4f469b
4f469b
Signed-off-by: Masayoshi Mizuma <m mizuma jp fujitsu com>
4f469b
---
4f469b
 gcore.c                         |  4 +++
4f469b
 libgcore/gcore_coredump_table.c | 48 +++++++++++++++++++++++++++------
4f469b
 libgcore/gcore_defs.h           |  2 ++
4f469b
 3 files changed, 46 insertions(+), 8 deletions(-)
4f469b
4f469b
4f469b
--- a/gcore.c
4f469b
+++ b/gcore.c
4f469b
@@ -505,6 +505,10 @@ static void gcore_offset_table_init(void
4f469b
 		GCORE_ANON_MEMBER_OFFSET_INIT(thread_struct_fpsimd_state, "thread_struct", "uw.fpsimd_state");
4f469b
 		GCORE_ANON_MEMBER_OFFSET_INIT(thread_struct_tp_value, "thread_struct", "uw.tp_value");
4f469b
 	}
4f469b
+	if (MEMBER_EXISTS("task_struct", "thread_pid"))
4f469b
+		GCORE_MEMBER_OFFSET_INIT(task_struct_thread_pid, "task_struct", "thread_pid");
4f469b
+	if (MEMBER_EXISTS("signal_struct", "pids"))
4f469b
+		GCORE_MEMBER_OFFSET_INIT(signal_struct_pids, "signal_struct", "pids");
4f469b
 }
4f469b
 
4f469b
 static void gcore_size_table_init(void)
4f469b
4f469b
diff --git a/libgcore/gcore_coredump_table.c b/libgcore/gcore_coredump_table.c
4f469b
index a073591..4cf9c38 100644
4f469b
--- a/libgcore/gcore_coredump_table.c
4f469b
+++ b/libgcore/gcore_coredump_table.c
4f469b
@@ -224,7 +224,7 @@ __task_pid_nr_ns(ulong task, enum pid_type type)
4f469b
 		sizeof(ns), "__task_pid_nr_ns: ns", gcore_verbose_error_handle());
4f469b
 
4f469b
 	if (pid_alive(task)) {
4f469b
-		ulong pids_type_pid;
4f469b
+		ulong pids_type_pid, signal;
4f469b
 
4f469b
                 if (type != PIDTYPE_PID)
4f469b
 			readmem(task + MEMBER_OFFSET("task_struct",
4f469b
@@ -233,10 +233,34 @@ __task_pid_nr_ns(ulong task, enum pid_type type)
4f469b
 				"__task_pid_nr_ns: group_leader",
4f469b
 				gcore_verbose_error_handle());
4f469b
 
4f469b
-		readmem(task + OFFSET(task_struct_pids) + type * SIZE(pid_link)
4f469b
-			+ OFFSET(pid_link_pid), KVADDR, &pids_type_pid,
4f469b
-			sizeof(pids_type_pid),
4f469b
-			"__task_pid_nr_ns: pids_type_pid", gcore_verbose_error_handle());
4f469b
+		if (VALID_MEMBER(task_struct_pids))
4f469b
+			readmem(task + OFFSET(task_struct_pids) +
4f469b
+				type * SIZE(pid_link) + OFFSET(pid_link_pid),
4f469b
+				KVADDR, &pids_type_pid,
4f469b
+				sizeof(pids_type_pid),
4f469b
+				"__task_pid_nr_ns: pids_type_pid",
4f469b
+				gcore_verbose_error_handle());
4f469b
+		else
4f469b
+			if (type == PIDTYPE_PID)
4f469b
+				readmem(task + GCORE_OFFSET(task_struct_thread_pid),
4f469b
+					KVADDR, &pids_type_pid,
4f469b
+					sizeof(pids_type_pid),
4f469b
+					"__task_pid_nr_ns: pids_type_pid",
4f469b
+					gcore_verbose_error_handle());
4f469b
+			else {
4f469b
+				readmem(task + OFFSET(task_struct_signal),
4f469b
+					KVADDR, &signal,
4f469b
+					sizeof(signal),
4f469b
+					"__task_pid_nr_ns: signal",
4f469b
+					gcore_verbose_error_handle());
4f469b
+
4f469b
+				readmem(signal + GCORE_OFFSET(signal_struct_pids) +
4f469b
+					type * sizeof(void *),
4f469b
+					KVADDR, &pids_type_pid,
4f469b
+					sizeof(pids_type_pid),
4f469b
+					"__task_pid_nr_ns: pids_type_pid",
4f469b
+					gcore_verbose_error_handle());
4f469b
+			}
4f469b
 
4f469b
 		nr = pid_nr_ns(pids_type_pid, ns);
4f469b
         }
4f469b
@@ -420,9 +444,17 @@ pid_alive(ulong task)
4f469b
 {
4f469b
 	pid_t pid;
4f469b
 
4f469b
-	readmem(task + OFFSET(task_struct_pids) + PIDTYPE_PID * SIZE(pid_link)
4f469b
-		+ OFFSET(pid_link_pid), KVADDR, &pid, sizeof(pid), "pid_alive",
4f469b
-		gcore_verbose_error_handle());
4f469b
+	if (VALID_MEMBER(task_struct_pids))
4f469b
+		readmem(task + OFFSET(task_struct_pids) +
4f469b
+			PIDTYPE_PID * SIZE(pid_link) + OFFSET(pid_link_pid),
4f469b
+			KVADDR, &pid, sizeof(pid),
4f469b
+			"pid_alive",
4f469b
+			gcore_verbose_error_handle());
4f469b
+	else
4f469b
+		readmem(task + GCORE_OFFSET(task_struct_thread_pid),
4f469b
+			KVADDR, &pid, sizeof(pid),
4f469b
+			"task_struct.thread_pid",
4f469b
+			gcore_verbose_error_handle());
4f469b
 
4f469b
         return !!pid;
4f469b
 }
4f469b
diff --git a/libgcore/gcore_defs.h b/libgcore/gcore_defs.h
4f469b
index 18c4c2c..3c839f9 100644
4f469b
--- a/libgcore/gcore_defs.h
4f469b
+++ b/libgcore/gcore_defs.h
4f469b
@@ -1077,6 +1077,7 @@ struct gcore_offset_table
4f469b
 	long sched_entity_sum_exec_runtime;
4f469b
 	long signal_struct_cutime;
4f469b
 	long signal_struct_pgrp;
4f469b
+	long signal_struct_pids;
4f469b
 	long signal_struct_session;
4f469b
 	long signal_struct_stime;
4f469b
 	long signal_struct_sum_sched_runtime;
4f469b
@@ -1090,6 +1091,7 @@ struct gcore_offset_table
4f469b
 	long task_struct_static_prio;
4f469b
 	long task_struct_uid;
4f469b
 	long task_struct_used_math;
4f469b
+	long task_struct_thread_pid;
4f469b
 	long thread_info_status;
4f469b
 	long thread_info_fpstate;
4f469b
 	long thread_info_vfpstate;
4f469b
-- 
4f469b
2.18.1
4f469b
4f469b
4f469b
--- a/gcore.mk
4f469b
+++ b/gcore.mk
4f469b
@@ -12,9 +12,9 @@
4f469b
 # GNU General Public License for more details.
4f469b
 #
4f469b
 
4f469b
-VERSION=1.5.0
4f469b
-DATE=30 Nov 2018
4f469b
-PERIOD=2010, 2011, 2012, 2013, 2014, 2016, 2017, 2018
4f469b
+VERSION=1.5.1
4f469b
+DATE=25 Jun 2019
4f469b
+PERIOD=2010, 2011, 2012, 2013, 2014, 2016, 2017, 2018, 2019
4f469b
 
4f469b
 ARCH=UNSUPPORTED
4f469b
 
4f469b