On Wed, Dec 02, 2026 at 02:54:07PM +1100, Alistair Popple wrote:
> So what I'm hearing is that the exporter should be unmapping as a defense
> against bad importers. I can definitely understand why that might be useful,
> especially as some kind of debug thing, but I don't think we should be basing
> the whole API design around the concept we can't trust importer to implement the
> contract correctly. Especially as that defense might not actually exist in a lot
> of cases anyway (eg. IOMMU disabled), in which case you have no choice but to
> trust the importer got things right.
+1
> I also sense there might be a deeper belief that the mapping of a resource
> (ie. the IOVA) is something owned by the resource rather than the user of that
> resource.
Well, this would be wrong. The IOVA is owned by the DMA API, the DMA
API is owned by its bound driver. In the kernel it is *never* owned by
the memory object being mapped by it.
Jason
On Wed, Dec 02, 2026 at 11:41:46AM +1000, Dave Airlie wrote:
> On Wed, 2 Dec 2026 at 11:30, Jason Gunthorpe <jgg(a)ziepe.ca> wrote:
> >
> > On Wed, Dec 02, 2026 at 10:47:28AM +1000, Dave Airlie wrote:
> >
> > > I think this is clearly where the divide is. I'm with Christian here,
> > > the exporter allocate the resource, then it owns the lifetime of the
> > > resource. In order for it to have complete ownership of the lifetime
> > > of the resource it needs the ability to remove the resource from other
> > > users (i.e. importers). If the exporter wasn't to free some pages, it
> > > should have all the information necessary to do so but traversing a
> > > list of places the object has been imported and a method to forcible
> > > unlink it from that side.
> >
> > If you change iommu mappings without telling the driver you will
> > create data corruption as new mappings can fall to places the device
> > is still doing DMA.
> >
> > The driver MUST be involved in any reclaim/move/revoke process and
> > DMABUF already has APIs for that. Managing this lifetime is one of the
> > main things it does.
> >
> > I don't like this notion we can trust one side more than the other, it
> > isn't like the exporter drivers are amazing clean things either. There
> > is a reasonable level of nannying..
>
> This isn't just about trust, it's about lifetime and ownership. If the
> exporter owns the resource, the exporter should have all necessary
> information to invalidate the resource and give it back to the system.
Importers own their DMA mappings and are the only things that should
ever be touching them. That is the way we expect DMA APIU to be used,
it is why Rust has the DMA API wrapped with the bound driver concept.
It is an extremely abnormal lifetime to suggest that some driver
should be operating the DMA API of someone elses device.
I don't agree at all that having exporters operating the DMA API of
importer devices makes any sense from a kernel lifetime perspective.
> > Importers are expected to unmap. I think we have to consider any one
> > that doesn't to be broken. You can't fix broken with more broken
> > things like force DMA unmapping and hoping that there is an iommu,
> > then hoping no corruption happens to crash the system.
>
> But we should allow the exporter to tell the imported to invalidate,
> wait for a response and then have the exporter free it.
We have that already.
> What the importer does in the invalidate is up to it, but the
> exporter controls the resource lifetime and any things bound to
> it.
Once the exporter asks for it to be invalidated it gets to assume
nothing is touching it anymore.
There is no reason for it to operate the DMA API of another driver,
and doing so doesn't give more protections or a better life time
design.
> If the importer fails to invalidate the resource then that is a
> clear problem. But an exporter can at least control all the mappings
> for the resource and tear them down without leaking things.
It really can't. Without an iommu the dma unmap does nothing. If you
unmap while DMA is still running you risk random corruption from
future maps.
Choosing to unmap without synchronizing in the HW is an extreme
dangerous action, and IMHO, accepting this buggy choice should be in
side the driver that is doing it, not hidden in layers of software.
> > I just saw someone in drivers/media do the most insane thing with the
> > new DMA API, unbelievable. No matter what we build someone will find a
> > creative way to abuse it.
> >
> > We need to have a 3rd party "Switzerland" if you want to keep this
> > direction that limits the exposure of either side to the details.
>
> If I had rust for this I'd be happier, but we don't get a
> switzerland,
Why not? This thread had several offers of some kind of dmabuf related
mapping library whatever you want to call it.
That's a fine Switzerland.
> but we should at least be speaking in terms of ownership and lifetime
> of resources and what can reasonable be defended against.
IMHO most of the problem here is the push to make unreasonable and
difficult design choices because we have to defend against other
drivers in the kernel. While somehow, against all reason, insisting
that the exporting DRM drivers should be given the most sensitive
access of everything.
> Okay maybe on that one we can give in, I do think path + offset/length
> lists might make sense for things like NVLINK/UALINK though were there
> is more arbitrary path to the resource than just what is CPU
> visible,
I think UALINK type devices you want a VRAM offset relative to the end
point. That gets converted into a fabric address through the fabric
mapping hardware.
> but maybe dma_addr_t can encapsulate that, but for some things it
No. Do not abuse dma_addr_t for things that do not come from the DMA
API, I think this has been said many times over the years. :(
> > Even the P2P permitted placement selection shouldn't be open coded in
> > drivers, this is a bit tricky to do well and none of the DRM drivers
> > get there.
>
> Because nobody has written the code to do it?
Lack of abstractions in dmabuf to help manage all of this, IMHO.
> > FWIW it is a huge pita to make things work like this inside iommufd
> > and if it gets messed up then iommufd will explode in a bad way.
> > It is so much easier to feed through phys_addr_t since we already have
> > this infrastructure.
>
> It's easier, but you don't respect lifetimes then.
Ridiculous. iommufd can be trusted to honor the existing invalidate
callback. Far more than we can trust a random DRM driver to operate
the iommu API correctly.
It is completely lifetime inappropriate for any other drivers to be
reaching into the iommu_domain object entirely and fully controlled by
iommufd. It breaks the encapsulation, complicates the code, and
invites creative abuses from the GPU drivers.
Do not use lifetimes as a justification for this backwards design.
Jason
On Tue, Dec 01, 2026 at 06:06:18PM +1100, Alistair Popple wrote:
> Currently the sg_table is used by dma-buf exporters to describe the
> range of physical addresses to map to the DMA API. This is then passed
> directly back to importers.
>
> This is problematic for a number of reasons. It exposes exporter side
> information to importers and doesn't have the capability to describe
> memory that isn't backed by struct page which is what MMIO such as PCI
> BAR needs.
>
> Add the dma-shared-buf as a library to handle this. A new type to
> replace the exporter's sg_table, struct dma_shared_buf, is added
> to describe a range of physical regions for mapping by the library.
> dma_shared_buf_map() can then be used to map this for a particular
> device.
>
> The mapping function handles either direct P2P mappings using the PCI
> peer-to-peer core if a p2pdma provider is listed, or system memory
> otherwise. This allows dma-buf exporters to use common logic to
> create mappings instead of open-coding it which is hard to get right,
> especially for P2P cases with complex routing and IOMMU requirements.
>
> This is kept in a file of its own as none of it depends on a DMA-buf and
> it could be a library elsewhere.
>
> Signed-off-by: Alistair Popple <apopple(a)nvidia.com>
>
> ---
>
> This is supposed to be used as a library for dma-buf exporters/importers
> so could be moved. I don't love the name so happy for suggestions or
> alternatives.
> ---
> MAINTAINERS | 1 +
> drivers/dma-buf/Makefile | 3 +-
> drivers/dma-buf/dma-shared-buf.c | 138 +++++++++++++++++++++++++++++++++++++++
> include/linux/dma-shared-buf.h | 77 ++++++++++++++++++++++
> 4 files changed, 218 insertions(+), 1 deletion(-)
<...>
> + if (shared_buf->provider) {
> + addrs->attrs |= DMA_ATTR_MMIO;
The patch looks good to me. I have just one nit:
Please move this assignment under PCI_P2PDMA_MAP_THRU_HOST_BRIDGE, since it
does not apply to the PCI_P2PDMA_MAP_BUS_ADDR case.
Thanks
> + switch (pci_p2pdma_map_type(shared_buf->provider, dev)) {
> + case PCI_P2PDMA_MAP_BUS_ADDR:
> + for (i = 0; i < shared_buf->nr_ranges; i++) {
> + const struct phys_vec *vec =
> + &shared_buf->ranges[i];
> +
> + addrs->ranges[i].addr =
> + pci_p2pdma_bus_addr_map(shared_buf->provider,
> + vec->paddr);
> + addrs->ranges[i].len = vec->len;
> + }
> + addrs->bus_addr = true;
> + return addrs;
> + case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE:
> + break;
> + default:
> + ret = -EINVAL;
> + goto err_free;
> + }
> + }
On 12/2/26 12:40, Boris Brezillon wrote:
> On Wed, 2 Dec 2026 09:11:02 +0000
> Tvrtko Ursulin <tursulin(a)ursulin.net> wrote:
>
>> On 02/12/2026 09:00, Boris Brezillon wrote:
>>> All dependencies get added through drm_sched_job_add_dependency() or
>>> variants that call drm_sched_job_add_dependency() internally. At this
>>> point, the job is already attached an entity, and we can do the
>>> same-entity check there, so we don't insert the fence in the XArray in
>>> the first place.
>>>
>>> Note that we keep the elimination logic in
>>> drm_sched_entity_add_dependency_cb() too, because dependencies returned
>>> by ::prepare_job() could also potentially be coming from the same
>>> entity.
>>>
>>> Signed-off-by: Boris Brezillon <boris.brezillon(a)collabora.com>
>>> ---
>>> drivers/gpu/drm/scheduler/sched_entity.c | 8 +-------
>>> drivers/gpu/drm/scheduler/sched_main.c | 5 +++++
>>> include/drm/gpu_scheduler.h | 20 ++++++++++++++++++++
>>> 3 files changed, 26 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
>>> index 03e68b4102d5..39419b3ac552 100644
>>> --- a/drivers/gpu/drm/scheduler/sched_entity.c
>>> +++ b/drivers/gpu/drm/scheduler/sched_entity.c
>>> @@ -473,13 +473,7 @@ static bool drm_sched_entity_add_dependency_cb(struct drm_sched_entity *entity,
>>> struct dma_fence *fence = entity->dependency;
>>> struct drm_sched_fence *s_fence;
>>>
>>> - if (fence->context == entity->fence_context ||
>>> - fence->context == entity->fence_context + 1) {
>>> - /*
>>> - * Fence is a scheduled/finished fence from a job
>>> - * which belongs to the same entity, we can ignore
>>> - * fences from ourself
>>> - */
>>> + if (drm_sched_entity_can_skip_dependency(entity, fence)) {
>>> dma_fence_put(entity->dependency);
>>> return false;
>>> }
>>> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
>>> index 85a49e219837..5f123a5e39ff 100644
>>> --- a/drivers/gpu/drm/scheduler/sched_main.c
>>> +++ b/drivers/gpu/drm/scheduler/sched_main.c
>>> @@ -678,6 +678,11 @@ int drm_sched_job_add_dependency(struct drm_sched_job *job,
>>> if (!fence)
>>> return 0;
>>>
>>> + if (drm_sched_entity_can_skip_dependency(job->entity, fence)) {
>>> + dma_fence_put(fence);
>>> + return 0;
>>
>> I thought we could be braver and unwrap, snipping at the root much more
>> than just the plain fences. As written it is not super exciting, but I
>> am also not saying the two have to come together. It can be considered
>> as a follow up.
IIRC I tried that once and it caused problems.
The background was that you have cases where you need to have a CPU round trip between submissions to the same engine because the run_job() callback needed the information from the previous submission to correctly stitch together the current one.
I then later cleaned that up by introducing the DRM_SCHED_FENCE_DONT_PIPELINE flag, so it should work now but please keep in mind that this might cause regressions.
Regards,
Christian.
>
> Just sent a new version introducing a
> drm_sched_job_add_dependency_unwrapped() helper so drivers don't have
> to do that manually. Sorry for the fast iteration rate BTW, but I
> oscillate between mesa and kernel a lot these days, and every time I
> leave something unfinished on the kernel side it tends to rot and
> eventually fall through cracks, so I thought this time I'd try to push
> this through as fast as possible, especially since there seems to be no
> controversy on the proposed changes. Please let me know if you want me
> to slow things down a bit.
This series tightens the alignment requirements for buffers that are shared
between confidential-computing guests and the host, and adds a common
allocator for host-shared memory.
When a guest runs with private memory, buffers shared with the hypervisor
are not only accessed by the guest. They are also accessed by the host
kernel, and the host may manage the corresponding shared/private state at a
granularity larger than the guest page size.
Architectures such as Arm can detect incorrect accesses to Realm physical
address space PFNs through GPC faults. However, relying on that as the only
line of defence is fragile and can still lead to kernel crashes. The risk
is especially visible for shared buffers that are later mmapped into
userspace, such as guest_memfd or dma-buf backed allocations. Once
userspace can access the mapping, the kernel cannot guarantee that
applications will only touch the intended 4K region rather than the whole
host page mapped into their address space. Those userspace addresses may
also be passed back into the kernel and accessed through the linear map,
resulting in a GPC fault.
To avoid this, host-shared buffers must satisfy two constraints:
- the address must be aligned to the CoCo shared-granule size
- the size must be a multiple of that granule size
The series adds a common CoCo shared-memory layer for enforcing these
constraints. It provides shared-granule geometry and range-validation
helpers, byte-oriented private/shared transition helpers, and
alloc_cc_shared() and its node-aware variant. The allocator accepts a byte
count, rounds internally to the sharing granule and a power-of-two number
of pages, and returns a linear-map address. The entire allocation is shared
and zeroed, with its physical base aligned to the allocation size.
cc_shared_alloc_size() reports the actual size from compound-page metadata.
free_cc_shared() restores the complete allocation to private
state before returning it to the buddy allocator. If private state cannot
be restored safely, the allocation is deliberately leaked rather than
returning potentially shared memory for unrelated use.
The series also makes zeroing part of private-to-shared transitions, with
each architecture clearing memory at the appropriate point. Callers must
therefore initialize shared buffers after the transition; existing contents
are not preserved.
The shared-granule size defaults to PAGE_SIZE and can be overridden by an
architecture. The arm64 CCA changes to discover the host's IPA state change
alignment are not included in this series.
GIC ITS command queues and tables and the dma-buf system_cc_shared heap
use the common allocator. DMA direct, atomic DMA pools and SWIOTLB retain
their allocation paths and use checked byte rounding or transition helpers.
Restricted DMA pools are checked for shared-granule alignment.
Hyper-V users of set_memory_encrypted() and set_memory_decrypted() are not
changed to use cc_make_shared() by this series. Those paths are not
currently used by the arm64 CCA code path, and therefore are not part of
the arm64 CCA IPA state change alignment problem addressed here.
Notes:
* Codex assisted with implementation, review and series organization.
Changes from v10:
https://patch.msgid.link/20261116091137.94252-1-aneesh.kumar@kernel.org
* Replace page/size descriptors with byte-based alloc_cc_shared_node() and
alloc_cc_shared(), returning a linear-map address. Recover the full size
from compound metadata in cc_shared_alloc_size() and free_cc_shared().
* Share and zero the entire allocation. Document physical alignment and
low-memory/nonmovable requirements, including without memory encryption.
* Replace layout structures with cc_shared_round_size() for callers that
manage their own backing memory.
* Require a sleepable allocation context regardless of memory encryption.
* Split architecture zeroing changes and caller cleanups into separate
patches. Separate SWIOTLB alignment from transition-helper conversion.
* Add a dedicated MAINTAINERS entry for CoCo memory sharing and
encryption, including the common interfaces and allocator.
Changes from v9:
https://lore.kernel.org/all/20261104164555.3555725-1-aneesh.kumar@kernel.org
* Leak allocations after failed sharing in the common allocator and SWIOTLB.
* Move x86 zeroing from the AMD, TDX and Hyper-V vTOM callbacks to
set_memory_decrypted(), after a successful transition
* Add set_memory_decrypted_nozero() for VGA mappings, which must change
memory attributes without clearing device memory.
* Zero memory even when encryption is inactive in the generic, arm64 and
pSeries implementations of set_memory_decrypted().
* Move pSeries zeroing after sharing. Document why pKVM and s390 must clear
private contents before sharing
* Drop the GIC ITS VPE L1 preallocation patch from this series.
This issue predates the series and will be addressed separately.
* Add mm/cc_shared.c and include/linux/cc_shared.h to the TSM MAINTAINERS
entry.
Changes from v8:
https://lore.kernel.org/all/20260924100529.1398790-1-aneesh.kumar@kernel.org
* Rebase onto the 7.4-rc1
* Move TDX and AMD (including SEV-SNP) zeroing to their finish callbacks
so private-to-shared transitions clear the final shared mapping.
* Clear __GFP_MOVABLE for shared allocations, which cannot be migrated.
* Resolve NUMA_NO_NODE in the common ITS allocation helper to preserve
placement for all ITS callers.
* Stop SWIOTLB allocation retries when the reduced pool would fall below
the shared granule size, avoiding an allocation retry loop.
Changes from v7:
https://lore.kernel.org/all/20260921144847.501151-1-aneesh.kumar@kernel.org
* Add the following new patches:
* "irqchip/gic-v3-its: Preallocate VPE L1 tables"
* "mm: Assert CoCo shared allocations may sleep"
* "mm: Zero memory during shared memory transitions"
* Drop the arm64 RHI and shared granule size patches so that the series can
be rebased on top of upstream to enable Shashiko review.
Changes from v6:
https://lore.kernel.org/all/20260904103452.1197239-1-aneesh.kumar@kernel.org
* Add a common allocator and geometry/transition helpers for CoCo host-shared
memory.
* Convert GIC ITS, dma-direct, atomic DMA pools, and the dma-buf
system_cc_shared heap to the common allocator.
* Limit dma-buf scatterlist entries to the requested buffer size so rounded
backing is not exposed to importers.
Changes from v5:
https://lore.kernel.org/all/20260706060432.1375570-1-aneesh.kumar@kernel.org
* Rebased to latest kernel
* Drop patch arm64: realm: Move Realm memory encryption ops to RSI code
Changes from v4:
https://lore.kernel.org/all/20260427063108.909019-1-aneesh.kumar@kernel.org
* Rename the helpers to use CoCo terminology
(mem_cc_shared_granule_size() / mem_cc_align_to_shared_granule() instead of
mem_decrypt_granule_size() / mem_decrypt_align()).
* Use __DMA_ATTR_ALLOC_CC_SHARED to pass CoCo shared allocation requirements
down to CMA-based allocation helpers.
* Add validation for restricted DMA pools to reject pools that are not aligned
to the shared granule size.
* Add dma-buf system heap handling for cc-shared buffers.
* Split the previous combined DMA/SWIOTLB/ITS change into smaller subsystem
patches covering ITS, DMA direct, SWIOTLB, restricted DMA pools, dma-buf
system heap, and arm64 Realm support.
* Rework arm64 Realm support by moving Realm memory encryption ops into RSI
code and exposing the CCA shared granule size through arm64_mem_crypt_ops.
Changes from v3:
https://lore.kernel.org/all/20260309102625.2315725-1-aneesh.kumar@kernel.org
* Fix build error reported by kernel test robot <lkp(a)intel.com>
Changes from v2:
https://lore.kernel.org/all/20251221160920.297689-1-aneesh.kumar@kernel.org
* Rebase to latest kernel
* Consider swiotlb always decrypted and don't align when allocating from swiotlb.
Changes from v1:
* Rename the helper to mem_encrypt_align
* Improve the commit message
* Handle DMA allocations from contiguous memory
* Handle DMA allocations from the pool
* swiotlb is still considered unencrypted. Support for an encrypted swiotlb pool
is left as TODO and is independent of this series.
Cc: Andrew Morton <akpm(a)linux-foundation.org>
Cc: Catalin Marinas <catalin.marinas(a)arm.com>
Cc: "Christian König" <christian.koenig(a)amd.com>
Cc: Jason Gunthorpe <jgg(a)ziepe.ca>
Cc: Joerg Roedel (AMD) <joro(a)8bytes.org>
Cc: Marc Zyngier <maz(a)kernel.org>
Cc: Marek Szyprowski <m.szyprowski(a)samsung.com>
Cc: Robin Murphy <robin.murphy(a)arm.com>
Cc: Steven Price <steven.price(a)arm.com>
Cc: Sumit Semwal <sumit.semwal(a)linaro.org>
Cc: Suzuki K Poulose <suzuki.poulose(a)arm.com>
Cc: Will Deacon <will(a)kernel.org>
Cc: "T.J. Mercier" <tjmercier(a)google.com>
Cc: Madhavan Srinivasan <maddy(a)linux.ibm.com>
Cc: Heiko Carstens <hca(a)linux.ibm.com>
Cc: Christian Borntraeger <borntraeger(a)linux.ibm.com>
Cc: Sven Schnelle <svens(a)linux.ibm.com>
Cc: Dave Hansen <dave.hansen(a)linux.intel.com>
Cc: Kiryl Shutsemau <kas(a)kernel.org>
Cc: Rick Edgecombe <rick.p.edgecombe(a)intel.com>
Cc: Paolo Bonzini <pbonzini(a)redhat.com>
Cc: Thomas Gleixner <tglx(a)kernel.org>
Cc: Ingo Molnar <mingo(a)redhat.com>
Cc: Borislav Petkov <bp(a)alien8.de>
Cc: Haiyang Zhang <haiyangz(a)microsoft.com>
Cc: Wei Liu <wei.liu(a)kernel.org>
Cc: Dexuan Cui <decui(a)microsoft.com>
Cc: Andy Lutomirski <luto(a)kernel.org>
Cc: Peter Zijlstra <peterz(a)infradead.org>
Cc: Alexander Gordeev <agordeev(a)linux.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer(a)linux.ibm.com>
Cc: Vasily Gorbik <gor(a)linux.ibm.com>
Cc: x86(a)kernel.org
Cc: dri-devel(a)lists.freedesktop.org
Cc: iommu(a)lists.linux.dev
Cc: linaro-mm-sig(a)lists.linaro.org
Cc: linux-arm-kernel(a)lists.infradead.org
Cc: linux-media(a)vger.kernel.org
Cc: linux-mm(a)kvack.org
Cc: kvmarm(a)lists.linux.dev
Cc: patches(a)lists.linux.dev
Aneesh Kumar K.V (Arm) (23):
MAINTAINERS: Add CoCo memory sharing and encryption entry
mm: Add an allocator for CoCo shared memory
x86/mm: Use the non-zeroing decryption helper for VGA mappings
s390/mm: Clear memory before making it shared
powerpc/pseries: Clear memory after making it shared
arm64: Zero memory during private-to-shared transitions
x86/mm: Clear memory after successful decryption transitions
mm: Document zeroing by set_memory_decrypted() and update the fallback
drivers: hv: Remove redundant clearing after decryption
x86/kvmclock: Avoid clearing decrypted clock memory twice
dma-direct: Avoid redundant clearing of shared allocations
mm: Avoid zeroing CoCo shared allocations twice
irqchip/gic-v3-its: Resolve the default NUMA node explicitly
irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory
allocator
dma-contiguous: Derive shared alignment from DMA attributes
dma-pool: Align shared atomic pools to the CoCo sharing granule
dma-direct: Align CoCo shared DMA allocations to the shared granule
size
swiotlb: Align shared IO TLB pools to the shared granule size
swiotlb: Use the common CoCo memory transition helpers
swiotlb: Reject misaligned restricted DMA pools for CoCo guests
dma-buf: system_heap: Limit scatterlist entries to the buffer size
dma-buf: system_heap: Allocate shared buffers using CoCo shared memory
allocator
swiotlb: Make rounded shared pool capacity allocatable
MAINTAINERS | 13 +
arch/arm/mm/dma-mapping.c | 5 +-
arch/arm64/mm/mem_encrypt.c | 8 +-
arch/powerpc/platforms/pseries/svm.c | 13 +-
arch/s390/mm/init.c | 7 +
arch/x86/hyperv/hv_init.c | 1 -
arch/x86/include/asm/set_memory.h | 1 +
arch/x86/include/asm/vga.h | 4 +-
arch/x86/kernel/kvmclock.c | 18 +-
arch/x86/mm/pat/set_memory.c | 19 +-
drivers/dma-buf/heaps/system_heap.c | 125 ++++-----
drivers/firmware/arm_rmm/rsi.c | 9 +
drivers/hv/connection.c | 7 -
drivers/hv/hv.c | 10 +-
drivers/hv/hv_common.c | 2 -
drivers/iommu/dma-iommu.c | 2 +-
drivers/irqchip/irq-gic-v3-its.c | 144 +++++-----
drivers/virt/coco/pkvm-guest/arm-pkvm-guest.c | 11 +
include/linux/cc_shared.h | 25 ++
include/linux/dma-map-ops.h | 9 +-
include/linux/set_memory.h | 8 +-
kernel/dma/contiguous.c | 47 +++-
kernel/dma/direct.c | 78 ++++--
kernel/dma/ops_helpers.c | 2 +-
kernel/dma/pool.c | 29 ++-
kernel/dma/swiotlb.c | 98 ++++---
kernel/kexec_file.c | 3 +-
mm/Makefile | 1 +
mm/cc_shared.c | 245 ++++++++++++++++++
29 files changed, 680 insertions(+), 264 deletions(-)
create mode 100644 include/linux/cc_shared.h
create mode 100644 mm/cc_shared.c
base-commit: 65e4fd942f72a9dba0e4e257290c4fa1aa756854
--
2.43.0
On Wed, Dec 02, 2026 at 10:47:28AM +1000, Dave Airlie wrote:
> I think this is clearly where the divide is. I'm with Christian here,
> the exporter allocate the resource, then it owns the lifetime of the
> resource. In order for it to have complete ownership of the lifetime
> of the resource it needs the ability to remove the resource from other
> users (i.e. importers). If the exporter wasn't to free some pages, it
> should have all the information necessary to do so but traversing a
> list of places the object has been imported and a method to forcible
> unlink it from that side.
If you change iommu mappings without telling the driver you will
create data corruption as new mappings can fall to places the device
is still doing DMA.
The driver MUST be involved in any reclaim/move/revoke process and
DMABUF already has APIs for that. Managing this lifetime is one of the
main things it does.
I don't like this notion we can trust one side more than the other, it
isn't like the exporter drivers are amazing clean things either. There
is a reasonable level of nannying..
Importers are expected to unmap. I think we have to consider any one
that doesn't to be broken. You can't fix broken with more broken
things like force DMA unmapping and hoping that there is an iommu,
then hoping no corruption happens to crash the system.
> This directly conflicts with Jason's idea that I'm not giving
> exporters the importers iommu_domain. I think we have to break this
> deadlock to move forward.
I just saw someone in drivers/media do the most insane thing with the
new DMA API, unbelievable. No matter what we build someone will find a
creative way to abuse it.
We need to have a 3rd party "Switzerland" if you want to keep this
direction that limits the exposure of either side to the details.
> I think I'm still with Christian though. I think you need to export a
> "dma-buf" with a list of supported both platform and device specific
> types that it can be imported into.
This was the entire idea behind the mapping type series, it came out
of Intel asking for support for ualink.
> for dma-buf the import meta-data is the struct device, the output
> meta-data is a mapped sg for that device.
> for PCI P2P, import meta-data might be just the PCI address of the
> importer, snooping, atomic access?, maybe we validate it can be
> reached, but then we return PCI BAR + offset/length lists.
No, the output is always a dma_addr_t, the dma api natively supports
P2P. You have to decorate it in a special flow to make it work.
Also nothing uses PCI BAR + offset/length. If you want to make that
you can in your own "Switzerland" <shrug> but it is an unnatural
interface in practice.
Even the P2P permitted placement selection shouldn't be open coded in
drivers, this is a bit tricky to do well and none of the DRM drivers
get there.
> for iommufd, import meta-data is the iommu_domain, the exporter maps,
> and hands back the correct table of addresses
FWIW it is a huge pita to make things work like this inside iommufd
and if it gets messed up then iommufd will explode in a bad way.
It is so much easier to feed through phys_addr_t since we already have
this infrastructure.
But if that end up being the only thing that we disagree on then fine,
but no giving it directly to any DRM drivers.
Jason
On Sun, 29 Nov 2026 17:25:07 +0200, Edward Srouji wrote:
> Today mlx5 imports every dma-buf as movable. The mkey is sized for the
> worst case, one entry per PAGE_SIZE of the dma-buf, and an invalidation
> zaps the mkey and relies on ODP page faults to map it again. This makes
> dma-buf MRs depend on CONFIG_INFINIBAND_ON_DEMAND_PAGING, and wastes
> translation entries for exporters that never move their memory, such as
> when GPU or device memory is registered for peer-to-peer DMA.
>
> [...]
Applied, thanks!
[1/3] RDMA/uverbs: Permit dma-buf export to work with pinned importers
https://git.kernel.org/rdma/rdma/c/fd94c97b8495c7
[2/3] RDMA/mlx5: Move dma-buf MR init out of ODP-only compilation
https://git.kernel.org/rdma/rdma/c/a460c35a999e00
[3/3] RDMA/mlx5: Try pinned revocable dmabuf import by default
https://git.kernel.org/rdma/rdma/c/bd3cf336bedb1f
Best regards,
--
Leon Romanovsky <leon(a)kernel.org>
On 12/1/26 17:52, Boris Brezillon wrote:
> On Tue, 01 Dec 2026 17:35:28 +0100
> Boris Brezillon <boris.brezillon(a)collabora.com> wrote:
>
>> If a job is passed a dependency that's coming from the same queue the
>> job is targeting, we can get rid of the dependency because of the
>> implicit serialization provided by the queue. This will allow us
>> benefit from the pipelining provided by the ring buffer (no extra
>> MCU <-> CPU round-trip to have the job pushed to the ring buffer).
>>
>> drm_sched_entity_add_dependency_cb() already has this optimization in
>> place, all we need to do is explode the chain/array containers with a
>> dma_fence_unwrap_for_each() when we add job dependencies.
>>
>> Signed-off-by: Boris Brezillon <boris.brezillon(a)collabora.com>
>> Cc: Xianzhong Li <xianzhong.li(a)nxp.com>
>> ---
>> Some recent effort to improve job pipelining [1] showed that the
>> MCU <-> CPU round-trip that lets us signal job fences adds a
>> non-negligible overhead, and this problem seems to be easier and
>> more systematically fixed if it's addressed at the KMD side, so
>> here's a patch doing exactly that.
>>
>> [1]https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/46172
>> ---
>> Changes in v2:
>> - Explode container fences with dma_fence_unwrap_for_each() instead of
>> and rely on drm_sched_entity_add_dependency_cb() elimination instead
>> of open-coding it
>> ---
>> drivers/gpu/drm/panthor/panthor_drv.c | 17 +++++++++++++----
>> 1 file changed, 13 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
>> index dc8d0191aef4..a527ce86a113 100644
>> --- a/drivers/gpu/drm/panthor/panthor_drv.c
>> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
>> @@ -7,6 +7,7 @@
>> #include <asm/arch_timer.h>
>> #endif
>>
>> +#include <linux/dma-fence-unwrap.h>
>> #include <linux/list.h>
>> #include <linux/module.h>
>> #include <linux/of_platform.h>
>> @@ -612,8 +613,9 @@ panthor_submit_ctx_add_sync_deps_to_job(struct panthor_submit_ctx *ctx,
>> int ret = 0;
>>
>> for (u32 i = 0; i < sync_op_count; i++) {
>> + struct dma_fence *fence, *inner_fence;
>> struct panthor_sync_signal *sig_sync;
>> - struct dma_fence *fence;
>> + struct dma_fence_unwrap iter;
>>
>> if (!sync_op_is_wait(&sync_ops[i]))
>> continue;
>> @@ -637,9 +639,16 @@ panthor_submit_ctx_add_sync_deps_to_job(struct panthor_submit_ctx *ctx,
>> return ret;
>> }
>>
>> - ret = drm_sched_job_add_dependency(job, fence);
>> - if (ret)
>> - return ret;
>> + /* Explode containers so that drm_sched_entity_add_dependency_cb() can
>> + * eliminate fences that are coming from the same queue.
>> + */
>> + dma_fence_unwrap_for_each(inner_fence, &iter, fence) {
>> + ret = drm_sched_job_add_dependency(job, inner_fence);
>
> Missing dma_fence_get(inner_fence) here, as reported by Sashiko.
Yeah drm_sched_job_add_dependency() consumed the fence reference.
>
>> + if (ret) {
>> + dma_fence_put(iter.chain);
I had it on my TODO list for a very long time to clean that up.
Just send you the patch which makes dma_fence_unwrap_for_each() drop the reference with a scoped guard.
Apart from the reference count your patch looks reasonable to me.
Regards,
Christian.
>> + return ret;
>> + }
>> + }
>> }
>>
>> return 0;
>>
>> ---
>> base-commit: 28f286b0dfa9610d4ee2447415e964e8bc603056
>> change-id: 20261201-panhtor-dep-skip-9c6a3e2f7cc7
>>
>> Best regards,
>
Dave Hansen <dave.hansen(a)intel.com> writes:
> On 11/16/26 01:11, Aneesh Kumar K.V (Arm) wrote:
>> if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
>> - r = set_memory_decrypted((unsigned long) hvclock_mem,
>> + r = set_memory_decrypted((unsigned long)hvclock_mem,
>> 1UL << order);
>
> NAK on this specific patch.
>
> Good idea, but this needs to be broken out to do fewer things at once.
>
Are you suggesting that this be split into per-architecture patches?
> The vga changes, for instance, are not explained anywhere.
modified arch/x86/include/asm/vga.h
@@ -14,7 +14,7 @@
* On the PC, we can just recalculate addresses and then
* access the videoram directly without any black magic.
* To support memory encryption however, we need to access
- * the videoram as decrypted memory.
+ * the videoram as decrypted memory without clearing its contents.
*/
#define VGA_MAP_MEM(x, s) \
@@ -22,7 +22,7 @@
unsigned long start = (unsigned long)phys_to_virt(x); \
\
if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) \
- set_memory_decrypted(start, (s) >> PAGE_SHIFT); \
+ set_memory_decrypted_nozero(start, (s) >> PAGE_SHIFT); \
\
start; \
})
The VGA change is an API substitution intended to preserve the existing
behavior: set_memory_decrypted_nozero() avoids the newly added memset().
I have not audited the VGA-specific memory encryption handling in detail.
I had intended the updated comment to explain this, but I can also split
the patch and add that explanation.
-aneesh
On 12/1/26 10:33, Alistair Popple wrote:
> On 2026-12-01 at 19:11 +1100, Christian König <christian.koenig(a)amd.com> wrote...
>> On 12/1/26 08:13, Alistair Popple wrote:
>>> On 2026-12-01 at 15:05 +1100, Dave Airlie <airlied(a)gmail.com> wrote...
>>>>> The problem is I can't figure out how to build that low level API.
>>
>> Seconded.
>>
>> I can give you quite a bunch of requirements based on what the high level DMA-buf API and uAPI has on functionality and based on what I have seen on use cases in the wild.
>
> I think a bunch of requirements would be helpful, because they've kind of been
> scattered across threads at this point and I concluded it was kind of impossible
> to build given the constraints.
>
> In particular the one thing that PCIe P2P, IOMMUFD, KVM, etc. all need is the
> physical address. That is the vendor agnostic thing below but providing that has
> been consistently NACKed and I can't see how you can make any low level API work
> without having the physical address.
Yeah good point, let's start with that one. There are multiple problems with using physical addresses.
First of all a physical address is only what the CPU can see, but there are a lot of use cases where you need to access resources the CPU can't reach. For example hidden device memory or even system memory where the CPU intentionally has no address for because of digital rights management reasons etc... Taking a look at all the use cases I have seen I would say that DMA-buf actually contains more non CPU accessible resources than CPU accessible ones.
Then especially for PCI a physical address is only halve the information you need. The importer can also need additional info to stitch together the TLP, like SH, snooping bit, atomic access ops etc....
Then there is the reason that we have seen a tremendous amount of cases where importers abused the physical address and/or struct page pointer which was unfortunately accessible through the SGT. To be honest I can't count the number of CVE entries given to such bugs.
There are some use cases for KVM for example which need physical addresses, but to be honest they look like corner cases.
Ideally even the exporter shouldn't work with physically addresses I think. For example even when you have a PCI P2P API which fills in your mapping it should work with PCI BAR, offset and length and and not a physical address into the BAR.
> I know in the past you've suggested passing all the importer context through to
> the exporter, but that is also a complete non-starter. It lets arbitrary drivers
> implement the mapping wrong and likely get all the life-times, which belong to
> the importer, wrong. So until we can solve that I'm not really seeing much of
> way forward here.
WOW, wait a second. With the exception of the old interface which pins things down the lifetime of the mapping belongs to the exporter and not the importer!
That's one of the reasons why the exporter needs the IOMMU context of the importer for example, otherwise you can't forcefully remove IOMMU mappings without relying on the importer doing that for you.
>> But I can't say either what the low level API needs to look like and one of the major reasons I want DMA-buf separated from that low level API is that it seems like this needs a different field of expertise and responsibilities.
>
> I get it, and I do appreciate the expertise provided here. However if DMA-buf
> is supposed to be some separate mechanism just for passing pointer types between
> exporter/importer with some lifetime and location negotiation rules it shouldn't
> also be seeking to impose constraints on what information those types actually
> contain. That is none of it's business and is up to what the low level API
> needs.
I have to admit that's a pretty good argument, but I would say the restriction is on the exporter, importer and which role is using what and not the low level API itself.
> If the low level API needs importer context and physical addresses to do
> anything useful then so be it.
As long as the low level API is only called by the exporter I have no problem with it taking physical addresses when it is sufficient for the use case.
I just think that we have use cases where the exporter needs to give additional information to the physical address to the IOMMU driver for example.
I need to attend some customer stuff now and will try to answer the rest of the mail later today.
Regards,
Christian.
>>>>>
>>>>> The current low level DMA API can't correctly handle PCIe P2P, or IOMMUFD, or
>>>>> the KVM/confidential compute use-cases (I'm less familiar with those). It can
>>>>> only handle creating a DMA mapping for system memory for a specific importing
>>>>> device.
>>>>>
>>>>> So I assume you are talking about some new API. Following Dave's lead lets call
>>>>> that shared_buf_map(). That would need to take some importing device context
>>>>> so that it could dispatch to the correct mapping code and a list of physical
>>>>> locations the exporter needs mapped.
>>>>>
>>>>> At a high level something like:
>>>>>
>>>>> struct dma_addr_list *shared_buf_map(import_context, location_list);
>>>>>
>>>>> Where the import_context is some importer specific struct opaque to the exporter
>>>>> and the location list is a list of either PCIe MMIO or system RAM physical
>>>>> addresses.
>>>>>
>>>>> Every exporter ->map_dma_buf() should call shared_buf_map() instead of
>>>>> open-coding their own mapping code, as I think we all agree we don't want that
>>>>> open-coded.
>>>>>
>>>>> Placement selection can be dealt with as a separate topic, so setting that
>>>>> aside means passing in the same location list regardless of importing device.
>>>>> shared_buf_map() then has to dispatch to the correct mapping generation code -
>>>>> either DMA API, PCIe peer-to-peer API, IOMMUFD API, KVM API or maybe some other
>>>>> importing device/driver specific API.
>>
>> That sounds totally sane to me, yes.
>
> Ok. The problem is how this shared_buf_map() gets the importer context.
>
> It would be easy enough to make work if an impoter could call eg.
> shared_buf_map(import_type, attachment) or something like that, but I got the
> impression from the middle-layer discussion that that would be undesirable and
> get NACKed because only exporter should call that. So not sure how to actually
> make that work, unless my impression there is wrong.
>
>>>>>
>>>>> I could see how that could be made to work, but it seems more complex than
>>>>> a dma_buf exporter op that returns a list of physical locations and a helper
>>>>> library that importers call to do the mapping into whatever importer specific
>>>>> context is needed. Instead you would have to add importer specific callbacks
>>>>> that the shared_buf_map code could call along with plumbing the importer context
>>>>> through.
>>
>> I've thought about that as well for a while but came to the conclusion that we most likely want some more differentiation here.
>>
>> On the one hand we have the vendor agnostic things like PCI P2P, IOMMU, IOVAs, bus addresses, CPU physical addresses etc... which a vendor agnostic API should be dealing with.
>
> Right - I'd like to tackle the vendor agnostic things, as they provide the most
> value. Vendor specific things have already been hacked up to work in all sorts
> of horrible ways, which is why I want to fix this so I can at least remove some
> of the horrid hacks from our code.
>
>> On the other hand we have vendor specific things like XGMI, GDS/GWS/OA, I2C, I2S, doorbells, <just name the strange thing people stuffed into a DMA-buf> which only specific drivers understand.
>>
>> The problem is now that those things at least partially overlap, for example a doorbell which is ringed by a PCI P2P write.
>
> I'd argue that a doorbell rung by a PCI P2P write isn't any different than any
> other PCI P2P access. The data in these buffers doesn't change the type from a
> buffer sharing perspective, the type of data in these buffers is always up to
> some other layer (eg. userspace), so I don't see the overlap.
>
>>>>
>>>> This is where I got to thinking it might end up, not that we have an
>>>> export function that actually exports anything, but merely advertises
>>>> this provider has an object with this fd and it can export it in these
>>>> ways.
>>>>
>>>> Then on import we'd have to go into the exporter and setup the object
>>>> that gets shared between that specific importer/exporter combination
>>>> and not always have a singular export, but one per import, that I
>>>> suppose could be refcounted per export if lots of importers wanted the
>>>> same thing.
>>
>> Yes that is a requirement of ROCm as well and we have hacked around such things massively with the KFD and all the rat tail of consequences seen by it.
>
> I should introduce you to RM :-)
>
> Thanks.
>
> - Alistair
>
>>> That sounds reasonably complex. Do you have a vague plan, ideally in the form
>>> of data-structures/API definitions, that would help explain what it would look
>>> like?
>>>
>>> For now I have sent a simplified RFC series -
>>> https://lore.kernel.org/dri-devel/20261201-dmabuf_shared_buf_v1_xe_rc5-v1-0… - that drops the placement
>>> bits and implements the rough plan I outlined in
>>> https://lore.kernel.org/dri-devel/awZ_Os1pXelOGaFP@nvdebian.thelocal/ . I'm not
>>> sure it addresses everything, but I'd be interested in getting feedback on what
>>> it gets right and what specifically needs fixing/changing, and how, to satisfy
>>> the design constraints.
>>>
>>> Thanks.
>>>
>>> - Alistair
>>>
>>>> Now maybe we can't call this dma-buf, but I think dma-buf is a subset of this.
>>
>> I would say that DMA-buf is the high level API which allows importers and exporters to exchange the data structures of the low level API.
>>
>> Christian.
>>
>>>>
>>>> Dave.
>>