Skip to content

Commit eb914cf

Browse files
Tianyu Lanbonzini
authored andcommitted
X86/Hyper-V: Add flush HvFlushGuestPhysicalAddressSpace hypercall support
Hyper-V supports a pv hypercall HvFlushGuestPhysicalAddressSpace to flush nested VM address space mapping in l1 hypervisor and it's to reduce overhead of flushing ept tlb among vcpus. This patch is to implement it. Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com> Acked-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 3553ae5 commit eb914cf

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

arch/x86/hyperv/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
obj-y := hv_init.o mmu.o
1+
obj-y := hv_init.o mmu.o nested.o
22
obj-$(CONFIG_X86_64) += hv_apic.o

arch/x86/hyperv/nested.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
/*
4+
* Hyper-V nested virtualization code.
5+
*
6+
* Copyright (C) 2018, Microsoft, Inc.
7+
*
8+
* Author : Lan Tianyu <Tianyu.Lan@microsoft.com>
9+
*/
10+
11+
12+
#include <linux/types.h>
13+
#include <asm/hyperv-tlfs.h>
14+
#include <asm/mshyperv.h>
15+
#include <asm/tlbflush.h>
16+
17+
int hyperv_flush_guest_mapping(u64 as)
18+
{
19+
struct hv_guest_mapping_flush **flush_pcpu;
20+
struct hv_guest_mapping_flush *flush;
21+
u64 status;
22+
unsigned long flags;
23+
int ret = -ENOTSUPP;
24+
25+
if (!hv_hypercall_pg)
26+
goto fault;
27+
28+
local_irq_save(flags);
29+
30+
flush_pcpu = (struct hv_guest_mapping_flush **)
31+
this_cpu_ptr(hyperv_pcpu_input_arg);
32+
33+
flush = *flush_pcpu;
34+
35+
if (unlikely(!flush)) {
36+
local_irq_restore(flags);
37+
goto fault;
38+
}
39+
40+
flush->address_space = as;
41+
flush->flags = 0;
42+
43+
status = hv_do_hypercall(HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE,
44+
flush, NULL);
45+
local_irq_restore(flags);
46+
47+
if (!(status & HV_HYPERCALL_RESULT_MASK))
48+
ret = 0;
49+
50+
fault:
51+
return ret;
52+
}
53+
EXPORT_SYMBOL_GPL(hyperv_flush_guest_mapping);

arch/x86/include/asm/hyperv-tlfs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ struct ms_hyperv_tsc_page {
309309
#define HV_X64_MSR_REENLIGHTENMENT_CONTROL 0x40000106
310310

311311
/* Nested features (CPUID 0x4000000A) EAX */
312+
#define HV_X64_NESTED_GUEST_MAPPING_FLUSH BIT(18)
312313
#define HV_X64_NESTED_MSR_BITMAP BIT(19)
313314

314315
struct hv_reenlightenment_control {
@@ -350,6 +351,7 @@ struct hv_tsc_emulation_status {
350351
#define HVCALL_SEND_IPI_EX 0x0015
351352
#define HVCALL_POST_MESSAGE 0x005c
352353
#define HVCALL_SIGNAL_EVENT 0x005d
354+
#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af
353355

354356
#define HV_X64_MSR_VP_ASSIST_PAGE_ENABLE 0x00000001
355357
#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT 12
@@ -741,6 +743,12 @@ struct ipi_arg_ex {
741743
struct hv_vpset vp_set;
742744
};
743745

746+
/* HvFlushGuestPhysicalAddressSpace hypercalls */
747+
struct hv_guest_mapping_flush {
748+
u64 address_space;
749+
u64 flags;
750+
};
751+
744752
/* HvFlushVirtualAddressSpace, HvFlushVirtualAddressList hypercalls */
745753
struct hv_tlb_flush {
746754
u64 address_space;

arch/x86/include/asm/mshyperv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ void hyperv_reenlightenment_intr(struct pt_regs *regs);
305305
void set_hv_tscchange_cb(void (*cb)(void));
306306
void clear_hv_tscchange_cb(void);
307307
void hyperv_stop_tsc_emulation(void);
308+
int hyperv_flush_guest_mapping(u64 as);
308309

309310
#ifdef CONFIG_X86_64
310311
void hv_apic_init(void);
@@ -324,6 +325,7 @@ static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)
324325
{
325326
return NULL;
326327
}
328+
static inline int hyperv_flush_guest_mapping(u64 as) { return -1; }
327329
#endif /* CONFIG_HYPERV */
328330

329331
#ifdef CONFIG_HYPERV_TSCPAGE

0 commit comments

Comments
 (0)