[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZDZqYTSHBNGLq0zI@dhcp22.suse.cz>
Date: Wed, 12 Apr 2023 10:22:57 +0200
From: Michal Hocko <mhocko@...e.com>
To: Jaewon Kim <jaewon31.kim@...sung.com>
Cc: jstultz@...gle.com, tjmercier@...gle.com, sumit.semwal@...aro.org,
daniel.vetter@...ll.ch, akpm@...ux-foundation.org,
hannes@...xchg.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, jaewon31.kim@...il.com
Subject: Re: [PATCH v3] dma-buf/heaps: system_heap: avoid too much allocation
Sorry for being late. I know there was some pre-existing discussion
around that but I didn't have time to participate.
On Mon 10-04-23 16:32:28, Jaewon Kim wrote:
> @@ -350,6 +350,9 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
> struct page *page, *tmp_page;
> int i, ret = -ENOMEM;
>
> + if (len / PAGE_SIZE > totalram_pages())
> + return ERR_PTR(-ENOMEM);
> +
This is an antipattern imho. Check 7661809d493b ("mm: don't allow
oversized kvmalloc() calls") how kvmalloc has dealt with a similar
issue. totalram_pages doesn't really tell you anything about incorrect
users. You might be on a low memory system where the request size is
sane normally, it just doesn't fit into memory on that particular
machine.
> buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
> if (!buffer)
> return ERR_PTR(-ENOMEM);
> --
> 2.17.1
--
Michal Hocko
SUSE Labs
Powered by blists - more mailing lists