The system dma-buf heap lets userspace allocate buffers from the page
allocator. However, these allocations are not accounted for in memcg,
allowing processes to escape limits that may be configured.
Pass __GFP_ACCOUNT for system heap allocations, based on the
dma_heap.mem_accounting parameter, to use memcg and account for them.
Signed-off-by: Eric Chanudet <echanude@redhat.com>
---
drivers/dma-buf/heaps/system_heap.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index 4c782fe33fd497a74eb5065797259576f9b651b6..4049d042afa14ec2f4d034f59f1740600a20c1e5 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -320,14 +320,17 @@ static struct page *alloc_largest_available(unsigned long size,
{
struct page *page;
int i;
+ gfp_t flags;
for (i = 0; i < NUM_ORDERS; i++) {
if (size < (PAGE_SIZE << orders[i]))
continue;
if (max_order < orders[i])
continue;
-
- page = alloc_pages(order_flags[i], orders[i]);
+ flags = order_flags[i];
+ if (mem_accounting)
+ flags |= __GFP_ACCOUNT;
+ page = alloc_pages(flags, orders[i]);
if (!page)
continue;
return page;
--
2.52.0
On Fri, Jan 16, 2026 at 12:06 PM Eric Chanudet <echanude@redhat.com> wrote: > > The system dma-buf heap lets userspace allocate buffers from the page > allocator. However, these allocations are not accounted for in memcg, > allowing processes to escape limits that may be configured. > > Pass __GFP_ACCOUNT for system heap allocations, based on the > dma_heap.mem_accounting parameter, to use memcg and account for them. > > Signed-off-by: Eric Chanudet <echanude@redhat.com> Reviewed-by: T.J. Mercier <tjmercier@google.com>
Hello Eric, On Sat, 17 Jan 2026 at 04:07, T.J. Mercier <tjmercier@google.com> wrote: > > On Fri, Jan 16, 2026 at 12:06 PM Eric Chanudet <echanude@redhat.com> wrote: > > > > The system dma-buf heap lets userspace allocate buffers from the page > > allocator. However, these allocations are not accounted for in memcg, > > allowing processes to escape limits that may be configured. > > > > Pass __GFP_ACCOUNT for system heap allocations, based on the > > dma_heap.mem_accounting parameter, to use memcg and account for them. > > > > Signed-off-by: Eric Chanudet <echanude@redhat.com> > > Reviewed-by: T.J. Mercier <tjmercier@google.com> Thank you for the series; LGTM, I'll push it tonight to drm-misc-next. Best, Sumit.
© 2016 - 2026 Red Hat, Inc.