linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH rdma-next 0/2] Allow netlink commands in non init_net net namespace
@ 2019-07-04 13:04 Leon Romanovsky
  2019-07-04 13:04 ` [PATCH rdma-next 1/2] IB/core: Work on the caller socket net namespace in nldev_newlink() Leon Romanovsky
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Leon Romanovsky @ 2019-07-04 13:04 UTC (permalink / raw)
  To: Doug Ledford, Jason Gunthorpe
  Cc: Leon Romanovsky, RDMA mailing list, Parav Pandit, Steve Wise

From: Leon Romanovsky <leonro@mellanox.com>

Now that RDMA devices can be attached to specific net namespace,
allow netlink commands in non init_net namespace.

Parav Pandit (2):
  IB/core: Work on the caller socket net namespace in nldev_newlink()
  IB: Support netlink commands in non init_net net namespaces

 drivers/infiniband/core/addr.c      |  2 +-
 drivers/infiniband/core/core_priv.h | 19 +++++++++--
 drivers/infiniband/core/device.c    | 34 ++++++------------
 drivers/infiniband/core/iwpm_msg.c  |  8 ++---
 drivers/infiniband/core/iwpm_util.c |  6 ++--
 drivers/infiniband/core/netlink.c   | 53 ++++++++++++++++++-----------
 drivers/infiniband/core/nldev.c     | 22 ++++++------
 drivers/infiniband/core/sa_query.c  |  2 +-
 include/rdma/rdma_netlink.h         | 10 ++++--
 9 files changed, 87 insertions(+), 69 deletions(-)

--
2.20.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH rdma-next 1/2] IB/core: Work on the caller socket net namespace in nldev_newlink()
  2019-07-04 13:04 [PATCH rdma-next 0/2] Allow netlink commands in non init_net net namespace Leon Romanovsky
@ 2019-07-04 13:04 ` Leon Romanovsky
  2019-07-04 13:04 ` [PATCH rdma-next 2/2] IB: Support netlink commands in non init_net net namespaces Leon Romanovsky
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Leon Romanovsky @ 2019-07-04 13:04 UTC (permalink / raw)
  To: Doug Ledford, Jason Gunthorpe
  Cc: Leon Romanovsky, RDMA mailing list, Parav Pandit, Steve Wise

From: Parav Pandit <parav@mellanox.com>

While creating new RDMA devices based on netdevice name,
consider the net namespace of the caller skb's socket similar to rest of
the doit() callbacks and nldev_dellink() which deletes the RDMA device
created using nldev_newlink().

Fixes: 3856ec4b93c94 ("RDMA/core: Add RDMA_NLDEV_CMD_NEWLINK/DELLINK support")
Signed-off-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 drivers/infiniband/core/nldev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index d9f2a30e6467..783e465e7c41 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -1476,7 +1476,7 @@ static int nldev_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 	nla_strlcpy(ndev_name, tb[RDMA_NLDEV_ATTR_NDEV_NAME],
 		    sizeof(ndev_name));

-	ndev = dev_get_by_name(&init_net, ndev_name);
+	ndev = dev_get_by_name(sock_net(skb->sk), ndev_name);
 	if (!ndev)
 		return -ENODEV;

--
2.20.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH rdma-next 2/2] IB: Support netlink commands in non init_net net namespaces
  2019-07-04 13:04 [PATCH rdma-next 0/2] Allow netlink commands in non init_net net namespace Leon Romanovsky
  2019-07-04 13:04 ` [PATCH rdma-next 1/2] IB/core: Work on the caller socket net namespace in nldev_newlink() Leon Romanovsky
@ 2019-07-04 13:04 ` Leon Romanovsky
  2019-07-08 20:20   ` Jason Gunthorpe
  2019-07-04 17:34 ` [PATCH rdma-next 0/2] Allow netlink commands in non init_net net namespace Jason Gunthorpe
  2019-07-08 20:21 ` Jason Gunthorpe
  3 siblings, 1 reply; 10+ messages in thread
From: Leon Romanovsky @ 2019-07-04 13:04 UTC (permalink / raw)
  To: Doug Ledford, Jason Gunthorpe
  Cc: Leon Romanovsky, RDMA mailing list, Parav Pandit, Steve Wise

From: Parav Pandit <parav@mellanox.com>

Now that IB core supports RDMA device binding with specific net
namespace, enable IB core to accept netlink commands in non init_net
namespaces.

This is done by having per net namespace netlink socket.

At present only netlink device handling client RDMA_NL_NLDEV supports
device handling in multiple net namespaces.
Hence do not accept netlink messages for other clients in non init_net
net namespaces.

Signed-off-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 drivers/infiniband/core/addr.c      |  2 +-
 drivers/infiniband/core/core_priv.h | 19 +++++++++--
 drivers/infiniband/core/device.c    | 34 ++++++------------
 drivers/infiniband/core/iwpm_msg.c  |  8 ++---
 drivers/infiniband/core/iwpm_util.c |  6 ++--
 drivers/infiniband/core/netlink.c   | 53 ++++++++++++++++++-----------
 drivers/infiniband/core/nldev.c     | 20 +++++------
 drivers/infiniband/core/sa_query.c  |  2 +-
 include/rdma/rdma_netlink.h         | 10 ++++--
 9 files changed, 86 insertions(+), 68 deletions(-)

diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
index 2f7d14159841..9be0400a9a51 100644
--- a/drivers/infiniband/core/addr.c
+++ b/drivers/infiniband/core/addr.c
@@ -183,7 +183,7 @@ static int ib_nl_ip_send_msg(struct rdma_dev_addr *dev_addr,

 	/* Repair the nlmsg header length */
 	nlmsg_end(skb, nlh);
-	rdma_nl_multicast(skb, RDMA_NL_GROUP_LS, GFP_KERNEL);
+	rdma_nl_multicast(&init_net, skb, RDMA_NL_GROUP_LS, GFP_KERNEL);

 	/* Make the request retry, so when we get the response from userspace
 	 * we will have something.
diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h
index 888d89ce81df..b441a31fd731 100644
--- a/drivers/infiniband/core/core_priv.h
+++ b/drivers/infiniband/core/core_priv.h
@@ -54,8 +54,21 @@ struct pkey_index_qp_list {
 	struct list_head    qp_list;
 };

+/**
+ * struct rdma_dev_net - rdma net namespace metadata for a net
+ * @nl_sock:	Pointer to netlink socket
+ * @net:	Pointer to owner net namespace
+ * @id:		xarray id to identify the net namespace.
+ */
+struct rdma_dev_net {
+	struct sock *nl_sock;
+	possible_net_t net;
+	u32 id;
+};
+
 extern const struct attribute_group ib_dev_attr_group;
 extern bool ib_devices_shared_netns;
+extern unsigned int rdma_dev_net_id;

 int ib_device_register_sysfs(struct ib_device *device);
 void ib_device_unregister_sysfs(struct ib_device *device);
@@ -179,9 +192,6 @@ void ib_mad_cleanup(void);
 int ib_sa_init(void);
 void ib_sa_cleanup(void);

-int rdma_nl_init(void);
-void rdma_nl_exit(void);
-
 int ib_nl_handle_resolve_resp(struct sk_buff *skb,
 			      struct nlmsghdr *nlh,
 			      struct netlink_ext_ack *extack);
@@ -362,4 +372,7 @@ void ib_port_unregister_module_stat(struct kobject *kobj);

 int ib_device_set_netns_put(struct sk_buff *skb,
 			    struct ib_device *dev, u32 ns_fd);
+
+int rdma_nl_net_init(struct rdma_dev_net *rnet);
+void rdma_nl_net_exit(struct rdma_dev_net *rnet);
 #endif /* _CORE_PRIV_H */
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index adf8d93bb42d..b404a8dfea89 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -105,17 +105,7 @@ static DECLARE_RWSEM(clients_rwsem);
  */
 #define CLIENT_DATA_REGISTERED XA_MARK_1

-/**
- * struct rdma_dev_net - rdma net namespace metadata for a net
- * @net:	Pointer to owner net namespace
- * @id:		xarray id to identify the net namespace.
- */
-struct rdma_dev_net {
-	possible_net_t net;
-	u32 id;
-};
-
-static unsigned int rdma_dev_net_id;
+unsigned int rdma_dev_net_id;

 /*
  * A list of net namespaces is maintained in an xarray. This is necessary
@@ -1084,6 +1074,7 @@ static void rdma_dev_exit_net(struct net *net)
 	}
 	up_read(&devices_rwsem);

+	rdma_nl_net_exit(rnet);
 	xa_erase(&rdma_nets, rnet->id);
 }

@@ -1094,15 +1085,21 @@ static __net_init int rdma_dev_init_net(struct net *net)
 	struct ib_device *dev;
 	int ret;

+	write_pnet(&rnet->net, net);
+
+	ret = rdma_nl_net_init(rnet);
+	if (ret)
+		return ret;
+
 	/* No need to create any compat devices in default init_net. */
 	if (net_eq(net, &init_net))
 		return 0;

-	write_pnet(&rnet->net, net);
-
 	ret = xa_alloc(&rdma_nets, &rnet->id, rnet, xa_limit_32b, GFP_KERNEL);
-	if (ret)
+	if (ret) {
+		rdma_nl_net_exit(rnet);
 		return ret;
+	}

 	down_read(&devices_rwsem);
 	xa_for_each_marked (&devices, index, dev, DEVICE_REGISTERED) {
@@ -2629,12 +2626,6 @@ static int __init ib_core_init(void)
 		goto err_comp_unbound;
 	}

-	ret = rdma_nl_init();
-	if (ret) {
-		pr_warn("Couldn't init IB netlink interface: err %d\n", ret);
-		goto err_sysfs;
-	}
-
 	ret = addr_init();
 	if (ret) {
 		pr_warn("Could't init IB address resolution\n");
@@ -2680,8 +2671,6 @@ static int __init ib_core_init(void)
 err_addr:
 	addr_cleanup();
 err_ibnl:
-	rdma_nl_exit();
-err_sysfs:
 	class_unregister(&ib_class);
 err_comp_unbound:
 	destroy_workqueue(ib_comp_unbound_wq);
@@ -2702,7 +2691,6 @@ static void __exit ib_core_cleanup(void)
 	ib_sa_cleanup();
 	ib_mad_cleanup();
 	addr_cleanup();
-	rdma_nl_exit();
 	class_unregister(&ib_class);
 	destroy_workqueue(ib_comp_unbound_wq);
 	destroy_workqueue(ib_comp_wq);
diff --git a/drivers/infiniband/core/iwpm_msg.c b/drivers/infiniband/core/iwpm_msg.c
index 2452b0ddcf0d..f1a873d4e842 100644
--- a/drivers/infiniband/core/iwpm_msg.c
+++ b/drivers/infiniband/core/iwpm_msg.c
@@ -112,7 +112,7 @@ int iwpm_register_pid(struct iwpm_dev_data *pm_msg, u8 nl_client)
 	pr_debug("%s: Multicasting a nlmsg (dev = %s ifname = %s iwpm = %s)\n",
 		__func__, pm_msg->dev_name, pm_msg->if_name, iwpm_ulib_name);

-	ret = rdma_nl_multicast(skb, RDMA_NL_GROUP_IWPM, GFP_KERNEL);
+	ret = rdma_nl_multicast(&init_net, skb, RDMA_NL_GROUP_IWPM, GFP_KERNEL);
 	if (ret) {
 		skb = NULL; /* skb is freed in the netlink send-op handling */
 		iwpm_user_pid = IWPM_PID_UNAVAILABLE;
@@ -202,7 +202,7 @@ int iwpm_add_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client)
 	nlmsg_end(skb, nlh);
 	nlmsg_request->req_buffer = pm_msg;

-	ret = rdma_nl_unicast_wait(skb, iwpm_user_pid);
+	ret = rdma_nl_unicast_wait(&init_net, skb, iwpm_user_pid);
 	if (ret) {
 		skb = NULL; /* skb is freed in the netlink send-op handling */
 		iwpm_user_pid = IWPM_PID_UNDEFINED;
@@ -297,7 +297,7 @@ int iwpm_add_and_query_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client)
 	nlmsg_end(skb, nlh);
 	nlmsg_request->req_buffer = pm_msg;

-	ret = rdma_nl_unicast_wait(skb, iwpm_user_pid);
+	ret = rdma_nl_unicast_wait(&init_net, skb, iwpm_user_pid);
 	if (ret) {
 		skb = NULL; /* skb is freed in the netlink send-op handling */
 		err_str = "Unable to send a nlmsg";
@@ -364,7 +364,7 @@ int iwpm_remove_mapping(struct sockaddr_storage *local_addr, u8 nl_client)

 	nlmsg_end(skb, nlh);

-	ret = rdma_nl_unicast_wait(skb, iwpm_user_pid);
+	ret = rdma_nl_unicast_wait(&init_net, skb, iwpm_user_pid);
 	if (ret) {
 		skb = NULL; /* skb is freed in the netlink send-op handling */
 		iwpm_user_pid = IWPM_PID_UNDEFINED;
diff --git a/drivers/infiniband/core/iwpm_util.c b/drivers/infiniband/core/iwpm_util.c
index 41929bb83739..c7ad3499228c 100644
--- a/drivers/infiniband/core/iwpm_util.c
+++ b/drivers/infiniband/core/iwpm_util.c
@@ -645,7 +645,7 @@ static int send_mapinfo_num(u32 mapping_num, u8 nl_client, int iwpm_pid)

 	nlmsg_end(skb, nlh);

-	ret = rdma_nl_unicast(skb, iwpm_pid);
+	ret = rdma_nl_unicast(&init_net, skb, iwpm_pid);
 	if (ret) {
 		skb = NULL;
 		err_str = "Unable to send a nlmsg";
@@ -674,7 +674,7 @@ static int send_nlmsg_done(struct sk_buff *skb, u8 nl_client, int iwpm_pid)
 		return -ENOMEM;
 	}
 	nlh->nlmsg_type = NLMSG_DONE;
-	ret = rdma_nl_unicast(skb, iwpm_pid);
+	ret = rdma_nl_unicast(&init_net, skb, iwpm_pid);
 	if (ret)
 		pr_warn("%s Unable to send a nlmsg\n", __func__);
 	return ret;
@@ -824,7 +824,7 @@ int iwpm_send_hello(u8 nl_client, int iwpm_pid, u16 abi_version)
 		goto hello_num_error;
 	nlmsg_end(skb, nlh);

-	ret = rdma_nl_unicast(skb, iwpm_pid);
+	ret = rdma_nl_unicast(&init_net, skb, iwpm_pid);
 	if (ret) {
 		skb = NULL;
 		err_str = "Unable to send a nlmsg";
diff --git a/drivers/infiniband/core/netlink.c b/drivers/infiniband/core/netlink.c
index eecfc0b377c9..676db08e7b4e 100644
--- a/drivers/infiniband/core/netlink.c
+++ b/drivers/infiniband/core/netlink.c
@@ -36,20 +36,22 @@
 #include <linux/export.h>
 #include <net/netlink.h>
 #include <net/net_namespace.h>
+#include <net/netns/generic.h>
 #include <net/sock.h>
 #include <rdma/rdma_netlink.h>
 #include <linux/module.h>
 #include "core_priv.h"

 static DEFINE_MUTEX(rdma_nl_mutex);
-static struct sock *nls;
 static struct {
 	const struct rdma_nl_cbs   *cb_table;
 } rdma_nl_types[RDMA_NL_NUM_CLIENTS];

 bool rdma_nl_chk_listeners(unsigned int group)
 {
-	return netlink_has_listeners(nls, group);
+	struct rdma_dev_net *rnet = net_generic(&init_net, rdma_dev_net_id);
+
+	return netlink_has_listeners(rnet->nl_sock, group);
 }
 EXPORT_SYMBOL(rdma_nl_chk_listeners);

@@ -73,13 +75,21 @@ static bool is_nl_msg_valid(unsigned int type, unsigned int op)
 	return (op < max_num_ops[type]) ? true : false;
 }

-static bool is_nl_valid(unsigned int type, unsigned int op)
+static bool
+is_nl_valid(const struct sk_buff *skb, unsigned int type, unsigned int op)
 {
 	const struct rdma_nl_cbs *cb_table;

 	if (!is_nl_msg_valid(type, op))
 		return false;

+	/*
+	 * Currently only NLDEV client is supporting netlink commands in
+	 * non init_net net namespace.
+	 */
+	if (sock_net(skb->sk) != &init_net && type != RDMA_NL_NLDEV)
+		return false;
+
 	if (!rdma_nl_types[type].cb_table) {
 		mutex_unlock(&rdma_nl_mutex);
 		request_module("rdma-netlink-subsys-%d", type);
@@ -161,7 +171,7 @@ static int rdma_nl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
 	unsigned int op = RDMA_NL_GET_OP(type);
 	const struct rdma_nl_cbs *cb_table;

-	if (!is_nl_valid(index, op))
+	if (!is_nl_valid(skb, index, op))
 		return -EINVAL;

 	cb_table = rdma_nl_types[index].cb_table;
@@ -185,7 +195,7 @@ static int rdma_nl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
 			.dump = cb_table[op].dump,
 		};
 		if (c.dump)
-			return netlink_dump_start(nls, skb, nlh, &c);
+			return netlink_dump_start(skb->sk, skb, nlh, &c);
 		return -EINVAL;
 	}

@@ -258,52 +268,55 @@ static void rdma_nl_rcv(struct sk_buff *skb)
 	mutex_unlock(&rdma_nl_mutex);
 }

-int rdma_nl_unicast(struct sk_buff *skb, u32 pid)
+int rdma_nl_unicast(struct net *net, struct sk_buff *skb, u32 pid)
 {
+	struct rdma_dev_net *rnet = net_generic(net, rdma_dev_net_id);
 	int err;

-	err = netlink_unicast(nls, skb, pid, MSG_DONTWAIT);
+	err = netlink_unicast(rnet->nl_sock, skb, pid, MSG_DONTWAIT);
 	return (err < 0) ? err : 0;
 }
 EXPORT_SYMBOL(rdma_nl_unicast);

-int rdma_nl_unicast_wait(struct sk_buff *skb, __u32 pid)
+int rdma_nl_unicast_wait(struct net *net, struct sk_buff *skb, __u32 pid)
 {
+	struct rdma_dev_net *rnet = net_generic(net, rdma_dev_net_id);
 	int err;

-	err = netlink_unicast(nls, skb, pid, 0);
+	err = netlink_unicast(rnet->nl_sock, skb, pid, 0);
 	return (err < 0) ? err : 0;
 }
 EXPORT_SYMBOL(rdma_nl_unicast_wait);

-int rdma_nl_multicast(struct sk_buff *skb, unsigned int group, gfp_t flags)
+int rdma_nl_multicast(struct net *net, struct sk_buff *skb,
+		      unsigned int group, gfp_t flags)
 {
-	return nlmsg_multicast(nls, skb, 0, group, flags);
+	struct rdma_dev_net *rnet = net_generic(net, rdma_dev_net_id);
+
+	return nlmsg_multicast(rnet->nl_sock, skb, 0, group, flags);
 }
 EXPORT_SYMBOL(rdma_nl_multicast);

-int __init rdma_nl_init(void)
+int rdma_nl_net_init(struct rdma_dev_net *rnet)
 {
+	struct net *net = read_pnet(&rnet->net);
 	struct netlink_kernel_cfg cfg = {
 		.input	= rdma_nl_rcv,
 	};
+	struct sock *nls;

-	nls = netlink_kernel_create(&init_net, NETLINK_RDMA, &cfg);
+	nls = netlink_kernel_create(net, NETLINK_RDMA, &cfg);
 	if (!nls)
 		return -ENOMEM;

 	nls->sk_sndtimeo = 10 * HZ;
+	rnet->nl_sock = nls;
 	return 0;
 }

-void rdma_nl_exit(void)
+void rdma_nl_net_exit(struct rdma_dev_net *rnet)
 {
-	int idx;
-
-	for (idx = 0; idx < RDMA_NL_NUM_CLIENTS; idx++)
-		rdma_nl_unregister(idx);
-
-	netlink_kernel_release(nls);
+	netlink_kernel_release(rnet->nl_sock);
 }

 MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_RDMA);
diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index 783e465e7c41..e287b71a1cfd 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -832,7 +832,7 @@ static int nldev_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
 	nlmsg_end(msg, nlh);

 	ib_device_put(device);
-	return rdma_nl_unicast(msg, NETLINK_CB(skb).portid);
+	return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);

 err_free:
 	nlmsg_free(msg);
@@ -972,7 +972,7 @@ static int nldev_port_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
 	nlmsg_end(msg, nlh);
 	ib_device_put(device);

-	return rdma_nl_unicast(msg, NETLINK_CB(skb).portid);
+	return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);

 err_free:
 	nlmsg_free(msg);
