From: Sicheng Liu <lsc2001@outlook.com>
To: kvm@vger.kernel.org
Cc: will@kernel.org, julien.thierry.kdev@gmail.com,
Sicheng Liu <lsc2001@outlook.com>
Subject: [PATCH kvmtool v2] x86: Fix some memory sizes when setting up bios
Date: Sat, 30 Mar 2024 08:21:28 +0000 [thread overview]
Message-ID: <SY6P282MB3733CDCCC1B9B2A16FFA2975A3392@SY6P282MB3733.AUSP282.PROD.OUTLOOK.COM> (raw)
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()
Signed-off-by: Sicheng Liu <lsc2001@outlook.com>
---
x86/bios.c | 13 +++++++------
x86/include/kvm/bios.h | 3 +++
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/x86/bios.c b/x86/bios.c
index 5ac9e24ae0a8..916fe7ddff46 100644
--- a/x86/bios.c
+++ b/x86/bios.c
@@ -1,3 +1,4 @@
+#include "kvm/bios.h"
#include "kvm/kvm.h"
#include "kvm/boot-protocol.h"
#include "kvm/e820.h"
@@ -45,7 +46,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 +76,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 +133,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
reply other threads:[~2024-03-30 8:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=SY6P282MB3733CDCCC1B9B2A16FFA2975A3392@SY6P282MB3733.AUSP282.PROD.OUTLOOK.COM \
--to=lsc2001@outlook.com \
--cc=julien.thierry.kdev@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.