mapping memory reserved by mmap kernel boot param into user space

假装没事ソ 提交于 2019-12-03 00:33:37
  1. You can use standard phram driver in steps to access your memory from userspace. No coding is needed. Kernel recompilation at maximum.

  2. Do You really have more then 64Gb of RAM? Does Your hardware really support it?

When i do mmap from the use space application i see a system hang.

Before you can use the remap_pfn_range() API, see documentation inlined inside mm/memory.c (of kernel source), and it indicated that you have to have held the mm semaphore first.

/**
 * remap_pfn_range - remap kernel memory to userspace
 * @vma: user vma to map to
 * @addr: target user address to start at
 * @pfn: physical address of kernel memory
 * @size: size of map area
 * @prot: page protection flags for this mapping
 *
 *  Note: this is only safe if the mm semaphore is held when called.
 */

And how to acquire the semaphore is via up_read() and down_read() API - just "grep" for up_read inside the mm directory and there are many examples:

mempolicy.c:    up_read(&mm->mmap_sem);
migrate.c:  up_read(&mm->mmap_sem);
mincore.c:      up_read(&current->mm->mmap_sem);
mmap.c:     up_read(&mm->mmap_sem);
msync.c:            up_read(&mm->mmap_sem);
nommu.c:    up_read(&mm->mmap_sem);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!