From mboxrd@z Thu Jan 1 00:00:00 1970 From: malte.vesper@postgrad.manchester.ac.uk (Malte Vesper) Date: Thu, 29 Jan 2015 19:50:52 +0000 Subject: Propper use of pci_map_sg Message-ID: <54CA8F1C.50909@postgrad.manchester.ac.uk> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org Hi, I am trying to use pci_map_sg in combination with get_user_pages_fast for a driver. However my code screws the processes memory map over. For easier testing I bundled the piinin/unpinning and mapping unmapping into one ioctl call. The following code misses all the checks on return values, since it is only inteneded as a MWE. When I run my code I get a "*BUG: Bad page map in process ...*", after "Done" is printed. I tried following DMA-API-howto.txt and looking at other code, but I fail to see where I go wrong. Regards, Ted Code from the IOCTL handler: case IOCTL_FPGA_PIN_PAGE: { struct pageInfo pageInfo; dev_dbg(&pcidev->dev, pr_fmt("IOCTL: IOCTL_FPGA_PIN_PAGE\n")); if(!copy_from_user(&pageInfo, (void*)arg, sizeof(struct pageInfo))) { //horrible test const int noPages = pageInfo.size/PAGE_SIZE; int pinned; int mapped = 0; struct scatterlist* scatterlist; printk("Test start\n"); //userspacestartpointer, nopages, write?, page* array struct page** pages=kmalloc(sizeof(struct page*)*noPages, GFP_KERNEL); pinned=*get_user_pages_fast*((unsigned long)pageInfo.start, noPages, 1, pages); scatterlist = kmalloc(sizeof(struct scatterlist)*pinned, GFP_KERNEL); for(int i=0; i