Skip to content

x86/Hyper-V: Remove legacy code in the hv_snp_boot_ap()#127

Open
tiala wants to merge 2 commits intomicrosoft:product/hcl-main/6.18from
tiala:user/tiala/6.18-branch
Open

x86/Hyper-V: Remove legacy code in the hv_snp_boot_ap()#127
tiala wants to merge 2 commits intomicrosoft:product/hcl-main/6.18from
tiala:user/tiala/6.18-branch

Conversation

@tiala
Copy link
Copy Markdown
Contributor

@tiala tiala commented Apr 21, 2026

Use vcpu index to match it with VMSA page instead of APIC id.
Remove some old code which depends on APIC id value to index
AP''s VMSA page.

Fixes: f313db8 (x86/sev: Use hvcall to convert apic id to vpid)

@tiala tiala marked this pull request as ready for review April 21, 2026 07:20
Copilot AI review requested due to automatic review settings April 21, 2026 07:21
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 updates the SEV-SNP enlightened AP bring-up path on Hyper-V to stop relying on APIC ID–based CPU lookup and instead use the provided CPU index for per-CPU VMSA tracking, while consistently using the Hyper-V VP index mapping.

Changes:

  • Remove legacy APIC-ID-to-CPU lookup logic from hv_snp_boot_ap().
  • Always derive the Hyper-V VP index via hv_apicid_to_vp_index(apic_id) (instead of treating APIC ID as the VP index).
  • Switch per-CPU hv_sev_vmsa bookkeeping to use the cpu argument.

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

Comment thread arch/x86/hyperv/ivm.c
Comment on lines 310 to 311
if (vp_index < 0 || vp_index > ms_hyperv.max_vp_index)
return -EINVAL;
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

vmsa is allocated before validating vp_index, but on the early -EINVAL return (when hv_apicid_to_vp_index() fails or returns an out-of-range value) the allocated page is leaked. Free the page (or call the existing cleanup helper as appropriate) before returning from this error path.

Suggested change
if (vp_index < 0 || vp_index > ms_hyperv.max_vp_index)
return -EINVAL;
if (vp_index < 0 || vp_index > ms_hyperv.max_vp_index) {
free_page((u64)vmsa);
return -EINVAL;
}

Copilot uses AI. Check for mistakes.
@tiala tiala force-pushed the user/tiala/6.18-branch branch 2 times, most recently from 4459a8b to 496517e Compare April 21, 2026 08:21
hargar19 and others added 2 commits April 21, 2026 05:36
The revert of the TDX reset page commit (3fca701) left
`apicid` instead of `cpu` as the second argument to
hv_vtl_bringup_vcpu(). This causes secondary CPUs to boot with
the wrong idle task stack, leading to stack corruption and
triple faults during sidecar servicing.

Fixes: 3fca701 ("Revert "x86/hyperv: Use Hyper-V reset page to boot tdx APs"")

Signed-off-by: Hardik Garg <hargar@microsoft.com>
Match VMSA page with vcpu index instead of APIC id. APIC
id maybe identity map with vcpu index.

Fixes: f313db8 ("x86/sev: Use hvcall to convert apic id to vpid")
Signed-off-by: Tianyu Lan <tiala@microsoft.com>
Copilot AI review requested due to automatic review settings April 21, 2026 19:28
@tiala tiala force-pushed the user/tiala/6.18-branch branch from 496517e to 0bd58ed Compare April 21, 2026 19:28
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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


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

Comment thread arch/x86/hyperv/ivm.c
}

cur_vmsa = per_cpu(hv_sev_vmsa, cpu_id);
cur_vmsa = per_cpu(hv_sev_vmsa, cpu);
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

The previous code derived cpu_id from apic_id (and would panic if no match), guaranteeing the per-cpu VMSA slot matched the APIC ID used for VP-index conversion. With the new approach, if cpu and apic_id ever disagree, the code will silently clean up and store the VMSA under the wrong CPU slot. Consider adding a cheap invariant check under the relevant config (e.g., WARN_ON_ONCE(per_cpu(x86_cpu_to_apicid, cpu) != apic_id) where available) or documenting that callers must pass a cpu that corresponds to apic_id.

Copilot uses AI. Check for mistakes.
Comment thread arch/x86/hyperv/ivm.c

/* Record the current VMSA page */
per_cpu(hv_sev_vmsa, cpu_id) = vmsa;
per_cpu(hv_sev_vmsa, cpu) = vmsa;
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

The previous code derived cpu_id from apic_id (and would panic if no match), guaranteeing the per-cpu VMSA slot matched the APIC ID used for VP-index conversion. With the new approach, if cpu and apic_id ever disagree, the code will silently clean up and store the VMSA under the wrong CPU slot. Consider adding a cheap invariant check under the relevant config (e.g., WARN_ON_ONCE(per_cpu(x86_cpu_to_apicid, cpu) != apic_id) where available) or documenting that callers must pass a cpu that corresponds to apic_id.

Copilot uses AI. Check for mistakes.
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.

3 participants