Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

i) Create kmemleak.cfg file under meta-cmf-raspberrypi/recipes-kernel/linux/files with below kernel configs.

CONFIG_HAVE_DEBUG_KMEMLEAK=y
CONFIG_DEBUG_KMEMLEAK=y
CONFIG_DEBUG_KMEMLEAK_TEST=m


ii) Add kmemleak.cfg file  in meta-cmf-raspberrypi/recipes-kernel/linux/linux-raspberrypi_5.10.52.bb 

Please find below diff file.
Ex:

diff --git a/recipes-kernel/linux/linux-raspberrypi_5.10.52.bb b/recipes-kernel/linux/linux-raspberrypi_5.10.52.bb
index 2c7f19a..224a64a 100644
--- a/recipes-kernel/linux/linux-raspberrypi_5.10.52.bb
+++ b/recipes-kernel/linux/linux-raspberrypi_5.10.52.bb
@@ -11,6 +11,7 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

 SRC_URI += " file://powersave.cfg \
              file://android-drivers.cfg \
+             file://kmemleak.cfg \
 "

iii) Once build done with above changes, verify the  kernel configs are enabled in final kernel boot config file.
Path of kernel boot config file:  build-raspberrypi-rdk-mc/tmp/work/raspberrypi_rdk_mc-rdk-linux-gnueabi/linux-raspberrypi/1_5.10.52+gitAUTOINC+dbe03fa900_2697f74031-r0/image/boot/config-5.10.52-v7

Ex:

csures569@dvm-yocto3-docker-csures569:~/feature-securestorage-rpi-2Mar/build-raspberrypi-rdk-mc/tmp/work/raspberrypi_rdk_mc-rdk-linux-gnueabi/linux-raspberrypi/1_5.10.52+gitAUTOINC+dbe03fa900_2697f74031-r0/image/boot$ cat config-5.10.52-v7  | grep "KMEMLEAK"
CONFIG_HAVE_DEBUG_KMEMLEAK=y
CONFIG_DEBUG_KMEMLEAK=y
CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE=16000
CONFIG_DEBUG_KMEMLEAK_TEST=m
# CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set
CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y

iv) Once flash the image with above changes , verify the kmemleak enabled in the device, it will create a kmemleak folder under /sys/modules/ and kmemleak file under /sys/kernel/debug/
Ex:

root@raspberrypi-rdk-mc:/sys/module# ls -l | grep "kmemleak"
drwxr-xr-x    3 root     root             0 Mar  5 09:49 kmemleak

root@raspberrypi-rdk-mc:~# ls /sys/kernel/debug/kmemleak
/sys/kernel/debug/kmemleak


v) Once enabled kmemleak we will get kernel memory leaks in /sys/kernel/debug/kmemleak file if leaks are reported.

Testing kmemleak tool with kmemleak-test module in rpi3:

Note: kmemleak-test.ko by default in rpi3 this module not compiled , there is no kmemleak-test.ko module , so enable to build as a module and generated module file.
kmemleak-test.koImage Added

Step 1 : Copy kmemleak-test.ko module to this path /lib/modules/5.10.52-v7/  in box .
Step 2 : load the module to kernel space with insmod command.
Ex:

root@raspberrypi-rdk-mc:~# insmod /lib/modules/5.10.52-v7/kmemleak-test.ko
root@raspberrypi-rdk-mc:~#

Step3 : verify module loaded or not
Ex: lsmod

root@raspberrypi-rdk-mc:~# lsmod

Module                Size      Used by

kmemleak_test    16384        0 // Here module loaded.

ip6t_REJECT         16384       2

nf_reject_ipv6      16384        1 ip6t_REJECT

ip6table_nat        16384        1

br_netfilter           32768       0

xt_state                16384       0


Step4: Perform a scan
Ex: echo scan > /sys/kernel/debug/kmemleak

root@raspberrypi-rdk-mc:~# echo scan > /sys/kernel/debug/kmemleak
root@raspberrypi-rdk-mc:~#

Step5: Collect memory leak data

Ex: cat /sys/kernel/debug/kmemleak


View file
namekmemleak_report_for_kmeleak_test_module.txt
height250
View file
namekmemleak-test.ko
height250