Since Incus 7.6 now supports native mlx5 live-migration, I thought it would be a good idea to walk interested administrators through how to actually pull that off, to put to good use the many hours I spent debugging it. This is essentially a careful adaptation of NVIDIA’s guide, with a few remarks and precisions.
If your system has kernel lockdown enabled (which should be the case when using Secure Boot), you will need to temporarily disable it (which should be possible by simply disabling Secure Boot). The guide assumes you have installed mstflint, the open source Mellanox firmware tools.
1. Manage your expectations
The feature is only compatible with high-end Mellanox cards, so this may actually not be for you because of that. Check the official requirements to get an idea whether your card is supported. This list actually misses a whole family of cards: ConnectX-6 Dx, which are definitely compatible (they actually are the ones I used to implement the feature).
Note the fine print:
The same PSID must be used on both the source and the target hosts (identical cards, same CAPs and features are needed), and have the same firmware version.
This means that two cards with the same commercial name may not actually be compatible, and if they actually are the same cards, their tuning must perfectly match.
To check the requirements, find your cards with lspci | awk '/Mellanox/&&!/Virtual/'. Note that each port of your cards will appear here as a separate component; just pick one for each card.
01:00.0 Ethernet controller: Mellanox Technologies MT2892 Family [ConnectX-6 Dx]
01:00.1 Ethernet controller: Mellanox Technologies MT2892 Family [ConnectX-6 Dx]
Check your PSID with mstflint --device <device address> query | grep PSID:.
PSID: MT_0000000437
If any of your cards has a PSID that differs from the others, you will not be able to live-migrate from and to it. There is nothing you can do about it (except buying a new one).
2. Configure your cards
First, upgrade your cards to a migration-capable firmware. I recommend using the last one available, but whichever you choose, make sure that you flash the exact same one on all your cards. If your OEM does not provide vendored firmware for your machine, you can download an official one on NVIDIA’s website and extract it. You can burn the firmware on your card with mstflint --device <device address> --image <extracted .bin file> burn.
You may not be able to directly install the latest firmware on your card (you may get a Burning Fs4 image failed: Bad parameter error), in which case you will have to first install an older one. You generally can flash the 22.50 firmware after flashing the 22.35 one. After each flashing operation, run mstfwreset --device <device address> reset.
Now, your cards need to have the exact same configuration. Mark my words. Your OEM may provide all the tools to configure the cards properly, but if it does not, follow along. It may be a good idea to reset your card to factory defaults with mstconfig --device <device address> reset. Then, enable SR-IOV, configure your number of VFs and enable the live-migration capability with mstconfig --device <device address> set SRIOV_EN=1 NUM_OF_VFS=<number of VFs> VF_MIGRATION_MODE=2.
From here, you can reboot the system, and if you had disabled it, re-enable Secure Boot and/or kernel lockdown.
3. Configure your network
Live-migration only works on a given port when that port is in switchdev mode. This mode requires to first unbind everything on your port, then switch the port to switchdev, then rebind everything back (for each port you want to use for live-migration):
for vf in /sys/bus/pci/devices/<device address>/virtfn*; do
base="$(basename "$(readlink -f "$vf")")"
echo "$base" > "/sys/bus/pci/devices/$base/driver/unbind"
done
devlink dev eswitch set pci/<device address> mode switchdev
for vf in /sys/bus/pci/devices/<device address>/virtfn*; do
base="$(basename "$(readlink -f "$vf")")"
echo "$base" > "/sys/bus/pci/drivers/mlx5_core/bind"
done
This mode manages VFs through so-called representors, which need to be put in a Linux bridge to properly operate. You will generally want to create a bridge (remember to set its link up) containing your PF and all your VF representors (not the VFs themselves!), and if you want VLANs, enable VLAN filtering on it. Be carefull though, switchdev mode does not persist across reboots, so you will want to have a startup service taking care of the setup in this section.
You are then good to go and can use your PF as your sriov NIC’s or network’s parent!