From patchwork Thu Jun 9 12:49:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: patrick wang X-Patchwork-Id: 12875549 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 779CBCCA473 for ; Thu, 9 Jun 2022 12:51:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEB0A8D0019; Thu, 9 Jun 2022 08:51:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D9B5E8D0015; Thu, 9 Jun 2022 08:51:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3BE28D0019; Thu, 9 Jun 2022 08:51:05 -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 B42EB8D0015 for ; Thu, 9 Jun 2022 08:51:05 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9500135843 for ; Thu, 9 Jun 2022 12:51:05 +0000 (UTC) X-FDA: 79558682490.06.0965A96 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf24.hostedemail.com (Postfix) with ESMTP id EF1EF180070 for ; Thu, 9 Jun 2022 12:51:04 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id 184so5793315pga.12 for ; Thu, 09 Jun 2022 05:51:04 -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=KwSRcViehwfAYeRTO3icyIMXkIxuHW5eq5bOlxud59g=; b=NOqJF7S/WByS4u665bimD3BKbv7ahHS1l6RPUqD0TU5ms64qlM4kF5yV7KJC89nNHv a17tntzu44cTUIoP8sSPb6j87kVUhI/unLOiNJNhaNEwSlOy/1wkKEwuGoFp20WZ6Eeh rRbbhfDIC5738q4r1eRNRkWTD1pmIwbvuv7zZGApID/OoUv7fr+jIwIoVwIFa19T6U2U Fxfpm7umKjzBN7pyUYtp2+7NdwJ/axPsWaCm6tA//usReZMhlnpEtOeCE1hiolMUKL64 D7uSlc3ofD5f6FnlZZTkZH8+mxYZiXrURz6eEM3Y9p7ATd+yBSQ57nLxaMv2skT8IT6o Ftxg== 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=KwSRcViehwfAYeRTO3icyIMXkIxuHW5eq5bOlxud59g=; b=KUK9smDoZO069/ewVZlkrRjSO3mui2wvRszq0mRV1/j/mI8XaHiL/26EkYVX5Jenvb uWAHLMUgsJj9+oQ3dJ1dg2mnzazu49JubDqlgWlzCn20Z3ArdVDtZRTzaJ9BZk2m1w5G q0abVaFCuyug/BLaSUl1sKHujgamsdi5o2BZzl9bvIXoOQEDLcP+PYX98HbxIyBiK0R+ itdNQV7gUS76hSA6ggNpp4N6xzcwOlBPRflcFhWkq/G/gIW8FTx1by7uscvzZaNjdLR8 I3x4jcjpWmLsIsAuMx0KcRyPbfe5O2v/ROiXIB1BXDn0dAXG/nm7l2dk0uVvl3JOJKdQ wVTg== X-Gm-Message-State: AOAM530GEbbugxd2i+W3W0mROYXbj8m/lOdIvuvSAXKkajk9sy2jzTbb 7879nuUX/yyWl40NwjMOPoo= X-Google-Smtp-Source: ABdhPJwKD7D9ZF1N62MeDGI5N2JXZ4WpXk3reHXe99z40A6BXMvU8ygtsV1HC2LEIcBh9MHFwuZQTw== X-Received: by 2002:a63:82c6:0:b0:3fe:3600:f816 with SMTP id w189-20020a6382c6000000b003fe3600f816mr7343707pgd.155.1654779064103; Thu, 09 Jun 2022 05:51:04 -0700 (PDT) Received: from localhost ([101.86.206.203]) by smtp.gmail.com with ESMTPSA id a190-20020a6390c7000000b003c62fa02f08sm17294112pge.43.2022.06.09.05.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jun 2022 05:51:03 -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 v3 3/3] mm: kmemleak: check physical address when scan Date: Thu, 9 Jun 2022 20:49:50 +0800 Message-Id: <20220609124950.1694394-4-patrick.wang.shcn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220609124950.1694394-1-patrick.wang.shcn@gmail.com> References: <20220609124950.1694394-1-patrick.wang.shcn@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654779065; a=rsa-sha256; cv=none; b=gjDRBi5IkQEC4XOx8clHgUeea2a6e69TFtipNa5mkuY8gF9FyoHZq5P2IWGvkb5SozqbEm vAVfiMN97NPAC4zK+qrf9/pHHUNTXFxdVEA38kNNx7t/EMT4MQmx2DCWU3L7yadu/jhCcG ryBMzDl0VDNZhhOoyqKvLdQYcABAH5Q= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="NOqJF7S/"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of patrick.wang.shcn@gmail.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=patrick.wang.shcn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654779065; 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=KwSRcViehwfAYeRTO3icyIMXkIxuHW5eq5bOlxud59g=; b=k6yWPhcRTYpkF6kTm4URz73RSanufRqNfC3flrXHENvjhVLW+wLFfCtyMn6f7+dwPZf5K3 335MI2wY/jO5FBn7Ub5V/Gvwt7bHMdoMU/Y2tzauQzM0YoWoZB7HMDXLo39p04Mm5BLbfV TzfoGl3tSNu4T750csrZqMZAlgfHoTM= X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: EF1EF180070 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="NOqJF7S/"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of patrick.wang.shcn@gmail.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=patrick.wang.shcn@gmail.com X-Stat-Signature: b4qqz5jyd3huesnwhe45qfq6he68fct7 X-HE-Tag: 1654779064-203032 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))