Skip to content

Commit e13aaf2

Browse files
kelleymhtyhicks
authored andcommitted
Drivers: hv: vmbus: Move Hyper-V page allocator to arch neutral code
The Hyper-V page allocator functions are implemented in an architecture neutral way. Move them into the architecture neutral VMbus module so a separate implementation for ARM64 is not needed. No functional change. Signed-off-by: Michael Kelley <mikelley@microsoft.com> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/1614721102-2241-2-git-send-email-mikelley@microsoft.com Signed-off-by: Wei Liu <wei.liu@kernel.org> (cherry picked from commit ca48739) Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
1 parent 2cd5fe2 commit e13aaf2

4 files changed

Lines changed: 40 additions & 27 deletions

File tree

arch/x86/hyperv/hv_init.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,6 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg);
4747
u32 hv_max_vp_index;
4848
EXPORT_SYMBOL_GPL(hv_max_vp_index);
4949

50-
void *hv_alloc_hyperv_page(void)
51-
{
52-
BUILD_BUG_ON(PAGE_SIZE != HV_HYP_PAGE_SIZE);
53-
54-
return (void *)__get_free_page(GFP_KERNEL);
55-
}
56-
EXPORT_SYMBOL_GPL(hv_alloc_hyperv_page);
57-
58-
void *hv_alloc_hyperv_zeroed_page(void)
59-
{
60-
BUILD_BUG_ON(PAGE_SIZE != HV_HYP_PAGE_SIZE);
61-
62-
return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
63-
}
64-
EXPORT_SYMBOL_GPL(hv_alloc_hyperv_zeroed_page);
65-
66-
void hv_free_hyperv_page(unsigned long addr)
67-
{
68-
free_page(addr);
69-
}
70-
EXPORT_SYMBOL_GPL(hv_free_hyperv_page);
71-
7250
static int hv_cpu_init(unsigned int cpu)
7351
{
7452
u64 msr_vp_index;

arch/x86/include/asm/mshyperv.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,6 @@ static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)
226226

227227
void __init hyperv_init(void);
228228
void hyperv_setup_mmu_ops(void);
229-
void *hv_alloc_hyperv_page(void);
230-
void *hv_alloc_hyperv_zeroed_page(void);
231-
void hv_free_hyperv_page(unsigned long addr);
232229
void set_hv_tscchange_cb(void (*cb)(void));
233230
void clear_hv_tscchange_cb(void);
234231
void hyperv_stop_tsc_emulation(void);
@@ -257,8 +254,6 @@ static inline void hv_set_msi_entry_from_desc(union hv_msi_entry *msi_entry,
257254
#else /* CONFIG_HYPERV */
258255
static inline void hyperv_init(void) {}
259256
static inline void hyperv_setup_mmu_ops(void) {}
260-
static inline void *hv_alloc_hyperv_page(void) { return NULL; }
261-
static inline void hv_free_hyperv_page(unsigned long addr) {}
262257
static inline void set_hv_tscchange_cb(void (*cb)(void)) {}
263258
static inline void clear_hv_tscchange_cb(void) {}
264259
static inline void hyperv_stop_tsc_emulation(void) {};

drivers/hv/hv.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,42 @@ int hv_init(void)
3636
return 0;
3737
}
3838

39+
/*
40+
* Functions for allocating and freeing memory with size and
41+
* alignment HV_HYP_PAGE_SIZE. These functions are needed because
42+
* the guest page size may not be the same as the Hyper-V page
43+
* size. We depend upon kmalloc() aligning power-of-two size
44+
* allocations to the allocation size boundary, so that the
45+
* allocated memory appears to Hyper-V as a page of the size
46+
* it expects.
47+
*/
48+
49+
void *hv_alloc_hyperv_page(void)
50+
{
51+
BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE);
52+
53+
if (PAGE_SIZE == HV_HYP_PAGE_SIZE)
54+
return (void *)__get_free_page(GFP_KERNEL);
55+
else
56+
return kmalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
57+
}
58+
59+
void *hv_alloc_hyperv_zeroed_page(void)
60+
{
61+
if (PAGE_SIZE == HV_HYP_PAGE_SIZE)
62+
return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
63+
else
64+
return kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
65+
}
66+
67+
void hv_free_hyperv_page(unsigned long addr)
68+
{
69+
if (PAGE_SIZE == HV_HYP_PAGE_SIZE)
70+
free_page(addr);
71+
else
72+
kfree((void *)addr);
73+
}
74+
3975
/*
4076
* hv_post_message - Post a message using the hypervisor message IPC.
4177
*

include/asm-generic/mshyperv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ extern u32 hv_max_vp_index;
114114
/* Sentinel value for an uninitialized entry in hv_vp_index array */
115115
#define VP_INVAL U32_MAX
116116

117+
void *hv_alloc_hyperv_page(void);
118+
void *hv_alloc_hyperv_zeroed_page(void);
119+
void hv_free_hyperv_page(unsigned long addr);
120+
117121
/**
118122
* hv_cpu_number_to_vp_number() - Map CPU to VP.
119123
* @cpu_number: CPU number in Linux terms

0 commit comments

Comments
 (0)