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 A0CB9606A330 for ; Thu, 3 Dec 2026 14:57:02 +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 kanga.kvack.org (Postfix) id BF6666B05B4; Thu, 3 Dec 2026 09:57:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BCE026B05B8; Thu, 3 Dec 2026 09:57:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE3F16B05B9; Thu, 3 Dec 2026 09:57:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 80A0B6B05B4 for ; Thu, 3 Dec 2026 09:57:01 -0500 (EST) Received: from smtpin08.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 17776406AD for ; Thu, 3 Dec 2026 14:57:01 +0000 (UTC) X-FDA: 85502974242.08.375B7FE Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf23.hostedemail.com (Postfix) with ESMTP id 6099C140004 for ; Thu, 3 Dec 2026 14:56:59 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=Tn7ptamf; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of aneesh.kumar@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=aneesh.kumar@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796309819; b=wHvxVBgaYQrUsbZMrec0BNhcNa3VQelDlSR12To7p6JBYun8bo0DbtzfunuKE8Anm94h+E ZLGNN6UEiDBbeA1dz61JT19Z3SnWLOk4KFBUP/4AtUrxaLTNiySs+R9L5a4DvItOc1S3ST S7aGRe7+4AoC1rxMls+5j/kFfKIicdQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796309819; 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=7yKxDOec6lZ5eNsHBmNIccxzl1NLipeyxM3LTtisVjI=; b=E79Jx4Hc1GDFbBEItKueZKDNG4dJNLK0zQYFysCXKVgBzFHtCRev7dDDYy7VHasEQpFvzy SN+eD6odI+nvow7Ek+T5xtAkkouhGWsJRyK2Tby0FZeOkrGtfeTfNoESTZKdhRpDxPn7da duuGmPVvWSRayDlkNa1W2L9WXRVwIKk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=Tn7ptamf; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of aneesh.kumar@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=aneesh.kumar@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id BD263629DB; Thu, 3 Dec 2026 14:56:58 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Stat-Signature: dtm9xchp84wgcboh7hk9chsy8csp68x7 X-Rspamd-Queue-Id: 6099C140004 X-Rspam-User: X-Rspamd-Server: rspam01 X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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: 1796309819-623750 X-HE-Meta: U2FsdGVkX1+qiXYRRMhiYpsAQk7GgGVVFOhbzfUXXFUYkAMIcZzbc7F+73uzYZ2dPwvqauZTnzUVPgCQSLNaKYUJZ2w0fVgRI2TaqZxZC9Bcz+d6zG+FrOlMxdTrDWWGw/X75cjx02kDcFf5zGPnMIpAWh1Bx7eu/fp+yXfCewS22gVBmt+7g4URJ3UEkQ2g1bD04as839JzcYGvBgjpdXeS92v3W+NBH/ATpgc0l/1gWOF2+cxrNoHwUEio9Dg52S5UX3pDKYER0Im05dnizHbRUimRZK4k/61jvqRi/fBkr3nQoa7ZxnrURtTPLZh8yBrsCPC4B7AB971Q0UzArRqrrgieZBGgbLQpKeCAsWZNABcLHbrk0bclleQB2fxgHxFbWT5x4R25TLmdh6JRjsnO7mVafHbssjyRl5hWvTG24ybdsYX6vguZUekVxlHP7wUckGVxAwcQZO/+WiS7RISNn5gUfmGt6Sk09nSallovCI/vTU2GVhf8lgUMW65RanvC6b/3V/wYKnwYFK5rIw/YphrK6M5nbnG9wszYeWWXEoVs9hwdnX5B3GGFTvoo2Ua6iOxXKJnIxgJSPLpsYXFEGUX4IYxXc9jRYqa1riAMQiK7lNad6W84plv2rO0ypITB28caY/Rs5+UQE04A1px3KYmYW10zeqgemn5oGPpXoBMamXhMvLQL24akN+STvpBCxFM8DiC2x6BJ94XrNe5awx7cH1G2WqNPrreDVSU072/skhXUraPLzYthAfsXFgY9erPUxsOwuao5pjPoSNa5P6Rp/VpDGbWV9EnonUgdiCn8iXi6RU9G+ebcdpVOKML3N3FwCeSavGIVddRdm4UxgjXfjBn2yYG7bzPqmMOkbe1mjr479YQu942xPd+xmpuUM5bemC5n8fJ29GrTPG8L5zkRvUFOBOFSsGcnZ8hPt6L3KnhAIx0tCFcWlQ42homrNEJaZYs6lCoxd6T HG/4UJbX apEJYsVaz2tb/jtRrSl+0Geqc+Kltw8wNYYiyiiNSJmChbb7nb4iEDQ8xxFHVxbMQhl5X007VUjiMIflHHQjZKukY+JimLDWkOE47w1js2neQH9Ir/yQll8s5m4qW32MuEKn2S5CgmUFpwKacHSTcADRILmSD/fdQC2NHuaa9nmSDEEjyrkZPu9xlkMBEma+Ri61Z5GImYEWQ6Bv3s/9NLoVIJl31gn+7gef0w0JZHeLodXC6wYZDMuCwH6fw5STPwwtQGct3TLSN95yUKKffCFiw9nhNmd6ksG1aQ7MI9MtT0SCAxWvQvfpYwUxTYXRhcWFsJIzQ03K/9fxhpup17HRu6oKaRhYVMzdhP7fKTJwcFOSang9H1zVKfD/4KVTFqTo4bmWhqUg6tePOUN0byoWMAjJio3ywHNCvk7gcNbfdueRBXd5Os0RG9ASZmTRR/5erDM6VDgugFSdxppItOGyd+w== 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 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