From patchwork Sat Jun 11 03:55: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: 12878330 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 1E410C433EF for ; Sat, 11 Jun 2022 03:57:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 798FC8D0106; Fri, 10 Jun 2022 23:57:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 74A6A8D00F7; Fri, 10 Jun 2022 23:57:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6109A8D0106; Fri, 10 Jun 2022 23:57:47 -0400 (EDT) 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 517CA8D00F7 for ; Fri, 10 Jun 2022 23:57:47 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 250DC6175F for ; Sat, 11 Jun 2022 03:57:47 +0000 (UTC) X-FDA: 79564596174.01.080D5FD Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf02.hostedemail.com (Postfix) with ESMTP id C015980088 for ; Sat, 11 Jun 2022 03:57:46 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id e66so869746pgc.8 for ; Fri, 10 Jun 2022 20:57:46 -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=EJ1428xewNFchdZrYlO+/855yPqA1ZpD9GpS9ECgUW8=; b=gv1KTcgDaORWCDyiFRbzOfYmnT5swt6Vy7IsHZdEk/OqpGhonYIbyodiBkQLrWYaj5 AVB5iyb+Q3Tq1O23WY2EcyyGia5nktw3zUCcihTtNId73vONqxqWhZ3ckGVp2dZBH02l msRgZTNGjNcqZ5QXsp+eTCVv++jDS05681if0egA/01Vwf6FG9VNcRqiJ6/cCFnJd478 HVMO2Xr2dD93otxBQbjYCrG6bFgDA3BxAXlhaV0XZIY2r+4pL5BZ2HMqJ9DKQC9saS36 taethIfe3+Uj7quEPNz56FdBSlWglUTDEpaFRTm+gW2wUF1zGPYDr642LDGk4ottZPy3 xilg== 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=EJ1428xewNFchdZrYlO+/855yPqA1ZpD9GpS9ECgUW8=; b=3XUZBaKSruRfukfSVXbzpbhlLP5l3Jqso12JdpJ+leo+P1xA90ZMgn2nXE/XxdcKxj imyQ1UxsXSfHccMBdKgAokYpzhOHPt0r0CtmFqfypxsCgyQO2zK/9EiOhEAh2eZDniJb ooWt9Wk05oqTtJlY31gnobLvWC71nMXDZ+t/cJfGZctfy0wZUTfWBRdaFDz4QBvT45jg 5a/rAtJcsGGUuEfBmD+kG6DWd+wbbX+EA6DBHNYTH/U4IVvltc67cHAwXkrnkBDrwoLl Q5lxzc5yTZsbU7uO2Awrfuowkecwi9lRt5pEu2k1+JDstNzCWl8nzA4M/XRgtRpGpdrh Dxhw== X-Gm-Message-State: AOAM532z3CA/Gga8ORbwhOFBtcSb8bU8CoGAfLkpi4An1KFzuZAaCfvG wATo0uEWQKKHC6cqbTE5IbI= X-Google-Smtp-Source: ABdhPJyO+3OsfXbuRV42VlcQc7PTHRUpnOw2Bh852r/keYAn4XeWwBHvTrPrPe6QLLU8TKTClEBHng== X-Received: by 2002:a05:6a00:16c7:b0:520:6ede:2539 with SMTP id l7-20020a056a0016c700b005206ede2539mr4624621pfc.46.1654919865690; Fri, 10 Jun 2022 20:57:45 -0700 (PDT) Received: from localhost ([101.86.206.203]) by smtp.gmail.com with ESMTPSA id bw11-20020a056a00408b00b0051868677e6dsm378084pfb.51.2022.06.10.20.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 20:57:44 -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 v4 0/4] mm: kmemleak: store objects allocated with physical address separately and check when scan Date: Sat, 11 Jun 2022 11:55:47 +0800 Message-Id: <20220611035551.1823303-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=1654919866; 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=EJ1428xewNFchdZrYlO+/855yPqA1ZpD9GpS9ECgUW8=; b=x+yy6YqwwcZ+IYR3X07PgAaijOd7K4rO4ajFFOntupMogWtK+PH1USHmDN6jaJ7nxRVFMk uF4LX+smHmhHm5YDpPyy4SYlDJk7asO7+0Ni8+XioUS+piLnvYCPPNaj5ViCF2w6SuBmSs qvhKWNlsvrEUbK5wX8JMhupRvTKXNCo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654919866; a=rsa-sha256; cv=none; b=2Jj6T1oWTYlxxwrGO91urNe2d4tODOYexDg7q46yeu0E25iurA63FW2CV1feuCTSPKvXX3 IPWI3gRXpww6XNU+CzgLovUm6jIrc50Bm48zUyXRjEYYCFKSVTUqt6gD89wbFe6K3Rtnyj 6frZhzZ80aG0IgrE+sSrg3f0thIW2Ko= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gv1KTcgD; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of patrick.wang.shcn@gmail.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=patrick.wang.shcn@gmail.com X-Rspamd-Server: rspam11 X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gv1KTcgD; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of patrick.wang.shcn@gmail.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=patrick.wang.shcn@gmail.com X-Stat-Signature: fey6xzdnujtxs4uyorbyneh1nj5uxkuw X-Rspamd-Queue-Id: C015980088 X-HE-Tag: 1654919866-151775 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 v3: https://lore.kernel.org/r/20220609124950.1694394-1-patrick.wang.shcn@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 v3->v4: - fix a build warning - move the prototype change of kmemleak_alloc_phys() and the kmemleak_not_leak_phys() removal to a separate patch (patch 1) 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 (4): mm: kmemleak: remove kmemleak_not_leak_phys() and the min_count argument to kmemleak_alloc_phys() 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(-) Tested-by: Geert Uytterhoeven