summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorKameron Carr <kameroncarr@linux.microsoft.com>2026-08-11 09:04:46 -0700
committerWei Liu <wei.liu@kernel.org>2026-08-24 00:33:24 +0000
commit73fe42af955a24b6cc792b9a4867e809196f05ed (patch)
tree9706cc1d4eb4aaef3cfaa9044520a92ff019fd17 /include/linux
parent8f1da3536b8f8420988fe6e6ae15d58afa2ba2d8 (diff)
downloadlinux-73fe42af955a24b6cc792b9a4867e809196f05ed.tar.gz
linux-73fe42af955a24b6cc792b9a4867e809196f05ed.zip
Drivers: hv: vmbus: Add vmbus_alloc_buffer()/vmbus_free_buffer() for CoCo VMs
On CoCo VMs without confidential VMBus, the netvsc send and receive buffers must be made host-visible by decrypting them. These buffers are vmalloc'ed, but set_memory_decrypted()/encrypted() do not work on vmalloc'ed memory. This use case is (so far) unique to netvsc, so solve it locally rather than changing the set_memory() or allocation APIs. Add vmbus_alloc_buffer()/vmbus_free_buffer() to the VMBus core. When the guest's isolation model requires it, allocate the buffer as a list of physically-contiguous chunks via alloc_pages_node(), starting at MAX_PAGE_ORDER and falling back to smaller orders so the allocation still succeeds under memory fragmentation. Each chunk is decrypted in place via set_memory_decrypted() on its direct-map address, and the chunks are then stitched into a single virtually-contiguous range with vmap(). Buffers that do not need decryption keep using vzalloc(). To free the buffer, vmbus_free_buffer() calls vunmap() on the range then re-encrypts and frees each chunk individually; any chunk that fails re-encryption is leaked to prevent accidentally freeing decrypted memory. This approach minimizes scattering of decrypted 4 KiB pages through the kernel direct map and the resulting shattering of large page mappings. Signed-off-by: Kameron Carr <kameroncarr@linux.microsoft.com> Reviewed-by: Michael Kelley <mhklinux@outlook.com> Signed-off-by: Wei Liu <wei.liu@kernel.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/hyperv.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 08b927fab610..a97be78653e8 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -1214,6 +1214,13 @@ extern int vmbus_establish_gpadl_caller_decrypted(struct vmbus_channel *channel,
extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
struct vmbus_gpadl *gpadl);
+extern void *vmbus_alloc_buffer(struct vmbus_channel *channel,
+ u32 size,
+ struct page ***chunks_out,
+ u32 *chunk_cnt_out);
+
+extern void vmbus_free_buffer(void *addr, struct page **chunks, u32 chunk_cnt);
+
void vmbus_reset_channel_cb(struct vmbus_channel *channel);
extern int vmbus_recvpacket(struct vmbus_channel *channel,