From patchwork Wed Oct 18 10:29:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13426733 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 6364DCDB47E for ; Wed, 18 Oct 2023 09:30:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8B6B8D0150; Wed, 18 Oct 2023 05:30:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9EDFF8D014C; Wed, 18 Oct 2023 05:30:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F1EC8D0150; Wed, 18 Oct 2023 05:30:29 -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 6869B8D014C for ; Wed, 18 Oct 2023 05:30:29 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 48E8080190 for ; Wed, 18 Oct 2023 09:30:29 +0000 (UTC) X-FDA: 81358061778.07.59DEB55 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf09.hostedemail.com (Postfix) with ESMTP id 0E78F14002E for ; Wed, 18 Oct 2023 09:30:26 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf09.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 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=1697621427; 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=2YkBZzFEEdP4jc8hH3YnUyxfaNF7mRJ+WWmUhHPaPYuiCUJVT38MKag6NHCKsMhYE3sOLk LsQX2Wo9BTGLEG6Theg5uZ0CIxrLRxp+LYyjRP1jiRREKN2c7HBSdljsTnRaKlglDCMynp khAgV5hfi14iGinN4i9L3WHaYV/0Pxw= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf09.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697621427; a=rsa-sha256; cv=none; b=EtD/wFzsymWp+h8K18bJLHEUPJnDMwDEKBdue/qil/s5BWImXABsp18RO1ctM8mb6c+bC1 L6uZcYxuedt+64qNvxmGshI14D1Cac9dZ1v4jgz7k41uwVWfiZBgwibpFKfxa+ZaF2Of24 e4n0tylRvhEAAnqjihe7hCkel4pNSDk= Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S9QTV12p7zRt62; Wed, 18 Oct 2023 17:26:38 +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, 18 Oct 2023 17:30:17 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton , Kefeng Wang CC: , , Liu Shixin Subject: [PATCH v3 1/7] bootmem: use kmemleak_free_part_phys in put_page_bootmem Date: Wed, 18 Oct 2023 18:29:46 +0800 Message-ID: <20231018102952.3339837-2-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018102952.3339837-1-liushixin2@huawei.com> References: <20231018102952.3339837-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspam-User: X-Stat-Signature: 599cmorxbfnoi78xjw7agro3njga3drm X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0E78F14002E X-HE-Tag: 1697621426-990000 X-HE-Meta: U2FsdGVkX18IVu8uWe67y1jO7oNPclIOOzJmLSucLIt2sK8c+hL+Ub8yzxl/Aio+g3IjCMF+Ejb9yOZ6jgF6AFlE+7WVqpQBUmO4U1WTT4CXiv5yt5XjJz2wJIFcei87iZ7mdBTlr7bYLF6h0hyulMod737KH9sP7l9eQPjEBcFpKss1+kAZIAWrIs8NmLr2fd7RnHLDWNp5Nfcch0qaqo11UuGAuLrosbbkUyDaH3BsU/VaZGkxkwoeZbZjhrzqa7knQ7nMHfsHCGk17yPlQOPveBF8++wYy6zg9m8JfOs7+dPwMt0IGM1cc3LRmXWsF5VoNIzLhZw78FZW79O33mI7BFwU0cq2w9rtAlA/siNAYC9AgiIYRZ5R1c+kwo44q6GXwDEevSvAvL+HHdtiNlEaX9ynQkPK6ue+dYvXP1suBYidoqMzCFffRMpR9qiyGR2ph3dtZVYm1kc/ptcxUuLmh8bIbt8xMS7dp+tGPFZXEWYaeM2ynG8W85Y/86Fv3MA2ODRFTwlyaBjPs4OunHinR24+YCKRYks2YgMq2YvCGimbmMvoCXGNrjd9dz/PxqNlbQe0QWa8iR1JxEUdmf1QFG1gCZC0NBNY4lzgBsq1VDYNMzVtCmKn2sEgRsG9EZ9qrGz+jNS1dR1FY3szxk0AH9umUde9DB4GuQYOFdWaYKlH1dqE8xQ1/fVBQeW9pi7UYd6Ljxe2vypsRKXoLsrIQSB3bifPO+TlI4UiauouDtqmnefLf6hgve6Nu2T8wyBNQHl07VBGszAEzyFWcEirU7cUtFe/0GbVP/zoRg5EN3Grq6ZdbwW1iOMexm+4mbpUY32VixWvDp/GiQRSs6PfjaIOoxmMuxDml0ZnCrZKWtbDiMnfBSfE4cvm/ZS6Rg1StGa5/FzQ8OoeaYDt3HhdNZuwgI+HmAteUacJRSrsU/At5S+KsCXvyb3RCv+vA6uoPgOLajGFASJeQhr qiWTMhRw 6OJ8D5WfIKPPI2wH6gDtecdlFnf8EOBEk5/PpXaPrl7fbhs+8lHpKmfi5Vh5HbUdHcZqMGBkQj9PeA5gEfOb0Iqx+B2zJdz3T/urGAxGrHgCPbVvhwz7RtCArBeOecdnEWdOk2y3pVMYO268oLBUBqRe7qbor41dYgizB+deIl0k86pz25ZLf1JcsubVFNlhQ0e2A35HFQMctvHMhyCFx5sQEMB/IdNR34Gz1oJVaQS7u7BewiejI/fNk6Qo6wOcMX5APFizjdhafeDgh/JBkX1GasIWSiRlkEAydeVZzOQ5wlE+yPa91IaMxzd1wfYVKxxXW 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 Wed Oct 18 10:29:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13426734 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 DCA7DCDB483 for ; Wed, 18 Oct 2023 09:30:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A4EA8D0151; Wed, 18 Oct 2023 05:30:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 72E3C8D014C; Wed, 18 Oct 2023 05:30:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55ABF8D0151; Wed, 18 Oct 2023 05:30:40 -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 430BE8D014C for ; Wed, 18 Oct 2023 05:30:40 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 18415A1115 for ; Wed, 18 Oct 2023 09:30:40 +0000 (UTC) X-FDA: 81358062240.06.8F21E2D Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf14.hostedemail.com (Postfix) with ESMTP id 61A17100026 for ; Wed, 18 Oct 2023 09:30:36 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.189 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=1697621438; 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=bbCkspqjeGi5Okl/SUon4VQig7G4PBQPdWgluk6vFF4ftpjqfziN6Dnx1vj6d1nYSIRj9p crBb+Mnh/INfYDz58554e01KxzQpZ5bEWqw4148uoOnq4SaCi0pz6gFGaYHlopOuj8Tb+f mmxfc6ALQIM0xf8pAQ5GfDZzaQQ0mgU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697621438; a=rsa-sha256; cv=none; b=KMVRxppSoq6eek5yfrbwi8+zQVNuOOyCQhMf+e9TrTUGFYCugJDWJMWXl/Bqzgqr+V4N2M S8zojRV1CoZeUahDPEls/6oKJOjISQIS1ynWFMADlpIGw9/RS6pmZIKFkiSj5n5oWAx6Cl x9TuPRvCKQ5Ga0GgoKoubF3cI7Bcs1g= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.189 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.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4S9QT12vG6zLp2r; Wed, 18 Oct 2023 17:26:13 +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, 18 Oct 2023 17:30:18 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton , Kefeng Wang CC: , , Liu Shixin Subject: [PATCH v3 2/7] bootmem: use kmemleak_free_part_phys in free_bootmem_page Date: Wed, 18 Oct 2023 18:29:47 +0800 Message-ID: <20231018102952.3339837-3-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018102952.3339837-1-liushixin2@huawei.com> References: <20231018102952.3339837-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Stat-Signature: ochmqc7hsetgphemuhz75ftp79xk53u9 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 61A17100026 X-Rspam-User: X-HE-Tag: 1697621436-333149 X-HE-Meta: U2FsdGVkX19UExpK5nDptzVWPL2Cy4dNl1ZJcCIn/jz7qUBFAEmA53b9y4tX3wBAGFYba6U+HxTMRsqgjDzX6lvh11shhN7VMJeglT85ftBtK39zPUgBPbu91R+bUXjpIQt9QGuv0gJ9r8Pzg0l078u24NGgZZkvYUploqV2dXWpPLwhzDPQONabEH6OmPqjOtBYnIwljDFj4kGzEO1WR7RDIwkrrnERC7mouSMLB4QsPN3fHo1gQQsSjfthRIW6LAYrRfakp8Xm/4PvkkOkHR5T1nSupkZltVghHGjq6bVJal96rWu1e4GpoVu4ZQqzELoXicuuhCJUcWlqahEcq3OWEtZy0gys9na3SA74vMqUChryMwR3LyqQBIRWp1AHN8N36Rnbu9IuFyfqN5cmcBkCxRwiR9q5oCWz6e6V5ZS6elI9XJJlKcVvFOTSdxgnzAvm5dsMZgcnndqXiYoYkghjTGE1XtdwE6MqVIHDY80VEIhYFNdaTt1YnGOQmR4UMR5wOf7O4YyUf4tl7EdFstm00lRrn7sfeLhV19HiVwpIzEc++MXNuQAqchjhdLK8ZI4HJzu08JSMHuo6Ik41xI04UNJHtLFaJzwlRuhQQbXuvyw79ZkVSIRAB5spcqPE1q1G6EEV39Yp1ji/BtI7ZA8QjEuZDpoYPVpDUzXMSzUp0f+OOy0vnQp+5O97QOpET7T2f+GbW0BHORDj4yAxOj8WdXXWqf95fkYPx/tg3yWyWuxlQxGe7c96pWXme0sZiszX8Vx0r4G58blQTKNtDXJwVdmOabIuM4tbaCmbRFkVA2rs+LY8BL+tkPGrNMTLZBiwy8geeRPTMb5uYegGcwU0iy+RVN8S4bk/HIvFtwmXHxtcP+QvZPh+LccVsTmNQTlbJt+7+NF5DGwyAuJj3/fR5idz98SD43MTeWI0qiBde4MT3NU1IRnxUTtPF8poZxJJw+kdy6Hi4a2wFTt sGlZDdQh 008KGiKtDdoC2JEI7Iw1hZUJxk9ibeVeXUFRRnrbduVmkuFO05qf/ZyLZZxGsfxR68O1Tp2VI1RJPx4nA268ApIC2QSA9R+O86QM8PdnDsyc29d7wMzG7ppwy2xBFV8JX6VsQmkMqTwZ6fszaX5jdDYwMuCNzJsS1IIR6JipIbx5Z5vTaM2tRLbveX3H9jABmMt60xhsph3Y6R8ykRJoNQoljFwGQj+8E5vQM2FkiCbnAtTbo5RAOyhX8o+JAKXsa0tp9TlysZ+guU5zcwx+vTe/knF7EXJAUUMyJECioH4Hfn0kh42Z4HH9Mcaa1jiVb5dYJ 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 Wed Oct 18 10:29:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13426731 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 BB0A8CDB483 for ; Wed, 18 Oct 2023 09:30:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DC6F8D014F; Wed, 18 Oct 2023 05:30:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 841288D014A; Wed, 18 Oct 2023 05:30:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 641FF8D0150; Wed, 18 Oct 2023 05:30:28 -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 38A058D014C for ; Wed, 18 Oct 2023 05:30:28 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 146961601A5 for ; Wed, 18 Oct 2023 09:30:28 +0000 (UTC) X-FDA: 81358061736.20.3942569 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf18.hostedemail.com (Postfix) with ESMTP id 937D21C000A for ; Wed, 18 Oct 2023 09:30:25 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.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=1697621426; a=rsa-sha256; cv=none; b=rXxDnkscPA9NTmAKzCV3JkkjKlGPzWKarcoq0E2o9Sm/F6qMj6Uj0YeCmWJourljSDfUmT +B1uaD6FeZZ4wDMWH88LnsedQwtXbl5hHpN1Quw9j6EkXKUFnZsm5P2I11prgvpwrJShQl sekMSLd4ES+9DzAsWRcB16wnLA1dvjo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.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=1697621426; 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=QynFQbdBOqMAbRbqIKAb4ezQxOAxrMBgtLmqyiL8XDo=; b=YsPpdjwI8xaclhV+SGDVfkhH1px886uURHzqTSDjvjwjk85zlyROxHiQzV0zIa7ulR0ZeT /K2gSbHOPepivMqqu6kOnUkuVtRJYJO0TCPZpCc9G6WvyZu1VEwG7e7cVCSwQxxcbuLT/u YPYZ16iSvsPKQrLtZ53L5y7YQoIrRjM= Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S9QT763HmzCrMt; Wed, 18 Oct 2023 17:26:19 +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, 18 Oct 2023 17:30:18 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton , Kefeng Wang CC: , , Liu Shixin Subject: [PATCH v3 3/7] mm/kmemleak: fix print format of pointer in pr_debug() Date: Wed, 18 Oct 2023 18:29:48 +0800 Message-ID: <20231018102952.3339837-4-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018102952.3339837-1-liushixin2@huawei.com> References: <20231018102952.3339837-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 937D21C000A X-Stat-Signature: oqri5yyfiknpij6k99pnp4ucnuick9t1 X-HE-Tag: 1697621425-874401 X-HE-Meta: U2FsdGVkX19GXY8KER//ubcQMc382pSztPDN+S4YfgIoXq3APJ1yElxXcfq7do6rWs9FKRq6+g2rXnPGG0fJ/JepsCZ8eX5ES0DTHiMkzigJEOZvlosDycO5xFSsqOOqUuZAL3Fqx+JHskgAV0kHDIDO5eU6ND6OORRE7VevjlQNjZm6APV9RP6lc2zp1PCoJLAZ+BRRZ+tlDaWMvxT0wQAqibYqoGAFsIXObxqOS1ZBeL5SvTsf7/CIBx3rIwNfdH4DqBIaPV/LmM6IXZRqaDQIAOLjsCMxp69LdaEz42IKEijlwO7qje9/TcIyQdzw9i7GXKM5EbYEMlDnptjKq8u4qdLFCORtRryUoZYeC1MEUoVDTvsBrK2ATC3odnGSiHPeuH/Yt2KFOl9Efks7CHCdZ5poY9aANexw/cJtcneiyTuUgqzPvmaNcUiFmCyfZI8VBHlrQAxPMTkz3d8iDH3VykbgOhLWQwF2qnw+W1AumSR0+uxAxDYqTEFni5KqfLLknKxx5fdhMiy5Yv5mA7g3WFWdwwsBbaCgrGHUySyYj8NJRysIFQ+V27+OsXUGfHZ8tsF62gjJj7iB8+gkqAUSur2NZTg3CFxDZxj7pKRcb0sjY/8B658u6o0GBcWfTT0Rdh/RWzNM+n8il4MoBeqoZ1GEuugflEmSiCJoqGe1nVCiPOWGkretA+JdRELH2h3dJcie+OprF0YtX1+oqteXBf2swmn/EnRP+nm5FXkIG8y6W7Q40FyL+OjafHRwVrkIZLhFmofWrDvtxqIcgBoR5x2Dh8/8NindUpdMDg3iQNETBPM3dkhxImKU0OGt/M6MW1mFOMdi492JRCM72/iRBb5lUm1h5gBaUUt+uGZpuC40OqzIOCC4tJL9lopI7dbOmpfuwkLYEPGyK8NPw3fhmBjxZHxWCg9o3eZrqvcnP5SsV+kVSKf61CvbVYaWVOBxX18AutDu9Cv8iMC D3EBJE1H dy5GMw6Zevpgn03wP4bip3n2YEtkRdT00X5LY2R6Q67TjxuSRWmPq5rUWT8NbC+BWnLiMMfq81Fzh/WMqylNCj6dMZ42mJAx/efP3MKYRhuWekvZjzJ0ocMrZim1jmFVV4tCjVAMC21tSlYdDSRhewL+AuI0wwUDx4SUGBvHHdRVAwy0k8gShkwrsq25kUQq6ChiofEJNPxVKm+9RlzKM6gWGdjpUoRnPFdtTy3XtbYuy4qKn4eNTxCUPHuJlyoaoyOhZJ6/019A0kcgKb3b7U2oefi7/31gzxB/XvmaN+62Gj4xD58P+Vot33VmpIyygfdvO 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 54c2c90d3abc..289b3be5ee6e 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -975,7 +975,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); @@ -996,7 +996,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 @@ -1020,7 +1020,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 @@ -1043,7 +1043,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); @@ -1061,7 +1061,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); @@ -1079,7 +1079,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) @@ -1100,7 +1100,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; @@ -1131,7 +1131,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); @@ -1149,7 +1149,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); @@ -1169,7 +1169,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); @@ -1187,7 +1187,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); @@ -1203,7 +1203,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) /* @@ -1223,7 +1223,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); @@ -1237,7 +1237,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); From patchwork Wed Oct 18 10:29:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13426730 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 D0780CDB482 for ; Wed, 18 Oct 2023 09:30:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 497CF8D014E; Wed, 18 Oct 2023 05:30:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 420178D014F; Wed, 18 Oct 2023 05:30:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D5B98D014E; Wed, 18 Oct 2023 05:30:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 00E8F8D014A for ; Wed, 18 Oct 2023 05:30:27 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C0917120C3E for ; Wed, 18 Oct 2023 09:30:27 +0000 (UTC) X-FDA: 81358061694.23.7734FB3 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf04.hostedemail.com (Postfix) with ESMTP id 2E4444001D for ; Wed, 18 Oct 2023 09:30:24 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.255 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=1697621425; 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=SRLMJjdHw559WUkNqfMGixZkAAP6vteLR3osyUIfiHA=; b=SjM8kVi45YhMOLuASiqsNmnzd8gBwOW6+4kfqSlKfGZ4g4dR0jttD0pi0ycswNa2OELNEA SvBNUAwK2zi7fmEJBclbb9/QIcmQq8whtPF4Qaje4Wxk2pLlhG1Zruykf6kXcVCX1nqLGn sYN8dUUSrejpnp2L7SqgBLgDwgu/CQ8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697621425; a=rsa-sha256; cv=none; b=IkymGRtpBGA14eS6j2Jxj7vYk61ZLW+OT5NEesfXizhqJTmnn/NFcMf95a9NXN22fFzm2Y 7PaZIbaycUXRnwfum0XVje+QVSzyvC3xEQSS+kaQ8UcLkpS7aGQisOGOFzcODqKkd45GYK 2Yq0NiidYGsu3EOe9F4sJV7AkJ7TxU0= Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4S9QVd0ZRSz15Nh8; Wed, 18 Oct 2023 17:27:37 +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, 18 Oct 2023 17:30:19 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton , Kefeng Wang CC: , , Liu Shixin Subject: [PATCH v3 4/7] mm: kmemleak: split __create_object into two functions Date: Wed, 18 Oct 2023 18:29:49 +0800 Message-ID: <20231018102952.3339837-5-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018102952.3339837-1-liushixin2@huawei.com> References: <20231018102952.3339837-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 2E4444001D X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 36jgnognk8j16i7b8df4kr8mse89hbmx X-HE-Tag: 1697621424-990728 X-HE-Meta: U2FsdGVkX1+uyVeQ0i/UMT/jYDC/6CQEFXf7trjMUs/gBReguberngpozW4YABBuGLxZhXZkgVHMdBGrySd+Wwh6/O3I19lLJALkjUFcUyiOj8omd/H50PYwgB5/GgYbJg98zih/TLvFp6Md9SmFpFp96hNXNGTlBde0VWQ87Gu+u6EvPxk3M6GEXtcVrbvdIbexkoL5XgTo3VbiBM3IxVDRl6jW6Bvf5Wrmj33clq76GU+FlOHZvf09XmNQu331JkM0FTubELRvtSjuFbltyvgD5Tg3K4kZHFdae1M20xZZVcFHLyzYqd1UP3Mf9Ygd9GNEyqKX5j1Oxj6MbQjM9s9nGE4B9m9jFJvLY3yfMJyg/RuHBaFqKpAuw/wj8sowqqJ2mmfE+b/Ta1FGfi3tGIq3IA0N3VgrsnqHWs4DdknpFqm/vQX4dWz1aBW/N44zlDAmWEqag8lx4pxL+2fKZr9RIo/xx0U1b7zMoIXai7vF6oGj51OVkgoVZ3vzatPgymWEPcepTnRezQiFqXdmGd8RS5pK/Ko3fYZS7XxKurGi4BDtQ2DKKIfHUMfpuNelwcH9hCLuZOhrzxZAUZtSfqbh3zeSlQZH4j+eACIm9PEBSDxUgQAsh6+7v2gALbH2ahNy0xtqjyoVd7E1yVRAXmzwE+goDKtdyNZBVQB/zynwb9cKbSaZ80o6a/c9wPsbEBXr9AYPW8c7uUjWFbwfL24DNjMsl848ZsiJR9KBaCMUVC18KRn6AuNCMZr2fPHjCwTbQxtM/Wp9ODa7tZt2yldeIYzVPsOa0XuPeZ4CCkV2gfJNcX5bVvRO4PbcmFa2TDdLeTtv1brC/yD9Kd4O2JTN0m2zoqVe3JQf+3zx0BMqOIShTSU2e08lSkxPvzGeuxeN+3Agqva5aal+SXI6o7g9CBUfkncwGC5m6B+N3onXwdF6SplnoJn0/hn1pD6XuyMNEiP8ps+MqcXjHoQ Cz+8Xrzu wWf+IvOppM8XW+CCsB3Ryyn0dbBtI8XbcqykrJfXeHPRo3IGVh2e3d2Ja4l88vvwYFKD4HRaVVYjC6lWxAWuK33jha8ekRWO/dyfuZjsnZNhj4DHnpjA9IrZzKtaRXjCuJTXlArtUl1TjFI+cOPLUPT2SOymbJxhY2Xe2LeDsMj04Xld4PmA4Zbxm7hlpmHCAlqElmeZFEEYf583wjl/ILSagOnyR8VCOUBsArzrAYZo3qyE78MuuUWXiPz8B3GdAiIB5 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: __create_object() consists of two part, the first part allocate a kmemleak object and initialize it, the second part insert it into object tree. This function need kmemleak_lock but actually only the second part need lock. Split it into two functions, the first function __alloc_object only allocate a kmemleak object, and the second function __link_object() will initialize the object and insert it into object tree, use the kmemleak_lock to protect __link_object() only. Signed-off-by: Liu Shixin --- mm/kmemleak.c | 61 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 289b3be5ee6e..064fc3695c6b 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -623,25 +623,15 @@ static noinline depot_stack_handle_t set_track_prepare(void) return trace_handle; } -/* - * Create the metadata (struct kmemleak_object) corresponding to an allocated - * memory block and add it to the object_list and object_tree_root (or - * object_phys_tree_root). - */ -static void __create_object(unsigned long ptr, size_t size, - int min_count, gfp_t gfp, bool is_phys) +static struct kmemleak_object * __alloc_object(gfp_t gfp) { - unsigned long flags; - struct kmemleak_object *object, *parent; - struct rb_node **link, *rb_parent; - unsigned long untagged_ptr; - unsigned long untagged_objp; + struct kmemleak_object *object; object = mem_pool_alloc(gfp); if (!object) { pr_warn("Cannot allocate a kmemleak_object structure\n"); kmemleak_disable(); - return; + return NULL; } INIT_LIST_HEAD(&object->object_list); @@ -649,13 +639,8 @@ static void __create_object(unsigned long ptr, size_t size, INIT_HLIST_HEAD(&object->area_list); raw_spin_lock_init(&object->lock); atomic_set(&object->use_count, 1); - object->flags = OBJECT_ALLOCATED | (is_phys ? OBJECT_PHYS : 0); - object->pointer = ptr; - object->size = kfence_ksize((void *)ptr) ?: size; object->excess_ref = 0; - object->min_count = min_count; object->count = 0; /* white color initially */ - object->jiffies = jiffies; object->checksum = 0; object->del_state = 0; @@ -680,7 +665,23 @@ static void __create_object(unsigned long ptr, size_t size, /* kernel backtrace */ object->trace_handle = set_track_prepare(); - raw_spin_lock_irqsave(&kmemleak_lock, flags); + return object; +} + +static void __link_object(struct kmemleak_object *object, unsigned long ptr, + size_t size, int min_count, bool is_phys) +{ + + struct kmemleak_object *parent; + struct rb_node **link, *rb_parent; + unsigned long untagged_ptr; + unsigned long untagged_objp; + + object->flags = OBJECT_ALLOCATED | (is_phys ? OBJECT_PHYS : 0); + object->pointer = ptr; + object->size = kfence_ksize((void *)ptr) ?: size; + object->min_count = min_count; + object->jiffies = jiffies; untagged_ptr = (unsigned long)kasan_reset_tag((void *)ptr); /* @@ -711,14 +712,32 @@ static void __create_object(unsigned long ptr, size_t size, */ dump_object_info(parent); kmem_cache_free(object_cache, object); - goto out; + return; } } rb_link_node(&object->rb_node, rb_parent, link); rb_insert_color(&object->rb_node, is_phys ? &object_phys_tree_root : &object_tree_root); list_add_tail_rcu(&object->object_list, &object_list); -out: +} + +/* + * Create the metadata (struct kmemleak_object) corresponding to an allocated + * memory block and add it to the object_list and object_tree_root (or + * object_phys_tree_root). + */ +static void __create_object(unsigned long ptr, size_t size, + int min_count, gfp_t gfp, bool is_phys) +{ + struct kmemleak_object *object; + unsigned long flags; + + object = __alloc_object(gfp); + if (!object) + return; + + raw_spin_lock_irqsave(&kmemleak_lock, flags); + __link_object(object, ptr, size, min_count, is_phys); raw_spin_unlock_irqrestore(&kmemleak_lock, flags); } From patchwork Wed Oct 18 10:29:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13426729 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 F1062CDB47E for ; Wed, 18 Oct 2023 09:30:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A3A28D014D; Wed, 18 Oct 2023 05:30:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 000FB8D014C; Wed, 18 Oct 2023 05:30:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBBE18D014A; Wed, 18 Oct 2023 05:30:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A96228D014C for ; Wed, 18 Oct 2023 05:30:27 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 821731CBEAC for ; Wed, 18 Oct 2023 09:30:27 +0000 (UTC) X-FDA: 81358061694.22.307FFB8 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf02.hostedemail.com (Postfix) with ESMTP id 4B65D80013 for ; Wed, 18 Oct 2023 09:30:24 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.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=1697621425; 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=qu7uzGEbwAgsDRGmzt6Cx98gc/6f+dugQWs0XNrfOZI=; b=6xR7t/XJjR16W3WlyUG3AaOhDLV0+o2OXpddiYy5MbImnayAJVeBsA1GGErQeZ4DXp2RPZ aRliX+CoEKUilD+O5euANWyFKkQpFV45tylfkj1c4EQzbWjEra/fRCTP8bALeBFVPA7YOI sVwRgU01iZyAR8T+REansmxAocO5AeE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697621425; a=rsa-sha256; cv=none; b=PG08XTKyP3lpt+AQvBGLcWP/MpIb6YyYwUt8Bb1oJiP9en4GBTI9Y9mADYQvlNwNslkeQM 4yNz6ZIjwLouFFHMU+So8jO6MQyKeae5iwpAV/ze9tEP9IjO5NoKnofXePsu+6nLxs7H1g xnBjiOsZ07BIriqLcjI7fFt/g5YF0lE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; spf=pass (imf02.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 Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S9QTW6l4szRt63; Wed, 18 Oct 2023 17:26:39 +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, 18 Oct 2023 17:30:19 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton , Kefeng Wang CC: , , Liu Shixin Subject: [PATCH v3 5/7] mm: kmemleak: use mem_pool_free() to free object Date: Wed, 18 Oct 2023 18:29:50 +0800 Message-ID: <20231018102952.3339837-6-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018102952.3339837-1-liushixin2@huawei.com> References: <20231018102952.3339837-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Stat-Signature: d438z5wsbr4dpxiq9g67pwiu71p1gk3n X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 4B65D80013 X-Rspam-User: X-HE-Tag: 1697621424-349813 X-HE-Meta: U2FsdGVkX1+ap+Nyy/CoYAjnINegqJxPLlwSVrMhUrC3/aFxGEyFa1drz0SJt95/71SLPWB49irsfnV8XANBWH45VIntooLD/ivMLnfjLN937vqYljJYWqCGFav6gz5ExE91quFRIc28HvPRNvVQbxMXFTCXjjqyR4oGqPYV8tVb5eM5xezdz6Kby6ujoKcmcnTQfUZb/+A6yileFrXLp3BaUhnTfX60Ywl9W70/3gcNdP/VBKVJMHSryofZoDZUVrsSSDxNrVGlWB5thF6Aw4DI6gKFTxk99xsq+I4aOB9m6abyDTLQQ5As6QJ//IQ2kMt9KEfWJiY9CaTbpm9kmBw+PTjKK1Apb8o8tuYhKiBN6Xd6OzlKsrRozLe2/Lu8QyeoUK6qPw2SR61Tf/inTp59I9EHfaNYhbr/+CUp1oRbcloX2vrGloPwY35S4Jt8f10fD13BsMeU7oAiTsVvIKNa4sKADaGagNPpvzQ1x6l5rFwdY/MGzegIm8XLC4eKK80FUFT4wxsS/3DtnWMdHFWUdqTf7K+s92YZywA2bZp5h0C9KV1R+iJCTcluW66ZATuEINoMcs/3fKmnb3eI825cEbbDD6r4E9IVqAU7Dt87aVxMmPQtXob3hY8jDnp3RC/QPXDpKYrZYH5twtlzd7dK8lzwznxuWihnK8j6zxB5LdHhCU2MXaZubQKpVulLgD//Nm0LUEvneaFKbQDg7pdfS3Hw0eiL6LC/qChhi15Wop/T1vxTOeayW+1gmc9g6Onact6UxN5W+t9ZjrejMwNhsly1RFynLQxN4OtlSG/25d9O2GwC/MtVFJ41yHomP4CaoK/5ovPkIxnSmI4/mrteK5gwNYB2kSd+TCH9RsUCJhaqvUMFj2kAYNLaj9NSu2zw3aLWwrZc70DPqu9Um301X7zJCn5/sJ/atKfgNIWqjtSY1oS0vk1Jd3UtZnZBxSfzCTkdIkkfYyWdBJO TwR2usUP KbcqRA/anvxY+NJX32GOIWjbEZbONbXnOGqACEh4N+9gXcIRe5gLYdhYcML0GaZdhm0YPcRMDJkwH9GbJHs+KHYfJ4BciHyK0gfAog3394CklVTgjkcSd12KEHKFxWd2gbJO2l8L3p/j9ZkJxuIDIeLKZK0KwbUueY95j8Xk0XRkukIAFQPQ3DzhNFopOCj5CW4Uqj7djnuZXG61dJ/VXbjqp0G9JwgzVoAZxI7xT8fps8XwHwYRhcSzJu+KfD00XZf9E6dCw0rAyMHY= 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: The kmemleak object is allocated by mem_pool_alloc(), which could be from slab or mem_pool[], so it's not suitable using __kmem_cache_free() to free the object, use __mem_pool_free() instead. Fixes: 0647398a8c7b ("mm: kmemleak: simple memory allocation pool for kmemleak objects") Signed-off-by: Liu Shixin Reviewed-by: Catalin Marinas --- mm/kmemleak.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 064fc3695c6b..ea34986c02b4 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -668,8 +668,8 @@ static struct kmemleak_object * __alloc_object(gfp_t gfp) return object; } -static void __link_object(struct kmemleak_object *object, unsigned long ptr, - size_t size, int min_count, bool is_phys) +static int __link_object(struct kmemleak_object *object, unsigned long ptr, + size_t size, int min_count, bool is_phys) { struct kmemleak_object *parent; @@ -711,14 +711,15 @@ static void __link_object(struct kmemleak_object *object, unsigned long ptr, * be freed while the kmemleak_lock is held. */ dump_object_info(parent); - kmem_cache_free(object_cache, object); - return; + return -EEXIST; } } rb_link_node(&object->rb_node, rb_parent, link); rb_insert_color(&object->rb_node, is_phys ? &object_phys_tree_root : &object_tree_root); list_add_tail_rcu(&object->object_list, &object_list); + + return 0; } /* @@ -731,14 +732,17 @@ static void __create_object(unsigned long ptr, size_t size, { struct kmemleak_object *object; unsigned long flags; + int ret; object = __alloc_object(gfp); if (!object) return; raw_spin_lock_irqsave(&kmemleak_lock, flags); - __link_object(object, ptr, size, min_count, is_phys); + ret = __link_object(object, ptr, size, min_count, is_phys); raw_spin_unlock_irqrestore(&kmemleak_lock, flags); + if (ret) + mem_pool_free(object); } /* Create kmemleak object which allocated with virtual address. */ From patchwork Wed Oct 18 10:29:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13426728 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 64C77CDB482 for ; Wed, 18 Oct 2023 09:30:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BBEC38D0016; Wed, 18 Oct 2023 05:30:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B04F78D014D; Wed, 18 Oct 2023 05:30:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F06F8D0016; Wed, 18 Oct 2023 05:30: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 626178D014A for ; Wed, 18 Oct 2023 05:30:27 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 343BBB6551 for ; Wed, 18 Oct 2023 09:30:27 +0000 (UTC) X-FDA: 81358061694.29.F8B1A32 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf28.hostedemail.com (Postfix) with ESMTP id 22143C0013 for ; Wed, 18 Oct 2023 09:30:23 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.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=1697621425; 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=m4eEU38Y9BEcrY5VDp3TGJpD23hoCN/TobWRnMlNnFk=; b=0M9Wix/cM72a0wGMXHXkOQgUMQyo0OIyBjSmob1XE1uhrpMjHVHJvHqF/tcemIwQ6gdhMN 4qIrNg0wyghCEYbb5ErocD7eaH0FKEViq4yZ2+CXxSYvDfhSoTN/55EzBRcOAgQLKxZ6N2 6Q3VAiHtnQXpbgFYAIiSZCeaN4KkxCU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697621425; a=rsa-sha256; cv=none; b=1Pmi3OixgNhOZJHwqNTtgY01C7UlHAMTZlaE5w204kyLICnjwHv0MmjM+sRCxby7B6vnRk h3hJwrZq07IHqMp9dD2LmmQ1AK3oUdvndPBYO/HYNr7IiCnd2cPSWtKR4ZuSt9s+LYxlie pafRo+fkoi2X3q5JpY3koOFcHutB9/8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.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.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4S9QVd1WMDzrTTM; Wed, 18 Oct 2023 17:27:37 +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, 18 Oct 2023 17:30:20 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton , Kefeng Wang CC: , , Liu Shixin Subject: [PATCH v3 6/7] mm: kmemleak: add __find_and_remove_object() Date: Wed, 18 Oct 2023 18:29:51 +0800 Message-ID: <20231018102952.3339837-7-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018102952.3339837-1-liushixin2@huawei.com> References: <20231018102952.3339837-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 22143C0013 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: qahxr1kcehxh1cqy6q7y57ysop15ozre X-HE-Tag: 1697621423-342164 X-HE-Meta: U2FsdGVkX19rAw+byI7WAeDmcg1D0wEa5TIK5IDS+j3uTwb88i6viUfJweTSEpcVh11/04sFemsB0+h3QToyjeElO2rBgzemv4qgmCw0wcdCycP61Qn5ejmT9TU9ih6cb2vx8Ygc2rRu2jyT45gPceWbsQM4LGq/TjhbBTmkCSwu+P+3LVQFhSRfLo5wipI437f2qgMkIt6TVOApau8Kh3U1ViYBCSrzuAe7bc5LYkGeXhUkNGW0MmWmI4XrsTjZB58Tilg7BKngBIBWYEik2FW35oj+tPZEEJlkV1hl1xegZTa/Lrbz55TCiAmNgTm+i47/vz/nxKrIwecxuLfkxKe/Wnpf3JQ7gcEEHfrFlrDKxJ89Srm4cbYr4Mt7Ac2hoN5xkh+50nhZ7j6meK0BqFOqjBHpnPKKpdmWG7JFIbnIuxYQ+PgJy5egVYQ/iMzapwKXhsudlwEQZyU0iKTV8sFQwQzGCGx1CIyMwq+7brxs+9W/0OVZZV9aiyilvyTjG8qK4h6RF8FInydQg7IJdZypEdVwOC/Gzb9AXzMe926YfBe2PvNkiOH2Yixly3HgeGPGs2anRS0HH4vxHLfLoOoYDCYPD0RefwignS560I9PzPNjtkoAj3cW5JJgpQIvUeFq/gOkUR1W1pB4ntZfZ6i+1Jb038BP58oCF2cfHw6FJeng4GnS0VMcAz2cPJw9LNGCHbpOcbCsS8I46Kdiawhn//uJ9Y9SplqDUp8qFfQCgzEwsVRxuJsQWhKHSBW+XVQrXwnNo/NG2GrGOOx4Ljst/UxPdzPkAutGYC5D5PpKlTQnkSLlOof3wzoEQ14ooXDOvMBmy4YkAChFqthOUWARf0Nzymx70r+6/7cm8tf9ZY7fqd16YspH7fRn5vcqXXCGWFnlEMGOZ8WAZXWSemwXVM2mOw3gXjGN8aIVqkDC/R0HRveY/zRc/ZhNdGuBndT2sCS4k6zaFtDTJUm 5L6Rr7mS DkBEKg2Qi42XkYNXdpODTOdQwGBA6KcxvUODmnXaqx0mLUTPUewuNqfADGJu5EcBm2At5lvPONGebOt8Qs2EsOU9lPfq7NYB4Bd4SrKmK0U6X04DED1Y6LBnt8xbEutpQSdvng6ww+2fb4l9FL6So3UH2ea275gRHc28unfywVbsbLogzQWT/1u71BjVDKlXqXhGbIv7/ic6WAZi2yxGj4Z/5ZngkdBHl5lx9eQQFJxaWnTiEgeZYlq8YQIpRqjPYRIe4T/nDBC7aQOCD5MGJ6vGCTAOHEcwDJGdKLUBl4YPQQkuzEbYo8kF9KMPozPncVyyIQTIN+gpnuKLXnuF9aNTDiaICTmfrmcNwNuyfYQAFlD4= 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: Add new __find_and_remove_object() without kmemleak_lock protect, it is in preparation for the next patch. Signed-off-by: Liu Shixin Acked-by: Catalin Marinas --- mm/kmemleak.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index ea34986c02b4..7c9125c18956 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -583,6 +583,19 @@ static void __remove_object(struct kmemleak_object *object) object->del_state |= DELSTATE_REMOVED; } +static struct kmemleak_object *__find_and_remove_object(unsigned long ptr, + int alias, + bool is_phys) +{ + struct kmemleak_object *object; + + object = __lookup_object(ptr, alias, is_phys); + if (object) + __remove_object(object); + + return object; +} + /* * Look up an object in the object search tree and remove it from both * object_tree_root (or object_phys_tree_root) and object_list. The @@ -596,9 +609,7 @@ static struct kmemleak_object *find_and_remove_object(unsigned long ptr, int ali struct kmemleak_object *object; raw_spin_lock_irqsave(&kmemleak_lock, flags); - object = __lookup_object(ptr, alias, is_phys); - if (object) - __remove_object(object); + object = __find_and_remove_object(ptr, alias, is_phys); raw_spin_unlock_irqrestore(&kmemleak_lock, flags); return object; From patchwork Wed Oct 18 10:29:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13426732 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 A6387CDB482 for ; Wed, 18 Oct 2023 09:30:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2A888D014A; Wed, 18 Oct 2023 05:30:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8D508D0150; Wed, 18 Oct 2023 05:30:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CA818D014C; Wed, 18 Oct 2023 05:30:28 -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 353438D014A for ; Wed, 18 Oct 2023 05:30:28 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EEAE31401C1 for ; Wed, 18 Oct 2023 09:30:27 +0000 (UTC) X-FDA: 81358061694.23.83B1DAB Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf20.hostedemail.com (Postfix) with ESMTP id 0CA8A1C0013 for ; Wed, 18 Oct 2023 09:30:24 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.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=1697621426; 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=dWbK1w2G5Vt4nI74O+31C3o0eZG9HMj3UWfx2X0Hdbw=; b=nXDv1pK1eZ8iOuRPQh1Zqb6+YZ6tYvgx5k7iFxscMLRO5c2uJfDu2uHzHtSNzF200s+ey0 yhg+7XVwl3qEwFaju5nLMYrapmZTXInbnKAB3rMN69G1V1TlQvdEnE3Ekjro3teCVNBSgT SBm4V+PX+jGMXD/uw087SZhalyE5XHI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.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=1697621426; a=rsa-sha256; cv=none; b=vCCHHDfOH93vEb2nOszQGRxNcVnzIkNmBWQoag02sDQK3dolto4fYQXp50ex7dHytgSePm BmFhZUSfj+CQSfeoV9hdWuDfjqC4tt++NAe/RolYqGYb7PW5jTDrfdsju7c81K2Ccv5yjk AvVjilhmL3eZL5i3jY/azbYrTSL33l4= Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4S9QVf0nMPzrTNn; Wed, 18 Oct 2023 17:27:38 +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, 18 Oct 2023 17:30:20 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton , Kefeng Wang CC: , , Liu Shixin Subject: [PATCH v3 7/7] mm/kmemleak: fix partially freeing unknown object warning Date: Wed, 18 Oct 2023 18:29:52 +0800 Message-ID: <20231018102952.3339837-8-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018102952.3339837-1-liushixin2@huawei.com> References: <20231018102952.3339837-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspam-User: X-Stat-Signature: w5rgdr6czfs633iig3ph3z5fgeozmnbo X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0CA8A1C0013 X-HE-Tag: 1697621424-898974 X-HE-Meta: U2FsdGVkX1/3o1baiXjuq+UyYUAS93BKAM4lXXSq3OTZ3MAP7Mh48/bWhFL0hh93qpjpy+1PfoJskFs/G44kH2jDK6DsLcBWbsK1ikT1mw6mH20gdoN8VU+VtxHXFzq5liRO/rxr9yf4UvBmzkRe0PFQuhbCxjTEMacKrFOQJKjTLEDGpTAHf5nIRMtR8JqX4MZK7JS7P3gsoIKam0dC4kmOqcGYL3s4U/UMtHalVRm5LUcjQzWCx22190+1KfrOPn5OG23aOTIZPBc2icVDoZcDXdagf4ElVqPBaT/rPnwByOVecyz1pNCOOmktQMcD1L6ZG4z4oKvsR0GGIwWsRY7ps26HC6Ru0eSftJsl1LxpEpZdRW23Izih77JTOWDhI9KawA/lh25XAoM4UZkLUFIbtMZw03NLClbB2PwUNT1S39p0mH5qizIrDNEmPT23WHjlK+7mlyV3CPEVRb2owxbyMqIUsx4Hc6jJyx2Joctg90tjkuoE1RfWUmUaMPkmdvxCdT/QbTs2MmXElNBXtdx6svZs4O2VKmruCTXHtFDMRRE5ScZTPirBbdBxi5HA8HpkSTbGa2ED97Nw2YO17hllJpRjOqv//LBRBmzpUH994GS/zbZS2jOI4D5R2Sy7bAoYnrqU6isYNMWz2fT8N5Qx0dahIJ5BP1iCuTpxPmWYlKnulX6RiwX7NrJrJfFVh2w578Lrn54vC+UC358MvGPnJC6fB9e37vmGoCJxfwJWa4csJWSadHy1YUsq2LnLxz+J8eaY9vfw6x8p4O9qB1ZhcAdTrHpMBff3+nglpx5kThdVBqLZrMPVD/5BYRl8W3PaZ0HG/JjFcfJhQvXPlj3Yoaw0LpQ+fsHfjMbzkNJ83Hx2WId76mxtXqPMoM0pAuVPhdRmVAFzbao/lH/10u+xzgbJIsMSieDVacOhHA/L+/2hpq2d2B75drb1F5GHhqVeVqnqrTMcOvqrJcq VWIjJZFz hmyogXwV3frYSfMObdD6ozBijWRcxcsw8n2gDGA7ELsg17cM0J1iJYHM/HwnrNGhtMHlCSlddbNW5EpuiiVx9TX+wGQQcclQdY3JO9OcF/ReukwQVtecXPPUw5I0GhBkqkrRs/jORY2X2p8m1cbXAGYGZkfAH5WIgUmlT/I3KeZ7c5iQTXEq5q2M4fchxzdD3fSS+1GTXz7ZUMie9wRPT+aa8O7aDIkbVsUQlbQ/QfkqPEcG+d3LOr8/fUhiQRs4BReXSFxKWnBYAw29voAmUTcUUKYkoeb45FOl1tBu9ucy8+8CU+z8i2RXC89rkdC0KDEJ18+2WL+/W4yghtRQeMofTpA== 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. It still be recorded by kmemleak even if it has already 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 Expand __create_object() and move __alloc_object() to the beginning. Then use kmemleak_lock to protect __find_and_remove_object() and __link_object() as a whole, which can guarantee all objects are processed sequentialally. Fixes: 53238a60dd4a ("kmemleak: Allow partial freeing of memory blocks") Signed-off-by: Liu Shixin Reviewed-by: Catalin Marinas --- mm/kmemleak.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 7c9125c18956..a956b2734324 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -816,16 +816,25 @@ static void delete_object_full(unsigned long ptr) */ static void delete_object_part(unsigned long ptr, size_t size, bool is_phys) { - struct kmemleak_object *object; - unsigned long start, end; + struct kmemleak_object *object, *object_l, *object_r; + unsigned long start, end, flags; + + object_l = __alloc_object(GFP_KERNEL); + if (!object_l) + return; - object = find_and_remove_object(ptr, 1, is_phys); + object_r = __alloc_object(GFP_KERNEL); + if (!object_r) + goto out; + + raw_spin_lock_irqsave(&kmemleak_lock, 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 - return; + goto unlock; } /* @@ -835,14 +844,25 @@ static void delete_object_part(unsigned long ptr, size_t size, bool is_phys) */ start = object->pointer; end = object->pointer + object->size; - if (ptr > start) - __create_object(start, ptr - start, object->min_count, - GFP_KERNEL, is_phys); - if (ptr + size < end) - __create_object(ptr + size, end - ptr - size, object->min_count, - GFP_KERNEL, is_phys); + if ((ptr > start) && + !__link_object(object_l, start, ptr - start, + object->min_count, is_phys)) + object_l = NULL; + if ((ptr + size < end) && + !__link_object(object_r, ptr + size, end - ptr - size, + object->min_count, is_phys)) + object_r = NULL; + +unlock: + raw_spin_unlock_irqrestore(&kmemleak_lock, flags); + if (object) + __delete_object(object); - __delete_object(object); +out: + if (object_l) + mem_pool_free(object_l); + if (object_r) + mem_pool_free(object_r); } static void __paint_it(struct kmemleak_object *object, int color)