Re: [PATCH 3/3] LoongArch: Skip relocation-time KASLR if it has already been applied

From: hev

Date: Mon Apr 27 2026 - 11:43:28 EST


Hi Huacai,

On Mon, Apr 27, 2026 at 9:29 PM Huacai Chen <chenhuacai@xxxxxxxxxx> wrote:
>
> Hi, Rui,
>
> On Mon, Apr 27, 2026 at 6:47 PM WANG Rui <r@xxxxxx> wrote:
> >
> > When the kernel is relocated during early boot, a randomized load
> > address may already have been selected and applied. In this case,
> > performing KASLR again in relocate.c is unnecessary.
> >
> > Signed-off-by: WANG Rui <r@xxxxxx>
> > ---
> > arch/loongarch/kernel/relocate.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/arch/loongarch/kernel/relocate.c b/arch/loongarch/kernel/relocate.c
> > index 16f6a9b39659..c36604a81d08 100644
> > --- a/arch/loongarch/kernel/relocate.c
> > +++ b/arch/loongarch/kernel/relocate.c
> > @@ -139,6 +139,10 @@ static inline __init bool kaslr_disabled(void)
> > char *str;
> > const char *builtin_cmdline = CONFIG_CMDLINE;
> >
> > + /* KASLR is performed during early boot. */
> > + if (kaslr_offset())
> > + return true;
> Maybe the "kexec_file" case is also handled by this?

Yeah, it looks like kexec_file doesn't load the kernel image to
VMLINUX_LOAD_ADDRESS, so it will disable KASLR here. This aligns with
our expectation of disabling KASLR for this case.

Thanks,
Rui


>
> Huacai
>
> > +
> > str = strstr(builtin_cmdline, "nokaslr");
> > if (str == builtin_cmdline || (str > builtin_cmdline && *(str - 1) == ' ')) {
> > pr_info(KASLR_DISABLED_MESSAGE, "\'nokaslr\'", "built-in");
> > --
> > 2.54.0
> >