Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/hyperv: Use vmmcall to implement Hyper-V hypercall in sev-snp enlightened guest

In sev-snp enlightened guest, Hyper-V hypercall needs
to use vmmcall to trigger vmexit and notify hypervisor
to handle hypercall request.

Signed-off-by: Tianyu Lan <tiala@microsoft.com>
Reviewed-by: Dexuan Cui <decui@microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Link: https://lore.kernel.org/r/20230818102919.1318039-6-ltykernel@gmail.com

authored by

Tianyu Lan and committed by
Wei Liu
48b1f683 193061ea

+27 -3
+27 -3
arch/x86/include/asm/mshyperv.h
··· 48 48 49 49 extern union hv_ghcb * __percpu *hv_ghcb_pg; 50 50 51 + extern bool hv_isolation_type_en_snp(void); 52 + 51 53 int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages); 52 54 int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id); 53 55 int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags); ··· 61 59 u64 hv_status; 62 60 63 61 #ifdef CONFIG_X86_64 62 + if (hv_isolation_type_en_snp()) { 63 + __asm__ __volatile__("mov %4, %%r8\n" 64 + "vmmcall" 65 + : "=a" (hv_status), ASM_CALL_CONSTRAINT, 66 + "+c" (control), "+d" (input_address) 67 + : "r" (output_address) 68 + : "cc", "memory", "r8", "r9", "r10", "r11"); 69 + return hv_status; 70 + } 71 + 64 72 if (!hv_hypercall_pg) 65 73 return U64_MAX; 66 74 ··· 114 102 u64 hv_status; 115 103 116 104 #ifdef CONFIG_X86_64 117 - { 105 + if (hv_isolation_type_en_snp()) { 106 + __asm__ __volatile__( 107 + "vmmcall" 108 + : "=a" (hv_status), ASM_CALL_CONSTRAINT, 109 + "+c" (control), "+d" (input1) 110 + :: "cc", "r8", "r9", "r10", "r11"); 111 + } else { 118 112 __asm__ __volatile__(CALL_NOSPEC 119 113 : "=a" (hv_status), ASM_CALL_CONSTRAINT, 120 114 "+c" (control), "+d" (input1) ··· 165 147 u64 hv_status; 166 148 167 149 #ifdef CONFIG_X86_64 168 - { 150 + if (hv_isolation_type_en_snp()) { 151 + __asm__ __volatile__("mov %4, %%r8\n" 152 + "vmmcall" 153 + : "=a" (hv_status), ASM_CALL_CONSTRAINT, 154 + "+c" (control), "+d" (input1) 155 + : "r" (input2) 156 + : "cc", "r8", "r9", "r10", "r11"); 157 + } else { 169 158 __asm__ __volatile__("mov %4, %%r8\n" 170 159 CALL_NOSPEC 171 160 : "=a" (hv_status), ASM_CALL_CONSTRAINT, ··· 265 240 #endif 266 241 267 242 extern bool hv_isolation_type_snp(void); 268 - extern bool hv_isolation_type_en_snp(void); 269 243 270 244 static inline bool hv_is_synic_reg(unsigned int reg) 271 245 {