Skip to content

[Deepin-Kernel-SIG] [linux 6.18-y] [Deepin] loongarch: disable kaslr when hibernate is supported#1591

Merged
opsiff merged 1 commit into
deepin-community:linux-6.18.yfrom
opsiff:linux-6.18.y-2026-03-27-loongarch
Mar 27, 2026
Merged

[Deepin-Kernel-SIG] [linux 6.18-y] [Deepin] loongarch: disable kaslr when hibernate is supported#1591
opsiff merged 1 commit into
deepin-community:linux-6.18.yfrom
opsiff:linux-6.18.y-2026-03-27-loongarch

Conversation

@opsiff
Copy link
Copy Markdown
Member

@opsiff opsiff commented Mar 27, 2026

Link: #338

deepin inclusion
category: feature

[ !broken ] kaslr is disabled !

When kaslr is enabled and no 'resume=' in cmdline (see 71344f2b0), loongarch cannot resume from a hibernated kernel. Console log stops at:

PM: Image loading progress: 100%
PM: Image loading done
PM: hibernation: Read 2669152 kbytes in 4.26 seconds (626.56 MB/s)
ata1.00: Entering standby power mode
radeon 0000:06:00.0: GPU pci config reset
Disabling non-boot CPUs ...

However, resume still fails after using nokaslr in cmdline. Log says:

