Skip to content

Commit 09eea7a

Browse files
longlimsftliuw
authored andcommitted
Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary
There are use cases that interrupt and monitor pages are mapped to user-mode through UIO, so they need to be system page aligned. Some Hyper-V allocation APIs introduced earlier broke those requirements. Fix this by using page allocation functions directly for interrupt and monitor pages. Cc: stable@vger.kernel.org Fixes: ca48739 ("Drivers: hv: vmbus: Move Hyper-V page allocator to arch neutral code") Signed-off-by: Long Li <longli@microsoft.com> Reviewed-by: Michael Kelley <mhklinux@outlook.com> Link: https://lore.kernel.org/r/1746492997-4599-2-git-send-email-longli@linuxonhyperv.com Signed-off-by: Wei Liu <wei.liu@kernel.org> Message-ID: <1746492997-4599-2-git-send-email-longli@linuxonhyperv.com>
1 parent 43cb39a commit 09eea7a

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

drivers/hv/connection.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,20 @@ int vmbus_connect(void)
206206
INIT_LIST_HEAD(&vmbus_connection.chn_list);
207207
mutex_init(&vmbus_connection.channel_mutex);
208208

209+
/*
210+
* The following Hyper-V interrupt and monitor pages can be used by
211+
* UIO for mapping to user-space, so they should always be allocated on
212+
* system page boundaries. The system page size must be >= the Hyper-V
213+
* page size.
214+
*/
215+
BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE);
216+
209217
/*
210218
* Setup the vmbus event connection for channel interrupt
211219
* abstraction stuff
212220
*/
213-
vmbus_connection.int_page = hv_alloc_hyperv_zeroed_page();
221+
vmbus_connection.int_page =
222+
(void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
214223
if (vmbus_connection.int_page == NULL) {
215224
ret = -ENOMEM;
216225
goto cleanup;
@@ -225,8 +234,8 @@ int vmbus_connect(void)
225234
* Setup the monitor notification facility. The 1st page for
226235
* parent->child and the 2nd page for child->parent
227236
*/
228-
vmbus_connection.monitor_pages[0] = hv_alloc_hyperv_page();
229-
vmbus_connection.monitor_pages[1] = hv_alloc_hyperv_page();
237+
vmbus_connection.monitor_pages[0] = (void *)__get_free_page(GFP_KERNEL);
238+
vmbus_connection.monitor_pages[1] = (void *)__get_free_page(GFP_KERNEL);
230239
if ((vmbus_connection.monitor_pages[0] == NULL) ||
231240
(vmbus_connection.monitor_pages[1] == NULL)) {
232241
ret = -ENOMEM;
@@ -342,21 +351,23 @@ void vmbus_disconnect(void)
342351
destroy_workqueue(vmbus_connection.work_queue);
343352

344353
if (vmbus_connection.int_page) {
345-
hv_free_hyperv_page(vmbus_connection.int_page);
354+
free_page((unsigned long)vmbus_connection.int_page);
346355
vmbus_connection.int_page = NULL;
347356
}
348357

349358
if (vmbus_connection.monitor_pages[0]) {
350359
if (!set_memory_encrypted(
351360
(unsigned long)vmbus_connection.monitor_pages[0], 1))
352-
hv_free_hyperv_page(vmbus_connection.monitor_pages[0]);
361+
free_page((unsigned long)
362+
vmbus_connection.monitor_pages[0]);
353363
vmbus_connection.monitor_pages[0] = NULL;
354364
}
355365

356366
if (vmbus_connection.monitor_pages[1]) {
357367
if (!set_memory_encrypted(
358368
(unsigned long)vmbus_connection.monitor_pages[1], 1))
359-
hv_free_hyperv_page(vmbus_connection.monitor_pages[1]);
369+
free_page((unsigned long)
370+
vmbus_connection.monitor_pages[1]);
360371
vmbus_connection.monitor_pages[1] = NULL;
361372
}
362373
}

0 commit comments

Comments
 (0)