From patchwork Thu Jan 19 01:22:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 45558 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp79906wrn; Wed, 18 Jan 2023 17:33:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXusK+VEwjlYeMt+H1klivxFtUnJiCMzQOZreR/N3Xy+Y+n77K0G4NELm/+mLFzZHF6+SVMc X-Received: by 2002:a17:902:e5d2:b0:192:7258:dfb1 with SMTP id u18-20020a170902e5d200b001927258dfb1mr9585391plf.59.1674092034173; Wed, 18 Jan 2023 17:33:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674092034; cv=none; d=google.com; s=arc-20160816; b=a65ydiQr3uWabDp7DEB3ep8VHh921fs7gC+/32j1LCOmC1z8n+5SeKDDTRlt84j+VJ fa/BRUZZ1nsjhaPrdOk9XWNvNqKt0Ur8PcST+FDcxNtMOk/JYiV5AwE+fpEihgRvcUBp 81nqMKOkMeKLuO1u8bK5s5G8dbPR+d+rnLYaLWEEhybqjGsi9fUPMOG366BJ7Zcu5Zcc fI/PpvVNg/6rgUq4kbFNbAnGoDyVMD9XRQW/sesDmlhHabaBrWRLWr6O0s1qQZcfc8rg LEuWT09z8PRPzs3Dmwrhd4+HZ/jdZCcC/Vpg9fqr5U+EpFIPFdtBVUHOkP0smsER0d7y Rmrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:to:from; bh=QEI2zSdw5lz0Ab0PAkdQu2TFJ9JhmDIuFmeRmcyFoBI=; b=Rg8OYBRfpO0isBzWWGSwM7L0UmE+/anTbI11eXZHKiaKuKOJ+48z6rUfPy8EypUrQk /Td4pOAfMS7w2nw21ZFcKd1Nd48zTmr/WMBIvve5MAwmkZ9s9gEmnZuUYUssg/XJqy2h F+e23+p3Z+ZtiDiAVptD0HmtEttpeWwC9iiloPSyM6QBi+zYtIxlAmqY5+cNfpQA4nJU ycnPs15rgyqRpgvM1sCuxtjv4eSORFa0m+zXdrV8GrjHbhA/C7CRXFBdjwEkXWzZQWww HvSkB8W+s/jQsu8c25IHzrPL9yvFaY1MUdRhXnaPTsiFm64MHOVoNzNqBqSLKYYyJJRI YUdg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t18-20020a170902b21200b00174eef66680si33792631plr.120.2023.01.18.17.33.39; Wed, 18 Jan 2023 17:33:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbjASB3F (ORCPT + 99 others); Wed, 18 Jan 2023 20:29:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230016AbjASB2Y (ORCPT ); Wed, 18 Jan 2023 20:28:24 -0500 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B611B68431 for ; Wed, 18 Jan 2023 17:22:56 -0800 (PST) Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTP id 30J1MpPB093127; Thu, 19 Jan 2023 09:22:51 +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; Thu, 19 Jan 2023 09:22:49 +0800 From: "zhaoyang.huang" To: Andrew Morton , Catalin Marinas , Vlastimil Babka , "Nathan Chancellor" , Peter Zijlstra , Zhaoyang Huang , , , , Mirsad Todorovac Subject: [PATCHv4 1/2] mm: move KMEMLEAK's Kconfig items from lib to mm Date: Thu, 19 Jan 2023 09:22:24 +0800 Message-ID: <1674091345-14799-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 30J1MpPB093127 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755412729098897239?= X-GMAIL-MSGID: =?utf-8?q?1755412729098897239?= From: Zhaoyang Huang Have the kmemleak's source code and Kconfig items be in the same directory. Signed-off-by: Zhaoyang Huang Acked-by: Mike Rapoport (IBM) Acked-by: Vlastimil Babka --- lib/Kconfig.debug | 70 ------------------------------------------------------- mm/Kconfig.debug | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 70 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. From patchwork Thu Jan 19 01:22:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 45559 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp79979wrn; Wed, 18 Jan 2023 17:34:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXvyFV7gke4pYquoNFInAyz3PrAaZqXZ9vLl0jujjLSWjSfEv2/cJdTEBFFfhwtBU1CpA4ce X-Received: by 2002:a17:903:2015:b0:194:8d2f:68f5 with SMTP id s21-20020a170903201500b001948d2f68f5mr8493838pla.17.1674092043379; Wed, 18 Jan 2023 17:34:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674092043; cv=none; d=google.com; s=arc-20160816; b=mIxQW1s0zaWjANmnuk+qK5MnhwR92sO1Dr6GQLcJQ4z2XGSfX3deRfO8Neb2qqqRd0 uYuZwtq/PXAFO/HsgrPG8ctjZMjp6hq8zKWtnG3g4eOf8eSnoaXm7nQxGba1CapjJ9bM MXzvrFclSiztrDtfnFXyoOYGpHaRDRSvCcGro5SbNB8pSRXNxxSgPQehPliVoceD7YGc fo/dqxaxsoiKX7/iQmVLNHeB4FabIQEA0u5rE8N4SUzhD2M36bs2+SVqrmsyxfTVGuiv mG5IJmFPfJP2Byz22T78wxsP/ecU8djyR4jhzJtQziy9ppM2V7dU7eer6SqEI/hrfrFm ZkAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:to:from; bh=jorMgqEQTOzxVCmiX8ybMmNHTugBay0HmFWGSRVJFk8=; b=Grt10yri9A+1CFGvRAHdfdzZqBsJowtK+V6GIXvzGy5IxObRGRGRYA8rTCTTgGdIAt wkHQwTyJX80fT/q19nuC6t0L5LlDTSYK649aaFd+WEyXn6QtX7PG/TfQrDTBHiITsXq+ oOibgPM9FX+40/3lRewjk/J9qiJXrM5GQB6e8TQbpafTaVbKB7nKk2wUaOtVZqF5Cuj8 4RjNpZygrdIVyLAw6LIJFvOKyThhIIjOXQmD3zHNwAxu+VVNZppsyJ7zQR6SYc7PqFkq CLu9NJWAaS7qoj2/BQozce1+E9dpDF26+GE5/WaapabTi71LF/gIrStPzG9UiWSFFImq x9Cw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a170902e88400b0018958008877si41494291plg.39.2023.01.18.17.33.51; Wed, 18 Jan 2023 17:34:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229689AbjASB32 (ORCPT + 99 others); Wed, 18 Jan 2023 20:29:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229976AbjASB21 (ORCPT ); Wed, 18 Jan 2023 20:28:27 -0500 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0664B6D35C for ; Wed, 18 Jan 2023 17:23:02 -0800 (PST) Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTP id 30J1Mu1A093179; Thu, 19 Jan 2023 09:22:56 +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; Thu, 19 Jan 2023 09:22:54 +0800 From: "zhaoyang.huang" To: Andrew Morton , Catalin Marinas , Vlastimil Babka , "Nathan Chancellor" , Peter Zijlstra , Zhaoyang Huang , , , , Mirsad Todorovac Subject: [PATCHv4 2/2] mm: use stack_depot_early_init for kmemleak Date: Thu, 19 Jan 2023 09:22:25 +0800 Message-ID: <1674091345-14799-2-git-send-email-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1674091345-14799-1-git-send-email-zhaoyang.huang@unisoc.com> References: <1674091345-14799-1-git-send-email-zhaoyang.huang@unisoc.com> 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 30J1Mu1A093179 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755412738678355116?= X-GMAIL-MSGID: =?utf-8?q?1755412738678355116?= 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. 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 Acked-by: Mike Rapoport (IBM) Acked-by: Catalin Marinas Acked-by: Vlastimil Babka --- v2: use stack_depot_want_early_init instead of CONFIG_STACKDEPOT_ALWAYS_INIT v3: have the Kconfig changes commited in another patch v4: select CONFIG_STACKDEPOT_ALWAYS_INIT when DEBUG_KMEMLEAK_DEFAULT_OFF is off --- Signed-off-by: Zhaoyang Huang --- mm/Kconfig.debug | 1 + mm/kmemleak.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug index d1893ac..466a37e 100644 --- a/mm/Kconfig.debug +++ b/mm/Kconfig.debug @@ -219,6 +219,7 @@ config DEBUG_KMEMLEAK select KALLSYMS select CRC32 select STACKDEPOT + select STACKDEPOT_ALWAYS_INIT if !DEBUG_KMEMLEAK_DEFAULT_OFF help Say Y here if you want to enable the memory leak detector. The memory allocation/freeing is traced in a way 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;