From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT: drivers/infiniband/hw/mlx5/main.c

Change-Id: Ia4e7f7c6ba5e6c94797a77cb8d8228b195f8b5b3
---
 drivers/infiniband/hw/mlx5/main.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -65,6 +65,9 @@ MODULE_ALIAS("auxiliary:mlx5_core.rdma")
 MODULE_ALIAS("auxiliary:mlx5_core.multiport");
 MODULE_ALIAS("auxiliary:mlx5_core.rdma-rep");
 
+#ifdef RETPOLINE_MLNX
+MODULE_INFO(retpoline, "Y");
+#endif
 struct mlx5_ib_event_work {
 	struct work_struct	work;
 	union {
@@ -2205,6 +2208,12 @@ static void mlx5_ib_dealloc_ucontext(str
 	struct mlx5_ib_dev *dev = to_mdev(ibcontext->device);
 	struct mlx5_bfreg_info *bfregi;
 
+#ifndef HAVE_MMU_NOTIFIER_OPS_HAS_FREE_NOTIFIER
+	mutex_lock(&ibcontext->per_mm_list_lock);
+	WARN_ON(!list_empty(&ibcontext->per_mm_list));
+	mutex_unlock(&ibcontext->per_mm_list_lock);
+#endif
+
 	bfregi = &context->bfregi;
 	mlx5_ib_dealloc_transport_domain(dev, context->tdn, context->devx_uid);
 
@@ -2259,9 +2268,11 @@ static int get_extended_index(unsigned l
 }
 
 
+#if defined(HAVE_PUT_TASK_STRUCT_EXPORTED) && defined (HAVE_GET_TASK_PID_EXPORTED) && defined(HAVE_GET_PID_TASK_EXPORTED)
 static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
 {
 }
+#endif
 
 static inline char *mmap_cmd2str(enum mlx5_ib_mmap_cmd cmd)
 {
@@ -2505,6 +2516,7 @@ static int mlx5_ib_mmap(struct ib_uconte
 		if (!dev->wc_support)
 			return -EPERM;
 		fallthrough;
+
 	case MLX5_IB_MMAP_NC_PAGE:
 	case MLX5_IB_MMAP_REGULAR_PAGE:
 		return uar_mmap(dev, command, vma, context);
@@ -3828,7 +3840,9 @@ static const struct uapi_definition mlx5
 static void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev)
 {
 	mlx5_ib_cleanup_multiport_master(dev);
+#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
 	WARN_ON(!xa_empty(&dev->odp_mkeys));
+#endif
 	mutex_destroy(&dev->cap_mask_mutex);
 	WARN_ON(!xa_empty(&dev->sig_mrs));
 	WARN_ON(!bitmap_empty(dev->dm.memic_alloc_pages, MLX5_MAX_MEMIC_PAGES));
@@ -3932,7 +3946,9 @@ static const struct ib_device_ops mlx5_i
 	.destroy_qp = mlx5_ib_destroy_qp,
 	.destroy_srq = mlx5_ib_destroy_srq,
 	.detach_mcast = mlx5_ib_mcg_detach,
+#if defined(HAVE_PUT_TASK_STRUCT_EXPORTED) && defined (HAVE_GET_TASK_PID_EXPORTED) && defined(HAVE_GET_PID_TASK_EXPORTED)
 	.disassociate_ucontext = mlx5_ib_disassociate_ucontext,
+#endif
 	.drain_rq = mlx5_ib_drain_rq,
 	.drain_sq = mlx5_ib_drain_sq,
 	.device_group = &mlx5_attr_group,
@@ -3962,7 +3978,9 @@ static const struct ib_device_ops mlx5_i
 	.query_srq = mlx5_ib_query_srq,
 	.query_ucontext = mlx5_ib_query_ucontext,
 	.reg_user_mr = mlx5_ib_reg_user_mr,
+#ifdef HAVE_DMA_BUF_DYNAMIC_ATTACH_GET_4_PARAMS
 	.reg_user_mr_dmabuf = mlx5_ib_reg_user_mr_dmabuf,
+#endif
 	.req_notify_cq = mlx5_ib_arm_cq,
 	.rereg_user_mr = mlx5_ib_rereg_user_mr,
 	.resize_cq = mlx5_ib_resize_cq,
@@ -3993,9 +4011,11 @@ static const struct ib_device_ops mlx5_i
 
 static const struct ib_device_ops mlx5_ib_dev_sriov_ops = {
 	.get_vf_config = mlx5_ib_get_vf_config,
-	.get_vf_guid = mlx5_ib_get_vf_guid,
 	.get_vf_stats = mlx5_ib_get_vf_stats,
+#ifdef HAVE_IFLA_VF_IB_NODE_PORT_GUID
+	.get_vf_guid = mlx5_ib_get_vf_guid,
 	.set_vf_guid = mlx5_ib_set_vf_guid,
+#endif
 	.set_vf_link_state = mlx5_ib_set_vf_link_state,
 };
 
