From nobody Mon Apr 27 16:11:56 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F14BC433EF for ; Sat, 11 Jun 2022 03:58:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350209AbiFKD56 (ORCPT ); Fri, 10 Jun 2022 23:57:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347341AbiFKD5u (ORCPT ); Fri, 10 Jun 2022 23:57:50 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ACB5B1DA for ; Fri, 10 Jun 2022 20:57:49 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id o17so803501pla.6 for ; Fri, 10 Jun 2022 20:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o8/TqUYnqNg8t/CvW6LMFVObKWE28UfvOsyQO7sI0J4=; b=p0tg6a/DgSUkvvHvfQo80tdneeHe9jNuP4jrsIHdzIxYIp++31whZIQa4/6FV4nsui LqZVM73UOCXFXTZteprQJFsihWDM8uG2wbVdm8hYuxs8d7VxtKWVozOnFqAV46vaety3 3Vza9j1yhc1pnsMXaZ60aJGDI7eEKZmsKA70/e33o+uk0BtEwT/aMnIlDGS5eaq/cUZG Fb2RwHFMZw0pRe+nGqP6mvOJt7cugOIddlaeiiS756I8oj+t9W31T4F0ISGmRLkNQg/g 4mw5F9plzlAROpfnhrlwkcgIoGGqoAdqbpDXvJjvfQ9dMwkzOqIBcvejv0XZmdShjMDZ hv0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o8/TqUYnqNg8t/CvW6LMFVObKWE28UfvOsyQO7sI0J4=; b=QkSn+jc1OowWpf0Hb8osNqVxe3v0YoWdN+H5JaWpnMj/UO1gZNjl5dkQtfZ9LNwY8Y dqT147R8YX4PUSw7lLoT5fnERo9F8n7SHSxLcuOKdfNhsfKJBRRoY11Qg2teR7B9Gjz4 k4dbWLqzqA3Io8eKv8a7PDKgRBVYg4t3JKVch3WTQqmm8RoL+L/MF9Gw10KY/xqBxb8/ R/aZ0mds0Sx9CHTSyLwAN8d7gPt8wnluC2Im+lp6NkLHrSzluSed3FXmpZCOqExATyKI E4LRQs2jT5N8Uov9SWSjfrU+IUThKYC3NuKzJ6eeuk2YFHwxD6AIryYIwH7sGKUbq6Vy Y9cA== X-Gm-Message-State: AOAM531Ih/LajDjlWAmZGbQZyK1leSY7GMuPrM4U0+hmNM70uwZ/CGz7 W6NYY4UF1yCNeICVL5JJHZY= X-Google-Smtp-Source: ABdhPJynE51UJe048V/xez49gTko/wcGxVofrqoECSyy2R6y0qqcQiW6nvrNhizLnUez7lPRSlQSsQ== X-Received: by 2002:a17:902:d652:b0:168:bffe:e5fe with SMTP id y18-20020a170902d65200b00168bffee5femr5081930plh.81.1654919868565; Fri, 10 Jun 2022 20:57:48 -0700 (PDT) Received: from localhost ([101.86.206.203]) by smtp.gmail.com with ESMTPSA id jg19-20020a17090326d300b00167729dfe0bsm491809plb.168.2022.06.10.20.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 20:57:47 -0700 (PDT) From: Patrick Wang To: catalin.marinas@arm.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, yee.lee@mediatek.com, patrick.wang.shcn@gmail.com Subject: [PATCH v4 1/4] mm: kmemleak: remove kmemleak_not_leak_phys() and the min_count argument to kmemleak_alloc_phys() Date: Sat, 11 Jun 2022 11:55:48 +0800 Message-Id: <20220611035551.1823303-2-patrick.wang.shcn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220611035551.1823303-1-patrick.wang.shcn@gmail.com> References: <20220611035551.1823303-1-patrick.wang.shcn@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove the unused kmemleak_not_leak_phys() function. And remove the min_count argument to kmemleak_alloc_phys() function, assume it's 0. Suggested-by: Catalin Marinas Signed-off-by: Patrick Wang Reviewed-by: Catalin Marinas Tested-by: Geert Uytterhoeven --- Documentation/dev-tools/kmemleak.rst | 1 - drivers/of/fdt.c | 2 +- include/linux/kmemleak.h | 8 ++------ mm/kmemleak.c | 20 +++----------------- mm/memblock.c | 14 +++++++------- tools/testing/memblock/linux/kmemleak.h | 2 +- 6 files changed, 14 insertions(+), 33 deletions(-) diff --git a/Documentation/dev-tools/kmemleak.rst b/Documentation/dev-tools= /kmemleak.rst index 1c935f41cd3a..5483fd39ef29 100644 --- a/Documentation/dev-tools/kmemleak.rst +++ b/Documentation/dev-tools/kmemleak.rst @@ -174,7 +174,6 @@ mapping: =20 - ``kmemleak_alloc_phys`` - ``kmemleak_free_part_phys`` -- ``kmemleak_not_leak_phys`` - ``kmemleak_ignore_phys`` =20 Dealing with false positives/negatives diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index a8f5b6532165..2c677e84c3f5 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -529,7 +529,7 @@ static int __init __reserved_mem_reserve_reg(unsigned l= ong node, pr_debug("Reserved memory: reserved region for node '%s': base %pa, siz= e %lu MiB\n", uname, &base, (unsigned long)(size / SZ_1M)); if (!nomap) - kmemleak_alloc_phys(base, size, 0, 0); + kmemleak_alloc_phys(base, size, 0); } else pr_info("Reserved memory: failed to reserve memory for node '%s': base = %pa, size %lu MiB\n", diff --git a/include/linux/kmemleak.h b/include/linux/kmemleak.h index 34684b2026ab..6a3cd1bf4680 100644 --- a/include/linux/kmemleak.h +++ b/include/linux/kmemleak.h @@ -29,10 +29,9 @@ extern void kmemleak_not_leak(const void *ptr) __ref; extern void kmemleak_ignore(const void *ptr) __ref; extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __= ref; extern void kmemleak_no_scan(const void *ptr) __ref; -extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size, int min_cou= nt, +extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size, gfp_t gfp) __ref; extern void kmemleak_free_part_phys(phys_addr_t phys, size_t size) __ref; -extern void kmemleak_not_leak_phys(phys_addr_t phys) __ref; extern void kmemleak_ignore_phys(phys_addr_t phys) __ref; =20 static inline void kmemleak_alloc_recursive(const void *ptr, size_t size, @@ -107,15 +106,12 @@ static inline void kmemleak_no_scan(const void *ptr) { } static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size, - int min_count, gfp_t gfp) + gfp_t gfp) { } static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size) { } -static inline void kmemleak_not_leak_phys(phys_addr_t phys) -{ -} static inline void kmemleak_ignore_phys(phys_addr_t phys) { } diff --git a/mm/kmemleak.c b/mm/kmemleak.c index a182f5ddaf68..156eafafa182 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1125,15 +1125,13 @@ EXPORT_SYMBOL(kmemleak_no_scan); * address argument * @phys: physical address of the object * @size: size of the object - * @min_count: minimum number of references to this object. - * See kmemleak_alloc() * @gfp: kmalloc() flags used for kmemleak internal memory allocations */ -void __ref kmemleak_alloc_phys(phys_addr_t phys, size_t size, int min_coun= t, - gfp_t gfp) +void __ref kmemleak_alloc_phys(phys_addr_t phys, size_t size, gfp_t gfp) { if (PHYS_PFN(phys) >=3D min_low_pfn && PHYS_PFN(phys) < max_low_pfn) - kmemleak_alloc(__va(phys), size, min_count, gfp); + /* assume min_count 0 */ + kmemleak_alloc(__va(phys), size, 0, gfp); } EXPORT_SYMBOL(kmemleak_alloc_phys); =20 @@ -1151,18 +1149,6 @@ void __ref kmemleak_free_part_phys(phys_addr_t phys,= size_t size) } EXPORT_SYMBOL(kmemleak_free_part_phys); =20 -/** - * kmemleak_not_leak_phys - similar to kmemleak_not_leak but taking a phys= ical - * address argument - * @phys: physical address of the object - */ -void __ref kmemleak_not_leak_phys(phys_addr_t phys) -{ - if (PHYS_PFN(phys) >=3D min_low_pfn && PHYS_PFN(phys) < max_low_pfn) - kmemleak_not_leak(__va(phys)); -} -EXPORT_SYMBOL(kmemleak_not_leak_phys); - /** * kmemleak_ignore_phys - similar to kmemleak_ignore but taking a physical * address argument diff --git a/mm/memblock.c b/mm/memblock.c index e4f03a6e8e56..749abd2685c4 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1345,8 +1345,8 @@ __next_mem_pfn_range_in_zone(u64 *idx, struct zone *z= one, * from the regions with mirroring enabled and then retried from any * memory region. * - * In addition, function sets the min_count to 0 using kmemleak_alloc_phys= for - * allocated boot memory block, so that it is never reported as leaks. + * In addition, function using kmemleak_alloc_phys for allocated boot + * memory block, it is never reported as leaks. * * Return: * Physical address of allocated memory block on success, %0 on failure. @@ -1398,12 +1398,12 @@ phys_addr_t __init memblock_alloc_range_nid(phys_ad= dr_t size, */ if (end !=3D MEMBLOCK_ALLOC_NOLEAKTRACE) /* - * The min_count is set to 0 so that memblock allocated - * blocks are never reported as leaks. This is because many - * of these blocks are only referred via the physical - * address which is not looked up by kmemleak. + * Memblock allocated blocks are never reported as + * leaks. This is because many of these blocks are + * only referred via the physical address which is + * not looked up by kmemleak. */ - kmemleak_alloc_phys(found, size, 0, 0); + kmemleak_alloc_phys(found, size, 0); =20 return found; } diff --git a/tools/testing/memblock/linux/kmemleak.h b/tools/testing/memblo= ck/linux/kmemleak.h index 462f8c5e8aa0..5fed13bb9ec4 100644 --- a/tools/testing/memblock/linux/kmemleak.h +++ b/tools/testing/memblock/linux/kmemleak.h @@ -7,7 +7,7 @@ static inline void kmemleak_free_part_phys(phys_addr_t phys= , size_t size) } =20 static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size, - int min_count, gfp_t gfp) + gfp_t gfp) { } =20 --=20 2.25.1 From nobody Mon Apr 27 16:11:56 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5D12C43334 for ; Sat, 11 Jun 2022 03:58:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349367AbiFKD6C (ORCPT ); Fri, 10 Jun 2022 23:58:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349040AbiFKD5x (ORCPT ); Fri, 10 Jun 2022 23:57:53 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0C84B1DA for ; Fri, 10 Jun 2022 20:57:52 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id y196so1082044pfb.6 for ; Fri, 10 Jun 2022 20:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aAKZps72PMMzoHcO+HkFjM55OhZNaxgE/SU4USJkil8=; b=PnUoFhqnRmYUsadvL00HsRESRoOzWZo2LXZ+DmTIxZVF3xYrhCvipnNBPkxycY0//h 0nBmRrT/VATjJDXBTrMntOD8PMRrWaHPhPoVl49LhmXhFyv7O8eAorMM9wiE3rDL1m98 i+Denny9OqXJcSM19Gkal2Yk/UfoLH9o4ZUrA5Rfh/JoCpdEWyL15yUOxPDhJ3vDEGpo IaHPwUVLqmCU249QeD/qGZ61iEiV/Iah/4kl3me5hyMyXSZjfSuiUOEJX3J5EYSaevge d+OLtj813UGsRvXKQcOEAPZ4ZCb2lJLCkUW81Ixxvx1VsRx1xcj2bZXI0D0m5f9VDvG8 oKIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aAKZps72PMMzoHcO+HkFjM55OhZNaxgE/SU4USJkil8=; b=fCVsLYoNga8XtixvstpOnho2g6PHztPqfhfOZLxnIkFZhgwvGLl+C0RLFPBsTR2buF 7+Y2FY1ouopfTS6CjStmWbbz2PW4ujIqjnH8Ood3UMKasJJlawL6teFWusoohyuBNiAT cqdO/ZlESN4kuzJIlaerKm/v4Vafz7U+LgE7w8PjNC3GsyljyTIpo88f7zwtH06/vYS/ h9/CK1x5urPYTXyV5boYSuzSJHDtCdyNJw7PK6EK78GE4FLeqytsjpqd1icnOl2lCXcw hWYs20wqrjGNHWfXzMsF8iD3YJvlJe0LtvYMIerQgYeLxCsWHw51zqsIGnf9rBs1e4GS dJxw== X-Gm-Message-State: AOAM533vmxBbXY4BKLyR0Zs+W7L2Aol5bsrDvS7isHZje7g+QmI1+gFG oHn3hpwpGqZ861tBFSawCGzuihl/JhwBGQ== X-Google-Smtp-Source: ABdhPJy4p+QtcgzeQNeAiLnmtk2zrkY6GToee55wx7X2yzN+844cprFJBj11wSVsyS1OaWyapN7+PA== X-Received: by 2002:a05:6a00:168a:b0:4f7:e161:83cd with SMTP id k10-20020a056a00168a00b004f7e16183cdmr49433188pfc.56.1654919872496; Fri, 10 Jun 2022 20:57:52 -0700 (PDT) Received: from localhost ([101.86.206.203]) by smtp.gmail.com with ESMTPSA id 2-20020a620602000000b0051844f3f637sm383080pfg.40.2022.06.10.20.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 20:57:51 -0700 (PDT) From: Patrick Wang To: catalin.marinas@arm.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, yee.lee@mediatek.com, patrick.wang.shcn@gmail.com Subject: [PATCH v4 2/4] mm: kmemleak: add OBJECT_PHYS flag for objects allocated with physical address Date: Sat, 11 Jun 2022 11:55:49 +0800 Message-Id: <20220611035551.1823303-3-patrick.wang.shcn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220611035551.1823303-1-patrick.wang.shcn@gmail.com> References: <20220611035551.1823303-1-patrick.wang.shcn@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add OBJECT_PHYS flag for object. This flag is used to identify the objects allocated with physical address. The create_object_phys() function is added as well to set that flag and is used by kmemleak_alloc_phys(). Suggested-by: Catalin Marinas Signed-off-by: Patrick Wang Reviewed-by: Catalin Marinas Tested-by: Geert Uytterhoeven --- mm/kmemleak.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 156eafafa182..d82d8db0e8df 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -172,6 +172,8 @@ struct kmemleak_object { #define OBJECT_NO_SCAN (1 << 2) /* flag set to fully scan the object when scan_area allocation failed */ #define OBJECT_FULL_SCAN (1 << 3) +/* flag set for object allocated with physical address */ +#define OBJECT_PHYS (1 << 4) =20 #define HEX_PREFIX " " /* number of bytes to print per line; must be 16 or 32 */ @@ -574,8 +576,9 @@ static int __save_stack_trace(unsigned long *trace) * Create the metadata (struct kmemleak_object) corresponding to an alloca= ted * memory block and add it to the object_list and object_tree_root. */ -static struct kmemleak_object *create_object(unsigned long ptr, size_t siz= e, - int min_count, gfp_t gfp) +static struct kmemleak_object *__create_object(unsigned long ptr, size_t s= ize, + int min_count, gfp_t gfp, + bool is_phys) { unsigned long flags; struct kmemleak_object *object, *parent; @@ -595,7 +598,7 @@ static struct kmemleak_object *create_object(unsigned l= ong ptr, size_t size, INIT_HLIST_HEAD(&object->area_list); raw_spin_lock_init(&object->lock); atomic_set(&object->use_count, 1); - object->flags =3D OBJECT_ALLOCATED; + object->flags =3D OBJECT_ALLOCATED | (is_phys ? OBJECT_PHYS : 0); object->pointer =3D ptr; object->size =3D kfence_ksize((void *)ptr) ?: size; object->excess_ref =3D 0; @@ -662,6 +665,20 @@ static struct kmemleak_object *create_object(unsigned = long ptr, size_t size, return object; } =20 +/* Create kmemleak object which allocated with virtual address. */ +static struct kmemleak_object *create_object(unsigned long ptr, size_t siz= e, + int min_count, gfp_t gfp) +{ + return __create_object(ptr, size, min_count, gfp, false); +} + +/* Create kmemleak object which allocated with physical address. */ +static struct kmemleak_object *create_object_phys(unsigned long ptr, size_= t size, + int min_count, gfp_t gfp) +{ + return __create_object(ptr, size, min_count, gfp, true); +} + /* * Mark the object as not allocated and schedule RCU freeing via put_objec= t(). */ @@ -728,11 +745,11 @@ static void delete_object_part(unsigned long ptr, siz= e_t size) start =3D object->pointer; end =3D object->pointer + object->size; if (ptr > start) - create_object(start, ptr - start, object->min_count, - GFP_KERNEL); + __create_object(start, ptr - start, object->min_count, + GFP_KERNEL, object->flags & OBJECT_PHYS); if (ptr + size < end) - create_object(ptr + size, end - ptr - size, object->min_count, - GFP_KERNEL); + __create_object(ptr + size, end - ptr - size, object->min_count, + GFP_KERNEL, object->flags & OBJECT_PHYS); =20 __delete_object(object); } @@ -1129,9 +1146,14 @@ EXPORT_SYMBOL(kmemleak_no_scan); */ void __ref kmemleak_alloc_phys(phys_addr_t phys, size_t size, gfp_t gfp) { + pr_debug("%s(0x%pa, %zu)\n", __func__, &phys, size); + if (PHYS_PFN(phys) >=3D min_low_pfn && PHYS_PFN(phys) < max_low_pfn) - /* assume min_count 0 */ - kmemleak_alloc(__va(phys), size, 0, gfp); + /* + * Create object with OBJECT_PHYS flag and + * assume min_count 0. + */ + create_object_phys((unsigned long)__va(phys), size, 0, gfp); } EXPORT_SYMBOL(kmemleak_alloc_phys); =20 --=20 2.25.1 From nobody Mon Apr 27 16:11:56 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0D1CC43334 for ; Sat, 11 Jun 2022 03:58:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350146AbiFKD6N (ORCPT ); Fri, 10 Jun 2022 23:58:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350136AbiFKD55 (ORCPT ); Fri, 10 Jun 2022 23:57:57 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BBFA57150 for ; Fri, 10 Jun 2022 20:57:56 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id d129so864557pgc.9 for ; Fri, 10 Jun 2022 20:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8IgHE1RR2lgSzL/zu612niRONbvD1GIsUKzYCMHfLRk=; b=k8RDJdXnD6VhFoap8uvxpyCiGOeDFnyeRiHkkndgFuxfGJle0gV8LVxbZFM/WBpfPH v+lSzdvM9CKpJ+7soW1fG/Zy9klMZGTaHNHAHj3PBOpJ8ob7FCT2gUV+X7SmMXwvz0NB 1AVpbPSPBwITkKoACGfTlBEyE62Y0gj3GuWgl0BRcVS5bOh5vu5RZ9wD5aAS+1q0oay8 LGYLx9sqWRQuiqVeADV1Kz2zXYVKFe58cFBxEMUcYp5Mz+S2GHqwnnuJTBTvt6fLWI9x TibA+BTwVKvO5r7ee9BWtkFEcU3o4PI7HePcaMGRigGQSO4AracDekSD6HAZ4Hfs2p3U gNJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8IgHE1RR2lgSzL/zu612niRONbvD1GIsUKzYCMHfLRk=; b=InZ6N/+rGZ/V+L2noMVY98nSE7XPgrbRjP6X7VfiROBmYJjKT1++S+LofeJK2PpDZM PXWI+n4N6o9KDEh+Xxv1sekaoqN1OW+UgHpDsdIZ4T7XPuu8yprSeXQzo5Ga4vKg18K/ hIOPgCvdnh9MamfYFNIPu5Es7/4s8ze6kh1aquaWmCLe4sAHNgOcYrCPLWrlZkDM1GFe 2bIq/+igMw5s/j/V/MGFMenvwL59Pu4VgpX2uXzpVtfwTGwO2tlhDsl8uHtf8761zgs4 +OdUGMnDCfWP0sqom4a+dZdzwRDNGZ/YizUOQE9OnLZ2P5m3qkaL4dML2D2d3op58awx YjMg== X-Gm-Message-State: AOAM530VsPI89CPK4zc+28Vc+SM0TmPw7fLC8WUQRUhbzhEgwNh+z+Rc DioO9rt+2opmrPT9OepCm7e0kPAExTAK6w== X-Google-Smtp-Source: ABdhPJxhn4I5BgkSwVGDYsJDfN7HPlUaTn39NLNOK8sRZjpRPnCgeR15BF/a9JElXWec6/nFo7jOYw== X-Received: by 2002:a63:6cb:0:b0:403:af21:972e with SMTP id 194-20020a6306cb000000b00403af21972emr5311847pgg.90.1654919875484; Fri, 10 Jun 2022 20:57:55 -0700 (PDT) Received: from localhost ([101.86.206.203]) by smtp.gmail.com with ESMTPSA id p10-20020a63950a000000b003fbfe88be17sm490493pgd.24.2022.06.10.20.57.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 20:57:54 -0700 (PDT) From: Patrick Wang To: catalin.marinas@arm.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, yee.lee@mediatek.com, patrick.wang.shcn@gmail.com Subject: [PATCH v4 3/4] mm: kmemleak: add rbtree and store physical address for objects allocated with PA Date: Sat, 11 Jun 2022 11:55:50 +0800 Message-Id: <20220611035551.1823303-4-patrick.wang.shcn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220611035551.1823303-1-patrick.wang.shcn@gmail.com> References: <20220611035551.1823303-1-patrick.wang.shcn@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add object_phys_tree_root to store the objects allocated with physical address. Distinguish it from object_tree_root by OBJECT_PHYS flag or function argument. The physical address is stored directly in those objects. Suggested-by: Catalin Marinas Signed-off-by: Patrick Wang Reviewed-by: Catalin Marinas Tested-by: Geert Uytterhoeven --- mm/kmemleak.c | 133 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 91 insertions(+), 42 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index d82d8db0e8df..155f50e1a604 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -14,14 +14,16 @@ * The following locks and mutexes are used by kmemleak: * * - kmemleak_lock (raw_spinlock_t): protects the object_list modification= s and - * accesses to the object_tree_root. The object_list is the main list - * holding the metadata (struct kmemleak_object) for the allocated memory - * blocks. The object_tree_root is a red black tree used to look-up - * metadata based on a pointer to the corresponding memory block. The - * kmemleak_object structures are added to the object_list and - * object_tree_root in the create_object() function called from the - * kmemleak_alloc() callback and removed in delete_object() called from = the - * kmemleak_free() callback + * accesses to the object_tree_root (or object_phys_tree_root). The + * object_list is the main list holding the metadata (struct kmemleak_ob= ject) + * for the allocated memory blocks. The object_tree_root and object_phys= _tree_root + * are red black trees used to look-up metadata based on a pointer to the + * corresponding memory block. The object_phys_tree_root is for objects + * allocated with physical address. The kmemleak_object structures are + * added to the object_list and object_tree_root (or object_phys_tree_ro= ot) + * in the create_object() function called from the kmemleak_alloc() (or + * kmemleak_alloc_phys()) callback and removed in delete_object() called= from + * the kmemleak_free() callback * - kmemleak_object.lock (raw_spinlock_t): protects a kmemleak_object. * Accesses to the metadata (e.g. count) are protected by this lock. Note * that some members of this structure may be protected by other means @@ -195,7 +197,9 @@ static int mem_pool_free_count =3D ARRAY_SIZE(mem_pool); static LIST_HEAD(mem_pool_free_list); /* search tree for object boundaries */ static struct rb_root object_tree_root =3D RB_ROOT; -/* protecting the access to object_list and object_tree_root */ +/* search tree for object (with OBJECT_PHYS flag) boundaries */ +static struct rb_root object_phys_tree_root =3D RB_ROOT; +/* protecting the access to object_list, object_tree_root (or object_phys_= tree_root) */ static DEFINE_RAW_SPINLOCK(kmemleak_lock); =20 /* allocation caches for kmemleak internal data */ @@ -287,6 +291,9 @@ static void hex_dump_object(struct seq_file *seq, const u8 *ptr =3D (const u8 *)object->pointer; size_t len; =20 + if (WARN_ON_ONCE(object->flags & OBJECT_PHYS)) + return; + /* limit the number of lines to HEX_MAX_LINES */ len =3D min_t(size_t, object->size, HEX_MAX_LINES * HEX_ROW_SIZE); =20 @@ -380,9 +387,11 @@ static void dump_object_info(struct kmemleak_object *o= bject) * beginning of the memory block are allowed. The kmemleak_lock must be he= ld * when calling this function. */ -static struct kmemleak_object *lookup_object(unsigned long ptr, int alias) +static struct kmemleak_object *__lookup_object(unsigned long ptr, int alia= s, + bool is_phys) { - struct rb_node *rb =3D object_tree_root.rb_node; + struct rb_node *rb =3D is_phys ? object_phys_tree_root.rb_node : + object_tree_root.rb_node; unsigned long untagged_ptr =3D (unsigned long)kasan_reset_tag((void *)ptr= ); =20 while (rb) { @@ -408,6 +417,12 @@ static struct kmemleak_object *lookup_object(unsigned = long ptr, int alias) return NULL; } =20 +/* Look-up a kmemleak object which allocated with virtual address. */ +static struct kmemleak_object *lookup_object(unsigned long ptr, int alias) +{ + return __lookup_object(ptr, alias, false); +} + /* * Increment the object use_count. Return 1 if successful or 0 otherwise. = Note * that once an object's use_count reached 0, the RCU freeing was already @@ -517,14 +532,15 @@ static void put_object(struct kmemleak_object *object) /* * Look up an object in the object search tree and increase its use_count. */ -static struct kmemleak_object *find_and_get_object(unsigned long ptr, int = alias) +static struct kmemleak_object *__find_and_get_object(unsigned long ptr, in= t alias, + bool is_phys) { unsigned long flags; struct kmemleak_object *object; =20 rcu_read_lock(); raw_spin_lock_irqsave(&kmemleak_lock, flags); - object =3D lookup_object(ptr, alias); + object =3D __lookup_object(ptr, alias, is_phys); raw_spin_unlock_irqrestore(&kmemleak_lock, flags); =20 /* check whether the object is still available */ @@ -535,28 +551,39 @@ static struct kmemleak_object *find_and_get_object(un= signed long ptr, int alias) return object; } =20 +/* Look up and get an object which allocated with virtual address. */ +static struct kmemleak_object *find_and_get_object(unsigned long ptr, int = alias) +{ + return __find_and_get_object(ptr, alias, false); +} + /* - * Remove an object from the object_tree_root and object_list. Must be cal= led - * with the kmemleak_lock held _if_ kmemleak is still enabled. + * Remove an object from the object_tree_root (or object_phys_tree_root) + * and object_list. Must be called with the kmemleak_lock held _if_ kmemle= ak + * is still enabled. */ static void __remove_object(struct kmemleak_object *object) { - rb_erase(&object->rb_node, &object_tree_root); + rb_erase(&object->rb_node, object->flags & OBJECT_PHYS ? + &object_phys_tree_root : + &object_tree_root); list_del_rcu(&object->object_list); } =20 /* * Look up an object in the object search tree and remove it from both - * object_tree_root and object_list. The returned object's use_count shoul= d be - * at least 1, as initially set by create_object(). + * object_tree_root (or object_phys_tree_root) and object_list. The + * returned object's use_count should be at least 1, as initially set + * by create_object(). */ -static struct kmemleak_object *find_and_remove_object(unsigned long ptr, i= nt alias) +static struct kmemleak_object *find_and_remove_object(unsigned long ptr, i= nt alias, + bool is_phys) { unsigned long flags; struct kmemleak_object *object; =20 raw_spin_lock_irqsave(&kmemleak_lock, flags); - object =3D lookup_object(ptr, alias); + object =3D __lookup_object(ptr, alias, is_phys); if (object) __remove_object(object); raw_spin_unlock_irqrestore(&kmemleak_lock, flags); @@ -574,7 +601,8 @@ static int __save_stack_trace(unsigned long *trace) =20 /* * Create the metadata (struct kmemleak_object) corresponding to an alloca= ted - * memory block and add it to the object_list and object_tree_root. + * memory block and add it to the object_list and object_tree_root (or + * object_phys_tree_root). */ static struct kmemleak_object *__create_object(unsigned long ptr, size_t s= ize, int min_count, gfp_t gfp, @@ -631,9 +659,16 @@ static struct kmemleak_object *__create_object(unsigne= d long ptr, size_t size, raw_spin_lock_irqsave(&kmemleak_lock, flags); =20 untagged_ptr =3D (unsigned long)kasan_reset_tag((void *)ptr); - min_addr =3D min(min_addr, untagged_ptr); - max_addr =3D max(max_addr, untagged_ptr + size); - link =3D &object_tree_root.rb_node; + /* + * Only update min_addr and max_addr with object + * storing virtual address. + */ + if (!is_phys) { + min_addr =3D min(min_addr, untagged_ptr); + max_addr =3D max(max_addr, untagged_ptr + size); + } + link =3D is_phys ? &object_phys_tree_root.rb_node : + &object_tree_root.rb_node; rb_parent =3D NULL; while (*link) { rb_parent =3D *link; @@ -657,7 +692,8 @@ static struct kmemleak_object *__create_object(unsigned= long ptr, size_t size, } } rb_link_node(&object->rb_node, rb_parent, link); - rb_insert_color(&object->rb_node, &object_tree_root); + rb_insert_color(&object->rb_node, is_phys ? &object_phys_tree_root : + &object_tree_root); =20 list_add_tail_rcu(&object->object_list, &object_list); out: @@ -707,7 +743,7 @@ static void delete_object_full(unsigned long ptr) { struct kmemleak_object *object; =20 - object =3D find_and_remove_object(ptr, 0); + object =3D find_and_remove_object(ptr, 0, false); if (!object) { #ifdef DEBUG kmemleak_warn("Freeing unknown object at 0x%08lx\n", @@ -723,12 +759,12 @@ static void delete_object_full(unsigned long ptr) * delete it. If the memory block is partially freed, the function may cre= ate * additional metadata for the remaining parts of the block. */ -static void delete_object_part(unsigned long ptr, size_t size) +static void delete_object_part(unsigned long ptr, size_t size, bool is_phy= s) { struct kmemleak_object *object; unsigned long start, end; =20 - object =3D find_and_remove_object(ptr, 1); + object =3D find_and_remove_object(ptr, 1, is_phys); if (!object) { #ifdef DEBUG kmemleak_warn("Partially freeing unknown object at 0x%08lx (size %zu)\n", @@ -746,10 +782,10 @@ static void delete_object_part(unsigned long ptr, siz= e_t size) end =3D object->pointer + object->size; if (ptr > start) __create_object(start, ptr - start, object->min_count, - GFP_KERNEL, object->flags & OBJECT_PHYS); + GFP_KERNEL, is_phys); if (ptr + size < end) __create_object(ptr + size, end - ptr - size, object->min_count, - GFP_KERNEL, object->flags & OBJECT_PHYS); + GFP_KERNEL, is_phys); =20 __delete_object(object); } @@ -770,11 +806,11 @@ static void paint_it(struct kmemleak_object *object, = int color) raw_spin_unlock_irqrestore(&object->lock, flags); } =20 -static void paint_ptr(unsigned long ptr, int color) +static void paint_ptr(unsigned long ptr, int color, bool is_phys) { struct kmemleak_object *object; =20 - object =3D find_and_get_object(ptr, 0); + object =3D __find_and_get_object(ptr, 0, is_phys); if (!object) { kmemleak_warn("Trying to color unknown object at 0x%08lx as %s\n", ptr, @@ -792,16 +828,16 @@ static void paint_ptr(unsigned long ptr, int color) */ static void make_gray_object(unsigned long ptr) { - paint_ptr(ptr, KMEMLEAK_GREY); + paint_ptr(ptr, KMEMLEAK_GREY, false); } =20 /* * Mark the object as black-colored so that it is ignored from scans and * reporting. */ -static void make_black_object(unsigned long ptr) +static void make_black_object(unsigned long ptr, bool is_phys) { - paint_ptr(ptr, KMEMLEAK_BLACK); + paint_ptr(ptr, KMEMLEAK_BLACK, is_phys); } =20 /* @@ -1007,7 +1043,7 @@ void __ref kmemleak_free_part(const void *ptr, size_t= size) pr_debug("%s(0x%p)\n", __func__, ptr); =20 if (kmemleak_enabled && ptr && !IS_ERR(ptr)) - delete_object_part((unsigned long)ptr, size); + delete_object_part((unsigned long)ptr, size, false); } EXPORT_SYMBOL_GPL(kmemleak_free_part); =20 @@ -1095,7 +1131,7 @@ void __ref kmemleak_ignore(const void *ptr) pr_debug("%s(0x%p)\n", __func__, ptr); =20 if (kmemleak_enabled && ptr && !IS_ERR(ptr)) - make_black_object((unsigned long)ptr); + make_black_object((unsigned long)ptr, false); } EXPORT_SYMBOL(kmemleak_ignore); =20 @@ -1153,7 +1189,7 @@ void __ref kmemleak_alloc_phys(phys_addr_t phys, size= _t size, gfp_t gfp) * Create object with OBJECT_PHYS flag and * assume min_count 0. */ - create_object_phys((unsigned long)__va(phys), size, 0, gfp); + create_object_phys((unsigned long)phys, size, 0, gfp); } EXPORT_SYMBOL(kmemleak_alloc_phys); =20 @@ -1166,8 +1202,10 @@ EXPORT_SYMBOL(kmemleak_alloc_phys); */ void __ref kmemleak_free_part_phys(phys_addr_t phys, size_t size) { + pr_debug("%s(0x%pa)\n", __func__, &phys); + if (PHYS_PFN(phys) >=3D min_low_pfn && PHYS_PFN(phys) < max_low_pfn) - kmemleak_free_part(__va(phys), size); + delete_object_part((unsigned long)phys, size, true); } EXPORT_SYMBOL(kmemleak_free_part_phys); =20 @@ -1178,8 +1216,10 @@ EXPORT_SYMBOL(kmemleak_free_part_phys); */ void __ref kmemleak_ignore_phys(phys_addr_t phys) { + pr_debug("%s(0x%pa)\n", __func__, &phys); + if (PHYS_PFN(phys) >=3D min_low_pfn && PHYS_PFN(phys) < max_low_pfn) - kmemleak_ignore(__va(phys)); + make_black_object((unsigned long)phys, true); } EXPORT_SYMBOL(kmemleak_ignore_phys); =20 @@ -1190,6 +1230,9 @@ static bool update_checksum(struct kmemleak_object *o= bject) { u32 old_csum =3D object->checksum; =20 + if (WARN_ON_ONCE(object->flags & OBJECT_PHYS)) + return false; + kasan_disable_current(); kcsan_disable_current(); object->checksum =3D crc32(0, kasan_reset_tag((void *)object->pointer), o= bject->size); @@ -1343,6 +1386,7 @@ static void scan_object(struct kmemleak_object *objec= t) { struct kmemleak_scan_area *area; unsigned long flags; + void *obj_ptr; =20 /* * Once the object->lock is acquired, the corresponding memory block @@ -1354,10 +1398,15 @@ static void scan_object(struct kmemleak_object *obj= ect) if (!(object->flags & OBJECT_ALLOCATED)) /* already freed object */ goto out; + + obj_ptr =3D object->flags & OBJECT_PHYS ? + __va((phys_addr_t)object->pointer) : + (void *)object->pointer; + if (hlist_empty(&object->area_list) || object->flags & OBJECT_FULL_SCAN) { - void *start =3D (void *)object->pointer; - void *end =3D (void *)(object->pointer + object->size); + void *start =3D obj_ptr; + void *end =3D obj_ptr + object->size; void *next; =20 do { --=20 2.25.1 From nobody Mon Apr 27 16:11:56 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F7BAC43334 for ; Sat, 11 Jun 2022 03:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350192AbiFKD6Q (ORCPT ); Fri, 10 Jun 2022 23:58:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349130AbiFKD57 (ORCPT ); Fri, 10 Jun 2022 23:57:59 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D18FE11462 for ; Fri, 10 Jun 2022 20:57:58 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id gc3-20020a17090b310300b001e33092c737so1077335pjb.3 for ; Fri, 10 Jun 2022 20:57:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BRhMR0ZHYhacS3442LotLCWWOUVPdNCodU10GIEMY0w=; b=Bikr50hWOgc7DNBC6J8V9OgTaGPyggfd5K1DmchOjSSYF/aiVNAoiFOXQNCc9j7oDy rHADQT+de00Tlzb56K4YyRrR4ZP3IsrxnAjP3EnZkD+VQ6ZO2T7T58rSDuQENcujxMLQ eJJ8Fx26CkNaLqLT6vtCgg3tq3u+F7u7XgvGpZe4aTxN+cMM0QHv84F5RPXP1CSd1Mof pfBgR1Yr3F5++iQHpBbaDAmYPzAJf/la/A6bRNAGspLj47QgGKXu60ENvOaL5ut/w4Mr NN/Tw+eHpnfOqM7SicupIzJKw+kh21jNRoL2/ubHzEdO5wXUX9k+QHi4mAupYe6voUs7 PUxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BRhMR0ZHYhacS3442LotLCWWOUVPdNCodU10GIEMY0w=; b=aFMSh3ClMbCQLgEixGyqBRvCUgZgbkFQekCtuXZazusFgbf2VSiLI6xAZRxVLds1KU 4lfqto/xXyGfdpar5dZrEtizIVq2qar406b32f4rO4vD+FLaHeifXx1TPcOaYdCkwGqg xdCqtzlpw3I85rbmP7SHk4wYv9G3Zbfhf/H9urdR2JalEwIq4f2ovdELx+ulxU13O+JE ZDJAqbUYkR/0XkNEn7XDI6Q6kWPiAgRZa+tsYhMKEmbtF8aztQCjejtzNBRjeJdWzaPt 47gYzbxukMvYEzXJRwqGwDCLnBAPvgb0GtzYt2OcP4UqYmc2pApxiyOUY0iECloCGT+T 3sMw== X-Gm-Message-State: AOAM530bMkEi7yrMkajTOAQwP9JCyaxuuO1jl0iEx8Zik/oiEk8ds5na Pmn+ui21ktkX9MjZtos+WcM= X-Google-Smtp-Source: ABdhPJzGgybSUKDPG1nlM6xxS/2e+0mjaKFrXr6aIaPH6O/k0r821mFiWjuBLf3vkhd6gImVMWO5Zw== X-Received: by 2002:a17:902:ecca:b0:166:3e34:4d01 with SMTP id a10-20020a170902ecca00b001663e344d01mr46885922plh.97.1654919878399; Fri, 10 Jun 2022 20:57:58 -0700 (PDT) Received: from localhost ([101.86.206.203]) by smtp.gmail.com with ESMTPSA id ct21-20020a056a000f9500b0051c0784cb45sm381671pfb.99.2022.06.10.20.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 20:57:57 -0700 (PDT) From: Patrick Wang To: catalin.marinas@arm.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, yee.lee@mediatek.com, patrick.wang.shcn@gmail.com Subject: [PATCH v4 4/4] mm: kmemleak: check physical address when scan Date: Sat, 11 Jun 2022 11:55:51 +0800 Message-Id: <20220611035551.1823303-5-patrick.wang.shcn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220611035551.1823303-1-patrick.wang.shcn@gmail.com> References: <20220611035551.1823303-1-patrick.wang.shcn@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Check the physical address of objects for its boundary when scan instead of in kmemleak_*_phys(). Fixes: 23c2d497de21 ("mm: kmemleak: take a full lowmem check in kmemleak_*_= phys()") Suggested-by: Catalin Marinas Signed-off-by: Patrick Wang Reviewed-by: Catalin Marinas Tested-by: Geert Uytterhoeven --- mm/kmemleak.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 155f50e1a604..387d6fa402c6 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1184,7 +1184,7 @@ void __ref kmemleak_alloc_phys(phys_addr_t phys, size= _t size, gfp_t gfp) { pr_debug("%s(0x%pa, %zu)\n", __func__, &phys, size); =20 - if (PHYS_PFN(phys) >=3D min_low_pfn && PHYS_PFN(phys) < max_low_pfn) + if (kmemleak_enabled) /* * Create object with OBJECT_PHYS flag and * assume min_count 0. @@ -1204,7 +1204,7 @@ void __ref kmemleak_free_part_phys(phys_addr_t phys, = size_t size) { pr_debug("%s(0x%pa)\n", __func__, &phys); =20 - if (PHYS_PFN(phys) >=3D min_low_pfn && PHYS_PFN(phys) < max_low_pfn) + if (kmemleak_enabled) delete_object_part((unsigned long)phys, size, true); } EXPORT_SYMBOL(kmemleak_free_part_phys); @@ -1218,7 +1218,7 @@ void __ref kmemleak_ignore_phys(phys_addr_t phys) { pr_debug("%s(0x%pa)\n", __func__, &phys); =20 - if (PHYS_PFN(phys) >=3D min_low_pfn && PHYS_PFN(phys) < max_low_pfn) + if (kmemleak_enabled) make_black_object((unsigned long)phys, true); } EXPORT_SYMBOL(kmemleak_ignore_phys); @@ -1493,6 +1493,17 @@ static void kmemleak_scan(void) dump_object_info(object); } #endif + + /* ignore objects outside lowmem (paint them black) */ + if ((object->flags & OBJECT_PHYS) && + !(object->flags & OBJECT_NO_SCAN)) { + unsigned long phys =3D object->pointer; + + if (PHYS_PFN(phys) < min_low_pfn || + PHYS_PFN(phys + object->size) >=3D max_low_pfn) + __paint_it(object, KMEMLEAK_BLACK); + } + /* reset the reference count (whiten the object) */ object->count =3D 0; if (color_gray(object) && get_object(object)) --=20 2.25.1