From patchwork Wed Sep 27 03:59:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13399835 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 C69B8E7F153 for ; Wed, 27 Sep 2023 03:06:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64ED16B01AB; Tue, 26 Sep 2023 23:06:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5FDDA6B01AE; Tue, 26 Sep 2023 23:06:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EE306B01B1; Tue, 26 Sep 2023 23:06:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3D7FE6B01AB for ; Tue, 26 Sep 2023 23:06:32 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0EB97120E45 for ; Wed, 27 Sep 2023 03:06:32 +0000 (UTC) X-FDA: 81280889424.28.7236738 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf17.hostedemail.com (Postfix) with ESMTP id 6F6A740002 for ; Wed, 27 Sep 2023 03:06:29 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695783990; a=rsa-sha256; cv=none; b=bofcL7B9J0SYfcLAucYm+i/+vMuF3gQ7IQEspNJatmbjXp51XCiGxKMcMmy6FZZs/U3623 GRhU57ApVJkSTqreTJ97P1+KsykXirY/vUgx9ZBdCbODVOchlbjrse+LSCXpMW0Q1/w4gj ou0qzVDCcQi7IUuOVOiSkKUq4j7b5DQ= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695783990; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n1N9i43KjaQcM7U65E1qxlfgcMuJTj9qK6/8Je6mn8k=; b=eMnz4Tt+nr4FsH9/EdSoR6uJqzguDupOPK5F2gO7u76y9UanUU6RzvXMi40cTTETj8CiWx JfaZiBdfHrxM/+o7N2bPGxIgDLruj1PfosVurRc7KXK/tHQt4cc3gNnLWw6aNqGYvq9ZjC KZ8JhdXWsqDBXqUAzDIdsVjc3jBLzEw= Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RwLx82PY8ztT3Y; Wed, 27 Sep 2023 11:01:48 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpemm500009.china.huawei.com (7.185.36.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 27 Sep 2023 11:06:09 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton CC: , , Liu Shixin Subject: [PATCH 1/3] bootmem: use kmemleak_free_part_phys in free_bootmem_page/put_page_bootmem Date: Wed, 27 Sep 2023 11:59:21 +0800 Message-ID: <20230927035923.1425340-2-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230927035923.1425340-1-liushixin2@huawei.com> References: <20230927035923.1425340-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6F6A740002 X-Stat-Signature: 7xsxazug6d65f4hkr9i99yxhu7k46jse X-HE-Tag: 1695783989-262826 X-HE-Meta: U2FsdGVkX1/FkQ1b2ZkWPOR8WcuBqPuJ4AjemdeSatZ8l5DsSszILNALQQGLHCm2SmA8hY0kSdPpoM1ECSlsiEf5td88eiT/4GrOO1Dzt4nR9OvvUEeLTS06y47ueUmxnw8hTqJvQzq/mLDWdQKqhJhcGbsZjLRT1HlypNJe5N2fGRuaUTO/ny5BZ3uqGroOOQ7jFKDe43JcIiEPmvmLs0X4Kqk84tef8yhRLtl5osaRa1NEi+5o+MyanmA8JiiaoOQTm9UZrsS6IhdNInYs5k1zKxCyNbXI7Cf/KwOXyf1IJkliRfa/LlXv7kHBA6ZUTDOFzdhdyupM8mQUm/qaGxMPtFfrWNYIojZAfX/tU3C7hcuaRF9k0cBsLwTZYXERmJAYp+eDzoAn8avRl26st9MYKFBAkPAOwXAPtiX8rEt+SQJXfmjdPHZXGOmDhPN1vKIOfX3MTyfNpwFh0/aGZDsxZAWOy4LxkLlG1ZZCWpEtVQ0WiByEGq2aROepbV/ZqAkrSqEx4ZCXU8lraVR4VFoOittsx/ahny0vBu3XcQVEtV0CzhdeH5rb1X+VzliFeMQSgvrb/Bckh3CK0OJq9Vn4KCi/06LyleGJtPZOrFbLy6lIx1Yln8i2uUWm2fDAhmjrYU115C4Ck3fuCOdWav90mjQaMtxiIAOZG1AnA1r55n6SZWWbEuEJnP2IIwWkt1uQc/zZc2HMthaKyVZXonW7j4vorK5uOCJKDYbu9Ia7YsckUG8TNGJbufSjGREjrpmSvyzJukgrCiyB59jN/TSD6sLoqd0ynu80h1ndbsnniiUwiW3mRL5kygGbW4Kg8RXs5OWWbFmWVXXA3t98zUe+Ndh0axw9sFZRmeWjdVetdme9R6rGsaSbfF53SkoXns6UlwmzGwzRqKoZ1p78XFOLdsftP3gfzJtj4lBLgheHukZQiN4CWFCmHhe8/aSE0tiavZa8FDyn7tS9EG1 6edajcde MN+6H40kDvj63Qb54lgNkraBYBLAdoleKzgc4YU4PATb01+kcMfjqE+9MCrL4bV/qb6wjVAfJ6p29qqVFWroQYLOucYt8ZGHaidC9tUExYcQptas/uwJonyavbPjjS6ZtmIwM67I2sQa9MFNGCN4RVork67hRLUmvuECspKCxiDcgHDAMknIiuVAbUA4/xqasaTfILPvlQEU3iyJwMEz0Yvg73/0GUIaKVDMri3NhOy09LlBPoWAjmDUvvVxQoZpZpSJ0FJ+nXIiVPlY= 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: Since kmemleak_alloc_phys() rather than kmemleak_alloc() was called from memblock_alloc_range_nid(), kmemleak_free_part_phys() should be used to delete kmemleak object in free_bootmem_page() and put_page_bootmem(). Fixes: 028725e73375 ("bootmem: remove the vmemmap pages from kmemleak in free_bootmem_page") Fixes: dd0ff4d12dd2 ("bootmem: remove the vmemmap pages from kmemleak in put_page_bootmem") Signed-off-by: Liu Shixin Acked-by: Catalin Marinas --- include/linux/bootmem_info.h | 2 +- mm/bootmem_info.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/bootmem_info.h b/include/linux/bootmem_info.h index e1a3c9c9754c..cffa38a73618 100644 --- a/include/linux/bootmem_info.h +++ b/include/linux/bootmem_info.h @@ -60,7 +60,7 @@ static inline void get_page_bootmem(unsigned long info, struct page *page, static inline void free_bootmem_page(struct page *page) { - kmemleak_free_part(page_to_virt(page), PAGE_SIZE); + kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE); free_reserved_page(page); } #endif diff --git a/mm/bootmem_info.c b/mm/bootmem_info.c index b1efebfcf94b..fa7cb0c87c03 100644 --- a/mm/bootmem_info.c +++ b/mm/bootmem_info.c @@ -34,7 +34,7 @@ void put_page_bootmem(struct page *page) ClearPagePrivate(page); set_page_private(page, 0); INIT_LIST_HEAD(&page->lru); - kmemleak_free_part(page_to_virt(page), PAGE_SIZE); + kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE); free_reserved_page(page); } } From patchwork Wed Sep 27 03:59:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13399834 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 A2EDAE7F153 for ; Wed, 27 Sep 2023 03:06:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 256396B01A1; Tue, 26 Sep 2023 23:06:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 207066B01A8; Tue, 26 Sep 2023 23:06:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CE676B01AA; Tue, 26 Sep 2023 23:06:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id F1C446B01A1 for ; Tue, 26 Sep 2023 23:06:18 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B9F0C1A0EB3 for ; Wed, 27 Sep 2023 03:06:18 +0000 (UTC) X-FDA: 81280888836.09.2EB9AF7 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf15.hostedemail.com (Postfix) with ESMTP id 14ECAA002C for ; Wed, 27 Sep 2023 03:06:14 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695783975; a=rsa-sha256; cv=none; b=agde6dM+f8hGUuwhs1hGdpLb+q/k82pBmi4j6DEMRL8vmrHEGVD+uwsovUyEuCh7BA0xXY Z0734eVWr2dsqZtmqksXA5XJKG0Nkmu7Cm6ntwRLGyQr/cjrg+yq14KnnXJOrmfOPfe3IU tT8CZYNpEkmoVyD0lSpcTL7sb6MWskE= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695783975; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FSq983pFeq00Rb3HA9pv8BxReSVB2oRe+x7EN0FejE0=; b=l7FSOA3aIimVngWQlkmMgRwaz8wmGA93GXSUdDEUrubaTb+ZvF2uQOgfmxH4namfe09UVW wy27Cezr4dgQQBN6is5N6cjhotVijASu9LziUEH1BjO11qAbFFuFo12oPWAHdDfX+BCkpG jQggcEaueOaeJ10SLXl4XRVrHT64zEc= Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RwLzZ6TCkzrSnL; Wed, 27 Sep 2023 11:03:54 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpemm500009.china.huawei.com (7.185.36.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 27 Sep 2023 11:06:10 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton CC: , , Liu Shixin Subject: [PATCH 2/3] mm/kmemleak: fix partially freeing unknown object warning Date: Wed, 27 Sep 2023 11:59:22 +0800 Message-ID: <20230927035923.1425340-3-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230927035923.1425340-1-liushixin2@huawei.com> References: <20230927035923.1425340-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 14ECAA002C X-Stat-Signature: fh1nm8eoqx95fixftuc75ri4hpk9cwu4 X-Rspam-User: X-HE-Tag: 1695783974-627650 X-HE-Meta: U2FsdGVkX19jLVomaCGh+nZ6JPdG+OgtngrIDEEl5jBwsf4pblZ+a7b5cMvFOwPOkwGbmYehAX1QXdwNJr6O48QWpCe6I1gyxl6WhQPSo9vbXyleaWeQHtPGt/4QnhyJaL6UNnVX/TTmygNcauowzhGWxn/z6aai0xBXxIjlQdm+/n3C6AATEF5l3Qbfk5x/QkAte3aUcYNVE1NWngRGa69HmB1I5ajlmDDt16k22cATNAJ1EYAIFm4SOgUGpbmSQw+CTcMOOboOIhIWYSUoWEMc9yzg78CMJC0JyYcckxwegFmpK/3Vj0Vtxp8TJCQ2jGPjjkxkn4R/sVcbN29BIy1QzNawL398B30+1rWmB/HDE8VJUEX8d9Rb8WpA+bhHazIov4Gl/yvituhi78vSnrTjaqwg0QiTphj4tpH4YXtZenoNVzWYdAhGcnTVkE6Lq1qIcXMIMM4AO7p46RcwtTBWoEKsrz/EXTp1Omhp8o7e7ycQzYMyWchUDlOr7/IFYERiiwbjCNW+6gFD3fsN1FBjhC9dFQ1lqkoYemIVzK2gjfrJGgeM6CUj2Gbp5gpSljOgvs8X7BgYyZDUKWSEmiEVR5K9xVhmNBLIJvdL/d2UdedAC4/o9I9S1WDPrrVYvAvtGR2caG9svbxk+Awt/v0r0lTb85zvDhYd1G5D/SM8N/eDcQUig4yzQOV4j5RBvl/Za0SR/Dq5p4qzjkRcRpO2/kIEe1ehoOW9kDJAQ+HeKLXRBHpI6j5cSpX0FlYQJVMo8jItFAEIW3GbLudugae8iGzEdy84v7sJZButS1igKWkV6V7VBoEDqStX23yyk7nm9yCzOnskmPJKD4R1phyZ2tUnlPfqbj4p4w5Fn/axOk4RgFhwX6YnauWY2hIhlVclM1pfsrvQ7DONndUSovubJPYkdqEr5a1uFufhsAwOsWNpdDhpr+SnR3cTQrAhQI4pffIAPtlqF7YcaSv lDOgi5Y0 QXi3Eo7UW/NfM2w8wYIhf6tSqcMESiE3Wb7Zi7weRHeUObzx75CtfzB8bgDaN2tH5glNd2scpeLNNDmFe1ZBeC2366t6KmPHe4tw5/TcmeZ8mvQtFJA1GwaU+Ur4ENJdupkyrxSlQloW1ZfvVx+DRw+nr0iarEUss3g4yA/bv945zXvj4+cjBjBVCW1zhgA5/rUeKFD7+NWhn2rFw1nNcUI2EZA== 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: delete_object_part() can be called by multiple callers in the same time. If an object is found and removed by a caller, and then another caller try to find it too, it failed and return directly. The secound part still be recorded by kmemleak even if it has alreadly been freed to buddy. With DEBUG on, kmemleak will report the following warning: kmemleak: Partially freeing unknown object at 0xa1af86000 (size 4096) CPU: 0 PID: 742 Comm: test_huge Not tainted 6.6.0-rc3kmemleak+ #54 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 Call Trace: dump_stack_lvl+0x37/0x50 kmemleak_free_part_phys+0x50/0x60 hugetlb_vmemmap_optimize+0x172/0x290 ? __pfx_vmemmap_remap_pte+0x10/0x10 __prep_new_hugetlb_folio+0xe/0x30 prep_new_hugetlb_folio.isra.0+0xe/0x40 alloc_fresh_hugetlb_folio+0xc3/0xd0 alloc_surplus_hugetlb_folio.constprop.0+0x6e/0xd0 hugetlb_acct_memory.part.0+0xe6/0x2a0 hugetlb_reserve_pages+0x110/0x2c0 hugetlbfs_file_mmap+0x11d/0x1b0 mmap_region+0x248/0x9a0 ? hugetlb_get_unmapped_area+0x15c/0x2d0 do_mmap+0x38b/0x580 vm_mmap_pgoff+0xe6/0x190 ksys_mmap_pgoff+0x18a/0x1f0 do_syscall_64+0x3f/0x90 entry_SYSCALL_64_after_hwframe+0x6e/0xd8 Fixes: 53238a60dd4a ("kmemleak: Allow partial freeing of memory blocks") Signed-off-by: Liu Shixin --- mm/kmemleak.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 54c2c90d3abc..5a2bbd85df57 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -208,6 +208,8 @@ static struct rb_root object_tree_root = RB_ROOT; static struct rb_root object_phys_tree_root = RB_ROOT; /* protecting the access to object_list, object_tree_root (or object_phys_tree_root) */ static DEFINE_RAW_SPINLOCK(kmemleak_lock); +/* Serial delete_object_part() to ensure all objects is deleted correctly */ +static DEFINE_RAW_SPINLOCK(delete_object_part_mutex); /* allocation caches for kmemleak internal data */ static struct kmem_cache *object_cache; @@ -784,13 +786,16 @@ static void delete_object_part(unsigned long ptr, size_t size, bool is_phys) { struct kmemleak_object *object; unsigned long start, end; + unsigned long flags; + raw_spin_lock_irqsave(&delete_object_part_mutex, flags); object = find_and_remove_object(ptr, 1, is_phys); if (!object) { #ifdef DEBUG kmemleak_warn("Partially freeing unknown object at 0x%08lx (size %zu)\n", ptr, size); #endif + raw_spin_unlock_irqrestore(&delete_object_part_mutex, flags); return; } @@ -809,6 +814,7 @@ static void delete_object_part(unsigned long ptr, size_t size, bool is_phys) GFP_KERNEL, is_phys); __delete_object(object); + raw_spin_unlock_irqrestore(&delete_object_part_mutex, flags); } static void __paint_it(struct kmemleak_object *object, int color) From patchwork Wed Sep 27 03:59:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13399837 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 5E630E7F157 for ; Wed, 27 Sep 2023 03:26:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EEB5A6B01AB; Tue, 26 Sep 2023 23:26:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E73A26B01AE; Tue, 26 Sep 2023 23:26:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D39F76B01B1; Tue, 26 Sep 2023 23:26:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C0D906B01AB for ; Tue, 26 Sep 2023 23:26:54 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 901681CABE2 for ; Wed, 27 Sep 2023 03:26:54 +0000 (UTC) X-FDA: 81280940748.24.1729266 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf01.hostedemail.com (Postfix) with ESMTP id 92B2F4000B for ; Wed, 27 Sep 2023 03:26:51 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695785212; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=trUyF+Ex0Dl5lpIZRJiDCRU7Gmwh7YkpGZCM5SkcZkk=; b=WhQaEJWvxuy7cFS22kUwStjZWYVLMGKJsDpbPFM79PUTKviyFcc4SXrmJ8G8rIPlf2T6/n arO+zbAjBjrgGolymx2lAs+e2gew0Yn31mAaPOAikeSHvQdpK181Z8zp2s/YrPYXrEuxMk O/CdkS8iF4MWbN8F8gcnbu4ztbKKvGA= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695785212; a=rsa-sha256; cv=none; b=AGK5gnJ8pe0Cvzru3P+PLlO3uRpFbB9kngnNF7cGMpJTYZMd2FoYCoq25QxMr69fkyQewS YHQMxsJ3I4t9ZdG1PPL2NXs2CZbb41O84i9O90O+9gKOi85Y3FifsBrbcZugOU+LEY2RHn njZMjj/oYh8IAvoLaGHIp0tnl6pBAy8= Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RwLxn1LJJzNnw3; Wed, 27 Sep 2023 11:02:21 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpemm500009.china.huawei.com (7.185.36.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 27 Sep 2023 11:06:10 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton CC: , , Liu Shixin Subject: [PATCH 3/3] mm/kmemleak: fix print format of pointer in pr_debug() Date: Wed, 27 Sep 2023 11:59:23 +0800 Message-ID: <20230927035923.1425340-4-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230927035923.1425340-1-liushixin2@huawei.com> References: <20230927035923.1425340-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 92B2F4000B X-Rspam-User: X-Stat-Signature: rm75txfh9mppryidkkfnx56onru6h9s8 X-Rspamd-Server: rspam01 X-HE-Tag: 1695785211-419914 X-HE-Meta: U2FsdGVkX19e1xMlOxXxOSjUgAxyrpkDVc/4xh48RGZZlfQVZpCHQMhcJRA9Vmff9CASgQeZAE2YBv6JrYrqJdkN3em1PlQjHL1mG/uHSacgjMqBm7LJYixKFNMeXYek5y35umSWKrHXNOX9p6/w1hy6k0Wen8M/tL7NbeKahWxzer4zhVwmSbX0EGWMKTOg1AosKKlyJ6o9KJMY5jS2xsvoCoFwd6+aA+tmu9MncykY5H1HbhCEhbmiwsmWBrRVPP1Dam0Rp4YKroSc935PXfIcu7xtg6Yt5gNbxxvT/smHaDYHTKbn/d2kdIVKhdYSc5CSXuZBzzbzbTxFxKzJrmXlxV/thBF/IrR8CIpVUyoPL4/f8/FeLhHKhC3+UmcMeW3OjOO8yypsK3TEhvzb3BhuHMQsPDfWjBlzl0zS0b+4bn12g8jSPZviMN8PboPs4heAwYU3L8fZnCX5KRoA9wAWljjNchPQLffJZeVxCMN+5RTqHv10IIR1ulmGOboTGbQRcRjBkiNyBe72r7Ijq57cf/qehfKrbOohhEDDnrt6jbidtPOteKP2m4ifg/g9mwwaWNmTBZwi/WHQw4vRlWD9l/1y1GWzP/keXNBt34zbbEZcgOS+gQjIIC2a/+2hXXmnQlUZ1UNi6pRRFfCA4938Fe76cHjByF06Xq6PfuakYKQpfNX8eH8eMMTf09aJAQIvQBrg8VKu6D1sQKGoowx9LiAT4esmVXJEadMSVqP5iD7icu8euUHo9e2z+PTNhPTJQp9dLGuJ0uA/WKnylQ+n7bOrOUj6gJYinxl4bdFNVYSxA+yDUvVaSGsyKzEQCE1Y08H6wOIBlih7g1WDdCCafO+64UUDfOaiZPvOTPCi8wjJN/wbvQHObwDsctf7vbeKvNlo4hqBBpqk+BOfEEB/LAyElNHTsX6ZDwnoDMMJhSNcoioO7jYM+xbUz8/BHVC2Xz54oUIrVSNXjoL 1ZJz0G2x KfjJpndv1JV/2A51D0bCHocbczvoAffRSJ4HGT3xXN+Q/PmhiKvwLTdlPFDTU15EGwC7V87MQWTu71ixPwK0UHWrXU92kc5Ys6pI69KZZvdkwEvbfY6pDHHIqcv+6S2T5NCc5qT8J2S+4zf6CFMUyqFuHrO02WcwaFWMWKd/LJ8S76FMPJytbz9dpLINUdS6FWUsPy9JyJNdfHcVJ1RvwoLxnBvXLPLqTuwH81ouopVBcMh0vZ11ZapPc7UnPyFlRTVUOHRb/BuxW2Zg= 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: With 0x%p, the pointer will be hashed and print (____ptrval____) instead. And with 0x%pa, the pointer can be successfully printed but with duplicate prefixes, which looks like: kmemleak: kmemleak_free(0x(____ptrval____)) kmemleak: kmemleak_free_part_phys(0x0x0000000a1af86000) Use %pa instead of 0x%p or 0x%pa to print the pointer, and use 0x%px for __percpu pointer to prevent crash. Then the print will be like: kmemleak: kmemleak_free(0xffff9111c145b020) kmemleak: kmemleak_free_percpu(0x00000000000333b0) kmemleak: kmemleak_free_part_phys(0x0000000a1af80000) Signed-off-by: Liu Shixin --- mm/kmemleak.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 5a2bbd85df57..c1053db98f55 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -981,7 +981,7 @@ static void object_no_scan(unsigned long ptr) void __ref kmemleak_alloc(const void *ptr, size_t size, int min_count, gfp_t gfp) { - pr_debug("%s(0x%p, %zu, %d)\n", __func__, ptr, size, min_count); + pr_debug("%s(%pa, %zu, %d)\n", __func__, ptr, size, min_count); if (kmemleak_enabled && ptr && !IS_ERR(ptr)) create_object((unsigned long)ptr, size, min_count, gfp); @@ -1002,7 +1002,7 @@ void __ref kmemleak_alloc_percpu(const void __percpu *ptr, size_t size, { unsigned int cpu; - pr_debug("%s(0x%p, %zu)\n", __func__, ptr, size); + pr_debug("%s(0x%px, %zu)\n", __func__, ptr, size); /* * Percpu allocations are only scanned and not reported as leaks @@ -1026,7 +1026,7 @@ EXPORT_SYMBOL_GPL(kmemleak_alloc_percpu); */ void __ref kmemleak_vmalloc(const struct vm_struct *area, size_t size, gfp_t gfp) { - pr_debug("%s(0x%p, %zu)\n", __func__, area, size); + pr_debug("%s(%pa, %zu)\n", __func__, area, size); /* * A min_count = 2 is needed because vm_struct contains a reference to @@ -1049,7 +1049,7 @@ EXPORT_SYMBOL_GPL(kmemleak_vmalloc); */ void __ref kmemleak_free(const void *ptr) { - pr_debug("%s(0x%p)\n", __func__, ptr); + pr_debug("%s(%pa)\n", __func__, ptr); if (kmemleak_free_enabled && ptr && !IS_ERR(ptr)) delete_object_full((unsigned long)ptr); @@ -1067,7 +1067,7 @@ EXPORT_SYMBOL_GPL(kmemleak_free); */ void __ref kmemleak_free_part(const void *ptr, size_t size) { - pr_debug("%s(0x%p)\n", __func__, ptr); + pr_debug("%s(%pa)\n", __func__, ptr); if (kmemleak_enabled && ptr && !IS_ERR(ptr)) delete_object_part((unsigned long)ptr, size, false); @@ -1085,7 +1085,7 @@ void __ref kmemleak_free_percpu(const void __percpu *ptr) { unsigned int cpu; - pr_debug("%s(0x%p)\n", __func__, ptr); + pr_debug("%s(0x%px)\n", __func__, ptr); if (kmemleak_free_enabled && ptr && !IS_ERR(ptr)) for_each_possible_cpu(cpu) @@ -1106,7 +1106,7 @@ void __ref kmemleak_update_trace(const void *ptr) struct kmemleak_object *object; unsigned long flags; - pr_debug("%s(0x%p)\n", __func__, ptr); + pr_debug("%s(%pa)\n", __func__, ptr); if (!kmemleak_enabled || IS_ERR_OR_NULL(ptr)) return; @@ -1137,7 +1137,7 @@ EXPORT_SYMBOL(kmemleak_update_trace); */ void __ref kmemleak_not_leak(const void *ptr) { - pr_debug("%s(0x%p)\n", __func__, ptr); + pr_debug("%s(%pa)\n", __func__, ptr); if (kmemleak_enabled && ptr && !IS_ERR(ptr)) make_gray_object((unsigned long)ptr); @@ -1155,7 +1155,7 @@ EXPORT_SYMBOL(kmemleak_not_leak); */ void __ref kmemleak_ignore(const void *ptr) { - pr_debug("%s(0x%p)\n", __func__, ptr); + pr_debug("%s(%pa)\n", __func__, ptr) ; if (kmemleak_enabled && ptr && !IS_ERR(ptr)) make_black_object((unsigned long)ptr, false); @@ -1175,7 +1175,7 @@ EXPORT_SYMBOL(kmemleak_ignore); */ void __ref kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) { - pr_debug("%s(0x%p)\n", __func__, ptr); + pr_debug("%s(%pa)\n", __func__, ptr); if (kmemleak_enabled && ptr && size && !IS_ERR(ptr)) add_scan_area((unsigned long)ptr, size, gfp); @@ -1193,7 +1193,7 @@ EXPORT_SYMBOL(kmemleak_scan_area); */ void __ref kmemleak_no_scan(const void *ptr) { - pr_debug("%s(0x%p)\n", __func__, ptr); + pr_debug("%s(%pa)\n", __func__, ptr); if (kmemleak_enabled && ptr && !IS_ERR(ptr)) object_no_scan((unsigned long)ptr); @@ -1209,7 +1209,7 @@ 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); + pr_debug("%s(%pa, %zu)\n", __func__, &phys, size); if (kmemleak_enabled) /* @@ -1229,7 +1229,7 @@ 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); + pr_debug("%s(%pa)\n", __func__, &phys); if (kmemleak_enabled) delete_object_part((unsigned long)phys, size, true); @@ -1243,7 +1243,7 @@ EXPORT_SYMBOL(kmemleak_free_part_phys); */ void __ref kmemleak_ignore_phys(phys_addr_t phys) { - pr_debug("%s(0x%pa)\n", __func__, &phys); + pr_debug("%s(%pa)\n", __func__, &phys); if (kmemleak_enabled) make_black_object((unsigned long)phys, true);