Skip to content

Commit a8ce7b2

Browse files
shayshyikuba-moo
authored andcommitted
devlink: Expose port function commands to control migratable
Expose port function commands to enable / disable migratable capability, this is used to set the port function as migratable. Live migration is the process of transferring a live virtual machine from one physical host to another without disrupting its normal operation. In order for a VM to be able to perform LM, all the VM components must be able to perform migration. e.g.: to be migratable. In order for VF to be migratable, VF must be bound to VFIO driver with migration support. When migratable capability is enabled for a function of the port, the device is making the necessary preparations for the function to be migratable, which might include disabling features which cannot be migrated. Example of LM with migratable function configuration: Set migratable of the VF's port function. $ devlink port show pci/0000:06:00.0/2 pci/0000:06:00.0/2: type eth netdev enp6s0pf0vf1 flavour pcivf pfnum 0 vfnum 1 function: hw_addr 00:00:00:00:00:00 migratable disable $ devlink port function set pci/0000:06:00.0/2 migratable enable $ devlink port show pci/0000:06:00.0/2 pci/0000:06:00.0/2: type eth netdev enp6s0pf0vf1 flavour pcivf pfnum 0 vfnum 1 function: hw_addr 00:00:00:00:00:00 migratable enable Bind VF to VFIO driver with migration support: $ echo <pci_id> > /sys/bus/pci/devices/0000:08:00.0/driver/unbind $ echo mlx5_vfio_pci > /sys/bus/pci/devices/0000:08:00.0/driver_override $ echo <pci_id> > /sys/bus/pci/devices/0000:08:00.0/driver/bind Attach VF to the VM. Start the VM. Perform LM. Signed-off-by: Shay Drory <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Acked-by: Shannon Nelson <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7db9839 commit a8ce7b2

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

Documentation/networking/devlink/devlink-port.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ this means a MAC address.
125125
Users may also set the RoCE capability of the function using
126126
`devlink port function set roce` command.
127127

128+
Users may also set the function as migratable using
129+
'devlink port function set migratable' command.
130+
128131
Function attributes
129132
===================
130133

@@ -194,6 +197,49 @@ VF/SF driver cannot override it.
194197
function:
195198
hw_addr 00:00:00:00:00:00 roce disable
196199

200+
migratable capability setup
201+
---------------------------
202+
Live migration is the process of transferring a live virtual machine
203+
from one physical host to another without disrupting its normal
204+
operation.
205+
206+
User who want PCI VFs to be able to perform live migration need to
207+
explicitly enable the VF migratable capability.
208+
209+
When user enables migratable capability for a VF, and the HV binds the VF to VFIO driver
210+
with migration support, the user can migrate the VM with this VF from one HV to a
211+
different one.
212+
213+
However, when migratable capability is enable, device will disable features which cannot
214+
be migrated. Thus migratable cap can impose limitations on a VF so let the user decide.
215+
216+
Example of LM with migratable function configuration:
217+
- Get migratable capability of the VF device::
218+
219+
$ devlink port show pci/0000:06:00.0/2
220+
pci/0000:06:00.0/2: type eth netdev enp6s0pf0vf1 flavour pcivf pfnum 0 vfnum 1
221+
function:
222+
hw_addr 00:00:00:00:00:00 migratable disable
223+
224+
- Set migratable capability of the VF device::
225+
226+
$ devlink port function set pci/0000:06:00.0/2 migratable enable
227+
228+
$ devlink port show pci/0000:06:00.0/2
229+
pci/0000:06:00.0/2: type eth netdev enp6s0pf0vf1 flavour pcivf pfnum 0 vfnum 1
230+
function:
231+
hw_addr 00:00:00:00:00:00 migratable enable
232+
233+
- Bind VF to VFIO driver with migration support::
234+
235+
$ echo <pci_id> > /sys/bus/pci/devices/0000:08:00.0/driver/unbind
236+
$ echo mlx5_vfio_pci > /sys/bus/pci/devices/0000:08:00.0/driver_override
237+
$ echo <pci_id> > /sys/bus/pci/devices/0000:08:00.0/driver/bind
238+
239+
Attach VF to the VM.
240+
Start the VM.
241+
Perform live migration.
242+
197243
Subfunction
198244
============
199245

include/net/devlink.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,27 @@ struct devlink_ops {
14691469
*/
14701470
int (*port_fn_roce_set)(struct devlink_port *devlink_port,
14711471
bool enable, struct netlink_ext_ack *extack);
1472+
/**
1473+
* @port_fn_migratable_get: Port function's migratable get function.
1474+
*
1475+
* Query migratable state of a function managed by the devlink port.
1476+
* Return -EOPNOTSUPP if port function migratable handling is not
1477+
* supported.
1478+
*/
1479+
int (*port_fn_migratable_get)(struct devlink_port *devlink_port,
1480+
bool *is_enable,
1481+
struct netlink_ext_ack *extack);
1482+
/**
1483+
* @port_fn_migratable_set: Port function's migratable set function.
1484+
*
1485+
* Enable/Disable migratable state of a function managed by the devlink
1486+
* port.
1487+
* Return -EOPNOTSUPP if port function migratable handling is not
1488+
* supported.
1489+
*/
1490+
int (*port_fn_migratable_set)(struct devlink_port *devlink_port,
1491+
bool enable,
1492+
struct netlink_ext_ack *extack);
14721493
/**
14731494
* port_new() - Add a new port function of a specified flavor
14741495
* @devlink: Devlink instance

include/uapi/linux/devlink.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,15 @@ enum devlink_resource_unit {
660660

661661
enum devlink_port_fn_attr_cap {
662662
DEVLINK_PORT_FN_ATTR_CAP_ROCE_BIT,
663+
DEVLINK_PORT_FN_ATTR_CAP_MIGRATABLE_BIT,
663664

664665
/* Add new caps above */
665666
__DEVLINK_PORT_FN_ATTR_CAPS_MAX,
666667
};
667668

