Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4456507pxf; Tue, 16 Mar 2021 14:06:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHStsqB1HF649XUhEgtsfi+Gw3V1OIDhXuxGrb/j4LlbNMTIMNuwa5j32hBbMPh4i5dWg4 X-Received: by 2002:a17:906:3751:: with SMTP id e17mr32139168ejc.553.1615928766610; Tue, 16 Mar 2021 14:06:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615928766; cv=none; d=google.com; s=arc-20160816; b=dPc88Ep/TAScB1Wy3EqXorXrHzYdtiTOvpBIXuxej7FOFpOUbAW5qGQ6+THoJQvsYR nfaYffH+1rtOK0ue4rr+gncuSqbJwBIGM9NSGDfA8p4eF4lJEuJzaGCtWRGGwMBLdwmy VqLbRowpuyQWpcyyIDcl0GLwnNvgxwcpd1r8u8u2gQElPlO5Nvu4nnq+CnvBoG5XX3gX KksQ/8mor1EwVuhBO23yrCVWcDAs5lpDtnl5VilTqwx0FvkI4T/Zf1q0pkqAjoUNr96b buSSD+5xCkjtzoR3Fov4zzZ3F69LwhZEf2M/1iqj9xvqJ9PiTDfO09jvwZ0rUipL6Iuh WNqA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=eyrARzBmKQXtVBzU/YrZtOZnkyW/Z8yY4+R8daqS+I8=; b=alO/cIjJyeTHBHjYEEjnCb6wyzz5oAOHy/nX8ove88qe6YHNeRN/ngwBMKdAactIQI mD31vpfz99ycgbRzQOWsueuJQjxjx43p0M/W9ZsSJTvKGJ/pKxiWckIgooW3TBhGHRSZ j4se9MybAy4exwsLhjOdOr5LBMwfok0GLUL0Gn+XrksHxw5hz7qbrn3KpNxHcCkpLVKk N0ld/Gv9mfaGKX4pq/nlUjO67WIGNTpF9SYfdcOH5WPh+uptGzD0qAIQf97pWc5HHsV2 zNe8cW2O0u8Byz0XD2GiBNziqAvvGMuL+ZQuwl3B9/ieedsW9IyLGhmmq78gQ9SjKZkG EnEg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g17si14857065eds.403.2021.03.16.14.05.43; Tue, 16 Mar 2021 14:06:06 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234870AbhCPRld (ORCPT + 99 others); Tue, 16 Mar 2021 13:41:33 -0400 Received: from mx2.suse.de ([195.135.220.15]:50296 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233930AbhCPRlI (ORCPT ); Tue, 16 Mar 2021 13:41:08 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D90A1AC1F; Tue, 16 Mar 2021 17:41:05 +0000 (UTC) Received: from localhost (brahms [local]) by brahms (OpenSMTPD) with ESMTPA id f6ee1319; Tue, 16 Mar 2021 17:42:20 +0000 (UTC) Date: Tue, 16 Mar 2021 17:42:20 +0000 From: Luis Henriques To: Marco Elver Cc: Alexander Potapenko , Dmitry Vyukov , Catalin Marinas , Andrew Morton , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: Issue with kfence and kmemleak Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 16, 2021 at 06:30:00PM +0100, Marco Elver wrote: > On Tue, Mar 16, 2021 at 04:42PM +0000, Luis Henriques wrote: > > Hi! > > > > This is probably a known issue, but just in case: looks like it's not > > possible to use kmemleak when kfence is enabled: > > Thanks for spotting this. > > > [ 0.272136] kmemleak: Cannot insert 0xffff888236e02f00 into the object search tree (overlaps existing) > > [ 0.272136] CPU: 0 PID: 8 Comm: kthreadd Not tainted 5.12.0-rc3+ #92 > > [ 0.272136] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a-rebuilt.opensuse.org 04/01/2014 > > [ 0.272136] Call Trace: > > [ 0.272136] dump_stack+0x6d/0x89 > > [ 0.272136] create_object.isra.0.cold+0x40/0x62 > > [ 0.272136] ? process_one_work+0x5a0/0x5a0 > > [ 0.272136] ? process_one_work+0x5a0/0x5a0 > > [ 0.272136] kmem_cache_alloc_trace+0x110/0x2f0 > > [ 0.272136] ? process_one_work+0x5a0/0x5a0 > > [ 0.272136] kthread+0x3f/0x150 > > [ 0.272136] ? lockdep_hardirqs_on_prepare+0xd4/0x170 > > [ 0.272136] ? __kthread_bind_mask+0x60/0x60 > > [ 0.272136] ret_from_fork+0x22/0x30 > > [ 0.272136] kmemleak: Kernel memory leak detector disabled > > [ 0.272136] kmemleak: Object 0xffff888236e00000 (size 2097152): > > [ 0.272136] kmemleak: comm "swapper", pid 0, jiffies 4294892296 > > [ 0.272136] kmemleak: min_count = 0 > > [ 0.272136] kmemleak: count = 0 > > [ 0.272136] kmemleak: flags = 0x1 > > [ 0.272136] kmemleak: checksum = 0 > > [ 0.272136] kmemleak: backtrace: > > [ 0.272136] memblock_alloc_internal+0x6d/0xb0 > > [ 0.272136] memblock_alloc_try_nid+0x6c/0x8a > > [ 0.272136] kfence_alloc_pool+0x26/0x3f > > [ 0.272136] start_kernel+0x242/0x548 > > [ 0.272136] secondary_startup_64_no_verify+0xb0/0xbb > > > > I've tried the hack below but it didn't really helped. Obviously I don't > > really understand what's going on ;-) But I think the reason for this > > patch not working as (I) expected is because kfence is initialised > > *before* kmemleak. > > > > diff --git a/mm/kfence/core.c b/mm/kfence/core.c > > index 3b8ec938470a..b4ffd7695268 100644 > > --- a/mm/kfence/core.c > > +++ b/mm/kfence/core.c > > @@ -631,6 +631,9 @@ void __init kfence_alloc_pool(void) > > > > if (!__kfence_pool) > > pr_err("failed to allocate pool\n"); > > + kmemleak_no_scan(__kfence_pool); > > } > > Can you try the below patch? Yep, that seems to fix the issue. Feel free to add my Tested-by. Thanks! Cheers, -- Lu?s > > Thanks, > -- Marco > > ------ >8 ------ > > diff --git a/mm/kfence/core.c b/mm/kfence/core.c > index f7106f28443d..5891019721f6 100644 > --- a/mm/kfence/core.c > +++ b/mm/kfence/core.c > @@ -12,6 +12,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -481,6 +482,13 @@ static bool __init kfence_init_pool(void) > addr += 2 * PAGE_SIZE; > } > > + /* > + * The pool is live and will never be deallocated from this point on; > + * tell kmemleak this is now free memory, so that later allocations can > + * correctly be tracked. > + */ > + kmemleak_free_part_phys(__pa(__kfence_pool), KFENCE_POOL_SIZE); > + > return true; > > err: