Skip to content

Commit 94a9471

Browse files
vivierMichael Tokarev
authored andcommitted
docs: Explain how to use passt
Add a chapter to explain how to use passt(1) instead of '-net user'. passt(1) can be connected to QEMU using UNIX socket or vhost-user. With vhost-user, migration of the VM is allowed and internal state of passt(1) is transfered from one side to the other Bug: https://gitlab.com/qemu-project/qemu/-/issues/2827 Signed-off-by: Laurent Vivier <[email protected]> Reviewed-by: David Gibson <[email protected]> Reviewed-by: Stefano Brivio <[email protected]> Signed-off-by: Michael Tokarev <[email protected]>
1 parent 14fb6db commit 94a9471

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

docs/system/devices/net.rst

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,106 @@ When using the ``'-netdev user,hostfwd=...'`` option, TCP or UDP
7777
connections can be redirected from the host to the guest. It allows for
7878
example to redirect X11, telnet or SSH connections.
7979

80+
Using passt as the user mode network stack
81+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82+
83+
passt_ can be used as a simple replacement for SLIRP (``-net user``).
84+
passt doesn't require any capability or privilege. passt has
85+
better performance than ``-net user``, full IPv6 support and better security
86+
as it's a daemon that is not executed in QEMU context.
87+
88+
passt can be connected to QEMU either by using a socket
89+
(``-netdev stream``) or using the vhost-user interface (``-netdev vhost-user``).
90+
See `passt(1)`_ for more details on passt.
91+
92+
.. _passt: https://passt.top/
93+
.. _passt(1): https://passt.top/builds/latest/web/passt.1.html
94+
95+
To use socket based passt interface:
96+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97+
98+
Start passt as a daemon::
99+
100+
passt --socket ~/passt.socket
101+
102+
If ``--socket`` is not provided, passt will print the path of the UNIX domain socket QEMU can connect to (``/tmp/passt_1.socket``, ``/tmp/passt_2.socket``,
103+
...). Then you can connect your QEMU instance to passt:
104+
105+
.. parsed-literal::
106+
|qemu_system| [...OPTIONS...] -device virtio-net-pci,netdev=netdev0 -netdev stream,id=netdev0,server=off,addr.type=unix,addr.path=~/passt.socket
107+
108+
Where ``~/passt.socket`` is the UNIX socket created by passt to
109+
communicate with QEMU.
110+
111+
To use vhost-based interface:
112+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
113+
114+
Start passt with ``--vhost-user``::
115+
116+
passt --vhost-user --socket ~/passt.socket
117+
118+
Then to connect QEMU:
119+
120+
.. parsed-literal::
121+
|qemu_system| [...OPTIONS...] -m $RAMSIZE -chardev socket,id=chr0,path=~/passt.socket -netdev vhost-user,id=netdev0,chardev=chr0 -device virtio-net,netdev=netdev0 -object memory-backend-memfd,id=memfd0,share=on,size=$RAMSIZE -numa node,memdev=memfd0
122+
123+
Where ``$RAMSIZE`` is the memory size of your VM ``-m`` and ``-object memory-backend-memfd,size=`` must match.
124+
125+
Migration of passt:
126+
^^^^^^^^^^^^^^^^^^^
127+
128+
When passt is connected to QEMU using the vhost-user interface it can
129+
be migrated with QEMU and the network connections are not interrupted.
130+
131+
As passt runs with no privileges, it relies on passt-repair to save and
132+
load the TCP connections state, using the TCP_REPAIR socket option.
133+
The passt-repair helper needs to have the CAP_NET_ADMIN capability, or run as root. If passt-repair is not available, TCP connections will not be preserved.
134+
135+
Example of migration of a guest on the same host
136+
________________________________________________
137+
138+
Before being able to run passt-repair, the CAP_NET_ADMIN capability must be set
139+
on the file, run as root::
140+
141+
setcap cap_net_admin+eip ./passt-repair
142+
143+
Start passt for the source side::
144+
145+
passt --vhost-user --socket ~/passt_src.socket --repair-path ~/passt-repair_src.socket
146+
147+
Where ``~/passt-repair_src.socket`` is the UNIX socket created by passt to
148+
communicate with passt-repair. The default value is the ``--socket`` path
149+
appended with ``.repair``.
150+
151+
Start passt-repair::
152+
153+
passt-repair ~/passt-repair_src.socket
154+
155+
Start source side QEMU with a monitor to be able to send the migrate command:
156+
157+
.. parsed-literal::
158+
|qemu_system| [...OPTIONS...] [...VHOST USER OPTIONS...] -monitor stdio
159+
160+
Start passt for the destination side::
161+
162+
passt --vhost-user --socket ~/passt_dst.socket --repair-path ~/passt-repair_dst.socket
163+
164+
Start passt-repair::
165+
166+
passt-repair ~/passt-repair_dst.socket
167+
168+
Start QEMU with the ``-incoming`` parameter:
169+
170+
.. parsed-literal::
171+
|qemu_system| [...OPTIONS...] [...VHOST USER OPTIONS...] -incoming tcp:localhost:4444
172+
173+
Then in the source guest monitor the migration can be started::
174+
175+
(qemu) migrate tcp:localhost:4444
176+
177+
A separate passt-repair instance must be started for every migration. In the case of a failed migration, passt-repair also needs to be restarted before trying
178+
again.
179+
80180
Hubs
81181
~~~~
82182

0 commit comments

Comments
 (0)