diff mbox series

[net-next,V2,7/8] devlink: Expose port function commands to control migratable

Message ID 20221202082622.57765-8-shayd@nvidia.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series devlink: Add port function attribute to enable/disable Roce and migratable | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 383 this patch: 383
netdev/cc_maintainers warning 4 maintainers not CCed: linux-doc@vger.kernel.org edumazet@google.com pabeni@redhat.com corbet@lwn.net
netdev/build_clang success Errors and warnings before: 24 this patch: 24
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 528 this patch: 528
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns WARNING: line length of 89 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 14 this patch: 14
netdev/source_inline success Was 0 now: 0

Commit Message

Shay Drori Dec. 2, 2022, 8:26 a.m. UTC
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 enable 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 <shayd@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Reported-by: kernel test robot <lkp@intel.com>
---
v1->v2:
 - fix documentation warning
---
 .../networking/devlink/devlink-port.rst       | 46 ++++++++++++++++
 include/net/devlink.h                         | 21 ++++++++
 include/uapi/linux/devlink.h                  |  1 +
 net/core/devlink.c                            | 54 +++++++++++++++++++
 4 files changed, 122 insertions(+)

Comments

Jiri Pirko Dec. 2, 2022, 9:02 a.m. UTC | #1
Fri, Dec 02, 2022 at 09:26:21AM CET, shayd@nvidia.com wrote:
>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 enable 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 <shayd@nvidia.com>
>Reviewed-by: Jiri Pirko <jiri@nvidia.com>
>Reported-by: kernel test robot <lkp@intel.com>

I believe that you put reported by only to patches that fix the reported
issue which exists in-tree. It does not apply to issues found on
a submitted patch.
kernel test robot Dec. 2, 2022, 5:26 p.m. UTC | #2
Hi Shay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Shay-Drory/devlink-Add-port-function-attribute-to-enable-disable-Roce-and-migratable/20221202-163357
patch link:    https://lore.kernel.org/r/20221202082622.57765-8-shayd%40nvidia.com
patch subject: [PATCH net-next V2 7/8] devlink: Expose port function commands to control migratable
reproduce:
        # https://github.com/intel-lab-lkp/linux/commit/e6d42af983fe1df41304f5e1da4d7d01e5850b3c
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Shay-Drory/devlink-Add-port-function-attribute-to-enable-disable-Roce-and-migratable/20221202-163357
        git checkout e6d42af983fe1df41304f5e1da4d7d01e5850b3c
        make menuconfig
        # enable CONFIG_COMPILE_TEST, CONFIG_WARN_MISSING_DOCUMENTS, CONFIG_WARN_ABI_ERRORS
        make htmldocs

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> Documentation/networking/devlink/devlink-port.rst:235: WARNING: Literal block expected; none found.

vim +235 Documentation/networking/devlink/devlink-port.rst

   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
Jakub Kicinski Dec. 2, 2022, 6:39 p.m. UTC | #3
On Fri, 2 Dec 2022 10:02:43 +0100 Jiri Pirko wrote:
> I believe that you put reported by only to patches that fix the reported
> issue which exists in-tree. It does not apply to issues found on
> a submitted patch.

+1, I also find adding the tag for previous-revision-issues
misleading
Jakub Kicinski Dec. 2, 2022, 6:58 p.m. UTC | #4
On Fri, 2 Dec 2022 10:26:21 +0200 Shay Drory wrote:
> Expose port function commands to enable / disable migratable
> capability, this is used to set the port function as migratable.

Could you CC Shannon on v3, please?
Shay Drori Dec. 4, 2022, 9:31 a.m. UTC | #5
On 02/12/2022 20:39, Jakub Kicinski wrote:
> External email: Use caution opening links or attachments
>
>
> On Fri, 2 Dec 2022 10:02:43 +0100 Jiri Pirko wrote:
>> I believe that you put reported by only to patches that fix the reported
>> issue which exists in-tree. It does not apply to issues found on
>> a submitted patch.
> +1, I also find adding the tag for previous-revision-issues
> misleading
will drop in next version
diff mbox series

Patch

diff --git a/Documentation/networking/devlink/devlink-port.rst b/Documentation/networking/devlink/devlink-port.rst
index 79f9c0390b47..2e3d17291ae0 100644
--- a/Documentation/networking/devlink/devlink-port.rst
+++ b/Documentation/networking/devlink/devlink-port.rst
@@ -125,6 +125,9 @@  this means a MAC address.
 Users may also set the RoCE capability of the function using
 'devlink port function set roce' command.
 
+Users may also set the function as migratable using
+'devlink port function set migratable' command.
+
 Function attributes
 ===================
 
@@ -194,6 +197,49 @@  VF/SF driver cannot override it.
         function:
             hw_addr 00:00:00:00:00:00 roce disable
 
+migratable capability setup
+---------------------------
+Live migration is the process of transferring a live virtual machine
+from one physical host to another without disrupting its normal
+operation.
+
+User who want PCI VFs to be able to perform live migration need to
+explicitly enable the VF migratable capability.
+
+When user enables migratable capability for a VF, and the HV binds the VF to VFIO driver
+with migration support, the user can migrate the VM with this VF from one HV to a
+different one.
+
+However, when migratable capability is enable, device will disable features which cannot
+be migrated. Thus migratable cap can impose limitations on a VF so let the user decide.
+
+Example of LM with migratable function configuration:
+- Get migratable capability of the VF device::
+
+    $ 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
+
+- Set migratable capability of the VF device::
+
+    $ 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 live migration.
+
 Subfunction
 ============
 
