[Deepin-Kernel-SIG] [linux 6.18-y] [Deepin] loongarch: disable kaslr when hibernate is supported#1591
Conversation
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>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis 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 enabledsequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new unconditional
return true;inkaslr_disabled()under the hibernation config makes the precedingresume=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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
/approve |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
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 returntrueunderCONFIG_HIBERNATION(unlessnohibernate/noresumeis 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.
| pr_info("KASLR is disabled by hibernate enabled.\n"); | ||
| return true; |
There was a problem hiding this comment.
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).
| 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; |
There was a problem hiding this comment.
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.
| if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' ')) | ||
| return true; | ||
|
|
||
| pr_info("KASLR is disabled by hibernate enabled.\n"); |
There was a problem hiding this comment.
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.
| pr_info("KASLR is disabled by hibernate enabled.\n"); | |
| pr_info("KASLR is disabled because hibernation is enabled.\n"); |
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:
However, resume still fails after using nokaslr in cmdline. Log says:
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: