Blame SOURCES/0488-99base-apply-kernel-module-memory-debug-support.patch

ace748
From e186d99780d1247f24535e5dc4ec9c82444afaa3 Mon Sep 17 00:00:00 2001
ace748
From: Xunlei Pang <xlpang@redhat.com>
ace748
Date: Thu, 3 Nov 2016 19:40:16 +0800
ace748
Subject: [PATCH] 99base: apply kernel module memory debug support
ace748
ace748
Extend "rd.memdebug" to "4", and "make_trace_mem" to "4+:komem".
ace748
Add new "cleanup_trace_mem" to cleanup the trace if active.
ace748
ace748
Signed-off-by: Xunlei Pang <xlpang@redhat.com>
ace748
---
ace748
 modules.d/98systemd/dracut-cmdline.sh     |  2 +-
ace748
 modules.d/98systemd/dracut-pre-mount.sh   |  2 +-
ace748
 modules.d/98systemd/dracut-pre-pivot.sh   |  3 ++-
ace748
 modules.d/98systemd/dracut-pre-trigger.sh |  2 +-
ace748
 modules.d/99base/dracut-lib.sh            | 13 ++++++++++++-
ace748
 modules.d/99base/init.sh                  |  9 +++++----
ace748
 modules.d/99base/module-setup.sh          |  1 +
ace748
 7 files changed, 23 insertions(+), 9 deletions(-)
ace748
ace748
diff --git a/modules.d/98systemd/dracut-cmdline.sh b/modules.d/98systemd/dracut-cmdline.sh
1755ca
index 630f3f92..b6b899f0 100755
ace748
--- a/modules.d/98systemd/dracut-cmdline.sh
ace748
+++ b/modules.d/98systemd/dracut-cmdline.sh
ace748
@@ -43,7 +43,7 @@ export root
ace748
 export rflags
ace748
 export fstype
ace748
 
ace748
-make_trace_mem "hook cmdline" '1+:mem' '1+:iomem' '3+:slab'
ace748
+make_trace_mem "hook cmdline" '1+:mem' '1+:iomem' '3+:slab' '4+:komem'
ace748
 # run scriptlets to parse the command line
ace748
 getarg 'rd.break=cmdline' -d 'rdbreak=cmdline' && emergency_shell -n cmdline "Break before cmdline"
ace748
 source_hook cmdline
ace748
diff --git a/modules.d/98systemd/dracut-pre-mount.sh b/modules.d/98systemd/dracut-pre-mount.sh
1755ca
index 55b051ab..199cf965 100755
ace748
--- a/modules.d/98systemd/dracut-pre-mount.sh
ace748
+++ b/modules.d/98systemd/dracut-pre-mount.sh
ace748
@@ -9,7 +9,7 @@ type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
ace748
 
ace748
 source_conf /etc/conf.d
ace748
 
ace748
-make_trace_mem "hook pre-mount" '1:shortmem' '2+:mem' '3+:slab'
ace748
+make_trace_mem "hook pre-mount" '1:shortmem' '2+:mem' '3+:slab' '4+:komem'
ace748
 # pre pivot scripts are sourced just before we doing cleanup and switch over
ace748
 # to the new root.
ace748
 getarg 'rd.break=pre-mount' 'rdbreak=pre-mount' && emergency_shell -n pre-mount "Break pre-mount"
ace748
diff --git a/modules.d/98systemd/dracut-pre-pivot.sh b/modules.d/98systemd/dracut-pre-pivot.sh
1755ca
index 4c3eefcd..c079972e 100755
ace748
--- a/modules.d/98systemd/dracut-pre-pivot.sh
ace748
+++ b/modules.d/98systemd/dracut-pre-pivot.sh
ace748
@@ -10,12 +10,13 @@ type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
ace748
 
ace748
 source_conf /etc/conf.d
ace748
 
ace748
-make_trace_mem "hook pre-pivot" '1:shortmem' '2+:mem' '3+:slab'
ace748
+make_trace_mem "hook pre-pivot" '1:shortmem' '2+:mem' '3+:slab' '4+:komem'
ace748
 # pre pivot scripts are sourced just before we doing cleanup and switch over
ace748
 # to the new root.
ace748
 getarg 'rd.break=pre-pivot' 'rdbreak=pre-pivot' && emergency_shell -n pre-pivot "Break pre-pivot"
ace748
 source_hook pre-pivot
ace748
 
ace748
+cleanup_trace_mem
ace748
 # pre pivot cleanup scripts are sourced just before we switch over to the new root.
ace748
 getarg 'rd.break=cleanup' 'rdbreak=cleanup' && emergency_shell -n cleanup "Break cleanup"
ace748
 source_hook cleanup
ace748
diff --git a/modules.d/98systemd/dracut-pre-trigger.sh b/modules.d/98systemd/dracut-pre-trigger.sh
1755ca
index 0dbf32a5..241cd1e5 100755
ace748
--- a/modules.d/98systemd/dracut-pre-trigger.sh
ace748
+++ b/modules.d/98systemd/dracut-pre-trigger.sh
ace748
@@ -10,7 +10,7 @@ type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
ace748
 
ace748
 source_conf /etc/conf.d
ace748
 
ace748
-make_trace_mem "hook pre-trigger" "1:shortmem" "2+:mem" "3+:slab"
ace748
+make_trace_mem "hook pre-trigger" '1:shortmem' '2+:mem' '3+:slab' '4+:komem'
ace748
 
ace748
 source_hook pre-trigger
ace748
 
ace748
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
1755ca
index 10d9cbc5..78e01a78 100755
ace748
--- a/modules.d/99base/dracut-lib.sh
ace748
+++ b/modules.d/99base/dracut-lib.sh
ace748
@@ -1177,12 +1177,20 @@ are_lists_eq() {
ace748
 
ace748
 setmemdebug() {
ace748
     if [ -z "$DEBUG_MEM_LEVEL" ]; then
ace748
-        export DEBUG_MEM_LEVEL=$(getargnum 0 0 3 rd.memdebug)
ace748
+        export DEBUG_MEM_LEVEL=$(getargnum 0 0 4 rd.memdebug)
ace748
     fi
ace748
 }
ace748
 
ace748
 setmemdebug
ace748
 
ace748
+cleanup_trace_mem()
ace748
+{
ace748
+    # tracekomem based on kernel trace needs cleanup after use.
ace748
+    if [ "$DEBUG_MEM_LEVEL" -eq 4 ]; then
ace748
+        tracekomem --cleanup
ace748
+    fi
ace748
+}
ace748
+
ace748
 # parameters: msg [trace_level:trace]...
ace748
 make_trace_mem()
ace748
 {
ace748
@@ -1267,5 +1275,8 @@ show_memstats()
ace748
         iomem)
ace748
             cat /proc/iomem
ace748
             ;;
ace748
+        komem)
ace748
+            tracekomem
ace748
+            ;;
ace748
     esac
ace748
 }
ace748
diff --git a/modules.d/99base/init.sh b/modules.d/99base/init.sh
1755ca
index 7bbe6703..473bf42e 100755
ace748
--- a/modules.d/99base/init.sh
ace748
+++ b/modules.d/99base/init.sh
ace748
@@ -124,7 +124,7 @@ if getarg "rd.cmdline=ask"; then
ace748
 fi
ace748
 
ace748
 # run scriptlets to parse the command line
ace748
-make_trace_mem "hook cmdline" '1+:mem' '1+:iomem' '3+:slab'
ace748
+make_trace_mem "hook cmdline" '1+:mem' '1+:iomem' '3+:slab' '4+:komem'
ace748
 getarg 'rd.break=cmdline' -d 'rdbreak=cmdline' && emergency_shell -n cmdline "Break before cmdline"
ace748
 source_hook cmdline
ace748
 
ace748
@@ -153,7 +153,7 @@ getargbool 0 rd.udev.info -d -y rdudevinfo && udevadm control "$UDEV_LOG_PRIO_AR
ace748
 getargbool 0 rd.udev.debug -d -y rdudevdebug && udevadm control "$UDEV_LOG_PRIO_ARG=debug"
ace748
 udevproperty "hookdir=$hookdir"
ace748
 
ace748
-make_trace_mem "hook pre-trigger" '1:shortmem' '2+:mem' '3+:slab'
ace748
+make_trace_mem "hook pre-trigger" '1:shortmem' '2+:mem' '3+:slab' '4+:komem'
ace748
 getarg 'rd.break=pre-trigger' -d 'rdbreak=pre-trigger' && emergency_shell -n pre-trigger "Break before pre-trigger"
ace748
 source_hook pre-trigger
ace748
 
ace748
@@ -224,7 +224,7 @@ unset RDRETRY
ace748
 
ace748
 # pre-mount happens before we try to mount the root filesystem,
ace748
 # and happens once.
ace748
-make_trace_mem "hook pre-mount" '1:shortmem' '2+:mem' '3+:slab'
ace748
+make_trace_mem "hook pre-mount" '1:shortmem' '2+:mem' '3+:slab' '4+:komem'
ace748
 getarg 'rd.break=pre-mount' -d 'rdbreak=pre-mount' && emergency_shell -n pre-mount "Break pre-mount"
ace748
 source_hook pre-mount
ace748
 
ace748
@@ -260,11 +260,12 @@ done
ace748
 
ace748
 # pre pivot scripts are sourced just before we doing cleanup and switch over
ace748
 # to the new root.
ace748
-make_trace_mem "hook pre-pivot" '1:shortmem' '2+:mem' '3+:slab'
ace748
+make_trace_mem "hook pre-pivot" '1:shortmem' '2+:mem' '3+:slab' '4+:komem'
ace748
 getarg 'rd.break=pre-pivot' -d 'rdbreak=pre-pivot' && emergency_shell -n pre-pivot "Break pre-pivot"
ace748
 source_hook pre-pivot
ace748
 
ace748
 make_trace_mem "hook cleanup" '1:shortmem' '2+:mem' '3+:slab'
ace748
+cleanup_trace_mem
ace748
 # pre pivot cleanup scripts are sourced just before we switch over to the new root.
ace748
 getarg 'rd.break=cleanup' -d 'rdbreak=cleanup' && emergency_shell -n cleanup "Break cleanup"
ace748
 source_hook cleanup
ace748
diff --git a/modules.d/99base/module-setup.sh b/modules.d/99base/module-setup.sh
1755ca
index d5e78613..8fd4e80d 100755
ace748
--- a/modules.d/99base/module-setup.sh
ace748
+++ b/modules.d/99base/module-setup.sh
ace748
@@ -34,6 +34,7 @@ install() {
ace748
     inst_script "$moddir/initqueue.sh" "/sbin/initqueue"
ace748
     inst_script "$moddir/loginit.sh" "/sbin/loginit"
ace748
     inst_script "$moddir/rdsosreport.sh" "/sbin/rdsosreport"
ace748
+    inst_script "$moddir/memtrace-ko.sh" "/sbin/tracekomem"
ace748
 
ace748
     [ -e "${initdir}/lib" ] || mkdir -m 0755 -p ${initdir}/lib
ace748
     mkdir -m 0755 -p ${initdir}/lib/dracut