x86/VMBus: DMA transfer with encrypted memory in Coco VM
Subsystems (2)
RFC PATCH 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.
--- drivers/hv/Kconfig | 5 ++ drivers/hv/Makefile | 1 + drivers/hv/hv_dma_ops.c | 140 ++++++++++++++++++++++++++++++++++++++++ drivers/hv/vmbus_drv.c | 14 +++- 4 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 drivers/hv/hv_dma_ops.c
drivers/hv/Kconfig +5 -0
@@ -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,10 @@ 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 + config HYPERV_VTL_MODE bool "Enable Linux to boot in VTL context" depends on (X86_64 && HAVE_STATIC_CALL) || ARM64
drivers/hv/Makefile +1 -0
@@ -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 +140 -0
140 lines not on this page · raw message
drivers/hv/vmbus_drv.c +13 -1
@@ -40,6 +40,10 @@#include <clocksource/hyperv_timer.h> #include <asm/mshyperv.h> #include "hyperv_vmbus.h" +#include "../../kernel/dma/direct.h" + +extern const struct dma_map_ops *dma_ops; +extern const struct dma_map_ops hyperv_dma_ops;struct vmbus_dynid {struct list_head node;
@@ -1468,6 +1472,11 @@ static int vmbus_alloc_synic_and_connect(void)return -ENOMEM ; } +bool is_vmbus_dev (struct device *dev) +{ +return dev->bus == &hv_bus; +} +/* * vmbus_bus_init -Main vmbus driver initialization routine. *
@@ -1523,8 +1532,11 @@ 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) { + dma_ops = &hyperv_dma_ops;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
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider: - [Critical] The fallback paths in the allocation and deallocation functions recursively call the…
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider:
- [Critical] The fallback paths in the allocation and deallocation functions recursively call the high-level DMA API, causing infinite loops.
- [Critical] The custom DMA allocator ignores the device's coherent DMA mask, allocating memory above the hardware's addressing limits.
- [Critical] Streaming DMA mappings do not apply the mandatory memory encryption bit to physical addresses.
- [Critical] Bypass of architectural DMA cache synchronization in streaming mappings causes data corruption on non-coherent systems.
- [High] Globally overriding the dma_ops pointer breaks DMA for all non-VMBus devices on the system, and fails to restore the state on initialization errors.
- [High] The deallocation logic completely mismatches the allocation APIs, causing memory leaks, WARN_ONs, and skipped DMA unmapping.
- [Medium] The dma_supported map op callback incorrectly modifies device state instead of performing a read-only query.
- [Low] Referencing the global dma_ops pointer causes an undefined symbol linker error on ARM64.
- [Low] The else branch managing unencrypted memory mappings in hyperv_dma_alloc_coherent is unreachable.
--
--- Patch [1]: [RFC PATCH 1/1] x86/VMBus: DMA transfer with encrypted memory in Coco VM --- commit 7e352d385400a7e2fcde56e56c2991270a9e565d
Author: Tianyu Lan <[email protected]>
Subject: x86/VMBus: DMA transfer with encrypted memory in Coco VM
This commit introduces Hyper-V DMA ops to support DMA transfers directly with private/encrypted memory in CoCo VMs. It bypasses SWIOTLB bounce buffers for certain PCI and Confidential VMBus devices.
Quoted 6 lines
drivers/hv/hv_dma_ops.c new file +0
-0@@ -0,0 +1,140 @@
[ ... ]
drivers/hv/hv_dma_ops.c line 18
Quoted 5 lines
drivers/hv/hv_dma_ops.c new file +5
-0+#include <asm/mshyperv.h> +#include "hyperv_vmbus.h" +#include "../../kernel/dma/direct.h" + +extern const struct dma_map_ops *dma_ops;
[Severity: Low]
Is this extern declaration safe on ARM64?
The CONFIG_HYPERV option supports ARM64, but the global dma_ops variable is only exported on certain architectures like x86. On ARM64, this does not exist, which could result in an undefined symbol linker error.
[ ... ]
drivers/hv/hv_dma_ops.c line 46
Quoted 12 lines
drivers/hv/hv_dma_ops.c new file +12
-0+static int hyperv_dma_map_sg (struct device *dev,struct scatterlist *sgl, +int nelems,enum dma_data_direction dir, +unsigned long attrs) +{ +struct scatterlist *sg; +dma_addr_t dma_addr; +int i; + +if (hyperv_private_memory_dma (dev)) { +for_each_sg (sgl, sg, nelems, i) { + dma_addr =__phys_to_dma (dev,sg_phys (sg)); +sg_dma_address (sg) = dma_addr;
[Severity: Critical]
Does this mapping miss the mandatory memory encryption bit?
For private memory transfers in CoCo VMs, physical addresses must be mapped with a specific encryption bit. Returning the unencrypted physical address here could cause the hardware to access the memory as shared or decrypted.
[Severity: Critical]
Is it safe to skip cache synchronization here?
By returning early after translation without calling generic wrappers, and lacking .sync_single_for_cpu and .sync_single_for_device callbacks in the hyperv_dma_ops structure, this bypasses architectural DMA cache flushing. On architectures that are not hardware cache-coherent, this could lead to data corruption.
Quoted 8 lines
drivers/hv/hv_dma_ops.c new file +8
-0+sg_dma_len (sg) = sg->length; + } + +return nelems; + }else { +return dma_direct_map_sg (dev, sgl, nelems, dir, attrs); + } +}
[ ... ]
drivers/hv/hv_dma_ops.c line 65
Quoted 3 lines
drivers/hv/hv_dma_ops.c new file +3
-0+static int hyperv_dma_supported (struct device *dev,u64 mask) +{ + dev->coherent_dma_mask = mask;
[Severity: Medium]
Should a dma_supported callback modify the device state?
The ops->dma_supported callback is strictly a read-only query evaluated by functions like dma_supported(). Assigning dev->coherent_dma_mask here silently alters the device state when the driver only intends to query supported capabilities.
Quoted 2 lines
drivers/hv/hv_dma_ops.c new file +2
-0+return 1 ; +}
[ ... ]
drivers/hv/hv_dma_ops.c line 86
Quoted 10 lines
drivers/hv/hv_dma_ops.c new file +10
-0+/* allocate and map a coherent mapping */ +static void * +hyperv_dma_alloc_coherent (struct device *dev,size_t size,dma_addr_t *dma_handle, +gfp_t flag,unsigned long attrs) +{ +phys_addr_t phys; +void *ret; + +if (!hyperv_private_memory_dma (dev)) +return dma_alloc_coherent (dev, size, dma_handle, flag);
[Severity: Critical]
Can this fallback path cause an infinite recursion?
If hyperv_private_memory_dma() is false, this calls dma_alloc_coherent(). The core API looks up the device's DMA ops via get_dma_ops(), which now returns hyperv_dma_ops due to the global override. This would recursively call back into hyperv_dma_alloc_coherent(), leading to a stack overflow.
drivers/hv/hv_dma_ops.c line 89
Quoted 3 lines
drivers/hv/hv_dma_ops.c new file +3
-0+ + size =ALIGN (size,PAGE_SIZE ); + ret = (void *)__get_free_pages (flag,get_order (size));
[Severity: Critical]
Could this allocation bypass the device's DMA boundary constraints?
The core DMA API strips memory placement zone flags (like __GFP_DMA32) before calling ops->alloc, expecting the implementation to allocate from the correct zone based on dev->coherent_dma_mask. Blindly allocating via __get_free_pages() here could result in allocating memory above the hardware's addressing limits for devices with constrained DMA masks.
drivers/hv/hv_dma_ops.c line 97
Quoted 8 lines
drivers/hv/hv_dma_ops.c new file +8
-0+if (!ret) +return ret; + phys =virt_to_phys (ret); + +if (hyperv_private_memory_dma (dev)) + *dma_handle =dma_addr_encrypted (__phys_to_dma (dev, phys)); +else + *dma_handle =phys_to_dma_unencrypted (dev, phys);
[Severity: Low]
Is this else branch reachable?
The function returns early at the top if hyperv_private_memory_dma(dev) is false. By the time execution reaches this block, the condition is guaranteed to be true, making this else branch dead code.
drivers/hv/hv_dma_ops.c line 109
Quoted 12 lines
drivers/hv/hv_dma_ops.c new file +12
-0+ +memset (ret,0 , size); +return ret; +} + +/* free a coherent mapping */ +static void +hyperv_dma_free_coherent (struct device *dev,size_t size,void *vaddr, +dma_addr_t dma_addr,unsigned long attrs) +{ +if (hyperv_private_memory_dma (dev)) +dmam_free_coherent (dev, size, vaddr, dma_addr);
[Severity: Critical]
Can the dmam_free_coherent() call result in infinite recursion?
Since the memory was not allocated via devres, dmam_free_coherent() will fall back to dma_free_coherent(). This looks up ops->free and infinitely recurses back into hyperv_dma_free_coherent().
drivers/hv/hv_dma_ops.c
Quoted 2 lines
drivers/hv/hv_dma_ops.c new file +2
-0+else +free_pages ((unsigned long )vaddr,get_order (size));
[Severity: High]
Are the allocation and deallocation APIs correctly paired here?
The branches appear to use inverted APIs. For private memory, it is allocated via __get_free_pages() but freed using the devres-managed dmam_free_coherent(), which could fail to find a devres entry.
For non-private memory, it is allocated via dma_alloc_coherent() but incorrectly freed using free_pages(). Bypassing the DMA API on free skips SWIOTLB bounce buffer cleanup and IOMMU unmapping, potentially causing resource leaks.
drivers/hv/hv_dma_ops.c line 119
Quoted 8 lines
drivers/hv/hv_dma_ops.c new file +8
-0+} + +static dma_addr_t hyperv_dma_map_phys (struct device *dev,phys_addr_t phys, +size_t size,enum dma_data_direction dir, +unsigned long attrs) +{ +if (hyperv_private_memory_dma (dev)) +return __phys_to_dma (dev, phys);
[Severity: Critical]
Does this mapping miss the memory encryption bit?
Similar to hyperv_dma_map_sg, returning the unencrypted physical address for private memory transfers could cause the hardware to access the memory as shared or decrypted.
[Severity: Critical]
Is it safe to bypass generic cache synchronization wrappers here?
As with hyperv_dma_map_sg, missing the cache flushing could cause data corruption on non-coherent architectures.
Quoted 3 lines
drivers/hv/hv_dma_ops.c new file +3
-0+else +return dma_direct_map_phys (dev, phys, size, dir, attrs, true); +}
[ ... ]
drivers/hv/vmbus_drv.c line 45
Quoted 11 lines
drivers/hv/vmbus_drv.c +3
-0@@ -40,6 +40,10 @@#include <clocksource/hyperv_timer.h> #include <asm/mshyperv.h> #include "hyperv_vmbus.h" +#include "../../kernel/dma/direct.h" + +extern const struct dma_map_ops *dma_ops;
[Severity: Low]
Would this extern declaration cause build issues on ARM64?
The global dma_ops pointer does not exist on ARM64, which may result in a linker error on architectures that do not export it.
[ ... ]
drivers/hv/vmbus_drv.c static int vmbus_bus_init(void) · line 1531
Quoted 7 lines
drivers/hv/vmbus_drv.c +2
-1@@ -1518,8 +1527,11 @@ 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) { + dma_ops = &hyperv_dma_ops;
[Severity: High]
Could overriding the global dma_ops pointer affect other devices?
Setting the system-wide dma_ops pointer forces all standard non-VMBus devices to use these Hyper-V DMA ops. Additionally, if vmbus_alloc_synic_and_connect() fails later, this global pointer is left hijacked on the error path, which could lead to system failures for non-VMBus devices.
Quoted 4 lines
drivers/hv/vmbus_drv.c +2
-0pr_info ("Establishing connection to the confidential VMBus\n" ); + } +hv_para_set_sint_proxy (!is_confidential);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 11 lines · Tianyu Lan
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.
Quoted 8 lines
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.
Can we use __DMA_ATTR_ALLOC_CC_SHARED instead of checking hyperv_private_memory_dma(dev) directly? Also, would it be possible to encapsulate this logic in something like force_dma_encrypted(dev)?
Looking at functions such as hyperv_dma_alloc_coherent(), how does this differ from dma_direct_alloc()?
-aneesh
Quoted 18 lines · Aneesh Kumar K.V
Quoted 15 lines · Tianyu Lan
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.
Quoted 9 lines
Quoted 4 lines
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.Can we use
__DMA_ATTR_ALLOC_CC_SHAREDinstead of checkinghyperv_private_memory_dma(dev)directly? Also, would it be possible to encapsulate this logic in something likeforce_dma_encrypted(dev)?
Hi Aneesh:
Thanks for your review. I go through your patchset “dma-mapping: Use
DMA_ATTR_CC_SHARED”(https://lkml.org/lkml/2026/6/4/588). This patch is compatible with your DMA_ATTR_CC_SHARED attr work in dma-mapping layer. Once dma ops callbacks get DMA_ATTR_CC_SHARED attr flag and it may use the flag to replace hyperv_private_memory_dma().
Quoted 3 lines
Looking at functions such as
hyperv_dma_alloc_coherent(), how does this differ fromdma_direct_alloc()?
hyperv_dma_alloc_coherent() is to allocate memory and returns encrypted memory address directly when hyperv_private_memory_dma() is ture. This change is to keep all changes under Hyper-V subsystem and it's also compatible with existing solution which changes DMA core with minor changes.
--
Thanks
Tianyu Lan
Quoted 29 lines · Tianyu Lan
Quoted 18 lines · Aneesh Kumar K.V
Quoted 15 lines · Tianyu Lan
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.
Quoted 9 lines
Quoted 4 lines
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.Can we use
__DMA_ATTR_ALLOC_CC_SHAREDinstead of checkinghyperv_private_memory_dma(dev)directly? Also, would it be possible to encapsulate this logic in something likeforce_dma_encrypted(dev)?
Quoted 7 lines
Hi Aneesh:
Thanks for your review. I go through your patchset “dma-mapping: Use
DMA_ATTR_CC_SHARED”(https://lkml.org/lkml/2026/6/4/588). This patch is compatible with yourDMA_ATTR_CC_SHAREDattr work in dma-mapping layer. Once dma ops callbacks getDMA_ATTR_CC_SHAREDattr flag and it may use the flag to replacehyperv_private_memory_dma().
Can we rework this patch to use that?
Quoted 9 lines
Quoted 4 lines
Looking at functions such as
hyperv_dma_alloc_coherent(), how does this differ fromdma_direct_alloc()?
hyperv_dma_alloc_coherent()is to allocate memory and returns encrypted memory address directly whenhyperv_private_memory_dma()is ture. This change is to keep all changes under Hyper-V subsystem and it's also compatible with existing solution which changes DMA core with minor changes.
If we update force_dma_unencrypted(dev) to return false when an encrypted memory address is required, wouldn't the existing DMA-direct support handle this case? Or are there issues with the existing code? If so, could you explain them in more detail?
-aneesh
Quoted 50 lines · Aneesh Kumar K.V
Quoted 37 lines · Tianyu Lan
Quoted 18 lines · Aneesh Kumar K.V
Quoted 15 lines · Tianyu Lan
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.
Quoted 9 lines
Quoted 4 lines
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.Can we use
__DMA_ATTR_ALLOC_CC_SHAREDinstead of checkinghyperv_private_memory_dma(dev)directly? Also, would it be possible to encapsulate this logic in something likeforce_dma_encrypted(dev)?Hi Aneesh:
Thanks for your review. I go through your patchset “dma-mapping: Use
DMA_ATTR_CC_SHARED”(https://lkml.org/lkml/2026/6/4/588). This patch is compatible with yourDMA_ATTR_CC_SHAREDattr work in dma-mapping layer. Once dma ops callbacks getDMA_ATTR_CC_SHAREDattr flag and it may use the flag to replacehyperv_private_memory_dma().Quoted 8 lines
Quoted 3 lines
Looking at functions such as
hyperv_dma_alloc_coherent(), how does this differ fromdma_direct_alloc()?
hyperv_dma_alloc_coherent()is to allocate memory and returns encrypted memory address directly whenhyperv_private_memory_dma()is ture. This change is to keep all changes under Hyper-V subsystem and it's also compatible with existing solution which changes DMA core with minor changes.
Quoted 5 lines
If we update
force_dma_unencrypted(dev)to return false when an encrypted memory address is required, wouldn't the existing DMA-direct support handle this case? Or are there issues with the existing code? If so, could you explain them in more detail?
Hyper-V Coco VM with T-disp scenario is to run a paravior(lightweight L1 hypervisor) with normal guest (Detail please see 13.2. OpenHCL Architecture
https://openvmmdev/guide/user_guide/openhcl.html). The paravisor is in charge of talking with hardware to accept PCI devices for Normal guest.
When PCI device is assigned to normal guest, __device_cc_accepted() should always return true for this device. Then, DMA core will not use bounce buffer and
unencrypted memory address for the device.
However, __device_cc_accepted() is based on TSM framework and Hyper-V doesn't support it. This means normal guest will not use TSM guest driver and so current code doesn't work. It's necessary to introduce an API for platforms without TSM support to mask the PCI device to be "accepted".
Quoted 3 lines
Can we rework this patch to use that(DMA_ATTR_CC_SHARED )?
I think the change is simple. The issue here is how to set the attr flag for platforms without TSM support. This patch is to make Hyper-V T-Disp case work without changing DMA core and PCI layer.
In parallel, we may co-work to add non-TSM platform support in your DMA CC SHARED patchset and "PCI/TSM: Core infrastructure" patchset.
--
Thanks
Tianyu Lan
Quoted 73 lines · Tianyu Lan
Quoted 50 lines · Aneesh Kumar K.V
Quoted 37 lines · Tianyu Lan
Quoted 18 lines · Aneesh Kumar K.V
Quoted 15 lines · Tianyu Lan
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.
Quoted 9 lines
Quoted 4 lines
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.Can we use
__DMA_ATTR_ALLOC_CC_SHAREDinstead of checkinghyperv_private_memory_dma(dev)directly? Also, would it be possible to encapsulate this logic in something likeforce_dma_encrypted(dev)?Hi Aneesh:
Thanks for your review. I go through your patchset “dma-mapping: Use
DMA_ATTR_CC_SHARED”(https://lkml.org/lkml/2026/6/4/588). This patch is compatible with yourDMA_ATTR_CC_SHAREDattr work in dma-mapping layer. Once dma ops callbacks getDMA_ATTR_CC_SHAREDattr flag and it may use the flag to replacehyperv_private_memory_dma().Quoted 8 lines
Quoted 3 lines
Looking at functions such as
hyperv_dma_alloc_coherent(), how does this differ fromdma_direct_alloc()?
hyperv_dma_alloc_coherent()is to allocate memory and returns encrypted memory address directly whenhyperv_private_memory_dma()is ture. This change is to keep all changes under Hyper-V subsystem and it's also compatible with existing solution which changes DMA core with minor changes.Quoted 5 lines
If we update
force_dma_unencrypted(dev)to return false when an encrypted memory address is required, wouldn't the existing DMA-direct support handle this case? Or are there issues with the existing code? If so, could you explain them in more detail?Hyper-V Coco VM with T-disp scenario is to run a paravior(lightweight L1 hypervisor) with normal guest (Detail please see 13.2. OpenHCL Architecture
https://openvmmdev/guide/user_guide/openhcl.html). The paravisor is in charge of talking with hardware to accept PCI devices for Normal guest.When PCI device is assigned to normal guest,
__device_cc_accepted()should always return true for this device. Then, DMA core will not use bounce buffer and
unencrypted memory address for the device.However,
__device_cc_accepted()is based on TSM framework and Hyper-V doesn't support it. This means normal guest will not use TSM guest driver and so current code doesn't work. It's necessary to introduce an API for platforms without TSM support to mask the PCI device to be "accepted".Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Can we rework this patch to use that(DMA_ATTR_CC_SHARED )?
I think the change is simple. The issue here is how to set the attr flag for platforms without TSM support. This patch is to make Hyper-V T-Disp case work without changing DMA core and PCI layer.
I don't see why Hyper-V would need to change any other layer. We're proposing a generic notion of device_cc_accepted() which requires the bus code to decide what it means to "accept" a device - TSM will be PCI's standard way to do that; meanwhile VMbus should be free to call device_cc_accept() for whatever VMbus devices it fancies. That would be this patch done already.
And similarly if you also want to auto-accept PCI devices via some Hyper-V-specific non-TDISP mechanism, I'd expect there to be some way of doing that from the pci-hyperv driver without needing to hack or reimplement common code.
Thanks,
Robin.
Quoted 6 lines
In parallel, we may co-work to add non-TSM platform support in your DMA CC SHARED patchset and "PCI/TSM: Core infrastructure" patchset.
--
Thanks
Tianyu Lan
Quoted 82 lines · Robin Murphy
Quoted 73 lines · Tianyu Lan
Quoted 50 lines · Aneesh Kumar K.V
Quoted 37 lines · Tianyu Lan
Quoted 18 lines · Aneesh Kumar K.V
Quoted 15 lines · Tianyu Lan
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.
Quoted 9 lines
Quoted 4 lines
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.Can we use
__DMA_ATTR_ALLOC_CC_SHAREDinstead of checkinghyperv_private_memory_dma(dev)directly? Also, would it be possible to encapsulate this logic in something likeforce_dma_encrypted(dev)?Hi Aneesh:
Thanks for your review. I go through your patchset “dma-mapping: Use
DMA_ATTR_CC_SHARED”(https://lkml.org/lkml/2026/6/4/588). This patch is compatible with yourDMA_ATTR_CC_SHAREDattr work in dma-mapping layer. Once dma ops callbacks getDMA_ATTR_CC_SHAREDattr flag and it may use the flag to replacehyperv_private_memory_dma().Quoted 8 lines
Quoted 3 lines
Looking at functions such as
hyperv_dma_alloc_coherent(), how does this differ fromdma_direct_alloc()?
hyperv_dma_alloc_coherent()is to allocate memory and returns encrypted memory address directly whenhyperv_private_memory_dma()is ture. This change is to keep all changes under Hyper-V subsystem and it's also compatible with existing solution which changes DMA core with minor changes.Quoted 5 lines
If we update
force_dma_unencrypted(dev)to return false when an encrypted memory address is required, wouldn't the existing DMA-direct support handle this case? Or are there issues with the existing code? If so, could you explain them in more detail?Hyper-V Coco VM with T-disp scenario is to run a paravior(lightweight L1 hypervisor) with normal guest (Detail please see 13.2. OpenHCL Architecture
https://openvmmdev/guide/user_guide/openhcl.html). The paravisor is in charge of talking with hardware to accept PCI devices for Normal guest.When PCI device is assigned to normal guest,
__device_cc_accepted()should always return true for this device. Then, DMA core will not use bounce buffer and
unencrypted memory address for the device.However,
__device_cc_accepted()is based on TSM framework and Hyper-V doesn't support it. This means normal guest will not use TSM guest driver and so current code doesn't work. It's necessary to introduce an API for platforms without TSM support to mask the PCI device to be "accepted".Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Can we rework this patch to use that(DMA_ATTR_CC_SHARED )?
I think the change is simple. The issue here is how to set the attr flag for platforms without TSM support. This patch is to make Hyper-V T-Disp case work without changing DMA core and PCI layer.
Quoted 7 lines
I don't see why Hyper-V would need to change any other layer. We're proposing a generic notion of
device_cc_accepted()which requires the bus code to decide what it means to "accept" a device - TSM will be PCI's standard way to do that; meanwhile VMbus should be free to calldevice_cc_accept()for whatever VMbus devices it fancies. That would be this patch done already.
Hi Robin:
Thanks for your review. For Confidential VMBus device, we may calldevice_cc_accept() in VMBus driver code directly to mark the device "accepted" when it's enumerated..
Quoted 5 lines
And similarly if you also want to auto-accept PCI devices via some Hyper-V-specific non-TDISP mechanism, I'd expect there to be some way of doing that from the pci-hyperv driver without needing to hack or reimplement common code.
For PCI devices with T-Disp, Hyper-V case will be different and the T-Disp code(e.g, TSM) will be in the paravior. So it will not run TSM code in the normal
guest. I think it may work via registering a PCI bus notification event in Hyper-V
PCI driver and mark the device to be "accepted" when get a new device event. I will have a try.
These changes will depend on "DMA CC SHARED" and "PCI/TSM: Core infrastructure" patchset. device_cc_accept() seems to be reworked in the latest TSM patch.
Hyper-V dma ops patch is to keep all changes in Hyper-V subsystem and may combine with "PCI/TSM: Core infrastructure" and "PCI/TSM: Core infrastructure" according to the upstream process. The dma ops call also may device->p->tcb/accept field to choose bounce buffer or encrypt memory. --
Thanks
Tianyu Lan
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Tianyu,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v7.2-rc7 next-20260814]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Tianyu-Lan/x86-VMBus-DMA-transfer-with-encrypted-memory-in-Coco-VM/20260814-182223 base: linus/master patch link: https://lore.kernel.org/r/20260803033520.12930-1-tiala%40microsoft.com patch subject: [RFC PATCH 1/1] x86/VMBus: DMA transfer with encrypted memory in Coco VM config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20260817/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260817/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All error/warnings (new ones prefixed by >>, old ones prefixed by <<):
>> drivers/hv/vmbus_drv.c:1471:6: warning: no previous prototype for 'is_vmbus_dev' [-Wmissing-prototypes] 1471 | bool is_vmbus_dev(struct device *dev) | ^~~~~~~~~~~~ -- >> ERROR: modpost: "hyperv_dma_ops" [drivers/hv/hv_vmbus.ko] undefined!
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki