From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AAC55606A322 for ; Thu, 3 Dec 2026 15:36:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.a=rsa-sha256 header.s=google header.b=El1rlcXd Received: by kanga.kvack.org (Postfix) id 687DC6B05BD; Thu, 3 Dec 2026 10:36:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E9B56B05BE; Thu, 3 Dec 2026 10:36:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4643E6B05C1; Thu, 3 Dec 2026 10:36:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8B5A46B05BD for ; Thu, 3 Dec 2026 10:36:55 -0500 (EST) Received: from smtpin14.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0516112079A for ; Thu, 3 Dec 2026 15:36:49 +0000 (UTC) X-FDA: 85503074580.14.2BD2960 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) by imf17.hostedemail.com (Postfix) with ESMTP id E388840005 for ; Thu, 3 Dec 2026 15:36:47 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=El1rlcXd; dmarc=none; spf=pass (imf17.hostedemail.com: domain of jgg@ziepe.ca designates 74.125.82.172 as permitted sender) smtp.mailfrom=jgg@ziepe.ca ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796312208; b=ATmxeawYH3tnvnakCvhMaK8lCwhD++8R6bRzLHkmRrewOV8vsre8IRjO3r8ncvUCE/wqPt rSpZeUmlqgRGFGFj7WDzmTgC/yt7I1lIuJ3ngSuMIRLonUQ6d/YMx1PevKglq4IZ3ZDLjR 71AZPSZVEoyeXXyfK+sgSPdLHwIVl4k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796312208; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wLVI4hf5FgiHx4bzwLZ+buN63C9tMYWk3cL5reqjcXw=; b=cmAkTNcK6VRVKPZaQgNI6dHjMarbl/AqWA0rXK8maZjTOCvtr6aUiqNaty04S20Tck++Ov t4Jx31lk+9vuTl9Zy5bAiPEh2e4E+xFJ/qpxqlr1B/4arpaCS5E2H8ZaeqMM6nhxpwrVEq 3cFJairS5WLjwNj2FRN5G5G/bpDaFiU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=El1rlcXd; dmarc=none; spf=pass (imf17.hostedemail.com: domain of jgg@ziepe.ca designates 74.125.82.172 as permitted sender) smtp.mailfrom=jgg@ziepe.ca Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-386d1859e1cso964621eec.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=kvack.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=El1rlcXdG+tAHvX4CL3i1yOiLu5AMdHnld0VL0ljG4EQcAF+2HQSTDqaOpAi0QljAi AZaGj84WoSoY5cV8UsbtPMca0AUDljmrcIoDUvy4sE55RuWE0dmf6vQZ834lXcqubxhH t5qr4emJ9TGsheednO5rCvwmT7LOnh/zgpDphdhpW2QA6ROzJI6TiirnIpg5FyjqLgdy jzgcuC/cw6qZojk8WHzjJ4ZDoGgd4M0+OFrzSaWyr+oBgz40F5uKy7v9trhu1XFxDxYU uAnp6IWvxq0u7+j4eLVvcCrX5IKKsSBb7zJGrxTr6DzuZm8/DLj/zTC4ctYorkn5pEjC OPVQ== 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=cIBTjBwJqeGQIsYeXzKq5Ok9mlm3uNhGxiscUiZXTlJQk/E9xjiZN+5CsyMPhxVv1G 6JELU1NBCGYc5urStQHdGFW2RyT/0q5TrTXCgwz/RuNbhK9cLq8kg0w98NLC2XNQQTnk JyCAkB2oNf6htpiFL070JGIxu5n9MtmhdMu1lbfX8xOaNpgnok2W3jcf+WjSGSKwxCVF cUPtCgunH+FgI96Mu4+juLDVUzjetyXdO/mqnkOIZ2Dyk6UxqHAfmCwDEAK7VjhkVX+5 0WmsDuCL00KK1hgbWJ6dyEkmm67jHtVZSncEHI510hPYVur2Ry1hMtAV9wwep0d1L/Yl 5rPw== X-Forwarded-Encrypted: i=1; AL+hErH5AOOxGyBgWFY4aZpeDsVFT4+SInsnq/rFNlfJLPtMWn9Wjfegh8zrOksM/lylRUqSPeidhI8X5g==@kvack.org X-Gm-Message-State: APuU4Z/BIYVKmzb5fMHEsyN5LL7BNZwE8NQxdN3Z7JUTcyK/v+F5549n BMkkSFNhNkxNQfw8CylpECJMvyNOKurHJ50ZJP3eYZMhEr4dZHHBH97k/AXi35blPhpYG3nZt/N cinML X-Gm-Gg: AZFdTZfEzRcRZRSP0syPivz19AMSY4Dzr3S5FlWhz4yTXit+N5SjIx+H++9A2hx7K1g xLR9rJRCLuNj7Ry4XQWPKu4WOv0nTCSS2fIgbVq33y2PfDCnVWqW5F4NgStfXhhVJik/fILLT+k U7+makSIcu/KmtpEhu9OdJzbyplbPoWEdGRrW774Rcv8vYKsEuxtNhIQULMF746/g9lLqIkKcCt bXuRxknKsSrF0/3Y89qrzy216qaDlj8mzp/BoXzV8pPGh4FdAB3qgUlOqHD/gmSz/bl0vQUCtH1 9GUnnD1RxsaQWGZFRDvE/p/ypgYCRRDZjRZfmc0Tc6M9nWNA5IBNUbP/J+LToC8S9Rt+pNEnZwu rVPQjrt/Ah6hTyCd7UjDIP/txI3zbv1VFfeivpDPnGtIQZLHtf5M3WjewTM6EBAtg3I7UFHBUvu DO/EXuuGLVPGtGKMVBPz8RlHHziuq1kY+oz5o8LI+r2Q2Rze/XCj5jmWHJ4j+HcRxMnOHQNk8rP U0kxE/LLZ7wDvy8UAnKjxCIhP7nDB1x/efMc8qluVIcYKP0wZjwZYNGal68zKfKFz9KmzOwakdR 2TA= 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-Stat-Signature: iqdbcbpuxxwhpr413eusujsm5961z411 X-Rspamd-Queue-Id: E388840005 X-Rspam-User: X-Rspamd-Server: rspam10 X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-HE-Tag: 1796312207-751856 X-HE-Meta: U2FsdGVkX1+C21iynDsB4SsRZ3bqpGoiyG6vgbRldDgTE2Z5CqbohMF/qeC26Igv/TxwIFKtFfpyJlT56zViYhn0dXaiZ5JykRpIe9kWrLLJfoENAQSIcGGa4KgWIcUdQDyCRCbesw3AVVVYAUxzt05xSNFm9zX7fBe8Y2FlK7phSNiezXOz7kf4yJxZiQ07DvUj+mPOlu9xVeImA+pU+fI0E4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rxA/Eev0e8DtPWLLYtavCK/syugfghBm/b8n6F/N7BFDf0Dq/R9bbI6rm3tdBKYnJu+ZDPV4odAAPK8KRtMZ/TpT65uDGo+nTFHSgmWyFFnfvqliaBmdhlN/sJvAqfafNCRLM4obh2TTDql/JVju4fbpInMQ7gIO94dlZdoEn9seyo939OwX40r+gajcn2d6w8tZRBTNg= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: 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