PM: Image loading progress: 100%
PM: Image loading done
PM: hibernation: Read 2669152 kbytes in 4.26 seconds (626.56 MB/s)
ata1.00: Entering standby power mode
radeon 0000:06:00.0: GPU pci config reset
Disabling non-boot CPUs ...
ACPI: PM: Restoring platform NVS memory
Enabling non-boot CPUs ...
Booting CPU#1...
CPU1: failed to start
Error taking CPU1 up: -5
Booting CPU#2...
CPU2: failed to start
Error taking CPU2 up: -5
Booting CPU#3...
CPU3: failed to start
Error taking CPU3 up: -5
Booting CPU#4...
64-bit Loongson Processor probed (LA664 Core)
CPU4 revision is: 0014d000 (Loongson-64bit)
FPU4 revision is: 00000000
CPU#4 finished
CPU4 is up
Booting CPU#5...
CPU5: failed to start
Error taking CPU5 up: -5
Booting CPU#6...
Kernel ade access[#5738]:
CPU: 0 PID: 0 Comm: swapper/0 Tainted: G      D            6.6.0-loong64-desktop #25.00.2000.002
Hardware name: KaiTian 90Y4A08AKX/KL3A60007A2000DTMB1, BIOS W0MKT0DA 11/25/2024
pc 9000000000304160 ra 900000000030415c tp 900000000341c000 sp 9000000100403f90
a0 24001c4c5676979d a1 0000000000000000 a2 0000000000000000 a3 0000000000000000
a4 90000000040aef08 a5 90000000040aedd0 a6 9000000003d78118 a7 0000000000000000
t0 0000000000000000 t1 0000000000000000 t2 0000000000000000 t3 0000000000000000
t4 0000000000000000 t5 0000000000000000 t6 0000000000000000 t7 0000000000000000
t8 0000000000000000 u0 0000000000000003 s9 00000000fd180638 s0 0000000000000000
s1 9000000004108cf0 s2 ffffffffffffffff s3 0000000000000001 s4 0000000000000000
s5 9000000008233481 s6 0000000000000000 s7 9000000002bd4d10 s8 9000000003d72910
   ra: 900000000030415c generic_handle_domain_irq+0x1c/0x80
  ERA: 9000000000304160 generic_handle_domain_irq+0x20/0x80
 CRMD: 000000b0 (PLV0 -IE -DA +PG DACF=CC DACM=CC -WE)
 PRMD: 00000008 (PPLV0 -PIE +PWE)
 EUEN: 00000000 (-FPE -SXE -ASXE -BTE)
 ECFG: 00071c1d (LIE=0,2-4,10-12 VS=7)
ESTAT: 00480800 [ADEM] (IS=11 ECode=8 EsubCode=1)
 BADV: 24001c4c56769835
 PRID: 0014d000 (Loongson-64bit, Loongson-3A6000-HV)
Modules linked in: snd_seq_dummy snd_hrtimer snd_seq snd_seq_device bnep st sr_mod cdrom bluetooth rfkill qrtr nls_iso8859_1 nls_cp4t
Process swapper/0 (pid: 0, threadinfo=00000000cf4196b1, task=000000007aa949f6)
Stack : 00000000000002b0 9000000000facff8 900000000344b000 9000000100403ff0
        0000000000000001 0000000000000000 900000000341fc90 9000000001b1f590
        90000001006f8000 900000000341fc90 900000000341fc60 9000000001b1f664
        900000000341fc90 0000000000000000
Call Trace:
[<9000000000304160>] generic_handle_domain_irq+0x20/0x80
[<9000000000facff8>] handle_cpu_irq+0x78/0xc0
[<9000000001b1f590>] handle_loongarch_irq+0x30/0x60
[<9000000001b1f664>] do_vint+0xa4/0xe0
[<90000000002225e0>] __arch_cpu_idle+0x20/0x24
[<9000000001b21f1c>] arch_cpu_idle+0x1c/0x40
[<9000000001b22180>] default_idle_call+0xa0/0x158
[<90000000002cb9c8>] do_idle+0x108/0x160
[<90000000002cbc84>] cpu_startup_entry+0x44/0x60
[<9000000001b23234>] kernel_init+0x0/0x14c
[<9000000001b411c4>] arch_post_acpi_subsys_init+0x0/0xc

This is caused by RANDOM_KMALLOC_CACHES, if this option is enabled, secondary CPUs may fail at "Error taking CPUx up: -5". System may stuck with the above calltrace, or can still enter graphic desktop with only CPU0.

To enable S4, disable kaslr and RANDOM_KMALLOC_CHACHES for now.

Summary by Sourcery

Bug Fixes:

  • Address hibernation resume failures and secondary CPU bring-up errors on LoongArch systems caused by KASLR and randomized kmalloc caches when resuming from S4.

deepin inclusion
category: feature

[ !broken ] kaslr is disabled !

When kaslr is enabled and no 'resume=' in cmdline (see 71344f2b0),
loongarch cannot resume from a hibernated kernel. Console log stops at:

	PM: Image loading progress: 100%
	PM: Image loading done
	PM: hibernation: Read 2669152 kbytes in 4.26 seconds (626.56 MB/s)
	ata1.00: Entering standby power mode
	radeon 0000:06:00.0: GPU pci config reset
	Disabling non-boot CPUs ...

However, resume still fails after using nokaslr in cmdline. Log says:

	PM: Image loading progress: 100%
	PM: Image loading done
	PM: hibernation: Read 2669152 kbytes in 4.26 seconds (626.56 MB/s)
	ata1.00: Entering standby power mode
	radeon 0000:06:00.0: GPU pci config reset
	Disabling non-boot CPUs ...
	ACPI: PM: Restoring platform NVS memory
	Enabling non-boot CPUs ...
	Booting CPU#1...
	CPU1: failed to start
	Error taking CPU1 up: -5
	Booting CPU#2...
	CPU2: failed to start
	Error taking CPU2 up: -5
	Booting CPU#3...
	CPU3: failed to start
	Error taking CPU3 up: -5
	Booting CPU#4...
	64-bit Loongson Processor probed (LA664 Core)
	CPU4 revision is: 0014d000 (Loongson-64bit)
	FPU4 revision is: 00000000
	CPU#4 finished
	CPU4 is up
	Booting CPU#5...
	CPU5: failed to start
	Error taking CPU5 up: -5
	Booting CPU#6...
	Kernel ade access[#5738]:
	CPU: 0 PID: 0 Comm: swapper/0 Tainted: G      D            6.6.0-loong64-desktop deepin-community#25.00.2000.002
	Hardware name: KaiTian 90Y4A08AKX/KL3A60007A2000DTMB1, BIOS W0MKT0DA 11/25/2024
	pc 9000000000304160 ra 900000000030415c tp 900000000341c000 sp 9000000100403f90
	a0 24001c4c5676979d a1 0000000000000000 a2 0000000000000000 a3 0000000000000000
	a4 90000000040aef08 a5 90000000040aedd0 a6 9000000003d78118 a7 0000000000000000
	t0 0000000000000000 t1 0000000000000000 t2 0000000000000000 t3 0000000000000000
	t4 0000000000000000 t5 0000000000000000 t6 0000000000000000 t7 0000000000000000
	t8 0000000000000000 u0 0000000000000003 s9 00000000fd180638 s0 0000000000000000
	s1 9000000004108cf0 s2 ffffffffffffffff s3 0000000000000001 s4 0000000000000000
	s5 9000000008233481 s6 0000000000000000 s7 9000000002bd4d10 s8 9000000003d72910
	   ra: 900000000030415c generic_handle_domain_irq+0x1c/0x80
	  ERA: 9000000000304160 generic_handle_domain_irq+0x20/0x80
	 CRMD: 000000b0 (PLV0 -IE -DA +PG DACF=CC DACM=CC -WE)
	 PRMD: 00000008 (PPLV0 -PIE +PWE)
	 EUEN: 00000000 (-FPE -SXE -ASXE -BTE)
	 ECFG: 00071c1d (LIE=0,2-4,10-12 VS=7)
	ESTAT: 00480800 [ADEM] (IS=11 ECode=8 EsubCode=1)
	 BADV: 24001c4c56769835
	 PRID: 0014d000 (Loongson-64bit, Loongson-3A6000-HV)
	Modules linked in: snd_seq_dummy snd_hrtimer snd_seq snd_seq_device bnep st sr_mod cdrom bluetooth rfkill qrtr nls_iso8859_1 nls_cp4t
	Process swapper/0 (pid: 0, threadinfo=00000000cf4196b1, task=000000007aa949f6)
	Stack : 00000000000002b0 9000000000facff8 900000000344b000 9000000100403ff0
	        0000000000000001 0000000000000000 900000000341fc90 9000000001b1f590
	        90000001006f8000 900000000341fc90 900000000341fc60 9000000001b1f664
	        900000000341fc90 0000000000000000
	Call Trace:
	[<9000000000304160>] generic_handle_domain_irq+0x20/0x80
	[<9000000000facff8>] handle_cpu_irq+0x78/0xc0
	[<9000000001b1f590>] handle_loongarch_irq+0x30/0x60
	[<9000000001b1f664>] do_vint+0xa4/0xe0
	[<90000000002225e0>] __arch_cpu_idle+0x20/0x24
	[<9000000001b21f1c>] arch_cpu_idle+0x1c/0x40
	[<9000000001b22180>] default_idle_call+0xa0/0x158
	[<90000000002cb9c8>] do_idle+0x108/0x160
	[<90000000002cbc84>] cpu_startup_entry+0x44/0x60
	[<9000000001b23234>] kernel_init+0x0/0x14c
	[<9000000001b411c4>] arch_post_acpi_subsys_init+0x0/0xc

This is caused by RANDOM_KMALLOC_CACHES, if this option is enabled,
secondary CPUs may fail at "Error taking CPUx up: -5". System may stuck
with the above calltrace, or can still enter graphic desktop with only
CPU0.

To enable S4, disable kaslr and RANDOM_KMALLOC_CHACHES for now.

Signed-off-by: wenlunpeng <wenlunpeng@uniontech.com>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Mar 27, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR ensures that when hibernation (resume=) is supported on LoongArch, KASLR is effectively disabled at boot time and logs a clear informational message, avoiding CPU bring‑up failures related to RANDOM_KMALLOC_CACHES after S4 resume.

Sequence diagram for KASLR disabling when hibernation is enabled

sequenceDiagram
    participant Bootloader
    participant Kernel
    participant kaslr_disabled

    Bootloader->>Kernel: start_kernel
    Kernel->>kaslr_disabled: check_kaslr_disabled(boot_command_line)
    kaslr_disabled->>kaslr_disabled: search boot_command_line for resume=
    alt resume_support_detected
        kaslr_disabled-->>Kernel: log KASLR is disabled by hibernate enabled
        kaslr_disabled-->>Kernel: return true (disable KASLR)
        Kernel->>Kernel: skip_KASLR_randomization
    else no_resume_support
        kaslr_disabled-->>Kernel: continue checks (e.g. kexec_file)
        Kernel->>Kernel: decide KASLR state by other conditions
    end
    Kernel-->>Bootloader: continue boot with final KASLR state
Loading

File-Level Changes

Change Details Files
Force-disable KASLR on LoongArch when hibernation (resume=) support is detected, and log this behavior at boot.
  • Extend the existing kaslr_disabled() logic so that detecting a valid resume= argument unconditionally returns true, thereby disabling KASLR whenever hibernation support is present.
  • Add an informational pr_info() message indicating that KASLR has been disabled because hibernation is enabled, improving debuggability of resume-related issues.
arch/loongarch/kernel/relocate.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The new unconditional return true; in kaslr_disabled() under the hibernation config makes the preceding resume= check dead code; consider either removing that check or restructuring the logic so it remains meaningful.
  • The log message "KASLR is disabled by hibernate enabled." is emitted on every boot whenever this path is compiled in; consider clarifying the wording and/or emitting it only when KASLR would otherwise be enabled to avoid noisy or misleading logs.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new unconditional `return true;` in `kaslr_disabled()` under the hibernation config makes the preceding `resume=` check dead code; consider either removing that check or restructuring the logic so it remains meaningful.
- The log message `"KASLR is disabled by hibernate enabled."` is emitted on every boot whenever this path is compiled in; consider clarifying the wording and/or emitting it only when KASLR would otherwise be enabled to avoid noisy or misleading logs.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Avenger-285714
Copy link
Copy Markdown
Member

/approve
疑难杂症,道阻且长

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Avenger-285714

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes LoongArch KASLR relocation logic to force-disable KASLR when hibernation support is enabled, aiming to avoid S4 resume failures reported on LoongArch systems.

Changes:

  • Force kaslr_disabled() to return true under CONFIG_HIBERNATION (unless nohibernate/noresume is set).
  • Add an informational boot log indicating KASLR was disabled due to hibernation being enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +168 to +169
pr_info("KASLR is disabled by hibernate enabled.\n");
return true;
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description mentions disabling RANDOM_KMALLOC_CACHES as part of enabling S4, but this change only forces KASLR off. If disabling randomized kmalloc caches is required for reliable resume, it should be implemented in this PR (or the description/scope adjusted).

Copilot uses AI. Check for mistakes.
Comment on lines 160 to +169
str = strstr(builtin_cmdline, "resume=");
if (str == builtin_cmdline || (str > builtin_cmdline && *(str - 1) == ' '))
return true;

str = strstr(boot_command_line, "resume=");
if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' '))
return true;

pr_info("KASLR is disabled by hibernate enabled.\n");
return true;
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new unconditional return true under CONFIG_HIBERNATION makes the preceding resume= checks redundant/unreachable for changing behavior (they only affect whether the log prints). Consider removing the resume= checks or restructuring so the intent is clear and the log behavior is consistent.

Copilot uses AI. Check for mistakes.
if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' '))
return true;

pr_info("KASLR is disabled by hibernate enabled.\n");
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log message grammar/terminology: "hibernate" here reads like a verb; consider using "hibernation" (e.g., "KASLR is disabled because hibernation is enabled") to match kernel terminology and improve clarity.

Suggested change
pr_info("KASLR is disabled by hibernate enabled.\n");
pr_info("KASLR is disabled because hibernation is enabled.\n");

Copilot uses AI. Check for mistakes.
@opsiff opsiff merged commit bff6601 into deepin-community:linux-6.18.y Mar 27, 2026
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants