From patchwork Mon Jan 9 22:16:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Manjarres X-Patchwork-Id: 13094427 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 AB69CC54EBD for ; Mon, 9 Jan 2023 22:16:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C835900003; Mon, 9 Jan 2023 17:16:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 47879900002; Mon, 9 Jan 2023 17:16:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34033900003; Mon, 9 Jan 2023 17:16:39 -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 27471900002 for ; Mon, 9 Jan 2023 17:16:39 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 014641612DB for ; Mon, 9 Jan 2023 22:16:38 +0000 (UTC) X-FDA: 80336670918.11.1E3C049 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf02.hostedemail.com (Postfix) with ESMTP id 62D238000A for ; Mon, 9 Jan 2023 22:16:37 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=C0Hc9uF3; spf=pass (imf02.hostedemail.com: domain of 3RJK8Yw4KCH8lvddfpdqmduuhvjrrjoh.frpolqx0-ppnydfn.ruj@flex--isaacmanjarres.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3RJK8Yw4KCH8lvddfpdqmduuhvjrrjoh.frpolqx0-ppnydfn.ruj@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=1673302597; 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=y9TFZ1eWP+JIndu1JdgCdrPRh+jAT3LtUVgzdE/rI84=; b=nqN9FopGKA1Zc+WkQOiwF9ob+ApJwAoQIYlvAqGLqSCegFJQTpuQSojK9PiDDYgNJXJhho /EeWV4c/HBOUBN+gx/c4oKjU4cDES9VBWtccBr3mmgGQ++7LfL/n1LSqwQE7y3uS673HaB mF2PZl+qv0diGwQqezEnU95egKwh5N0= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=C0Hc9uF3; spf=pass (imf02.hostedemail.com: domain of 3RJK8Yw4KCH8lvddfpdqmduuhvjrrjoh.frpolqx0-ppnydfn.ruj@flex--isaacmanjarres.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3RJK8Yw4KCH8lvddfpdqmduuhvjrrjoh.frpolqx0-ppnydfn.ruj@flex--isaacmanjarres.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673302597; a=rsa-sha256; cv=none; b=dzUp6KIjfNkKwHzKC3s+IfgyDRSGl6AAHoLsdrS5ye/jsnAgRHs00XqnsPbQjIKEe2jj4x hBKDSzRiP7/vAlxFidHVshHlrOIhYxQMV9bux8RISBtK5/hB23b5KDBdBpNRK+xg2momrm n5SsxYne/C/eWbB4gsJGd3EomSj2LkQ= Received: by mail-yb1-f201.google.com with SMTP id e12-20020a25500c000000b007b48c520262so10552748ybb.14 for ; Mon, 09 Jan 2023 14:16:37 -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=y9TFZ1eWP+JIndu1JdgCdrPRh+jAT3LtUVgzdE/rI84=; b=C0Hc9uF3im6Ys2/s/4e6nNvgxvlythCwW8m17GdXHrOqWQ9yn0iW0LTZyj+MdItAEY iybja8FN1XyhoSwQX36EF+9wSfenpbb6LvJn2ASIr9ARjPf3bBYDEf0TmC1ADROKbIzA uqBW5UJwXEglstUm+YQchdmDfMIzIajQqCXdq5tXej2n/om0MByQQj7QiCcAlkoHzW+f 0EvQf8SiwDxeGivZRKBfCGtD95VHgBTkc0pBRfvgB/JhWJIan9MB+IxMjhlK+NPhAWfg dNKLyThxKdiUaJhH8Ndfdtdxjx9wWLvlbjqkUFmWXQ0tbaB5ICv8vHAarsuXw/gDkqnj gHfA== 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=y9TFZ1eWP+JIndu1JdgCdrPRh+jAT3LtUVgzdE/rI84=; b=0wtmUL8Ep+tMeiwTEZisfKbrKz5fKnUgDuS02HDOWAWoe1MLxT1NO+Dj2aq0RPCEPq yAAB5PPG6fU+JaSzKbXVYfsdgiHWnCAlg7Z3gnylaYn7evdMFAiqwOIc8l+35ZYhrGF1 Mgnr3oyHyZp9wvxMoEqiuhNNrjDI5J1k1SOGbJ/GvqnDH6s3jNrEP3By39MMR+KPV1Wz kNAzdF52bhRny2ZlamRwLLwXGBIv4a5YTmxskg9iRhO9xprXC22iFxCrxA7r3D0wLOzt A3ncn/FuJruQXygoTgtnTDhtm/kLjGIrHWjhszKHQg3V4GchRJwG0YnNooa+d6LGi+W7 d9yQ== X-Gm-Message-State: AFqh2kpbYbGsSJIWbpC3YpGsUiW9SuEUHteCmqVlpLODBojQrr+7NYEV k80AZbkjn7WH+vPWTdZSiPqkLaLgqQ9MStzOt5dlQw== X-Google-Smtp-Source: AMrXdXvHobRDwuXj4MA5OcW3NVM1spLgSqNMAAiW4GhwomXZXFwO2kaU1GbMWchPaX3UjiQoZHyyjBmkbD8YjhmyaldVbQ== X-Received: from isaacmanjarres.irv.corp.google.com ([2620:15c:2d:3:3990:5e50:b0f8:bcdd]) (user=isaacmanjarres job=sendgmr) by 2002:a05:690c:b08:b0:469:28df:b2c2 with SMTP id cj8-20020a05690c0b0800b0046928dfb2c2mr1656471ywb.122.1673302596557; Mon, 09 Jan 2023 14:16:36 -0800 (PST) Date: Mon, 9 Jan 2023 14:16:23 -0800 In-Reply-To: <20230109221624.592315-1-isaacmanjarres@google.com> Mime-Version: 1.0 References: <20230109221624.592315-1-isaacmanjarres@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230109221624.592315-3-isaacmanjarres@google.com> Subject: [PATCH v1 2/2] mm/cma.c: Delete kmemleak objects when freeing CMA areas to buddy at boot From: "Isaac J. Manjarres" To: Andrew Morton Cc: Saravana Kannan , Suren Baghdasaryan , "Isaac J. Manjarres" , kernel-team@android.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 62D238000A X-Stat-Signature: fjiefxpbs98pmfttbmmr7tmwx887jt3x X-HE-Tag: 1673302597-100266 X-HE-Meta: U2FsdGVkX1+nCZ78I/nje6iKDBWYEIph6PbjUvghS3E4Irwa+hxmVFZpi9AMdNVjpP85RilwE/ofjDpVgPipswMSsAIlKqTZ4zNAhJ1ShiX/K2BmpOTnhHKKF9ip662ZqsWZUTA0IqhfRyK/mkVg3xMhUhfZFp3Je5AgV3UIcMslY5Ph/QporXvW42ZHTSuuUlORJtaj9Dj4kKY3hLxsOs3JYxZGoGiSTcOukW9HZ0UYgnBuGk9ouRvhsnGXkGuB90XhQ3vtviJrfkWSUobUzzV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xbsmJyfvFzd8J76JAMwR3XJsduubJY0OKX51yh34MQxLzWBAlapY8+I= 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 every CMA region is now tracked by kmemleak at the time cma_activate_area() is invoked, and cma_activate_area() is called for each CMA region, invoke kmemleak_free_part_phys() during cma_activate_area() to inform kmemleak that the CMA region will be freed. Doing so also removes the need to invoke kmemleak_ignore_phys() when the global CMA region is being created, as the kmemleak object for it will be deleted. This helps resolve a crash when kmemleak and CONFIG_DEBUG_PAGEALLOC are both enabled, since CONFIG_DEBUG_PAGEALLOC causes the CMA region to be unmapped from the kernel's address space when the pages are freed to buddy. Without this patch, kmemleak will attempt to scan the CMA regions, even though they are unmapped, which leads to a page-fault. Cc: stable@vger.kernel.org Signed-off-by: Isaac J. Manjarres --- mm/cma.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index 674b7fdd563e..dd25b095d9ca 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -102,6 +102,13 @@ static void __init cma_activate_area(struct cma *cma) if (!cma->bitmap) goto out_error; + /* + * The CMA region was marked as allocated by kmemleak when it was either + * dynamically allocated or statically reserved. In any case, + * inform kmemleak that the region is about to be freed to the page allocator. + */ + kmemleak_free_part_phys(cma_get_base(cma), cma_get_size(cma)); + /* * alloc_contig_range() requires the pfn range specified to be in the * same zone. Simplify by forcing the entire CMA resv range to be in the @@ -361,11 +368,6 @@ int __init cma_declare_contiguous_nid(phys_addr_t base, } } - /* - * kmemleak scans/reads tracked objects for pointers to other - * objects but this address isn't mapped and accessible - */ - kmemleak_ignore_phys(addr); base = addr; }