[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 01/14] hw/i386/vmport: Propagate IOPort read to vCPU EAX register
From: |
Liran Alon |
Subject: |
[PATCH 01/14] hw/i386/vmport: Propagate IOPort read to vCPU EAX register |
Date: |
Tue, 10 Mar 2020 01:53:58 +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/i386/vmport.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/hw/i386/vmport.c b/hw/i386/vmport.c
index 1f31e27c8aa4..9319720e8204 100644
--- a/hw/i386/vmport.c
+++ b/hw/i386/vmport.c
@@ -72,25 +72,36 @@ 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.
+ */
+ cpu->env.regs[R_EAX] = eax;
+ return eax;
}
static void vmport_ioport_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
- X86CPU *cpu = X86_CPU(current_cpu);
-
- cpu->env.regs[R_EAX] = vmport_ioport_read(opaque, addr, 4);
+ vmport_ioport_read(opaque, addr, 4);
}
static uint32_t vmport_cmd_get_version(void *opaque, uint32_t addr)
--
2.20.1
- [PATCH 00/14]: hw/i386/vmport: Bug fixes and improvements, Liran Alon, 2020/03/09
- [PATCH 02/14] hw/i386/vmport: Set EAX to -1 on failed and unsupported commands, Liran Alon, 2020/03/09
- [PATCH 01/14] hw/i386/vmport: Propagate IOPort read to vCPU EAX register,
Liran Alon <=
- [PATCH 03/14] hw/i386/vmport: Add device properties, Liran Alon, 2020/03/09
- [PATCH 04/14] hw/i386/vmport: Introduce vmx-version property, Liran Alon, 2020/03/09
- Re: [PATCH 04/14] hw/i386/vmport: Introduce vmx-version property, Michael S. Tsirkin, 2020/03/10
- Re: [PATCH 04/14] hw/i386/vmport: Introduce vmx-version property, Liran Alon, 2020/03/10
- Re: [PATCH 04/14] hw/i386/vmport: Introduce vmx-version property, Michael S. Tsirkin, 2020/03/10
- Re: [PATCH 04/14] hw/i386/vmport: Introduce vmx-version property, Liran Alon, 2020/03/10
- Re: [PATCH 04/14] hw/i386/vmport: Introduce vmx-version property, Michael S. Tsirkin, 2020/03/10
- Re: [PATCH 04/14] hw/i386/vmport: Introduce vmx-version property, Liran Alon, 2020/03/10
[PATCH 05/14] hw/i386/vmport: Report VMX type in CMD_GETVERSION, Liran Alon, 2020/03/09