0

I'm writing a device driver these days. User process get a virtual address through mmap and mapped with a physical address with remap_pfn_range. Now I need to implement the .access function in vm_operations_struct in kernel to get the mapped memory of the virtual address passed by user thread, which I met problem.
int vm_access(struct vm_area_struct *vma, unsigned long addr, void *buf, int len, int write) I need to copy the data in the addr, which is the virtual address allocated by mmap and is mapped to a physical address, to *buf. I tried copy_from_user, it fails; When I try memcpy_fromio, the os simply crashes when it's called.. Tried several methods, just don't work.

Is there any way to do so or it's just not practical? Thanks in advance!

Update:
Now the problem is to get physical memory already mapped to user space in kernel device driver. I used ioremap and memcpy_fromio to get the data, but system crashes.. But since the address can be successfully reached in user mode process with mmap and remap_pfn_range, it's confusing why I cannot read it in kernel..

cynkiller
  • 73
  • 9
  • https://stackoverflow.com/questions/13465095/how-to-mmap-a-file-in-linux-kernel-space – stark Jun 05 '17 at 17:23
  • thanks @stark. I tried `set_fs(KERNEL_DS)` but seems it doesn't work either.. – cynkiller Jun 06 '17 at 02:28
  • I am figuring the problem is because user space isolation. I want to implement this function for gdb debug use, but since gdb is a different user process, it cannot reach the exec user space directly. What I need is to figure out a way to reach the actual physical address from kernel... – cynkiller Jun 06 '17 at 05:21

0 Answers0