Skip to contentSkip to conversation

cpu-exec: Fix direct jump to TB spanning page

PATCH Applied Sergey Fedorov 5 participants 6 messages May 16, 2016 – May 26, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpu-exec: Fix direct jump to TB spanning page

From: Sergey Fedorov <[email protected]>

It is not safe to make a direct jump to a TB spanning two pages in system emulation because the mapping for the second page can get changed but we don't take care of direct jumps in this case.

However in user mode emulation, this is not the case because there's only static address translation and TBs are always invalidated properly.

Fixes 5b053a4a2827 ("tcg: Clean up direct block chaining safety checks")
---
 cpu-exec.c | 9 +++++++++
 1 file changed, 9 insertions(+)
cpu-exec.c +9 -0
index 14df1aacf42a..ec2364df624d 100644
@@ -344,6 +344,15 @@ static inline TranslationBlock *tb_find_fast(CPUState *cpu,
         *last_tb = NULL;
         cpu->tb_flushed = false;
     }
+#ifndef CONFIG_USER_ONLY
+    /* We don't take care of direct jumps when address mapping changes in
+     * system emulation. So it's not safe to make a direct jump to a TB
+     * spanning two pages because the mapping for the second page can change.
+     */
+    if (tb->page_addr[1] != -1) {
+        *last_tb = NULL;
+    }
+#endif
     /* See if we can patch the calling TB. */
     if (*last_tb && !qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) {
         tb_add_jump(*last_tb, tb_exit, tb);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 3 lines · Sergey Fedorov

It is not safe to make a direct jump to a TB spanning two pages in system emulation because the mapping for the second page can get changed but we don't take care of direct jumps in this case.

We don't? I'm pretty sure that we do...

r~

#2 lore raw
Quoted 5 lines · Richard Henderson
Quoted 3 lines · Sergey Fedorov

It is not safe to make a direct jump to a TB spanning two pages in system emulation because the mapping for the second page can get changed but we don't take care of direct jumps in this case.

We don't? I'm pretty sure that we do...

What we just do is flushing the CPU virtual address cache, see for tlb_flush() etc.

Kind regards,
Sergey

#3 lore raw
Quoted 8 lines · Sergey Fedorov
Quoted 5 lines · Richard Henderson
Quoted 3 lines · Sergey Fedorov

It is not safe to make a direct jump to a TB spanning two pages in system emulation because the mapping for the second page can get changed but we don't take care of direct jumps in this case.

We don't? I'm pretty sure that we do...

What we just do is flushing the CPU virtual address cache, see for tlb_flush() etc.

Ping. This patch fixed a bug discussed in this thread:
http://thread.gmane.org/gmane.comp.emulators.qemu/411648

Kind regards,
Sergey

#4 lore raw
Quoted 6 lines · Sergey Fedorov
Quoted 5 lines · Sergey Fedorov
Quoted 4 lines · Richard Henderson
Quoted 3 lines · Sergey Fedorov

It is not safe to make a direct jump to a TB spanning two pages in system emulation because the mapping for the second page can get changed but we don't take care of direct jumps in this case.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

We don't? I'm pretty sure that we do...

What we just do is flushing the CPU virtual address cache, see for tlb_flush() etc.

Ping. This patch fixed a bug discussed in this thread:
http://thread.gmane.org/gmane.comp.emulators.qemu/411648

Applied to master, thanks.

-- PMM

Tested-by on v1 1/1
#5 lore raw
In reply to Sergey Fedorov
Quoted 9 lines · Sergey Fedorov

From: Sergey Fedorov <[email protected]>

It is not safe to make a direct jump to a TB spanning two pages in system emulation because the mapping for the second page can get changed but we don't take care of direct jumps in this case.

However in user mode emulation, this is not the case because there's only static address translation and TBs are always invalidated properly.

Quoted 8 lines
Fixes 5b053a4a2827 ("tcg: Clean up direct block chaining safety checks")
---
 cpu-exec.c | 9 +++++++++
 1 file changed, 9 insertions(+)
Signature · 2 lines
Thanks.
-- Max