Can memory pages be allocated to a specified physical address in the kernel module?

I am writing a kernel module in a guest operating system that will run on a virtual machine using KVM. Here I want to allocate a memory page at a specific physical address. kmalloc () gives me memory, but at the physical address chosen by the OS.

Reference Information. I am writing a device emulation method in qemu that would not exit when a guest contacts the device (it goes, for example, to I / O cards, as well as to the displayed ports). The basic idea is this: the guest device driver will write to the specific (guest) address of the physical memory. The thread in the qemu process will continuously check it to check for new data (through some status bits, etc.). And take action accordingly, without causing an exit. Since there is no (existing) way in which a guest can tell the host which address is used by the device driver, I want a predefined memory page to be allocated for it.

+4
source share
2 answers

You cannot allocate memory at a specific address, however you can reserve specific physical addresses at boot time using reserve_bootmem() . Calling reserve_bootmem() at the start of the download (of course, it requires a modified kernel) ensures that the reserved memory will not be transferred to the buddy's system (i.e. alloc_pages() and friends of a higher level - kmalloc() ), and you can use this memory for any purpose.

+6
source

It looks like you should attack this on the other hand, having a range of physical memory reserved on the memory card that the QEMU BIOS passes to the guest kernel at boot time.

0
source

Source: https://habr.com/ru/post/1380430/


All Articles