Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6891760rwl; Mon, 9 Jan 2023 14:39:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXsfBkdpdGeTif6UqJwiQtP46YZUFH8X72uoYO/2NX0hsSvq9642cG0deafJF5Z5G0ayqGMN X-Received: by 2002:a17:906:3ac3:b0:844:1d1d:f7 with SMTP id z3-20020a1709063ac300b008441d1d00f7mr50046503ejd.23.1673303962864; Mon, 09 Jan 2023 14:39:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673303962; cv=none; d=google.com; s=arc-20160816; b=TiKBjx2O5y9m2Qke7/+SNHOafTk72GgNRPz0bqhvjdhwKFAT4pFPr0xLMmwmosBaec 22YW4FfzcbGkX594QeveMo/RqKMfB/nrRv2DGU6kS7Ad225wzyegSvfGX0KUxa/1vOa6 Vzyl0/38sa2qJs7sFipoogi2CFHzLcobMo4dnjM1GUqTQTRFYDCtfo/MqGiLCcnhhHJI X8Y0aSZNkvtLHQwuYveeY8cnPGEMOASmu7y/B83WRx9Na5rTl+T3i5KAxTw2Vmv1vOwE CecKM4+ABpgED2/Hnm/PchbYyi01xYZQj0XVJxq6TmMOtKFelxDbgPq6sxfBuniUleJ3 JHVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=y9TFZ1eWP+JIndu1JdgCdrPRh+jAT3LtUVgzdE/rI84=; b=UT1d7e8k7EG9E0cRv9+PxOAHRbfi7EquoA2/CxtXmN8EVNA7ojmsNwn4jKZFgj3oEW /EgwGr7KBFBppVi8/nC7WsWdeoNz7u0ZMVEsGQgsr2dm9FVdSuLGin25yuGK5xU7Z0IL AyiYLQsc/9uWl4Jzi+DSzmzvv2EqJUzJEemG2PSl5DaMcRhKyBWO50++Pg6y5t05R9jp sr/Catt4oAQW2ktfxaTcA5jtlM3+G1pTy+HGvtSgg0foA27Qn8V9RES32I8UumJk+u5w gKM8ECQm6a2GpGGHezg1wI1bIKKmTsJVb0DjQ2e4Sg5qLPr9oWfc3oT+QuS65fPsYqWD nI8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=C0Hc9uF3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs17-20020a170906dc9100b0084c464789adsi11432403ejc.790.2023.01.09.14.39.10; Mon, 09 Jan 2023 14:39:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=C0Hc9uF3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237691AbjAIWQq (ORCPT + 53 others); Mon, 9 Jan 2023 17:16:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231220AbjAIWQh (ORCPT ); Mon, 9 Jan 2023 17:16:37 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F60711C31 for ; Mon, 9 Jan 2023 14:16:37 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-4c57d19de6fso78939577b3.20 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=ZartU+aikrBtyaxMtbqUgV7urohYbrKCpguh4lNlmyimSK615nX0LhpIjElJ1PkScK LABOv/GqQvZjHtnC8Sj/znfXJHXF8Ha8dR79FgsbVktzZM2JJnibjvpAoj4daAc418Zl ZT+Kf9eeHLFBPid5ACrj5xeIpXPVERkoTLJpqzNgYE707qXnMppq1DKE0gxtiU/9+jYp RhQzrx0Zk8CNNopTXYzYO+YypO7tQgHHZb3J5+WhogJcgY4jyVtGAMcM7bcLE+Xx0q48 V3CfvT8kY93jpWnpR3TWNcqhLGvzYEVjfD8dcVgRksfGiqKl3VYPoZCSIKfsA31GWRuf vFkw== X-Gm-Message-State: AFqh2kpMjdiOctfCMqMkQahzyl6xBA+cLL7NIPloxFs3PfyTingsY1xp wdgvvt4g8lPJ4WgWMFgsupbbtDPpxZ4o5E7IRrKEew== 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.39.0.314.g84b9a713c41-goog