From patchwork Thu Jun 9 12:49:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: patrick wang X-Patchwork-Id: 12875546 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 DA35DC433EF for ; Thu, 9 Jun 2022 12:50:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6722F8D0016; Thu, 9 Jun 2022 08:50:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 621E98D0015; Thu, 9 Jun 2022 08:50:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E9E98D0016; Thu, 9 Jun 2022 08:50:57 -0400 (EDT) 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 3DFE28D0015 for ; Thu, 9 Jun 2022 08:50:57 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 16AAA8112C for ; Thu, 9 Jun 2022 12:50:57 +0000 (UTC) X-FDA: 79558682154.30.39E6B65 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf28.hostedemail.com (Postfix) with ESMTP id 93C04C0004 for ; Thu, 9 Jun 2022 12:50:56 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id o6-20020a17090a0a0600b001e2c6566046so26610608pjo.0 for ; Thu, 09 Jun 2022 05:50:56 -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:mime-version :content-transfer-encoding; bh=qv9uiCnYkz7r1g81Uxpd/4YaIX8fP8HTMmvq6kZi5lg=; b=Z3X3g/QGldKGffMSt6uWhAgADYxTRzzt38s6Pl69DAYLj1AM7WTDnUcZBlWAjKzHjz t36dGvwHRMlH5CSHGrAcMtXSlzUVagN60htpNE2pzC10V9BySpRdo555jFDaKA3nGd5E nIwSjf7UZWrga5twSOS5YPkCbvTpaHc4eODH0OrzTkv71qCXmAnLNc42dDvobiBRPwCr MdC8vysihai1udc5P40yfWlX+wUyurn8FnCLqNZTePbJSyp3XDa3FHNjcYb+rFeHGI5Q +j7fF8Cdjx4NOyh1dy4lCJCxK+Ikhv86U7eRUK5LrFxHLXQo/Eeamh8ixO6waC+8ZlB8 6d+Q== 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:mime-version :content-transfer-encoding; bh=qv9uiCnYkz7r1g81Uxpd/4YaIX8fP8HTMmvq6kZi5lg=; b=Fq86y9BGzjFRFHEZy+Ce2FnCk2uDma8YmlqSAl8f9R1w4PlxaNUW32/UdawoqTlJQl 889rEboyKtRFvmksYrmOIG510Jefcx+yKMp1APv9ooHLlFo0nupJX+ycqGnliipwNrQt mCRH8A4xiglwq/797rofH+6RFeBZUUg0nJSoiPuWxmMkxxXch3B/zeFHz8mV7RjCY5lB JtrCaRQRYSYUjBhTF6Sx7WiuOrpqQ0XBrZKx4asSZt+PQl7kLn0LW1mFaxqpakKl9yWW aevI6FQhcG1wlM89CAisQNGm43w6Z3eSePOdc1Uhj15dHDwx1RdT//EULtuvQmBgj2L7 99yA== X-Gm-Message-State: AOAM5338SzhAMUGZ3IbKqyHMC3X0XYYtBWO7g/csKycw2s51C9UCI9jj ovsmHrRjAVKwLF/Zyx9BS7A= X-Google-Smtp-Source: ABdhPJyBnxAQEPn+HX6J+QIyBBx3dSo2YPqdDlBYIzCGbyEsPlUrXIAm08nFvf+/fUte/mJiqvpZ8w== X-Received: by 2002:a17:903:120f:b0:15f:99f:9597 with SMTP id l15-20020a170903120f00b0015f099f9597mr38766686plh.45.1654779055575; Thu, 09 Jun 2022 05:50:55 -0700 (PDT) Received: from localhost ([101.86.206.203]) by smtp.gmail.com with ESMTPSA id p1-20020a1709027ec100b00167736c8568sm9214922plb.70.2022.06.09.05.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jun 2022 05:50:55 -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 0/3] mm: kmemleak: store objects allocated with physical address separately and check when scan Date: Thu, 9 Jun 2022 20:49:47 +0800 Message-Id: <20220609124950.1694394-1-patrick.wang.shcn@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654779056; 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:references:dkim-signature; bh=qv9uiCnYkz7r1g81Uxpd/4YaIX8fP8HTMmvq6kZi5lg=; b=Uih/dYOnhGScfVwLeH1Ymdia8TGSsa9c86Baeto/WDCYZDUwai9NtitGymZO5wrQgVoo7U oSTWeuLLvJA1ZsdQwA5rJI9AeV8lBymdRM69F4LRdKSzMAiAc5swVCkFN5l9/kBBa6jRB3 ZZ05pWfqdLCT8EjLs4QL0106/xsL1SM= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Z3X3g/QG"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of patrick.wang.shcn@gmail.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=patrick.wang.shcn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654779056; a=rsa-sha256; cv=none; b=pkes+Q/njumVgOF6J3RkP5zN1TfStXFa59AoSeeuvYu9x7WyldHiKkA/wTPscTWRxAMLxD jAViBajcNFmZK31oTdxF9Hei7bS2dqKC2PD7WsjFZuM2WgmcuJLaJZ1iVNs+xr9SoymVe+ QBjlrdNmJSNuy3ZGmY5VssnnyoT/L2k= X-Stat-Signature: bgmsgt45rgpeccbx8bx9me45tzmfcdb6 X-Rspamd-Queue-Id: 93C04C0004 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Z3X3g/QG"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of patrick.wang.shcn@gmail.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=patrick.wang.shcn@gmail.com X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1654779056-587515 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: The kmemleak_*_phys() interface uses "min_low_pfn" and "max_low_pfn" to check address. But on some architectures, kmemleak_*_phys() is called before those two variables initialized. The following steps will be taken: 1) Add OBJECT_PHYS flag and rbtree for the objects allocated with physical address 2) Store physical address in objects if allocated with OBJECT_PHYS 3) Check the boundary when scan instead of in kmemleak_*_phys() This patch set will solve: https://lore.kernel.org/r/20220527032504.30341-1-yee.lee@mediatek.com https://lore.kernel.org/r/9dd08bb5-f39e-53d8-f88d-bec598a08c93@gmail.com v2: https://lore.kernel.org/r/20220603035415.1243913-1-patrick.wang.shcn@gmail.com v1: https://lore.kernel.org/r/20220531150823.1004101-1-patrick.wang.shcn@gmail.com v2->v3: - remove the min_count argument to kmemleak_alloc_phys() function and assume it's 0 - remove unused kmemleak_not_leak_phys() function - add functions to reduce unnecessary changes - remove the check for kasan_reset_tag() - add Fixes tag in patch 3 v1->v2: - add rbtree for the objects allocated with physical address - store physical address in objects if allocated with OBJECT_PHYS - check the upper object boundary as well and avoid duplicate check Patrick Wang (3): mm: kmemleak: add OBJECT_PHYS flag for objects allocated with physical address mm: kmemleak: add rbtree and store physical address for objects allocated with PA mm: kmemleak: check physical address when scan Documentation/dev-tools/kmemleak.rst | 1 - drivers/of/fdt.c | 2 +- include/linux/kmemleak.h | 8 +- mm/kmemleak.c | 200 ++++++++++++++++-------- mm/memblock.c | 14 +- tools/testing/memblock/linux/kmemleak.h | 2 +- 6 files changed, 145 insertions(+), 82 deletions(-)