Skip to content

Commit 48b1f68

Browse files
tialaliuw
authored andcommitted
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
1 parent 193061e commit 48b1f68

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

arch/x86/include/asm/mshyperv.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ extern u64 hv_current_partition_id;
4848

4949
extern union hv_ghcb * __percpu *hv_ghcb_pg;
5050

51+
extern bool hv_isolation_type_en_snp(void);
52+
5153
int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
5254
int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
5355
int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
@@ -59,6 +61,16 @@ static inline u64 hv_do_hypercall(u64 control, void *input, void *output)
5961
u64 hv_status;
6062

6163
#ifdef CONFIG_X86_64
64+
if (hv_isolation_type_en_snp()) {
65+
__asm__ __volatile__("mov %4, %%r8\n"
66+
"vmmcall"
67+
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
68+
"+c" (control), "+d" (input_address)
69+
: "r" (output_address)
70+
: "cc", "memory", "r8", "r9", "r10", "r11");
71+
return hv_status;
72+
}
73+
6274
if (!hv_hypercall_pg)
6375
return U64_MAX;
6476

@@ -102,7 +114,13 @@ static inline u64 _hv_do_fast_hypercall8(u64 control, u64 input1)
102114
u64 hv_status;
103115

104116
#ifdef CONFIG_X86_64
105-
{
117+
if (hv_isolation_type_en_snp()) {
118+
__asm__ __volatile__(
119+
"vmmcall"
120+
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
121+
"+c" (control), "+d" (input1)
122+
:: "cc", "r8", "r9", "r10", "r11");
123+
} else {
106124
__asm__ __volatile__(CALL_NOSPEC
107125
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
108126
"+c" (control), "+d" (input1)
@@ -147,7 +165,14 @@ static inline u64 _hv_do_fast_hypercall16(u64 control, u64 input1, u64 input2)
147165
u64 hv_status;
148166

149167
#ifdef CONFIG_X86_64
150-
{
168+
if (hv_isolation_type_en_snp()) {
169+
__asm__ __volatile__("mov %4, %%r8\n"
170+
"vmmcall"
171+
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
172+
"+c" (control), "+d" (input1)
173+
: "r" (input2)
174+
: "cc", "r8", "r9", "r10", "r11");
175+
} else {
151176
__asm__ __volatile__("mov %4, %%r8\n"
152177
CALL_NOSPEC
153178
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
@@ -240,7 +265,6 @@ static inline void hv_vtom_init(void) {}
240265
#endif
241266

242267
extern bool hv_isolation_type_snp(void);
243-
extern bool hv_isolation_type_en_snp(void);
244268

245269
static inline bool hv_is_synic_reg(unsigned int reg)
246270
{

0 commit comments

Comments
 (0)