Skip to contentSkip to conversation

introduce vfio-user protocol specification

PATCH Superseded Thanos Makatos 1 participant 2 messages Nov 9, 2020 – Nov 13, 2020

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 introduce vfio-user protocol specification

This patch introduces the vfio-user protocol specification (formerly known as VFIO-over-socket), which is designed to allow devices to be emulated outside QEMU, in a separate process. vfio-user reuses the existing VFIO defines, structs and concepts.

It has been earlier discussed as an RFC in:
"RFC: use VFIO over a UNIX domain socket to implement device oading"

---

Changed since v1:
* fix coding style issues
* update MAINTAINERS for VFIO-over-socket
* add vfio-over-socket to ToC

Changed since v2:
* fix whitespace

Changed since v3:
* rename protocol to vfio-user
* add table of contents
* fix Unicode problems
* fix typos and various reStructuredText issues
* various stylistic improvements
* add backend program conventions
* rewrite part of intro, drop QEMU-specific stuff
* drop QEMU-specific paragraph about implementation
* explain that passing of FDs isn't necessary
* minor improvements in the VFIO section
* various text substitutions for the sake of consistency
* drop paragraph about client and server, already explained in
* intro
* drop device ID
* drop type from version
* elaborate on request concurrency
* convert some inessential paragraphs into notes
* explain why some existing VFIO defines cannot be reused
* explain how to make changes to the protocol
* improve text of DMA map
* reword comment about existing VFIO commands
* add reference to Version section
* reset device on disconnection
* reword live migration section
* replace sys/vfio.h with linux/vfio.h
* drop reference to iovec
* use argz the same way it is used in VFIO
* add type field in header for clarity

Changed since v4:
* introduce support for live migration as defined in
* include/uapi/linux/vfio.h
* introduce 'max_fds' and 'migration' capabilities:
* remove 'index' from VFIO_USER_DEVICE_GET_IRQ_INFO
* fix minor typos and reworded some text for clarity

Changed since v5:
* fix minor typos
* separate VFIO_USER_DMA_MAP and VFIO_USER_DMA_UNMAP
* clarify meaning of VFIO bitmap size field
* move version major/minor outside JSON
* client proposes version first
* make Errno optional in message header
* clarification about message ID uniqueness
* clarify that server->client request can appear in between

    client->server request/reply

You can focus on v5 to v6 changes by cloning my fork
(https://github.com/tmakatos/qemu) and doing:

git diff refs/tags/vfio-user/v5 refs/heads/vfio-user/v6

There's still an outstanding question to asnwer regarding why it DMA_*MAP instead of *MAP_DMA, however I believe it can wait until the next revisition.

---
 MAINTAINERS              |    6 +
 docs/devel/index.rst     |    1 +
 docs/devel/vfio-user.rst | 1641 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1648 insertions(+)
 create mode 100644 docs/devel/vfio-user.rst
MAINTAINERS +6 -0
index 7e442b5247..3611f9e365 100644
@@ -1754,6 +1754,12 @@ F: hw/vfio/ap.c
 F: docs/system/s390x/vfio-ap.rst
 L: [email protected]
 
+vfio-user
+M: John G Johnson <[email protected]>
+M: Thanos Makatos <[email protected]>
+S: Supported
+F: docs/devel/vfio-user.rst
+
 vhost
 M: Michael S. Tsirkin <[email protected]>
 S: Supported
docs/devel/index.rst +1 -0
index 77baae5c77..7c7740a096 100644
@@ -34,3 +34,4 @@ Contents:
    clocks
    qom
    block-coroutine-wrapper
+   vfio-user
docs/devel/vfio-user.rst new file +1641 -0

1,641 lines not on this page · raw message

Signature · 1 line
2.12.2
#1 lore raw
Quoted 27 lines
docs/devel/vfio-user.rst new file +8 -0
+Version Data Format
+^^^^^^^^^^^^^^^^^^^
+
+The version data is an optional JSON byte array with the following format:
+
++--------------+------------------+-------------------------------------------+
+| Name         | Type             | Description                               |
++==============+==================+======================

=====================+

+| capabilities | collection of    | Contains common capabilities that the     |
+|              | name/value pairs | sender supports. Optional.                |

++--------------+------------------+-------------------------------------------+

docs/devel/vfio-user.rst new file +6 -0
+
+Capabilities:
+
++---------------+------------------+------------------------------------------+
+| Name          | Type             | Description                              |
++===============+==================+=====================

=====================+

+| ``max_fds``   | number           | Maximum number of file descriptors that  |
+|               |                  | can be received by the sender. Optional. |
+|               |                  | If not specified then the receiver must  |
+|               |                  | assume ``max_fds=1``.                    |
++---------------+------------------+------------------------------------------+
+| ``migration`` | collection of    | Migration capability parameters. If      |
+|               | name/value pairs | missing then migration is not supported  |
+|               |                  | by the sender.                           |
Quoted 1 line

++---------------+------------------+------------------------------------------+

Can we introduce the following parameters that can help simplify the server implementation?

* max_dma_regions: maximum number of DMA regions per VFIO_USER_DMA_MAP/UNMAP message

* max_dirty_bitmaps: maximum number of dirty bitmaps requested per VFIO_USER_DIRTY_PAGES message

If these parameters are missing then they can be unlimited. The vfio-user client will have to break a single operation into multiple messages.

Quoted 77 lines
docs/devel/vfio-user.rst new file +65 -0
+VFIO_USER_DEVICE_GET_REGION_INFO
+--------------------------------
+
+Message format
+^^^^^^^^^^^^^^
+
++--------------+------------------------+
+| Name         | Value                  |
++==============+========================+
+| Message ID   | <ID>                   |
++--------------+------------------------+
+| Command      | 5                      |
++--------------+------------------------+
+| Message size | 48 + any caps          |
++--------------+------------------------+
+| Flags        | Reply bit set in reply |
++--------------+------------------------+
+| Error        | 0/errno                |
++--------------+------------------------+
+| Region info  | VFIO region info       |
++--------------+------------------------+
+
+This command message is sent by the client to the server to query for
+information about device memory regions. The VFIO region info structure is
+defined in ``<linux/vfio.h>`` (``struct vfio_region_info``). Since the client
+does not know the size of the capabilities, the size of the reply it should
+expect is 48 plus any capabilities whose size is indicated in the size field of
+the reply header.
+
+VFIO region info format
+^^^^^^^^^^^^^^^^^^^^^^^
+
++------------+--------+------------------------------+
+| Name       | Offset | Size                         |
++============+========+==============================+
+| argsz      | 16     | 4                            |
++------------+--------+------------------------------+
+| flags      | 20     | 4                            |
++------------+--------+------------------------------+
+|            | +-----+-----------------------------+ |
+|            | | Bit | Definition                  | |
+|            | +=====+=============================+ |
+|            | | 0   | VFIO_REGION_INFO_FLAG_READ  | |
+|            | +-----+-----------------------------+ |
+|            | | 1   | VFIO_REGION_INFO_FLAG_WRITE | |
+|            | +-----+-----------------------------+ |
+|            | | 2   | VFIO_REGION_INFO_FLAG_MMAP  | |
+|            | +-----+-----------------------------+ |
+|            | | 3   | VFIO_REGION_INFO_FLAG_CAPS  | |
+|            | +-----+-----------------------------+ |
++------------+--------+------------------------------+
+| index      | 24     | 4                            |
++------------+--------+------------------------------+
+| cap_offset | 28     | 4                            |
++------------+--------+------------------------------+
+| size       | 32     | 8                            |
++------------+--------+------------------------------+
+| offset     | 40     | 8                            |
++------------+--------+------------------------------+
+
+* *argsz* is the size of the VFIO region info structure plus the
+  size of any region capabilities returned.
+* *flags* are attributes of the region:
+
+  * *VFIO_REGION_INFO_FLAG_READ* allows client read access to the

region.
+ * *VFIO_REGION_INFO_FLAG_WRITE* allows client write access to the region.
+ * *VFIO_REGION_INFO_FLAG_MMAP* specifies the client can mmap() the region.

docs/devel/vfio-user.rst new file +4 -0
+    When this flag is set, the reply will include a file descriptor in its
+    meta-data. On AF_UNIX sockets, the file descriptors will be passed as
+    SCM_RIGHTS type ancillary data.
+  * *VFIO_REGION_INFO_FLAG_CAPS* indicates additional capabilities

found in the

docs/devel/vfio-user.rst new file +2 -0
+    reply.
+

docs/devel/vfio-user.rst line 825

Quoted 10 lines
docs/devel/vfio-user.rst new file +10 -0
+* *index* is the index of memory region being queried, it is the only field
+  that is required to be set in the command message.
+* *cap_offset* describes where additional region capabilities can be found.
+  cap_offset is relative to the beginning of the VFIO region info structure.
+  The data structure it points is a VFIO cap header defined in
+  ``<linux/vfio.h>``.
+* *size* is the size of the region.
+* *offset* is the offset given to the mmap() system call for regions with the
+  MMAP attribute. It is also used as the base offset when mapping a VFIO
+  sparse mmap area, described below.

In the command message we only use vfio_region_info.index. VFIO passes the entire struct since it gets filled in, however this doesn't make sense in vfio-user. Shall we drop sending the entire struct vfio_region_info and only send the region index?