Skip to content

Commit 2982635

Browse files
anirudhrbliuw
authored andcommitted
x86/hyperv: fix invalid writes to MSRs during root partition kexec
hyperv_cleanup resets the hypercall page by setting the MSR to 0. However, the root partition is not allowed to write to the GPA bits of the MSR. Instead, it uses the hypercall page provided by the MSR. Similar is the case with the reference TSC MSR. Clear only the enable bit instead of zeroing the entire MSR to make the code valid for root partition too. Signed-off-by: Anirudh Rayabharam <anrayabh@linux.microsoft.com> Reviewed-by: Michael Kelley <mikelley@microsoft.com> Link: https://lore.kernel.org/r/20221027095729.1676394-3-anrayabh@linux.microsoft.com Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent 4ad1aa5 commit 2982635

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

arch/x86/hyperv/hv_init.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ void __init hyperv_init(void)
535535
void hyperv_cleanup(void)
536536
{
537537
union hv_x64_msr_hypercall_contents hypercall_msr;
538+
union hv_reference_tsc_msr tsc_msr;
538539

539540
unregister_syscore_ops(&hv_syscore_ops);
540541

@@ -550,12 +551,14 @@ void hyperv_cleanup(void)
550551
hv_hypercall_pg = NULL;
551552

552553
/* Reset the hypercall page */
553-
hypercall_msr.as_uint64 = 0;
554-
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
554+
hypercall_msr.as_uint64 = hv_get_register(HV_X64_MSR_HYPERCALL);
555+
hypercall_msr.enable = 0;
556+
hv_set_register(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
555557

556558
/* Reset the TSC page */
557-
hypercall_msr.as_uint64 = 0;
558-
wrmsrl(HV_X64_MSR_REFERENCE_TSC, hypercall_msr.as_uint64);
559+
tsc_msr.as_uint64 = hv_get_register(HV_X64_MSR_REFERENCE_TSC);
560+
tsc_msr.enable = 0;
561+
hv_set_register(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
559562
}
560563

561564
void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die)

0 commit comments

Comments
 (0)