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=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 61BCAC49EBA for ; Fri, 25 Jun 2021 15:04:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A00A761976 for ; Fri, 25 Jun 2021 15:01:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A00A761976 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B55776B005D; Fri, 25 Jun 2021 11:01:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B2C3B6B006C; Fri, 25 Jun 2021 11:01:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F60B6B0070; Fri, 25 Jun 2021 11:01:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0165.hostedemail.com [216.40.44.165]) by kanga.kvack.org (Postfix) with ESMTP id 6E8556B005D for ; Fri, 25 Jun 2021 11:01:39 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 9A191824999B for ; Fri, 25 Jun 2021 15:01:39 +0000 (UTC) X-FDA: 78292560318.05.0CF6A5A Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf22.hostedemail.com (Postfix) with ESMTP id B8CBEC01C084 for ; Fri, 25 Jun 2021 15:01:37 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id C42CA6197D; Fri, 25 Jun 2021 15:01:35 +0000 (UTC) Date: Fri, 25 Jun 2021 16:01:33 +0100 From: Catalin Marinas To: Rustam Kovhaev Cc: Dmitry Vyukov , Andrew Morton , Linux-MM , LKML , Greg Kroah-Hartman Subject: Re: kmemleak memory scanning Message-ID: <20210625150132.GF20835@arm.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of cmarinas@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) X-Stat-Signature: 5im4p18jtpndn6ujwtsgtrj3n45awf5x X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B8CBEC01C084 X-HE-Tag: 1624633297-651505 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, Jun 24, 2021 at 10:36:50AM -0700, Rustam Kovhaev wrote: > On Wed, Jun 16, 2021 at 11:25:22AM -0700, Rustam Kovhaev wrote: > > On Tue, Jun 15, 2021 at 07:15:24AM +0200, Dmitry Vyukov wrote: > > > On Mon, Jun 14, 2021 at 10:31 PM Rustam Kovhaev wrote: > > > > > > > > hello Catalin, Andrew! > > > > > > > > while troubleshooting a false positive syzbot kmemleak report i have > > > > noticed an interesting behavior in kmemleak and i wonder whether it is > > > > behavior by design and should be documented, or maybe something to > > > > improve. > > > > apologies if some of the questions do not make sense, i am still going > > > > through kmemleak code.. > > > > > > > > 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? > > > > > > Hi Rustam, > > > > > > Nice debugging! > > > I assume lots of pages are allocated for slab and we don't want to > > > scan the whole page if only a few slab objects are alive on the page. > > > However alloc_pages() can be called by end kernel code as well. > > > I grepped for any kmemleak annotations around existing calls to > > > alloc_pages, but did not find any... > > > Does it require an explicit kmemleak_alloc() after allocating the page > > > and kmemleak_free () before freeing the page? > > > > hi Dmitry, thank you! > > yes, as Catalin has pointed out, there are a few places where we call > > kmemleak_alloc()/kmemleak_free() explicitly in order for the pages to be > > scanned, like in blk_mq_alloc_rqs() > > > > > If there are more than one use case for this, I guess we could add > > > some GFP flag for this maybe. > > > > and this way kernel users won't have to use kmemleak fuctions mentioned > > above including some or most kmemleak_not_leak() calls and basically > > kmemleak will be kind of "transparent" to them? and they will only need > > to use the GFP flag to instruct kmemleak to scan the page contents? > > it sounds like a good idea to me.. > > > > i've been thinking about this and it seems like in the scenario where we > want kmemleak to scan only some part of the page, we will have to either > do separate alloc_page() calls with different flags or use > kmemleak_scan_area() to limit the memory scan area. maybe this approach > won't simplify things and will produce more code instead of reducing it Since page allocation is not tracked by kmemleak, you can always do an explicit kmemleak_alloc() call with a smaller size than a full page. -- Catalin