Received: from eggs.gnu.org ([2001:4830:134:3::10]:45093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XA2r4-0007Uh-3R for qemu-devel@nongnu.org; Wed, 23 Jul 2014 16:09:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XA2qw-0007V4-SF for qemu-devel@nongnu.org; Wed, 23 Jul 2014 16:09:38 -0400 Received: from mail-by2lp0240.outbound.protection.outlook.com ([207.46.163.240]:23075 helo=na01-by2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XA2qw-0007Uf-GN for qemu-devel@nongnu.org; Wed, 23 Jul 2014 16:09:30 -0400 From: Joel Schopp Date: Wed, 23 Jul 2014 15:09:25 -0500 Message-ID: <20140723200925.9787.75225.stgit@joelaarch64.amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] arm64: 64K pages and > 1024MB guest List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell kvm_set_phys_mem doesn't work on arm64 with memory > 1GB. It exits with: kvm_set_phys_mem: error registering slot: Invalid argument An example of the failing address and size are start_addr == 0x90011000 and size=0xaffef000. As you can see both of these are 4K aligned, not 64K aligned. At 1024MB or smaller qemu only makes one call to kvm_set_user_memory_region, so the start_addr and size are aligned by accident and the bug doesn't happen. The following patch makes things work for me on an arm64 SOC. I also smoke tested the patch on an x86-64 box and qemu seemed to still run fine there with the patch applied. Cc: Peter Maydell Signed-off-by: Joel Schopp --- kvm-all.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 1402f4f..1975862 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -618,14 +618,14 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add) /* kvm works in page size chunks, but the function may be called with sub-page size and unaligned start address. */ - delta = TARGET_PAGE_ALIGN(size) - size; + delta = HOST_PAGE_ALIGN(start_addr) - start_addr; if (delta > size) { return; } start_addr += delta; size -= delta; - size &= TARGET_PAGE_MASK; - if (!size || (start_addr & ~TARGET_PAGE_MASK)) { + size &= qemu_host_page_mask; + if (!size || (start_addr & ~qemu_host_page_mask)) { return; }