From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34918) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VZSEC-00056o-D9 for qemu-devel@nongnu.org; Thu, 24 Oct 2013 17:14:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VZSE5-0007F1-2R for qemu-devel@nongnu.org; Thu, 24 Oct 2013 17:14:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2233) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VZSE4-0007EO-Ou for qemu-devel@nongnu.org; Thu, 24 Oct 2013 17:13:52 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9OLDpkD007822 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 24 Oct 2013 17:13:51 -0400 Message-Id: <20131024211249.650294999@amt.cnet> Date: Thu, 24 Oct 2013 19:11:59 -0200 From: Marcelo Tosatti References: <20131024211158.064049176@amt.cnet> Content-Disposition: inline; filename=add-hpagesize-to-ramblock Subject: [Qemu-devel] [patch 1/2] exec: add qemu_get_ram_hpagesize List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aarcange@redhat.com, pbonzini@redhat.com, Marcelo Tosatti , gleb@redhat.com 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);