vmap() problem, possible bug?

From: Thomas Koeller
Date: Fri May 20 2005 - 08:27:35 EST


Hi,

writing a device driver I came across something that looks
to me like a bug in the vmap() function. I am using kernel
2.6.11-rc1 (from linux-mips.org cvs, but the problem is
probably not mips-specific).

My driver transfers large amounts of data using DMA to a
buffer passed in from userland and translated to a page
list via get_user_pages(). Due to alignment restrictions
imposed by the DMA hardware, I have to use a temporary
buffer page for a part of the data buffer, and to copy
the data from this page to the actual buffer using
memcpy(). To be able to to so, I am using vmap() to create
a temporary mapping for the part of the buffer where the
data is to be copied, do the copy, and then call vunmap()
to remove the mapping:



if (pkt->copy_size) {
const unsigned int page_order =
(pkt->copy_size > PAGE_SIZE) ? 1 : 0;
void * const dst = vmap(pkt->copy_pg, 0x1 << page_order,
VM_MAP, PAGE_USERIO);

if (dst) {
memcpy(dst + pkt->copy_offs, pkt->copy_src,
pkt->copy_size);
free_pages((unsigned long) pkt->copy_src, page_order);
vunmap(dst);
} else {
pkt->pset->status = XICAP_BUFSTAT_VMERR;
}
}



The code above is executed once for every data buffer
processed. It works as expected most of the time, but
every once in a while the data copied is not written to
the correct location, but to the previously processed
buffer instead. It looks as if the mapping established
for that buffer had survived the vunmap() / vmap() sequence.

In case it matters, my system is single core (not SMP).
Any ideas, anybody?

tk
--
--------------------------------------------------

Thomas Koeller, Software Development
Basler Vision Technologies

thomas dot koeller at baslerweb dot com
http://www.baslerweb.com

==============================

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/