From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796312208; b=HNpHqovWU7iUzQ/Hu1L6YlNBCNv/PYKbSj/C+xJw7vgeJOzFjqy2KZFVT8n2UHTEaDfX T0uOniRfGy+3FZ8oMdQUg/g+lUKNVhyACJWI+1JWG/USDXIPDrpK1NiIznamOihWkzzL8 EYPHrX1e3JHCH4jLYes4bVqvgE8vdo2rm/ZtyQ4PXoi46XY51Za2JXuo2+Z2/2zBI5vVl KBgkFZRazjyG24CX9zOzeh7i/UFwYOWyfIxCdlpgQIOl6gttCPgMqH7OXnV28fDmMyWJm afoYIb+v91jc7urUJxXzhP21kjvXbnJa/Fxj61Fv+I/4OKbffsE+aWj0TN1mvtoHqVA== 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=LiLXNWzKQrj8+D27M/SZG8Depk0PO+ko4jkHm1cihm991Zq18/sWajUoE1ZYIrTYOYEx QhvkbL/Fesnc/5OGj4OZ+mtecV79KNq/kPXIzYB+6RTAQkcCQ2yjKd7fAcYWGkF/dl2Ze oM7Ly9ZY6DmIWPbc7sktWwkGOJSzjNpUZ/DXRehuD8QPwxfRsn7322t5x3Xxo9TLcrgwW DinVegvCvYyTV/DntqhtoGv24GwP+FGcMURxCZs4onb1rSMb5V16zdaGhNWBUtFoHw0Vz bCwbHNgqWRPyocUr7o26wsVfJGGcI5Xgl+JN17GRMedxrPAmOra9EpGbMkbNSc2nmkA== 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=giKx8p92; arc=none smtp.remote-ip=74.125.82.45 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (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 918A1606A33D for ; Thu, 3 Dec 2026 15:36:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 918A1606A33D 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) header.d=ziepe.ca header.i=@ziepe.ca header.a=rsa-sha256 header.s=google header.b=giKx8p92 Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-1b5cd9b3131so223979c88.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=vger.kernel.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=giKx8p926tXCkAiGy0IPj2Pi5MtSzBv4AdUECpZYCCzo+lsFNPejy9PHN0HC8cooS3 8uMOwrvv4YSqeYYdGx5Qa7ryNI2ahQ5X+1dB5R5xIJjYSn7f00+9aTMfJmHs2N2J3qCI lMP5ljWM3T7PjF2Axe40nU9ZddR1aXVhswk0xOskBDdfmyAsY5fytGL18PhG/UBCnJ0F BD6jc5naPOPQBtOA4nRrXx3tGMtQeXEq9DMUCtqXpWDDL45toVP1r9mCA+elUuzAyqJ3 9TOGC4+vQuPdrRE7nBj/YidboU48XILujbwH5ZmzpojnYMiekFQPsOMIAUVw+kEcLFvR WXRw== 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=pAU/E4yv8FnuuVKycaTo793TCa4Y7ro6RStGYk8jztvfa3rKrEqlc2cpUhplWYQE2t Mdn2kjAPOHkwyfqugC553UGnrbMyvY2omz5+86GbPRWy6AXcJlnQWkcLjPcmGNWY0o5I qRpp4a7LD0lUotv6OdQv/h1JcJsDivqIVlZcVXZU9/YqFp3cn00h9Knq7lTjR8WQ7D+X H/Hzl7iqp5TC75E2v3h5rkPEL1fcrlniARg+aThbWAQus+cGuk0n55dqIYH+ZtO1Pjfc 9jrk1epC0tIlc0G7z6qChvVvX40uJavBOtRCGXPYNGoQM0Dolpp26JHYxgqPJkbuqW3b jWUA== X-Forwarded-Encrypted: i=1; AL+hErE4NNyK2fEpgzFz6AzLIb/LsLGUXeps/jEaKyK0SjjMrYdEUcZ8676KEUhYVT1vG6t89jmZW/8rl0zfeg==@vger.kernel.org X-Gm-Message-State: APuU4Z/9Lf3npYz+7It54IQBueEgJYuu0YKajwdlyctNgtMAQeBMDkHf P1zmMhQjtusxv96llDvNzrOB7mG5jINP6M7Z6tx9t9rdKwZGI8tFVHOFPIfVJwa9BIo= X-Gm-Gg: AZFdTZfpHdYkA4CRARx/Ryznhobq6I2VPMR3o69tH2zJVfOQLWRRuCVfnP19778Cd2e 5koNKkNPJkbgQDPKiL7kT3EGAcj9m5WFwwMMuzpGjzES0N1wQ3JLaIh5VxQJ7aji7dFZGGMZeLy tkKjNeSGf4O0yN9I4eT67VMSH0ExxDGe+1rJnRgiMm9CGRU7hYDJpkzWkH1RNfhrmqq/nAV0dO5 /TDaLxqXxRMX/np1heGMHop2rFUp8b+HY1xyQIOZ8qbxLNbLRZBR0wYZ6vhud78w/H2J01dBkOS L83bGh5s2m3GwyIY4GUZQtWIdU8e+XI940Jys2in+qEDa0dpAZzpJvjTB2WbeRUi+M2YE3/B//i k2sfWrtn5jPGtPGwzyAsKuI/c+ehB8lRA4+QOWUt7EjWf56PcKHHAtWrw/ov/Y5Zay0R/nCYrlA 4euUR9oLCzRM/V40heL02rShwJsT3+rvLErIyHLYYYpg5p666WACOHvInajGOJ5ZhkOZtoUA26o qe4WExiy2lA+wHYLW3VZt3YrLb5EES+mHRT1XVqB7Wfj95mUQjVYyQwiR0Lcr23bJQhodUYfCwi kLU= 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: linux-media@vger.kernel.org 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