Skip to content

Commit 8c3e44b

Browse files
fishavoreKAGA-KOKO
authored andcommitted
x86/hyperv: Add functions to allocate/deallocate page for Hyper-V
Introduce two new functions, hv_alloc_hyperv_page() and hv_free_hyperv_page(), to allocate/deallocate memory with the size and alignment that Hyper-V expects as a page. Although currently they are not used, they are ready to be used to allocate/deallocate memory on x86 when their ARM64 counterparts are implemented, keeping symmetry between architectures with potentially different guest page sizes. Signed-off-by: Maya Nakamura <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Reviewed-by: Vitaly Kuznetsov <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Link: https://lore.kernel.org/lkml/[email protected]/ Link: https://lkml.kernel.org/r/706b2e71eb3e587b5f8801e50f090fae2a00e35d.1562916939.git.m.maya.nakamura@gmail.com
1 parent fcd3f62 commit 8c3e44b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg);
3737
u32 hv_max_vp_index;
3838
EXPORT_SYMBOL_GPL(hv_max_vp_index);
3939

40+
void *hv_alloc_hyperv_page(void)
41+
{
42+
BUILD_BUG_ON(PAGE_SIZE != HV_HYP_PAGE_SIZE);
43+
44+
return (void *)__get_free_page(GFP_KERNEL);
45+
}
46+
EXPORT_SYMBOL_GPL(hv_alloc_hyperv_page);
47+
48+
void hv_free_hyperv_page(unsigned long addr)
49+
{
50+
free_page(addr);
51+
}
52+
EXPORT_SYMBOL_GPL(hv_free_hyperv_page);
53+
4054
static int hv_cpu_init(unsigned int cpu)
4155
{
4256
u64 msr_vp_index;

arch/x86/include/asm/mshyperv.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)
218218

219219
void __init hyperv_init(void);
220220
void hyperv_setup_mmu_ops(void);
221-
221+
void *hv_alloc_hyperv_page(void);
222+
void hv_free_hyperv_page(unsigned long addr);
222223
void hyperv_reenlightenment_intr(struct pt_regs *regs);
223224
void set_hv_tscchange_cb(void (*cb)(void));
224225
void clear_hv_tscchange_cb(void);
@@ -241,6 +242,8 @@ static inline void hv_apic_init(void) {}
241242
#else /* CONFIG_HYPERV */
242243
static inline void hyperv_init(void) {}
243244
static inline void hyperv_setup_mmu_ops(void) {}
245+
static inline void *hv_alloc_hyperv_page(void) { return NULL; }
246+
static inline void hv_free_hyperv_page(unsigned long addr) {}
244247
static inline void set_hv_tscchange_cb(void (*cb)(void)) {}
245248
static inline void clear_hv_tscchange_cb(void) {}
246249
static inline void hyperv_stop_tsc_emulation(void) {};

0 commit comments

Comments
 (0)