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

Change-Id: If8d258c0a0d18190c8eca954baf1d8d620391877
---
 drivers/infiniband/core/ucma.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -43,9 +43,10 @@
 #include <linux/sysctl.h>
 #include <linux/module.h>
 #include <linux/nsproxy.h>
-
 #include <linux/nospec.h>
-
+#ifdef HAVE_BASECODE_EXTRAS
+#include <linux/vfio.h>
+#endif
 #include <rdma/rdma_user_cm.h>
 #include <rdma/ib_marshall.h>
 #include <rdma/rdma_cm.h>
@@ -59,9 +60,13 @@
 MODULE_AUTHOR("Sean Hefty");
 MODULE_DESCRIPTION("RDMA Userspace Connection Manager Access");
 MODULE_LICENSE("Dual BSD/GPL");
+#ifdef RETPOLINE_MLNX
+MODULE_INFO(retpoline, "Y");
+#endif
 
 static unsigned int max_backlog = 1024;
 
+#ifndef CONFIG_SYSCTL_SYSCALL_CHECK
 static struct ctl_table_header *ucma_ctl_table_hdr;
 static struct ctl_table ucma_ctl_table[] = {
 	{
@@ -71,7 +76,11 @@ static struct ctl_table ucma_ctl_table[]
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
 	},
+#ifndef HAVE_REMOVE_SENTINEL_FROM_CTL_TABLE
+	{ }
+#endif
 };
+#endif
 
 struct ucma_file {
 	struct mutex		mut;
@@ -1733,7 +1742,6 @@ static ssize_t ucma_write(struct file *f
 	if (hdr.cmd >= ARRAY_SIZE(ucma_cmd_table))
 		return -EINVAL;
 	hdr.cmd = array_index_nospec(hdr.cmd, ARRAY_SIZE(ucma_cmd_table));
-
 	if (hdr.in + sizeof(hdr) > len)
 		return -EINVAL;
 
@@ -1784,7 +1792,11 @@ static int ucma_open(struct inode *inode
 	filp->private_data = file;
 	file->filp = filp;
 
+#ifdef HAVE_STREAM_OPEN
 	return stream_open(inode, filp);
+#else
+	return nonseekable_open(inode, filp);
+#endif
 }
 
 static int ucma_close(struct inode *inode, struct file *filp)
@@ -1862,12 +1874,14 @@ static int __init ucma_init(void)
 		goto err1;
 	}
 
+#ifndef CONFIG_SYSCTL_SYSCALL_CHECK
 	ucma_ctl_table_hdr = register_net_sysctl(&init_net, "net/rdma_ucm", ucma_ctl_table);
 	if (!ucma_ctl_table_hdr) {
 		pr_err("rdma_ucm: couldn't register sysctl paths\n");
 		ret = -ENOMEM;
 		goto err2;
 	}
+#endif
 
 	ret = ib_register_client(&rdma_cma_client);
 	if (ret)
@@ -1876,8 +1890,10 @@ static int __init ucma_init(void)
 	return 0;
 err3:
 	unregister_net_sysctl_table(ucma_ctl_table_hdr);
+#ifndef CONFIG_SYSCTL_SYSCALL_CHECK
 err2:
 	device_remove_file(ucma_misc.this_device, &dev_attr_abi_version);
+#endif
 err1:
 	misc_deregister(&ucma_misc);
 	return ret;
@@ -1886,7 +1902,9 @@ err1:
 static void __exit ucma_cleanup(void)
 {
 	ib_unregister_client(&rdma_cma_client);
+#ifndef CONFIG_SYSCTL_SYSCALL_CHECK
 	unregister_net_sysctl_table(ucma_ctl_table_hdr);
+#endif
 	device_remove_file(ucma_misc.this_device, &dev_attr_abi_version);
 	misc_deregister(&ucma_misc);
 }
