Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796312208; b=h4VyLyxjGN2spSOJVUb5Cyc9spgQgUAARLu15hOaROyzYXtIPhsJnhxa3wRplkFvMAoi s1nwqaWYLbtpx0q1f6VeTQjkxJkQpUIFxkeN9PJz84mTNQUDvcFq3zK/plHu/GAgr3OH1 Lr/WpR0hho+ypTjfxmvjp2MmA+ENLaOWakaPBicJTbCaJ4InvvLl6F+LZey4Z7KSf9ILe Abfr5olMo5YRZJoUr5wWZyo23u2yteQGG1nCpRAYzIcj7qfFOgtMPCRVHi4d6pUCtYUsq qH5f2scCWqdvQE13k65ugJhlPT5t3/y9Va04/owRVV5nYjN2OGQ1N7bHUrkjsiDeWfQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796312208; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Received:Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:Content-Transfer-Encoding: In-Reply-To; bh=wLVI4hf5FgiHx4bzwLZ+buN63C9tMYWk3cL5reqjcXw=; b=v0tlIB1MNum4vixal4yTOV9EwMsmy/gv79QD4sVpsvmcCxvNLR5SbswIQHGb2v6qpTmQ f3jdZGMail/m3j6isnA5mqTA5XnJNR8IKaKMDXGyWmjxkM7FSn3fxWebtxeVHO+/1I+Dx 4nD+8Z5BICC3OsVhjPmw1pxJvPr7ZpSe21wchIh+c2G3p1FHHhCvoOXs6D1UkxedbXupl nhIovNbGdDy9j18iqL9wAGCDE9M8a/i7s95EGRChk9niaqawtPJuy/2PQ9b+PbsQS1CQq jl/EzH+k8WTfR1f3LccGfYlCV6UOxoDX+VtiJ3RYawE9bNu4Ef7O+PkoPNO1dvDAPuw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass header.d=ziepe.ca header.i=@ziepe.ca header.a=rsa-sha256 header.s=google header.b=CaVHgZz0; arc=none smtp.remote-ip=74.125.82.171 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96A54606A680 for ; Thu, 3 Dec 2026 15:36:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 96A54606A680 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=ziepe.ca header.i=@ziepe.ca header.a=rsa-sha256 header.s=google header.b=CaVHgZz0 Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-3869f03af6aso1291962eec.1 for ; Thu, 03 Dec 2026 07:36:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1796312207; x=1796917007; darn=lists.linux.dev; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=wLVI4hf5FgiHx4bzwLZ+buN63C9tMYWk3cL5reqjcXw=; b=CaVHgZz0Paw16GiAQVG5E293JvorCg7jyXp17KYLDsf/PrfrfMDLZwtLtG+TddDkiG G3DPObA0qKhJFpiGVC5MBJ10F2OykLTztYlJW5vKW74AfYpuzsLH3k3heAuVopzsN15r BClgaxGIK5PXy4kegz25cywNx7Pa1j5Et/Um0+U4RuAAZaA0G3u3srUqlKV6IMXOzH68 pkj1GzntMyE6fuJTLQX4l+rwcyeyH+VRR3mbycpvlTPYCGpaoy59KtQSqVvGk74QR1ep 8TBRkCDJd9OCbYONwKMb1LM03RoxAW9Mx4cZo+NRbMknjWK21AzuTUVxPMDvrM8BPkYZ XBLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796312207; x=1796917007; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=wLVI4hf5FgiHx4bzwLZ+buN63C9tMYWk3cL5reqjcXw=; b=0eE3BoV4rrrehTXrN1Ub16oGrbUO9iScRIIYGONbHqU2ALKKhRC911RKJ7u0YTChI2 NagM6fMR7jszJvDdFDrttsbvLUBy1bHil2JfvyNkAy1MMXmFjKaAu0fFVABTF+Y7qPbp N8yNdpKa68+duiWDYPhFRLRXxWmHF77iAwR5Pfv29WVLjVLoD6ciGtLdQ136qcZVC69r tZ+SIUKtmoH8F1aAATYSabiaxBP5KPh7nOxUS29SkZ5qIu8ydDZMuPYbOuAwXKt5n3B6 vpYwrLNxQxL+oNI5dwuunU8a7OQmP09kxgDQ73u3JvF9cp9R0/46ILGJMoWdq2/XXA++ NK4A== X-Forwarded-Encrypted: i=1; AL+hErH6anl2o2RMJE8ekKXvzo5jAwTXHby712SKfXYWI8/aLwBpAdlOo0ndJt49E+DSQcNFhLCg6cw=@lists.linux.dev X-Gm-Message-State: APuU4Z+oNCR8paKC9WAZB/NkPkwYQUAY4DljQqTlF1XF6e9BeMA5DHdN GGIu0RUWB34ahz9DfajfGAc26HNLIRvPadRotASxJB8mf1gffRs+C9E8AJPhSxg9yoM= X-Gm-Gg: AZFdTZcnaOyfjpxoXGUpT1Va0PPTqMyGJ8paAeigo2RaHOtV4joIm1Djw+1Wx/VVTyO KInBjSryyVxvj7DWoov6cmRSj646ZXD3kGJkVU6/L9zfTTbfAy1x2epmEFU38YCT0sf7dKe8atH cjzFJMeLXeMAdD1AEgKKdyiJ2olsdKocNaVO9ij0KwJYlafjBJ+8QQElJDRyNtl0/vGDKmtM4jd krPmCDwWO1/UUmyJecKN2JQnRMeGKNBDoodFXJq3dFeZEM2VoRUkqAkL+dkwiT2uRdSJSmSWGom cemqvL1rkjFXAEegP7uyhdPePwUyVh7UnwvlV18iaIhrC9INm3xHi3oFHjkc5EDPq9W9imEUFHi aUx086py8rQEeeD6a1CzpHy1tvFuoZLVw986cEQ6DeZA7ai5+FgiC19XXp8x2QnlO5SW0UaBDY+ 0vvTGwXHzQPNo6M54niRXX0i+JdEghXC8EWtnoL5uh8h1uwN/6MOrYJ/gTTua2WOjvLFw5usdtC KDq0U5vck9sC4qiPaEouMD2SV/aIDGLAb8J0euBytGCKEVWMW1nxWxhS+4vTJwbKJ3ma9B8+U9Y Mwk= X-Received: by 2002:a05:7301:4d02:b0:36c:a3ae:936e with SMTP id 5a478bee46e88-38742cf7cfdmr2341854eec.5.1796312206401; Thu, 03 Dec 2026 07:36:46 -0800 (PST) Received: from ziepe.ca ([140.209.225.78]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385677c371esm130328725eec.23.2026.12.03.07.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 07:36:45 -0800 (PST) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1xZ8rU-00000006lIB-2LN9; Thu, 03 Dec 2026 11:36:44 -0400 Date: Thu, 3 Dec 2026 11:36:44 -0400 From: Jason Gunthorpe To: Marek Szyprowski Cc: "Aneesh Kumar K.V (Arm)" , linux-coco@lists.linux.dev, Andrew Morton , Catalin Marinas , Christian =?utf-8?B?S8O2bmln?= , Joerg Roedel , Marc Zyngier , Robin Murphy , Steven Price , Sumit Semwal , Suzuki K Poulose , Will Deacon , "T.J. Mercier" , Madhavan Srinivasan , Heiko Carstens , Christian Borntraeger , Sven Schnelle , Dave Hansen , Kiryl Shutsemau , Rick Edgecombe , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Haiyang Zhang , Wei Liu , Dexuan Cui , Andy Lutomirski , Peter Zijlstra , Alexander Gordeev , Gerald Schaefer , Vasily Gorbik , 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 Message-ID: <20261203153644.GA1074888@ziepe.ca> References: <20261202095446.2029567-1-aneesh.kumar@kernel.org> <20261202095446.2029567-16-aneesh.kumar@kernel.org> X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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