Linux Media Controller development
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
	linux-coco@lists.linux.dev,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Joerg Roedel" <joro@8bytes.org>, "Marc Zyngier" <maz@kernel.org>,
	"Robin Murphy" <robin.murphy@arm.com>,
	"Steven Price" <steven.price@arm.com>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	"Suzuki K Poulose" <suzuki.poulose@arm.com>,
	"Will Deacon" <will@kernel.org>,
	"T.J. Mercier" <tjmercier@google.com>,
	"Madhavan Srinivasan" <maddy@linux.ibm.com>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Sven Schnelle" <svens@linux.ibm.com>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"Kiryl Shutsemau" <kas@kernel.org>,
	"Rick Edgecombe" <rick.p.edgecombe@intel.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Haiyang Zhang" <haiyangz@microsoft.com>,
	"Wei Liu" <wei.liu@kernel.org>,
	"Dexuan Cui" <decui@microsoft.com>,
	"Andy Lutomirski" <luto@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Gerald Schaefer" <gerald.schaefer@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	x86@kernel.org, dri-devel@lists.freedesktop.org,
	iommu@lists.linux.dev, linaro-mm-sig@lists.linaro.org,
	linux-arm-kernel@lists.infradead.org,
	linux-media@vger.kernel.org, linux-mm@kvack.org,
	kvmarm@lists.linux.dev, patches@lists.linux.dev
Subject: Re: [PATCH v11 15/23] dma-contiguous: Derive shared alignment from DMA attributes
Date: Thu, 3 Dec 2026 11:36:44 -0400	[thread overview]
Message-ID: <20261203153644.GA1074888@ziepe.ca> (raw)
In-Reply-To: <c70f20e8-ae51-490f-b85a-03dc73acb930@samsung.com>

On Thu, Dec 03, 2026 at 02:13:21PM +0100, Marek Szyprowski wrote:
> On 02.12.2026 10:54, Aneesh Kumar K.V (Arm) wrote:
> > Confidential-computing shared DMA allocations require CMA backing memory
> > to be aligned to the architecture shared-memory granule. Passing explicit
> > alignment orders through the DMA allocation stack exposes this derived
> > constraint to callers and requires separate preferred and mandatory values.
> >
> > The DMA core already records whether an allocation needs shared backing in
> > __DMA_ATTR_ALLOC_CC_SHARED. Pass allocation attributes to the DMA-contiguous
> > entry points and derive the mandatory alignment there before calling CMA.
> > Preserve the existing alignment clamping for ordinary allocations, while
> > rejecting shared allocations whose granule exceeds CONFIG_CMA_ALIGNMENT so
> > callers can fall back to the page allocator.
> 
> Do we really need to pass the information about required alignment to every
> low-level allocator? I think that all low-level allocator obey the common rule
> that the buffer is aligned to the nearest power-of-2 larger/equal to the
> requested size.

The CMA API is a little weird and doesn't do that..

dma_alloc_from_contiguous() is probably the wrong API for the users,
all of them are doing like this:

			page = dma_alloc_from_contiguous(NULL, 1 << order,
							 order,
							 false);

Which effectively makes everything aligned to the size in the first
place. 

I don't really understand why we have both

static inline struct page *dma_alloc_contiguous(struct device *dev, size_t size,
		gfp_t gfp, unsigned long attrs)

And

static inline struct page *dma_alloc_from_contiguous(struct device *dev,
		size_t count, unsigned int order, unsigned long attrs,
		bool no_warn)

Can't the atomic pool just use dma_alloc_contiguous with a size
instead of the other API?

I say this because:

> IMHO it would be much easier to ensure that the caller simply aligns the
> requested buffer size to the shared-memory granule size?

The overal design of this series is to hide the set_memory_decrypted()
inside the allocators.

So, IMHO, it is a mistake that cma_alloc() or related isn't calling
the set_memory_decrypted, and all the remaing calls to
cc_make_shared() look misplaced to me because they are not immediately
linked to a low level allocator.

dma_alloc_contiguous() has attrs in this series, and it can be updated
to call shared versions of both the plain and CMA allocators and just
return already shared memory directly.

This would eliminate the rest of the open coding of cc_make_shared(),
I think.

