How can kernel reach the mmaped memory by the virtual address
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..
上一篇: 如何在内核模块中注册用户空间内存区域?
下一篇: 内核如何通过虚拟地址到达虚拟内存