Re: [PATCH v2] LoongArch: improve logging of disabling KASLR

From: Huacai Chen

Date: Thu Apr 16 2026 - 23:15:52 EST


Applied with some modifications, thanks.

Huacai

On Mon, Apr 13, 2026 at 11:13 AM Yuqian Yang <yangyuqian@xxxxxxxxxxxxx> wrote:
>
> Whether KASLR is disabled is not handled in nokaslr (early param
> "nokaslr" setup function) but in kaslr_disabled. However, the logging
> was done in nokaslr previously. So we move the logging to the right
> place and add more specific info about why it's disabled.
>
> Suggested-by: Wentao Guan <guanwentao@xxxxxxxxxxxxx>
> Signed-off-by: Yuqian Yang <yangyuqian@xxxxxxxxxxxxx>
> ---
>
> Changes since v1:
> * update commit title, loongarch -> LoongArch, remove trailing period.
> * use macro instead of const variable as log message to avoid build error.
>
> arch/loongarch/kernel/relocate.c | 27 +++++++++++++++++++--------
> 1 file changed, 19 insertions(+), 8 deletions(-)
>
> diff --git a/arch/loongarch/kernel/relocate.c b/arch/loongarch/kernel/relocate.c
> index 82aa3f0359278..80720175c89dc 100644
> --- a/arch/loongarch/kernel/relocate.c
> +++ b/arch/loongarch/kernel/relocate.c
> @@ -128,9 +128,8 @@ static inline __init unsigned long get_random_boot(void)
>
> static int __init nokaslr(char *p)
> {
> - pr_info("KASLR is disabled.\n");
> -
> - return 0; /* Print a notice and silence the boot warning */
> + /* The real check is handled in kaslr_disabled() below. */
> + return 0;
> }
> early_param("nokaslr", nokaslr);
>
> @@ -138,14 +137,19 @@ static inline __init bool kaslr_disabled(void)
> {
> char *str;
> const char *builtin_cmdline = CONFIG_CMDLINE;
> +#define LOONGARCH_KASLR_DISABLED_MESSAGE "KASLR is disabled by %s in %s cmdline.\n"
>
> str = strstr(builtin_cmdline, "nokaslr");
> - if (str == builtin_cmdline || (str > builtin_cmdline && *(str - 1) == ' '))
> + if (str == builtin_cmdline || (str > builtin_cmdline && *(str - 1) == ' ')) {
> + pr_info(LOONGARCH_KASLR_DISABLED_MESSAGE, "nokaslr", "built-in");
> return true;
> + }
>
> str = strstr(boot_command_line, "nokaslr");
> - if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' '))
> + if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' ')) {
> + pr_info(LOONGARCH_KASLR_DISABLED_MESSAGE, "nokaslr", "boot");
> return true;
> + }
>
> #ifdef CONFIG_HIBERNATION
> str = strstr(builtin_cmdline, "nohibernate");
> @@ -165,19 +169,26 @@ static inline __init bool kaslr_disabled(void)
> return false;
>
> str = strstr(builtin_cmdline, "resume=");
> - if (str == builtin_cmdline || (str > builtin_cmdline && *(str - 1) == ' '))
> + if (str == builtin_cmdline || (str > builtin_cmdline && *(str - 1) == ' ')) {
> + pr_info(LOONGARCH_KASLR_DISABLED_MESSAGE, "resume=", "built-in");
> return true;
> + }
>
> str = strstr(boot_command_line, "resume=");
> - if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' '))
> + if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' ')) {
> + pr_info(LOONGARCH_KASLR_DISABLED_MESSAGE, "resume=", "boot");
> return true;
> + }
> #endif
>
> str = strstr(boot_command_line, "kexec_file");
> - if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' '))
> + if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' ')) {
> + pr_info(LOONGARCH_KASLR_DISABLED_MESSAGE, "kexec_file", "boot");
> return true;
> + }
>
> return false;
> +#undef LOONGARCH_KASLR_DISABLED_MESSAGE
> }
>
> /* Choose a new address for the kernel */
>
> base-commit: e774d5f1bc27a85f858bce7688509e866f8e8a4e
> --
> 2.50.1
>