From: Johannes Weiner <hannes@cmpxchg.org>
To: Guennadi Liakhovetski <lg@denx.de>
Cc: linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Ingo Molnar <mingo@elte.hu>
Subject: Re: [PATCH] bitmap: fix bitmap_find_free_region()
Date: Fri, 19 Dec 2008 23:45:33 +0100 [thread overview]
Message-ID: <20081219224532.GA2581@cmpxchg.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0812191553550.4536@axis700.grange>
On Fri, Dec 19, 2008 at 04:09:42PM +0100, Guennadi Liakhovetski wrote:
> Yes, this is the i.MX31 video capture driver (patch has once been
> submitted, new version in work). The thing is, we reserve and declare a
> fixed size coherent region in the board code at start-up, but then what
> the driver allocates depends on what a user-space application requests -
> what size video frame and how many buffers. And the driver does not check
> how much coherent memory it has available, it relies on
> dma_alloc_coherent() to tell. In fact, the actual i.MX31 camera driver
> knows nothing about this allocation, this all happens automatically in
> soc_camera.c::soc_camera_mmap() ->
> videobuf-dma-contig.c::__videobuf_mmap_mapper().
>
> > I think we should add the check, WARN if it's true and return an
> > appropriate error number. It will be handled gracefully then and we
> > still know which callsite screwed up.
>
> Well, given above you'd get warning each time the user requests too big a
> frame or too many buffers, which is not nice.
Indeed, that's BS then.
The region size information is local to the dma-coherent code. So
either the callsite keeps track of the size itself or, if it can not
as in your case, we should check for the correct size on exactly that
layer of code, as well. Does that sound reasonable?
Why do other driver not need this? I will look further into it. If
it's any use, here is a patch that does the check on the allocation
level.
---
dma-coherent: catch oversized requests to dma_alloc_from_coherent()
Prevent passing an order to bitmap_find_free_region() that is larger
than the actual bitmap can represent.
These requests can come from device drivers that have no idea how big
the dma region is and need to rely on dma_alloc_from_coherent() to
sort it out for them.
Reported-by: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
diff --git a/kernel/dma-coherent.c b/kernel/dma-coherent.c
index f013a0c..56ea73e 100644
--- a/kernel/dma-coherent.c
+++ b/kernel/dma-coherent.c
@@ -112,6 +112,9 @@ int dma_alloc_from_coherent(struct device *dev, ssize_t size,
struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL;
int order = get_order(size);
+ if (unlikely(size > mem->size))
+ return 0;
+
if (mem) {
int page = bitmap_find_free_region(mem->bitmap, mem->size,
order);
next prev parent reply other threads:[~2008-12-19 22:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-19 11:26 [PATCH] bitmap: fix bitmap_find_free_region() Guennadi Liakhovetski
2008-12-19 13:02 ` Johannes Weiner
2008-12-19 13:18 ` Guennadi Liakhovetski
2008-12-19 13:59 ` Pekka Enberg
2008-12-19 14:47 ` Johannes Weiner
2008-12-19 15:09 ` Guennadi Liakhovetski
2008-12-19 22:45 ` Johannes Weiner [this message]
2008-12-19 23:19 ` Guennadi Liakhovetski
2008-12-20 11:34 ` Johannes Weiner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081219224532.GA2581@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=akpm@linux-foundation.org \
--cc=lg@denx.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.