From: Bradley Morgan <brads@mainlining.org>
To: ardb+git@google.com
Cc: abarnas@google.com, akpm@linux-foundation.org, ardb@kernel.org,
atomlin@atomlin.com, catalin.marinas@arm.com,
da.gomez@kernel.org, kevin.brodsky@arm.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-modules@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, mark.rutland@arm.com,
mcgrof@kernel.org, mhiramat@kernel.org, petr.pavlu@suse.com,
rostedt@goodmis.org, rppt@kernel.org, ryan.roberts@arm.com,
samitolvanen@google.com, will@kernel.org
Subject: Re: [RFC PATCH 4/9] module: Allocate MOD_INIT_TEXT from the MOD_TEXT ROX allocation
Date: Fri, 28 Aug 2026 15:11:08 +0100 [thread overview]
Message-ID: <5D55C497-95FF-4603-98E4-8C47CDAB504C@mainlining.org> (raw)
In-Reply-To: <20260822135323.795946-15-ardb+git@google.com>
On 22 August 2026 14:53:26 BST, Ard Biesheuvel <ardb+git@google.com> wrote:
>From: Ard Biesheuvel <ardb@kernel.org>
>
>When execmem ROX caches are used for module text and inittext, place
>them adjacently in memory, by allocating space for both initially, and
>splitting off the space for MOD_INIT_TEXT as needed.
>
>This avoids the corner case on arm64, where .init.text being placed far
>from .text results in a lot of complexity wrt indirect branches and PLTs
>that we'd prefer to avoid.
>
I can't see anything wrong, thanks for the patch
Reviewed-by: Bradley Morgan <brads@mainlining.org> # kernel/
>Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
>---
> kernel/module/main.c | 22 ++++++++++++++++----
> 1 file changed, 18 insertions(+), 4 deletions(-)
>
>diff --git a/kernel/module/main.c b/kernel/module/main.c
>index 46dd8d25a605..2d6213496359 100644
>--- a/kernel/module/main.c
>+++ b/kernel/module/main.c
>@@ -1342,7 +1342,7 @@ static int module_memory_alloc(struct module *mod, enum mod_mem_type type)
> {
> unsigned int size = PAGE_ALIGN(mod->mem[type].size);
> enum execmem_type execmem_type;
>- void *ptr;
>+ void *ptr = NULL;
>
> mod->mem[type].size = size;
>
>@@ -1351,11 +1351,25 @@ static int module_memory_alloc(struct module *mod, enum mod_mem_type type)
> else
> execmem_type = EXECMEM_MODULE_TEXT;
>
>- ptr = execmem_alloc_rw(execmem_type, size);
>+ bool is_rox = execmem_is_rox(execmem_type);
>+ if (is_rox) {
>+ /*
>+ * Special case for MOD_TEXT / MOD_INIT_TEXT: allocate the
>+ * latter by splitting off required space from the former
>+ * so that they are always placed close together.
>+ */
>+ if (type == MOD_TEXT)
>+ size += PAGE_ALIGN(mod->mem[MOD_INIT_TEXT].size);
>+ else if (type == MOD_INIT_TEXT)
>+ ptr = execmem_split(mod->mem[MOD_TEXT].base, size);
>+ }
>+
>+ if (!ptr)
>+ ptr = execmem_alloc_rw(execmem_type, size);
> if (!ptr)
> return -ENOMEM;
>
>- mod->mem[type].is_rox = execmem_is_rox(execmem_type);
>+ mod->mem[type].is_rox = is_rox;
>
> /*
> * The pointer to these blocks of memory are stored on the module
>@@ -1368,7 +1382,7 @@ static int module_memory_alloc(struct module *mod, enum mod_mem_type type)
> * *do* eventually get freed, but let's just keep things simple
> * and avoid *any* false positives.
> */
>- if (!mod->mem[type].is_rox)
>+ if (!is_rox)
> kmemleak_not_leak(ptr);
>
> memset(ptr, 0, size);
>
--- Thanks!
https://lore.kernel.org/all/EE579805-42F2-4C58-B752-F28779EEB717@grrlz.net/
next prev parent reply other threads:[~2026-08-28 14:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-22 13:53 [RFC PATCH 0/9] arm64: Allocate .text and .init.text together Ard Biesheuvel
2026-08-22 13:53 ` [RFC PATCH 1/9] mm: execmem: Add API to split an existing execmem cache allocation Ard Biesheuvel
2026-08-22 13:53 ` [RFC PATCH 2/9] mm: execmem: Allow huge vmappings to be avoided for execmem caches Ard Biesheuvel
2026-08-22 13:53 ` [RFC PATCH 3/9] module: Place MOD_TEXT before MOD_INIT_TEXT in enumeration Ard Biesheuvel
2026-08-22 13:53 ` [RFC PATCH 4/9] module: Allocate MOD_INIT_TEXT from the MOD_TEXT ROX allocation Ard Biesheuvel
2026-08-28 14:11 ` Bradley Morgan [this message]
2026-08-22 13:53 ` [RFC PATCH 5/9] arm64: mm: Permit permissions changes on huge vmappings Ard Biesheuvel
2026-08-23 16:52 ` Adrian Barnaś
2026-08-22 13:53 ` [RFC PATCH 6/9] arm64: Enable the execmem ROX cache for module text Ard Biesheuvel
2026-08-23 16:46 ` Adrian Barnaś
2026-08-22 13:53 ` [RFC PATCH 7/9] arm64: ftrace: Revert "fix unreachable PLT for ftrace_caller ..." Ard Biesheuvel
2026-08-22 13:53 ` [RFC PATCH 8/9] arm64: module: Combine init and core PLT entries again Ard Biesheuvel
2026-08-22 13:53 ` [RFC PATCH 9/9] arm64: ftrace: Simplify PLT handling Ard Biesheuvel
2026-08-28 13:07 ` [RFC PATCH 0/9] arm64: Allocate .text and .init.text together Petr Pavlu
2026-08-28 13:45 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5D55C497-95FF-4603-98E4-8C47CDAB504C@mainlining.org \
--to=brads@mainlining.org \
--cc=abarnas@google.com \
--cc=akpm@linux-foundation.org \
--cc=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=atomlin@atomlin.com \
--cc=catalin.marinas@arm.com \
--cc=da.gomez@kernel.org \
--cc=kevin.brodsky@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-modules@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mcgrof@kernel.org \
--cc=mhiramat@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=samitolvanen@google.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox