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=-13.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 00FECC2B9F4 for ; Fri, 25 Jun 2021 15:37:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 89C8061939 for ; Fri, 25 Jun 2021 15:36:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 89C8061939 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8DAD86B0036; Fri, 25 Jun 2021 11:36:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 863E36B005D; Fri, 25 Jun 2021 11:36:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B5766B006C; Fri, 25 Jun 2021 11:36:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0090.hostedemail.com [216.40.44.90]) by kanga.kvack.org (Postfix) with ESMTP id 335216B0036 for ; Fri, 25 Jun 2021 11:36:58 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5032E16498 for ; Fri, 25 Jun 2021 15:36:58 +0000 (UTC) X-FDA: 78292649316.22.0CB2F71 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) by imf09.hostedemail.com (Postfix) with ESMTP id EA7586000158 for ; Fri, 25 Jun 2021 15:36:57 +0000 (UTC) Received: by mail-qt1-f181.google.com with SMTP id r20so7792603qtp.3 for ; Fri, 25 Jun 2021 08:36:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=y6YthVsh8dQjzhz84cmChJODP2HFEjc+K0QQHEGVnrE=; b=T2BwYjUYm8dCG6g1wWe1slEjX7RbA8+gxd4uTXeIpz6MAqZBFjXxO0iI79vx0SE1SM XPYTNq+OMcqMEJMfp75JkHVzfwTSRKyvafXN3ce6757htf4jUVoMPll5xM7QLCuqwfq4 MgN8O/SiibJV+/qfM7Q+odwqYOr9ZkXGs9CG4YpJ6YWIv6yqcNpUSyM2hQIGN9G/l3Sg TS4ePF+Sqj02U5zfYCZ+irvBvHX5G1HOwLm1AIQzBOpgLj1uCrez3v+3OgSEEU8SdV27 RrUXMrvKGbMRnPKH7bjkGtQtvgIelcb7/U7g9ICmJl3B9i91kJD6oT3oc8NapNCVnEnd jSQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=y6YthVsh8dQjzhz84cmChJODP2HFEjc+K0QQHEGVnrE=; b=lUL+UYo2ZpC02chhPIS9XTnu/4ttBEDUpWqQUnr+aEiUEQeDKKmWKx2jYRHDIsWFS1 OLEfPgvONHqtTh6qahjtGJyjqNtdxuBa7BFkxXI06bpYLJfhapWFv0sGrp2JPLO1Klif 2vIjAzToAy3T1H82kmw8iNj+CJW3dTMOeGnTwsN5DM60Fs6gioGUIzpHt+7RY8v7wUCK VKDlcyTtXMqD1ekmuP8nnTTh14ZpGe/53PSnDrDW1YGCadte5fFI7eB4dDsVdUzyFyYg SDJH2wMLuZCD8MucqNxEtTcTztaX9suoPBAL+HsPQ+YBh5nkMqotoKXlWdDc3U9Dbaeb 9ibw== X-Gm-Message-State: AOAM530I/vBESNOCCRYCKGBumq7uXT0CVYgta84ZengLvs9bKRf+T5nS cs1tnyf/vxMQdd/YndfJdX+gZQh+hieFpzNAmF5pmg== X-Google-Smtp-Source: ABdhPJxhinfjBO7oNGQJqZEc0znZWhLWJqW9EKmj2hb3Pyeuy92aA6j1jXFeEB/bMnV4Wzx3zh5QtfbmO4SnjZr1xU0= X-Received: by 2002:ac8:7616:: with SMTP id t22mr9735295qtq.43.1624635417070; Fri, 25 Jun 2021 08:36:57 -0700 (PDT) MIME-Version: 1.0 References: <20210625150132.GF20835@arm.com> In-Reply-To: From: Dmitry Vyukov Date: Fri, 25 Jun 2021 17:36:44 +0200 Message-ID: Subject: Re: kmemleak memory scanning To: Rustam Kovhaev Cc: Catalin Marinas , Andrew Morton , Linux-MM , LKML , Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=T2BwYjUY; spf=pass (imf09.hostedemail.com: domain of dvyukov@google.com designates 209.85.160.181 as permitted sender) smtp.mailfrom=dvyukov@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: EA7586000158 X-Stat-Signature: qhcp9uop7meftqum9a9utsn78ymoroy9 X-HE-Tag: 1624635417-818147 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 Fri, Jun 25, 2021 at 5:28 PM Rustam Kovhaev wrote: > > Hi Catalin, > > On Fri, Jun 25, 2021 at 04:01:33PM +0100, Catalin Marinas wrote: > > 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. > > > right, but if i understood Dmitry's idea correctly, he was thinking > about using a new GFP flag, like GFP_KMEMLEAK, and burying > kmemleak_alloc() in page allocator I don't have a strong opinion either way. Especially since we have only 1 use case so far.