[PATCH v3 3/3] hv: vmbus: allocate requestor metadata with kvcalloc()

From: Emerson Busson

Date: Tue Nov 24 2026 - 16:41:28 EST


Opening a VMBus channel allocates a request-ID array and bitmap sized
from the ring buffer. For a 128-page NetVSC ring, kcalloc() and
bitmap_zalloc() require multi-page physically contiguous allocations
that can fail under buddy fragmentation even when order-0 pages remain
available.

Switch both guest-private structures to kvcalloc() and free them with
kvfree(), keeping slab allocation for small channels while allowing
vmalloc fallback under fragmentation. Guard against a zero requestor
size and clear the pointers after freeing.

Signed-off-by: Emerson Busson <emersonbusson@xxxxxxxxx>
---
drivers/hv/channel.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index c0bf154915..8547b10f3d 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -733,10 +733,13 @@ EXPORT_SYMBOL_GPL(vmbus_alloc_buffer);
*/
static u64 *request_arr_init(u32 size)
{
- int i;
+ u32 i;
u64 *req_arr;

- req_arr = kcalloc(size, sizeof(u64), GFP_KERNEL);
+ if (!size)
+ return NULL;
+
+ req_arr = kvcalloc(size, sizeof(*req_arr), GFP_KERNEL);
if (!req_arr)
return NULL;

@@ -763,9 +766,10 @@ static int vmbus_alloc_requestor(struct vmbus_requestor *rqstor, u32 size)
if (!rqst_arr)
return -ENOMEM;

- bitmap = bitmap_zalloc(size, GFP_KERNEL);
+ bitmap = kvcalloc(size / BITS_PER_LONG + !!(size % BITS_PER_LONG),
+ sizeof(*bitmap), GFP_KERNEL);
if (!bitmap) {
- kfree(rqst_arr);
+ kvfree(rqst_arr);
return -ENOMEM;
}

@@ -784,8 +788,10 @@ static int vmbus_alloc_requestor(struct vmbus_requestor *rqstor, u32 size)
*/
static void vmbus_free_requestor(struct vmbus_requestor *rqstor)
{
- kfree(rqstor->req_arr);
- bitmap_free(rqstor->req_bitmap);
+ kvfree(rqstor->req_arr);
+ kvfree(rqstor->req_bitmap);
+ rqstor->req_arr = NULL;
+ rqstor->req_bitmap = NULL;
}

static int __vmbus_open(struct vmbus_channel *newchannel,
--
2.43.0