Skip to content

Conversation

@namancse
Copy link
Contributor

@namancse namancse commented Oct 29, 2025

After Linux v6.17, the x86_64 kernel startup code moved from .head.text
to .init.text. This moves the startup code to an address, higher than
the actual physical load address. Update the loader to check the
lowest program header address for relocation, not just the entry point,
to handle both old and new kernels.

This issue was identified when latest upstream kernel is built with latest openvmm.
Compilation error:
Error: underhill kernel loader

Caused by:
0: kernel load error
1: elf loader error
2: invalid ELF program header memory offset 134217728, below start 136314880

Tested the change, for bootup, both with current mainline and latest upstream kernel.

@namancse namancse requested a review from chris-oo October 29, 2025 07:13
After Linux v6.17, the x86_64 kernel startup code moved from .head.text
to .init.text. This moves the startup code to an address, higher than
the actual physical load address. Update the loader to check the
lowest program header address for relocation, not just the entry point,
to handle both old and new kernels.

Co-authored-by: GitHub Copilot <copilot@microsoft.com>
@namancse namancse marked this pull request as ready for review October 30, 2025 04:45
@namancse namancse requested a review from a team as a code owner October 30, 2025 04:45
Copilot AI review requested due to automatic review settings October 30, 2025 04:45
Copy link
Contributor

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 updates the ELF loader logic to handle new Linux kernel layouts introduced in kernel version 6.17. The key change is determining the load offset for Position-Independent Code (PIC) kernels by examining the lowest physical address in program headers instead of relying solely on the entry point address.

  • Moved program header parsing earlier in the function to enable load offset calculation
  • Changed PIC load offset calculation to use the lowest p_paddr from PT_LOAD segments instead of comparing e_entry with start_address
  • Added comprehensive documentation explaining the rationale for both old (< v6.17) and new (≥ v6.17) kernel layouts

@namancse namancse merged commit c430e9d into microsoft:main Oct 31, 2025
115 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants