xref: /linux/Documentation/filesystems/fuse/uapi/fuse-uapi-io-uring.rst (revision 67f8bc848ee31831336bd478e57d2f993551902e)
1*76709425SJoanne Koong.. SPDX-License-Identifier: GPL-2.0
2*76709425SJoanne Koong
3*76709425SJoanne Koong=====================================
4*76709425SJoanne KoongFUSE-over-io-uring uapi documentation
5*76709425SJoanne Koong=====================================
6*76709425SJoanne Koong
7*76709425SJoanne KoongCommands
8*76709425SJoanne Koong========
9*76709425SJoanne Koong
10*76709425SJoanne Koong``enum fuse_uring_cmd``:
11*76709425SJoanne Koong
12*76709425SJoanne Koong``FUSE_IO_URING_CMD_ADD_QUEUE``
13*76709425SJoanne Koong  Create a queue identified by ``fuse_uring_cmd_req.qid``. Queue-wide
14*76709425SJoanne Koong  options are passed in ``fuse_uring_cmd_req.flags``:
15*76709425SJoanne Koong
16*76709425SJoanne Koong  ``FUSE_URING_ZERO_COPY``
17*76709425SJoanne Koong    Enable zero-copy on this queue. Requires ``CAP_SYS_ADMIN`` and a buffer
18*76709425SJoanne Koong    pool, which is added separately via ``ADD_BUFPOOL`` before registering
19*76709425SJoanne Koong    entries (see `Zero-copy`_).
20*76709425SJoanne Koong
21*76709425SJoanne Koong``FUSE_IO_URING_CMD_ADD_BUFPOOL``
22*76709425SJoanne Koong  Register the payload buffer pool for an existing queue. The server provides
23*76709425SJoanne Koong  a single contiguous region in ``fuse_uring_cmd_req.bufpool.uaddr`` /
24*76709425SJoanne Koong  ``.len``. This command must be issued after ``ADD_QUEUE`` and before
25*76709425SJoanne Koong  registering any payload-carrying entries on that queue.
26*76709425SJoanne Koong  ``fuse_uring_cmd_req.flags`` must be 0. Submitting this command with
27*76709425SJoanne Koong  ``IORING_URING_CMD_FIXED`` marks the pool as registered, which avoids per
28*76709425SJoanne Koong  i/o pinning/unpinning and mapping overhead (see `Buffer pools`_).
29*76709425SJoanne Koong
30*76709425SJoanne Koong``FUSE_IO_URING_CMD_REGISTER``
31*76709425SJoanne Koong  Register a ring entry (a long-lived SQE that carries the request header
32*76709425SJoanne Koong  iovec). For a zero-copy queue, ``fuse_uring_cmd_req.ent_zero_copy_buf_index``
33*76709425SJoanne Koong  indicates the reserved registered buffer table slot this entry uses for
34*76709425SJoanne Koong  zero-copy (see `Zero-copy`_).
35*76709425SJoanne Koong
36*76709425SJoanne Koong``FUSE_IO_URING_CMD_COMMIT_AND_FETCH``
37*76709425SJoanne Koong  Commit the reply for a completed request and fetch the next one. The
38*76709425SJoanne Koong  request is identified by ``fuse_uring_cmd_req.commit_id`` (the value the
39*76709425SJoanne Koong  kernel reported in ``fuse_uring_ent_in_out.commit_id``).
40*76709425SJoanne Koong
41*76709425SJoanne KoongStructures
42*76709425SJoanne Koong==========
43*76709425SJoanne Koong
44*76709425SJoanne Koong``struct fuse_uring_cmd_req`` (80-byte SQE command area):
45*76709425SJoanne Koong
46*76709425SJoanne Koong============================  ==================================================
47*76709425SJoanne KoongField                         Meaning
48*76709425SJoanne Koong============================  ==================================================
49*76709425SJoanne Koong``flags``                     Command-specific flags (see each command).
50*76709425SJoanne Koong``commit_id``                 Request id, for ``COMMIT_AND_FETCH``.
51*76709425SJoanne Koong``qid``                       Queue index.
52*76709425SJoanne Koong``bufpool.uaddr``             Pool base address, for ``ADD_BUFPOOL``.
53*76709425SJoanne Koong``bufpool.len``               Pool length in bytes, for ``ADD_BUFPOOL``.
54*76709425SJoanne Koong``bufpool.reserved``          Must be 0, for ``ADD_BUFPOOL``.
55*76709425SJoanne Koong``ent_zero_copy_buf_index``   Per-entry zero-copy slot, for ``REGISTER``.
56*76709425SJoanne Koong============================  ==================================================
57*76709425SJoanne Koong
58*76709425SJoanne Koong``struct fuse_uring_ent_in_out`` (reported by the kernel per request):
59*76709425SJoanne Koong
60*76709425SJoanne Koong============================  ==================================================
61*76709425SJoanne KoongField                         Meaning
62*76709425SJoanne Koong============================  ==================================================
63*76709425SJoanne Koong``flags``                     ``FUSE_URING_ENT_ZERO_COPY`` if zero-copied.
64*76709425SJoanne Koong``commit_id``                 Id to echo back in ``COMMIT_AND_FETCH``.
65*76709425SJoanne Koong``payload_sz``                Total payload size in bytes (see `Zero-copy`_).
66*76709425SJoanne Koong``offset``                    Payload buffer offset within the pool.
67*76709425SJoanne Koong============================  ==================================================
68*76709425SJoanne Koong
69*76709425SJoanne KoongBuffer pools
70*76709425SJoanne Koong============
71*76709425SJoanne KoongSetup:
72*76709425SJoanne Koong
73*76709425SJoanne Koong* Issue ``ADD_QUEUE`` for the qid.
74*76709425SJoanne Koong* Issue ``ADD_BUFPOOL`` with ``bufpool.uaddr`` and ``bufpool.len`` pointing
75*76709425SJoanne Koong  at the region.
76*76709425SJoanne Koong* Register entries with ``REGISTER``.
77*76709425SJoanne Koong
78*76709425SJoanne KoongFor every request that has a payload, the kernel reports where the payload
79*76709425SJoanne Koonglives in ``struct fuse_uring_ent_in_out`` (part of
80*76709425SJoanne Koong``struct fuse_uring_req_header``):
81*76709425SJoanne Koong
82*76709425SJoanne Koong``offset``
83*76709425SJoanne Koong  Byte offset, within the pool region, for this request's payload buffer.
84*76709425SJoanne Koong  The server adds this to the pool base address to locate the payload.
85*76709425SJoanne Koong
86*76709425SJoanne Koong``payload_sz``
87*76709425SJoanne Koong  Number of payload bytes for this request.
88*76709425SJoanne Koong
89*76709425SJoanne KoongTo use registered buffers, the server registers the pool region with io_uring
90*76709425SJoanne Koongand submits ``ADD_BUFPOOL`` with ``IORING_URING_CMD_FIXED`` set in
91*76709425SJoanne Koong``sqe->uring_cmd_flags`` and the index of the registered bufpool in
92*76709425SJoanne Koong``sqe->buf_index``. Every SQE the server submits afterwards must follow the
93*76709425SJoanne Koongsame fixed-buffer protocol, carrying ``IORING_URING_CMD_FIXED`` and that same
94*76709425SJoanne Koong``sqe->buf_index``. The same registered buffer can be reused for the server's
95*76709425SJoanne Koongbacking-store I/O as well (e.g. ``IORING_OP_READ_FIXED`` /
96*76709425SJoanne Koong``IORING_OP_WRITE_FIXED``).
97*76709425SJoanne Koong
98*76709425SJoanne KoongZero-copy
99*76709425SJoanne Koong=========
100*76709425SJoanne KoongRequirements:
101*76709425SJoanne Koong
102*76709425SJoanne Koong* The server must be privileged (``CAP_SYS_ADMIN``).
103*76709425SJoanne Koong* A zero-copy queue: ``ADD_QUEUE`` with the ``FUSE_URING_ZERO_COPY`` flag set.
104*76709425SJoanne Koong* A buffer pool: ``ADD_BUFPOOL``.
105*76709425SJoanne Koong* For each entry, ``REGISTER`` with ``ent_zero_copy_buf_index`` set to the
106*76709425SJoanne Koong  index this entry uses in the server's io_uring registered-buffer table.
107*76709425SJoanne Koong  This is where the kernel registers the request's pages for the server to
108*76709425SJoanne Koong  access (it is separate from the payload pool). On a non-zero-copy queue this
109*76709425SJoanne Koong  field must be 0.
110*76709425SJoanne Koong
111*76709425SJoanne KoongZero-copy is selected per open file. The server sets the open-file flag in
112*76709425SJoanne Koongthe ``FUSE_OPEN`` / ``FUSE_CREATE`` reply:
113*76709425SJoanne Koong
114*76709425SJoanne Koong``FOPEN_IO_URING_ZERO_COPY``
115*76709425SJoanne Koong  Reads/writes on this open file should use zero-copy.
116*76709425SJoanne Koong
117*76709425SJoanne KoongFor a request that is zero-copied, the kernel sets ``FUSE_URING_ENT_ZERO_COPY``
118*76709425SJoanne Koongin ``fuse_uring_ent_in_out.flags`` and places the request's pages at the
119*76709425SJoanne Koongentry's ``ent_zero_copy_buf_index``. The server then issues
120*76709425SJoanne Koong``IORING_OP_READ_FIXED`` / ``IORING_OP_WRITE_FIXED`` against that index to
121*76709425SJoanne Koongtransfer the data directly to/from the client's pages.
122*76709425SJoanne Koong
123*76709425SJoanne KoongFor such a request, ``payload_sz`` includes the zero-copied page bytes
124*76709425SJoanne Koong(transferred via the registered buffer at ``ent_zero_copy_buf_index``). Any
125*76709425SJoanne Koongnon-page-backed args (e.g. op headers) are still copied through the pool
126*76709425SJoanne Koongpayload buffer at ``offset``.
127