diff --git a/include/net/devlink.h b/include/net/devlink.h
index 20306fb8a1d9..fdb5e8da33ce 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -1470,6 +1470,27 @@  struct devlink_ops {
 	int (*port_function_roce_set)(struct devlink_port *devlink_port,
 				      bool enable,
 				      struct netlink_ext_ack *extack);
+	/**
+	 * @port_function_mig_get: Port function's migratable get function.
+	 *
+	 * Query migratable state of a function managed by the devlink port.
+	 * Return -EOPNOTSUPP if port function migratable handling is not
+	 * supported.
+	 */
+	int (*port_function_mig_get)(struct devlink_port *devlink_port,
+				     bool *is_enable,
+				     struct netlink_ext_ack *extack);
+	/**
+	 * @port_function_mig_set: Port function's migratable set function.
+	 *
+	 * Enable/Disable migratable state of a function managed by the devlink
+	 * port.
+	 * Return -EOPNOTSUPP if port function migratable handling is not
+	 * supported.
+	 */
+	int (*port_function_mig_set)(struct devlink_port *devlink_port,
+				     bool enable,
+				     struct netlink_ext_ack *extack);
 	/**
 	 * port_new() - Add a new port function of a specified flavor
 	 * @devlink: Devlink instance
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 830f8ffd69d1..5a2b87a05c74 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -660,6 +660,7 @@  enum devlink_resource_unit {
 
 enum devlink_port_fn_attr_cap {
 	DEVLINK_PORT_FN_ATTR_CAP_ROCE,
+	DEVLINK_PORT_FN_ATTR_CAP_MIGRATABLE,
 
 	/* Add new caps above */
 	__DEVLINK_PORT_FN_ATTR_CAPS_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index dcf6aae443a9..9ea6d1f854db 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -728,6 +728,29 @@  static int devlink_port_fn_roce_fill(const struct devlink_ops *ops,
 	return 0;
 }
 
+static int devlink_port_function_mig_fill(const struct devlink_ops *ops,
+					  struct devlink_port *devlink_port,
+					  struct nla_bitfield32 *caps,
+					  struct netlink_ext_ack *extack)
+{
+	bool is_enable;
+	int err;
+
+	if (!ops->port_function_mig_get ||
+	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PCI_VF)
+		return 0;
+
+	err = ops->port_function_mig_get(devlink_port, &is_enable, extack);
+	if (err) {
+		if (err == -EOPNOTSUPP)
+			return 0;
+		return err;
+	}
+
+	DEVLINK_PORT_FN_SET_CAP(caps, DEVLINK_PORT_FN_CAP(MIGRATABLE), is_enable);
+	return 0;
+}
+
 static int devlink_port_fn_caps_fill(const struct devlink_ops *ops,
 				     struct devlink_port *devlink_port,
 				     struct sk_buff *msg,
@@ -741,6 +764,10 @@  static int devlink_port_fn_caps_fill(const struct devlink_ops *ops,
 	if (err)
 		return err;
 
+	err = devlink_port_function_mig_fill(ops, devlink_port, &caps, extack);
+	if (err)
+		return err;
+
 	if (!caps.selector)
 		return 0;
 	err = nla_put_bitfield32(msg, DEVLINK_PORT_FN_ATTR_CAPS, caps.value,
@@ -1335,6 +1362,15 @@  static int devlink_port_fn_state_fill(const struct devlink_ops *ops,
 	return 0;
 }
 
+static int
+devlink_port_fn_mig_set(struct devlink_port *devlink_port, bool enable,
+			struct netlink_ext_ack *extack)
+{
+	const struct devlink_ops *ops = devlink_port->devlink->ops;
+
+	return ops->port_function_mig_set(devlink_port, enable, extack);
+}
+
 static int
 devlink_port_fn_roce_set(struct devlink_port *devlink_port, bool enable,
 			 struct netlink_ext_ack *extack)
@@ -1361,6 +1397,13 @@  static int devlink_port_fn_caps_set(struct devlink_port *devlink_port,
 		if (err)
 			return err;
 	}
+	if (caps.selector & DEVLINK_PORT_FN_CAP(MIGRATABLE)) {
+		err = devlink_port_fn_mig_set(devlink_port, caps_value &
+					      DEVLINK_PORT_FN_CAP(MIGRATABLE),
+					      extack);
+		if (err)
+			return err;
+	}
 	return 0;
 }
 
@@ -1781,6 +1824,17 @@  static int devlink_port_function_validate(struct devlink_port *devlink_port,
 					    "Port doesn't support RoCE function attribute");
 			return -EOPNOTSUPP;
 		}
+		if (caps.selector & DEVLINK_PORT_FN_CAP(MIGRATABLE)) {
+			if (!ops->port_function_mig_set) {
+				NL_SET_ERR_MSG_ATTR(extack, attr,
+						    "Port doesn't support migratable function attribute");
+			}
+			if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PCI_VF) {
+				NL_SET_ERR_MSG_ATTR(extack, attr,
+						    "migratable function attribute supported for VFs only");
+				return -EOPNOTSUPP;
+			}
+		}
 	}
 	return 0;
 }