Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp279696rwl; Tue, 4 Apr 2023 23:56:05 -0700 (PDT) X-Google-Smtp-Source: AKy350ZaCKh7zHQkBKEttcIjZUvgGgUVCeo9V1mUKDyUXb8ijrLhcuUYOskCkTeUYgyvDHtc0Bow X-Received: by 2002:aa7:cc0b:0:b0:4fa:d75c:16c6 with SMTP id q11-20020aa7cc0b000000b004fad75c16c6mr733547edt.38.1680677765543; Tue, 04 Apr 2023 23:56:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680677765; cv=none; d=google.com; s=arc-20160816; b=u+Asu6TdtCudqLE8F1AZDWtShpRVAO6FnKA7Qoio11MXM/L4BdG5hO+to3X6Ero1Av 2Nrf7zvIa0mMZwUs9pvdRVLbpDGsKRE9nLsiHdegyQ99jtqexvhFDuo51h5SR3xhAEQv TYz7X8I2bzjNoUP8C21OSwPsbymEHKiXTYn0qrZORkrRycEFyqNi+Ux/cFdK2n4ZIVzT vP0sRSo0Ly93j4KSDeKi/WDKU+oXIxAaXVcv2D8sxTI/6n1FxbDM/0uH4pdny5nilajo gdFs8InHlE1S+drHK34qNkohx92iH8rGWfCIe9PWouuxxmndz/p7iOmf6BN9VGFfxHKb dzkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=lAilofri596eScwRNLRZrxRUNrylNWtKF02FeVhA9us=; b=Za+zzw7TxZBEO2KL7cAJAx6PXFRa/krmX6t8oDbujCJdBU2JpTemiwb8r6YiomA5O7 ALEFa0Py89XoVMfYGHU4hZdpmcEJgcL+4JczXE7QygQZtZ0VJ5L2yQCpQszawHXGxR/Q wY7b+SMpXpHWX2QJfgDGhhERnPO4n8h4BT5iQXjHIhE9EYaaF92orKvPvpYhnbrVRFyH 5jWrOh8Fjg4/tmDqajIqHtswdbINQBHcRQaDQjkl31TDhDLKppgljdHVDHtxG9asPYsO zsPjfCTzZoqWyA5QmojneLsqoY7JmfCKOdSS9bLFUxy3hjqQLQETty6wpchRdpWJ3Oza blxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lkT4mgj2; 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 y10-20020a50eb0a000000b004f0f197860fsi2164462edp.264.2023.04.04.23.55.40; Tue, 04 Apr 2023 23:56:05 -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=@kernel.org header.s=k20201202 header.b=lkT4mgj2; 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 S236778AbjDEGwk (ORCPT + 99 others); Wed, 5 Apr 2023 02:52:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229943AbjDEGwj (ORCPT ); Wed, 5 Apr 2023 02:52:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BE4C3A8E; Tue, 4 Apr 2023 23:52:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AA0F0622C7; Wed, 5 Apr 2023 06:52:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CCC7C433B0; Wed, 5 Apr 2023 06:52:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680677557; bh=XUuQ7Bb4fmNGW4BDO3pXmRn2zVkwWZkSaUU2boHvL/M=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=lkT4mgj2agKQd29h+FxK0YhPn8c6UtfOswmOyb6crEefOooUhJPp0ZN6HKwz7n0Rc Xi4Sq8YwJOWswjT0ihPhVUEaAKhw/lvD4AZgZyduhRzIdvrbgZo20pcFr6z/zfli6A LejdkVLtw+4Kwp8zZJQSPnsIXcXD31u03m6zZooDEdVO4KIU1obmny/HMw8przOfmH o986LodMYnqZGJDK8/UhoIphMjw1poxwqr4HbzaoGu75cB8uAoWUmNrPiuUV/hwkfb GdMKKJtaJK1OcSRpbB6iZv2+TO3Bb9aGYs18l2bHa/hVkA1FxBtcNuZaLxO1kBux2J fodldYHrBFbCg== Received: by mail-lj1-f176.google.com with SMTP id by14so17109769ljb.12; Tue, 04 Apr 2023 23:52:37 -0700 (PDT) X-Gm-Message-State: AAQBX9fWyBKDawOBEZ48qHe/af/h1CQvzQuLYwBxJ0y9ZGVVakhdnMlK /pEJSJKIB64+tJ26SExGBIITpDMrawnFkUREDN4= X-Received: by 2002:a2e:824a:0:b0:299:b5e6:4c45 with SMTP id j10-20020a2e824a000000b00299b5e64c45mr1866847ljh.5.1680677554868; Tue, 04 Apr 2023 23:52:34 -0700 (PDT) MIME-Version: 1.0 References: <20230405022702.753323-1-mcgrof@kernel.org> <20230405022702.753323-2-mcgrof@kernel.org> In-Reply-To: <20230405022702.753323-2-mcgrof@kernel.org> From: Song Liu Date: Tue, 4 Apr 2023 23:52:22 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/6] module: fix kmemleak annotations for non init ELF sections To: Luis Chamberlain Cc: david@redhat.com, patches@lists.linux.dev, linux-modules@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pmladek@suse.com, petr.pavlu@suse.com, prarit@redhat.com, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, rafael@kernel.org, christophe.leroy@csgroup.eu, tglx@linutronix.de, peterz@infradead.org, rppt@kernel.org, dave@stgolabs.net, willy@infradead.org, vbabka@suse.cz, mhocko@suse.com, dave.hansen@linux.intel.com, colin.i.king@gmail.com, jim.cromie@gmail.com, catalin.marinas@arm.com, jbaron@akamai.com, rick.p.edgecombe@intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS 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 4, 2023 at 7:27=E2=80=AFPM Luis Chamberlain = wrote: > > 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 handled kmemleak_ignore() or kmemleak_not_leak= () > for different ELF 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 Acked-by: Song Liu Thanks for the fix! > --- > 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..d8bb23fa6989 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 =3D module_memory_alloc(mod->mem[type].size, type); > > /* > - * The pointer to this block is stored in the module stru= cture > - * which is inside the block. Just mark it as not being a > - * leak. > + * The pointer to these blocks of memory are stored on th= e module > + * structure and we keep that around so long as the modul= e is > + * around. We only free that memory when we unload the mo= dule. > + * Just mark them as not being a leak then. The .init* EL= F > + * sections *do* get freed after boot so we treat them sl= ightly > + * differently and only grey them out -- they work as typ= ical > + * memory allocations which *do* 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 =3D type; > goto out_enomem; > -- > 2.39.2 >