Re: mmap() implementation for pci_alloc_consistent() memory?

From: Leon Woestenberg
Date: Wed May 18 2011 - 21:04:43 EST


Hello,

On Thu, May 19, 2011 at 12:14 AM, Leon Woestenberg
<leon.woestenberg@xxxxxxxxx> wrote:
>
> int ringbuffer_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
> {
>        /* the buffer allocated with pci_alloc_consistent() */
>        void *vaddr = ringbuffer_virt;
>        int ret;
>
>        /* find the struct page that describes vaddr, the buffer
>         * allocated with pci_alloc_consistent() */
>        struct page *page = virt_to_page(lro_char->engine->ringbuffer_virt);
>        vmf->page = page;
>
>        /*** I have verified that vaddr, page, and the pfn correspond
> with vaddr = pci_alloc_consistent() ***/
>        ret = vm_insert_pfn(vma, address, page_to_pfn(page));
>        return ret;
> }
>

Some further debugging insights:

I found that pfn_valid is 0 on page_to_pfn(page). Isn't
pci_alloc_consistent() memory backed by a real struct page?

I found that when I use the allocation/mapping below instead of
pci_alloc_consistent(), the fault handler does the mapping correctly.

vaddr = __get_free_pages(GFP_KERNEL, 4);
busaddr = dma_map_single(lro->pci_dev, vaddr,
psize, dir_to_dev? DMA_TO_DEVICE: DMA_FROM_DEVICE);

Still no clue why the mmap fails on pci_alloc_consistent() memory.

Regards,
--
Leon
--
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/