From patchwork Sun Oct 8 02:33:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13412515 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 2A37FE95A87 for ; Sun, 8 Oct 2023 01:33:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 911D68D0017; Sat, 7 Oct 2023 21:33:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E7AF8D0001; Sat, 7 Oct 2023 21:33:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D93C8D0017; Sat, 7 Oct 2023 21:33:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6DA2C8D0001 for ; Sat, 7 Oct 2023 21:33:27 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 409DD802FA for ; Sun, 8 Oct 2023 01:33:27 +0000 (UTC) X-FDA: 81320571654.18.3C7532B Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf06.hostedemail.com (Postfix) with ESMTP id 0BE7D180009 for ; Sun, 8 Oct 2023 01:33:23 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.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=1696728805; 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=D3ZK2F+1B7hk/Ob5LKYTaMLtCgj+8CCYSXooVfHp9ZI=; b=HN6B5wl/3qeWwayONoMqYAkTeCbpPf9yGGBmKaaUm69CrP0CB7k6NlWGBq9ikj9ExX2XCL RVo7K3wSCQfR5//ok4cAMDhIckigE9Xj+D3xEuxAmgIrAnCBtUI/KFscE/yxfkaODHsJTD YO1Tp/Ytb1hbwTmwjgt5G/OEpvl7/oU= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.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=1696728805; a=rsa-sha256; cv=none; b=6+VMg4VhhkDeZoK57b8GvWnCyzIdxg+ny5aC8ZmkCKF0vuSurux6LpXsBOwZMSA2W014sU 3bqVZlPh/whlRYr+8QpFscvy4NJyPBSj6kUTr3lMC90R1Q1pOqnren7rN92lduPfCmb9Xb 6R54DtlEJk7ruECTW3V+GN6VXa4d5gg= Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4S34Lh2dH9ztTD8; Sun, 8 Oct 2023 09:28:44 +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; Sun, 8 Oct 2023 09:33:17 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton CC: , , Liu Shixin Subject: [PATCH v2 1/4] bootmem: use kmemleak_free_part_phys in put_page_bootmem Date: Sun, 8 Oct 2023 10:33:14 +0800 Message-ID: <20231008023317.3015699-2-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231008023317.3015699-1-liushixin2@huawei.com> References: <20231008023317.3015699-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 0BE7D180009 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: qjibgeoewhf1wmuf3nxwtbyeydxquxk5 X-HE-Tag: 1696728803-872557 X-HE-Meta: U2FsdGVkX1+385esU36RwuepxZDSwUFzUCAJ5sLMQvKr70OjkFqTDc4lwPgUgvnc7yhI89ryqMrSdQUJpmogM/6KLHxXosTzib4cLK/LLWWph+WD30tURDePMUD97Ls0uBBVERg6ySt8mCK4lx/oVpqzK89Q4Pm8ZDeDjMl9EFTXm+6mYFgr3wD68tgjy/xf8e6YnpkueUHmpmSWiCTYzlOuSn8TWfa1YgxlVTWGXiIEXRyFKvai8l8ambWkXjWpXvUKIwPVkqLC7LXxzUmEors/ui3NUCedZ+IZAZl01YkO6Uuscdhoy6aK4jOdzsEWX4PrhMm9MEGZKY7EOLuf2JkqRnsbsZgkrQri+LCrQz8Vdwn+v8uQvbbrJdTMpsRta9AR/oatFL8GsY25ONG6KNDAJfmHN8O/0mIcFzK5gXEpAdhZbQOSncqrfyaw4sLAq3vUO649j13WuqLEuHlGZAx68TQSZfLPoSnQOIKBC9qpwmMelaXgPpY/Ab1RoUowzZZxuGzXlPfY7af1oKMrQ99MTw2t53SjqDsCzTQEIZJE81qpzQHN4NULXKvfcEmaqGJclbDCLRxymG7g8qlUC9D9YfWgoPwOTn7+z/InvvyT8SgJlGQ04f9StNeQjEk9LVlubSlntXskg0wO4WWD/EHlpTfKbErcO2Q1Kcz+59A13hz0++CtSlmBUW7NKpcmU6MKPQhnTWNL/JiFzRpG/dj+NBMXogvkQU6+qbg+BlQJgPK8pr5slACn6bGNSr31DvARY6to0IHQ0aJf3pRTcWLFYO5jrlMW4xw/45feSb0dWNPXVkMkCsJUT6oAlBeBUvoPcBFbqEAPsn89ZZmSOAmGWYQQ6Zcyh52zMo1f4uLQZzNF0APbwYd+o05y1dx6xq5CrhmqTkwHw4/Stj8dCHfRUv2ZRL7YVx80mxi6Pz5ClKlldVbhD+kXWo81gBJ2EVfdxPyBbIjrODfriL2 irtwmd02 3QHygOdRrsK5Oqul+8t7GNwT00L0NvahMQHHD5onAIJ4Y1u54oGhAIaCSdE2vwMCbKRDCIK/tq2Ljz5i2LrzCtdNiGQxDRfPEn+Ac7H5Fc9kPfHcPmGthiyK+2sItpm2UxExwJb8/YF9gW+hBrK3LbNNF3xRamJTZp2c7jhoAGXcjrWEgj2irRI19TLr+NmmKkohPgt9CJ1GCnI+NHXw/aTfC2LkKTL4Shs5vzWqWICGY8snY8B6an+8njRkoqH8Zk/emf6KbCcjYIykopxZlvbJCTHYn7N29e9Q6jHEkJF/Qp7agyhCBGn5PykqdlF2DwgNoDdWlrk9RwzoZriHNI8dmlh4GOwU8GzT+xK6OYpWK0gouhTou5eOTnQmXbFVCekPl/DwOAQgtIuibQn+UB7hNrnYKIS0nKTPI 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 put_page_bootmem(). In debug mode, there are following warning: kmemleak: Partially freeing unknown object at 0xffff97345aff7000 (size 4096) Fixes: dd0ff4d12dd2 ("bootmem: remove the vmemmap pages from kmemleak in put_page_bootmem") Signed-off-by: Liu Shixin Acked-by: Catalin Marinas --- mm/bootmem_info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 Sun Oct 8 02:33:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13412518 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 63DF5E95A86 for ; Sun, 8 Oct 2023 01:33:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 010AC8D001A; Sat, 7 Oct 2023 21:33:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F02FF8D0001; Sat, 7 Oct 2023 21:33:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFB028D001A; Sat, 7 Oct 2023 21:33:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CF7EA8D0001 for ; Sat, 7 Oct 2023 21:33:39 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9C8051A02E5 for ; Sun, 8 Oct 2023 01:33:39 +0000 (UTC) X-FDA: 81320572158.15.FE15B1E Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf24.hostedemail.com (Postfix) with ESMTP id 61333180011 for ; Sun, 8 Oct 2023 01:33:37 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.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=1696728817; 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=uxAR8iPpyzK1PAA01I33pQ2SqFi5A2TOT/zKa9EjxMQ=; b=NNHbTyOqo8hVNHmQXNj9P0YYSwRUlEaLPecCt3bQ9XPMDV32O/cGJF5907ic7oxUASwcDF LHrCndKtIzbLRtYrzo22yLxjkah6j6BhkjhZtPlqj2J4TO0ioI+lKrA5KGklT93p5ZCda5 FCmVWXxmR7efDmfptjA5gyk7HkAlq70= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696728818; a=rsa-sha256; cv=none; b=igc/UDp7oID8Qo+BvyzkC9OicF192c4zGKP3KwW8+XUqFzsPev0+jnCnqbVDYlfAuxdxPQ mN7xnCj8Ls5XkqExPl36Ejo50+5geBynkkRuSZVYll4iFi0wYNegnTtvlimHz570J/+Aj7 qsR0HaNelATg3lWNs1pY3/y6rcKGheU= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.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 Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4S34P42l2WzrTFk; Sun, 8 Oct 2023 09:30: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; Sun, 8 Oct 2023 09:33:17 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton CC: , , Liu Shixin Subject: [PATCH v2 2/4] bootmem: use kmemleak_free_part_phys in free_bootmem_page Date: Sun, 8 Oct 2023 10:33:15 +0800 Message-ID: <20231008023317.3015699-3-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231008023317.3015699-1-liushixin2@huawei.com> References: <20231008023317.3015699-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Stat-Signature: x54yox6b81ux7f4u78fuwqa854s5i567 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 61333180011 X-Rspam-User: X-HE-Tag: 1696728816-366248 X-HE-Meta: U2FsdGVkX1/oHVpDkti/m34HZNmjfHG57Ws5Jrepz40jfZaqruoZY94/M0avRPxlBioiX/M47MLl+tBqeDvrj8lWRBPE2lu5XlNtyiiq4Ql92jnwGAHu24i4W4JQSK4vhgYXXG8uAiQgd1pURGzRxk2SI3k2ni2dWulL1BMVoYnat6UDxWc30vIsB5q0rEzckEuuVy+hie/yfX2RPcNC0MH2S9H4i7RBTemz9a+XiaQPpmW2P4xHR2fPUuVvGhrGQ+SB4pKSWIWvu17t1orK5xt2sVK08DGyEjuNvWwtKNWYC3VWdKeWj2oqzjokbXXOEZD09ko+y9wQnR9GM2vSBbWAzY5TtO6YAWB5sWeKxEkuoNrs3g1hPdE8/UxpFacE4dRUkXgDEDX4et9TcL1IACmW+vgqLRKijw3FCs8cOD6BJmIbYxKJtvnaNy597YinWzh0Y0/dmfS6PFUe+8VlGlPxV3MW+5bXi0WeTHj5q0yOmJ1DLIaBsv42y+JK7frJEmO28BoFVsraXS3iK/tCTYzDDOI4d21dYuZyeTUhzJ5kdm5l8bvqNrRYWK6B5+oSZ1UaRcMmkXBGWiF8DBAGEzjiTlZ/KxwDTRzsAe9v5+uOr8U7EK9byaJ0SAJsrhwBxBwsgPA6k5TlHvWLrVj1gl91B21w5qFEp/m00gpXKhiNWOIHZjTm4+pLhY2/y1qEOwCgtVThotXRrhKauA6nYICqOLjwvXsznNAsCTO/V3KQf6jlxUTe9JT0EqUwNVq9zczNBCXsBrvW5dCHaU8/ozJ+IrN2iuTyq4Qd5YwfXLazDhJ6cbBPqsCRrY70Pc1pt/+vJAyHchC8872N612nPqXewRLyOn5zEyS9SgOkncV8qynCDImhD1dfa0Iuz0KpAk3Gq7NCh4Kylg95C2mQd+vM2oAco2GDAb/HaDq8RSJQTcAG+MqNgzeVSEzj2k9SnkxwMvnT2WzvBjX2d5W 8BN6u1cE wBK46trE8VFNZiuKwwHxq9XFw5Ghsp4mE6SzL8PJEJ7Zc846cPVScF2xaaGm6GHESSMDKiqJO2pUwmTHRneGe/4KcyaKlm8CrqmgCPsJr8Waz3Pqv7VMcZYDd+Ytk9o68D3LMsQGsHjbPO5KlaQO7oFh3dhCkYetJkuuTYcGrPTuaKXf5olBPEvL7v4ehyCCzYKsLuaiLBLUiWx4KCdvWSb0Er4gLMC4khDi9Ml+0xBjFnVtnpI7dAyzt3vYCEQyNRWM1wLMmgOww3h1ZD/ZTLFnOe4w73VTneUJllLIL8UPuYkO6DjRVSlZShYNLHmqQR6xBWTHSldtUHBRfJlMKIn9g9u/2vdhs6dBb3ni0VLNQ7OYEla9eqbD2cvQ87iSNld18jP7OWw1EUHDY20XdBrDHgCEv4fBt3hn5 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(). In debug mode, there are following warning: kmemleak: Partially freeing unknown object at 0xffff97345aff7000 (size 4096) Fixes: 028725e73375 ("bootmem: remove the vmemmap pages from kmemleak in free_bootmem_page") Signed-off-by: Liu Shixin Acked-by: Catalin Marinas --- include/linux/bootmem_info.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From patchwork Sun Oct 8 02:33:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13412529 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 2DCAFE95A67 for ; Sun, 8 Oct 2023 01:52:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B41278D001B; Sat, 7 Oct 2023 21:52:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF1338D0001; Sat, 7 Oct 2023 21:52:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DFDD8D001B; Sat, 7 Oct 2023 21:52:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8F8A38D0001 for ; Sat, 7 Oct 2023 21:52:08 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5A301B4723 for ; Sun, 8 Oct 2023 01:52:08 +0000 (UTC) X-FDA: 81320618736.30.6B3FD9F Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf22.hostedemail.com (Postfix) with ESMTP id 0E16BC001E for ; Sun, 8 Oct 2023 01:52:04 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.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=1696729926; a=rsa-sha256; cv=none; b=q69F285cCGQxeBjoabTvLVtv4Zxz2Wx0UFJuDrqFRI/asXJ1kp+KU4tMg76wPPKXjK/HEw A/Io5FIcVHiWjRXue2bCAzEaEiixUq5itz6Fa8MpQCdqAM6t1j1snf2WCQTgKTV+DnWcj5 cCzx02UU7BdqkQLhontNIGTIoVvwY/w= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.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=1696729926; 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=kIA9pqOpOsNwldWmWgfkumgb8X/NzdMY33JHLY+Khkc=; b=HdhWpqM+eo0t2ujLI06B83Nc91rcZF7pAfKAJGEFAeYl2++QWWfGb2JoMxB1YrC5p+5ia2 J63tKaSexjvegpRY7LkWXZuUT7J96yYoTSVe+x1UyGw50BGFbhD8Ow9bMQ2Z+nRWaOia+8 rFEoEDBVpbrAQPRxVMsydYmrvNonEwU= Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4S34Lj1DjzztTDg; Sun, 8 Oct 2023 09:28:45 +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; Sun, 8 Oct 2023 09:33:18 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton CC: , , Liu Shixin Subject: [PATCH v2 3/4] mm/kmemleak: fix partially freeing unknown object warning Date: Sun, 8 Oct 2023 10:33:16 +0800 Message-ID: <20231008023317.3015699-4-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231008023317.3015699-1-liushixin2@huawei.com> References: <20231008023317.3015699-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 0E16BC001E X-Stat-Signature: 11ehjwstttm56zznugf74ms651w3tpcf X-Rspam-User: X-HE-Tag: 1696729924-181458 X-HE-Meta: U2FsdGVkX19UnuSTD0cJ/ILno3qj+yinP/M8zTz7Bks+MnLedwZzmCJxjTT/n0cLtaiK8Z6/lgHA18pjOn4INjtfoaQvqKUT24ir6M47IT+GGA45Pn0FF/Rqo5vO7KLPXm3F0VkD/w1luIcx7BKp2ofq4MOZYIuet/SK16w+2KY291Lugr2wesJba0KqUUSwz5yPfChW1Op7tTwHAyiMqEwcl9gyy0+A80Rbbc9Ecg5MUJ6IquIK/ct64+mbB0m+M2+VOqy+QuXuLCXc0N+I4o4pydfDib7fjsSwcb8eWLwxa0ejQIAjfTWe1+j1Mtk1TTn5uViwWYoAghFqoD0o0VNdTxkXr3tMCT46QoqTr95UdmSva6GrcsrSJV9bbjmyznpKLVXEsvlVdTKs9eACIQ14ITHK5TBBLoUIQZ2vaVYYtqj/JWyS/zmla/jG6W4U8LceJB+1ob3Dta+Spk7oeI0MEtXi9k5wswFUA5GthCpb7V9OTNKTRTzOFRSHbuffB7xGcVcjz0TSuuN8VFKo0B+w6yrM8GB6GyW+3P5AkWU91a3/FIBNXkO8y4j8r55tae9xidcfh3X802EqGUNkh8vFDtL1g0Vwx5SRIZXnBUlpL7NCU86q/M9GdDuDFwZZfZ5hZjgipuVP50mV70BkBxla7WBlcBmIaG2weTElht1gw1QxD44jU6+/Luqprsy3z4Ot2qM2pYTv8atCHsYCNK7FnT0ZCbpfI1Fe23Ebq9GxRNNUF74lk8HZE1wkXVnDc8rBAtG4DuhzY/V3WW/BgYpmnxWlQN+GF8tzoD91PltRllNeb7fvx+T0M4ZcpCAPYHl/gGD+kwf3uyldCZwJF0cKmYmyiRYgae1EgHTIQxcloBSd3ELsvy+udZ/i+fRuWZDhnfbnRcSNO0xQAPPRf39ENKrHBwLfZfztDvsep3oV2PUIVZ01c3JfF/9anudkdJ/+ZCOhgQ07nMVlZFq 0iR3GI6U D4nvQ0HXgooOmvTpFWfarwrvwRdggRrMtrUvzRNmZ2jRXCI2rCZurcscjrglpcI+EmvwkW73OiPKbwCPDAfJtcrJATcZQiYHF0qv9ooVEJax/okr7TEC4Iu4Pce6+TyUe3iDhtwfSwFz51qmDzgzuwxagENqEqyiKMDYDsuuBex1lAQsY4O5X4zEZOUOjyltSADaitGPd7EiknZv8VvvsBiKQnvG637puVqZ5HojElhFJa08TZOqxjiwzGZc06nfN0MQXrepaIV+fKpvav3F8qgvYJZMM8S3OEKx9u8JopUGx7YLP5VY+0Reg9g== 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 Fix the problem by adding a new mutex lock to make sure all objects are deleted sequentially in delete_object_part(). The kmemleak_lock is not suitable here because there is a memory allocation with flag GFP_KERNEL. Fixes: 53238a60dd4a ("kmemleak: Allow partial freeing of memory blocks") Signed-off-by: Liu Shixin --- mm/kmemleak.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 54c2c90d3abc..ed497866361a 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 are deleted correctly */ +static DEFINE_MUTEX(delete_object_part_mutex); /* allocation caches for kmemleak internal data */ static struct kmem_cache *object_cache; @@ -785,13 +787,15 @@ static void delete_object_part(unsigned long ptr, size_t size, bool is_phys) struct kmemleak_object *object; unsigned long start, end; + mutex_lock(&delete_object_part_mutex); + 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 - return; + goto unlock; } /* @@ -809,6 +813,9 @@ static void delete_object_part(unsigned long ptr, size_t size, bool is_phys) GFP_KERNEL, is_phys); __delete_object(object); + +unlock: + mutex_unlock(&delete_object_part_mutex); } static void __paint_it(struct kmemleak_object *object, int color) From patchwork Sun Oct 8 02:33:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13412516 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 3F21EE95A89 for ; Sun, 8 Oct 2023 01:33:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D4298D0018; Sat, 7 Oct 2023 21:33:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0842A8D0001; Sat, 7 Oct 2023 21:33:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E8D1C8D0018; Sat, 7 Oct 2023 21:33:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id DB4CE8D0001 for ; Sat, 7 Oct 2023 21:33:27 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B6EC3402F6 for ; Sun, 8 Oct 2023 01:33:27 +0000 (UTC) X-FDA: 81320571654.19.245529F Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf23.hostedemail.com (Postfix) with ESMTP id 1062C140012 for ; Sun, 8 Oct 2023 01:33:23 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.255 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=1696728805; a=rsa-sha256; cv=none; b=e/rycKrOPO/rCrWjv8JB46VF2qzDp54I4r2kWpa/7L3KfZPT8EoKgx6RefzxeT5MzSPRnB UkpA1qKZmmH9ZTvs3tAihm/88iSFfOpES5wAvp7VPR+Hhyp2PO093TNvCaagkrAygZ2t9+ qZeMtPCjIsvv406vd3bWhSJz0JWSW0A= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.255 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=1696728805; 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=J2Is8BYDc9rNwSqPl1bKHd3fAAzOA0SWizeVob94fOU=; b=EyFv2Q++S079XdZrxwaH9lr53xyCvTc/EiN4e4yGFVQnc88XNwPZxaI4+8uWei2VRo1Drl 4VSygrPAg8CxF54MFy7yPJwbm8Kv/WeTkdhHPmC/utgoAjutFh3LjJ3RszyCncc6VDHKBq /SKTNmG4zP/QLuyXesRCIi4wPeQulIw= Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4S34P56rbsz1P6g0; Sun, 8 Oct 2023 09:30:49 +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; Sun, 8 Oct 2023 09:33:18 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton CC: , , Liu Shixin Subject: [PATCH v2 4/4] mm/kmemleak: fix print format of pointer in pr_debug() Date: Sun, 8 Oct 2023 10:33:17 +0800 Message-ID: <20231008023317.3015699-5-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231008023317.3015699-1-liushixin2@huawei.com> References: <20231008023317.3015699-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1062C140012 X-Stat-Signature: 4bhqbxqcttypswbeth3hkarhuqtxqb7b X-HE-Tag: 1696728803-514170 X-HE-Meta: U2FsdGVkX19/bSe4AyWd0gjI7RiqlkNDhlBXdop6a3e0lvfQW0SAlWze6oxaab5nhzqJEWnbIUDFMhwU5eWXqUAU8aTUAj0HIbPFpDaeyxVtARy4OYjqw/IVgxaQKuFQFHAiz8LIeJt7YBoOGKB2CqmXaaWbc/o2VJIzfQeSCWQUV+mkeaO9BQTUWIk6SSUJKBUkw6oe2f2QP6Ly9gRKFI05oqDUHcrL1GKjhAHNm699vM19j1R/wrjp68DQp+m3IgmMw4+1MZoz3QgUjOhxGfr4pSrp7IjEemGQp/lXjh9qeGvDCcnEtPOINOqDxPoa+W/Elo14iDFHMSZmppTXIXXzzTyxwDTkJEaTd9vuG0VccWWbNY15GPs9sBCu9Ku2umMMdJW0bhTV+M0Xz2ahkSWubAqYIO/Vj9/WxkARSl+fSnHHvChC1m6QcAjej5qX9zy3CwRUUwxg4G/gqWzw8d1drYFDm3nwvqJViInLmzG2EUYXLOStCkAspPwmbLY/UBmI0T/n7lBUR0jBMgiTTmJcNmFQ7Bj7NhgDc7EdBL4yRMaqL+jJeiWvcS5ec3sTHDWwF+LoH2e15zpQzA60x61wvC3/F3dIjlTQ6JSYeaDnvcO9n+HgG8BintIhK9PTRZ6F77LJhMLpPSmM/EAUfvBzoieUNWIwSLEO1MxkQtyaNtEoexhjA6Y0kfRP2fYDDpjjIDxyYsrbTgGNVjDKiTyDwJeIs8VASkPkxR5ZPEd8KF1tgm3bEVXHbwClmckP/8Ht2KzPSmjqdG0SbejSmk85NgTF/IU+roJVs5wTGWTaW0+WQqYaABpmFM9VIQgeTQ7Yw+VDA2vc55zaGr8Q9hSTWNpe7kKifu1OimjVcBm5GUxVo7eRAKAjCXLZOpNvgiCTRxHU1kB7wqRFCTqS3tt/sh0G+nrXz9eFk3Kp/vF/ZdImVaz4Y43rRaWXLa71y6s1h6sLIMG01NHQ9jd n2QAWtVb v7Jttlm1icJ0at6WXlft82XVwOUlIkbIzL6P/8UW+sVRXIiRaXNsx06qyIpu6sHDnZkvdjzwh+LQDurdnBsT1Z2UJMLRBVPalMl08cv8jWnH5k7vksqDA7oXMRViR+UhUfr/p4a66ERWNea0SMJbzZGe7Aj7teYb4mTM7W4RTNdY03UAZBILS2DzeXc5e9FDLp80DfhgPAet4IitYIU3dX/wiPkllFoKmWf93VPmi3XMBd9GycRwNIDYz7E74T74z9x/w 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_percpu(0x(____ptrval____)) kmemleak: kmemleak_free_part_phys(0x0x0000000a1af86000) Use 0x%px instead of 0x%p or 0x%pa to print the pointer. 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 Acked-by: Catalin Marinas --- mm/kmemleak.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index ed497866361a..042cb0d18c7a 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -982,7 +982,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(0x%px, %zu, %d)\n", __func__, ptr, size, min_count); if (kmemleak_enabled && ptr && !IS_ERR(ptr)) create_object((unsigned long)ptr, size, min_count, gfp); @@ -1003,7 +1003,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 @@ -1027,7 +1027,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(0x%px, %zu)\n", __func__, area, size); /* * A min_count = 2 is needed because vm_struct contains a reference to @@ -1050,7 +1050,7 @@ EXPORT_SYMBOL_GPL(kmemleak_vmalloc); */ void __ref kmemleak_free(const void *ptr) { - pr_debug("%s(0x%p)\n", __func__, ptr); + pr_debug("%s(0x%px)\n", __func__, ptr); if (kmemleak_free_enabled && ptr && !IS_ERR(ptr)) delete_object_full((unsigned long)ptr); @@ -1068,7 +1068,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(0x%px)\n", __func__, ptr); if (kmemleak_enabled && ptr && !IS_ERR(ptr)) delete_object_part((unsigned long)ptr, size, false); @@ -1086,7 +1086,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) @@ -1107,7 +1107,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(0x%px)\n", __func__, ptr); if (!kmemleak_enabled || IS_ERR_OR_NULL(ptr)) return; @@ -1138,7 +1138,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(0x%px)\n", __func__, ptr); if (kmemleak_enabled && ptr && !IS_ERR(ptr)) make_gray_object((unsigned long)ptr); @@ -1156,7 +1156,7 @@ EXPORT_SYMBOL(kmemleak_not_leak); */ void __ref kmemleak_ignore(const void *ptr) { - pr_debug("%s(0x%p)\n", __func__, ptr); + pr_debug("%s(0x%px)\n", __func__, ptr); if (kmemleak_enabled && ptr && !IS_ERR(ptr)) make_black_object((unsigned long)ptr, false); @@ -1176,7 +1176,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(0x%px)\n", __func__, ptr); if (kmemleak_enabled && ptr && size && !IS_ERR(ptr)) add_scan_area((unsigned long)ptr, size, gfp); @@ -1194,7 +1194,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(0x%px)\n", __func__, ptr); if (kmemleak_enabled && ptr && !IS_ERR(ptr)) object_no_scan((unsigned long)ptr); @@ -1210,7 +1210,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(0x%px, %zu)\n", __func__, &phys, size); if (kmemleak_enabled) /* @@ -1230,7 +1230,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(0x%px)\n", __func__, &phys); if (kmemleak_enabled) delete_object_part((unsigned long)phys, size, true); @@ -1244,7 +1244,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(0x%px)\n", __func__, &phys); if (kmemleak_enabled) make_black_object((unsigned long)phys, true);