On 03/15/17 00:09, Petr Berky wrote:
From b06589c683a7defb4853a3b810bd7e6a12abe2d6 Mon Sep 17 00:00:00 2001 From: Petr Berky petr.berky@email.cz Date: Tue, 14 Mar 2017 23:32:15 +0100 Subject: [PATCH v2] config: Add function to check if fw_cfg exists
It was found qemu_get_present_cpus_count may return impossible number of cpus because of not checking if fw_cfg exists before using it. That may lead to undefined behavior of emulator, in particular Bochs that freezes.
Signed-off-by: Petr Berky petr.berky@email.cz
src/fw/paravirt.c | 12 +++++++++++- src/fw/paravirt.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index 707502d..dfc69d4 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -32,9 +32,16 @@ u32 RamSize; u64 RamSizeOver4G; // Type of emulator platform. int PlatformRunningOn VARFSEG; +// cfg enabled +int cfg_enabled = 0; // cfg_dma enabled int cfg_dma_enabled = 0;
+inline int qemu_cfg_enabled(void) +{
- return cfg_enabled;
+}
inline int qemu_cfg_dma_enabled(void) { return cfg_dma_enabled; @@ -392,7 +399,9 @@ u16 qemu_get_present_cpus_count(void) { u16 smp_count = 0;
- qemu_cfg_read_entry(&smp_count, QEMU_CFG_NB_CPUS, sizeof(smp_count));
- if (qemu_cfg_enabled()) {
qemu_cfg_read_entry(&smp_count, QEMU_CFG_NB_CPUS,
sizeof(smp_count));
- } u16 cmos_cpu_count = rtc_read(CMOS_BIOS_SMP_COUNT) + 1; if (smp_count < cmos_cpu_count) { smp_count = cmos_cpu_count;
@@ -570,6 +579,7 @@ void qemu_cfg_init(void) if (inb(PORT_QEMU_CFG_DATA) != sig[i]) return;
cfg_enabled = 1; dprintf(1, "Found QEMU fw_cfg\n");
// Detect DMA interface.
If we wanted to parallel the DMA check 100%, we'd set the variable under the debug message, not above it, but even I am not that pedantic. :)
Reviewed-by: Laszlo Ersek lersek@redhat.com
Igor, can you check if this is safe for S3 resume too? I think it is, but I had better ask you.
Thanks Laszlo
diff --git a/src/fw/paravirt.h b/src/fw/paravirt.h index 16f3d9a..a14d83e 100644 --- a/src/fw/paravirt.h +++ b/src/fw/paravirt.h @@ -49,6 +49,7 @@ static inline int runningOnKVM(void) { // QEMU_CFG_DMA ID bit #define QEMU_CFG_VERSION_DMA 2
+int qemu_cfg_enabled(void); int qemu_cfg_dma_enabled(void); void qemu_preinit(void); void qemu_platform_setup(void);