From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796309818; b=P4uq+C9K7zjsfdyIkmrPuD4i4G1GYqXNVkCr2e5VgcnXEKOb8cpxdTHehSJF90kr8EJL 4xYfbY12q7HKep5hup9FHUWsamZLNk81ibgHv+eSCmuS4McpCCG6HeMymcSjhQR5hfqo/ fPk8Byzgj5cIvIJhxJ1otDMJ7+UrvI5gLKXpU9cwnu2eK/cL0/7V3fed2Azx8I6gCqY7W WBls+lNFE9nutfBC7DtKrj0a4GLZ+EAdIkat3bTnnuOIOBdMZFYHiF+kzuW4mFcz1qDU5 sg8iVpBIJk8GObRaXR4M+Rk3AbED4a3asvx2r2FnTGc5m1hcnTE5r03zOOl5BtMDHFQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309818; h=Received:DKIM-Signature:X-Mailer:From:To:Cc:Subject:In-Reply-To: References:Date:Message-ID:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=7yKxDOec6lZ5eNsHBmNIccxzl1NLipeyxM3LTtisVjI=; b=OfLgDSdaqqctf/6h5b9KYcIDo/ekuHg2zqMKe5VJkP4/ae68FVmgopmY8a8VpDWKAyY2 5uBL4SruHMiJUPcxq0UaTWpxiITixmdaV7ghgAxV9/SeExZJjdAqdnu0yE70Xep/OhORb bIYBxirPzTHUrZIhgnNzC6FfTqKg3I5VPu/mZOXETXjVucjCCLM36MK2d85s7W0vZU7Ib 7DUHv4I1mygLsSbXLwyFljn4+9Zh0VI14Z8h9KrUW6g4t8Xk0FuBRcLAQSwn/SHys7NP7 jb++2UQeyBf8wwipV3ZZiwqk2EQa/iwuLqBPtP/jMbBahHn5vI0sUrabFrKfi0ACBkg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Tn7ptamf; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D00F3606A338; Thu, 3 Dec 2026 14:56:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Tn7ptamf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 704B91F00896; Thu, 3 Dec 2026 14:56:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796309818; bh=7yKxDOec6lZ5eNsHBmNIccxzl1NLipeyxM3LTtisVjI=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=Tn7ptamfBM9UReVVX8bIbPvmIaiustHrVci4FMFQu9VmgPsB4A/G9lD5/Cs2QvSuV OdsX0RairNwAr8iN6wuWM9Mmve6QqwTdF2xSPt2w4NOowhgpgfoNKeF0S+kCQsyKNI fMspIarpbSXVCrzwfrDhG0xeHeni+ujj8wbzsMkXfWnBXbojAx1A5okX3TJVBgc/iX wDsZFhFZc/unYAI9Nrd28tFl5QxvCMSpz1dD81dn9+kere46uLb+je2WVQhQu0/mkn neI10U/YGP5tPUCgMNdR4nI79q4+29GdLFen/+24iycF65ueTMs9i7ZSRTDlv9u4DH 3nGSpMmcXTLog== X-Mailer: emacs 31.1 (via feedmail 11-beta-1 I) From: Aneesh Kumar K.V To: Marek Szyprowski , linux-coco@lists.linux.dev Cc: Andrew Morton , Catalin Marinas , Christian =?utf-8?Q?K=C3=B6nig?= , Jason Gunthorpe , 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 In-Reply-To: References: <20261202095446.2029567-1-aneesh.kumar@kernel.org> <20261202095446.2029567-16-aneesh.kumar@kernel.org> Date: Thu, 03 Dec 2026 20:26:42 +0530 Message-ID: X-Mailing-List: patches@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-Transfer-Encoding: quoted-printable Marek Szyprowski writes: > 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 valu= es. >> >> The DMA core already records whether an allocation needs shared backing = in >> __DMA_ATTR_ALLOC_CC_SHARED. Pass allocation attributes to the DMA-contig= uous >> 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 eve= ry > 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. > > IMHO it would be much easier to ensure that the caller simply aligns the > requested buffer size=C2=A0to the shared-memory granule size? > We already round the size in paths such as dma_direct_alloc(), using cc_shared_round_size() before passing the rounded size to __dma_direct_alloc_pages() -> dma_alloc_contiguous(). if (mark_mem_decrypt) { if (cc_shared_round_size(size, &shared_size)) return NULL; } /* we always manually zero the memory once we are done */ page =3D __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO, allow_highmem, attrs); But dma_alloc_contiguous() caps the alignment at CONFIG_CMA_ALIGNMENT (also documented in Kconfig). The rounded size alone cannot tell us the required minimum alignment. We pass the DMA attribute so the CMA allocation code can derive that minimum from the shared granule size and check it against CONFIG_CMA_ALIGNMENT. When the shared-memory granule's alignment order exceeds CONFIG_CMA_ALIGNMENT, we need to skip CMA so that the caller can fall back to the page allocator. Rather than passing an explicit alignment value through the call chain, I thought it was clearer to pass the DMA attribute and derive the required alignment where we check the CMA limit. -aneesh