All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: iii@linux.ibm.com
Subject: [PATCH 1/4] accel/tcg: Fix tb_invalidate_phys_page_unwind
Date: Sat, 24 Dec 2022 07:18:18 -0800	[thread overview]
Message-ID: <20221224151821.464455-2-richard.henderson@linaro.org> (raw)
In-Reply-To: <20221224151821.464455-1-richard.henderson@linaro.org>

When called from syscall(), we are not within a TB and pc == 0.
We can skip the check for invalidating the current TB.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 accel/tcg/tb-maint.c | 78 ++++++++++++++++++++++++--------------------
 1 file changed, 43 insertions(+), 35 deletions(-)

diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c
index 1b8e860647..b3d6529ae2 100644
--- a/accel/tcg/tb-maint.c
+++ b/accel/tcg/tb-maint.c
@@ -1024,43 +1024,51 @@ void tb_invalidate_phys_page(tb_page_addr_t addr)
  */
 bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc)
 {
-    assert(pc != 0);
-#ifdef TARGET_HAS_PRECISE_SMC
-    assert_memory_lock();
-    {
-        TranslationBlock *current_tb = tcg_tb_lookup(pc);
-        bool current_tb_modified = false;
-        TranslationBlock *tb;
-        PageForEachNext n;
+    TranslationBlock *current_tb;
+    bool current_tb_modified;
+    TranslationBlock *tb;
+    PageForEachNext n;
 
-        addr &= TARGET_PAGE_MASK;
-
-        PAGE_FOR_EACH_TB(addr, addr + TARGET_PAGE_SIZE, unused, tb, n) {
-            if (current_tb == tb &&
-                (tb_cflags(current_tb) & CF_COUNT_MASK) != 1) {
-                /*
-                 * If we are modifying the current TB, we must stop its
-                 * execution. We could be more precise by checking that
-                 * the modification is after the current PC, but it would
-                 * require a specialized function to partially restore
-                 * the CPU state.
-                 */
-                current_tb_modified = true;
-                cpu_restore_state_from_tb(current_cpu, current_tb, pc);
-            }
-            tb_phys_invalidate__locked(tb);
-        }
-
-        if (current_tb_modified) {
-            /* Force execution of one insn next time.  */
-            CPUState *cpu = current_cpu;
-            cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
-            return true;
-        }
+    /*
+     * Without precise smc semantics, or when outside of a TB,
+     * we can skip to invalidate.
+     */
+#ifndef TARGET_HAS_PRECISE_SMC
+    pc = 0;
+#endif
+    if (!pc) {
+        tb_invalidate_phys_page(addr);
+        return false;
+    }
+
+    assert_memory_lock();
+    current_tb = tcg_tb_lookup(pc);
+
+    addr &= TARGET_PAGE_MASK;
+    current_tb_modified = false;
+
+    PAGE_FOR_EACH_TB(addr, addr + TARGET_PAGE_SIZE, unused, tb, n) {
+        if (current_tb == tb &&
+            (tb_cflags(current_tb) & CF_COUNT_MASK) != 1) {
+            /*
+             * If we are modifying the current TB, we must stop its
+             * execution. We could be more precise by checking that
+             * the modification is after the current PC, but it would
+             * require a specialized function to partially restore
+             * the CPU state.
+             */
+            current_tb_modified = true;
+            cpu_restore_state_from_tb(current_cpu, current_tb, pc);
+        }
+        tb_phys_invalidate__locked(tb);
+    }
+
+    if (current_tb_modified) {
+        /* Force execution of one insn next time.  */
+        CPUState *cpu = current_cpu;
+        cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
+        return true;
     }
-#else
-    tb_invalidate_phys_page(addr);
-#endif /* TARGET_HAS_PRECISE_SMC */
     return false;
 }
 #else
-- 
2.34.1



  reply	other threads:[~2022-12-24 15:19 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-24 15:18 [PATCH 0/4] accel/tcg: Fixes for user-only page tracking Richard Henderson
2022-12-24 15:18 ` Richard Henderson [this message]
2022-12-28 12:49   ` [PATCH 1a/4] accel/tcg: Fix tb_invalidate_phys_page_unwind Philippe Mathieu-Daudé
2022-12-28 12:49     ` [PATCH 1b/4] accel/tcg: Unindent tb_invalidate_phys_page_unwind Philippe Mathieu-Daudé
2022-12-28 12:52       ` Philippe Mathieu-Daudé
2022-12-28 12:52     ` [PATCH 1a/4] accel/tcg: Fix tb_invalidate_phys_page_unwind Philippe Mathieu-Daudé
2022-12-24 15:18 ` [PATCH 2/4] accel/tcg: Use g_free_rcu for user-exec interval trees Richard Henderson
2022-12-28  7:19   ` Philippe Mathieu-Daudé
2022-12-24 15:18 ` [PATCH 3/4] accel/tcg: Handle false negative lookup in page_check_range Richard Henderson
2022-12-28  7:24   ` Philippe Mathieu-Daudé
2022-12-28 12:53     ` Philippe Mathieu-Daudé
2022-12-28 17:36     ` Richard Henderson
2022-12-28 18:27       ` Philippe Mathieu-Daudé
2022-12-28 18:30         ` Richard Henderson
2022-12-28 18:53           ` Philippe Mathieu-Daudé
2022-12-24 15:18 ` [PATCH 4/4] tests/tcg/multiarch: add vma-pthread.c Richard Henderson
2022-12-27 17:23   ` Alex Bennée
2023-01-13 15:17   ` Peter Maydell
2023-01-13 17:10     ` Alex Bennée
2023-01-16 12:40       ` Philippe Mathieu-Daudé
2023-01-16 15:07         ` Peter Maydell
2023-01-16 16:27           ` Alex Bennée
2023-01-16 16:48             ` Peter Maydell
2023-01-16 17:09               ` Alex Bennée
2023-01-16 19:21             ` Richard Henderson
2023-01-20 14:58       ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221224151821.464455-2-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=iii@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.