From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C20B8C9830C for ; Wed, 23 Sep 2026 13:49:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1E7E110E0E0; Wed, 23 Sep 2026 13:49:15 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=arm.com header.i=@arm.com header.b="mQ/W8ZyC"; dkim-atps=neutral Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by gabe.freedesktop.org (Postfix) with ESMTP id 56E7010E0E0 for ; Wed, 23 Sep 2026 13:49:13 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1F5BE1516; Wed, 23 Sep 2026 06:49:09 -0700 (PDT) Received: from arm.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 115DE3F86F; Wed, 23 Sep 2026 06:49:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1790171352; bh=XZjpz87fWuq0xeTRn18TokdKjnI48O4gDE75aIXRo/8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mQ/W8ZyCxdppzKi6TjFPjx+SnN6nJs1Q0ck64jZseOqja959/n3ZX/3vuBXryqiVy OL6BsCU2pOXRu8nZ7Rw2k3kSXnD9/Eum+CdiLMgaM+zfOhJSn9F4DHjrcdbTXpAfoQ tqz7RvO89PTGnZD7MrNYoOLeOeYFrJCzF3uTP37o= Date: Wed, 23 Sep 2026 14:49:07 +0100 From: Catalin Marinas To: "Aneesh Kumar K.V" Cc: linux-coco@lists.linux.dev, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, Andrew Morton , christian.koenig@amd.com, Jason Gunthorpe , Joerg Roedel , Marc Zyngier , Marek Szyprowski , Robin Murphy , Steven Price , Sumit Semwal , Suzuki K Poulose , Thomas Gleixner , Will Deacon , dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, linux-mm@kvack.org Subject: Re: [RFC PATCH v7 06/13] dma-contiguous: Accept an explicit minimum alignment Message-ID: References: <20260921144847.501151-1-aneesh.kumar@kernel.org> <20260921144847.501151-7-aneesh.kumar@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Wed, Sep 23, 2026 at 05:19:52PM +0530, Aneesh Kumar K.V wrote: > Catalin Marinas writes: > > On Mon, Sep 21, 2026 at 08:18:40PM +0530, Aneesh Kumar K.V (Arm) wrote: > >> @@ -125,7 +126,8 @@ static inline int dma_contiguous_reserve_area(phys_addr_t size, > >> return -ENOSYS; > >> } > >> static inline struct page *dma_alloc_from_contiguous(struct device *dev, > >> - size_t count, unsigned int order, bool no_warn) > >> + size_t count, unsigned int order, unsigned int required_order, > >> + bool no_warn) > >> { > >> return NULL; > >> } > >> @@ -136,7 +138,7 @@ static inline bool dma_release_from_contiguous(struct device *dev, > >> } > >> /* Use fallback alloc() and free() when CONFIG_DMA_CMA=n */ > >> static inline struct page *dma_alloc_contiguous(struct device *dev, size_t size, > >> - gfp_t gfp) > >> + gfp_t gfp, unsigned int align_order) > > > > Can we not just bake the alignment further down in these functions > > rather than getting the callers to pass the {required,align}_order? > > > > But, we need this to be conditional on CoCo shared allocations. We could > derive that from attrs and pass attrs instead of align_order, i.e. > something like: > > > struct page *dma_alloc_from_contiguous(struct device *dev, size_t count, > - unsigned int align, unsigned int required_align, bool no_warn) > + unsigned int align, unsigned long attrs, bool no_warn) > { > - if (required_align > CONFIG_CMA_ALIGNMENT) > + if (!dma_contiguous_resolve_alignment(attrs, &align)) > return NULL; > - align = min(max(align, required_align), CONFIG_CMA_ALIGNMENT); > > return cma_alloc(dev_get_cma_area(dev), count, align, no_warn); > } > > > with > > +static bool dma_contiguous_resolve_alignment(unsigned long attrs, > + unsigned int *align) > +{ > + unsigned int required_align = 0; > + > + if (attrs & __DMA_ATTR_ALLOC_CC_SHARED) > + required_align = get_order(cc_shared_granule_size()); > + if (required_align > CONFIG_CMA_ALIGNMENT) > + return false; > + > + *align = min(max(*align, required_align), CONFIG_CMA_ALIGNMENT); > + return true; > +} Yes, I think this would work. -- Catalin