Re: [PATCH v3 2/7] dma-mapping: Let a device declare that it reaches private memory

From: Jason Gunthorpe

Date: Wed Nov 25 2026 - 13:08:09 EST


> DMA devices in a confidential guest can access only shared memory, or both
> private and shared memory. Some method outside the DMA API will confirm the
> device is able to access private memory through DMA.
>
> Add DEV_FLAG_DMA_CC_PRIVATE and dma_set_cc_private(dev, bool).
>
> The flag must be stable while any DMA mapping exists.

>From the thread with Greg lets frame this to what it does:

Inside a confidential VM the HW controls how the DMA translation
works. This boils down to a single bit, either the vIOMMU is ignored
and only a bit of shared/decrypted address space is reachable or the
vIOMMU is used and all address space is reachable. The state of this
HW control varies per device and is an input to the DMA API, just like
all the other DMA parameters, and defines the rules for how the DMA
API builds dma_addr_t.

Only one bit is needed so add a DEV_FLAG_DMA_CC_PRIVATE. The bit only
has meaning inside a CC VM and is to only be consumed by the DMA API.
It reflects the current HW configuration and is true if the HW permits
access to the full address space via DMA'd it, false keep the current
CC VM behavior of the DMA API unchanged.

Like other DMA API parameters this must not change once the DMA API is
used, basically it should not change while a driver is bound.

However, some SOC embedded devices, like the SMMU, are hardwired to be
able to access all memory. In this case the driver itself will have
some way to confirm if the device has full DMA access and can call
dma_set_cc_private() very early, before using the DMA API, to set it
up. This flow is similar to dma_set_mask_and_coherent().

The next patch teaches the DMA API to use this bit when making
decisions within a CC VM.

A future series will teach TDSIP capable PCIe devices to control this
bit as well using the TSM subsystem.

> Suggested-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
> Acked-by: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
> Signed-off-by: Nicolin Chen <nicolinc@xxxxxxxxxx>

Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx>

--
Jason