From mboxrd@z Thu Jan 1 00:00:00 1970 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 543A8C54E94 for ; Tue, 24 Jan 2023 15:49:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90AC16B0071; Tue, 24 Jan 2023 10:49:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BB436B0072; Tue, 24 Jan 2023 10:49:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AAC26B0073; Tue, 24 Jan 2023 10:49:07 -0500 (EST) 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 6E3CB6B0071 for ; Tue, 24 Jan 2023 10:49:07 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3D1CE1C6396 for ; Tue, 24 Jan 2023 15:49:07 +0000 (UTC) X-FDA: 80390126334.27.207FB3A Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf01.hostedemail.com (Postfix) with ESMTP id 7CC7440018 for ; Tue, 24 Jan 2023 15:49:04 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674575345; a=rsa-sha256; cv=none; b=EVzc7iGxwVFVGg02CEV3/J8DctUKUU+IreYKfuaditIcpamHuSdtrZ3r5wQWju+QxMlqSZ nufnMLg1bbdMW8iEDt1RUDk8c/HwmXeYFZEdIBr3e+aqWbEGedx7AYULbTtcKmyRoCDYFi D58flYoW2++s6lIHDxw+0Hz2Kh6qwsw= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674575345; 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; bh=kezbMli3R7ZlsufN0vrdKZYr5o8Q7c9fBLX36x2oGj4=; b=T79m7EzfuqiT3CvRHPQLlpZoh8biK52i6x9+ga5P0PHOQpSL/RbVUT+T5lPmFIpNOSfZ4Y qqFyl3n0SFbQOREjF5P0yj90EL6zIfCDlCyJgodgnC6FYnNnb6nAAooXXZONuEet8CI7X8 lhl5kxVjnYRis8fPsJekZMZP8JFX98Y= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6A6BAB8129F; Tue, 24 Jan 2023 15:49:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B23FAC433EF; Tue, 24 Jan 2023 15:49:00 +0000 (UTC) Date: Tue, 24 Jan 2023 15:48:57 +0000 From: Catalin Marinas To: Isaac Manjarres Cc: Andrew Morton , Saravana Kannan , Suren Baghdasaryan , kernel-team@android.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 0/2] Fixes for kmemleak tracking with CMA regions Message-ID: References: <20230109221624.592315-1-isaacmanjarres@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Queue-Id: 7CC7440018 X-Rspamd-Server: rspam01 X-Stat-Signature: 74wceydy7mr6fkihxjgsqjubsf7izruu X-HE-Tag: 1674575344-944594 X-HE-Meta: U2FsdGVkX18ZfWArPy4i5hf9y1bysoQLb2yyK0EPYUGeAnO2SpXwaOh/hKNEuuEmq1maLyauVlGSK4mNDnaFZhy1gLcLip3XvBRz4G5qk60ILJG/mDBEFLDtN+C5mBL9mAZ8Rkg33b65a67QZkOqE+Ld6w8Zkx3JK+3D9aFHgkJzkACtJjv8n6Uu/DQL4fGYisKjODcX3T3jRCqK8mrGp1JM3RwKu6EKprzri1qURO1ql4KMeLOiN7R/rwVsbMqb+Jai6047NqmvUMWtGa+n2Ugf1o+b5FCM1Sf7eCv4GDS0PLH4PE9oCPYG1odWSq/rahkiQ4IKFNadTRXwjZqcchofO2nhkXcq9GhJ4/F1rtlUbrZNw4c3hqmf0xMEOTXSzYEU/y8Y0NOzO1GATIkqMXgs8AsRVGtvjtvae/gWCEVIU5sdIsJXiriUB4YSvt/Sg89b/zuMVI+4Rkb/3y7+PoRtAKPOKKuk2PXVoAG8+EBRlYIHIeAM8uBH+Kdb+QuRsBqiz4MfFBe9YXPCACJCtExOI5uN7ugrsfdWotpGzlz1H/pMPtvTB5og8K4EHDn8O+pUnGzxiqXP2M54wwOzfzfSn7yyfSaEJ7DHZYovl89GVzEItYlefBMZ9KEn+XhshmKQ6/DBkErFIIgkz8K+1ndDEphDy0IzsnjE0uZ2gYpR7/MmRUQjKLiDlqYsfJzj3zk/YJBNJX7wQW2KD99goaVDcjDZPCuMNtKDpM3M+C53CYNffKrv75Y6t1uZEgPO6GJpJ0Wq23/YBqQubO0CWaimoR4+cnC6E2454RcWyyq/sFp7g8WDpLeBD8mgHXLrlOzJcJIZ0aaznFCTmTF2QY0mOdPYsrnGNnyc8tRdn5no+S75urmL1njDPaiXEJAfmH/RTRW2oaId8tKN1Q+n6AlC9fop2Y+xjPKm7ZFwhnuC9VvWpMD0m4kfZJqaLPzzRUKLr6s7gLLyGuebNJn L7rl9Tlb n8canmAnJVFEE5N/QOKsIiAmsXeJ75dnFN6SXAY0oz/wHFo5Jn9I2EuXoAxgOQKIu0h719MtBrBp9+fsK973ZAwI+1OkG6p6ss16Sdox0JspopsvVE+zWh3IhiGr/hkGcTqtL2CHxtx7Gi9Weqp6kThm/EjodJd5BZd+UIdln9lCB3IUT3DvPUsM5+wBoXjZL7z9j6LQooM3gTj+RZnl+FpphojIGNiIvaSN/RLyrzODpiHDKVxAyQIXuSboBv1q0PA4tMb6mx9OB3/z+HKZ8bBFBnSoQb9pYh3Gx37Uunnr2RLL1s7U2radE0ZpUdAc22+s568J1oWY/kG3bF+28Y4lyGFtVO89/u+/QM+Z/8knqDfyX8WpHAw0cdJ1FUX/JCkz0gIZenT/2Ky3PxFkfrXLjCubhrYoX0eNg4VxGOR1O06RWfd3cfmsocIlGRal6PGm6KlXZLCpN/Fm6bOvkpZX1y5agpTSHAqfS+PFWQqeKh1CBA4UmS6bTsKv6RuB/mnEU 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: On Thu, Jan 19, 2023 at 04:20:56PM -0800, Isaac Manjarres wrote: > On Wed, Jan 18, 2023 at 05:16:46PM +0000, Catalin Marinas wrote: > > What I don't understand is why kmemleak scans such CMA regions. The only > > reason for a kmemleak_ignore_phys() call in cma_declare_contiguous_nid() > > is because the kmemleak_alloc_phys() hook was called on the > > memblock_alloc_range_nid() path, so we don't want this scanned. > The reason is because kmemleak_ignore_phys() is only called within > cma_declare_contiguous_nid(), which is not called for every CMA region. > > For instance, CMA regions which are specified through the devicetree > and not constrained to a fixed address are allocated through > early_init_dt_alloc_reserved_memory_arch(), which eventually calls > kmemleak_alloc_phys() through memblock_phys_alloc_range(). > > When the CMA region is constrained to a particular address, it is allocated > through early_init_dt_reserve_memory(), which is followed up by a call to > kmemleak_alloc_phys() due to this commit: > https://lore.kernel.org/all/20211123090641.3654006-1-calvinzhang.cool@gmail.com/T/#u Thanks for digging this out. This patch shouldn't have ended up upstream (commit 972fa3a7c17c "mm: kmemleak: alloc gray object for reserved region with direct map"). I thought both Calvin Zhang and I agreed that it's not the correct approach (not even sure there was a real problem to fix). Do you still get the any faults with the above commit reverted? I'd prefer this if it works rather than adding unnecessary kmemleak_alloc/free callbacks that pretty much cancel each-other. > I'm not sure if that commit is appropriate, given that reserved regions > that still have their direct mappings intact may be used for DMA, which > isn't appropriate for kmemleak scanning. It's not. I think it should be reverted. > > kmemleak would only scan such objects if it knows about them. So I think > > it's only the case where CMA does a memblock allocation. The > > kmemleak_ignore_phys() should tell kmemleak not to touch this region but > > it's probably better to just free it altogether (i.e. replace the ignore > > with the free kmemleak callback). Would this be sufficient for your > > scenario? > > I agree that freeing the kmemleak object is a better strategy. However, > replacing the call to kmemleak_ignore_phys() wouldn't be sufficient, > as there are other scenarios that would still leave behind kmemleak > objects to be scanned. That's why I ended up freeing the kmemleak object > in a path that is common for all CMA areas. The only reason for kmemleak_ignore_phys() was to counter the actual kmemleak_alloc() call from the memblock code on the CMA allocation. -- Catalin