[PATCH kvmtool v3] x86: Fix some memory sizes when setting up bios

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sorry for this resending. Delete redundant auto-added header "kvm/bios.h".

In e820_setup(), the memory region of MB_BIOS is [MB_BIOS_BEGIN, MB_BIOS_END],
so its memory size should be MB_BIOS_SIZE (= MB_BIOS_END - MB_BIOS_BEGIN + 1).
The same thing goes for BDA, EBDA, MB_BIOS and VGA_ROM in setup_bios().
By the way, a little change is made in setup_irq_handler() to avoid using
hard coding.

Changes since v1:
- Adopt Will's suggestions
- A little change in setup_irq_handler()

Changes since v2:
- Delete redundant headers

Signed-off-by: Sicheng Liu <lsc2001@xxxxxxxxxxx>
---
 x86/bios.c             | 12 ++++++------
 x86/include/kvm/bios.h |  3 +++
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/x86/bios.c b/x86/bios.c
index 5ac9e24ae0a8..0f8dd2415a11 100644
--- a/x86/bios.c
+++ b/x86/bios.c
@@ -45,7 +45,7 @@ static void setup_irq_handler(struct kvm *kvm, struct irq_handler *handler)
 		.offset		= handler->address - MB_BIOS_BEGIN,
 	};
 
-	DIE_IF((handler->address - MB_BIOS_BEGIN) > 0xffffUL);
+	DIE_IF((handler->address - MB_BIOS_BEGIN + 1) > MB_BIOS_SIZE);
 
 	interrupt_table__set(&kvm->arch.interrupt_table, &intr_desc, handler->irq);
 }
@@ -75,7 +75,7 @@ static void e820_setup(struct kvm *kvm)
 	};
 	mem_map[i++]	= (struct e820entry) {
 		.addr		= MB_BIOS_BEGIN,
-		.size		= MB_BIOS_END - MB_BIOS_BEGIN,
+		.size		= MB_BIOS_SIZE,
 		.type		= E820_RESERVED,
 	};
 	if (kvm->ram_size < KVM_32BIT_GAP_START) {
@@ -132,16 +132,16 @@ void setup_bios(struct kvm *kvm)
 	 * we definitely don't want any trash here
 	 */
 	p = guest_flat_to_host(kvm, BDA_START);
-	memset(p, 0, BDA_END - BDA_START);
+	memset(p, 0, BDA_SIZE);
 
 	p = guest_flat_to_host(kvm, EBDA_START);
-	memset(p, 0, EBDA_END - EBDA_START);
+	memset(p, 0, EBDA_SIZE);
 
 	p = guest_flat_to_host(kvm, MB_BIOS_BEGIN);
-	memset(p, 0, MB_BIOS_END - MB_BIOS_BEGIN);
+	memset(p, 0, MB_BIOS_SIZE);
 
 	p = guest_flat_to_host(kvm, VGA_ROM_BEGIN);
-	memset(p, 0, VGA_ROM_END - VGA_ROM_BEGIN);
+	memset(p, 0, VGA_ROM_SIZE);
 
 	/* just copy the bios rom into the place */
 	p = guest_flat_to_host(kvm, MB_BIOS_BEGIN);
diff --git a/x86/include/kvm/bios.h b/x86/include/kvm/bios.h
index edeab17fdd1b..6f4338d50717 100644
--- a/x86/include/kvm/bios.h
+++ b/x86/include/kvm/bios.h
@@ -21,9 +21,11 @@
 
 #define BDA_START			0x00000400
 #define BDA_END				0x000004ff
+#define BDA_SIZE			(BDA_END - BDA_START + 1)
 
 #define EBDA_START			0x0009fc00
 #define EBDA_END			0x0009ffff
+#define EBDA_SIZE			(EBDA_END - EBDA_START + 1)
 
 #define E820_MAP_START			EBDA_START
 
@@ -43,6 +45,7 @@
 #define VGA_ROM_MODES			(VGA_ROM_OEM_STRING + VGA_ROM_OEM_STRING_SIZE)
 #define VGA_ROM_MODES_SIZE		32
 #define VGA_ROM_END			0x000c7fff
+#define VGA_ROM_SIZE			(VGA_ROM_END - VGA_ROM_BEGIN + 1)
 
 /* we handle one page only */
 #define VGA_RAM_SEG			(VGA_RAM_BEGIN >> 4)
-- 
2.25.1





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux