remap_pfn_range 如何将内核内存重新映射到用户空间? [英] How remap_pfn_range remaps kernel memory to user space?

查看:34
本文介绍了remap_pfn_range 如何将内核内存重新映射到用户空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

remap_pfn_range 函数(用于驱动程序中的mmap 调用)可用于将内核内存映射到用户空间.它是如何完成的?谁能解释一下具体的步骤?内核模式是特权模式(PM),而用户空间是非特权模式(NPM).在 PM CPU 中可以访问所有内存,而在 NPM 中一些内存是受限的 - CPU 无法访问.当 remap_pfn_range 被调用时,那个仅限于 PM 的内存范围现在如何可供用户空间访问?

remap_pfn_range function (used in mmap call in driver) can be used to map kernel memory to user space. How is it done? Can anyone explain precise steps? Kernel Mode is a privileged mode (PM) while user space is non privileged (NPM). In PM CPU can access all memory while in NPM some memory is restricted - cannot be accessed by CPU. When remap_pfn_range is called, how is that range of memory which was restricted only to PM is now accessible to user space?

查看remap_pfn_range 代码有pgprot_t struct.这是保护映射相关的结构.什么是保护映射?是上面问题的答案吗?

Looking at remap_pfn_range code there is pgprot_t struct. This is protection mapping related struct. What is protection mapping? Is it the answer to above question?

推荐答案

其实很简单,内核内存(通常)只有一个页表条目,其架构特定位表示:这个页表条目仅在CPU 处于内核模式".

It's simple really, kernel memory (usually) simply has a page table entry with the architecture specific bit that says: "this page table entry is only valid while the CPU is in kernel mode".

remap_pfn_range 的作用是创建另一个页表条目,该条目具有与未设置该位的同一物理内存页不同的虚拟地址.

What remap_pfn_range does is create another page table entry, with a different virtual address to the same physical memory page that doesn't have that bit set.

通常,顺便说一句,这是个坏主意:-)

Usually, it's a bad idea btw :-)

这篇关于remap_pfn_range 如何将内核内存重新映射到用户空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