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=1793810979; b=0CqB2W/VgsDaAEKFFRbTvSaXgsoSYhLD4gCFF5R918hG5braSEtNWdHO9w1oHVSd2Q06 XuS0chTQNEnHPaENl5j3ZqlJZvXVznk0pfcrLK3g7PH0L/m249iauekP6u/zX/USm2Gsh TewPfNj0RdNjcs649LgQLENzMZC0ZGv+e6Z/EXh4os/3R5HQRufK9CP34K9NecITrBosu AOpD2Kk0bpgP4KW5uOOajWxOhHwTzcb0c3rqYdv7qwIKhpPJ4vllNsmE2jqt22oRFyniL RaLVJ3CUhTIMtBsjDvy5qBzGjverOwFQ7C+37/XQ75IRSz4gCEY7TTJa6hAIsQXqZcw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793810979; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=wOq7lOU2FcK7bFNXejlGbOi1XU8BMJcPZcRxtw9e4Sw=; b=C3280kqgkofK6M3zvfbHoM454sV7gbfj2guQ+mhp2g9YPqy0OEHfKrny1sVZV0YngexP Oh4YxLvJcgD58ctZPRxPdVr8axIlhimIDgLoaJ0ZFkgITk+ojDbfKZjpoe8MzxTPWExnw KqcGCkMI+N7UVprrvz4lH+SFWOvCZ3HAEqdX7FwD2V3+fZ4Y4D9ORGaWHRtIbsyy8ZNRp C9jir16vtDw29u60/58xw3BtvWo5QPnP62WTLrCpdn0Qq5KV467bmbe5srxyYZ3zS+UHz xlK8epY5jqbM7cUZCpM9tpoe8DyHB90PLfg9mAWH9y2WCk+FaIMwQ0JKbWxuolug5oA== 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="S/AMpaE0"; 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 4600D6082BC7; Wed, 4 Nov 2026 16:49:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=S/AMpaE0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 582901F00A02; Wed, 4 Nov 2026 16:49:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793810979; bh=wOq7lOU2FcK7bFNXejlGbOi1XU8BMJcPZcRxtw9e4Sw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=S/AMpaE00fvvNCHGl97WBk8zSr2Z+LGjVk4URN9z8aKZMRN5JAerN3vmWJlI5rxkx qZqY02ZGMboQuXsqOOKwAeBf0IaIgR4HqZls5fR6h96A4T5Ch52OXvcemUeAl9V7de zzcvqatJ0Qtz/NAghg0z9oZ5n4WFpDnlVmvGXKlDvLzPJruBt6w0goOl3/TJMAcSmK n/QFxR4RJoYREDyKOE7PRo0pd1NFdYcJaT03hhcFDyDzeTdAJqBeZQ3EjiybtejP23 TW855K1qXgLsFcjIRFrt3vNSNC/8OB+imIeXz6VNmRT/mZg9x7E8shFo83Pk9mJSF1 3h37ZBLS/x1+g== From: "Aneesh Kumar K.V (Arm)" To: linux-coco@lists.linux.dev Cc: "Aneesh Kumar K.V (Arm)" , Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , 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 , Thomas Gleixner , Will Deacon , Russell King , Benjamin Gaignard , Brian Starkey , John Stultz , Mark Rutland , Radu Rendec , "T.J. Mercier" , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Ritesh Harjani , Shrikanth Hegde , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Kiryl Shutsemau , Rick Edgecombe , "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Paolo Bonzini , Vitaly Kuznetsov , Andy Lutomirski , Peter Zijlstra , 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 v9 10/14] dma-buf: system_heap: Limit scatterlist entries to the buffer size Date: Wed, 4 Nov 2026 22:15:51 +0530 Message-ID: <20261104164555.3555725-11-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104164555.3555725-1-aneesh.kumar@kernel.org> References: <20261104164555.3555725-1-aneesh.kumar@kernel.org> X-Mailing-List: linux-coco@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: 8bit 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: Benjamin Gaignard Cc: Brian Starkey Cc: John Stultz 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