Skip to content

Commit ca48739

Browse files
kelleymhliuw
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>
1 parent f850a4c commit ca48739

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
@@ -54,28 +54,6 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg);
5454
u32 hv_max_vp_index;
5555
EXPORT_SYMBOL_GPL(hv_max_vp_index);
5656

57-
void *hv_alloc_hyperv_page(void)
58-
{
59-
BUILD_BUG_ON(PAGE_SIZE != HV_HYP_PAGE_SIZE);
60-
61-
return (void *)__get_free_page(GFP_KERNEL);
62-
}
63-
EXPORT_SYMBOL_GPL(hv_alloc_hyperv_page);
64-
65-
void *hv_alloc_hyperv_zeroed_page(void)
66-
{
67-
BUILD_BUG_ON(PAGE_SIZE != HV_HYP_PAGE_SIZE);
68-
69-
return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
70-
}
71-
EXPORT_SYMBOL_GPL(hv_alloc_hyperv_zeroed_page);
72-
73-
void hv_free_hyperv_page(unsigned long addr)
74-
{
75-
free_page(addr);
76-
}
77-
EXPORT_SYMBOL_GPL(hv_free_hyperv_page);
78-
7957
static int hv_cpu_init(unsigned int cpu)
8058
{
8159
u64 msr_vp_index;

‎arch/x86/include/asm/mshyperv.h‎

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

234234
void __init hyperv_init(void);
235235
void hyperv_setup_mmu_ops(void);
236-
void *hv_alloc_hyperv_page(void);
237-
void *hv_alloc_hyperv_zeroed_page(void);
238-
void hv_free_hyperv_page(unsigned long addr);
239236
void set_hv_tscchange_cb(void (*cb)(void));
240237
void clear_hv_tscchange_cb(void);
241238
void hyperv_stop_tsc_emulation(void);
@@ -272,8 +269,6 @@ int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry);
272269
#else /* CONFIG_HYPERV */
273270
static inline void hyperv_init(void) {}
274271
static inline void hyperv_setup_mmu_ops(void) {}
275-
static inline void *hv_alloc_hyperv_page(void) { return NULL; }
276-
static inline void hv_free_hyperv_page(unsigned long addr) {}
277272
static inline void set_hv_tscchange_cb(void (*cb)(void)) {}
278273
static inline void clear_hv_tscchange_cb(void) {}
279274
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
@@ -117,6 +117,10 @@ extern u32 hv_max_vp_index;
117117
/* Sentinel value for an uninitialized entry in hv_vp_index array */
118118
#define VP_INVAL U32_MAX
119119

120+
void *hv_alloc_hyperv_page(void);
121+
void *hv_alloc_hyperv_zeroed_page(void);
122+
void hv_free_hyperv_page(unsigned long addr);
123+
120124
/**
121125
* hv_cpu_number_to_vp_number() - Map CPU to VP.
122126
* @cpu_number: CPU number in Linux terms

0 commit comments

Comments
 (0)