patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	 dave.hansen@linux.intel.com
Cc: x86@kernel.org, hpa@zytor.com, ndesaulniers@google.com,
	 morbo@google.com, justinstitt@google.com, song@kernel.org,
	 ribalda@chromium.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev,  patches@lists.linux.dev,
	ns <0n-s@users.noreply.github.com>,
	 Nathan Chancellor <nathan@kernel.org>
Subject: [PATCH 0/2] x86/purgatory: Avoid kexec runtime warning with LLVM 18
Date: Wed, 17 Apr 2024 14:53:44 -0700	[thread overview]
Message-ID: <20240417-x86-fix-kexec-with-llvm-18-v1-0-5383121e8fb7@kernel.org> (raw)

Hi all,

After LLVM commit d8a04398f949 ("Reland [X86] With large code model, put
functions into .ltext with large section flag (#73037)") [1], which
landed in the 18.x cycle, there is a runtime warning when loading a
kernel via kexec due to the presence of two text sections (.text and
.ltext).

  $ kexec -l /boot/vmlinuz-linux --initrd=/boot/initramfs-linux.img --reuse-cmdline
  $ dmesg -l warn+
  ...
  [    1.264240] ------------[ cut here ]------------
  [    1.264647] WARNING: CPU: 0 PID: 96 at kernel/kexec_file.c:945 kexec_load_purgatory+0x2c8/0x3c0
  [    1.265322] Modules linked in:
  [    1.265565] CPU: 0 PID: 96 Comm: kexec Not tainted 6.9.0-rc4-00031-g96fca68c4fbf #1 eae91b3fe699ecba2dd0a886471788e49eb36ac0
  [    1.266403] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014
  [    1.267268] RIP: 0010:kexec_load_purgatory+0x2c8/0x3c0
  [    1.267661] Code: 54 24 0c 48 89 c8 48 29 d0 0f 82 5d ff ff ff 49 03 54 24 1c 48 39 d1 0f 83 4f ff ff ff 49 8b 17 48 39 4a 18 0f 84 30 ff ff ff <0f> 0b e9 3b ff ff ff 66 85 c9 74 18 48 8b 5a 28 48 01 d3 45 31 e4
  [    1.269052] RSP: 0018:ffffbe28007cfb50 EFLAGS: 00010206
  [    1.269447] RAX: 0000000000000000 RBX: 00000000000000d0 RCX: 0000000000000000
  [    1.269982] RDX: ffff988c8174d000 RSI: 0000000000000010 RDI: ffffbe2801d940c0
  [    1.270527] RBP: 0000000000000002 R08: 0000003d8b4c0000 R09: cc0000000025ff00
  [    1.271063] R10: 0000003d8b4c0000 R11: cc0000000025ff00 R12: ffffbe28000d5084
  [    1.271603] R13: 000000013ffff000 R14: ffff988c8174d000 R15: ffffbe28007cfbe0
  [    1.272140] FS:  00007fec73535740(0000) GS:ffff988cbbc00000(0000) knlGS:0000000000000000
  [    1.272744] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  [    1.273178] CR2: 00007fec736b1390 CR3: 0000000101a24000 CR4: 0000000000350ef0
  [    1.273732] Call Trace:
  [    1.273929]  <TASK>
  [    1.274100]  ? __warn+0xc9/0x1c0
  [    1.274356]  ? kexec_load_purgatory+0x2c8/0x3c0
  [    1.274704]  ? report_bug+0x139/0x1e0
  [    1.274998]  ? handle_bug+0x42/0x70
  [    1.275269]  ? exc_invalid_op+0x1a/0x50
  [    1.275574]  ? asm_exc_invalid_op+0x1a/0x20
  [    1.275900]  ? kexec_load_purgatory+0x2c8/0x3c0
  [    1.276251]  bzImage64_load+0x1c1/0x6a0
  [    1.276556]  kexec_image_load_default+0x49/0x60
  [    1.276907]  __se_sys_kexec_file_load+0x606/0x790
  [    1.277280]  ? arch_exit_to_user_mode_prepare+0x6e/0x70
  [    1.277675]  do_syscall_64+0x90/0x170
  [    1.277955]  ? srso_return_thunk+0x5/0x5f
  [    1.278265]  ? __count_memcg_events+0x50/0xc0
  [    1.278597]  ? srso_return_thunk+0x5/0x5f
  [    1.278901]  ? handle_mm_fault+0xb18/0x11c0
  [    1.279218]  ? vfs_read+0x2c8/0x2f0
  [    1.279498]  ? srso_return_thunk+0x5/0x5f
  [    1.279802]  ? do_user_addr_fault+0x4d2/0x690
  [    1.280138]  ? srso_return_thunk+0x5/0x5f
  [    1.280449]  ? srso_return_thunk+0x5/0x5f
  [    1.280755]  entry_SYSCALL_64_after_hwframe+0x76/0x7e
  [    1.281136] RIP: 0033:0x7fec7363e88d
  [    1.281411] Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 73 14 0d 00 f7 d8 64 89 01 48
  [    1.282789] RSP: 002b:00007ffd136f4808 EFLAGS: 00000246 ORIG_RAX: 0000000000000140
  [    1.283354] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fec7363e88d
  [    1.283893] RDX: 00000000000000c5 RSI: 0000000000000005 RDI: 0000000000000003
  [    1.284427] RBP: 0000000000000003 R08: 0000000000000000 R09: 00005628517eef10
  [    1.284966] R10: 00005628580a75f0 R11: 0000000000000246 R12: 0000000000000003
  [    1.285500] R13: 00005628517f89a8 R14: 00007ffd136f4b98 R15: 0000000000000004
  [    1.286036]  </TASK>
  [    1.286210] ---[ end trace 0000000000000000 ]---

Unlike LTO and PGO, which were disabled for the purgatory in commit
97b6b9cbba40 ("x86/purgatory: remove PGO flags") and commit 75b2f7e4c9e0
("x86/purgatory: Remove LTO flags"), this optimization has no flag to
opt out of it. One way to resolve this would be to use '.ltext' and
'.lrodata' as the text and read-only data sections in the out of line
assembly in arch/x86/purgatory but there is nothing that stops future
changes from splitting the text section further.

Properly avoid the warning by using a linker script to coalesce all
separate text sections into one, which was alluded to by both the change
that introduced the warning and 75b2f7e4c9e0... I think this really
should have been done then but I wasn't looking too far ahead :) To
avoid backsliding now that all sections are properly described by the
linker script, turn on orphan section warnings as well.

[1]: https://github.com/llvm/llvm-project/commit/d8a04398f9492f043ffd8fbaf2458778f7d0fcd5

---
Nathan Chancellor (2):
      x86/purgatory: Add a linker script
      x86/purgatory: Enable orphan section warnings

 arch/x86/purgatory/.gitignore      |  1 +
 arch/x86/purgatory/Makefile        | 19 +++---------
 arch/x86/purgatory/purgatory.lds.S | 63 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 14 deletions(-)
---
base-commit: 0bbac3facb5d6cc0171c45c9873a2dc96bea9680
change-id: 20240416-x86-fix-kexec-with-llvm-18-c986b21845c5

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>


             reply	other threads:[~2024-04-17 21:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17 21:53 Nathan Chancellor [this message]
2024-04-17 21:53 ` [PATCH 1/2] x86/purgatory: Add a linker script Nathan Chancellor
2024-04-17 21:53 ` [PATCH 2/2] x86/purgatory: Enable orphan section warnings Nathan Chancellor
2024-04-18 11:14 ` [PATCH 0/2] x86/purgatory: Avoid kexec runtime warning with LLVM 18 Borislav Petkov
2024-04-18 15:15   ` Nathan Chancellor
2024-04-18 15:44   ` Nick Desaulniers
2024-04-18 15:59     ` Ard Biesheuvel
2024-04-18 17:52       ` Ard Biesheuvel

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=20240417-x86-fix-kexec-with-llvm-18-v1-0-5383121e8fb7@kernel.org \
    --to=nathan@kernel.org \
    --cc=0n-s@users.noreply.github.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=justinstitt@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mingo@redhat.com \
    --cc=morbo@google.com \
    --cc=ndesaulniers@google.com \
    --cc=patches@lists.linux.dev \
    --cc=ribalda@chromium.org \
    --cc=song@kernel.org \
    --cc=tglx@linutronix.de \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).