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 B9175C531DF for ; Tue, 20 Aug 2024 11:10:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E27F6B007B; Tue, 20 Aug 2024 07:10:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 291BD6B0082; Tue, 20 Aug 2024 07:10:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1597C6B0083; Tue, 20 Aug 2024 07:10:24 -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 EB0D16B007B for ; Tue, 20 Aug 2024 07:10:23 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 85BF1141A45 for ; Tue, 20 Aug 2024 11:10:23 +0000 (UTC) X-FDA: 82472355126.19.D0D8312 Received: from out-187.mta0.migadu.com (out-187.mta0.migadu.com [91.218.175.187]) by imf19.hostedemail.com (Postfix) with ESMTP id D4ED41A0014 for ; Tue, 20 Aug 2024 11:10:19 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=NP8bQsKX; spf=pass (imf19.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.187 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724152143; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UrvRMz+I1gRJfeA35OXeWpHMimIWlbjsoNl2/JOsDPI=; b=Gcqs70z/DSUUqau4eQ5SNUVrF60rXyuLXhSWq5r8MOhk+yTR7b/Oc0DIb+/O9zBMkYxswi oNPYNuFs+XzwFY0PGXYY6lWK6CYPOoB2cLP6lgppMW176EN9xf5DK0NS3sdu0DHXOsY/7Y CBVwyGkYiWQi/1s0QPLgR9eFMqqIpwc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724152143; a=rsa-sha256; cv=none; b=EchKnkPJy+NgAmfCmvcsNH7r1sdHGX57ftdanB2xxiWrgiFejLrWXGoGM4/BHj2KWMROi0 ouuxQyGH+wrNUk6yVr+9vnnq7Y8BO4eYzjvsiVPzfu3DC1kTc2BJN7rnzPrLE4HwbpW68z RU7pFz7IWX5Jzq+VbQx39IeoFaJ0njE= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=NP8bQsKX; spf=pass (imf19.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.187 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Date: Tue, 20 Aug 2024 07:10:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724152217; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UrvRMz+I1gRJfeA35OXeWpHMimIWlbjsoNl2/JOsDPI=; b=NP8bQsKXUU0lsovxuRtz0Ny98VqZ6sb3M0pF7We+DamT+Nkxzg+jEfcz/+so+XoYucaCwl HyHe1BH61bKKin9KYl5it34q73DaQAIAISB/XzkwT6U1NBU4njeT6fpwDxpd4AvPofWpZ/ OMZcGIne2AwXUUICsUeUxK7QRHF+ObM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Mike Rapoport Cc: Suren Baghdasaryan , akpm@linux-foundation.org, corbet@lwn.net, arnd@arndb.de, mcgrof@kernel.org, paulmck@kernel.org, thuth@redhat.com, tglx@linutronix.de, bp@alien8.de, xiongwei.song@windriver.com, ardb@kernel.org, david@redhat.com, vbabka@suse.cz, mhocko@suse.com, hannes@cmpxchg.org, roman.gushchin@linux.dev, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, pasha.tatashin@soleen.com, souravpanda@google.com, keescook@chromium.org, dennis@kernel.org, jhubbard@nvidia.com, yuzhao@google.com, vvvvvv@google.com, rostedt@goodmis.org, iamjoonsoo.kim@lge.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH 1/5] alloc_tag: load module tags into separate continuous memory Message-ID: References: <20240819151512.2363698-1-surenb@google.com> <20240819151512.2363698-2-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Stat-Signature: ayryqps5wi4ztetob879r99k74u9573f X-Rspamd-Queue-Id: D4ED41A0014 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724152219-117213 X-HE-Meta: U2FsdGVkX1+0yIon/KQmNKkMlvkf+hCQO1RMf1jUhMFu/jIipeiJ07ZJygvpkNQ0YVGoj6tHeMwcUJeJfmV5zKLhBRkdQzrfGRocurveh8Tc02oY6f1OjLnCOEgBkhZcWahOVZJH+/LOOASdTM2Fhl68eX3Cd7hj1WvOLNuHKt7Onl3zuIEuMoJfN+v/KYCejXQDOlxyz8zAzTMzWvcKC/8GyQMs0P5tbUC/Ngw3fK/JRYfhKKPoIMT3qynzctfniKbKIuBaWJDLYlzppwgQotf46NWtregTiKOGZNT02RhgsF+YDRuurnONdj75AEGa6HwIcMEqTDJIlXP7+QrX72fpYEvFYL2hgLAEWOaDywTLYJISXuJ/GfVeCsO32SZksuBm0okGuuL++X2WUja6FZ4z+kDRNvMB8wj+pBaktfAb2dFFyk4GSZp8zhoXe8NC1heMz+/cfw+8utgvKdvFMB1XgLi3FFZZH1ag7vQL67KJEyOlFPVZO1MjjXArhFClBe6KXTVX3ancmAr7ywXzYchDt2pXb4IeSuWVwRvfeECsvmgdDVF+JzqpWNLwJqwhSBsOpBoBN0ibLojXi8a4aUjdZ3g8lH9dU7puWBhPd/Pxr1wa03qazCChyHcdCFulMeeU10bT79ry4Pt6lbvHeOSJE/GwSMx/dbGXqE6D98LZ9i+o0gSn7H3/8bPWET+H1zT+YORyWUFb+V0UZUY0PsLL3y50riQti83GYj6S477bCkWR8Y53AMIvvvEpYVzGu2hLVXQCXlU54DDFUs14Zb4YJfnpvhsM+cJHKxG5FKJmEI4Vv3t9MEXggf/bd1vlBKBSZV/K4mD5UXMNYdky93I/PLrNR9QSKCKgAwzMCWSat+6JedYL/TKFqrlFmXoRaNgCH8uRMVCIMclIHqaVHa3LViDJKKgoU/HZb1tgwtTHmp27PgumMlALWtPd3RkRj1Xg69xO/LSYAuM6zan UP3jGKdg MjcVBLUXtsq6CFW/E3DfXeYurmEj1+/BgwyYRr5r32bqgDRoMoXCU/7osJoEtqCjWGspDONghoyfOTrK42QV8nPIQMLKi2XBGSZ919gblR5qZbhM9ZN58gXopkbkpE5HN8Bnaf3edFzG5CuFbxDWjyPAtMHmBFk9hOU4hv3MrlBjgyBVHXTtnBLMxjJc9bCX5VgTg 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 Tue, Aug 20, 2024 at 10:13:07AM GMT, Mike Rapoport wrote: > On Mon, Aug 19, 2024 at 08:15:07AM -0700, Suren Baghdasaryan wrote: > > When a module gets unloaded there is a possibility that some of the > > allocations it made are still used and therefore the allocation tags > > corresponding to these allocations are still referenced. As such, the > > memory for these tags can't be freed. This is currently handled as an > > abnormal situation and module's data section is not being unloaded. > > To handle this situation without keeping module's data in memory, > > allow codetags with longer lifespan than the module to be loaded into > > their own separate memory. The in-use memory areas and gaps after > > module unloading in this separate memory are tracked using maple trees. > > Allocation tags arrange their separate memory so that it is virtually > > contiguous and that will allow simple allocation tag indexing later on > > in this patchset. The size of this virtually contiguous memory is set > > to store up to 100000 allocation tags and max_module_alloc_tags kernel > > parameter is introduced to change this size. > > > > Signed-off-by: Suren Baghdasaryan > > --- > > .../admin-guide/kernel-parameters.txt | 4 + > > include/asm-generic/codetag.lds.h | 19 ++ > > include/linux/alloc_tag.h | 13 +- > > include/linux/codetag.h | 35 ++- > > kernel/module/main.c | 67 +++-- > > lib/alloc_tag.c | 245 ++++++++++++++++-- > > lib/codetag.c | 101 +++++++- > > scripts/module.lds.S | 5 +- > > 8 files changed, 429 insertions(+), 60 deletions(-) > > ... > > > diff --git a/include/linux/codetag.h b/include/linux/codetag.h > > index c2a579ccd455..c4a3dd60205e 100644 > > --- a/include/linux/codetag.h > > +++ b/include/linux/codetag.h > > @@ -35,8 +35,13 @@ struct codetag_type_desc { > > size_t tag_size; > > void (*module_load)(struct codetag_type *cttype, > > struct codetag_module *cmod); > > - bool (*module_unload)(struct codetag_type *cttype, > > + void (*module_unload)(struct codetag_type *cttype, > > struct codetag_module *cmod); > > + void (*module_replaced)(struct module *mod, struct module *new_mod); > > + bool (*needs_section_mem)(struct module *mod, unsigned long size); > > + void *(*alloc_section_mem)(struct module *mod, unsigned long size, > > + unsigned int prepend, unsigned long align); > > + void (*free_section_mem)(struct module *mod, bool unused); > > }; > > > > struct codetag_iterator { > > @@ -71,11 +76,31 @@ struct codetag_type * > > codetag_register_type(const struct codetag_type_desc *desc); > > > > #if defined(CONFIG_CODE_TAGGING) && defined(CONFIG_MODULES) > > + > > +bool codetag_needs_module_section(struct module *mod, const char *name, > > + unsigned long size); > > +void *codetag_alloc_module_section(struct module *mod, const char *name, > > + unsigned long size, unsigned int prepend, > > + unsigned long align); > > +void codetag_free_module_sections(struct module *mod); > > +void codetag_module_replaced(struct module *mod, struct module *new_mod); > > void codetag_load_module(struct module *mod); > > -bool codetag_unload_module(struct module *mod); > > -#else > > +void codetag_unload_module(struct module *mod); > > + > > +#else /* defined(CONFIG_CODE_TAGGING) && defined(CONFIG_MODULES) */ > > + > > +static inline bool > > +codetag_needs_module_section(struct module *mod, const char *name, > > + unsigned long size) { return false; } > > +static inline void * > > +codetag_alloc_module_section(struct module *mod, const char *name, > > + unsigned long size, unsigned int prepend, > > + unsigned long align) { return NULL; } > > +static inline void codetag_free_module_sections(struct module *mod) {} > > +static inline void codetag_module_replaced(struct module *mod, struct module *new_mod) {} > > static inline void codetag_load_module(struct module *mod) {} > > -static inline bool codetag_unload_module(struct module *mod) { return true; } > > -#endif > > +static inline void codetag_unload_module(struct module *mod) {} > > + > > +#endif /* defined(CONFIG_CODE_TAGGING) && defined(CONFIG_MODULES) */ > > Maybe I'm missing something, but can't alloc_tag::module_unload() just copy > the tags that cannot be freed somewhere outside of module sections and then > free the module? > > The heavy lifting would be localized to alloc_tags rather than spread all > over. The reason they can't be freed is because they're referenced by slab/page allocatons - can't move them either.