From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9ACD606A330 for ; Thu, 3 Dec 2026 16:22:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=UN61sjtO; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.a=rsa-sha256 header.s=google header.b=pYmBXHc/ DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=wLVI4hf5FgiHx4bzwLZ+buN63C9tMYWk3cL5reqjcXw=; b=UN61sjtO0ilJeLTOH4i3S2fG3X rKn4T42FwHd8AZcoVT3IUvAWBzJGJKhZ1cJcuwNjkoggt52+joV2L/sQ2m6JBcDbdCdRfirb/Jhdq 3+0QmpvRhSBJc4SOm6BLgsqf97hHeRHXenYTGpILrhCyuABM9p3WDXCVIa4JTJ4Sh/8+eijOGZwVo olPN8RxOBv7FFrsSbrQo3PtU1HwVYbeou3cWHtT5E/e1+zsX3Bz/2m7kCrZ1iKKlURNdYLhg6Gcsy 4bv63fYHZ2yGZd4hc+Pn53LegJ9jMBVa5pOeKWTmUDrNsrKEOmip8KbtdSvpgX0o2Ll7RVg22lI7c DrxgX57Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ8ra-0000000FADI-1Tc4; Thu, 03 Dec 2026 15:36:50 +0000 Received: from mail-dy1-x1336.google.com ([2607:f8b0:4864:20::1336]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ8rX-0000000FABb-2eKu for linux-arm-kernel@lists.infradead.org; Thu, 03 Dec 2026 15:36:49 +0000 Received: by mail-dy1-x1336.google.com with SMTP id 5a478bee46e88-386d1859e1cso964623eec.0 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.infradead.org; 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=pYmBXHc/YDS4P8p/cHa7lmyaxys2d0KuFgjap/sXOwXv2GMF7VTKtQ6+9l0thmtY6G OCRSEXFc+swYnV6x5Elaq0zsdlY7j0x2vj47iukHfsHwulTLgQc2mCjc0f+oMMMtulKH DoNNNQk86GcajUC7lIbUhC3uDtLlQaasV3laqkF0/aQK5IOJ+Idj2GJpqcacOKtvdrgk LewuNeXoFa7B3k4DXYfTda0FdIWJkQ7E7QbiylUgF13aFVNqrHi0l/i2PFAxZ3M291Uh r8CCWvmIOf3c3dxRhFcnebRK3xGOo5aN0D6+xnodcP6oDqk2a1lN3rIAylmcL4uyawhG o2cA== 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=wLVI4hf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wu+r2X2k3pbIfUi8GHz d86x5krHNlwpcwEZDaHypcsuSBywiWg8OJ6h+V8qw7ebRixixsg5Gg3wxT2OtyN71CdE/CikgR/ PeS8welqM+IzooJEUFPKbmAtv4wWNpFPFHS5Uxz1+8TNQUH7ZGphFpym4uLF20TEOuHPu3/1qOr Cd8= 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-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261203_073647_728980_59861184 X-CRM114-Status: GOOD ( 21.77 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-5.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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