From patchwork Wed Feb 8 23:20:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Manjarres X-Patchwork-Id: 13133779 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 87073C636D3 for ; Wed, 8 Feb 2023 23:20:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DF4C6B0074; Wed, 8 Feb 2023 18:20:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 08FA76B0075; Wed, 8 Feb 2023 18:20:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E98F76B0078; Wed, 8 Feb 2023 18:20:11 -0500 (EST) 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 DA9A16B0074 for ; Wed, 8 Feb 2023 18:20:11 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BCE2A1C6757 for ; Wed, 8 Feb 2023 23:20:11 +0000 (UTC) X-FDA: 80445695022.16.23826E3 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf18.hostedemail.com (Postfix) with ESMTP id 0B69E1C000F for ; Wed, 8 Feb 2023 23:20:09 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=BOhMexM+; spf=pass (imf18.hostedemail.com: domain of 3KS7kYw4KCDwgqYYakYlhYppcqemmejc.amkjglsv-kkitYai.mpe@flex--isaacmanjarres.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3KS7kYw4KCDwgqYYakYlhYppcqemmejc.amkjglsv-kkitYai.mpe@flex--isaacmanjarres.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675898410; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SCoda6GVlJUCMEgaP5lPaK+3ESTiE3x/X85Mx974aXU=; b=n4J2FhcVMleinTjaoX6a8w532RKSkpfr1ERFTmb3bDtRiFLW6Luf9BPmj8XP/alWQjvzkI 1f24AwLQyAv5k+wVQPI1bSLi9hV9AMJmspLW56sfyu6F8VVLBZpSjgt0TKLLb4TAFppZQ5 wG6Z4pZbY9OIw4/40m9qSKo2c+q8Sgk= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=BOhMexM+; spf=pass (imf18.hostedemail.com: domain of 3KS7kYw4KCDwgqYYakYlhYppcqemmejc.amkjglsv-kkitYai.mpe@flex--isaacmanjarres.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3KS7kYw4KCDwgqYYakYlhYppcqemmejc.amkjglsv-kkitYai.mpe@flex--isaacmanjarres.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675898410; a=rsa-sha256; cv=none; b=yGOt/mODy5wA4Q8rEnBJqulXnEDBR7ffTUu5j2yNbrGp1ehmynDUPggRhb/Vc3a99ciV3W YAZM/fkktOZ2HxnFHtZWfX3U+n0Qk8C3nuy9M/ZzyQl7WzHpRCPnFlX5UqQk0ObjNbn0C+ WjlkjVnEvMsAJzqsnAcqNmxh529q/qE= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-527501b56ffso1970387b3.15 for ; Wed, 08 Feb 2023 15:20:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SCoda6GVlJUCMEgaP5lPaK+3ESTiE3x/X85Mx974aXU=; b=BOhMexM+VCdHXQh/QVZbzJHyumhrxhqyTt2CuvMH7lTp68/z+gaP3Wu9xOqUmMi+JB mrrdzAIQS5IgMvvLESeevC/Ab3TlUwMbewpdRZ/zUx0Y82FQXKYzOeTxkST4GZDbMs54 bdNJm//D6to89ZuTxojonQAVWRuv9Z7ksH+y2Fkng+GggZovQ2CXp0Y+ob3G7vpvkpA+ DrNYqfDijWuCk8YdtgwZLUAXZiEqzXoPKXNelEj9fobF8XJ5dYblWPSyuKdeL0KI17O4 zb1jvbx9k1b9/14wdpulwjMcLCrsI5irymeM9A3/uL7UAA8qiFOsUvys67q2yh38HKl1 cHUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SCoda6GVlJUCMEgaP5lPaK+3ESTiE3x/X85Mx974aXU=; b=CeH9063G36Ya8exXydY8286oUeIBD+4f4ToXo/zMLPcMrRiFGSX7qCXgvDZ6bHro44 fu7CyS/s7gGEdTR/K5lZqL41bah9TRblF5svi4j6PY71yQ0hVLtRABrfxkoWed/XoVeE oKqf4EtX+NnbpUPDveKCk9UPUAOL2D69dUIkVZE+IOcVZcSZ0gze9da3G+3DltG+Dh96 lX7gZiwAoY/3yBN+LRsQCyQX5zZJn5nnXoCj7JMIFSCduZAWETmyRjnmwyyfttZqOxRN b2Cz8F4PjFR7D04SC45cjXYU1ukJINxovbcOA8UDZobq2VeaC1ij4KBBLDvlklfGQwnB w8aQ== X-Gm-Message-State: AO0yUKUCSmRmjXbS83mR9SXzgo2z5EboZib2akPBD92Rn25uDGjPBcW7 qF/6zoIGkyDAt1aN7r1SgtFRlIR9JfJzvL20qbt1aA== X-Google-Smtp-Source: AK7set/42Lq6W0kYDD0CkT7h1nmhW62J2WaSTP+TeY8dH0u9K20cQW4TZ3bI5L0bGpIY9ILamFJb+DNqD2WEeUFn24UATA== X-Received: from isaacmanjarres.irv.corp.google.com ([2620:15c:2d:3:32e8:a89:521e:3f2e]) (user=isaacmanjarres job=sendgmr) by 2002:a05:6902:101:b0:893:5f24:71b0 with SMTP id o1-20020a056902010100b008935f2471b0mr1029072ybh.163.1675898409119; Wed, 08 Feb 2023 15:20:09 -0800 (PST) Date: Wed, 8 Feb 2023 15:20:00 -0800 In-Reply-To: <20230208232001.2052777-1-isaacmanjarres@google.com> Mime-Version: 1.0 References: <20230208232001.2052777-1-isaacmanjarres@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230208232001.2052777-2-isaacmanjarres@google.com> Subject: [PATCH v2 1/1] of: reserved_mem: Have kmemleak ignore dynamically allocated reserved mem From: "Isaac J. Manjarres" To: Rob Herring , Frank Rowand , "Russell King (Oracle)" , Mike Rapoport , "Kirill A. Shutemov" , Nick Kossifidis , Catalin Marinas , Andrew Morton Cc: Saravana Kannan , linux-mm@kvack.org, "Isaac J. Manjarres" , kernel-team@android.com, "Rafael J. Wysocki" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Rob Herring X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: mdxpwcpzncgi7trp4hbo16easqixr1aj X-Rspamd-Queue-Id: 0B69E1C000F X-HE-Tag: 1675898409-567224 X-HE-Meta: U2FsdGVkX1+pLxAsbtCsYQ+gQMN6CFQ++0pw0MW9D1/tdcBooSiSlxKkpZviCoutPK5QNMQl9nIKyhtsvOed9JEOddpQgaadHm6tXvjIAEstWxPAGYz/+u3EmDCy1X9XG22rMtRKYQVQMrdnorJNfq0bK5NgTDpU1Bpk1TYvAniunnTEsjkPoxZaccIyI0Vjx18AAFroAmnpvH48FaZ0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ehj5TUjDC1Jt8oAwTmfePq8Lvyvb+EE4WNgJwshJsTweKU2/vkDXy3IVbzteQ0qNEMIMsuZ0S4MSCqluug/7PH1yw7A1ecIpn20ucjtOs68sHoQ+pt7+sOXiu5LcmkPBjFgXyEala2WWv9TYae5nc/p6TmIk3UucOL4RubkuEW+NgPyZycyDsUe+HUKAV5yCgIELC+vqa8/v4Mll5gUDYWNKzNLp/wCVDjdvSzUxMzxP7OUCwHcg1B0InpOLqgCWkB3+1Shq0K6IMnMNkFEUmjyavyHxjdAiJu1vok+9egUQOKGd5ZQBWJDHyzN3I3X9hw0VL8XGDTAZMiWNcdkCHzMgbflKjv7I65Ko9II877NQuHTk7ZiJsnvRGroWgIbC5z+YO5bOKQI9FKdbwbMBkdybOHCsOpM8YaNGnfscUbp8T7EX00OLzpr/lrmF0hdNY9L8mO+3uP7b6NcvlghrwSCSBf2/SLHWqjig2w6yfsDpYkuOU9xJLjRMGJ1MOAV4Em1NFHRBajXp6oO1Vkqn9AXPPXbN4CUtFaVlmV4kWLQe0o+JTCz/6EqdCg3/uq44oXn+Kxw== 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: Currently, kmemleak ignores dynamically allocated reserved memory regions that don't have a kernel mapping. However, regions that do retain a kernel mapping (e.g. CMA regions) do get scanned by kmemleak. This is not ideal for two reasons: 1. kmemleak works by scanning memory regions for pointers to allocated objects to determine if those objects have been leaked or not. However, reserved memory regions can be used between drivers and peripherals for DMA transfers, and thus, would not contain pointers to allocated objects, making it unnecessary for kmemleak to scan these reserved memory regions. 2. When CONFIG_DEBUG_PAGEALLOC is enabled, along with kmemleak, the CMA reserved memory regions are unmapped from the kernel's address space when they are freed to buddy at boot. These CMA reserved regions are still tracked by kmemleak, however, and when kmemleak attempts to scan them, a crash will happen, as accessing the CMA region will result in a page-fault, since the regions are unmapped. Thus, use kmemleak_ignore_phys() for all dynamically allocated reserved memory regions, instead of those that do not have a kernel mapping associated with them. Cc: # 5.15+ Fixes: a7259df76702 ("memblock: make memblock_find_in_range method private") Signed-off-by: Isaac J. Manjarres Acked-by: Mike Rapoport (IBM) Acked-by: Catalin Marinas --- drivers/of/of_reserved_mem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 65f3b02a0e4e..f90975e00446 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -48,9 +48,10 @@ static int __init early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, err = memblock_mark_nomap(base, size); if (err) memblock_phys_free(base, size); - kmemleak_ignore_phys(base); } + kmemleak_ignore_phys(base); + return err; }