diff mbox series

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

Message ID SY6P282MB373318D6241D56E074B040DFA3392@SY6P282MB3733.AUSP282.PROD.OUTLOOK.COM (mailing list archive)
State New, archived
Headers show
Series [kvmtool,v3] x86: Fix some memory sizes when setting up bios | expand

Commit Message

Sicheng Liu March 30, 2024, 8:41 a.m. UTC
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@outlook.com>
---
 x86/bios.c             | 12 ++++++------
 x86/include/kvm/bios.h |  3 +++
 2 files changed, 9 insertions(+), 6 deletions(-)

Comments

Will Deacon April 9, 2024, 4:59 p.m. UTC | #1
On Sat, 30 Mar 2024 08:41:49 +0000, Sicheng Liu wrote:
> 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.
> 
> [...]

Applied to kvmtool (master), thanks!

[1/1] x86: Fix some memory sizes when setting up bios
      https://git.kernel.org/will/kvmtool/c/da4cfc3e5403

Cheers,
diff mbox series

Patch

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)