public inbox for qemu-arm@nongnu.org
 help / color / mirror / Atom feed
From: Ruslan Ruslichenko <ruslichenko.r@gmail.com>
To: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org, artem_mygaiev@epam.com,
	volodymyr_babchuk@epam.com, alex.bennee@linaro.org,
	peter.maydell@linaro.org, pierrick.bouvier@linaro.org,
	philmd@linaro.org, Ruslan_Ruslichenko@epam.com
Subject: [RFC PATCH 3/9] plugins: Expose Transaction Block cache flush API to plugins
Date: Wed, 18 Mar 2026 11:46:34 +0100	[thread overview]
Message-ID: <20260318104640.239752-4-ruslichenko.r@gmail.com> (raw)
In-Reply-To: <20260318104640.239752-1-ruslichenko.r@gmail.com>

From: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>

The patch introduces qemu_plugin_flush_tb_cache() to the plugin API,
allowing plugins to invalidate QEMU translate code cache.

If a plugin needs to dynamically register a new instruction or memory
callback, the new hooks may not be triggered for code blocks that
QEMU has already translated and cached. This API allows QEMU
re-translate TB, so that new applied hooks will take effect.

Signed-off-by: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>
---
 include/plugins/qemu-plugin.h |  3 +++
 plugins/api.c                 |  6 ++++++
 plugins/core.c                | 11 +++++++++++
 plugins/plugin.h              |  2 ++
 4 files changed, 22 insertions(+)

diff --git a/include/plugins/qemu-plugin.h b/include/plugins/qemu-plugin.h
index bbd21e79c5..a68427536f 100644
--- a/include/plugins/qemu-plugin.h
+++ b/include/plugins/qemu-plugin.h
@@ -1246,6 +1246,9 @@ void qemu_plugin_u64_set(qemu_plugin_u64 entry, unsigned int vcpu_index,
 QEMU_PLUGIN_API
 uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry);
 
+QEMU_PLUGIN_API
+void qemu_plugin_flush_tb_cache(void);
+
 QEMU_PLUGIN_API
 uint64_t qemu_plugin_get_virtual_clock_ns(void);
 
diff --git a/plugins/api.c b/plugins/api.c
index 609ea69293..fa650e1219 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -653,6 +653,12 @@ uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry)
     return total;
 }
 
+QEMU_PLUGIN_API
+void qemu_plugin_flush_tb_cache(void)
+{
+    plugin_flush_tb_cache();
+}
+
 typedef struct {
     void (*cb)(void *opaque);
     void* opaque;
diff --git a/plugins/core.c b/plugins/core.c
index 42fd986593..462f4bae81 100644
--- a/plugins/core.c
+++ b/plugins/core.c
@@ -21,6 +21,7 @@
 #include "qemu/rcu.h"
 #include "exec/tb-flush.h"
 #include "tcg/tcg-op-common.h"
+#include "qemu/main-loop.h"
 #include "plugin.h"
 
 struct qemu_plugin_cb {
@@ -888,3 +889,13 @@ enum qemu_plugin_cb_flags tcg_call_to_qemu_plugin_cb_flags(int flags)
         return QEMU_PLUGIN_CB_RW_REGS;
     }
 }
+
+void plugin_flush_tb_cache(void)
+{
+    CPUState *cpu = qemu_get_cpu(0);
+    if (cpu) {
+        queue_tb_flush(cpu);
+
+        qemu_cpu_kick(cpu);
+    }
+}
diff --git a/plugins/plugin.h b/plugins/plugin.h
index 6fbc443b96..0bf819536b 100644
--- a/plugins/plugin.h
+++ b/plugins/plugin.h
@@ -125,4 +125,6 @@ void plugin_scoreboard_free(struct qemu_plugin_scoreboard *score);
  */
 void qemu_plugin_fillin_mode_info(qemu_info_t *info);
 
+void plugin_flush_tb_cache(void);
+
 #endif /* PLUGIN_H */
-- 
2.43.0



  parent reply	other threads:[~2026-03-18 10:48 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18 10:46 [RFC PATCH 0/9] plugins: Introduce Fault Injection framework and API extensions Ruslan Ruslichenko
2026-03-18 10:46 ` [RFC PATCH 1/9] target/arm: Add API for dynamic exception injection Ruslan Ruslichenko
2026-03-18 10:46 ` [RFC PATCH 2/9] plugins/api: Expose virtual clock timers to plugins Ruslan Ruslichenko
2026-03-18 10:46 ` Ruslan Ruslichenko [this message]
2026-03-18 10:46 ` [RFC PATCH 4/9] plugins: Introduce fault injection API and core subsystem Ruslan Ruslichenko
2026-03-18 10:46 ` [RFC PATCH 5/9] system/memory: Add plugin callbacks to intercept MMIO accesses Ruslan Ruslichenko
2026-03-18 10:46 ` [RFC PATCH 6/9] hw/intc/arm_gic: Register primary GIC for plugin IRQ injection Ruslan Ruslichenko
2026-03-18 10:46 ` [RFC PATCH 7/9] hw/arm/smmuv3: Add plugin fault handler for CMDQ errors Ruslan Ruslichenko
2026-03-18 10:46 ` [RFC PATCH 8/9] contrib/plugins: Add fault injection plugin Ruslan Ruslichenko
2026-03-18 10:46 ` [RFC PATCH 9/9] docs: Add description of fault-injection plugin and subsystem Ruslan Ruslichenko
2026-03-18 17:16 ` [RFC PATCH 0/9] plugins: Introduce Fault Injection framework and API extensions Pierrick Bouvier
2026-03-19 18:20   ` Ruslan Ruslichenko
2026-03-19 19:04     ` Pierrick Bouvier
2026-03-19 22:29       ` Ruslan Ruslichenko
2026-03-20 18:08         ` Pierrick Bouvier
2026-03-25 23:39           ` Ruslan Ruslichenko
2026-03-26  0:17             ` Pierrick Bouvier
2026-03-26 11:45               ` Alex Bennée
2026-03-26 15:59                 ` Pierrick Bouvier
2026-03-27 18:18                   ` Pierrick Bouvier
2026-03-31 20:23                     ` Ruslan Ruslichenko
2026-03-31 21:24                       ` Pierrick Bouvier

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=20260318104640.239752-4-ruslichenko.r@gmail.com \
    --to=ruslichenko.r@gmail.com \
    --cc=Ruslan_Ruslichenko@epam.com \
    --cc=alex.bennee@linaro.org \
    --cc=artem_mygaiev@epam.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=volodymyr_babchuk@epam.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox