Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp71796rwl; Tue, 4 Apr 2023 19:08:09 -0700 (PDT) X-Google-Smtp-Source: AKy350ZwChq5FNh6zQhSUEuVKEJSQ2vMtuXBd1HhJlyMoN1roZR106qy2YCgvQVYA2bf6rEfH4Oh X-Received: by 2002:a17:907:a042:b0:93f:2114:9a1c with SMTP id gz2-20020a170907a04200b0093f21149a1cmr1353626ejc.45.1680660489165; Tue, 04 Apr 2023 19:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680660489; cv=none; d=google.com; s=arc-20160816; b=oT7K4NuMcDaQHItsRsDrk2XXGaUCO8KhpedpmcVlbSHM/Cmtd3od9gxoacjiwwNy6r NkqJGPdu76Jcq9sCZVvnLv61DcWkTV80Dbwvqjn6iqW1p+uPv1RM8PRvAkMztzV/0LUf tXV6PtbPVgRqeYsRVzUYm7jp0qRFa/LTwM+nROArLNrC9Lf2yeLO7QN5gyNQzgRMr/lh 16UswFltkJ9FUSVE6UDxh6r5GmD/6udlMF9dN9DO5MuE4yLziqpyqVnDzoJDgueZ8u9u 9rwvjwMkvrEgrn3IaI14b9KykFbEtR8sF3Yi0WQ3X/MjcOcjZq6+0LiEY7MSicYwC1qN mQng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=bnij7B0KBrBY34+9pqfeC1+5qwU+6Gl1IMo8qKh3a0w=; b=Fp3fwF8VGnnou0iDdvKJiV3VmgblL0WrHOpn1mv9Vb6Ov8kxjazQMIQY+43IJ93ucY wLR3r04TI6UUbwOu63Gj0vRboMvfXuWqEZmkOOH1TAUrE2MjiQ6+pM0GOIQuJhiKdR8y +t3Vg+Tg1lXb6ALoz3or1aY2oA+ij4Mb5mUgJxDTm95eyf+qGuJyFMRGf5JdulMj48LT PtqVVU5hcwGWRnGKD4wJNfeXk5TACN/1TULdhNdzihM2e+74dAj58NBGMYR1AALiMXfz FeLJVm0c7sHwNTvHf3FeBj8c+ZYzwOBYQcOCRPl0IKxNuP7xfC/B6fPFN3/cw+2aBxg7 7/TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=sLskrmc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f7-20020a170906738700b0092a3709e877si3635690ejl.679.2023.04.04.19.07.21; Tue, 04 Apr 2023 19:08:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=sLskrmc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236706AbjDECBe (ORCPT + 99 others); Tue, 4 Apr 2023 22:01:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232695AbjDECB3 (ORCPT ); Tue, 4 Apr 2023 22:01:29 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78DE33ABC; Tue, 4 Apr 2023 19:01:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description; bh=bnij7B0KBrBY34+9pqfeC1+5qwU+6Gl1IMo8qKh3a0w=; b=sLskrmc3H71rRgY//Xwu9rGo7X aP4mZe/iMJJUITsQCbgmmLjhL0J5B6WIAdIFTVxffAeFdNIiHKUHzc35OnXRMQJGMs/HbiIkmbQbA Oi/LUv26ON/XEbYsGEbrNZJ7Tk+ohjnsLW32+jHrRkkB3aTjqwoz/ub8m7KmvZHXNeloOE7Fr0mzh vijvMUpKsKJGjjgL+yiEAjlaI5bX0lqfmbMRVkYfJXpnZzptixH4lBIRWIAKWimLFodTQFXGseosL 7djeMmKOIhVXuLOaejB3zI9u3BAdUbcDP64LJ5cQ6lX6DT1H/iLMrqbjtQ5Ts9n9h1sUg9B4LP2s2 ZZl4whzA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pjsSi-0038fI-1W; Wed, 05 Apr 2023 02:01:24 +0000 Date: Tue, 4 Apr 2023 19:01:24 -0700 From: Luis Chamberlain To: jim.cromie@gmail.com Cc: Song Liu , Catalin Marinas , linux-modules@vger.kernel.org, LKML , Jason Baron , Greg KH Subject: Re: kmemleaks on ac3b43283923 ("module: replace module_layout with module_memory") Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: Luis Chamberlain X-Spam-Status: No, score=-2.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 04, 2023 at 07:38:41PM -0600, jim.cromie@gmail.com wrote: > On Mon, Apr 3, 2023 at 2:44 PM Luis Chamberlain wrote: > > > > On Fri, Mar 31, 2023 at 05:27:04PM -0700, Song Liu wrote: > > > On Fri, Mar 31, 2023 at 12:00 AM Luis Chamberlain wrote: > > > > > > > > On Thu, Mar 30, 2023 at 04:45:43PM -0600, jim.cromie@gmail.com wrote: > > > > > hi Luis, etal > > > > > > > > > > kmemleak is reporting 19 leaks during boot > > > > > > > > > > because the hexdumps appeared to have module-names, > > > > > and Ive been hacking nearby, and see the same names > > > > > every time I boot my test-vm, I needed a clearer picture > > > > > Jason corroborated and bisected. > > > > > > > > > > the 19 leaks split into 2 groups, > > > > > 9 with names of builtin modules in the hexdump, > > > > > all with the same backtrace > > > > > 9 without module-names (with a shared backtrace) > > > > > +1 wo name-ish and a separate backtrace > > > > > > > > Song, please take a look. > > > > > > I will look into this next week. > > > > I'm thinking this may be it, at least this gets us to what we used to do > > as per original Catalinas' 4f2294b6dc88d ("kmemleak: Add modules > > support") and right before Song's patch. > > > > diff --git a/kernel/module/main.c b/kernel/module/main.c > > index 6b6da80f363f..3b9c71fa6096 100644 > > --- a/kernel/module/main.c > > +++ b/kernel/module/main.c > > @@ -2240,7 +2240,10 @@ static int move_module(struct module *mod, struct load_info *info) > > * which is inside the block. Just mark it as not being a > > * leak. > > */ > > - kmemleak_ignore(ptr); > > + if (type == MOD_INIT_TEXT) > > + kmemleak_ignore(ptr); > > + else > > + kmemleak_not_leak(ptr); > > if (!ptr) { > > t = type; > > goto out_enomem; > > > > We used to use the grey area for the TEXT but the original commit > > doesn't explain too well why we grey out init but not the others. Ie > > why kmemleak_ignore() on init and kmemleak_not_leak() on the others. > > > > Catalinas, any thoughts / suggestions? Should we just stick to > > kmemleak_not_leak() for both now? > > > > Luis > > So I have mixed results. > > your patch fixed the 19 leaks on my worktree / branch where I found them. > > on top of > ac3b43283923 module: replace module_layout with module_memory > > it fixed the (same) 19, but gets a few new ones. > whats weird is that once they report, they disappear from > /sys/kernel/debug/kmemleak I think I missed the MOD_INIT_DATA and MOD_INIT_RODATA. Can you try the patch below instead: From 6890bd43866c40e1b58a832361812cdc5d965e4c Mon Sep 17 00:00:00 2001 From: Luis Chamberlain Date: Tue, 4 Apr 2023 18:52:47 -0700 Subject: [PATCH] module: fix kmemleak annotations for non init ELF sections Commit ac3b43283923 ("module: replace module_layout with module_memory") reworked the way to handle memory allocations to make it clearer. But it lost in translation how we handle kmemleak_ignore() or kmemleak_not_leak() for these sections. Fix this and clarify the comments a bit more. Fixes: ac3b43283923 ("module: replace module_layout with module_memory") Reported-by: Jim Cromie Signed-off-by: Luis Chamberlain --- kernel/module/main.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index 5cc21083af04..fe0f3b8fd3a8 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2233,11 +2233,23 @@ static int move_module(struct module *mod, struct load_info *info) ptr = module_memory_alloc(mod->mem[type].size, type); /* - * The pointer to this block is stored in the module structure - * which is inside the block. Just mark it as not being a - * leak. + * The pointer to these blocks of memory are stored on the module + * structure and we keep that around so long as the module is + * around. We only free that memory when we unload the module. + * Just mark them as not being a leak then. The .init* ELF + * sections *do* get freed after boot so we treat them slightly + * differently and only grey them out as they work as typical + * memory allocations which *do* get eventually get freed. */ - kmemleak_ignore(ptr); + switch (type) { + case MOD_INIT_TEXT: /* fallthrough */ + case MOD_INIT_DATA: /* fallthrough */ + case MOD_INIT_RODATA: /* fallthrough */ + kmemleak_ignore(ptr); + break; + default: + kmemleak_not_leak(ptr); + } if (!ptr) { t = type; goto out_enomem; -- 2.39.2