From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86EE2606A322 for ; Thu, 3 Dec 2026 15:29:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Yy6Bg8JW; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Tn7ptamf DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-ID:Date:References:In-Reply-To:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=7yKxDOec6lZ5eNsHBmNIccxzl1NLipeyxM3LTtisVjI=; b=Yy6Bg8JW92+Akx ofO9Kk5c98xNgqNwf5QdvaNEKjsjswsbuxo61fEsieB68qfZRaB99cTLoDbEaWasHpyM/60aVFAq2 ik5W5+cWl+awtjJEZExxZl9V6Lkia+rz0CVTZUQ8sMAVeADbyZ5eboO/oj/k+hYTTQ92VQPulRDUy jplo8MlWpumtFrtyw79xhMC9/rwhydj/i5Fm0fB/dipG4p67hO11JwLDlAFk9BLrCRVulWpWQMt5f J4TA35Y4CYPryuSQ+QLNGGqE6vk+OW6SUT54Bb9sQZDVmVlxYp7OvxtEIUihHmqhUlbyn8U0vyqOF KysWTBdcY9KFohlv3oLg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ8F2-0000000F2Gg-1nfu; Thu, 03 Dec 2026 14:57:00 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ8F1-0000000F2GX-1Yde for linux-arm-kernel@lists.infradead.org; Thu, 03 Dec 2026 14:56:59 +0000 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-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-5.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 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