x86/Hyper-V: Remove legacy code in the hv_snp_boot_ap()#127
x86/Hyper-V: Remove legacy code in the hv_snp_boot_ap()#127tiala wants to merge 2 commits intomicrosoft:product/hcl-main/6.18from
Conversation
There was a problem hiding this comment.
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_vmsabookkeeping to use thecpuargument.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (vp_index < 0 || vp_index > ms_hyperv.max_vp_index) | ||
| return -EINVAL; |
There was a problem hiding this comment.
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.
| 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; | |
| } |
4459a8b to
496517e
Compare
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>
496517e to
0bd58ed
Compare
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| cur_vmsa = per_cpu(hv_sev_vmsa, cpu_id); | ||
| cur_vmsa = per_cpu(hv_sev_vmsa, cpu); |
There was a problem hiding this comment.
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.
|
|
||
| /* Record the current VMSA page */ | ||
| per_cpu(hv_sev_vmsa, cpu_id) = vmsa; | ||
| per_cpu(hv_sev_vmsa, cpu) = vmsa; |
There was a problem hiding this comment.
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.
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)