From patchwork Tue Jan 17 08:11:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13104279 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E904C63797 for ; Tue, 17 Jan 2023 08:13:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1CBF6B0071; Tue, 17 Jan 2023 03:13:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BCCAE6B0073; Tue, 17 Jan 2023 03:13:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A94236B0074; Tue, 17 Jan 2023 03:13:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 971C36B0071 for ; Tue, 17 Jan 2023 03:13:05 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 576DBA081A for ; Tue, 17 Jan 2023 08:13:05 +0000 (UTC) X-FDA: 80363575530.25.DAEFC51 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by imf19.hostedemail.com (Postfix) with ESMTP id 70FFB1A0009 for ; Tue, 17 Jan 2023 08:13:02 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673943183; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references; bh=ttIIGLd9wdcwpHD0l7GBwXhDKl/2g6nnSf0XRhOz8UA=; b=Lm3wyzfgDzBk2KdHlhU6kyTRZL81Fc2824OTFHUX4GZcjyzMs4g7KnSH2g0muJvYdCeF7K rVPrU4hML2DyhonmxTlVGMHWDKSeShqbI5RE6Mt3FIXyk1p2uAgF/PLGxOBWzrhP0fdMpH nnvOrguwDJsRPGF4gvtjl28qmVyu3Lk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673943183; a=rsa-sha256; cv=none; b=YILJzZjFND20fr2Jg8ZjIzVWoPRwpgLBEacQ4UtIcAwGoGpbjXze5jSdIHyBGPCpzFnK1e ukwXapSIDHgaaD6WSweaam3IQXlvQDjJ0KRFbNzwGo59EmiV+SqItnkuwF3emkGNohLUKA ZwMQjHBc8UkqC0nsG9AO4njR93VWrcQ= Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTP id 30H8C8xe076583; Tue, 17 Jan 2023 16:12:08 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from bj03382pcu.spreadtrum.com (10.0.74.65) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 17 Jan 2023 16:12:06 +0800 From: "zhaoyang.huang" To: Andrew Morton , Catalin Marinas , Vlastimil Babka , "Nathan Chancellor" , Peter Zijlstra , Zhaoyang Huang , , , , Mirsad Todorovac Subject: [PATCHv2] mm: use stack_depot_early_init for kmemleak Date: Tue, 17 Jan 2023 16:11:52 +0800 Message-ID: <1673943112-8620-1-git-send-email-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.0.74.65] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 30H8C8xe076583 X-Stat-Signature: uargiphadod1kfckob45wp8cgagbni5b X-Rspam-User: X-Rspamd-Queue-Id: 70FFB1A0009 X-Rspamd-Server: rspam06 X-HE-Tag: 1673943182-448792 X-HE-Meta: U2FsdGVkX19HWviiPtsmrgktveXxTBd8gvmhwYQ25fJKGkkSOgj1guSSg4g9BGAtyjzq8lLWZeMnwX1TC+oYBM4jMgofbGt/lwnPSSWiZ9nCxhy8U+AZbUCSEpjz0Wbuxcj+aXS5Qzz4FZGAANn04TJzq8z38rktdEk1clflhIp8AcMvo+tf/GUkrQ14rSUjyfTCQkun08Q/GwtP37ESnA/Qz69zrDFgD+frsM+LGaW0FLRuzX4mq0ZsuOKOCxMwVJe0w1zRxcm4U/fAGfmntuHxqRaftDxpXe3YULwZ7cSc/qTDYLykVJzCxZ0zk3bTj3WaRJxBrYqbuxmo0YUrukEHVf09F4mzUWm0EwZNf3ni2DSOn/6POMHzKfqifnxQnY5+iVv7tNlLgfEBI/yXv9JjBtJ5rgA/SwVRPfPQrdgaML160p+bnybNqz2ig+rLc+38mYdZi7PNogv9Wv0ksAuDesf4OQMztsUDO1UJPV9EvKGDfdyPZ67jMfO/GzuCJa97zNyCoelL/NR5cLYlQ4oasv9oMMyACSCKx8wwS8/cQR3Zh8qLkwgDF2AP8t3M1s6DBSJQzWjBEmPahP/MPqxaZF5pQ/tRl6ezsUE2QIHctz0UIXrRBu+b9LI/0/yHBUPTUAxrk4g8xbnAZMK7+uiiGM26wwk29pKK5lmoVQTSTO1TidZ/Psrivy8ftB103MiKIp03aDVxUn/ldcV9EEf6cuvbevMZVihmawuAFx8ryXJOpDZVRhMTiXBRDJSIRE+RrZhQ4RG8omHxsgYxLK3NSOwLuagiWEJZGOSJnknXeK5g0VQDtoJTwezVTeuQH4gU4Y84DlJ4RfBFJc/YruxVAWS0gdACLWC6GSeRk/b8q8L58K3jh7pgvPVGhJVv6YzuIRwkdwsKdex2/MUPmoXgeHRvB5afdHLlRaYdfopHeMZeA3I9UQi8CBaQUwi1GAS3Xl4wLQx7Xld1EpJ OSYY6lWI UwFyIZXwsZNB4sCY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Zhaoyang Huang Mirsad report bellow error which caused by stack_depot_init failed in kvcalloc. Solve this by having stackdepot use stack_depot_early_init. Extra Kconfig also done by moving kmemleak stuff to mm/Kconfig.debug. On 1/4/23 17:08, Mirsad Goran Todorovac wrote: I hate to bring bad news again, but there seems to be a problem with the output of /sys/kernel/debug/kmemleak: [root@pc-mtodorov ~]# cat /sys/kernel/debug/kmemleak unreferenced object 0xffff951c118568b0 (size 16): comm "kworker/u12:2", pid 56, jiffies 4294893952 (age 4356.548s) hex dump (first 16 bytes): 6d 65 6d 73 74 69 63 6b 30 00 00 00 00 00 00 00 memstick0....... backtrace: [root@pc-mtodorov ~]# Apparently, backtrace of called functions on the stack is no longer printed with the list of memory leaks. This appeared on Lenovo desktop 10TX000VCR, with AlmaLinux 8.7 and BIOS version M22KT49A (11/10/2022) and 6.2-rc1 and 6.2-rc2 builds. This worked on 6.1 with the same CONFIG_KMEMLEAK=y and MGLRU enabled on a vanilla mainstream kernel from Mr. Torvalds' tree. I don't know if this is deliberate feature for some reason or a bug. Please find attached the config, lshw and kmemleak output. reported-by: Mirsad Todorovac suggested-by: Vlastimil Babka Signed-off-by: Zhaoyang Huang --- v2: use stack_depot_want_early_init instead of CONFIG_STACKDEPOT_ALWAYS_INIT --- --- lib/Kconfig.debug | 70 ------------------------------------------------------- mm/Kconfig.debug | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ mm/kmemleak.c | 4 +++- 3 files changed, 73 insertions(+), 71 deletions(-) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 401ad4b..62884ac 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -716,76 +716,6 @@ config SHRINKER_DEBUG visibility into the kernel memory shrinkers subsystem. Disable it to avoid an extra memory footprint. -config HAVE_DEBUG_KMEMLEAK - bool - -config DEBUG_KMEMLEAK - bool "Kernel memory leak detector" - depends on DEBUG_KERNEL && HAVE_DEBUG_KMEMLEAK - select DEBUG_FS - select STACKTRACE if STACKTRACE_SUPPORT - select KALLSYMS - select CRC32 - select STACKDEPOT - help - Say Y here if you want to enable the memory leak - detector. The memory allocation/freeing is traced in a way - similar to the Boehm's conservative garbage collector, the - difference being that the orphan objects are not freed but - only shown in /sys/kernel/debug/kmemleak. Enabling this - feature will introduce an overhead to memory - allocations. See Documentation/dev-tools/kmemleak.rst for more - details. - - Enabling DEBUG_SLAB or SLUB_DEBUG may increase the chances - of finding leaks due to the slab objects poisoning. - - In order to access the kmemleak file, debugfs needs to be - mounted (usually at /sys/kernel/debug). - -config DEBUG_KMEMLEAK_MEM_POOL_SIZE - int "Kmemleak memory pool size" - depends on DEBUG_KMEMLEAK - range 200 1000000 - default 16000 - help - Kmemleak must track all the memory allocations to avoid - reporting false positives. Since memory may be allocated or - freed before kmemleak is fully initialised, use a static pool - of metadata objects to track such callbacks. After kmemleak is - fully initialised, this memory pool acts as an emergency one - if slab allocations fail. - -config DEBUG_KMEMLEAK_TEST - tristate "Simple test for the kernel memory leak detector" - depends on DEBUG_KMEMLEAK && m - help - This option enables a module that explicitly leaks memory. - - If unsure, say N. - -config DEBUG_KMEMLEAK_DEFAULT_OFF - bool "Default kmemleak to off" - depends on DEBUG_KMEMLEAK - help - Say Y here to disable kmemleak by default. It can then be enabled - on the command line via kmemleak=on. - -config DEBUG_KMEMLEAK_AUTO_SCAN - bool "Enable kmemleak auto scan thread on boot up" - default y - depends on DEBUG_KMEMLEAK - help - Depending on the cpu, kmemleak scan may be cpu intensive and can - stall user tasks at times. This option enables/disables automatic - kmemleak scan at boot up. - - Say N here to disable kmemleak auto scan thread to stop automatic - scanning. Disabling this option disables automatic reporting of - memory leaks. - - If unsure, say Y. - config DEBUG_STACK_USAGE bool "Stack utilization instrumentation" depends on DEBUG_KERNEL && !IA64 diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug index ce8dded..d1893ac 100644 --- a/mm/Kconfig.debug +++ b/mm/Kconfig.debug @@ -207,3 +207,73 @@ config PTDUMP_DEBUGFS kernel. If in doubt, say N. + +config HAVE_DEBUG_KMEMLEAK + bool + +config DEBUG_KMEMLEAK + bool "Kernel memory leak detector" + depends on DEBUG_KERNEL && HAVE_DEBUG_KMEMLEAK + select DEBUG_FS + select STACKTRACE if STACKTRACE_SUPPORT + select KALLSYMS + select CRC32 + select STACKDEPOT + help + Say Y here if you want to enable the memory leak + detector. The memory allocation/freeing is traced in a way + similar to the Boehm's conservative garbage collector, the + difference being that the orphan objects are not freed but + only shown in /sys/kernel/debug/kmemleak. Enabling this + feature will introduce an overhead to memory + allocations. See Documentation/dev-tools/kmemleak.rst for more + details. + + Enabling DEBUG_SLAB or SLUB_DEBUG may increase the chances + of finding leaks due to the slab objects poisoning. + + In order to access the kmemleak file, debugfs needs to be + mounted (usually at /sys/kernel/debug). + +config DEBUG_KMEMLEAK_MEM_POOL_SIZE + int "Kmemleak memory pool size" + depends on DEBUG_KMEMLEAK + range 200 1000000 + default 16000 + help + Kmemleak must track all the memory allocations to avoid + reporting false positives. Since memory may be allocated or + freed before kmemleak is fully initialised, use a static pool + of metadata objects to track such callbacks. After kmemleak is + fully initialised, this memory pool acts as an emergency one + if slab allocations fail. + +config DEBUG_KMEMLEAK_TEST + tristate "Simple test for the kernel memory leak detector" + depends on DEBUG_KMEMLEAK && m + help + This option enables a module that explicitly leaks memory. + + If unsure, say N. + +config DEBUG_KMEMLEAK_DEFAULT_OFF + bool "Default kmemleak to off" + depends on DEBUG_KMEMLEAK + help + Say Y here to disable kmemleak by default. It can then be enabled + on the command line via kmemleak=on. + +config DEBUG_KMEMLEAK_AUTO_SCAN + bool "Enable kmemleak auto scan thread on boot up" + default y + depends on DEBUG_KMEMLEAK + help + Depending on the cpu, kmemleak scan may be cpu intensive and can + stall user tasks at times. This option enables/disables automatic + kmemleak scan at boot up. + + Say N here to disable kmemleak auto scan thread to stop automatic + scanning. Disabling this option disables automatic reporting of + memory leaks. + + If unsure, say Y. diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 762b91f..ddc1ddf 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -2070,8 +2070,10 @@ static int __init kmemleak_boot_config(char *str) return -EINVAL; if (strcmp(str, "off") == 0) kmemleak_disable(); - else if (strcmp(str, "on") == 0) + else if (strcmp(str, "on") == 0) { kmemleak_skip_disable = 1; + stack_depot_want_early_init(); + } else return -EINVAL; return 0;