]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary
authorLong Li <longli@microsoft.com>
Tue, 6 May 2025 00:56:33 +0000 (17:56 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 6 Jul 2025 08:57:58 +0000 (10:57 +0200)
[ Upstream commit 09eea7ad0b8e973dcf5ed49902838e5d68177f8e ]

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: ca48739e59df ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hv/connection.c

index 744d2809acc3fb531721f269d91e006c5bad7e23..7bb94e0dd0f6677839f65d703bd7ad68359fa700 100644 (file)
@@ -205,11 +205,20 @@ int vmbus_connect(void)
        INIT_LIST_HEAD(&vmbus_connection.chn_list);
        mutex_init(&vmbus_connection.channel_mutex);
 
+       /*
+        * The following Hyper-V interrupt and monitor pages can be used by
+        * UIO for mapping to user-space, so they should always be allocated on
+        * system page boundaries. The system page size must be >= the Hyper-V
+        * page size.
+        */
+       BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE);
+
        /*
         * Setup the vmbus event connection for channel interrupt
         * abstraction stuff
         */
-       vmbus_connection.int_page = hv_alloc_hyperv_zeroed_page();
+       vmbus_connection.int_page =
+               (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
        if (vmbus_connection.int_page == NULL) {
                ret = -ENOMEM;
                goto cleanup;
@@ -224,8 +233,8 @@ int vmbus_connect(void)
         * Setup the monitor notification facility. The 1st page for
         * parent->child and the 2nd page for child->parent
         */
-       vmbus_connection.monitor_pages[0] = hv_alloc_hyperv_page();
-       vmbus_connection.monitor_pages[1] = hv_alloc_hyperv_page();
+       vmbus_connection.monitor_pages[0] = (void *)__get_free_page(GFP_KERNEL);
+       vmbus_connection.monitor_pages[1] = (void *)__get_free_page(GFP_KERNEL);
        if ((vmbus_connection.monitor_pages[0] == NULL) ||
            (vmbus_connection.monitor_pages[1] == NULL)) {
                ret = -ENOMEM;
@@ -341,21 +350,23 @@ void vmbus_disconnect(void)
                destroy_workqueue(vmbus_connection.work_queue);
 
        if (vmbus_connection.int_page) {
-               hv_free_hyperv_page(vmbus_connection.int_page);
+               free_page((unsigned long)vmbus_connection.int_page);
                vmbus_connection.int_page = NULL;
        }
 
        if (vmbus_connection.monitor_pages[0]) {
                if (!set_memory_encrypted(
                        (unsigned long)vmbus_connection.monitor_pages[0], 1))
-                       hv_free_hyperv_page(vmbus_connection.monitor_pages[0]);
+                       free_page((unsigned long)
+                               vmbus_connection.monitor_pages[0]);
                vmbus_connection.monitor_pages[0] = NULL;
        }
 
        if (vmbus_connection.monitor_pages[1]) {
                if (!set_memory_encrypted(
                        (unsigned long)vmbus_connection.monitor_pages[1], 1))
-                       hv_free_hyperv_page(vmbus_connection.monitor_pages[1]);
+                       free_page((unsigned long)
+                               vmbus_connection.monitor_pages[1]);
                vmbus_connection.monitor_pages[1] = NULL;
        }
 }