From patchwork Sat Jun 11 03:55:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: patrick wang X-Patchwork-Id: 12878334 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 60A71C43334 for ; Sat, 11 Jun 2022 03:58:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EED338D010A; Fri, 10 Jun 2022 23:58:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9C138D00F7; Fri, 10 Jun 2022 23:58:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D15E88D010A; Fri, 10 Jun 2022 23:58:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C36158D00F7 for ; Fri, 10 Jun 2022 23:58:00 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A1EAF188D for ; Sat, 11 Jun 2022 03:58:00 +0000 (UTC) X-FDA: 79564596720.06.0638CD3 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf22.hostedemail.com (Postfix) with ESMTP id 4818DC0080 for ; Sat, 11 Jun 2022 03:57:59 +0000 (UTC) Received: by mail-pl1-f173.google.com with SMTP id i15so825692plr.1 for ; Fri, 10 Jun 2022 20:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BRhMR0ZHYhacS3442LotLCWWOUVPdNCodU10GIEMY0w=; b=Bikr50hWOgc7DNBC6J8V9OgTaGPyggfd5K1DmchOjSSYF/aiVNAoiFOXQNCc9j7oDy rHADQT+de00Tlzb56K4YyRrR4ZP3IsrxnAjP3EnZkD+VQ6ZO2T7T58rSDuQENcujxMLQ eJJ8Fx26CkNaLqLT6vtCgg3tq3u+F7u7XgvGpZe4aTxN+cMM0QHv84F5RPXP1CSd1Mof pfBgR1Yr3F5++iQHpBbaDAmYPzAJf/la/A6bRNAGspLj47QgGKXu60ENvOaL5ut/w4Mr NN/Tw+eHpnfOqM7SicupIzJKw+kh21jNRoL2/ubHzEdO5wXUX9k+QHi4mAupYe6voUs7 PUxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BRhMR0ZHYhacS3442LotLCWWOUVPdNCodU10GIEMY0w=; b=ni/xt7OT//6H34S1elnIp2/2AKv1a+qVNfaRDr5oy/hekU+Qyr5+MKFwbzIz0kM5pe W72V2Pp4vmqwWUiLlb4ADRRepZwLuqTP7EASD4rR3iJQtrfvHsBZC8c0sxGQBaiyDJYS XO+77GDndlXdJw8XzCHp4cvdY5CtmzQ2AUIWkx+TmSQhvqQAfEsvlODPT4NBtNEhg+Pr ho3Mw7khv2rAPugDFkIy7emrkqj3facKjYCg912bwF+anDaB2VEwjTrK1DgOvFGk5oxh 1emC2antDPHmI8HY+qxHniZv5GW9GhOgPYkcNChhHJlCDXnmt+dS4rg+xGOApvgusmU6 CbPg== X-Gm-Message-State: AOAM530Jj2RV8Q6k1uljOXSN5CV7cLYGMWb10Uq08917Hh36hAh7/BRd 0wzcHOoE+ka5p1epFdoCMCw= X-Google-Smtp-Source: ABdhPJzGgybSUKDPG1nlM6xxS/2e+0mjaKFrXr6aIaPH6O/k0r821mFiWjuBLf3vkhd6gImVMWO5Zw== X-Received: by 2002:a17:902:ecca:b0:166:3e34:4d01 with SMTP id a10-20020a170902ecca00b001663e344d01mr46885922plh.97.1654919878399; Fri, 10 Jun 2022 20:57:58 -0700 (PDT) Received: from localhost ([101.86.206.203]) by smtp.gmail.com with ESMTPSA id ct21-20020a056a000f9500b0051c0784cb45sm381671pfb.99.2022.06.10.20.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 20:57:57 -0700 (PDT) From: Patrick Wang To: catalin.marinas@arm.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, yee.lee@mediatek.com, patrick.wang.shcn@gmail.com Subject: [PATCH v4 4/4] mm: kmemleak: check physical address when scan Date: Sat, 11 Jun 2022 11:55:51 +0800 Message-Id: <20220611035551.1823303-5-patrick.wang.shcn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220611035551.1823303-1-patrick.wang.shcn@gmail.com> References: <20220611035551.1823303-1-patrick.wang.shcn@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654919879; a=rsa-sha256; cv=none; b=JswtYulW9pEt5KcPaapFtOgRPRgU5RGrAejsGoPlIa2F6PkxH1uzkJPDkbPSp9Jv02dylG mLQiTlLsj6weZt/+V37I98f5W4EYxdvXpvaPpVd1VBIcI2imeS71YRwYsL33v8XaMSq3/a oy+OVA4hA++NUsIIg4Zu774IAGVJ6BM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Bikr50hW; spf=pass (imf22.hostedemail.com: domain of patrick.wang.shcn@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=patrick.wang.shcn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654919879; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BRhMR0ZHYhacS3442LotLCWWOUVPdNCodU10GIEMY0w=; b=mbJ8KESHziTNuuWP4BARrB93eFjsRvAurs/iDQ8dV18rJh45MwFCoFxzBBEpcKS5Qdludm 9uA7hPjCCS3ic9AmZr8KdHClIwRgo80iJFbcdYpTC5IHcs/lX9xEGPENVHaMKw2zeGFtwi /9mfwFN+swemNrJvHpRrBGmxe6Ym4yA= X-Rspamd-Queue-Id: 4818DC0080 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Bikr50hW; spf=pass (imf22.hostedemail.com: domain of patrick.wang.shcn@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=patrick.wang.shcn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: 7be86as4e1o8nr54939kg1k6oxq8iq1h X-HE-Tag: 1654919879-905118 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: Check the physical address of objects for its boundary when scan instead of in kmemleak_*_phys(). Fixes: 23c2d497de21 ("mm: kmemleak: take a full lowmem check in kmemleak_*_phys()") Suggested-by: Catalin Marinas Signed-off-by: Patrick Wang Reviewed-by: Catalin Marinas --- mm/kmemleak.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 155f50e1a604..387d6fa402c6 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1184,7 +1184,7 @@ void __ref kmemleak_alloc_phys(phys_addr_t phys, size_t size, gfp_t gfp) { pr_debug("%s(0x%pa, %zu)\n", __func__, &phys, size); - if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn) + if (kmemleak_enabled) /* * Create object with OBJECT_PHYS flag and * assume min_count 0. @@ -1204,7 +1204,7 @@ void __ref kmemleak_free_part_phys(phys_addr_t phys, size_t size) { pr_debug("%s(0x%pa)\n", __func__, &phys); - if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn) + if (kmemleak_enabled) delete_object_part((unsigned long)phys, size, true); } EXPORT_SYMBOL(kmemleak_free_part_phys); @@ -1218,7 +1218,7 @@ void __ref kmemleak_ignore_phys(phys_addr_t phys) { pr_debug("%s(0x%pa)\n", __func__, &phys); - if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn) + if (kmemleak_enabled) make_black_object((unsigned long)phys, true); } EXPORT_SYMBOL(kmemleak_ignore_phys); @@ -1493,6 +1493,17 @@ static void kmemleak_scan(void) dump_object_info(object); } #endif + + /* ignore objects outside lowmem (paint them black) */ + if ((object->flags & OBJECT_PHYS) && + !(object->flags & OBJECT_NO_SCAN)) { + unsigned long phys = 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))