From patchwork Fri May 20 14:23:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 803762 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 p4KENYla024875 for ; Fri, 20 May 2011 14:23:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933648Ab1ETOXb (ORCPT ); Fri, 20 May 2011 10:23:31 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:50731 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933122Ab1ETOXa (ORCPT ); Fri, 20 May 2011 10:23:30 -0400 Received: by wwa36 with SMTP id 36so4075904wwa.1 for ; Fri, 20 May 2011 07:23:29 -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=OHZnMlJvXp/TlLxnom38TmlvsSHL9BRq1Z4aMDpi+Hk=; b=QjfCi7iUipf11olvPcT/lDChTF58tOwDoSCQpqapukTfUz+lQqXIH+u6Ylz40THpqB 65YwyIMuqzWQeOjnMKcErorC64g0AdbjxKmG81uq0GLTmYlspDqFIeCeeTeRzbzqCyB7 81iC6AYxsYAU9wypKPIZCqwAINpL7IaY5DVdY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=kybFYTpOEcGibItLd5VnBNTfWdWFeQniH3IhapK+Ldv4TE378kNErzypk/DACUg4/3 wlbwlABJkfOu20qJ1VqJBKpcRIdsv1RAupQKZAMct26GADDDA4DTSe7gF0tPuPyR417h 9mwl5Zcrd74AreDwYElvJ9pg7xuWwjqTs0zvE= Received: by 10.217.6.197 with SMTP id y47mr683781wes.55.1305901409018; Fri, 20 May 2011 07:23:29 -0700 (PDT) Received: from localhost.localdomain (bzq-79-179-206-38.red.bezeqint.net [79.179.206.38]) by mx.google.com with ESMTPS id m15sm1874392weq.26.2011.05.20.07.23.27 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 20 May 2011 07:23:28 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH] kvm tools: Cleanup e820 code Date: Fri, 20 May 2011 17:23:05 +0300 Message-Id: <1305901385-8211-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]); Fri, 20 May 2011 14:23:34 +0000 (UTC) Several cleanups in the patch: - Use kernel headers for e820 types and definitions. - A byte sized entry count for e820 enteries was used, this should be dword sized. Update in-memory layout and bios code to fix it. - Use struct e820map to calculate offsets used by bios code. Signed-off-by: Sasha Levin Reviewed-by: Cyrill Gorcunov --- tools/kvm/bios.c | 37 +++++++++++++++++++------------------ tools/kvm/bios/e820.c | 29 +++++++++++++++++++++-------- tools/kvm/include/kvm/bios.h | 3 +-- tools/kvm/include/kvm/e820.h | 11 ----------- 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/tools/kvm/bios.c b/tools/kvm/bios.c index 3cd9b24..94e914c 100644 --- a/tools/kvm/bios.c +++ b/tools/kvm/bios.c @@ -5,6 +5,7 @@ #include "kvm/util.h" #include +#include #include "bios/bios-rom.h" @@ -54,50 +55,50 @@ static void setup_irq_handler(struct kvm *kvm, struct irq_handler *handler) */ static void e820_setup(struct kvm *kvm) { - struct e820_entry *mem_map; - unsigned char *size; + struct e820map *e820; + struct e820entry *mem_map; unsigned int i = 0; - size = guest_flat_to_host(kvm, E820_MAP_SIZE); - mem_map = guest_flat_to_host(kvm, E820_MAP_START); + e820 = guest_flat_to_host(kvm, E820_MAP_START); + mem_map = e820->map; - mem_map[i++] = (struct e820_entry) { + mem_map[i++] = (struct e820entry) { .addr = REAL_MODE_IVT_BEGIN, .size = EBDA_START - REAL_MODE_IVT_BEGIN, - .type = E820_MEM_USABLE, + .type = E820_RAM, }; - mem_map[i++] = (struct e820_entry) { + mem_map[i++] = (struct e820entry) { .addr = EBDA_START, .size = VGA_RAM_BEGIN - EBDA_START, - .type = E820_MEM_RESERVED, + .type = E820_RESERVED, }; - mem_map[i++] = (struct e820_entry) { + mem_map[i++] = (struct e820entry) { .addr = MB_BIOS_BEGIN, .size = MB_BIOS_END - MB_BIOS_BEGIN, - .type = E820_MEM_RESERVED, + .type = E820_RESERVED, }; if (kvm->ram_size < KVM_32BIT_GAP_START) { - mem_map[i++] = (struct e820_entry) { + mem_map[i++] = (struct e820entry) { .addr = BZ_KERNEL_START, .size = kvm->ram_size - BZ_KERNEL_START, - .type = E820_MEM_USABLE, + .type = E820_RAM, }; } else { - mem_map[i++] = (struct e820_entry) { + mem_map[i++] = (struct e820entry) { .addr = BZ_KERNEL_START, .size = KVM_32BIT_GAP_START - BZ_KERNEL_START, - .type = E820_MEM_USABLE, + .type = E820_RAM, }; - mem_map[i++] = (struct e820_entry) { + mem_map[i++] = (struct e820entry) { .addr = 0x100000000ULL, .size = kvm->ram_size - KVM_32BIT_GAP_START, - .type = E820_MEM_USABLE, + .type = E820_RAM, }; } - BUILD_BUG_ON(i > E820_MEM_AREAS); + BUILD_BUG_ON(i > E820_X_MAX); - *size = i; + e820->nr_map = i; } /** diff --git a/tools/kvm/bios/e820.c b/tools/kvm/bios/e820.c index e4d8354..b7fa4c1 100644 --- a/tools/kvm/bios/e820.c +++ b/tools/kvm/bios/e820.c @@ -4,6 +4,8 @@ #include "kvm/bios.h" #include "kvm/util.h" +#include + static inline void set_fs(u16 seg) { asm volatile("movw %0,%%fs" : : "rm" (seg)); @@ -18,37 +20,48 @@ static inline u8 rdfs8(unsigned long addr) return v; } +static inline u32 rdfs32(unsigned long addr) +{ + u32 v; + + asm volatile("addr32 movl %%fs:%1,%0" : "=q" (v) : "m" (*(u32 *)addr)); + + return v; +} + bioscall void e820_query_map(struct e820_query *query) { - u8 map_size; + struct e820map *e820; + u32 map_size; u16 fs_seg; u32 ndx; - fs_seg = flat_to_seg16(E820_MAP_SIZE); + e820 = (struct e820map *)E820_MAP_START; + fs_seg = flat_to_seg16(E820_MAP_START); set_fs(fs_seg); ndx = query->ebx; - map_size = rdfs8(flat_to_off16(E820_MAP_SIZE, fs_seg)); + map_size = rdfs32(flat_to_off16((u32)&e820->nr_map, fs_seg)); if (ndx < map_size) { - unsigned long start; + u32 start; unsigned int i; u8 *p; - fs_seg = flat_to_seg16(E820_MAP_START); + fs_seg = flat_to_seg16(E820_MAP_START); set_fs(fs_seg); - start = E820_MAP_START + sizeof(struct e820_entry) * ndx; + start = (u32)&e820->map[ndx]; p = (void *) query->edi; - for (i = 0; i < sizeof(struct e820_entry); i++) + for (i = 0; i < sizeof(struct e820entry); i++) *p++ = rdfs8(flat_to_off16(start + i, fs_seg)); } query->eax = SMAP; - query->ecx = sizeof(struct e820_entry); + query->ecx = sizeof(struct e820entry); query->ebx = ++ndx; if (ndx >= map_size) diff --git a/tools/kvm/include/kvm/bios.h b/tools/kvm/include/kvm/bios.h index 7586e2a..9db2ab5 100644 --- a/tools/kvm/include/kvm/bios.h +++ b/tools/kvm/include/kvm/bios.h @@ -24,8 +24,7 @@ #define EBDA_START 0x0009fc00 #define EBDA_END 0x0009ffff -#define E820_MAP_SIZE EBDA_START -#define E820_MAP_START (EBDA_START + 0x01) +#define E820_MAP_START EBDA_START #define MB_BIOS_BEGIN 0x000f0000 #define MB_BIOS_END 0x000fffff diff --git a/tools/kvm/include/kvm/e820.h b/tools/kvm/include/kvm/e820.h index e0f5f2a..9b339ed 100644 --- a/tools/kvm/include/kvm/e820.h +++ b/tools/kvm/include/kvm/e820.h @@ -5,17 +5,6 @@ #define SMAP 0x534d4150 /* ASCII "SMAP" */ -#define E820_MEM_USABLE 1 -#define E820_MEM_RESERVED 2 - -#define E820_MEM_AREAS 5 - -struct e820_entry { - u64 addr; /* start of memory segment */ - u64 size; /* size of memory segment */ - u32 type; /* type of memory segment */ -} __attribute__((packed)); - struct e820_query { u32 eax; u32 ebx;