Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arch/x86/hyperv/hv_vtl.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip, unsi
return -EINVAL;
}

return hv_vtl_bringup_vcpu(vp_index, apicid, start_eip);
return hv_vtl_bringup_vcpu(vp_index, cpu, start_eip);
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

The PR description focuses on fixing the wrong argument passed to hv_vtl_bringup_vcpu(), but this PR also changes Hyper-V isolation gating in arch/x86/kernel/cpu/amd.c and per-CPU VMSA bookkeeping in arch/x86/hyperv/ivm.c. Please either mention these additional changes in the PR description (with rationale) or split them into separate commits/PRs so the fix can be reviewed/merged independently.

Copilot uses AI. Check for mistakes.
}

/*
Expand Down
21 changes: 3 additions & 18 deletions arch/x86/hyperv/ivm.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,32 +298,17 @@ int hv_snp_boot_ap(u32 apic_id, unsigned long start_ip, unsigned int cpu)
struct sev_es_save_area *cur_vmsa;
struct desc_ptr gdtr;
struct hv_enable_vp_vtl *start_vp_input;
int cpu_id = -EINVAL;
unsigned long flags;
int vp_index = apic_id;
int vp_index;
u64 ret, retry = 5;

if (!vmsa)
return -ENOMEM;

#ifdef CONFIG_HYPERV_VTL_MODE
int i;

for_each_possible_cpu(i) {
if (per_cpu(x86_cpu_to_apicid, i) == apic_id) {
cpu_id = i;
break;
}
}

if (cpu_id == -EINVAL)
panic("%s: no cpu found for APIC ID %d\n", __func__, apic_id);

/* Find the Hyper-V VP index which might be not the same as APIC ID */
vp_index = hv_apicid_to_vp_index(apic_id);
if (vp_index < 0 || vp_index > ms_hyperv.max_vp_index)
return -EINVAL;
Comment on lines 310 to 311
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

On the vp_index validation failure path, the function returns -EINVAL without freeing the newly allocated VMSA page (vmsa), leaking a page. Free vmsa (free_page()) before returning, e.g., via a common error path/goto.

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.
#endif

native_store_gdt(&gdtr);

Expand Down Expand Up @@ -403,13 +388,13 @@ int hv_snp_boot_ap(u32 apic_id, unsigned long start_ip, unsigned int cpu)
vmsa = NULL;
}

cur_vmsa = per_cpu(hv_sev_vmsa, cpu_id);
cur_vmsa = per_cpu(hv_sev_vmsa, cpu);
/* Free up any previous VMSA page */
if (cur_vmsa)
snp_cleanup_vmsa(cur_vmsa);

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

return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ static __init int print_s5_reset_status_mmio(void)
* The below ioread32() causes a triple fault for SNP due to a hypevisor
* bug. Work it around for now.
*/
if (!ms_hyperv.paravisor_present && hv_isolation_type_snp())
if (!ms_hyperv.paravisor_present && hv_is_isolation_supported())
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

The comment says the ioread32() triple-fault issue is SNP-specific, but the new condition skips the read for any Hyper-V isolation type (hv_is_isolation_supported()), which includes non-SNP isolation modes. Either narrow the condition back to hv_isolation_type_snp() or update the comment to match the broadened behavior (and justify why all isolation types need the workaround).

Suggested change
if (!ms_hyperv.paravisor_present && hv_is_isolation_supported())
if (!ms_hyperv.paravisor_present && hv_isolation_type_snp())

Copilot uses AI. Check for mistakes.
return 0;

if (!cpu_feature_enabled(X86_FEATURE_ZEN))
Expand Down
Loading