Add helper to retrieve page size of RAM backing, when hugetlbfs is used. Signed-off-by: Marcelo Tosatti Index: git/qemu/exec.c =================================================================== --- qemu.orig/exec.c +++ qemu/exec.c @@ -961,8 +961,27 @@ static void *file_ram_alloc(RAMBlock *bl return (NULL); } block->fd = fd; + block->hpagesize = hpagesize; return area; } + +uint32_t qemu_get_ram_hpagesize(ram_addr_t addr) +{ + RAMBlock *block; + + QTAILQ_FOREACH(block, &ram_list.blocks, next) { + if (addr - block->offset < block->length) { + return block->hpagesize; + } + } + + fprintf(stderr, "%s: Bad ram offset %" PRIx64 "\n", __func__, + (uint64_t)addr); + abort(); + + return 0; +} + #else static void *file_ram_alloc(RAMBlock *block, ram_addr_t memory, Index: qemu/include/exec/cpu-all.h =================================================================== --- qemu.orig/include/exec/cpu-all.h +++ qemu/include/exec/cpu-all.h @@ -448,6 +448,7 @@ typedef struct RAMBlock { ram_addr_t offset; ram_addr_t length; uint32_t flags; + uint32_t hpagesize; char idstr[256]; /* Reads can take either the iothread or the ramlist lock. * Writes must take both locks. Index: git/qemu/include/exec/cpu-common.h =================================================================== --- qemu.orig/include/exec/cpu-common.h +++ qemu/include/exec/cpu-common.h @@ -54,6 +54,9 @@ void qemu_ram_remap(ram_addr_t addr, ram /* This should not be used by devices. */ MemoryRegion *qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr); void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev); +#ifdef __linux__ +uint32_t qemu_get_ram_hpagesize(ram_addr_t addr); +#endif void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf, int len, int is_write);