aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2019-11-04 13:18:36 +0000
committerAlex Bennée <alex.bennee@linaro.org>2019-11-12 14:32:55 +0000
commit3fb356cc86461a14450802e14fa79e8436dbbf31 (patch)
tree1fa66d329a0031fcdc7b7ac7117bdf921236a1d8
parent05273a43af5f9e71152ad1b877bc3a898857e989 (diff)
downloadqemu-3fb356cc86461a14450802e14fa79e8436dbbf31.tar.gz
tcg plugins: expose an API version concept
This is a very simple versioning API which allows the plugin infrastructure to check the API a plugin was built against. We also expose a min/cur API version to the plugin via the info block in case it wants to avoid using old deprecated APIs in the future. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Robert Foley <robert.foley@linaro.org>
-rw-r--r--include/qemu/qemu-plugin.h19
-rw-r--r--plugins/loader.c21
-rw-r--r--plugins/plugin.h2
-rw-r--r--tests/plugin/bb.c2
-rw-r--r--tests/plugin/empty.c2
-rw-r--r--tests/plugin/hotblocks.c2
-rw-r--r--tests/plugin/hotpages.c2
-rw-r--r--tests/plugin/howvec.c2
-rw-r--r--tests/plugin/insn.c2
-rw-r--r--tests/plugin/mem.c2
10 files changed, 56 insertions, 0 deletions
diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
index a00a7deb461..5502e112c81 100644
--- a/include/qemu/qemu-plugin.h
+++ b/include/qemu/qemu-plugin.h
@@ -38,9 +38,28 @@
typedef uint64_t qemu_plugin_id_t;
+/*
+ * Versioning plugins:
+ *
+ * The plugin API will pass a minimum and current API version that
+ * QEMU currently supports. The minimum API will be incremented if an
+ * API needs to be deprecated.
+ *
+ * The plugins export the API they were built against by exposing the
+ * symbol qemu_plugin_version which can be checked.
+ */
+
+extern QEMU_PLUGIN_EXPORT int qemu_plugin_version;
+
+#define QEMU_PLUGIN_VERSION 0
+
typedef struct {
/* string describing architecture */
const char *target_name;
+ struct {
+ int min;
+ int cur;
+ } version;
/* is this a full system emulation? */
bool system_emulation;
union {
diff --git a/plugins/loader.c b/plugins/loader.c
index ce724ed5839..15fc7e55156 100644
--- a/plugins/loader.c
+++ b/plugins/loader.c
@@ -178,6 +178,25 @@ static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info)
goto err_symbol;
}
+ if (!g_module_symbol(ctx->handle, "qemu_plugin_version", &sym)) {
+ error_report("TCG plugin %s does not declare API version %s",
+ desc->path, g_module_error());
+ goto err_symbol;
+ } else {
+ int version = *(int *)sym;
+ if (version < QEMU_PLUGIN_MIN_VERSION) {
+ error_report("TCG plugin %s requires API version %d, but "
+ "this QEMU supports only a minimum version of %d",
+ desc->path, version, QEMU_PLUGIN_MIN_VERSION);
+ goto err_symbol;
+ } else if (version > QEMU_PLUGIN_VERSION) {
+ error_report("TCG plugin %s requires API version %d, but "
+ "this QEMU supports only up to version %d",
+ desc->path, version, QEMU_PLUGIN_VERSION);
+ goto err_symbol;
+ }
+ }
+
qemu_rec_mutex_lock(&plugin.lock);
/* find an unused random id with &ctx as the seed */
@@ -248,6 +267,8 @@ int qemu_plugin_load_list(QemuPluginList *head)
g_autofree qemu_info_t *info = g_new0(qemu_info_t, 1);
info->target_name = TARGET_NAME;
+ info->version.min = QEMU_PLUGIN_MIN_VERSION;
+ info->version.cur = QEMU_PLUGIN_VERSION;
#ifndef CONFIG_USER_ONLY
MachineState *ms = MACHINE(qdev_get_machine());
info->system_emulation = true;
diff --git a/plugins/plugin.h b/plugins/plugin.h
index 5482168d797..1aa29dcaddf 100644
--- a/plugins/plugin.h
+++ b/plugins/plugin.h
@@ -14,6 +14,8 @@
#include <gmodule.h>
+#define QEMU_PLUGIN_MIN_VERSION 0
+
/* global state */
struct qemu_plugin_state {
QTAILQ_HEAD(, qemu_plugin_ctx) ctxs;
diff --git a/tests/plugin/bb.c b/tests/plugin/bb.c
index 45e1de5bd68..f30bea08dcc 100644
--- a/tests/plugin/bb.c
+++ b/tests/plugin/bb.c
@@ -14,6 +14,8 @@
#include <qemu-plugin.h>
+QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
+
static uint64_t bb_count;
static uint64_t insn_count;
static bool do_inline;
diff --git a/tests/plugin/empty.c b/tests/plugin/empty.c
index 3f60f690278..8fa6bacd93d 100644
--- a/tests/plugin/empty.c
+++ b/tests/plugin/empty.c
@@ -13,6 +13,8 @@
#include <qemu-plugin.h>
+QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
+
/*
* Empty TB translation callback.
* This allows us to measure the overhead of injecting and then
diff --git a/tests/plugin/hotblocks.c b/tests/plugin/hotblocks.c
index 1bd183849a1..3942a2ca544 100644
--- a/tests/plugin/hotblocks.c
+++ b/tests/plugin/hotblocks.c
@@ -15,6 +15,8 @@
#include <qemu-plugin.h>
+QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
+
static bool do_inline;
/* Plugins need to take care of their own locking */
diff --git a/tests/plugin/hotpages.c b/tests/plugin/hotpages.c
index 77df07a3ccf..ecd6c187327 100644
--- a/tests/plugin/hotpages.c
+++ b/tests/plugin/hotpages.c
@@ -18,6 +18,8 @@
#include <qemu-plugin.h>
+QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
+
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
static uint64_t page_size = 4096;
diff --git a/tests/plugin/howvec.c b/tests/plugin/howvec.c
index 58fa675e348..4ca555e1239 100644
--- a/tests/plugin/howvec.c
+++ b/tests/plugin/howvec.c
@@ -20,6 +20,8 @@
#include <qemu-plugin.h>
+QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
+
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
typedef enum {
diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c
index e5fd07fb64b..0a8f5a0000e 100644
--- a/tests/plugin/insn.c
+++ b/tests/plugin/insn.c
@@ -14,6 +14,8 @@
#include <qemu-plugin.h>
+QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
+
static uint64_t insn_count;
static bool do_inline;
diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c
index d9673889896..878abf09d19 100644
--- a/tests/plugin/mem.c
+++ b/tests/plugin/mem.c
@@ -14,6 +14,8 @@
#include <qemu-plugin.h>
+QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
+
static uint64_t mem_count;
static uint64_t io_count;
static bool do_inline;