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 X-Spam-Level: X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C939DC48BE5 for ; Wed, 16 Jun 2021 18:36:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6A6BD6105A for ; Wed, 16 Jun 2021 18:36:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6A6BD6105A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DF63C6B0036; Wed, 16 Jun 2021 14:36:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA6956B006C; Wed, 16 Jun 2021 14:36:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF9EE6B0070; Wed, 16 Jun 2021 14:36:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id 88D656B0036 for ; Wed, 16 Jun 2021 14:36:45 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 22FC71191F for ; Wed, 16 Jun 2021 18:36:45 +0000 (UTC) X-FDA: 78260443170.20.060D3C5 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf06.hostedemail.com (Postfix) with ESMTP id D5915C00CBE9 for ; Wed, 16 Jun 2021 18:36:34 +0000 (UTC) Received: by mail-pf1-f179.google.com with SMTP id z26so2902785pfj.5 for ; Wed, 16 Jun 2021 11:36:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=68dUbqfE4SHuzDV/ITTjNzfPVwl+Y5E4YdaUjtV5+SM=; b=J+iBSCxVI9jYH68oWvPqs6SrIxZU+B/vsIhREijY8w3hbBXi0m+cMBoTbXebRF6s6x 4UxTaREsNGYJa8ehBhFYFDN5idvzz93nPKAEvXMkrPIkJDV3Ju/C/WB6Lz1ii9QwuUMQ OXBorfuFc8hzPkZ9tLz+tSJHcedePwKKCRonrQLqmZLycOG1U6QhEfc+LRgVHVCL5HCX 172NrBIiRlHwjuJQa9vHZBjQocLtduj64PkGZrCt1l9JazTF6trQy0l77j9i5+SJhBs0 MH2gXxNW8017ZMuqXOHr8S5hLZU1/3/LQbEXmZT+q4sxzIisYpc1r+88qS+ObnSW6FBf JVEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=68dUbqfE4SHuzDV/ITTjNzfPVwl+Y5E4YdaUjtV5+SM=; b=O66BkW6iN4/Z6A5g0T1GNFSCZnskhtc3etpdBGF82OMvNkFb42k8nAjdgu0xHN1Rdc eQhegVBWBEPYWjuiiyQ9X3hS9kb1HJbyw5mTlSrBXCeLdzDJghzLxQe60T7z3J1i6SOD qRQbsbj0LzSUd3xhr1jjKi9bMOxXnYMKPfi4Rh8+gmbowfr1XhYGMRluTnH4+jJ+pcou g9HzHbdDvDqS1wYsNS4PX4XdWaTAVsP79h/+R0/B/cCEv34+2uzSOBzAFpc4N/oXtYlt cl86inOBvIYs6nx/OPeYG+W/nLFE1W2jYZDrT4piPoXLSLPJlNT69ZU7MINUDRl8FgIw B8KA== X-Gm-Message-State: AOAM530/6Xg9FPVD+YfvhRu6AL9tpZhyYVjgCfLUK3xjA3BkQaAsX8JQ XSe8Q9G4pn6PN8gCEAJ8fso= X-Google-Smtp-Source: ABdhPJzlYRExpxBz/5ZI5xAqecq1F1uVwziv1Eqs8rATfkZT1HYyPVtArS2KZGFO5m5Np9AOdUb7GA== X-Received: by 2002:a63:d40d:: with SMTP id a13mr972537pgh.382.1623868603888; Wed, 16 Jun 2021 11:36:43 -0700 (PDT) Received: from nuc10 (104.36.148.139.aurocloud.com. [104.36.148.139]) by smtp.gmail.com with ESMTPSA id b133sm2944503pfb.36.2021.06.16.11.36.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 11:36:43 -0700 (PDT) Date: Wed, 16 Jun 2021 11:36:39 -0700 From: Rustam Kovhaev To: Catalin Marinas Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, dvyukov@google.com, gregkh@linuxfoundation.org Subject: Re: kmemleak memory scanning Message-ID: References: <20210615101515.GC26027@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210615101515.GC26027@arm.com> Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=J+iBSCxV; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of rkovhaev@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=rkovhaev@gmail.com X-Rspamd-Server: rspam02 X-Stat-Signature: 4t3oxfhim4wqifi7r9cbazagmy4wkj15 X-Rspamd-Queue-Id: D5915C00CBE9 X-HE-Tag: 1623868594-914947 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: hi Catalin, On Tue, Jun 15, 2021 at 11:15:15AM +0100, Catalin Marinas wrote: > Hi Rustam, > > On Mon, Jun 14, 2021 at 01:31:14PM -0700, Rustam Kovhaev wrote: > > a) kmemleak scans struct page (kmemleak.c:1462), but it does not scan > > the actual contents (page_address(page)) of the page. > > if we allocate an object with kmalloc(), then allocate page with > > alloc_page(), and if we put kmalloc pointer somewhere inside that page, > > kmemleak will report kmalloc pointer as a false positive. > > should we improve kmemleak and make it scan page contents? > > or will this bring too many false negatives? > > This is indeed on purpose otherwise (1) we'd get a lot of false > negatives and (2) the scanning would take significantly longer. There > are a lot more pages allocated for user processes than used in the > kernel, we don't need to scan them all. > > We do have a few places where we explicitly call kmemleak_alloc(): > neigh_hash_alloc(), alloc_page_ext(), blk_mq_alloc_rqs(), > early_amd_iommu_init(). makes sense, tyvm! > > b) when kmemleak object gets created (kmemleak.c:598) it gets checksum > > of 0, by the time user requests kmemleak "scan" via debugfs the pointer > > will be most likely changed to some value by the kernel and during > > first scan kmemleak won't report the object as orphan even if it did not > > find any reference to it, because it will execute update_checksum() and > > after that will proceed to updating object->count (kmemleak.c:1502). > > and so the user will have to initiate a second "scan" via debugfs and > > only then kmemleak will produce the report. > > should we document this? > > That's a mitigation against false positives. Lot's of objects that get > allocated just prior to a memory scan have a tendency to be reported as > leaks before they get referenced via e.g. a list (and the in-object > list_head structure updated). So you'd need to get the checksum > identical in two consecutive scans to report it as a leak. > > We should probably document this. thanks, i'll send a documentation patch for this