我可以在内核模块中的指定物理地址分配内存页吗?
我正在客户操作系统中编写一个内核模块,该模块将在使用 KVM 的虚拟机上运行。这里我想在特定的物理地址分配一个内存页。 kmalloc() 为我提供内存,但物理地址由操作系统选择。
背景:我正在 qemu 中编写一种设备模拟技术,当来宾与设备通信时,该技术不会退出(例如,在 I/O 映射以及端口映射设备中它会退出)。基本思想如下:来宾设备驱动程序将写入特定的(来宾)物理内存地址。 qemu 进程中的线程将连续轮询它以检查新数据(通过一些状态位等)。并将采取相应行动而不导致退出。由于没有(现有)方式让来宾可以告诉主机设备驱动程序正在使用哪个地址,所以我希望为其分配一个预先指定的内存页面。
I am writing a kernel module in a guest operating system that will be run on a virtual machine using KVM. Here I want to allcoate a memory page at a particular physical address. kmalloc() gives me memory but at a physical address chosen by the OS.
Background : I am writing a device emulation technique in qemu that wouldn't exit when the guest communicates with the device (It exits, for example, in I/O mapped as well as port mapped devices). The basic idea is as follows : The guest device driver will write to a specific (guest) physical memory address. A thread in the qemu process will be polling it continuously to check for new data (through some status bits etc.). And will take action accordingly without causing an exit. Since there is no (existing) way by which guest can tell the host what address is being used by the device driver, I want a pre-specified memory page to be allocated for it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法在特定地址分配内存,但是,您可以使用
reserve_bootmem()
在启动时保留某些物理地址。在启动时尽早调用reserve_bootmem()(当然,它需要修改内核)将确保保留的内存不会传递给伙伴系统(即alloc_pages()) > 和更高级别的朋友 -kmalloc()
),您将能够将该内存用于任何目的。You cannot allocate memory at a specific address, however, you can reserve certain physical addresses on boot time using
reserve_bootmem()
. Callingreserve_bootmem()
early on boot (of course, it requires a modified kernel) will ensure that the reserved memory will not be passed on to the buddy system (i.e.alloc_pages()
and higher level friends -kmalloc()
), and you will be able to use that memory for any purpose.听起来您应该从另一面攻击这个问题,方法是在内存映射中保留物理内存范围,QEMU BIOS 在启动时将其传递给来宾内核。
It sounds like you should be attacking this from the other side, by having a physical memory range reserved in the memory map that the QEMU BIOS passes to the guest kernel at boot.