Skip to content

openhcl_boot: derive the hw id chunk size from the page size - #4144

Merged
Steven Malis (smalis-msft) merged 1 commit into
microsoft:mainfrom
knQzx:fix/hwid-chunking-page-limit
Aug 4, 2026
Merged

openhcl_boot: derive the hw id chunk size from the page size#4144
Steven Malis (smalis-msft) merged 1 commit into
microsoft:mainfrom
knQzx:fix/hwid-chunking-page-limit

Conversation

@knQzx

Copy link
Copy Markdown
Contributor

get_vp_index_from_hw_id chunks hardware IDs at a hardcoded 512 per call, but the input page carries a 16-byte GetVpIndexFromApicId header, leaving 4080 bytes. On aarch64 HwId is a u64, so a 512-element chunk needs 4096 bytes, write_to_prefix returns Err and the unwrap panics. The todo above that line tracked this against this issue

one correction to the issue text: the panic starts at 511 CPUs, not 512. The estimate of 8 * 512 == 4096 did not count the header, so the last chunk that still fits is 510

this computes the limit from the page size, the header and size_of::<HwId>() the way accept_vtl2_pages and apply_vtl2_protections in the same file already do, giving 510 on aarch64 and 1020 on x86_64. Both fit the output page (n * 4 bytes) and the 12-bit rep count field. The offset now uses the same HEADER_SIZE constant as the chunk limit, matching set_register and get_register, so the two can no longer drift apart

verified the constants by compiling openhcl_boot for both targets with a temporary const assertion, and checked the arithmetic against zerocopy directly: 510 u64s fit the 4080-byte tail, 511 do not

Fixes #745

get_vp_index_from_hw_id chunked hardware IDs at a hardcoded 512 per call.
The input page holds a 16-byte header, leaving 4080 bytes, so on aarch64
(HwId is u64) a 512-element chunk needs 4096 bytes and write_to_prefix
fails, panicking on the unwrap. This starts at 511 CPUs, not 512 as the
issue estimates, because the header was not counted.

Compute the limit from the page size, header and HwId size the way the
other rep hypercalls in this file already do: 510 on aarch64, 1020 on
x86_64. Both fit the output page and the 12-bit rep count field.
@knQzx
Novikov Kirill (knQzx) requested a review from a team as a code owner August 1, 2026 15:39
Copilot AI review requested due to automatic review settings August 1, 2026 15:39
@github-actions github-actions Bot added the unsafe Related to unsafe code label Aug 1, 2026
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes a panic in openhcl_boot’s HvCall::get_vp_index_from_hw_id by deriving the maximum per-hypercall chunk size from the actual input page capacity (page size minus hypercall header) and the HwId element size, instead of using a hardcoded 512.

Changes:

  • Compute MAX_PER_CALL from HV_PAGE_SIZE, the GetVpIndexFromApicId header size, and size_of::<HwId>() to prevent write_to_prefix failures (notably on aarch64).
  • Use the same HEADER_SIZE constant for both the chunk-size calculation and the buffer offset used to write the hw_ids, avoiding future drift.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

@smalis-msft
Steven Malis (smalis-msft) enabled auto-merge (squash) August 4, 2026 15:39
@smalis-msft
Steven Malis (smalis-msft) merged commit 34d639b into microsoft:main Aug 4, 2026
99 of 101 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openhcl_boot: get_vp_index_from_hw_id will panic with > 511 CPUs on aarch64

3 participants