@@ -122,6 +122,7 @@ static void *mttcg_cpu_thread_fn(void *arg)
bql_unlock();
rcu_remove_force_rcu_notifier(&force_rcu.notifier);
rcu_unregister_thread();
+ tcg_unregister_thread();
return NULL;
}
@@ -51,6 +51,13 @@ void tcg_register_thread(void);
void tcg_register_thread(CPUState *cpu);
#endif
+/**
+ * tcg_unregister_thread: Unregister this thread with the TCG runtime
+ *
+ * This leg shall be called whenever TCG vCPU is hot-unplugged
+ */
+void tcg_unregister_thread(void);
+
/**
* tcg_prologue_init(): Generate the code for the TCG prologue
*
@@ -811,6 +811,39 @@ void tcg_register_thread(CPUState *cpu)
tcg_ctx = s;
}
+
+static void tcg_free_plugin_context(TCGContext *s)
+{
+#ifdef CONFIG_PLUGIN
+ unsigned i;
+
+ if (s->plugin_tb) {
+ for (i = 0; i < s->plugin_tb->insns->len; i++) {
+ g_free(g_ptr_array_index(s->plugin_tb->insns, i));
+ }
+ g_ptr_array_free(s->plugin_tb->insns, TRUE);
+
+ if (!s->plugin_tb->insns) {
+ g_free(s->plugin_tb);
+ }
+ }
+#endif
+}
+
+void tcg_unregister_thread(void)
+{
+ TCGContext *s = tcg_ctx;
+ unsigned int n;
+
+ /* unclaim an entry in tcg_ctxs */
+ n = qatomic_fetch_dec(&tcg_cur_ctxs);
+ g_assert(n > 1);
+ qatomic_store_release(&tcg_ctxs[n - 1], 0);
+
+ tcg_free_plugin_context(s);
+
+ g_free(s);
+}
#endif /* !CONFIG_USER_ONLY */
/* pool based memory allocation */