From patchwork Tue May 10 21:05:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 775362 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4AL5YS6018735 for ; Tue, 10 May 2011 21:05:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751363Ab1EJVFc (ORCPT ); Tue, 10 May 2011 17:05:32 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:44245 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751130Ab1EJVFb (ORCPT ); Tue, 10 May 2011 17:05:31 -0400 Received: by wya21 with SMTP id 21so4996566wya.19 for ; Tue, 10 May 2011 14:05:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=0adKCPmfskxPBbWOHsQr/VpcRSt4Ku/CxfaXLsNQ6ao=; b=TSyfURtMK+KLJBYZqTFPWi04O2UGMBTHU19zDgUY0AJnWWXhtO6FRFFxFfe0GFm1zi B6mZOzMl+v6l7eHpsa596jH4EJoIL5jSshaUyLOjBbdzBOfJgKHyarlzqRkk8CgScCiB gz/GS6xF5wPutTnhQcvjVM2jS5maC4gkyl2Rg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=cRGwDxoxmOSsWiwWLgJcbLbFBF1TuzpyUYa8aKLvUDg1/fy0cIeoQGakJyxx7RPfq1 RXOqFPkxB1ioeB45HK10/R9OJYgK/L7vvvnO4z9P94tk69f5lyno02UMKJxZhZotWNHu lNr4ZYRgD3lcb/msGpVM2PCj7AFYguiuR+xz8= Received: by 10.216.81.69 with SMTP id l47mr4332410wee.78.1305061530012; Tue, 10 May 2011 14:05:30 -0700 (PDT) Received: from localhost.localdomain ([188.120.134.217]) by mx.google.com with ESMTPS id m14sm2341809wes.14.2011.05.10.14.05.27 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 10 May 2011 14:05:29 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, prasadjoshi124@gmail.com, avi@redhat.com, gorcunov@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 1/2] kvm tools: Add memory gap for larger RAM sizes Date: Wed, 11 May 2011 00:05:12 +0300 Message-Id: <1305061513-28360-1-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 10 May 2011 21:05:35 +0000 (UTC) Add a memory gap between 0xe0000000 and 0x100000000 when using more than 0xe0000000 bytes for guest RAM. This space is used by several things, PCI configuration space for example. This patch updates the e820 table, slot allocations used for KVM_SET_USER_MEMORY_REGION, and the address translation. Signed-off-by: Sasha Levin --- tools/kvm/bios.c | 27 +++++++++++++++++++++------ tools/kvm/include/kvm/e820.h | 2 +- tools/kvm/include/kvm/kvm.h | 9 ++++++++- tools/kvm/kvm.c | 22 ++++++++++++++++------ 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/tools/kvm/bios.c b/tools/kvm/bios.c index 2199c0c..cd417fa 100644 --- a/tools/kvm/bios.c +++ b/tools/kvm/bios.c @@ -61,7 +61,7 @@ static void e820_setup(struct kvm *kvm) size = guest_flat_to_host(kvm, E820_MAP_SIZE); mem_map = guest_flat_to_host(kvm, E820_MAP_START); - *size = E820_MEM_AREAS; + mem_map[i++] = (struct e820_entry) { .addr = REAL_MODE_IVT_BEGIN, @@ -78,13 +78,28 @@ static void e820_setup(struct kvm *kvm) .size = MB_BIOS_END - MB_BIOS_BEGIN, .type = E820_MEM_RESERVED, }; - mem_map[i++] = (struct e820_entry) { - .addr = BZ_KERNEL_START, - .size = kvm->ram_size - BZ_KERNEL_START, - .type = E820_MEM_USABLE, - }; + if (kvm->ram_size < 0xe0000000) { + mem_map[i++] = (struct e820_entry) { + .addr = BZ_KERNEL_START, + .size = kvm->ram_size - BZ_KERNEL_START, + .type = E820_MEM_USABLE, + }; + } else { + mem_map[i++] = (struct e820_entry) { + .addr = BZ_KERNEL_START, + .size = 0xe0000000 - BZ_KERNEL_START, + .type = E820_MEM_USABLE, + }; + mem_map[i++] = (struct e820_entry) { + .addr = 0x100000000ULL, + .size = kvm->ram_size - 0xe0000000 - BZ_KERNEL_START, + .type = E820_MEM_USABLE, + }; + } BUILD_BUG_ON(i > E820_MEM_AREAS); + + *size = i; } /** diff --git a/tools/kvm/include/kvm/e820.h b/tools/kvm/include/kvm/e820.h index 252ae1f..e0f5f2a 100644 --- a/tools/kvm/include/kvm/e820.h +++ b/tools/kvm/include/kvm/e820.h @@ -8,7 +8,7 @@ #define E820_MEM_USABLE 1 #define E820_MEM_RESERVED 2 -#define E820_MEM_AREAS 4 +#define E820_MEM_AREAS 5 struct e820_entry { u64 addr; /* start of memory segment */ diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index 3dab78d..e9c16ea 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -60,7 +60,14 @@ static inline u32 segment_to_flat(u16 selector, u16 offset) static inline void *guest_flat_to_host(struct kvm *self, unsigned long offset) { - return self->ram_start + offset; + /* + * We have a gap between 0xe0000000 and 0x100000000. + * Consider it when translating an address above 0x100000000. + */ + if (offset < 0xe0000000) + return self->ram_start + offset; + else + return self->ram_start + 0xe0000000 + (offset - 0x100000000); } static inline void *guest_real_to_host(struct kvm *self, u16 selector, u16 offset) diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index 65793f2..976b099 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -153,23 +153,33 @@ static bool kvm__cpu_supports_vm(void) return regs.ecx & (1 << feature); } -void kvm__init_ram(struct kvm *self) +static void kvm_register_mem_slot(struct kvm *kvm, u32 slot, u64 guest_phys, u64 size, u64 userspace_addr) { struct kvm_userspace_memory_region mem; int ret; mem = (struct kvm_userspace_memory_region) { - .slot = 0, - .guest_phys_addr = 0x0UL, - .memory_size = self->ram_size, - .userspace_addr = (unsigned long) self->ram_start, + .slot = slot, + .guest_phys_addr = guest_phys, + .memory_size = size, + .userspace_addr = userspace_addr, }; - ret = ioctl(self->vm_fd, KVM_SET_USER_MEMORY_REGION, &mem); + ret = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &mem); if (ret < 0) die_perror("KVM_SET_USER_MEMORY_REGION ioctl"); } +void kvm__init_ram(struct kvm *self) +{ + if (self->ram_size < 0xe0000000) { + kvm_register_mem_slot(self, 0, 0, self->ram_size, (u64)self->ram_start); + } else { + kvm_register_mem_slot(self, 0, 0, 0xe0000000, (u64)self->ram_start); + kvm_register_mem_slot(self, 1, 0x100000000ULL, self->ram_size - 0xe0000000, (u64)self->ram_start + 0xe0000000); + } +} + int kvm__max_cpus(struct kvm *self) { int ret;