Re: [RFC PATCH] binfmt_elf: Align eligible read-only PT_LOAD segments to PMD_SIZE for THP
From: Matthew Wilcox
Date: Tue Mar 03 2026 - 00:33:03 EST
On Tue, Mar 03, 2026 at 12:31:59PM +0800, hev wrote:
> On Tue, Mar 3, 2026 at 12:46 AM Matthew Wilcox <willy@xxxxxxxxxxxxx> 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.
This isn't reasonable at all. You're asking distro maintainers to make
a decision they have insufficient information to make. Almost none of
our users compile their own kernels, and frankly those that do don't have
enough information to make an informed decision about which way to choose.
So if we're going to have a way to opt in/out, it needs to be something
different. Maybe a heuristic based on size of text segment? Maybe an
ELF flag? But then, if we're going to modify the binary, why not just
set p_align and then we don't need this patch at all?