Skip to contentSkip to conversation

x86/VMBus: DMA transfer with encrypted memory in Coco VM

RFC PATCH Superseded Tianyu Lan 1 participant 1 message Sep 3

Subsystems (2)
lore
Share & tools
lore

Tianyu Lan

author
#0 lore raw

RFC PATCH v2 1/1 x86/VMBus: DMA transfer with encrypted memory in Coco VM

In CoCo VMs, system memory is encrypted by default. Device drivers typically rely on the DMA core's SWIOTLB as a bounce buffer for DMA operations, providing decrypted memory that can be shared between the guest and host.

For PCI devices with T-Disp support and Confidential VMBus devices (https://lkml.org/lkml/2026/7/27/1733) can perform DMA transfers directly with private/encrypted memory in a CoCo VM.

To support DMA transfer with encrypted memory, Hyper-V DMA ops are introduced and bypass some API which may use swiotlb as bounce buffer.

The DMA ops used is global data structure(see get_arch_ dma_ops() and get_dma_ops() for details). There is no need to set up for each device individually.

---
Change since RFC v1:
* Fix warning, code style issues and make the code of reference dma ops under CONFIG_ARCH_HAS_DMA_OPS.

---
 drivers/hv/Kconfig        |   9 +++
 drivers/hv/Makefile       |   1 +
 drivers/hv/hv_dma_ops.c   | 138 ++++++++++++++++++++++++++++++++++++++
 drivers/hv/hyperv_vmbus.h |   1 +
 drivers/hv/vmbus_drv.c    |  19 +++++-
 5 files changed, 167 insertions(+), 1 deletion(-)
 create mode 100644 drivers/hv/hv_dma_ops.c
drivers/hv/Kconfig +9 -0
index 2d0b3fcb0ff87..fbbeb67cb2cab 100644
@@ -7,6 +7,7 @@ config HYPERV
 	depends on (X86 && X86_LOCAL_APIC && HYPERVISOR_GUEST) \
 		|| (ARM64 && !CPU_BIG_ENDIAN)
 	select PARAVIRT
+	select HYPERV_DMA_OPS
 	select X86_HV_CALLBACK_VECTOR if X86
 	select OF_EARLY_FLATTREE if OF
 	select IRQ_MSI_LIB if X86
@@ -14,6 +15,13 @@ config HYPERV
 	  Select this option to run Linux as a Hyper-V client operating
 	  system.
 
+config HYPERV_DMA_OPS
+	bool "Enable Microsoft Hyper-V DMA ops support"
+	depends on ARCH_HAS_DMA_OPS
+	help
+	  Select this option to enable DMA with encrypt
+	  memory in CoCo VM.
+
 config HYPERV_VTL_MODE
 	bool "Enable Linux to boot in VTL context"
 	depends on (X86_64 && HAVE_STATIC_CALL) || ARM64
@@ -62,6 +70,7 @@ config HYPERV_VMBUS
 	depends on HYPERV
 	default HYPERV
 	select SYSFB if EFI && !HYPERV_VTL_MODE
+	default y if HYPERV_DMA_OPS
 	help
 	  Select this option to enable Hyper-V Vmbus driver.
 
drivers/hv/Makefile +1 -0
index 888a748cc7cb9..b4d23c88b9eb0 100644
@@ -2,6 +2,7 @@
 obj-$(CONFIG_HYPERV_VMBUS)	+= hv_vmbus.o
 obj-$(CONFIG_HYPERV_UTILS)	+= hv_utils.o
 obj-$(CONFIG_HYPERV_BALLOON)	+= hv_balloon.o
+obj-$(CONFIG_HYPERV_DMA_OPS)	+= hv_dma_ops.o
 obj-$(CONFIG_MSHV_ROOT)		+= mshv_root.o
 obj-$(CONFIG_MSHV_VTL)          += mshv_vtl.o
 
drivers/hv/hv_dma_ops.c new file +138 -0

138 lines not on this page · raw message

drivers/hv/hyperv_vmbus.h +1 -0
index 05a36854389af..94f16382bba7b 100644
@@ -356,6 +356,7 @@ extern const struct vmbus_channel_message_table_entry
 /* General vmbus interface */
 
 bool vmbus_is_confidential(void);
+bool is_vmbus_dev(struct device *dev);
 
 #if IS_ENABLED(CONFIG_HYPERV_VMBUS)
 /* Free the message slot and signal end-of-message if required */
drivers/hv/vmbus_drv.c +18 -1
index d28ff45d4cfdd..a45a1d010a1cd 100644
@@ -40,6 +40,12 @@
 #include <clocksource/hyperv_timer.h>
 #include <asm/mshyperv.h>
 #include "hyperv_vmbus.h"
+#include "../../kernel/dma/direct.h"
+
+#ifdef CONFIG_ARCH_HAS_DMA_OPS
+const struct dma_map_ops *dma_ops;
+const struct dma_map_ops hyperv_dma_ops;
+#endif
 
 struct vmbus_dynid {
 	struct list_head node;
@@ -62,6 +68,7 @@ int vmbus_interrupt;
  * visible to either the host or the hypervisor.
  */
 static bool is_confidential;
+static const struct bus_type  hv_bus;
 
 bool vmbus_is_confidential(void)
 {
@@ -69,6 +76,11 @@ bool vmbus_is_confidential(void)
 }
 EXPORT_SYMBOL_GPL(vmbus_is_confidential);
 
+bool is_vmbus_dev(struct device *dev)
+{
+	return dev->bus == &hv_bus;
+}
+
 /*
  * The panic notifier below is responsible solely for unloading the
  * vmbus connection, which is necessary in a panic event.
@@ -1523,8 +1535,13 @@ static int vmbus_bus_init(void)
 	 * doing that on each VP while initializing SynIC's wastes time.
 	 */
 	is_confidential = ms_hyperv.confidential_vmbus_available;
-	if (is_confidential)
+	if (is_confidential) {
+#ifdef CONFIG_ARCH_HAS_DMA_OPS
+		dma_ops = &hyperv_dma_ops;
+#endif
 		pr_info("Establishing connection to the confidential VMBus\n");
+	}
+
 	hv_para_set_sint_proxy(!is_confidential);
 	ret = vmbus_alloc_synic_and_connect();
 	if (ret)
Signature · 1 line
2.53.0