Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5676281rwl; Tue, 11 Apr 2023 08:31:55 -0700 (PDT) X-Google-Smtp-Source: AKy350ZeVW7RzdNl7rRhapFhqMBli9IfsA9xvrDXOBr0Q3tzvw2bicb8x1xmy/6/G72F6dZnMdY7 X-Received: by 2002:a17:903:805:b0:1a0:50bd:31c0 with SMTP id kr5-20020a170903080500b001a050bd31c0mr14471505plb.24.1681227115110; Tue, 11 Apr 2023 08:31:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681227115; cv=none; d=google.com; s=arc-20160816; b=iQ/j6REbQap7SiMwwHIlQK+mOuxFKKt/tUSAnAOuzBuQhWH+As33hasHZ2uQQSG20V ZyVwDnx3iQOfs+Kj3xSfxcGXdQr7P385nX5rSszXAEC4GzRLKSQ6WujQDQroQJOacfxi quIFrZ9IUQa2pcFLGBQfGdCXeuaLEYRjeea/S1QJtPCCEJcB6t/pxQM/wuFFYQMZMAny Gkf0BncnCEjDERHTJkYI7xhpjI3tRaczYNhSlJF6v6Fea2SFFshM6lwOOqVOlCdzEgWd atUDiM0B2/Y/q6lvJsR4BUGGagMPaumbffvATB3UE+tQW8H9qJFIv8p9ybAvVoqd1GOD e0AA== 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; bh=n1yGSM4Y7ifZcSHnvwNq4o7w6qrAWMrQH3AFgbFF2bQ=; b=huu1xTvhw2zG7xitBUkHdMcL546sksgiggeOSODJiXTXNsqH3wE2EYd2ldDJlsBFfK 9oIhFSAn/tVxdjKg0/cIVygxFI5T8bJ1rZPeyMi/4jgwPW01ORkWRjYpFWP+TXRoyu+u jicXpt/ElI8T60XF069RZc03fU1Ji5gkXWnbj/LXdPYud8HjquwsLwNtKj1HAtO48Teg XHFlagdPl4h4Mxk30tR/pVGNnQ/6w3sVuJi9jNrAqEAvuY6aIDzE3FhXhmtNMKIlfiE2 oEgr6E/HeWlEYQDug1IB7rqd03Hshf4hgQQJs5MmsJjMwGaYeE+YskUqFoR99b/1yg6E Z53A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jy14-20020a17090342ce00b001a652580118si2828654plb.237.2023.04.11.08.31.42; Tue, 11 Apr 2023 08:31:55 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229456AbjDKPVS (ORCPT + 99 others); Tue, 11 Apr 2023 11:21:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229616AbjDKPVQ (ORCPT ); Tue, 11 Apr 2023 11:21:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 465053C26; Tue, 11 Apr 2023 08:20:47 -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 A4E29625BE; Tue, 11 Apr 2023 15:17:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0237DC433EF; Tue, 11 Apr 2023 15:17:38 +0000 (UTC) Date: Tue, 11 Apr 2023 16:17:35 +0100 From: Catalin Marinas 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, song@kernel.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, jbaron@akamai.com, rick.p.edgecombe@intel.com Subject: Re: [PATCH v2 1/6] module: fix kmemleak annotations for non init ELF sections Message-ID: References: <20230405022702.753323-1-mcgrof@kernel.org> <20230405022702.753323-2-mcgrof@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230405022702.753323-2-mcgrof@kernel.org> X-Spam-Status: No, score=-4.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 04, 2023 at 07:26:57PM -0700, Luis Chamberlain wrote: > 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 = 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 -- they work as typical > + * 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); > + } This works as well but if you want to keep it simple, just call kmemleak_not_leak() in all cases. When freeing the init sections, they would be removed from the kmemleak tracing anyway. -- Catalin