From: "Ard Biesheuvel" <ardb@kernel.org>
To: "H . Peter Anvin" <hpa@zytor.com>,
"Ard Biesheuvel" <ardb+git@google.com>,
x86@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org
Subject: Re: [PATCH] x86: Make the 64-bit bzImage always physically relocatable
Date: Thu, 19 Nov 2026 10:58:55 +0100 [thread overview]
Message-ID: <1cba56de-1094-4245-9100-2598039a09f7@app.fastmail.com> (raw)
In-Reply-To: <f2297061-4ad1-4ece-89de-5459816e5461@zytor.com>
On Wed, 18 Nov 2026, at 20:35, H. Peter Anvin wrote:
> On 2026-11-18 09:26, Ard Biesheuvel wrote:
>>>> ...
>>>>> I'm going to vote NAK on this one... I was already thinking that it
>>>>> would mess up low-level debugging too much,
>>>>
>>>> How so? The last time I proposed this, you replied that you were
>>>> planning to do this yourself.
>>>>
>>>> https://lore.kernel.org/all/3f2e8d7c-6029-49ef-8e31-a3eb5efb385b@zytor.com/
>>>>
>>>
>>> If we are going to get rid of it, we should get rid of it properly as
>>> in removing the conditional machinery,
>>
>> Which conditional machinery is that? All the code that reasons about the
>> physical load address needs to stay, the only thing I am changing here
>> is that you can no longer disable it on x86_64, as there is no upside to
>> forcing the 64-bit kernel to run from a fixed physical address. This
>> means the EFI stub no longer needs to depend on CONFIG_RELOCATABLE
>> (which also controls the generation for relocation data for virtual
>> displacement) for x86_64.
>>
>> The i386 situation is different, but I left that alone on purpose.
>> Would you prefer it if that always became relocatable as well?
>>
>
> Yes, if we're going to do it, it would make more sense to do exactly that.
>
OK I'll go that way then.
>>> not use it as a backdoor for
>>> doing something explicitly NAKed (forcing PIC compilation.)
>>>
>>
>> I know PIC compilation is a sensitive subject for some people, but
>> would you mind not framing this as some backhanded action on my part?
>>
>> Once I get to resending that series, you will have ample opportunity
>> to voice your concerns and suggest workloads that will prove that
>> it is infeasible. Or even provide one now so that I won't have to
>> bother resending it in the first place.
>
> I do (genuinely) apologize; that was indeed *quite* uncalled for.
>
Thanks, much appreciated.
> What I *do* think is a real problem -- and you are far from the only or
> worst offender -- is to put a vague "future improvements" as
> justification for a change. This is literally asking people to take on
> faith that the "future improvements" is actually an engineering
> direction we want to go in.
>
Point taken.
Since we are discussing the future respin of my PIC proposal here, let
me address those points as well.
> PIC compilation is another matter entirely (as you also very correctly
> point out!), as x86 unlike most RISC architectures has enough direct
> addressing reach to encompass the entire kernel (in the "medium" model
> for user space and the "kernel" model for kernel space.) This means that
> x86 benefits from GOT/PLT elision in ways that many other architectures
> don't. On the flipside, because x86 is a CISC architecture once you give
> atup performance in the compiler stage it is very hard to recover it
> even in the linker stage. Furthermore, on i386 PIC is *extremely*
> painful since it involves giving up one of only 7 usable GPRs (6 if you
> are compiling with frame pointers!) and a relatively expensive
> sequence(*) to get EIP manifest.
>
> As a result, I very much will continue to object to PIC compilation on
> x86 as opposed to boot time relocation. Whereas code patching in user
> space is expensive due to breaking sharing and thus demand paging of
> executables and libraries, none of that applies to the kernel -- and we
> do runtime code patching of the kernel anyway. The relocation is just a
> special case of that.
>
Please wait for me to make my proposal before shooting it down. You are
making assumptions about the impact these changes will have without ever
having looked at them.
I am not proposing any changes to i386.
I am not proposing the use of GOTs, PLTs, etc.
What I will be proposing is the use of RIP-relative references instead of
sign-extended 32-bit references to global symbols. The reason for that is
that this will allow use to run the linker in -pie mode, which then produces
all metadata that traditional kaslr needs at boot time.
> Now I do know you don't like the compressed kernel relocation format
> (which you are not trying to change with this patch) and it is *most
> certainly* insufficiently expressive for fgKASLR. For fgKASLR you need
> to know the relocation base rather than a simple adjustment factor, even
> on an architecture like x86 that doesn't have to deal with "upper
> part"-type relocations (for which the compressed format approach,
> carrying embedded addends, completely collapses.)
PIE linking allows the use of RELR packing, which reduces the size of
these compressed kernel relocations by about 95%. This is the same
format used by PIE in user space, as well as other architectures in
Linux.
The size increase of .text is between 0.3% and 0.5%, and none of the
benchmarks I've tried showed any significant performance impact on
the micro-architectures I have access to. With this patch applied,
you get those 0.5% back if you disable CONFIG_RANDOMIZE_BASE. This
is the future work I was referring to.
I will be more than happy to try any benchmark you can throw at this.
> The metadata required
> by fgKASLR is positively vast in comparison to the ordinary kernel boot,
> and legitimately so.
>
Indeed.
The implementation I will be proposing is essentially layered on top of
the ELF representation, using a seed to permute the contents of .text
in a stable manner.
This means that a debugger that knows the seed can permute the image in
the same way before loading it, and so all post-mortem and source level
debug use cases are still supported. (Whether the seed is preserved on
the system itself is a separate matter - on Android we will probably
discard it after booting)
So the permutation performed by the loader and by the debugger is
implemented by the same shared code, and the resulting ELF image
remains a valid image as before. This allows permuted images to
be packaged and shipped as well, without changes to the runtime
loader (this might be useful for Android in some cases). It also
means that traditional KASLR is still possible too - fgkaslr just
fixes up the RELR/RELA metadata after doing the permutation, and
the existing code works exactly the same as before.
The upshot of this is that relocations tacked onto the binary after
linking will go out of sync, and fgkaslr boot would lose the ability
to do traditional KASLR as a result, which is undesirable. This is
why the existing x86 relocation format is incompatible.
> However, fgKALSR is time-consuming. On bare metal this is rarely a
> concern, but users want to be able to spin up a VM kernel in ~100 ms. In
> that case, the compressed relocation format is highly efficient, both
> since it is compact and since the processing of those relocations is
> extremely simple.
I am not proposing to replace those relocations with fgkaslr, but
with standard packed RELR relocations, which take up only 5% of the
space used by the bespoke x86 relocation format, and can be applied
by the following for loop:
for (const u64 *relr = relr_start; relr < relr_end; relr++) {
if ((*relr & 1) == 0) {
place = (u64 *)(*relr + offset);
*place++ += offset;
} else {
for (u64 *p = place, r = *relr >> 1; r; p++, r >>= 1)
if (r & 1)
*p += offset;
place += 63;
}
}
> Furthermore, since the kernel is also ready to go if
> loaded at its advertised preferred address (which is the reason why this
> address is explicitly advertised, even for a relocatable kernel: "if you
> can load me at this specific address, I can boot faster and your vmlinux
> symbols will match the runtime, too."), the performance-sensitive VM
> spinup the (virtual) environment can be set up so that the relocation
> can be skipped entirely.
>
Both RELR packing and the fgkaslr I will be proposing have the same
properties: the metadata can just be ignored, and the kernel will boot
in its default permutation from its default virtual load address.
So perhaps we can continue this discussion based on the actual code once
I post it, rather than on your assumptions on how these things will be
implemented? I promise you I will take your feedback very seriously.
prev parent reply other threads:[~2026-11-19 10:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 9:18 Ard Biesheuvel
2026-11-18 11:23 ` Ard Biesheuvel
2026-11-18 15:51 ` H. Peter Anvin
2026-11-18 16:18 ` Ard Biesheuvel
2026-11-18 16:29 ` H. Peter Anvin
2026-11-18 16:55 ` Ard Biesheuvel
2026-11-18 17:04 ` H. Peter Anvin
2026-11-18 17:26 ` Ard Biesheuvel
2026-11-18 19:35 ` H. Peter Anvin
2026-11-19 9:58 ` Ard Biesheuvel [this message]
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=1cba56de-1094-4245-9100-2598039a09f7@app.fastmail.com \
--to=ardb@kernel.org \
--cc=ardb+git@google.com \
--cc=hpa@zytor.com \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=x86@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
all inboxes | Powered by JetHome®