From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0B15C10F1A for ; Tue, 7 May 2024 23:41:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E1B96B0082; Tue, 7 May 2024 19:41:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3919B6B0088; Tue, 7 May 2024 19:41:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 259ED6B0089; Tue, 7 May 2024 19:41:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 07C546B0082 for ; Tue, 7 May 2024 19:41:19 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7506F140FAD for ; Tue, 7 May 2024 23:41:18 +0000 (UTC) X-FDA: 82093223436.19.C460966 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id B0E2CC0002 for ; Tue, 7 May 2024 23:41:15 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=WH1d1Zrd; spf=pass (imf28.hostedemail.com: domain of mhiramat@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715125275; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=toxbKtlios/OXMsWkELSsG4wmGzSzCKNfORqN1i40yw=; b=JbDHNlIQaoCU/eYmUuCfdgjMsJMMXtXc0r0vUEbAedVy0S8bh0LSGKIr886GaZej5ziBoW qC8XgdbWpQnB+0Ev/pJtJMnQa39iX4OENpOYS2OCoJZ51UVpsbTHFHWzy2CReTiat2Pm1S DGFrjOpSqdwfM7l3xPc34uQF1wH3AXM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715125275; a=rsa-sha256; cv=none; b=MXN0ZGjGw0DWMnHhLLxiJUeDvhTY0UdYfBDKkKwsLJom5hUlzQILOWrmqWz1CqVoo3LF+8 ihFfcSEZrlObMC1rbvWL0Q89v5Xm7kVUN29uC2SmVGCi1gpn0eSbY79HnXXTFlClZFreps lMjobV1N9sxjEUriqYydZSlskoZimH4= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=WH1d1Zrd; spf=pass (imf28.hostedemail.com: domain of mhiramat@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 5A11261B3C; Tue, 7 May 2024 23:41:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D7C2C2BBFC; Tue, 7 May 2024 23:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715125273; bh=ODKOUMcSjW/vZC3ltI6tPmb1ZIxhx2e2qI8/N+kVOFM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WH1d1ZrdOijFn1cT49Jm2ZUSrhswkNac03IVHqq7Eohwb66eyC/upbIRg5OmSQrS5 590jVcfK2eY7mGIT+Mu2vfZ+2kgvT+bvvG+nO0mpjkaiB/hzuVoCqKdsgEfcB6GUI1 tZHVMdm8HMaoJWCDDdSEsUeSS2shrn9LwS64jApcEtp551mG5S0J2RXLfrbG59V5J/ HlHuUhoLZsEzbSOo52SetyHK+GisTyafXt2qQ3WQN6uI/FPqAL3Mvb4Ag0onvgsMRn PVoqChvTS3nyekeTg4nrB1W8PoOH/gLtrOXEqRETwcHpFeC7NS6eZgZtaW77r3KgQl SXWjnlSGSut3Q== Date: Wed, 8 May 2024 08:41:02 +0900 From: Masami Hiramatsu (Google) To: Mike Rapoport Cc: linux-kernel@vger.kernel.org, Alexandre Ghiti , Andrew Morton , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , Philippe =?UTF-8?B?TWF0aGlldS1EYXVkw6k=?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, netdev@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH RESEND v8 05/16] module: make module_memory_{alloc,free} more self-contained Message-Id: <20240508084102.9e9b18a9b111d427e7cc9c94@kernel.org> In-Reply-To: <20240505160628.2323363-6-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> <20240505160628.2323363-6-rppt@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Stat-Signature: wnn44sdgyjyswothqwbapfkaftdazsnc X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: B0E2CC0002 X-HE-Tag: 1715125275-397018 X-HE-Meta: U2FsdGVkX19MlsSEFA1zBbjZAGeF8HC9ivvO6qcXCPDb1B+J6J/wHp2s/fqHMH1eYToprYL7LpKWjRiKDiJcWzIvmNt8tJgLpQe/eJpa6KLiGmlmFYjR0BnnjhUDSpWTurqGoNdvGxwC9PcmlZxNjE67cxcTfKNhctkwD5ETfDKztTvi5usyRx65TA9zFcQ93btktA02cMYA8WMDrzsIoBGFUpae2OuFYwE1/CIfpUt/XKnnsmf70f5osnKNrFe/gh87K9f8q1QPObmQscXDRTPxX/fGfQHsPCec302hMN4NdUHxYT54ZqFN6CkLXbI+h7NQbD2nLS/oA622UY/HooyE0bLMPpXAfqSE/MINUJ4E4Tolt4E2U5+tiSppnErk6xDkJSA81kg6Z9m1Xl4t/tG8sB9/d1PGmzy1AW3RaFn/45bSchuHhVDLxyoSLVmXBgjl9our34PaYKcpP5LMIp+uN7WXAoxnRn+oIn1MHtKYkYo2j3LsYGv7k0uzMqDHakUOsrdjz1ItjBQ+SEvFlqJV8yxVe1hccp/qrxoel1RB4zldsysA6HW/TVO9ALinGCbJA8QA01trfHoUR+f/WFoP7E4NW10znyRiyxC8mdLnI3w02TGHLyC1MRD1ZECuXbOTpjZN3KsyFuLpaigH7TCbH+39N3sFIja85lXaeihLayoMHSWwOeX0hIlsKoCXQ/k2TZEI4AUkbX+MItrA7QoE9Ubu9BphSBbhao3HT3gNji7l0KHrqu1/GuCYiV+tWHUxg8T8MSdnESuWH07BtF1zBZ7v48+a/BfcsFDwho/xZqIHk94uKjgn+6dLrGA02gqS9me2AFSN2IGYI3Kz1wOwsU8unviliO1VUp/W5eaua4WikC3kkD5K6NyB0Fv8OSRUxbozhnjZDS8Qu7ge753BGQIkrH+4E1U9pRxzD/Q//S+TUj/Gmgem4UtASj4E99hVdESZsAsn/pv2oZx 0pR080GR W45hLUvYDyMTkav7izwM1e9GOxKTkoMLrgswoqBqNQk/U9fQnBFX+1q5SDNMJCQlMh04VZQQDW1q30sPXrBIz6ZNCKfMDlbie1IL5+m/qTf7T2SxeZOs/k5R57Eb+Jel740PLvC4p6vlhlIRnvnN+xFj+0wp4XvQCiW1cLTwcVosWnmc6tTAOBpEvKjDcPLdFvhsmcG8fxstwElJavfGeDQj9FH5ZEXCMbOU6J7iSHKnN3CYMFgxLNc+XlTUW2tIhoCfwUo/NRYOSnfADyq8VXsgTG9ESxjQQqX9bUKHruvY6eINtt9Ms291AOLmstuCE1olDemUXjnH9Lg0Padv28bRg8WJ9qEoxGKvfGbcdrAaFWk+EnqSrpk25Br5ShAmPsGEWNWP9WXDnQJSrr8MEQa8EyvXcQz9GvlA4oId1QIyzhc4gFsrvF+DkvI7Mvh11B6MIDSSdRyGn18xgj0FGlKjatcdzVqQY3B3o X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Sun, 5 May 2024 19:06:17 +0300 Mike Rapoport wrote: > From: "Mike Rapoport (IBM)" > > Move the logic related to the memory allocation and freeing into > module_memory_alloc() and module_memory_free(). > Looks good to me. Reviewed-by: Masami Hiramatsu (Google) Thanks, > Signed-off-by: Mike Rapoport (IBM) > Reviewed-by: Philippe Mathieu-Daudé > --- > kernel/module/main.c | 64 +++++++++++++++++++++++++++----------------- > 1 file changed, 39 insertions(+), 25 deletions(-) > > diff --git a/kernel/module/main.c b/kernel/module/main.c > index e1e8a7a9d6c1..5b82b069e0d3 100644 > --- a/kernel/module/main.c > +++ b/kernel/module/main.c > @@ -1203,15 +1203,44 @@ static bool mod_mem_use_vmalloc(enum mod_mem_type type) > mod_mem_type_is_core_data(type); > } > > -static void *module_memory_alloc(unsigned int size, enum mod_mem_type type) > +static int module_memory_alloc(struct module *mod, enum mod_mem_type type) > { > + unsigned int size = PAGE_ALIGN(mod->mem[type].size); > + void *ptr; > + > + mod->mem[type].size = size; > + > if (mod_mem_use_vmalloc(type)) > - return vzalloc(size); > - return module_alloc(size); > + ptr = vmalloc(size); > + else > + ptr = module_alloc(size); > + > + if (!ptr) > + return -ENOMEM; > + > + /* > + * 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 *could* treat them > + * slightly differently with kmemleak_ignore() and only grey > + * them out as they work as typical memory allocations which > + * *do* eventually get freed, but let's just keep things simple > + * and avoid *any* false positives. > + */ > + kmemleak_not_leak(ptr); > + > + memset(ptr, 0, size); > + mod->mem[type].base = ptr; > + > + return 0; > } > > -static void module_memory_free(void *ptr, enum mod_mem_type type) > +static void module_memory_free(struct module *mod, enum mod_mem_type type) > { > + void *ptr = mod->mem[type].base; > + > if (mod_mem_use_vmalloc(type)) > vfree(ptr); > else > @@ -1229,12 +1258,12 @@ static void free_mod_mem(struct module *mod) > /* Free lock-classes; relies on the preceding sync_rcu(). */ > lockdep_free_key_range(mod_mem->base, mod_mem->size); > if (mod_mem->size) > - module_memory_free(mod_mem->base, type); > + module_memory_free(mod, type); > } > > /* MOD_DATA hosts mod, so free it at last */ > lockdep_free_key_range(mod->mem[MOD_DATA].base, mod->mem[MOD_DATA].size); > - module_memory_free(mod->mem[MOD_DATA].base, MOD_DATA); > + module_memory_free(mod, MOD_DATA); > } > > /* Free a module, remove from lists, etc. */ > @@ -2225,7 +2254,6 @@ static int find_module_sections(struct module *mod, struct load_info *info) > static int move_module(struct module *mod, struct load_info *info) > { > int i; > - void *ptr; > enum mod_mem_type t = 0; > int ret = -ENOMEM; > > @@ -2234,26 +2262,12 @@ static int move_module(struct module *mod, struct load_info *info) > mod->mem[type].base = NULL; > continue; > } > - mod->mem[type].size = PAGE_ALIGN(mod->mem[type].size); > - ptr = module_memory_alloc(mod->mem[type].size, type); > - /* > - * 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 *could* treat them > - * slightly differently with kmemleak_ignore() and only grey > - * them out as they work as typical memory allocations which > - * *do* eventually get freed, but let's just keep things simple > - * and avoid *any* false positives. > - */ > - kmemleak_not_leak(ptr); > - if (!ptr) { > + > + ret = module_memory_alloc(mod, type); > + if (ret) { > t = type; > goto out_enomem; > } > - memset(ptr, 0, mod->mem[type].size); > - mod->mem[type].base = ptr; > } > > /* Transfer each section which specifies SHF_ALLOC */ > @@ -2296,7 +2310,7 @@ static int move_module(struct module *mod, struct load_info *info) > return 0; > out_enomem: > for (t--; t >= 0; t--) > - module_memory_free(mod->mem[t].base, t); > + module_memory_free(mod, t); > return ret; > } > > -- > 2.43.0 > -- Masami Hiramatsu (Google)