On Fri, Nov 06, 2026 at 09:18:27PM +0800, Tao Cui wrote:
> From: Tao Cui <cuitao(a)kylinos.cn>
>
> IOMMUFD_CMD_HW_QUEUE_ALLOC pins up to max_npages pages just to check
> that a user supplied queue region is physically contiguous, and the
> page array for that check is plain GFP_KERNEL. The size comes from
> cmd->length, a u64 that is only overflow checked, and the array is
> freed again as soon as the contiguity check fails, so the allocation
> can be repeated concurrently: a 1GB region costs about 2MB of
> uncharged memory per attempt.
>
> Every other iommufd allocation that scales with user input is already
> charged, and the pinned pages charge the mapper at map time. Charge
> this array like the rest.
>
> Signed-off-by: Tao Cui <cuitao(a)kylinos.cn>
> ---
> drivers/iommu/iommufd/viommu.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
Reviewed-by: Jason Gunthorpe <jgg(a)nvidia.com>
Jason
On Mon, Nov 16, 2026 at 10:02:56AM -0800, David Matlack wrote:
> > > The way I designed the P2P selftest support requires 2 things:
> > >
> > > (A) initiator: A device that has a VFIO selftests driver.
> > > (B) target: A device that can provide a memory BAR (vfio_pci_find_mem_bar()).
> > >
> > > So far I haven't found a single device that can do both. But you are
> > > right that theoretically a single device could satisfy both
> > > requirements.
> >
> > mlx5 can do both
>
> Looks like GPUs and NVMe can do both as well.
>
> How would we implement vfio_pci_find_mem_bar() for mlx5? BTW for the
> target device, by "a memory BAR" I meant "a region of a memory BAR
> that behaves like normal RAM". Sorry that was not clear.
It's a litlle complicated, you have to allocate a "Device memory" (DM)
from the FW, then you get a chunk of BAR that is like RAM.
There may also be some device boot time configuration that has to be
done to turn it on, I forget.
Jason
On 16/11/2026 10:51, Lorenzo Pieralisi wrote:
> On Mon, Nov 16, 2026 at 11:51:04AM +0530, Aneesh Kumar K.V wrote:
>> Marc Zyngier <maz(a)kernel.org> writes:
>>
>>> On Fri, 06 Nov 2026 15:45:29 +0000,
>>> Aneesh Kumar K.V <aneesh.kumar(a)kernel.org> wrote:
>>>>
>>>> Marc Zyngier <maz(a)kernel.org> writes:
>>>>
>>>>> On Wed, 04 Nov 2026 16:45:55 +0000,
>>>>> "Aneesh Kumar K.V (Arm)" <aneesh.kumar(a)kernel.org> wrote:
>>>>>>
>>>>>> VPE L1 tables are allocated from the CPU-starting callback, where sleeping is
>>>>>> not allowed. Remove the page allocation from this atomic path.
>>>>>>
>>>>>> Use a blocking allocation for the boot CPU and record the resulting table
>>>>>> order. Allocate a page of that order from the sleepable CPU hotplug prepare
>>>>>> stage for each secondary CPU. Consume the preallocated page only when the CPU
>>>>>> cannot inherit an existing redistributor or ITS table.
>>>>>>
>>>>>> Reclaim unused preallocations after the CPU reaches the online state, and from
>>>>>> the prepare-state teardown when CPU bring-up aborts.
>>>>>
>>>>> No. The way to do it is to move the ITS probing out of the
>>>>> non-sleepable CPU hotplug path.
>>>>>
>>>>> I proposed a potential hack at [1] (which I find far more palatable
>>>>> than this proposal), but the real fix is to probe the ITSs as
>>>>> devices.
>>>>>
>>>>
>>>> Could you share a bit more detail on what you have in mind?
>>>>
>>>> Are you suggesting that we create a platform device for each ITS and
>>>> initialize it through the driver's probe callback, while the rest of the
>>>> GIC initialization stays in the existing early boot path?
>>>>
>>>> Would that mean the main GIC is operational during early boot, while
>>>> ITS-dependent features, such as MSI delivery and direct injection, become
>>>> available after the ITS devices probe?
>>>>
>>>> Is that the split you have in mind?
>>>
>>> Yes. Then once this is done, all the tables become normal DMA
>>> allocations, for which there should already be adequate support.
>>>
>>
>> Thanks for confirming. Can we handle the ITS platform-device conversion
>> and the switch to DMA allocations in a separate series?
>>
>> The existing VPE L1 allocation path calls set_memory_decrypted() from
>> the non-sleepable CPU-starting callback, even though
>> set_memory_decrypted() can sleep. This issue predates the shared-granule
>> allocator changes.
>
> If I may ask, why does the existing code ends up calling set_memory_decrypt(),
> or reworded, why does the VPE L1 allocation path goes through the ITS specific
> allocation function rather than using alloc_pages() (as it was before
> b08e2f42e86b5) ?
Because it needs to be accessible to the GIC "hardware". In this case
the GIC is emulated by the hypervisor and the hypervisor for a realm can
only see the unprotected memory.
Now I agree this is a little academic in practise because Linux (as a
hypervisor) will not expose RVPEID - so allocate_vpe_l1_table() will
early out. IIUC this would only actually be relevant in the case of
nested virtualisation within a realm guest - which is a long way off if
it ever happens.
> Why did b08e2f42e86b5 patched allocate_vpe_l1_table() allocation and moved
> it to using its_alloc_pages() ?
In that commit I simply changed all the allocation paths which were
allocating memory to be visible to the GIC to use the new allocator. As
we "know" that the GIC can only access "decrypted" memory. Admittedly
that could easily change in the future - but my expectation is that it
will only change with the switch to GICv5.
Of course what I missed was that this specific allocation uses
GFP_ATOMIC and that set_memory_decrypted() can sleep. This wouldn't have
shown up on any testing because of the early exit:
if (!gic_rdists->has_rvpeid)
return 0;
Thanks,
Steve
> Thanks,
> Lorenzo
>
>>
>> Since fixing this properly needs a broader ITS rework, can we handle
>> that separately and drop the preallocation patch from this series?
>>
>> -aneesh
Fuad Tabba <fuad.tabba(a)linux.dev> writes:
> Hi Aneesh,
>
> On Mon, 16 Nov 2026 at 09:12, Aneesh Kumar K.V (Arm)
> <aneesh.kumar(a)kernel.org> wrote:
> [...]
>> Keep allocations on platforms without memory encryption on the ordinary page
>> allocator path so the original GFP constraints, including __GFP_ZERO, remain
>> intact. Remove post-transition memset() calls that are now redundant and
>> explicitly clear allocations on paths where no transition occurs.
>>
>> This intentionally makes every private-to-shared transition destructive;
>> callers can no longer use set_memory_decrypted() to preserve existing contents.
>
> pKVM shares memory in place, and a guest has to be able to share
> memory it has already set up, as Vincent pointed out [1]. That was one
> of the primary reasons for in-place conversion in guest_memfd.
>
> Cheers,
> /fuad
>
> [1] https://lore.kernel.org/all/avro44jUWOARFzul@google.com/
Thanks for catching this. We discussed it before, but I reached the
opposite conclusion:
https://lore.kernel.org/all/yq5a5wzw2ree.fsf@kernel.org
My mistake. How do you suggest we handle this? We want to avoid zeroing
pages multiple times with different CoCo configurations. For example, to
allocate a zeroed page, we currently do:
alloc_pages(__GFP_ZERO)
set_memory_decrypted()
memset(0, PAGE_SIZE)
Should we do something like
https://lore.kernel.org/all/yq5aa4p82sqt.fsf@kernel.org/
-anees
On Mon, Nov 16, 2026 at 10:09:35AM +0000, Suzuki K Poulose wrote:
> Cc Michael Roth, Alexey, Pankaj Gupta
>
> On 16/11/2026 09:11, Aneesh Kumar K.V (Arm) wrote:
> >
> > 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.
>
> IIUC, AMD SEV-SNP also has a similar requirement for other reasons, to
> align the "shared" allocations within a guest (2MB ?, as mentioned by
> David Kaplan at the LPC).
>
> Michael, Alexey,
>
> Please could you share your thoughts on this series ?
Yes, I think we concluded at LPC that AMD should use this series with
a 2MB setting rather than try to do their HW assisted smash/unsmash
Jason
On 11/16/26 07:27, Alistair Popple wrote:
> On 2026-11-09 at 21:59 +1100, Christian König <christian.koenig(a)amd.com> wrote...
>> On 11/9/26 03:58, Alistair Popple wrote:
>>> On 2026-11-07 at 19:57 +1100, Karl Mehltretter <kmehltretter(a)gmail.com> wrote...
>>>> On Thu, Nov 05, 2026 at 05:40:41PM +0100, Alistair Popple wrote:
>>>>> + * A pin or map that fails after dma_buf_mapping_select() may reopen the
>>>>> + * choice only if it was the one that made it. A selection that predates the
>>>>> + * call belongs to a live pin or mapping and must survive, otherwise the next
>>>>> + * pin or map would reselect under it without an invalidate.
>>>>> + */
>>>>> +void dma_buf_mapping_unselect(struct dma_buf_attachment *attach,
>>>>> + bool was_selected)
>>>>> +{
>>>>> + dma_resv_assert_held(attach->dmabuf->resv);
>>>>> +
>>>>> + if (was_selected)
>>>>> + return;
>>>>> +
>>>>> + attach->selected = false;
>>>>> + attach->selected_idx = 0;
>>>>> +}
>>>>> +
>>>>
>>>> After dma_buf_invalidate_mappings(), attach->selected is false while
>>>> attach->selected_idx still holds that mapping's entry for a pending
>>>> unmap.
>>>>
>>>> If a pin/map fails before that unmap runs, was_selected is false and
>>>> dma_buf_mapping_unselect() resets attach->selected_idx to 0.
>>>>
>>>> A subsequent dma_buf_unmap_sgt() then uses matches[0].
>>>
>>> Actually there's a bigger issue here. The contract at the moment states that
>>> mapping type may change after invalidation. However that doesn't account for the
>>> fact mappings can outlive the invalidation.
>>>
>>> This could be dealt with by switching everything over to the generic
>>> dma_buf_mapping_map/unmap() path, but that requires an allocation per mapping
>>> just to track the mapping type.
>>
>> You need an allocation per mapping anyway to identify the mapping anyway.
>>
>> We currently abuse the sg_table for that, but essentially the idea of having a structure/object to represent the mapping needs to stay around as far as I can see.
>
> Oh right, I see that now.
>
> Do you think it makes sense to convert all exporters to return a mapping type
> specific struct (eg. dma_buf_sgt_mapping) rather than the sgt directly?
No, we essentially want to get away from the whole sgt approach.
The whole purpose of DMA-buf was to exchange DMA addresses between drivers and sgt is problematic for that job because it mixed both the input as well as the output of the DMA mapping operation into one structure.
What we need is the functionality to either say map the buffer at this specific address in that address space (IOMMU domain, internal address space whatever) or just to return DMA addresses plus the information in which address space those addresses are valid.
Regards,
Christian.
> Ie. change map_dma_buf() callbacks to return *dma_buf_sgt_mapping instead of
> *sg_table and convert exporters to allocate that instead of a *sg_table.
>
> I've taken a look at doing that and whilst it touches all the exporters the
> changes are fairly mechanical in nature, with only two or three annoying
> exporters that have slightly different patterns (one of which is buggy).
>
> - Alistair
>
>> Regards,
>> Christian.
>>
>>>
>>> The alternate is we update the contract to say mapping type cannot change until
>>> after all importers have unmapped. Enforcing this would require tracking the
>>> number of live mappings/pins per-attachment, but I think this is the better
>>> solution so will add that for the next version.
>>>
>>>>> int dma_buf_pin(struct dma_buf_attachment *attach)
>>>>> {
>>>>> struct dma_buf *dmabuf = attach->dmabuf;
>>>>> + bool selected = attach->selected;
>>>>> int ret = 0;
>>>>>
>>>>> WARN_ON(!attach->importer_ops);
>>>>>
>>>>> dma_resv_assert_held(dmabuf->resv);
>>>>>
>>>>> - if (dmabuf->ops->pin)
>>>>> + ret = dma_buf_mapping_select(attach);
>>>>> + if (ret)
>>>>> + return ret;
>>>>> +
>>>>> + if (dmabuf->ops->pin) {
>>>>> ret = dmabuf->ops->pin(attach);
>>>>> + if (ret)
>>>>> + dma_buf_mapping_unselect(attach, selected);
>>>>> + }
>>>>
>>>> dma_buf_mapping_select() sets attach->selected = true before ops->pin()
>>>> and the map callbacks run.
>>>>
>>>> In patches 14/15, xe/amdgpu migrate a VRAM buffer to system memory
>>>> during pin and map when the attachment does not accept P2P.
>>>>
>>>> That migration calls dma_buf_invalidate_mappings() and clears
>>>> attach->selected on every attachment, also the one being pinned/mapped.
>>>>
>>>> When the callback succeeds, the attachment stays pinned or mapped with
>>>> attach->selected == false.
>>>>
>>>> A later map/pin on the same attachment can then reselect without an
>>>> invalidation.
>>>
>>> Argh. Thanks. Will fix.
>>>
>>> - Alistair
>>>
>>>> Thanks,
>>>> Karl
>>
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_pages(). The allocator rounds a request to the architecture
shared granule, allocates suitably aligned contiguous pages, transitions
the complete allocation to shared state, and returns the transitioned size
alongside the page.
The corresponding free helper 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 the common layout 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 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: Baoquan He <baoquan.he(a)linux.dev>
Cc: Mike Rapoport <rppt(a)kernel.org>
Cc: Pasha Tatashin <pasha.tatashin(a)soleen.com>
Cc: Pratyush Yadav <pratyush(a)kernel.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: Thomas Gleixner <tglx(a)kernel.org>
Cc: Will Deacon <will(a)kernel.org>
Cc: Russell King <linux(a)armlinux.org.uk>
Cc: Benjamin Gaignard <benjamin.gaignard(a)collabora.com>
Cc: Brian Starkey <Brian.Starkey(a)arm.com>
Cc: John Stultz <jstultz(a)google.com>
Cc: Mark Rutland <mark.rutland(a)arm.com>
Cc: Radu Rendec <radu(a)rendec.net>
Cc: "T.J. Mercier" <tjmercier(a)google.com>
Cc: Madhavan Srinivasan <maddy(a)linux.ibm.com>
Cc: Michael Ellerman <mpe(a)ellerman.id.au>
Cc: Nicholas Piggin <npiggin(a)gmail.com>
Cc: Christophe Leroy (CS GROUP) <chleroy(a)kernel.org>
Cc: Ritesh Harjani (IBM) <ritesh.list(a)gmail.com>
Cc: Shrikanth Hegde <sshegde(a)linux.ibm.com>
Cc: Alexander Gordeev <agordeev(a)linux.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer(a)linux.ibm.com>
Cc: Heiko Carstens <hca(a)linux.ibm.com>
Cc: Vasily Gorbik <gor(a)linux.ibm.com>
Cc: Christian Borntraeger <borntraeger(a)linux.ibm.com>
Cc: Sven Schnelle <svens(a)linux.ibm.com>
Cc: Ingo Molnar <mingo(a)redhat.com>
Cc: Borislav Petkov <bp(a)alien8.de>
Cc: Dave Hansen <dave.hansen(a)linux.intel.com>
Cc: x86(a)kernel.org
Cc: H. Peter Anvin <hpa(a)zytor.com>
Cc: Kiryl Shutsemau <kas(a)kernel.org>
Cc: Rick Edgecombe <rick.p.edgecombe(a)intel.com>
Cc: K. Y. Srinivasan <kys(a)microsoft.com>
Cc: Haiyang Zhang <haiyangz(a)microsoft.com>
Cc: Wei Liu <wei.liu(a)kernel.org>
Cc: Dexuan Cui <decui(a)microsoft.com>
Cc: Long Li <longli(a)microsoft.com>
Cc: Paolo Bonzini <pbonzini(a)redhat.com>
Cc: Vitaly Kuznetsov <vkuznets(a)redhat.com>
Cc: Andy Lutomirski <luto(a)kernel.org>
Cc: Peter Zijlstra <peterz(a)infradead.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) (13):
mm: Add an allocator for CoCo shared memory
mm: Zero memory during shared memory transitions
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: Allocate CoCo atomic pools using CoCo shared memory
allocator
dma-direct: Align CoCo shared DMA allocations to the shared granule
size
swiotlb: Align shared IO TLB pools to the shared granule size
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
mm: Assert CoCo shared allocations may sleep
MAINTAINERS | 2 +
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 | 6 +-
arch/x86/include/asm/set_memory.h | 1 +
arch/x86/include/asm/vga.h | 4 +-
arch/x86/kernel/kvmclock.c | 6 +-
arch/x86/mm/mem_encrypt_amd.c | 1 +
arch/x86/mm/pat/set_memory.c | 19 +-
drivers/dma-buf/heaps/system_heap.c | 128 +++++-----
drivers/firmware/arm_rmm/rsi.c | 9 +
drivers/hv/connection.c | 41 ++-
drivers/hv/hv.c | 11 +-
drivers/hv/hv_common.c | 2 -
drivers/iommu/dma-iommu.c | 2 +-
drivers/irqchip/irq-gic-v3-its.c | 42 ++--
drivers/virt/coco/pkvm-guest/arm-pkvm-guest.c | 4 +
include/linux/cc_shared.h | 39 +++
include/linux/dma-map-ops.h | 9 +-
include/linux/set_memory.h | 8 +-
kernel/dma/contiguous.c | 41 ++-
kernel/dma/direct.c | 73 ++++--
kernel/dma/ops_helpers.c | 2 +-
kernel/dma/pool.c | 27 +-
kernel/dma/swiotlb.c | 94 ++++---
kernel/kexec_file.c | 3 +-
mm/Makefile | 1 +
mm/cc_shared.c | 238 ++++++++++++++++++
30 files changed, 635 insertions(+), 211 deletions(-)
create mode 100644 include/linux/cc_shared.h
create mode 100644 mm/cc_shared.c
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
prerequisite-patch-id: 121492d71cc22b2adbfdedd668868c5a449ad764
prerequisite-patch-id: ed31fd728f0adba3d60dcd6f3bae8da1a2193bcc
--
2.43.0
Marc Zyngier <maz(a)kernel.org> writes:
> On Fri, 06 Nov 2026 15:45:29 +0000,
> Aneesh Kumar K.V <aneesh.kumar(a)kernel.org> wrote:
>>
>> Marc Zyngier <maz(a)kernel.org> writes:
>>
>> > On Wed, 04 Nov 2026 16:45:55 +0000,
>> > "Aneesh Kumar K.V (Arm)" <aneesh.kumar(a)kernel.org> wrote:
>> >>
>> >> VPE L1 tables are allocated from the CPU-starting callback, where sleeping is
>> >> not allowed. Remove the page allocation from this atomic path.
>> >>
>> >> Use a blocking allocation for the boot CPU and record the resulting table
>> >> order. Allocate a page of that order from the sleepable CPU hotplug prepare
>> >> stage for each secondary CPU. Consume the preallocated page only when the CPU
>> >> cannot inherit an existing redistributor or ITS table.
>> >>
>> >> Reclaim unused preallocations after the CPU reaches the online state, and from
>> >> the prepare-state teardown when CPU bring-up aborts.
>> >
>> > No. The way to do it is to move the ITS probing out of the
>> > non-sleepable CPU hotplug path.
>> >
>> > I proposed a potential hack at [1] (which I find far more palatable
>> > than this proposal), but the real fix is to probe the ITSs as
>> > devices.
>> >
>>
>> Could you share a bit more detail on what you have in mind?
>>
>> Are you suggesting that we create a platform device for each ITS and
>> initialize it through the driver's probe callback, while the rest of the
>> GIC initialization stays in the existing early boot path?
>>
>> Would that mean the main GIC is operational during early boot, while
>> ITS-dependent features, such as MSI delivery and direct injection, become
>> available after the ITS devices probe?
>>
>> Is that the split you have in mind?
>
> Yes. Then once this is done, all the tables become normal DMA
> allocations, for which there should already be adequate support.
>
Thanks for confirming. Can we handle the ITS platform-device conversion
and the switch to DMA allocations in a separate series?
The existing VPE L1 allocation path calls set_memory_decrypted() from
the non-sleepable CPU-starting callback, even though
set_memory_decrypted() can sleep. This issue predates the shared-granule
allocator changes.
Since fixing this properly needs a broader ITS rework, can we handle
that separately and drop the preallocation patch from this series?
-aneesh
On Thu, Nov 12, 2026 at 01:47:03PM -0800, David Matlack wrote:
> On Thu Nov 12, 2026 at 12:35 PM PST, Alex Mastro wrote:
> > Hey David,
> >
> > On Wed, Nov 11, 2026 at 07:24:04PM +0000, David Matlack wrote:
> >
> >> Is requiring userspace to re-issue IOMMU_IOAS_MAP_FILE the expected
> >> uAPI behavior?
Yes. Even if we wanted to the locking is doesn't allow trying to do it
automatically.
> The way I designed the P2P selftest support requires 2 things:
>
> (A) initiator: A device that has a VFIO selftests driver.
> (B) target: A device that can provide a memory BAR (vfio_pci_find_mem_bar()).
>
> So far I haven't found a single device that can do both. But you are
> right that theoretically a single device could satisfy both
> requirements.
mlx5 can do both
Jason
Punch line for Linus from Jason:
"Enhance detecting if the PCI fabric can support a peer to peer path
by evaluating the full bi-directional fabric path over each of the
three traffic type ACS controls. Expand the number of fabric
configurations where the P2P algorithm makes the correct determination
of support to include non-uniform ACS and situations where translated
takes different routes from untranslated."
--------------------------------------------------------------------------
PCI P2PDMA applies Request and Completion Redirect throughout both paths.
This misclassifies asymmetric and nested switches, and reports one answer
for every kind of TLP.
Three ACS controls act on TLP attributes the Requester chooses rather
than on the topology: Translation Blocking and Direct Translated P2P act on
a Request's Address Type, and Completion Redirect skips Completions
carrying Relaxed Ordering.
Evaluate each direction at the path divergence, decide every class from the
one walk, and treat a client with ATS enabled as translating unless its
driver declares per-mapping ATS.
This completes the P2PDMA side; dma-buf and mlx5 follow separately.
Signed-off-by: Leon Romanovsky <leonro(a)nvidia.com>
---
Changes in v13:
- Read the Intel SPT PCH ACS Control dword at its nonstandard offset so
Translation Blocking is honored on host routes, addressing the
Sashiko review of patch 10.
- Distinguished unreadable forwarding controls from missing forwarding
and retained redirect advice when clearing controls restores a direct
route, addressing the Sashiko review of patch 5.
- Updated the directional routing documentation for shared ancestors.
- Reused the ACS isolation-test mock setup
- Link to v12: https://patch.msgid.link/20261103-fix-p2p-acs-v4-0-v12-0-912101f93517@nvidi…
Changes in v12:
- Rebaed to v7.4-rc1
- Link to v11: https://patch.msgid.link/20261013-fix-p2p-acs-v4-0-v11-0-72cf8c96e617@nvidi…
Changes in v11:
- Applied the client ATS policy in pci_p2pdma_distance_many() too, as
local Sashiko pointed out.
- Read the ATS Enable bit once per query, so the class and the ATS policy
always agree.
- Documented that pcim_p2pdma_set_ats_per_mapping() needs a successful
pcim_p2pdma_init().
- The path diagnostics no longer read ACS Control or the bridge bus range,
and they report a failed cache store.
- Added a KUnit case for Direct Translated P2P without a redirect.
- Clarified the Relaxed Ordering and diagnostics commit messages.
- Honored device-specific ACS redirection, such as Zhaoxin Downstream
Ports, in a new first patch with a KUnit case, as local Sashiko
pointed out. Relaxed Ordering Completions are redirected at such a
port too.
- Clarified in the documentation that a quirk also redirects Relaxed
Ordering Completions and that Translation Blocking applies only to
upstream Requests, and labelled the ACS routing debug line with its
class, as local Sashiko pointed out.
- Treated ACS registers that read as all ones as unreadable, and named
ports that a quirk redirects instead of suggesting
pci=disable_acs_redir= for them, as local Sashiko pointed out.
- Ignored ACS quirks of endpoints, which only describe traffic between
their own functions.
- Link to v10: https://patch.msgid.link/20261012-fix-p2p-acs-v4-0-v10-0-6ffe7b7a4517@nvidi…
Changes in v10:
- Fixed the Relaxed Ordering description: a Completion carries the
attribute of its Request (PCIe r7.0 sec 2.2.9.1).
- Used the PCIe terms Requester and Completer for TLPs, ACS and ports;
client and provider remain for P2PDMA objects.
- Rebased on pci/p2pdma, which includes the prerequisite P2PDMA fixes.
- Added a topology example to the path divergence patch.
- Removed a repeated sentence from the disable_acs_redir documentation.
- Explained the path divergence in the documentation.
- Link to v9: https://patch.msgid.link/20261001-fix-p2p-acs-v4-0-v9-0-1a8e0f50ddd9@nvidia…
Changes in v9:
- Removed dmabuf patches for now.
- Removed mlx5 per-mapping ATS declaration for now; it comes back with
the dmabuf patches.
- Link to v8: https://patch.msgid.link/20260928-fix-p2p-acs-v4-0-v8-0-404453b9c435@nvidia…
Changes in v8:
- Added extra Reviewed-by from Logan.
- Added patches to take care of ATS per-device vs. per-mapping option
- Link to v7: https://patch.msgid.link/20260920-fix-p2p-acs-v4-0-v7-0-ca0828ab697c@nvidia…
Changes in v7:
- Removed "Document pdev->p2pdma lifetime rules" patch, it gives nothing
after p2pmem fix.
- Split dmabuf patch.
- Tushar retested the series, so added his Tested-by.
- Added Logan's ROB tags and fixed minor documentation issues pointed
by him.
- Link to v6: https://lore.kernel.org/all/20260914-fix-p2p-acs-v4-0-v6-0-5ef07ec9ef06@nvi…
Changes in v6:
- Changed DMABUF to use callbacks and not directly stored pointer.
- Link to v5: https://patch.msgid.link/20260910-fix-p2p-acs-v4-0-v5-0-856087f63c0d@nvidia…
Changes in v5:
- Rebase on the posted fixes.
- Dropped tags from changed patches.
- Remove Egress Control Vector interpretation and coverage.
- Keep enabled Egress Control conservative as a Request redirect.
- Use pci_dbg()/dev_dbg() for diagnostics and drop the "debug" prefix.
- Removed code comments from "Document the pdev->p2pdma lifetime and RCU
rules" patch and reduced description to actual lifetime explanation.
- Added note that Linux assumes that TLPs are in strict-ordering and
untranslated.
- Added code to calculate p2p paths per-TLP type.
- Converted mlx5 to use that new proposed API.
- Link to https://patch.msgid.link/20260821-fix-p2p-acs-v4-0-v4-0-94426b96de73@nvidia…
Changes in v4:
- Reject ACS Violations and unreadable routing state instead of treating
them as host-bridge redirects
- Added Tested-by tags from Tushar Dave
- Added support to asymmetric ACS routing
- Limited redirect checks to the two ports at the path divergence
- Added standalone ACS routing diagnostics for hardware retesting
- Dropped " PCI: Account for Direct Translated P2P in ACS isolation checks" patch
- Link to v3: https://patch.msgid.link/20260811-fix-p2p-acs-v3-0-efc488ee7c03@nvidia.com
Changes in v3:
- Fixed pci_p2pdma_add_resource() error unwinding
- Made pdev->p2pdma teardown wait unconditionally for RCU readers
- Restricted pci_p2pmem_find_many() to pool-backed providers
- Documented the pdev->p2pdma lifetime and RCU rules
- Fixed calc_map_type_and_dist() handling of the verbose argument
- Required the ACS port and target to share a bus before indexing the
Egress Control Vector
- Gave pci_acs_enabled() and pci_acs_path_enabled() a scope, so the ACS
Direct Translated P2P rule no longer stops pci_enable_pasid() from
enabling PASID
- Dropped "Report ACS ports when the paths share no upstream bridge":
the mapping type cannot change without a shared upstream bridge, so
the pci=disable_acs_redir= hint was not actionable there and the ACS
walk only cost config space reads
- Folded the Request Redirect rule into pci_acs_rr_ineffective(), so
pci_acs_flags_enabled() and the Intel SPT PCH quirk share one copy
- Renamed pci_acs_egress_ctrl_set() to pci_acs_egress_ctrl_is_set(), it
reads the bit rather than setting it
- Reworded the blocked-path warning: ACS may also leave the direct route
indeterminate rather than blocked
- Added KUnit coverage for the shared-bus guard, a device with no ACS
capability and an unreadable ACS Control register
- Added the missing Fixes: tags, a second one on the
pci_p2pdma_add_resource() unwinding fix (the dangling devres action
dates to f58ef9d1d135) and one on the Egress Control isolation change
- Link to v2: https://patch.msgid.link/20260806-fix-p2p-acs-v2-0-0cec14812965@nvidia.com
Changes in v2:
- Added Logan's ROB tags
- Added commas in Documentation patch
- Link to v1: https://patch.msgid.link/20260802-fix-p2p-acs-v1-0-a7c5eb64fff6@nvidia.com
---
Leon Romanovsky (19):
PCI/P2PDMA: Honor device-specific ACS redirection
PCI/P2PDMA: Document the TLP attribute assumptions
PCI/P2PDMA: Derive routing from directional ACS controls
PCI: Reject unreadable ACS controls in isolation checks
PCI/P2PDMA: Evaluate ACS controls at the path divergence
PCI/P2PDMA: Document directional ACS routing
PCI/P2PDMA: Collect the path's ACS controls before deciding
PCI/P2PDMA: Answer routing per TLP class
PCI/P2PDMA: Route Relaxed Ordering Completions directly
PCI/P2PDMA: Reject Translated Requests blocked by Translation Blocking
PCI/P2PDMA: Route Translated Requests under Direct Translated P2P
PCI/P2PDMA: Log detailed ACS routing diagnostics
PCI/P2PDMA: Add KUnit tests for the ACS routing decisions
PCI/P2PDMA: Test the ACS P2P routing walk
PCI: Add KUnit coverage for ACS isolation checks
PCI/P2PDMA: Document TLP-class routing
PCI/P2PDMA: Let a client declare that it selects ATS per mapping
PCI/P2PDMA: Evaluate the ATS path for clients with ATS enabled
PCI/P2PDMA: Test the routing of clients with ATS enabled
Documentation/admin-guide/kernel-parameters.txt | 11 +-
Documentation/driver-api/pci/p2pdma.rst | 106 ++
drivers/pci/Kconfig | 15 +
drivers/pci/Makefile | 1 +
drivers/pci/p2pdma.c | 961 ++++++++++++++--
drivers/pci/pci.c | 8 +-
drivers/pci/pci.h | 63 +
drivers/pci/pci_acs_test.c | 1409 +++++++++++++++++++++++
drivers/pci/quirks.c | 23 +-
include/linux/pci-p2pdma.h | 12 +-
10 files changed, 2517 insertions(+), 92 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20260821-fix-p2p-acs-v4-0-e72455e3a261
Best regards,
--
Leon Romanovsky <leonro(a)nvidia.com>