[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 03/16] hw/i386/vmport: Propagate IOPort read to vCPU EAX regis
From: |
Liran Alon |
Subject: |
[PATCH v2 03/16] hw/i386/vmport: Propagate IOPort read to vCPU EAX register |
Date: |
Tue, 10 Mar 2020 18:53:19 +0200 |
vmport_ioport_read() returns the value that should propagate to vCPU EAX
register when guest reads VMPort IOPort (i.e. By x86 IN instruction).
However, because vmport_ioport_read() calls cpu_synchronize_state(), the
returned value gets overridden by the value in QEMU vCPU EAX register.
i.e. cpu->env.regs[R_EAX].
To fix this issue, change vmport_ioport_read() to explicitly override
cpu->env.regs[R_EAX] with the value it wish to propagate to vCPU EAX
register.
Reviewed-by: Nikita Leshenko <address@hidden>
Signed-off-by: Liran Alon <address@hidden>
---
hw/core/machine.c | 1 +
hw/i386/vmport.c | 24 ++++++++++++++++++++----
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 9e8c06036faf..b9da40460d52 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -39,6 +39,7 @@ GlobalProperty hw_compat_4_2[] = {
{ "usb-redir", "suppress-remote-wake", "off" },
{ "qxl", "revision", "4" },
{ "qxl-vga", "revision", "4" },
+ { "vmport", "version", "1" },
};
const size_t hw_compat_4_2_len = G_N_ELEMENTS(hw_compat_4_2);
diff --git a/hw/i386/vmport.c b/hw/i386/vmport.c
index ca4d95fc017f..736d78263889 100644
--- a/hw/i386/vmport.c
+++ b/hw/i386/vmport.c
@@ -75,17 +75,33 @@ static uint64_t vmport_ioport_read(void *opaque, hwaddr
addr,
eax = env->regs[R_EAX];
if (eax != VMPORT_MAGIC) {
- return eax;
+ goto out;
}
command = env->regs[R_ECX];
trace_vmport_command(command);
if (command >= VMPORT_ENTRIES || !s->func[command]) {
qemu_log_mask(LOG_UNIMP, "vmport: unknown command %x\n", command);
- return eax;
+ goto out;
}
- return s->func[command](s->opaque[command], addr);
+ eax = s->func[command](s->opaque[command], addr);
+
+out:
+ /*
+ * The call above to cpu_synchronize_state() gets vCPU registers values
+ * to QEMU but also cause QEMU to write QEMU vCPU registers values to
+ * vCPU implementation (e.g. Accelerator such as KVM) just before
+ * resuming guest.
+ *
+ * Therefore, in order to make IOPort return value propagate to
+ * guest EAX, we need to explicitly update QEMU EAX register value.
+ */
+ if (s->version > 1) {
+ cpu->env.regs[R_EAX] = eax;
+ }
+
+ return eax;
}
static void vmport_ioport_write(void *opaque, hwaddr addr,
@@ -163,7 +179,7 @@ static Property vmport_properties[] = {
* On every guest-visible change, should make changes conditioned on
* version and define proper version for previous machine-types.
*/
- DEFINE_PROP_UINT8("version", VMPortState, version, 1),
+ DEFINE_PROP_UINT8("version", VMPortState, version, 2),
DEFINE_PROP_END_OF_LIST(),
};
--
2.20.1
- [PATCH v2 00/16]: hw/i386/vmport: Bug fixes and improvements, Liran Alon, 2020/03/10
- [PATCH v2 01/16] hw/i386/vmport: Add device properties, Liran Alon, 2020/03/10
- [PATCH v2 02/16] hw/i386/vmport: Add compatability version field, Liran Alon, 2020/03/10
- [PATCH v2 04/16] hw/i386/vmport: Set EAX to -1 on failed and unsupported commands, Liran Alon, 2020/03/10
- [PATCH v2 03/16] hw/i386/vmport: Propagate IOPort read to vCPU EAX register,
Liran Alon <=
- [PATCH v2 05/16] hw/i386/vmport: Introduce vmx-version property, Liran Alon, 2020/03/10
- [PATCH v2 06/16] hw/i386/vmport: Report VMX type in CMD_GETVERSION, Liran Alon, 2020/03/10
- [PATCH v2 07/16] hw/i386/vmport: Introduce vmport.h, Liran Alon, 2020/03/10
- [PATCH v2 09/16] hw/i386/vmport: Add support for CMD_GETBIOSUUID, Liran Alon, 2020/03/10
- [PATCH v2 10/16] hw/i386/vmport: Add support for CMD_GETTIME, Liran Alon, 2020/03/10
- [PATCH v2 11/16] hw/i386/vmport: Add support for CMD_GETTIMEFULL, Liran Alon, 2020/03/10
- [PATCH v2 12/16] hw/i386/vmport: Add support for CMD_GET_VCPU_INFO, Liran Alon, 2020/03/10
- [PATCH v2 13/16] hw/i386/vmport: Allow x2apic without IR, Liran Alon, 2020/03/10
- [PATCH v2 14/16] i386/cpu: Store LAPIC bus frequency in CPU structure, Liran Alon, 2020/03/10
- [PATCH v2 15/16] hw/i386/vmport: Add support for CMD_GETHZ, Liran Alon, 2020/03/10