From: hev <r@hev.cc>
To: Matthew Wilcox <willy@infradead.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Kees Cook <kees@kernel.org>,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] binfmt_elf: Align eligible read-only PT_LOAD segments to PMD_SIZE for THP
Date: Tue, 3 Mar 2026 12:31:59 +0800 [thread overview]
Message-ID: <CAHirt9j-appZ+Mn=8AoG=SW3Lrqi2ajdZDGp8yYWiBWkzBbQ9g@mail.gmail.com> (raw)
In-Reply-To: <aaW-x-HVQpSuPRA1@casper.infradead.org>
On Tue, Mar 3, 2026 at 12:46 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Mon, Mar 02, 2026 at 11:50:46PM +0800, WANG Rui wrote:
> > +config ELF_RO_LOAD_THP_ALIGNMENT
> > + bool "Align read-only ELF load segments for THP (EXPERIMENTAL)"
> > + depends on READ_ONLY_THP_FOR_FS
>
> This doesn't deserve a config option.
This optimization is not entirely free. Increasing PT_LOAD alignment
can waste virtual address space, which is especially significant on
32-bit systems, and it also reduces ASLR entropy by limiting the
number of possible load addresses.
In addition, coarser alignment may have secondary microarchitectural
effects (eg. on indirect branch prediction), depending on the
workload. Because this change affects address space layout and
security-related properties, providing users with a way to opt out is
reasonable, rather than making it completely unconditional. This
behavior fits naturally under READ_ONLY_THP_FOR_FS.
>
> > +#if defined(CONFIG_ELF_RO_LOAD_THP_ALIGNMENT) && PMD_SIZE <= SZ_32M
>
> Why 32MB? This is weird and not justified anywhere.
The 32MB limit is intended as a practical upper bound. With 16KB base
pages, which are commonly used on some 64-bit architectures, PMD_SIZE
is 32MB. Larger PMD sizes (eg. 128MB or more with 32KB pages) exist
but represent relatively extreme configurations where alignment costs,
virtual address space padding, and ASLR entropy loss grow
disproportionately relative to the expected THP benefit.
On 32-bit systems, this issue is even more pronounced: PMD_SIZE can
reach 128MB or 256MB depending on configuration, which is clearly
unreasonable as an alignment requirement given the already constrained
virtual address space. The cap therefore avoids these pathological
cases while still covering all realistic and widely deployed PMD huge
page sizes.
Thanks,
Rui
>
> > + if (hugepage_global_always() && !(cmds[i].p_flags & PF_W)
> > + && IS_ALIGNED(cmds[i].p_vaddr | cmds[i].p_offset, PMD_SIZE)
> > + && cmds[i].p_filesz >= PMD_SIZE && p_align < PMD_SIZE)
> > + p_align = PMD_SIZE;
>
> Normal style is to put the '&&' at the end of the line:
>
> if (!(cmds[i].p_flags & PF_W) &&
> IS_ALIGNED(cmds[i].p_vaddr | cmds[i].p_offset, PMD_SIZE) &&
> cmds[i].p_filesz >= PMD_SIZE && p_align < PMD_SIZE))
> p_align = PMD_SIZE;
>
> But this conditional is too complex to be at this level of indentation.
> Factor it out into a helper:
>
> if (align_to_pmd(cmds) && p_align < PMD_SIZE)
> p_align = PMD_SIZE;
>
next prev parent reply other threads:[~2026-03-03 4:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-02 15:50 WANG Rui
2026-03-02 16:45 ` Matthew Wilcox
2026-03-03 4:31 ` hev [this message]
2026-03-03 5:32 ` Matthew Wilcox
2026-03-03 7:00 ` hev
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='CAHirt9j-appZ+Mn=8AoG=SW3Lrqi2ajdZDGp8yYWiBWkzBbQ9g@mail.gmail.com' \
--to=r@hev.cc \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.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