@@ -1074,7 +1074,7 @@ static int nldev_res_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,

 	nlmsg_end(msg, nlh);
 	ib_device_put(device);
-	return rdma_nl_unicast(msg, NETLINK_CB(skb).portid);
+	return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);

 err_free:
 	nlmsg_free(msg);
@@ -1251,7 +1251,7 @@ static int res_get_common_doit(struct sk_buff *skb, struct nlmsghdr *nlh,

 	nlmsg_end(msg, nlh);
 	ib_device_put(device);
-	return rdma_nl_unicast(msg, NETLINK_CB(skb).portid);
+	return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);

 err_free:
 	nlmsg_free(msg);
@@ -1596,7 +1596,7 @@ static int nldev_get_chardev(struct sk_buff *skb, struct nlmsghdr *nlh,
 	put_device(data.cdev);
 	if (ibdev)
 		ib_device_put(ibdev);
-	return rdma_nl_unicast(msg, NETLINK_CB(skb).portid);
+	return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);

 out_data:
 	put_device(data.cdev);
@@ -1636,7 +1636,7 @@ static int nldev_sys_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
 		return err;
 	}
 	nlmsg_end(msg, nlh);
-	return rdma_nl_unicast(msg, NETLINK_CB(skb).portid);
+	return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);
 }

 static int nldev_set_sys_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -1734,7 +1734,7 @@ static int nldev_stat_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,

 	nlmsg_end(msg, nlh);
 	ib_device_put(device);
-	return rdma_nl_unicast(msg, NETLINK_CB(skb).portid);
+	return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);

 err_fill:
 	rdma_counter_unbind_qpn(device, port, qpn, cntn);
@@ -1802,7 +1802,7 @@ static int nldev_stat_del_doit(struct sk_buff *skb, struct nlmsghdr *nlh,

 	nlmsg_end(msg, nlh);
 	ib_device_put(device);
-	return rdma_nl_unicast(msg, NETLINK_CB(skb).portid);
+	return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);

 err_fill:
 	rdma_counter_bind_qpn(device, port, qpn, cntn);
@@ -1893,7 +1893,7 @@ static int stat_get_doit_default_counter(struct sk_buff *skb,
 	mutex_unlock(&stats->lock);
 	nlmsg_end(msg, nlh);
 	ib_device_put(device);
-	return rdma_nl_unicast(msg, NETLINK_CB(skb).portid);
+	return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);

 err_table:
 	nla_nest_cancel(msg, table_attr);
@@ -1961,7 +1961,7 @@ static int stat_get_doit_qp(struct sk_buff *skb, struct nlmsghdr *nlh,

 	nlmsg_end(msg, nlh);
 	ib_device_put(device);
-	return rdma_nl_unicast(msg, NETLINK_CB(skb).portid);
+	return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);

 err_msg:
 	nlmsg_free(msg);
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index 7d8071c7e564..17fc2936c077 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -860,7 +860,7 @@ static int ib_nl_send_msg(struct ib_sa_query *query, gfp_t gfp_mask)
 	/* Repair the nlmsg header length */
 	nlmsg_end(skb, nlh);

-	return rdma_nl_multicast(skb, RDMA_NL_GROUP_LS, gfp_mask);
+	return rdma_nl_multicast(&init_net, skb, RDMA_NL_GROUP_LS, gfp_mask);
 }

 static int ib_nl_make_request(struct ib_sa_query *query, gfp_t gfp_mask)
diff --git a/include/rdma/rdma_netlink.h b/include/rdma/rdma_netlink.h
index 6631624e4d7c..ab22759de7ea 100644
--- a/include/rdma/rdma_netlink.h
+++ b/include/rdma/rdma_netlink.h
@@ -76,28 +76,32 @@ int ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh,

 /**
  * Send the supplied skb to a specific userspace PID.
+ * @net: Net namespace in which to send the skb
  * @skb: The netlink skb
  * @pid: Userspace netlink process ID
  * Returns 0 on success or a negative error code.
  */
-int rdma_nl_unicast(struct sk_buff *skb, u32 pid);
+int rdma_nl_unicast(struct net *net, struct sk_buff *skb, u32 pid);

 /**
  * Send, with wait/1 retry, the supplied skb to a specific userspace PID.
+ * @net: Net namespace in which to send the skb
  * @skb: The netlink skb
  * @pid: Userspace netlink process ID
  * Returns 0 on success or a negative error code.
  */
-int rdma_nl_unicast_wait(struct sk_buff *skb, __u32 pid);
+int rdma_nl_unicast_wait(struct net *net, struct sk_buff *skb, __u32 pid);

 /**
  * Send the supplied skb to a netlink group.
+ * @net: Net namespace in which to send the skb
  * @skb: The netlink skb
  * @group: Netlink group ID
  * @flags: allocation flags
  * Returns 0 on success or a negative error code.
  */
-int rdma_nl_multicast(struct sk_buff *skb, unsigned int group, gfp_t flags);
+int rdma_nl_multicast(struct net *net, struct sk_buff *skb,
+		      unsigned int group, gfp_t flags);

 /**
  * Check if there are any listeners to the netlink group
--
2.20.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH rdma-next 0/2] Allow netlink commands in non init_net net namespace
  2019-07-04 13:04 [PATCH rdma-next 0/2] Allow netlink commands in non init_net net namespace Leon Romanovsky
  2019-07-04 13:04 ` [PATCH rdma-next 1/2] IB/core: Work on the caller socket net namespace in nldev_newlink() Leon Romanovsky
  2019-07-04 13:04 ` [PATCH rdma-next 2/2] IB: Support netlink commands in non init_net net namespaces Leon Romanovsky
@ 2019-07-04 17:34 ` Jason Gunthorpe
  2019-07-05  2:12   ` Parav Pandit
  2019-07-08 20:21 ` Jason Gunthorpe
  3 siblings, 1 reply; 10+ messages in thread
From: Jason Gunthorpe @ 2019-07-04 17:34 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Doug Ledford, Leon Romanovsky, RDMA mailing list, Parav Pandit,
	Steve Wise

On Thu, Jul 04, 2019 at 04:04:00PM +0300, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@mellanox.com>
> 
> Now that RDMA devices can be attached to specific net namespace,
> allow netlink commands in non init_net namespace.
> 
> Parav Pandit (2):
>   IB/core: Work on the caller socket net namespace in nldev_newlink()
>   IB: Support netlink commands in non init_net net namespaces

Could someone please confirm that all the new libibverbs stuff works
properly in a container after this series?

Jason

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH rdma-next 0/2] Allow netlink commands in non init_net net namespace
  2019-07-04 17:34 ` [PATCH rdma-next 0/2] Allow netlink commands in non init_net net namespace Jason Gunthorpe
@ 2019-07-05  2:12   ` Parav Pandit
  0 siblings, 0 replies; 10+ messages in thread
From: Parav Pandit @ 2019-07-05  2:12 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Leon Romanovsky, Doug Ledford, Leon Romanovsky,
	RDMA mailing list, Parav Pandit, Steve Wise

On Thu, Jul 4, 2019 at 11:46 PM Jason Gunthorpe <jgg@ziepe.ca> wrote:
>
> On Thu, Jul 04, 2019 at 04:04:00PM +0300, Leon Romanovsky wrote:
> > From: Leon Romanovsky <leonro@mellanox.com>
> >
> > Now that RDMA devices can be attached to specific net namespace,
> > allow netlink commands in non init_net namespace.
> >
> > Parav Pandit (2):
> >   IB/core: Work on the caller socket net namespace in nldev_newlink()
> >   IB: Support netlink commands in non init_net net namespaces
>
> Could someone please confirm that all the new libibverbs stuff works
> properly in a container after this series?
>
Hi Jason,

I tested rping using rdma-core from [1] where I had to skip siw
compilation due to a compile error.
I used kernel from [2].

[1] https://github.com/jgunthorpe/rdma-plumbing.git branch netlink
[2] https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git/log/?h=rdma-next

Test were done in non init_net net namespace.
It looks good.
A sample kernel frace to double confirm below.

Due to our internal net-next-mlx5 behind of nldev patches, I couldn't
test mdev devices yet with this series.

19)               |  rdma_nl_rcv [ib_core]() {
19)               |    rdma_nl_rcv_msg [ib_core]() {
19)               |      nldev_get_chardev [ib_core]() {
19)   2.220 us    |        ib_device_get_by_index [ib_core]();
19)               |        ib_get_client_nl_info [ib_core]() {
19)               |          __ib_get_client_nl_info [ib_core]() {
19)   1.697 us    |            xan_find_marked.constprop.26 [ib_core]();
19)   1.024 us    |            xan_find_marked.constprop.26 [ib_core]();
19)   1.023 us    |            xan_find_marked.constprop.26 [ib_core]();
19)   1.153 us    |            xan_find_marked.constprop.26 [ib_core]();
19)   0.574 us    |            ib_uverbs_get_nl_info [ib_uverbs]();
19) + 12.507 us   |          }
19) + 13.533 us   |        }
19)   0.380 us    |        ib_device_put [ib_core]();
19)   4.600 us    |        rdma_nl_unicast [ib_core]();
19) + 26.533 us   |      }
19) + 27.457 us   |    }

Some issue with my outlook email. So replying from gmail..
Thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH rdma-next 2/2] IB: Support netlink commands in non init_net net namespaces
  2019-07-04 13:04 ` [PATCH rdma-next 2/2] IB: Support netlink commands in non init_net net namespaces Leon Romanovsky
@ 2019-07-08 20:20   ` Jason Gunthorpe
  2019-07-09  6:38     ` Leon Romanovsky
  2019-07-09  6:55     ` Parav Pandit
  0 siblings, 2 replies; 10+ messages in thread
From: Jason Gunthorpe @ 2019-07-08 20:20 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Doug Ledford, Leon Romanovsky, RDMA mailing list, Parav Pandit,
	Steve Wise

On Thu, Jul 04, 2019 at 04:04:02PM +0300, Leon Romanovsky wrote:
> -int rdma_nl_unicast(struct sk_buff *skb, u32 pid)
> +int rdma_nl_unicast(struct net *net, struct sk_buff *skb, u32 pid)
>  {
> +	struct rdma_dev_net *rnet = net_generic(net, rdma_dev_net_id);

This should be a proper type safe accessor in all places

> -void rdma_nl_exit(void)
> +void rdma_nl_net_exit(struct rdma_dev_net *rnet)
>  {
> -	int idx;
> -
> -	for (idx = 0; idx < RDMA_NL_NUM_CLIENTS; idx++)
> -		rdma_nl_unregister(idx);

There should be a WARN_ON during the module unload that no NL clients
are still registered

Thanks,
Jason

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH rdma-next 0/2] Allow netlink commands in non init_net net namespace
  2019-07-04 13:04 [PATCH rdma-next 0/2] Allow netlink commands in non init_net net namespace Leon Romanovsky
                   ` (2 preceding siblings ...)
  2019-07-04 17:34 ` [PATCH rdma-next 0/2] Allow netlink commands in non init_net net namespace Jason Gunthorpe
@ 2019-07-08 20:21 ` Jason Gunthorpe
  3 siblings, 0 replies; 10+ messages in thread
From: Jason Gunthorpe @ 2019-07-08 20:21 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Doug Ledford, Leon Romanovsky, RDMA mailing list, Parav Pandit,
	Steve Wise

On Thu, Jul 04, 2019 at 04:04:00PM +0300, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@mellanox.com>
> 
> Now that RDMA devices can be attached to specific net namespace,
> allow netlink commands in non init_net namespace.
> 
> Parav Pandit (2):
>   IB/core: Work on the caller socket net namespace in
>   nldev_newlink()

I applied the first one to for-next

>   IB: Support netlink commands in non init_net net namespaces

The second needs a resend

Thanks,
Jason

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH rdma-next 2/2] IB: Support netlink commands in non init_net net namespaces
  2019-07-08 20:20   ` Jason Gunthorpe
@ 2019-07-09  6:38     ` Leon Romanovsky
  2019-07-09 12:25       ` Jason Gunthorpe
  2019-07-09  6:55     ` Parav Pandit
  1 sibling, 1 reply; 10+ messages in thread
From: Leon Romanovsky @ 2019-07-09  6:38 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Doug Ledford, RDMA mailing list, Parav Pandit, Steve Wise

On Mon, Jul 08, 2019 at 05:20:23PM -0300, Jason Gunthorpe wrote:
> On Thu, Jul 04, 2019 at 04:04:02PM +0300, Leon Romanovsky wrote:
> > -int rdma_nl_unicast(struct sk_buff *skb, u32 pid)
> > +int rdma_nl_unicast(struct net *net, struct sk_buff *skb, u32 pid)
> >  {
> > +	struct rdma_dev_net *rnet = net_generic(net, rdma_dev_net_id);
>
> This should be a proper type safe accessor in all places

"const struct net *net" and not "struct net *net"?

>
> > -void rdma_nl_exit(void)
> > +void rdma_nl_net_exit(struct rdma_dev_net *rnet)
> >  {
> > -	int idx;
> > -
> > -	for (idx = 0; idx < RDMA_NL_NUM_CLIENTS; idx++)
> > -		rdma_nl_unregister(idx);
>
> There should be a WARN_ON during the module unload that no NL clients
> are still registered

IMHO, the usage of WARN_ON is overrated.

>
> Thanks,
> Jason

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH rdma-next 2/2] IB: Support netlink commands in non init_net net namespaces
  2019-07-08 20:20   ` Jason Gunthorpe
  2019-07-09  6:38     ` Leon Romanovsky
@ 2019-07-09  6:55     ` Parav Pandit
  1 sibling, 0 replies; 10+ messages in thread
From: Parav Pandit @ 2019-07-09  6:55 UTC (permalink / raw)
  To: Jason Gunthorpe, Leon Romanovsky
  Cc: Doug Ledford, Leon Romanovsky, RDMA mailing list, Steve Wise



> -----Original Message-----
> From: Jason Gunthorpe <jgg@ziepe.ca>
> Sent: Tuesday, July 9, 2019 1:50 AM
> To: Leon Romanovsky <leon@kernel.org>
> Cc: Doug Ledford <dledford@redhat.com>; Leon Romanovsky
> <leonro@mellanox.com>; RDMA mailing list <linux-rdma@vger.kernel.org>;
> Parav Pandit <parav@mellanox.com>; Steve Wise
> <swise@opengridcomputing.com>
> Subject: Re: [PATCH rdma-next 2/2] IB: Support netlink commands in non
> init_net net namespaces
> 
> On Thu, Jul 04, 2019 at 04:04:02PM +0300, Leon Romanovsky wrote:
> > -int rdma_nl_unicast(struct sk_buff *skb, u32 pid)
> > +int rdma_nl_unicast(struct net *net, struct sk_buff *skb, u32 pid)
> >  {
> > +	struct rdma_dev_net *rnet = net_generic(net, rdma_dev_net_id);
> 
> This should be a proper type safe accessor in all places
> 
Adding it.

> > -void rdma_nl_exit(void)
> > +void rdma_nl_net_exit(struct rdma_dev_net *rnet)
> >  {
> > -	int idx;
> > -
> > -	for (idx = 0; idx < RDMA_NL_NUM_CLIENTS; idx++)
> > -		rdma_nl_unregister(idx);
> 
> There should be a WARN_ON during the module unload that no NL clients are
> still registered
> 
Adding it.

> Thanks,
> Jason

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH rdma-next 2/2] IB: Support netlink commands in non init_net net namespaces
  2019-07-09  6:38     ` Leon Romanovsky
@ 2019-07-09 12:25       ` Jason Gunthorpe
  0 siblings, 0 replies; 10+ messages in thread
From: Jason Gunthorpe @ 2019-07-09 12:25 UTC (permalink / raw)
  To: Leon Romanovsky; +Cc: Doug Ledford, RDMA mailing list, Parav Pandit, Steve Wise

On Tue, Jul 09, 2019 at 09:38:42AM +0300, Leon Romanovsky wrote:
> On Mon, Jul 08, 2019 at 05:20:23PM -0300, Jason Gunthorpe wrote:
> > On Thu, Jul 04, 2019 at 04:04:02PM +0300, Leon Romanovsky wrote:
> > > -int rdma_nl_unicast(struct sk_buff *skb, u32 pid)
> > > +int rdma_nl_unicast(struct net *net, struct sk_buff *skb, u32 pid)
> > >  {
> > > +	struct rdma_dev_net *rnet = net_generic(net, rdma_dev_net_id);
> >
> > This should be a proper type safe accessor in all places
> 
> "const struct net *net" and not "struct net *net"?

No, 

  static inline struct rdma_dev_net *rdma_get_net(struct net *net);

> >
> > > -void rdma_nl_exit(void)
> > > +void rdma_nl_net_exit(struct rdma_dev_net *rnet)
> > >  {
> > > -	int idx;
> > > -
> > > -	for (idx = 0; idx < RDMA_NL_NUM_CLIENTS; idx++)
> > > -		rdma_nl_unregister(idx);
> >
> > There should be a WARN_ON during the module unload that no NL clients
> > are still registered
> 
> IMHO, the usage of WARN_ON is overrated.

If there is to be any code at all I want to see WARN_ON's for things
that can't happen. Not pr_debug, not nonsense loops like the above.

Jason

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-07-09 12:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-04 13:04 [PATCH rdma-next 0/2] Allow netlink commands in non init_net net namespace Leon Romanovsky
2019-07-04 13:04 ` [PATCH rdma-next 1/2] IB/core: Work on the caller socket net namespace in nldev_newlink() Leon Romanovsky
2019-07-04 13:04 ` [PATCH rdma-next 2/2] IB: Support netlink commands in non init_net net namespaces Leon Romanovsky
2019-07-08 20:20   ` Jason Gunthorpe
2019-07-09  6:38     ` Leon Romanovsky
2019-07-09 12:25       ` Jason Gunthorpe
2019-07-09  6:55     ` Parav Pandit
2019-07-04 17:34 ` [PATCH rdma-next 0/2] Allow netlink commands in non init_net net namespace Jason Gunthorpe
2019-07-05  2:12   ` Parav Pandit
2019-07-08 20:21 ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).