With another little fix to allow the NULL dev we can just use it in
the atomic pools directly. For example a little helper like this:

static struct page *atomic_pool_alloc_single(struct dma_gen_pool *dma_pool,
					     unsigned int order, gfp_t gfp)
{
	unsigned long attrs = dma_pool->cc_shared ? __DMA_ATTR_ALLOC_CC_SHARED : 0;
	struct page *page;
	void *addr;

	if (cma_in_zone(gfp)) {
		page = dma_alloc_contiguous(NULL, PAGE_SIZE << order, gfp, attrs);
		if (page)
			return page;
	}

	if (dma_pool->cc_shared) {
		addr = alloc_cc_shared(gfp | __GFP_NOWARN, PAGE_SIZE << order);
		return addr ? virt_to_page(addr) : NULL;
	}

	return alloc_pages(gfp | __GFP_NOWARN, order);
}

Shows how it would be organized.

This helper is quite close to what __dma_direct_alloc_pages() does, so
perhaps there is some room for further sharing in this twisty maze of
allocator paths we have :\

Jason

  parent reply	other threads:[~2026-12-03 15:36 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 01/23] MAINTAINERS: Add CoCo memory sharing and encryption entry Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 02/23] mm: Add an allocator for CoCo shared memory Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 03/23] x86/mm: Use the non-zeroing decryption helper for VGA mappings Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 04/23] s390/mm: Clear memory before making it shared Aneesh Kumar K.V (Arm)
2026-12-02  9:57   ` Christian Borntraeger
2026-12-02  9:54 ` [PATCH v11 05/23] powerpc/pseries: Clear memory after " Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 06/23] arm64: Zero memory during private-to-shared transitions Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 07/23] x86/mm: Clear memory after successful decryption transitions Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 08/23] mm: Document zeroing by set_memory_decrypted() and update the fallback Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 09/23] drivers: hv: Remove redundant clearing after decryption Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 10/23] x86/kvmclock: Avoid clearing decrypted clock memory twice Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 11/23] dma-direct: Avoid redundant clearing of shared allocations Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 12/23] mm: Avoid zeroing CoCo shared allocations twice Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 13/23] irqchip/gic-v3-its: Resolve the default NUMA node explicitly Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 14/23] irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory allocator Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 15/23] dma-contiguous: Derive shared alignment from DMA attributes Aneesh Kumar K.V (Arm)
2026-12-03 13:13   ` Marek Szyprowski
2026-12-03 14:56     ` Aneesh Kumar K.V
2026-12-03 15:40       ` Jason Gunthorpe
2026-12-03 15:36     ` Jason Gunthorpe [this message]
2026-12-02  9:54 ` [PATCH v11 16/23] dma-pool: Align shared atomic pools to the CoCo sharing granule Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 17/23] dma-direct: Align CoCo shared DMA allocations to the shared granule size Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 18/23] swiotlb: Align shared IO TLB pools " Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 19/23] swiotlb: Use the common CoCo memory transition helpers Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 20/23] swiotlb: Reject misaligned restricted DMA pools for CoCo guests Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 21/23] dma-buf: system_heap: Limit scatterlist entries to the buffer size Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 22/23] dma-buf: system_heap: Allocate shared buffers using CoCo shared memory allocator Aneesh Kumar K.V (Arm)
2026-12-02  9:54 ` [PATCH v11 23/23] swiotlb: Make rounded shared pool capacity allocatable Aneesh Kumar K.V (Arm)
2026-12-02 15:06 ` [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Dave Hansen
2026-12-03 10:09   ` Aneesh Kumar K.V

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203153644.GA1074888@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=agordeev@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@kernel.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=christian.koenig@amd.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=decui@microsoft.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gerald.schaefer@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=haiyangz@microsoft.com \
    --cc=hca@linux.ibm.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=kas@kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=maddy@linux.ibm.com \
    --cc=maz@kernel.org \
    --cc=mingo@redhat.com \
    --cc=patches@lists.linux.dev \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=robin.murphy@arm.com \
    --cc=steven.price@arm.com \
    --cc=sumit.semwal@linaro.org \
    --cc=suzuki.poulose@arm.com \
    --cc=svens@linux.ibm.com \
    --cc=tglx@kernel.org \
    --cc=tjmercier@google.com \
    --cc=wei.liu@kernel.org \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox