Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp415748pxv; Thu, 24 Jun 2021 10:40:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywD+xsbVkR2Qw0c8QFFyc9ll2C9e5CvBL5rJtCOUMwAr8glBivmIZwzsyxWJFTgYUC/1/j X-Received: by 2002:a17:906:388:: with SMTP id b8mr6414831eja.397.1624556458480; Thu, 24 Jun 2021 10:40:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624556458; cv=none; d=google.com; s=arc-20160816; b=xb2rciIyzVKP2zy0deHDn+fQp/ZjOI0t9UMA9ULWm2I/PxNpqJmHesAvDUEGUs8rjt hc+wm5FoF+bTyYx2q+Aibw8tR4WaT55qzdMNNVO1DWy+7bzv2Iq4FXsGtlKcVMAwP7xa kMn3oOuyehnI2ucITEEGZiNZm4SKO9XvbQQbyB7H7Nv/Vv4sueefInfdDCkc8cNIfgWX ZbH4eiQ0LH9JPIefMsnhJ9+uhKwWHfUQGpFRDRRE0mXpNkBTOg7ok8NdVyOjyz+GYDxt oUmAhe29DeH/DOV+s9wPNKNZB0KmIBNX22hjIOdnIJSnLFA1RzOURdGlUaLeEVBq6V9O F8NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=PeRKsgy74/XMQSubNA8psgjoWJKBQi8NTy2S1z7EZtA=; b=PrHPVkW6xzN/KpSbSkA3LplgdqeViDJpvu5M/nLDWCAad3wFC9ZGoCVIQ+FZAq7QM4 t04fa/PE+avUeP28eRrhzVzzZ91bExNUb3hn3sSon0k6RTHNeWDZTWO5r0cAEpMmrwhP LiWh7WNM5oRwMt0UViqHvCMbQHU2F3osJLZW1MmOpqay+ZVTOgLaS/lYaSG2nHhsT5z1 177uvclMpi+X20VdX6Tgf529630xWEuXuS1uTdblMaE7PaSbsqWFLHCqsgE74KUKmO/g bEhmpzRyNi5YWZniRiXXV6hKRL3sRm2ruyVRqo0HN4D4JZcCaJ9QkUh3C4KJrv7oQF+Z 0gqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="N/X8xyzR"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q8si3461610edb.138.2021.06.24.10.40.34; Thu, 24 Jun 2021 10:40:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="N/X8xyzR"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232174AbhFXRjR (ORCPT + 99 others); Thu, 24 Jun 2021 13:39:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbhFXRjO (ORCPT ); Thu, 24 Jun 2021 13:39:14 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4CB0C061574 for ; Thu, 24 Jun 2021 10:36:55 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id w71so5803204pfd.4 for ; Thu, 24 Jun 2021 10:36:55 -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=PeRKsgy74/XMQSubNA8psgjoWJKBQi8NTy2S1z7EZtA=; b=N/X8xyzRMvKBxZFAr3CR8HD6HGsZwVBeIe1wh3HdrE8VLQVtSsen5KkxX2ZdLIVwAT Ko+DoSRx662BsfDGZPoGFnWai4VGGC8J+GL8KPN/UKFYlAr96orvk5HXFA5kWJ45ZtpT t7GkirUt+ls5zr4SR2UZToo9tZ91JhYCzI2/QC96FkNcHfZEhXFg4/WY4J59U0TSTdxo q+NfcdszvkjEd9hzVIwNvYCWRDDydMgIUrf5oF+x6yuvhDB9WvmDXlrmJrvc82rdMc4s ea+njS9uyYa2eOeokpSTb66SogV6aLjpq02mSLTPc9R7V0TwgnsZYVZ/DlnBp2UdV1vx ei1Q== 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=PeRKsgy74/XMQSubNA8psgjoWJKBQi8NTy2S1z7EZtA=; b=fq2ZKOvtatyJiLa94DK2mf1oayeLiehWDcJ63yMISbxiVSq8fnBx/hOvGiOCf1X/yz 114JWdTlzMIJRuFxTglvPKxy8gzBu9ML0pBfJUUmKwwuclWRF9CDrDPF8C1zCzAICNWj WMo+fma6fCbPBRapwPeqbUiy/eu7MphghHYaIStN/soO4y1ockpjEr8kAn6VF7N2qICc tXBA2yqN0zLyxNJgxqp4Ld9UJykwtPzkOi2XVCT0M66uIkTYBUgyzldw2kQureD+Tjnw i4AjqrOZr9b2kNGTMkGw0FURzhbm3Kh3IAafMKhJO8bTaAPqkV47ZB6FnbD5B1lPqvN2 5ErQ== X-Gm-Message-State: AOAM5313LbaWXzzbEVg7L19/FQogwSzNkp5PW4hYpKgaJgqG75ccyFyN 1djvteGzOFxQ9gafpLSkXrg= X-Received: by 2002:a63:5c04:: with SMTP id q4mr5637097pgb.127.1624556215056; Thu, 24 Jun 2021 10:36:55 -0700 (PDT) Received: from nuc10 (104.36.148.139.aurocloud.com. [104.36.148.139]) by smtp.gmail.com with ESMTPSA id y1sm3542572pfe.72.2021.06.24.10.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 10:36:54 -0700 (PDT) Date: Thu, 24 Jun 2021 10:36:50 -0700 From: Rustam Kovhaev To: Dmitry Vyukov Cc: Catalin Marinas , Andrew Morton , Linux-MM , LKML , Greg Kroah-Hartman Subject: Re: kmemleak memory scanning Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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