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 E6505606A680 for ; Wed, 2 Dec 2026 10:00:11 +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=kp/7nxL2; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JDIAwJgT 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:References:In-Reply-To:Message-ID:Date: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=k8HH9ZNjz6kStFgt8PML2HQeRAOX/M+rRAvyrDv9+Cg=; b=kp/7nxL2vCEEtc iEraUD7lwxdas2n+7R897pfc/+Fe3ItJZb6l7v3iBmJuzv/DKc2JK0iaxH1N7Erq6F5TB0+RrWBfT VqtVNjQrNELcneLDY4TRFbRDKYw5uTcIQWhF9sek7Xkwh7dr1DQGASkqsz1tLhZIbOZcQrHRvK+CJ LV42Ql+Sk6KTSV1YA9OW+4TFQdp+yaMgyTaV9yWeKNIJDiGlHVlRe/VnvcHUzBGH2xososMcsovL6 9PST1eKpWObamuF7ecT4oKcUfH34MXWnx/umnSHtd1ml+PhUNerzE9WwaMo/Kbyyu8CdFqNoZ3+KB tL03oLU9uhbYAgZnnEug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYh80-0000000AxuB-1vzg; Wed, 02 Dec 2026 09:59:56 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYh7y-0000000Axt8-2btW for linux-arm-kernel@lists.infradead.org; Wed, 02 Dec 2026 09:59:54 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 5FB0F45092; Wed, 2 Dec 2026 09:59:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FA481F00926; Wed, 2 Dec 2026 09:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796205594; bh=k8HH9ZNjz6kStFgt8PML2HQeRAOX/M+rRAvyrDv9+Cg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JDIAwJgTlz89a/wB/Lz+qneKRvLpK5nzvqZCTyrzYBEx2KaUoHXj9ho/8r1G/gGqa CCboNRN7PXXbZT21nzehmBLXdsLu34AnoEjt6edKeBdvB/SeXkdkKGikZ3SVw8Gnbm kddfiCyMytBA+2tLK/i/XUujvopnqt18P+zPns4r/GGs9xk5mXJgSQXjLIDd8gZrA0 izV00qbtgpVUNsyyOFsyG/UXnab9fB7UZFELEUwYz0fI1yR1eQMmUBk4GLPT2VU2UU nDV0zJ3OtDnYl1ZOeE3moSJj4HIhEHWn7kFd1H3DV4pZiDb4GNsuHhSIkAv7xa13qm UpZDpQYUWYzrg== From: "Aneesh Kumar K.V (Arm)" To: linux-coco@lists.linux.dev Cc: "Aneesh Kumar K.V (Arm)" , Andrew Morton , Catalin Marinas , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jason Gunthorpe , Joerg Roedel , Marc Zyngier , Marek Szyprowski , 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: [PATCH v11 21/23] dma-buf: system_heap: Limit scatterlist entries to the buffer size Date: Wed, 2 Dec 2026 15:24:44 +0530 Message-ID: <20261202095446.2029567-22-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261202095446.2029567-1-aneesh.kumar@kernel.org> References: <20261202095446.2029567-1-aneesh.kumar@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 The system heap currently allocates each backing page no larger than the remaining dma-buf length. It can therefore use the complete compound-page size for every scatterlist entry while keeping the total length equal to the buffer size. Shared backing allocations may need to be rounded up to an architecture shared granule size. A backing allocation can then be larger than the remaining buffer length. Describing the complete allocation in the scatterlist would incorrectly expose the rounded tail to scatterlist consumers as part of the dma-buf. Track the remaining buffer length while constructing the scatterlist and limit each entry to the smaller of the compound-page size and the remaining length. The complete backing allocation remains owned by the heap and is still released normally. This does not change behavior with the current allocation policy, but prepares the heap for shared-granule-sized backing allocations. Cc: Sumit Semwal Cc: "T.J. Mercier" Cc: "Christian König" Signed-off-by: Aneesh Kumar K.V (Arm) --- drivers/dma-buf/heaps/system_heap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index c8959eadc71d..b5b8cdf65f23 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -406,6 +406,7 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap, struct system_heap_buffer *buffer; DEFINE_DMA_BUF_EXPORT_INFO(exp_info); unsigned long size_remaining = len; + unsigned long sg_remaining = len; unsigned int max_order = orders[0]; struct system_heap_priv *priv = dma_heap_get_drvdata(heap); bool cc_shared = priv->cc_shared; @@ -454,7 +455,11 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap, sg = table->sgl; list_for_each_entry_safe(page, tmp_page, &pages, lru) { - sg_set_page(sg, page, page_size(page), 0); + unsigned long sg_len; + + sg_len = min_t(unsigned long, page_size(page), sg_remaining); + sg_set_page(sg, page, sg_len, 0); + sg_remaining -= sg_len; sg = sg_next(sg); list_del(&page->lru); } -- 2.43.0