From patchwork Tue Nov 12 14:50:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 179207 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp8230362ilf; Tue, 12 Nov 2019 07:00:04 -0800 (PST) X-Google-Smtp-Source: APXvYqz205vu4x4a+NwFwRm5Fgb4M/ydCgEMaff3TBoGalRf+RUVbE9YGg/dEIb7g5EHvT91wXw3 X-Received: by 2002:ae9:e404:: with SMTP id q4mr1144445qkc.365.1573570804324; Tue, 12 Nov 2019 07:00:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573570804; cv=none; d=google.com; s=arc-20160816; b=uSCDQa6GOX4Nl5RgDznG/Odi0qdIETcxpU8rE7ZxtPypmcEPewsVc2JtUaslCj+7/j CCquni+tMgjOrVbVC7HNrPUUEsrymSTRNZF+9AwzfLgNu9uTfOJZxIa147HGzx/b+8rW whdqezH5P+p5B44UM0tXAEfIkIoklnluB+voHH081Cm9yR+BmaFOE7d8wzQuwUL7sEnG iV9Nv1vtrxwOH3EzVX18b+sSND4PmETkcUcw7GrY1e9HcoriYaILu3aO1If6Ws93lQfy 5sBLwVP2sjmvk98HtZtPK2DqvseK9mDlmpHHRSI66KInAXNF+LZtPjPZssV5UgMgEKjV qLSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=gqg0+V7qSEz/6ZJOKa53BGZgGZ5jVCsKocXvLtTyKDM=; b=j4ZNgxr3n5Q5pdVSUErw0GP+MH/FyxakrelFEV/MtYB9O9vpV6irNZjM5E3oZDfshU x7sHmTkSnKTWS5eyoIPwk0H4Aj6KiHeGBfdfrNEPXlOhZLgD05DXYwpPEVt9Z8Fp5jWF 2fnnrvujL9DfcO/ySNrc1YQ9bWekP6Hq639jtXSksLe1oqTjm5B4Fp+WpbVqQOUq433D vV6ZguZAA9A96zwF9N7AZUJbjzt+wC72keCbrdt5ETv8cwtywt2FCSxrOcKPaDb1Cwg2 DmuRm7M9AfZg27SVQ/PBL6ibElRXf8P1SKTrHJMhKq0DfxBWKjA/qmb7VK2vyX2P7yr8 +btA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="cGi/Yk2C"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n135si5993982qka.216.2019.11.12.07.00.04 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Nov 2019 07:00:04 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="cGi/Yk2C"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUXeF-0004o5-Rr for patch@linaro.org; Tue, 12 Nov 2019 10:00:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59785) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUXVD-0003ZW-W8 for qemu-devel@nongnu.org; Tue, 12 Nov 2019 09:50:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUXVC-00037p-8J for qemu-devel@nongnu.org; Tue, 12 Nov 2019 09:50:43 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:39964) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iUXVC-00036t-1a for qemu-devel@nongnu.org; Tue, 12 Nov 2019 09:50:42 -0500 Received: by mail-wr1-x436.google.com with SMTP id i10so18836240wrs.7 for ; Tue, 12 Nov 2019 06:50:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gqg0+V7qSEz/6ZJOKa53BGZgGZ5jVCsKocXvLtTyKDM=; b=cGi/Yk2CehzucHabB93Ij5kZCzQJ+6MYYNgNxLnbbXlH1Xas/XnGWoNE1xyU4B47Yu jQF7Flaw8Fo+yemlkVPYqChTV3FQ2ESyGiYRSjhUoQX2TUJDJItAqzkbJij2i2KBn7Or V5XW8EGDij7u/M56tYBlsGkUNsx3XF7mzuGUkFWlme1Z8pMPwJVQIR6KWCGWbrWAbWmT 1jbx5pr3Y1m900INehVbJT+/cgakEEKyfyjhdKiK25kw7kY1cPGmzvyV5wLVlYNJzoDI A9TpjVMeEgUm6Xw7dI0btutPKNJGDsP/tiJN6wctHaXNC1QQ7Qx6yqVVct364PABxGTO AXxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gqg0+V7qSEz/6ZJOKa53BGZgGZ5jVCsKocXvLtTyKDM=; b=M7CfognzxmkuaSaaDXTUbJxabheJXP1csQ1WAmjfaC3qNtI18wbJc1EwRNygA3snGr XzI7xdgTKu1UkvSnMIIA1jP486CF/rh54OTs2FweNBPia4UTwkHGYXIyIoYTPz9UNxI9 u/3WgyoZQLpjh6ZemhvkX6E0X76KqMb0MhAq8MqIQGz14dyOzzeGYbZzxMc1KTEP0Tqo lVBP5NRFpt163fTmy9eL390sAedLmd0Fo34sktNAIjiUIQVIdP+jusPmbogJuGxVu+dl GyMXRehkdBkVIzVSWG/1WuQE7XgDun1mde1vaIFR5w3ky+aX9RyFKi+YArRPq6bVhgtK W0iQ== X-Gm-Message-State: APjAAAUQ5/nnqnSKqbNnplCH6oB6QieqUzLX1yjQpIKLLvQxbZkW80Bh HK+40PokclhHMXvsOYvaFEO3Aw== X-Received: by 2002:adf:979a:: with SMTP id s26mr21423502wrb.92.1573570240901; Tue, 12 Nov 2019 06:50:40 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l4sm3185204wme.4.2019.11.12.06.50.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2019 06:50:35 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C31801FF98; Tue, 12 Nov 2019 14:50:29 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 8/8] tcg plugins: expose an API version concept Date: Tue, 12 Nov 2019 14:50:28 +0000 Message-Id: <20191112145028.26386-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191112145028.26386-1-alex.bennee@linaro.org> References: <20191112145028.26386-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::436 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Robert Foley Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Maydell Reviewed-by: Robert Foley -- 2.20.1 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 +#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_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_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_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_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_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_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_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; + static uint64_t mem_count; static uint64_t io_count; static bool do_inline;