RE: Could convert a buffer that allocated by vmalloc to pages?

From: Anton Altaparmakov
Date: Tue Jan 23 2007 - 14:37:20 EST


Hi,

On Tue, 23 Jan 2007, Yu-Chen Wu wrote:
> All of the code as below:
> //==============================================
> extern struct vm_struct *vmlist;
> struct vm_struct *vmlist2,*L2vm;
>
> int find_vm_struct(void *addr)
> {
> struct vm_struct **p;
> int i;
> struct page *pg;
> printk("&vmlist=%x\n",&vmlist);
> for (p = &vmlist ; (L2vm = *p) != NULL ;p = &L2vm->next) {
> if (L2vm->addr == addr)
> goto found;
> }
> printk(KERN_INFO "find_vm_struct filed\n");
> return 0;
> found:
> printk(KERN_INFO "find_vm_struct OK:%x addr:%x
> nr_pages:%d\n",L2vm,L2vm->addr,L2vm->nr_pages);
> for(i=0;i<L2vm->nr_pages;i++)
> {
> if(L2vm->pages[i])
> printk("page
> allocated:%x\n",page_address(L2vm->pages[i]));

You are printing "page_address()" of each of the pages here.

[snip]
> find_vm_struct(L2cache);
> read_unlock(&vmlist_lock);
> tpage=vmalloc_to_page(L2cache);
> printk(KERN_INFO "vmalloc_to_page tpage :%x\n",tpage);

You are printing "tpage" instead of page_address(tpage)" here so of course
it will not be the same as what you did above where you printed the
page_address() instead of the pages themselves...

> Is it possible that the buffer allocated by vmalloc be used to do DMA
> transmission?

Only if you do it page by page as the pages are not physically contiguous,
i.e. you would have to call vmalloc_to_page() for each page in the
vmalloced area and then create a scatter-gather DMA operation working on
each page in sequence. I suspect this is not what you want...

You will need to read up on doing DMA mappings from the kernel to learn
how to make memory physicall contiguous. Hint start with reading
Documentation/DMA-API.txt and DMA-mapping.txt...

Best regards,

Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer, http://www.linux-ntfs.org/
-
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/