From: "Alex Bennée" <alex.bennee@linaro.org>
To: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org,
maria.klimushenkova@ispras.ru, dovgaluk@ispras.ru,
pbonzini@redhat.com, vilanova@ac.upc.edu
Subject: Re: [Qemu-devel] [RFC PATCH v2 2/7] Add plugin support
Date: Fri, 07 Sep 2018 15:14:15 +0100 [thread overview]
Message-ID: <87mustz96w.fsf@linaro.org> (raw)
In-Reply-To: <152819516675.30857.9162557650483931182.stgit@pasha-ThinkPad-T60>
Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru> writes:
> This patch adds support for dynamically loaded plugins.
> Every plugin is a dynamic library with a set of optional exported
> functions that will be called from QEMU.
>
<snip>
> +
> +static QLIST_HEAD(, QemuPluginInfo) qemu_plugins
> + = QLIST_HEAD_INITIALIZER(qemu_plugins);
> +
> +static QemuOptsList qemu_plugin_opts = {
> + .name = "plugin",
> + .head = QTAILQ_HEAD_INITIALIZER(qemu_plugin_opts.head),
> + .desc = {
> + {
> + .name = "file",
> + .type = QEMU_OPT_STRING,
> + },{
> + .name = "args",
> + .type = QEMU_OPT_STRING,
> + },
> + { /* end of list */ }
> + },
> +};
> +
> +void qemu_plugin_parse_cmd_args(const char *optarg)
> +{
> + QemuOpts *opts = qemu_opts_parse_noisily(&qemu_plugin_opts, optarg, false);
> + qemu_plugin_load(qemu_opt_get(opts, "file"),
> + qemu_opt_get(opts, "args"));
> +}
Currently this is only available to system mode emulation. Can it be
extended to include linux-user as well?
> +
> +void qemu_plugin_load(const char *filename, const char *args)
> +{
> + GModule *g_module;
> + QemuPluginInfo *info = NULL;
> + if (!filename) {
> + error_report("plugin name was not specified");
> + return;
> + }
> + g_module = g_module_open(filename,
> + G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
> + if (!g_module) {
> + error_report("can't load plugin '%s'", filename);
> + return;
> + }
> + info = g_new0(QemuPluginInfo, 1);
> + info->filename = g_strdup(filename);
> + info->g_module = g_module;
> + if (args) {
> + info->args = g_strdup(args);
> + }
> +
> + g_module_symbol(g_module, "plugin_init", (gpointer*)&info->init);
> +
> + /* Get the instrumentation callbacks */
> + g_module_symbol(g_module, "plugin_needs_before_insn",
> + (gpointer*)&info->needs_before_insn);
> + g_module_symbol(g_module, "plugin_before_insn",
> + (gpointer*)&info->before_insn);
> +
> + QLIST_INSERT_HEAD(&qemu_plugins, info, next);
> +
> + return;
> +}
> +
> +void qemu_plugins_init(void)
> +{
> + QemuPluginInfo *info;
> + QLIST_FOREACH(info, &qemu_plugins, next) {
> + if (info->init) {
> + info->init(info->args);
> + }
> + }
> +}
> diff --git a/qemu-options.hx b/qemu-options.hx
> index c0d3951..d171544 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -3950,6 +3950,16 @@ Dump json-encoded vmstate information for current machine type to file
> in @var{file}
> ETEXI
>
> +#ifdef CONFIG_PLUGINS
> +DEF("plugin", HAS_ARG, QEMU_OPTION_plugin, \
> + "-plugin file=<file>[,args=<args>] load <dso> plugin with <args>\n", QEMU_ARCH_ALL)
> +STEXI
> +@item -plugin file=@var{file}[,args=@var{args}]
> +@findex -plugin
> +Load @var{file} plugin passing @var{args} arguments.
> +ETEXI
> +#endif
> +
> STEXI
> @end table
> ETEXI
> diff --git a/vl.c b/vl.c
> index 0603171..05420bf 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -129,6 +129,7 @@ int main(int argc, char **argv)
> #include "qapi/qapi-commands-run-state.h"
> #include "qapi/qmp/qerror.h"
> #include "sysemu/iothread.h"
> +#include "qemu/plugins.h"
>
> #define MAX_VIRTIO_CONSOLES 1
>
> @@ -3925,6 +3926,11 @@ int main(int argc, char **argv, char **envp)
> exit(1);
> }
> break;
> +#ifdef CONFIG_PLUGINS
> + case QEMU_OPTION_plugin:
> + qemu_plugin_parse_cmd_args(optarg);
> + break;
> +#endif
> case QEMU_OPTION_nodefconfig:
> case QEMU_OPTION_nouserconfig:
> /* Nothing to be parsed here. Especially, do not error out below. */
> @@ -4470,6 +4476,8 @@ int main(int argc, char **argv, char **envp)
> }
> parse_numa_opts(current_machine);
>
> + qemu_plugins_init();
> +
> /* do monitor/qmp handling at preconfig state if requested */
> main_loop();
>
--
Alex Bennée
next prev parent reply other threads:[~2018-09-07 14:14 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-05 10:39 [Qemu-devel] [RFC PATCH v2 0/7] QEMU binary instrumentation prototype Pavel Dovgalyuk
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 1/7] tcg: add headers for non-target helpers Pavel Dovgalyuk
2018-06-05 13:07 ` Thomas Huth
2018-06-06 7:30 ` Pavel Dovgalyuk
2018-09-07 12:16 ` Alex Bennée
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 2/7] Add plugin support Pavel Dovgalyuk
2018-09-07 10:11 ` Alex Bennée
2018-09-13 6:40 ` Pavel Dovgalyuk
2018-09-07 12:34 ` Alex Bennée
2018-09-10 8:30 ` Pavel Dovgalyuk
2018-09-07 14:14 ` Alex Bennée [this message]
2018-09-10 11:41 ` Pavel Dovgalyuk
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 3/7] plugins: provide helper functions for plugins Pavel Dovgalyuk
2018-09-07 13:06 ` Alex Bennée
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 4/7] tcg: add instrumenting module Pavel Dovgalyuk
2018-09-07 13:36 ` Alex Bennée
2018-09-13 6:55 ` Pavel Dovgalyuk
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 5/7] plugins: add plugin template Pavel Dovgalyuk
2018-09-07 13:41 ` Alex Bennée
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 6/7] plugin: add instruction execution logger Pavel Dovgalyuk
2018-09-07 13:59 ` Alex Bennée
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 7/7] plugins: add syscall logging plugin sample Pavel Dovgalyuk
2018-09-07 14:06 ` Alex Bennée
2018-09-10 9:18 ` Pavel Dovgalyuk
2018-09-10 13:58 ` Alex Bennée
2018-06-05 10:49 ` [Qemu-devel] [RFC PATCH v2 0/7] QEMU binary instrumentation prototype Peter Maydell
2018-06-05 11:56 ` Pavel Dovgalyuk
2018-06-25 5:46 ` Pavel Dovgalyuk
2018-06-25 9:06 ` Peter Maydell
2018-09-07 14:10 ` Alex Bennée
2018-07-10 13:06 ` Stefan Hajnoczi
2018-07-11 6:02 ` Pavel Dovgalyuk
2018-07-30 13:26 ` Pavel Dovgalyuk
2018-08-29 5:39 ` Pavel Dovgalyuk
2018-08-29 19:57 ` Peter Maydell
2018-08-30 4:03 ` Alex Bennée
2018-06-06 8:52 ` no-reply
2018-06-06 9:21 ` no-reply
2018-06-06 10:45 ` no-reply
2018-09-07 14:39 ` Alex Bennée
2018-09-08 0:57 ` Peter Maydell
2018-09-10 9:01 ` Alex Bennée
2018-09-10 11:44 ` Pavel Dovgalyuk
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=87mustz96w.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=Pavel.Dovgaluk@ispras.ru \
--cc=dovgaluk@ispras.ru \
--cc=maria.klimushenkova@ispras.ru \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=vilanova@ac.upc.edu \
/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.