668669
#define DEVLINK_PORT_FN_CAP_ROCE _BITUL(DEVLINK_PORT_FN_ATTR_CAP_ROCE_BIT)
670+
#define DEVLINK_PORT_FN_CAP_MIGRATABLE \
671+
_BITUL(DEVLINK_PORT_FN_ATTR_CAP_MIGRATABLE_BIT)
669672

670673
enum devlink_port_function_attr {
671674
DEVLINK_PORT_FUNCTION_ATTR_UNSPEC,

net/core/devlink.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,29 @@ static int devlink_port_fn_roce_fill(const struct devlink_ops *ops,
715715
return 0;
716716
}
717717

718+
static int devlink_port_fn_migratable_fill(const struct devlink_ops *ops,
719+
struct devlink_port *devlink_port,
720+
struct nla_bitfield32 *caps,
721+
struct netlink_ext_ack *extack)
722+
{
723+
bool is_enable;
724+
int err;
725+
726+
if (!ops->port_fn_migratable_get ||
727+
devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PCI_VF)
728+
return 0;
729+
730+
err = ops->port_fn_migratable_get(devlink_port, &is_enable, extack);
731+
if (err) {
732+
if (err == -EOPNOTSUPP)
733+
return 0;
734+
return err;
735+
}
736+
737+
devlink_port_fn_cap_fill(caps, DEVLINK_PORT_FN_CAP_MIGRATABLE, is_enable);
738+
return 0;
739+
}
740+
718741
static int devlink_port_fn_caps_fill(const struct devlink_ops *ops,
719742
struct devlink_port *devlink_port,
720743
struct sk_buff *msg,
@@ -728,6 +751,10 @@ static int devlink_port_fn_caps_fill(const struct devlink_ops *ops,
728751
if (err)
729752
return err;
730753

754+
err = devlink_port_fn_migratable_fill(ops, devlink_port, &caps, extack);
755+
if (err)
756+
return err;
757+
731758
if (!caps.selector)
732759
return 0;
733760
err = nla_put_bitfield32(msg, DEVLINK_PORT_FN_ATTR_CAPS, caps.value,
@@ -1322,6 +1349,15 @@ static int devlink_port_fn_state_fill(const struct devlink_ops *ops,
13221349
return 0;
13231350
}
13241351

1352+
static int
1353+
devlink_port_fn_mig_set(struct devlink_port *devlink_port, bool enable,
1354+
struct netlink_ext_ack *extack)
1355+
{
1356+
const struct devlink_ops *ops = devlink_port->devlink->ops;
1357+
1358+
return ops->port_fn_migratable_set(devlink_port, enable, extack);
1359+
}
1360+
13251361
static int
13261362
devlink_port_fn_roce_set(struct devlink_port *devlink_port, bool enable,
13271363
struct netlink_ext_ack *extack)
@@ -1348,6 +1384,13 @@ static int devlink_port_fn_caps_set(struct devlink_port *devlink_port,
13481384
if (err)
13491385
return err;
13501386
}
1387+
if (caps.selector & DEVLINK_PORT_FN_CAP_MIGRATABLE) {
1388+
err = devlink_port_fn_mig_set(devlink_port, caps_value &
1389+
DEVLINK_PORT_FN_CAP_MIGRATABLE,
1390+
extack);
1391+
if (err)
1392+
return err;
1393+
}
13511394
return 0;
13521395
}
13531396

@@ -1769,6 +1812,18 @@ static int devlink_port_function_validate(struct devlink_port *devlink_port,
17691812
"Port doesn't support RoCE function attribute");
17701813
return -EOPNOTSUPP;
17711814
}
1815+
if (caps.selector & DEVLINK_PORT_FN_CAP_MIGRATABLE) {
1816+
if (!ops->port_fn_migratable_set) {
1817+
NL_SET_ERR_MSG_ATTR(extack, attr,
1818+
"Port doesn't support migratable function attribute");
1819+
return -EOPNOTSUPP;
1820+
}
1821+
if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PCI_VF) {
1822+
NL_SET_ERR_MSG_ATTR(extack, attr,
1823+
"migratable function attribute supported for VFs only");
1824+
return -EOPNOTSUPP;
1825+
}
1826+
}
17721827
}
17731828
return 0;
17741829
}

0 commit comments

Comments
 (0)