feat: add vmnet_network support on macOS 26+#4394
feat: add vmnet_network support on macOS 26+#4394norio-nomura wants to merge 4 commits intolima-vm:masterfrom
vmnet_network support on macOS 26+#4394Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Any advantage using them? |
As far as the API is concerned, customization that is not supported by vzNAT should be possible. |
07eebec to
270556e
Compare
This comment was marked as outdated.
This comment was marked as outdated.
81d4cc6 to
57553f8
Compare
433432d to
adf5456
Compare
This comment was marked as resolved.
This comment was marked as resolved.
4cd78ff to
8cc5f26
Compare
|
Updated PR description. |
|
Most of the functions I wanted at the start of this PR have been realized. |
5f7ec7b to
b7c39e0
Compare
This comment was marked as outdated.
This comment was marked as outdated.
6e02bc4 to
a5d58f3
Compare
VZVmnetNetworkDeviceAttachment support on macOS 26+vmnet_network support on macOS 26+
a5d58f3 to
c078397
Compare
|
Updated PR description. Updated $ iperf3 -c 192.168.107.10 --bidir
Connecting to host 192.168.107.10, port 5201
[ 5] local 192.168.107.1 port 54776 connected to 192.168.107.10 port 5201
[ 7] local 192.168.107.1 port 54777 connected to 192.168.107.10 port 5201
[ ID][Role] Interval Transfer Bitrate
[ 5][TX-C] 0.00-1.00 sec 2.41 GBytes 20.7 Gbits/sec
[ 7][RX-C] 0.00-1.00 sec 1.70 GBytes 14.6 Gbits/sec
[ 5][TX-C] 1.00-2.00 sec 2.27 GBytes 19.5 Gbits/sec
[ 7][RX-C] 1.00-2.00 sec 1.60 GBytes 13.7 Gbits/sec
[ 5][TX-C] 2.00-3.00 sec 2.26 GBytes 19.5 Gbits/sec
[ 7][RX-C] 2.00-3.00 sec 1.62 GBytes 13.9 Gbits/sec
[ 5][TX-C] 3.00-4.00 sec 2.31 GBytes 19.8 Gbits/sec
[ 7][RX-C] 3.00-4.00 sec 1.63 GBytes 14.0 Gbits/sec
[ 5][TX-C] 4.00-5.00 sec 2.36 GBytes 20.3 Gbits/sec
[ 7][RX-C] 4.00-5.00 sec 1.69 GBytes 14.6 Gbits/sec
[ 5][TX-C] 5.00-6.00 sec 2.26 GBytes 19.4 Gbits/sec
[ 7][RX-C] 5.00-6.00 sec 1.60 GBytes 13.7 Gbits/sec
[ 5][TX-C] 6.00-7.00 sec 2.26 GBytes 19.4 Gbits/sec
[ 7][RX-C] 6.00-7.00 sec 1.58 GBytes 13.5 Gbits/sec
[ 5][TX-C] 7.00-8.00 sec 2.33 GBytes 20.0 Gbits/sec
[ 7][RX-C] 7.00-8.00 sec 1.66 GBytes 14.3 Gbits/sec
[ 5][TX-C] 8.00-9.00 sec 2.39 GBytes 20.5 Gbits/sec
[ 7][RX-C] 8.00-9.00 sec 1.69 GBytes 14.6 Gbits/sec
[ 5][TX-C] 9.00-10.00 sec 2.30 GBytes 19.7 Gbits/sec
[ 7][RX-C] 9.00-10.00 sec 1.64 GBytes 14.1 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID][Role] Interval Transfer Bitrate Retr
[ 5][TX-C] 0.00-10.00 sec 23.2 GBytes 19.9 Gbits/sec sender
[ 5][TX-C] 0.00-10.00 sec 23.2 GBytes 19.9 Gbits/sec receiver
[ 7][RX-C] 0.00-10.00 sec 16.4 GBytes 14.1 Gbits/sec 0 sender
[ 7][RX-C] 0.00-10.00 sec 16.4 GBytes 14.1 Gbits/sec receiver
iperf Done.There are times when TX performance deteriorates, like #4394 (comment), but the cause is not clear. |
c078397 to
024f35d
Compare
Document the XPC protocol for developers who want to build their own client library or understand how the broker communicates with clients.
c0d1289 to
a5a0f2b
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Update: TX performance degradation occurs when an interface that has not enabled TSO is connected to the subnet. It does not depend on the interface that started the subnet. |
be97162 to
e406ddd
Compare
Based on `VMNET_SHARED_MODE`, and `VMNET_HOST_MODE` ```yaml networks: - vzShared: true - vzHost: true ``` But, to sharing network between multiple VMs, `VZVmnetNetworkDeviceAttachment` requires VMs are launched by same process. It depends on Code-Hex/vz#205 Signed-off-by: Norio Nomura <norio.nomura@gmail.com> # Conflicts: # go.sum # Conflicts: # go.sum
It provides `vzvmnet.Network` serialization to VMs.
`limactl vmnet` takes flags:
- `--unregister-mach-service`: unregister Mach service from `launchd`
- There is no need to register manually because the VZ driver registers as appropriate.
- `--mach-service=<service name>`: launched as Mach server by `launchd` via `io.lima-vm.vmnet.plist`
- Launched on demand to connection from clients by `launchd`.
- Receives a request payload from clients with fields:
- `Network`: name of the network ("shared", "host", etc)
- `Configuration`: `[]bytes@ representing `VzNetworkConfig` in JSON.
- Validates clients are the same executable (cdhash) by using xpc_peer_requirement API.
- Create `vzvmnet.Network` from provided `Configuration` if cached one does not exist.
- Replies to clients with fields:
- `Configuration`: If `vzvmnet.Network` is cached, it may be created by different configuration.
- `Serialization`: newly created or cached.
- Monitors changes of networks
- When the interface created by `vzvmnet.Network` disappears from host, remove them from cache.
- If all `vzvmnet.Network` are removed, `limactl vmnet` exits.
Clients (hostagent) does:
- Read `.vmnet` VmnetConfig from `networks.yaml`
- Use them on `- vmnet: <network>` fields; "shared" and "host" network are predefined.
- Register `limactl vmnet` to `launchd` if not registered.
- Request serialization to the Mach service "io.lima-vm.vmnet".
- Create `vzvmnet.Network` by provided serialization, then use them.
Additional changes:
- Because shutdown takes longer on using `vzvmnet.Network`:
- Extend VZ driver's shutdown timeout from 5 seconds to 15 seconds
- Add `ExitTimeOut` key with 20 seconds to autostart `io.lima-vm.autostart.INSTANCE.plist`
- `lima.yaml`: `- vzShared` and `- vzHost` are renamed to `- vmnet: shared` and `- vmnet: host`
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
## In QEMU, there are six options for `-netdev` that uses vmnet. It can be select by `_LIMA_QEMU_VMNET_BACKEND` environment variable. - `datagram`, `dgram`: use `-netdev dgram,...` with `vzvmnet.DatagramFileAdaptorForInterface` (recvmsg/sendmsg) - `datagram_next`, `dgram_next`: use `-netdev dgram,...` with `vzvmnet.DatagramNextFileAdaptorForInterface` (recvmsg_x/sendmsg_x) - `socket`: use `-netdev socket,...` with `vzvmnet.StreamFileAdaptorForInterface` - `stream`: use `-netdev stream,...` with `vzvmnet.StreamFileAdaptorForInterface` - `tap`: use `-netdev tap,...` with `vzvmnet.DatagramFileAdaptorForInterface` (recvmsg/sendmsg) - `tap_next`: use `-netdev tap,...` with `vzvmnet.DatagramNextFileAdaptorForInterface` (recvmsg_x/sendmsg_x) The default is `tap` and the best performance with iperf3 is selected (although not a big difference). ## In krunkit, there are three options for `--device virtio-net` that uses vmnet. It can be selected by `_LIMA_KRUNKIT_VMNET_BACKEND` environment variable. - `datagram`, `dgram`: use `type=unixgram,...` with `vzvmnet.DatagramFileAdaptorForInterface` (recvmsg/sendmsg) - `datagram_next`, `dgram_next`: use `type=unixgram,...` with `vzvmnet.DatagramNextFileAdaptorForInterface` (recvmsg_x/sendmsg_x) - `stream`: use `type=unixstream,...` with `vzvmnet.StreamFileAdaptorForInterface` The default is `stream` because: - In the simple iperf3 test, `dgram` performs the best (than vz), but when `iperf3` runs with the `-P 3` option, `krunkit` will stop the network device after outputting the `ENOBUFS` error: > [2026-01-21T05:02:28Z ERROR devices::virtio::net::worker] Failed to process rx: Backend(Internal(ENOBUFS)) (triggered by backend socket readable) - `stream` records retry in `iperf3` but does not stop. Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
e406ddd to
a35b0f2
Compare
|
Let me remove this from v2.1 milestone |
vmnet_network support on macOS 26+
vmType: vz, it usesVZVmnetNetworkDeviceAttachmentvmType: qemu|krunkit, it usesvmnet_interface_start_with_networkDepends on Code-Hex/vz#205
About what can be done and the restrictions with this API:
vmnetwithout root privilegeVMNET_SHARED_MODE, andVMNET_HOST_MODEvzNAT, the "bridge10x" interface is created on the hostVMNET_BRIDGED_MODEvmnet_network_refwith multiple processes, it must be the same executable file.VZVmnetNetworkDeviceAttachmentinstead ofvmnet_network_create.CDHashis probably used to determine "same executable file". TN3126: Inside Code Signing: HashesRedoingcodesignwith "Developer ID", where the hash of the executable file changes, does not interfere with the sharing ofvmnet_network_ref.CDHashdoes not change before and after redoingcodesignwith "Developer ID".Even if it iscodesignusing the same "Developer ID", ifCDHashis changed due to source code changes, etc.,vmnet_network_refcannot be shared.limactlprocess.vmnet_network_refis owned by the process that createdvmnet_network_ref, not the process that started the network based on the sharedvmnet_network_ref.vmnet_network_refis done in the form ofxpc_object_t.xpc_object_toutside the XPC API, but to avoid relying on private information, use the XPC API for sharing.This PR allows
VMNET_SHARED_MODEandVMNET_HOST_MODEto be used under these conditions.Functions to be added
networks.yamllima.yamllimactl vmnetRegistration as a Mach service is automatically done by hostagent when the instance using
- vmnet: *is started, so only unregistering is visible from the user.The registered Mach service is displayed as "io.lima-vm.vmnet.sh" in macOS System Settings (General > Login Items & Extensions).
As a Mach service process, it is started by
launchdas appropriate at the request of the supported drivers.The Mach service responds to requests only if the executable file of the VZ driver process that sent the request has the sameThis restriction is removed on macOS 26.2+.CDHashas itself. It uses xpc_peer_requirement.The Mach service process creates and retains
vmnet_network_refand provides serialization data to the VZ driver.If QEMU driver or krunkit driver request file descriptor to passing
qemuorkrunkit, the Mach service process createsvzvmnet.*FileAdaptorForInterface, and provides file descriptor to communicating packets with the adaptor.When the Mach service detects the termination of the network started by the supported driver based on the serialization data, it discards
vmnet_network_ref.When all the
vmnet_network_refto be retained is gone, the Mach service process will terminate.Additional changes
VmnetNetwork:ExitTimeOutkey with 20 seconds to autostartio.lima-vm.autostart.INSTANCE.plistBenchmark:
iperf3between VMs on the same networkMacBook Pro 14 inch, 2023
CPU: Apple M2 Pro
Memory: 16GB
macOS Tahoe 26.2
socket_vmnet
vmnet: shared