[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 07/21] target/i386: allow access_ptr to force slow path on fai
From: |
Alex Bennée |
Subject: |
[PATCH v2 07/21] target/i386: allow access_ptr to force slow path on failed probe |
Date: |
Tue, 13 Aug 2024 21:23:15 +0100 |
When we are using TCG plugin memory callbacks probe_access_internal
will return TLB_MMIO to force the slow path for memory access. This
results in probe_access returning NULL but the x86 access_ptr function
happily accepts an empty haddr resulting in segfault hilarity.
Check for an empty haddr to prevent the segfault and enable plugins to
track all the memory operations for the x86 save/restore helpers. As
we also want to run the slow path when instrumenting *-user we should
also not have the short cutting test_ptr macro.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2489
Fixes: 6d03226b42 (plugins: force slow path when plugins instrument memory ops)
Reviewed-by: Alexandre Iooss <erdnaxe@crans.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20240807160236.2478459-1-alex.bennee@linaro.org>
---
v2
- add comment around haddr1 test
- drop test_ptr macro
---
target/i386/tcg/access.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/target/i386/tcg/access.c b/target/i386/tcg/access.c
index 56a1181ea5..e68b73a24b 100644
--- a/target/i386/tcg/access.c
+++ b/target/i386/tcg/access.c
@@ -58,6 +58,11 @@ static void *access_ptr(X86Access *ac, vaddr addr, unsigned
len)
assert(addr >= ac->vaddr);
+ /* No haddr means probe_access wants to force slow path */
+ if (!ac->haddr1) {
+ return NULL;
+ }
+
#ifdef CONFIG_USER_ONLY
assert(offset <= ac->size1 - len);
return ac->haddr1 + offset;
@@ -78,17 +83,11 @@ static void *access_ptr(X86Access *ac, vaddr addr, unsigned
len)
#endif
}
-#ifdef CONFIG_USER_ONLY
-# define test_ptr(p) true
-#else
-# define test_ptr(p) likely(p)
-#endif
-
uint8_t access_ldb(X86Access *ac, vaddr addr)
{
void *p = access_ptr(ac, addr, sizeof(uint8_t));
- if (test_ptr(p)) {
+ if (likely(p)) {
return ldub_p(p);
}
return cpu_ldub_mmuidx_ra(ac->env, addr, ac->mmu_idx, ac->ra);
@@ -98,7 +97,7 @@ uint16_t access_ldw(X86Access *ac, vaddr addr)
{
void *p = access_ptr(ac, addr, sizeof(uint16_t));
- if (test_ptr(p)) {
+ if (likely(p)) {
return lduw_le_p(p);
}
return cpu_lduw_le_mmuidx_ra(ac->env, addr, ac->mmu_idx, ac->ra);
@@ -108,7 +107,7 @@ uint32_t access_ldl(X86Access *ac, vaddr addr)
{
void *p = access_ptr(ac, addr, sizeof(uint32_t));
- if (test_ptr(p)) {
+ if (likely(p)) {
return ldl_le_p(p);
}
return cpu_ldl_le_mmuidx_ra(ac->env, addr, ac->mmu_idx, ac->ra);
@@ -118,7 +117,7 @@ uint64_t access_ldq(X86Access *ac, vaddr addr)
{
void *p = access_ptr(ac, addr, sizeof(uint64_t));
- if (test_ptr(p)) {
+ if (likely(p)) {
return ldq_le_p(p);
}
return cpu_ldq_le_mmuidx_ra(ac->env, addr, ac->mmu_idx, ac->ra);
@@ -128,7 +127,7 @@ void access_stb(X86Access *ac, vaddr addr, uint8_t val)
{
void *p = access_ptr(ac, addr, sizeof(uint8_t));
- if (test_ptr(p)) {
+ if (likely(p)) {
stb_p(p, val);
} else {
cpu_stb_mmuidx_ra(ac->env, addr, val, ac->mmu_idx, ac->ra);
@@ -139,7 +138,7 @@ void access_stw(X86Access *ac, vaddr addr, uint16_t val)
{
void *p = access_ptr(ac, addr, sizeof(uint16_t));
- if (test_ptr(p)) {
+ if (likely(p)) {
stw_le_p(p, val);
} else {
cpu_stw_le_mmuidx_ra(ac->env, addr, val, ac->mmu_idx, ac->ra);
@@ -150,7 +149,7 @@ void access_stl(X86Access *ac, vaddr addr, uint32_t val)
{
void *p = access_ptr(ac, addr, sizeof(uint32_t));
- if (test_ptr(p)) {
+ if (likely(p)) {
stl_le_p(p, val);
} else {
cpu_stl_le_mmuidx_ra(ac->env, addr, val, ac->mmu_idx, ac->ra);
@@ -161,7 +160,7 @@ void access_stq(X86Access *ac, vaddr addr, uint64_t val)
{
void *p = access_ptr(ac, addr, sizeof(uint64_t));
- if (test_ptr(p)) {
+ if (likely(p)) {
stq_le_p(p, val);
} else {
cpu_stq_le_mmuidx_ra(ac->env, addr, val, ac->mmu_idx, ac->ra);
--
2.39.2
- [PATCH v2 00/21] Various fixes and tweaks for 9.1-rc2/3, Alex Bennée, 2024/08/13
- [PATCH v2 02/21] Makefile: trigger re-configure on updated pythondeps, Alex Bennée, 2024/08/13
- [PATCH v2 04/21] configure: Avoid use of param. expansion when using gdb_version, Alex Bennée, 2024/08/13
- [PATCH v2 01/21] tests/avocado: Re-enable gdbsim-r5f562n8 testing U-Boot, Alex Bennée, 2024/08/13
- [PATCH v2 06/21] scripts/checkpatch: more checks on files imported from Linux, Alex Bennée, 2024/08/13
- [PATCH v2 05/21] configure: Fix GDB version detection for GDB_HAS_MTE, Alex Bennée, 2024/08/13
- [PATCH v2 03/21] configure: Fix arch detection for GDB_HAS_MTE, Alex Bennée, 2024/08/13
- [PATCH v2 08/21] buildsys: Fix building without plugins on Darwin, Alex Bennée, 2024/08/13
- [PATCH v2 09/21] scripts/replay-dump.py: Update to current rr record format, Alex Bennée, 2024/08/13
- [PATCH v2 07/21] target/i386: allow access_ptr to force slow path on failed probe,
Alex Bennée <=
- [PATCH v2 11/21] tests/avocado: excercise scripts/replay-dump.py in replay tests, Alex Bennée, 2024/08/13
- [PATCH v2 14/21] tests/avocado: replay_kernel.py add x86-64 q35 machine test, Alex Bennée, 2024/08/13
- [PATCH v2 12/21] replay: allow runstate shutdown->running when replaying trace, Alex Bennée, 2024/08/13
- [PATCH v2 13/21] Revert "replay: stop us hanging in rr_wait_io_event", Alex Bennée, 2024/08/13
- [PATCH v2 16/21] virtio-net: Use replay_schedule_bh_event for bhs that affect machine state, Alex Bennée, 2024/08/13