From patchwork Fri Jun 3 03:54:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: patrick wang X-Patchwork-Id: 12868487 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 032A4C43334 for ; Fri, 3 Jun 2022 03:54:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95FE46B0078; Thu, 2 Jun 2022 23:54:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 90BCD6B007B; Thu, 2 Jun 2022 23:54:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D5106B007D; Thu, 2 Jun 2022 23:54:36 -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 6DEE06B0078 for ; Thu, 2 Jun 2022 23:54:36 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 4AF89120544 for ; Fri, 3 Jun 2022 03:54:36 +0000 (UTC) X-FDA: 79535557752.29.127B95B Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf17.hostedemail.com (Postfix) with ESMTP id D96AB40028 for ; Fri, 3 Jun 2022 03:53:58 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id v11-20020a17090a4ecb00b001e2c5b837ccso11140856pjl.3 for ; Thu, 02 Jun 2022 20:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gDxq5rt5EfBvQEGX/JbF39Xsu3MLwHYHF4domviF5Aw=; b=ZcAWiVl5MNXHqF9gqoBMhVMeSBj8YV7gkiqwngFfitNG69DQnL05R75t16nEkhz4EG Qf5CF1hphATAOuY2icg7qLXEdZ1jq64mvXSbGdqtF2l1Zk9Xfe/lrOvmgA+i4d9RC8ba m+zdi3W3znACUwxWTUhycqt5Jcl0SO3JvTBq/F08392xPXx29tUknHvi/AC0bvpCVDZ5 zRuCBlExCz83+x29q8fnoTokJShnTZbCUVYjdO7/SgFwlZKawpOP7bcDiQ6R/8qwX9Zo Qr6EyW7MdBZj+2wK0qqxR3ZGmJNc604K8EqLHvXLztZk+PYSx3SWFkbr5Sjy6XMMu7sT ehfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gDxq5rt5EfBvQEGX/JbF39Xsu3MLwHYHF4domviF5Aw=; b=HkhWXXV8NCCaIjsL7sowQ1ap5KU6Q7A4xVZl4BABRlMl2xl4JvwMPeybHx7HdPd2X9 Nr2UXBXU8HSJ2+ygKV59eZvPifLE/Q4V2HDg0Vfc2AWzODZK5Cp1Cw/io/jtGdgyHtuJ JsAMvIflEIEB+96NJX3qdHsUuBzpX+JxDOJNJHCp0fPeJJTyxeBPNSvnDfkt1t4rMhtW 9O8Fd6F/34ewHEAFqHtyhFAgOYvRMz9dK5DoJjW7pYnhnjp7R1O1kjXdo6M/NHZ6JC2Z WHPfLy3nF+RMItwfjIoZePK0O5CvvrOuKcZQ0ZGApLh2bC7iwfcwyLDH9NmeXSvJksAc 8qlQ== X-Gm-Message-State: AOAM530INVk6f2UZr12jHh9Cbkbefgs00eZdguCoP3oU/AyonKHyhLsT MpdfDKyp5kKqeIExv6scvbs= X-Google-Smtp-Source: ABdhPJyakeYteI7Y7hTx45KhYNBoAbLV1IEg+M8GI7pdT6/wyhfrtWQm941y/qg3ytvpVGlkGNVsTw== X-Received: by 2002:a17:903:120f:b0:15f:99f:9597 with SMTP id l15-20020a170903120f00b0015f099f9597mr8133275plh.45.1654228475075; Thu, 02 Jun 2022 20:54:35 -0700 (PDT) Received: from localhost ([101.86.206.159]) by smtp.gmail.com with ESMTPSA id a4-20020a1709027e4400b00163ac8673edsm4274072pln.35.2022.06.02.20.54.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 20:54:34 -0700 (PDT) From: Patrick Wang To: catalin.marinas@arm.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, yee.lee@mediatek.com, patrick.wang.shcn@gmail.com Subject: [PATCH v2 4/4] mm: kmemleak: kmemleak_*_phys() set address type and check PA when scan Date: Fri, 3 Jun 2022 11:54:15 +0800 Message-Id: <20220603035415.1243913-5-patrick.wang.shcn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220603035415.1243913-1-patrick.wang.shcn@gmail.com> References: <20220603035415.1243913-1-patrick.wang.shcn@gmail.com> MIME-Version: 1.0 X-Stat-Signature: aja46hxph141so45qghb66zsh6hyr7tw Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ZcAWiVl5; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of patrick.wang.shcn@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=patrick.wang.shcn@gmail.com X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: D96AB40028 X-HE-Tag: 1654228438-202007 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_*_phys() functions call next level interface by setting address type to physical. And the physical address of objects will be checked for its boundary when scan instead of in kmemleak_*_phys(). Suggested-by: Catalin Marinas Signed-off-by: Patrick Wang --- mm/kmemleak.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 246a70b7218f..62d1ad8f8a44 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1156,8 +1156,12 @@ EXPORT_SYMBOL(kmemleak_no_scan); void __ref kmemleak_alloc_phys(phys_addr_t phys, size_t size, int min_count, gfp_t gfp) { - if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn) - kmemleak_alloc(__va(phys), size, min_count, gfp); + pr_debug("%s(0x%pa, %zu, %d)\n", __func__, &phys, size, min_count); + + if (kmemleak_enabled && !min_count) + /* create object with OBJECT_PHYS flag */ + create_object((unsigned long)phys, size, min_count, + gfp, true); } EXPORT_SYMBOL(kmemleak_alloc_phys); @@ -1170,8 +1174,10 @@ EXPORT_SYMBOL(kmemleak_alloc_phys); */ void __ref kmemleak_free_part_phys(phys_addr_t phys, size_t size) { - if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn) - kmemleak_free_part(__va(phys), size); + pr_debug("%s(0x%pa)\n", __func__, &phys); + + if (kmemleak_enabled) + delete_object_part((unsigned long)phys, size, true); } EXPORT_SYMBOL(kmemleak_free_part_phys); @@ -1182,8 +1188,10 @@ EXPORT_SYMBOL(kmemleak_free_part_phys); */ void __ref kmemleak_not_leak_phys(phys_addr_t phys) { - if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn) - kmemleak_not_leak(__va(phys)); + pr_debug("%s(0x%pa)\n", __func__, &phys); + + if (kmemleak_enabled) + make_gray_object((unsigned long)phys, true); } EXPORT_SYMBOL(kmemleak_not_leak_phys); @@ -1194,8 +1202,10 @@ EXPORT_SYMBOL(kmemleak_not_leak_phys); */ void __ref kmemleak_ignore_phys(phys_addr_t phys) { - if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn) - kmemleak_ignore(__va(phys)); + pr_debug("%s(0x%pa)\n", __func__, &phys); + + if (kmemleak_enabled) + make_black_object((unsigned long)phys, true); } EXPORT_SYMBOL(kmemleak_ignore_phys); @@ -1468,6 +1478,17 @@ static void kmemleak_scan(void) dump_object_info(object); } #endif + + /* ignore objects outside lowmem (paint them black) */ + if ((object->flags & OBJECT_PHYS) && + !(object->flags & OBJECT_NO_SCAN)) { + unsigned long phys = object->pointer; + + if (PHYS_PFN(phys) < min_low_pfn || + PHYS_PFN(phys + object->size) >= max_low_pfn) + __paint_it(object, KMEMLEAK_BLACK); + } + /* reset the reference count (whiten the object) */ object->count = 0; if (color_gray(object) && get_object(object))