Copyright (c) 2019, Linaro Limited
Written by Emilio Cota and Alex Bennée
-================
QEMU TCG Plugins
================
individual instruction granularity including potentially subscribing
to all load and store operations.
-API Stability
-=============
+Usage
+-----
+
+Any QEMU binary with TCG support has plugins enabled by default.
+Earlier releases needed to be explicitly enabled with::
+
+ configure --enable-plugins
+
+Once built a program can be run with multiple plugins loaded each with
+their own arguments::
+
+ $QEMU $OTHER_QEMU_ARGS \
+ -plugin tests/plugin/libhowvec.so,inline=on,count=hint \
+ -plugin tests/plugin/libhotblocks.so
+
+Arguments are plugin specific and can be used to modify their
+behaviour. In this case the howvec plugin is being asked to use inline
+ops to count and break down the hint instructions by type.
+
+Writing plugins
+---------------
+
+API versioning
+~~~~~~~~~~~~~~
This is a new feature for QEMU and it does allow people to develop
out-of-tree plugins that can be dynamically linked into a running QEMU
API should it need to do so. The best way to avoid this is to submit
your plugin upstream so they can be updated if/when the API changes.
-API versioning
---------------
-
All plugins need to declare a symbol which exports the plugin API
version they were built against. This can be done simply by::
incremented if new APIs are added. The minimum API version will be
incremented if existing APIs are changed or removed.
-Exposure of QEMU internals
---------------------------
-
-The plugin architecture actively avoids leaking implementation details
-about how QEMU's translation works to the plugins. While there are
-conceptions such as translation time and translation blocks the
-details are opaque to plugins. The plugin is able to query select
-details of instructions and system configuration only through the
-exported *qemu_plugin* functions.
-
-Query Handle Lifetime
----------------------
+Lifetime of the query handle
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Each callback provides an opaque anonymous information handle which
can usually be further queried to find out information about a
information that is needed is extracted during the callback and saved
by the plugin.
-API
-===
-
-.. kernel-doc:: include/qemu/qemu-plugin.h
-
-Usage
-=====
-
-Any QEMU binary with TCG support has plugins enabled by default.
-Earlier releases needed to be explicitly enabled with::
-
- configure --enable-plugins
-
-Once built a program can be run with multiple plugins loaded each with
-their own arguments::
-
- $QEMU $OTHER_QEMU_ARGS \
- -plugin tests/plugin/libhowvec.so,inline=on,count=hint \
- -plugin tests/plugin/libhotblocks.so
-
-Arguments are plugin specific and can be used to modify their
-behaviour. In this case the howvec plugin is being asked to use inline
-ops to count and break down the hint instructions by type.
-
-Plugin Life cycle
-=================
+Plugin life cycle
+~~~~~~~~~~~~~~~~~
First the plugin is loaded and the public qemu_plugin_install function
is called. The plugin will then register callbacks for various plugin
Finally when QEMU exits all the registered *atexit* callbacks are
invoked.
+Exposure of QEMU internals
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The plugin architecture actively avoids leaking implementation details
+about how QEMU's translation works to the plugins. While there are
+conceptions such as translation time and translation blocks the
+details are opaque to plugins. The plugin is able to query select
+details of instructions and system configuration only through the
+exported *qemu_plugin* functions.
+
+API
+~~~
+
+.. kernel-doc:: include/qemu/qemu-plugin.h
+
Internals
-=========
+---------
Locking
--------
+~~~~~~~
We have to ensure we cannot deadlock, particularly under MTTCG. For
this we acquire a lock when called from plugin code. We also keep the
has executed while all vCPUs are quiescent.
Example Plugins
-===============
+---------------
There are a number of plugins included with QEMU and you are
encouraged to contribute your own plugins plugins upstream. There is a