From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796312208; b=fyvLc2WPkwbdHyUo9jw7t+jMRzEVeL1C+8j17w9yib2IR8/4uh8fu5gP6d+AlqWSBZDW 8Q21gfFU72Ic8FI+/AxJId60/7RY9gJw9bFMwxR9tQVEaegALgwHcHnKWkOsfClMJ0EO1 DAt+vQcSIj/gVZvW4FVWYbDW4PrFFz50pjdNaPQQXH7pPBTYIMUnQksD9Rtjd0QdXrLwE RZrtvVe6qmC43XWjxoYG+QLVFW0bjGGwr1IW9qx62lt7DrYYGlUUGDX8uEaH9uYcrLrEG i2x2NxY3g1EBaWE9CJ6f0uZNDbCbFQL3KqNVU9ue29RYWoaMhK6HDCfNRgkGSetYqLA== 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=N/iY+C2mBIgFDWDgAZWqXQuEiji7jxKTg93Vs0a7/XqOPDa8DGDqYdAScqNJGUDn3ptR GdFP9VuqojkkIdmjSHHvTXC45jlusm7eh9lkcdZkOwncF2/zHgZ8pA9NnzD+zTLHicDLx e7FEprwKiaV+cGwEd9qRAQskY85qqJjVr/DLy6rjwz4nn2ZZ03muAftd5X6Gh9JQaNt8d ZpIIVtBdXOGoU6AmPTjfa2ZfgerP8YrY0rrEhjXR894HJG9NT7/bM7bUp9NkwCax4sfCr dn0FRa/fiXx9ktdvu/qqABUKvfCMLQ30KoNIA3luYhcpHFnvYCvTyuPRugWORN8iDLg== 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.169 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (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 9826F606A682 for ; Thu, 3 Dec 2026 15:36:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9826F606A682 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=CaVHgZz0 Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-386d1859e1cso964627eec.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.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=Zqy3pQc7VORBNOePRX2vsrNnmbXhy8v0DD/CHpX6GrxNIciUeXIUdZbaOX0iush+Lt AHPylhceGHJS8bNLgOw0VfkaGTp0NTaui4zZoFasaZMWUswDzyR+lch5ndGATqqbEU6t 2Dc9/JAXCcKBvuYvD1F0QPgWjrcgkViwg3ctp7PBQrNwjgfVhm73bAnZ8ISu6la+hKao 5Ia2//dEEh+0QK4xo/7/SUZBRc7Bxas8qrxdXdr/3ke5yqFqMLgddjOZgbDR7WWQi06+ fh1YyEz4x2Z9k35np7TPlGx3/ydHOzcd9IxAz2FSd9O7zU127VBX0UP38Ivxiy75bus0 6YpA== X-Forwarded-Encrypted: i=1; AL+hErH6jsP1qblrKUyDK7Di0b1CWln+Tv/b4+Rop2RZJpwp7XP9v+QuWpNf5eU3CMcOZJY976E7ufozMiB4@lists.linux.dev X-Gm-Message-State: APuU4Z8x51PlDmN7IzRW1qMHuk+EEv3/yqoOXqEle7fZdWVc+3wzM17t aIUjVQcoUHKaLoVvrgSDQeRs+VJcjrJWt9ZsDR4qy3hWQfO75/h1wfSrLlc9pLRPjhw= X-Gm-Gg: AZFdTZcGGt6VzMPEhqLOJ7lktXrBmFJJV8Hylj2LonA3IwM/+9/5N1OY7lVlJntDdYx 1vEGNCTgrsEZ42769SGmhq6m0K6xyk27skyHmYryN6ZlNhOPlGTFbMELPEFpHPtRRjVNJPo/cls mCjBuzVljD+WdT7TOCsMcJY0ypaHQ3dib3g85uucPtVpKTc29HGigObjiNMxqTLCkVO1T9dtcG3 57BB8bs2T/C+CIvCGwqTZJonCRWmu0t9M0RcFUaXugQexMB1FS7PmloHFPwvWfe4fXH+9enbFgc gF26UuaEPWRR2kI3eOASjXPJlMdCJhYQgLJgfo3IwDR/CU+mh/00vJikb6C0WLeP0A/le94tjA5 pFVVO1gWnAvPnrtVJ6b3UjR7/mJ7TBUazP6kfUzqve1bqyGdU82BpUdQZ6azl0pYLuCCpuKNUMj 7fvx9/xqslKhl+cC5VCtvi+8r8yfWFUnJfX+Y7QBSg4oys6B9kaP74wVLnjpmk8kMb8y5hQ6Fsj QfdbLAvDeaY2s5JrQhUfsmIXvB/uac80QV4VnJ5Ary20C7HdevI1GAE9n15IIH3gViQKlkscwGC HUE= 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-coco@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