[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 07/23] target-mips: Fix RDHWR exception host PC
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH v2 07/23] target-mips: Fix RDHWR exception host PC |
Date: |
Mon, 9 May 2016 13:07:51 +0100 |
From: James Hogan <address@hidden>
Commit b00c72180c36 ("target-mips: add PC, XNP reg numbers to RDHWR")
changed the rdhwr helpers to use check_hwrena() to check the register
being accessed is enabled in CP0_HWREna when used from user mode. If
that check fails an EXCP_RI exception is raised at the host PC
calculated with GETPC().
However check_hwrena() may not be fully inlined as the
do_raise_exception() part of it is common regardless of the arguments.
This causes GETPC() to calculate the address in the call in the helper
instead of the generated code calling the helper. No TB will be found
and the EPC reported with the resulting guest RI exception points to the
beginning of the TB instead of the RDHWR instruction.
We can't reliably force check_hwrena() to be inlined, and converting it
to a macro would be ugly, so instead pass the host PC in as an argument,
with each rdhwr helper passing GETPC(). This should avoid any dependence
on compiler behaviour, and in practice seems to ensure the full inlining
of check_hwrena() on x86_64.
This issue causes failures when running a MIPS KVM (trap & emulate)
guest in a MIPS QEMU TCG guest, as the inner guest kernel will do a
RDHWR of counter, which is disabled in the outer guest's CP0_HWREna by
KVM so it can emulate the inner guest's counter. The emulation fails and
the RI exception is passed to the inner guest.
Fixes: b00c72180c36 ("target-mips: add PC, XNP reg numbers to RDHWR")
Signed-off-by: James Hogan <address@hidden>
Cc: Leon Alrae <address@hidden>
Cc: Yongbok Kim <address@hidden>
Cc: Aurelien Jarno <address@hidden>
Reviewed-by: Aurelien Jarno <address@hidden>
Reviewed-by: Leon Alrae <address@hidden>
Signed-off-by: Leon Alrae <address@hidden>
---
target-mips/op_helper.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/target-mips/op_helper.c b/target-mips/op_helper.c
index 8ec1bef..4417e6b 100644
--- a/target-mips/op_helper.c
+++ b/target-mips/op_helper.c
@@ -2294,29 +2294,29 @@ void helper_deret(CPUMIPSState *env)
}
#endif /* !CONFIG_USER_ONLY */
-static inline void check_hwrena(CPUMIPSState *env, int reg)
+static inline void check_hwrena(CPUMIPSState *env, int reg, uintptr_t pc)
{
if ((env->hflags & MIPS_HFLAG_CP0) || (env->CP0_HWREna & (1 << reg))) {
return;
}
- do_raise_exception(env, EXCP_RI, GETPC());
+ do_raise_exception(env, EXCP_RI, pc);
}
target_ulong helper_rdhwr_cpunum(CPUMIPSState *env)
{
- check_hwrena(env, 0);
+ check_hwrena(env, 0, GETPC());
return env->CP0_EBase & 0x3ff;
}
target_ulong helper_rdhwr_synci_step(CPUMIPSState *env)
{
- check_hwrena(env, 1);
+ check_hwrena(env, 1, GETPC());
return env->SYNCI_Step;
}
target_ulong helper_rdhwr_cc(CPUMIPSState *env)
{
- check_hwrena(env, 2);
+ check_hwrena(env, 2, GETPC());
#ifdef CONFIG_USER_ONLY
return env->CP0_Count;
#else
@@ -2326,19 +2326,19 @@ target_ulong helper_rdhwr_cc(CPUMIPSState *env)
target_ulong helper_rdhwr_ccres(CPUMIPSState *env)
{
- check_hwrena(env, 3);
+ check_hwrena(env, 3, GETPC());
return env->CCRes;
}
target_ulong helper_rdhwr_performance(CPUMIPSState *env)
{
- check_hwrena(env, 4);
+ check_hwrena(env, 4, GETPC());
return env->CP0_Performance0;
}
target_ulong helper_rdhwr_xnp(CPUMIPSState *env)
{
- check_hwrena(env, 5);
+ check_hwrena(env, 5, GETPC());
return (env->CP0_Config5 >> CP0C5_XNP) & 1;
}
--
2.5.5
- [Qemu-devel] [PATCH v2 00/23] libqos: use standard virtio headers, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 01/23] hw/ppc/spapr: Fix crash when specifying bad parameters to spapr-pci-host-bridge, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 02/23] usb/uhci: move pid check, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 03/23] spapr_drc: fix aborts during DRC-count based hotplug, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 04/23] QemuOpts: Fix qemu_opts_foreach() dangling location regression, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 10/23] vvfat: Fix volume name assertion, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 07/23] target-mips: Fix RDHWR exception host PC,
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH v2 11/23] vvfat: Fix default volume label, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 12/23] acpi: fix bios linker loadder COMMAND_ALLOCATE on bigendian host, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 09/23] qapi: Don't pass NULL to printf in string input visitor, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 13/23] configure: Check if struct fsxattr is available from linux header, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 15/23] Update version for v2.6.0-rc4 release, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 14/23] Revert "acpi: mark PMTIMER as unlocked", Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 18/23] libqos: drop duplicated virtio_config.h definitions, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 17/23] libqos: drop duplicated PCI vendor ID definition, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 19/23] libqos: drop duplicated virtio_ring.h bit definitions, Stefan Hajnoczi, 2016/05/09
- [Qemu-devel] [PATCH v2 16/23] libqos: use virtio_ids.h for device ID definitions, Stefan Hajnoczi, 2016/05/09