Skip to contentSkip to conversation

ksmbd: set the rdma capability of network adapter using ib_client

PATCH In review Hyunchul Lee 2 participants 7 messages Dec 22, 2021 – Dec 25, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ksmbd: set the rdma capability of network adapter using ib_client

Set the rdma capability using ib_clien, Because For some devices, ib_device_get_by_netdev() returns NULL.

---
 fs/ksmbd/transport_rdma.c | 89 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 83 insertions(+), 6 deletions(-)
fs/ksmbd/transport_rdma.c +83 -6
index 7e57cbb0bb35..0820c6a9d75e 100644
@@ -79,6 +79,14 @@ static int smb_direct_max_read_write_size = 1024 * 1024;
 
 static int smb_direct_max_outstanding_rw_ops = 8;
 
+static LIST_HEAD(smb_direct_device_list);
+static DEFINE_RWLOCK(smb_direct_device_lock);
+
+struct smb_direct_device {
+	struct ib_device	*ib_dev;
+	struct list_head	list;
+};
+
 static struct smb_direct_listener {
 	struct rdma_cm_id	*cm_id;
 } smb_direct_listener;
@@ -2007,12 +2015,62 @@ static int smb_direct_listen(int port)
 	return ret;
 }
 
+static int smb_direct_ib_client_add(struct ib_device *ib_dev)
+{
+	struct smb_direct_device *smb_dev;
+
+	if (!ib_dev->ops.get_netdev ||
+	    ib_dev->node_type != RDMA_NODE_IB_CA ||
+	    !rdma_frwr_is_supported(&ib_dev->attrs))
+		return 0;
+
+	smb_dev = kzalloc(sizeof(*smb_dev), GFP_KERNEL);
+	if (!smb_dev)
+		return -ENOMEM;
+	smb_dev->ib_dev = ib_dev;
+
+	write_lock(&smb_direct_device_lock);
+	list_add(&smb_dev->list, &smb_direct_device_list);
+	write_unlock(&smb_direct_device_lock);
+
+	ksmbd_debug(RDMA, "ib device added: name %s\n", ib_dev->name);
+	return 0;
+}
+
+static void smb_direct_ib_client_remove(struct ib_device *ib_dev,
+					void *client_data)
+{
+	struct smb_direct_device *smb_dev, *tmp;
+
+	write_lock(&smb_direct_device_lock);
+	list_for_each_entry_safe(smb_dev, tmp, &smb_direct_device_list, list) {
+		if (smb_dev->ib_dev == ib_dev) {
+			list_del(&smb_dev->list);
+			kfree(smb_dev);
+			break;
+		}
+	}
+	write_unlock(&smb_direct_device_lock);
+}
+
+static struct ib_client smb_direct_ib_client = {
+	.name	= "ksmbd_smb_direct_ib",
+};
+
 int ksmbd_rdma_init(void)
 {
 	int ret;
 
 	smb_direct_listener.cm_id = NULL;
 
+	smb_direct_ib_client.add = smb_direct_ib_client_add;
+	smb_direct_ib_client.remove = smb_direct_ib_client_remove;
+	ret = ib_register_client(&smb_direct_ib_client);
+	if (ret) {
+		pr_err("failed to ib_register_client\n");
+		return ret;
+	}
+
 	/* When a client is running out of send credits, the credits are
 	 * granted by the server's sending a packet using this queue.
 	 * This avoids the situation that a clients cannot send packets
@@ -2046,20 +2104,39 @@ int ksmbd_rdma_destroy(void)
 		destroy_workqueue(smb_direct_wq);
 		smb_direct_wq = NULL;
 	}
+
+	if (smb_direct_ib_client.add)
+		ib_unregister_client(&smb_direct_ib_client);
+	smb_direct_ib_client.add = NULL;
 	return 0;
 }
 
 bool ksmbd_rdma_capable_netdev(struct net_device *netdev)
 {
-	struct ib_device *ibdev;
+	struct smb_direct_device *smb_dev;
+	int i;
 	bool rdma_capable = false;
 
-	ibdev = ib_device_get_by_netdev(netdev, RDMA_DRIVER_UNKNOWN);
-	if (ibdev) {
-		if (rdma_frwr_is_supported(&ibdev->attrs))
-			rdma_capable = true;
-		ib_device_put(ibdev);
+	read_lock(&smb_direct_device_lock);
+	list_for_each_entry(smb_dev, &smb_direct_device_list, list) {
+		for (i = 0; i < smb_dev->ib_dev->phys_port_cnt; i++) {
+			struct net_device *ndev;
+
+			ndev = smb_dev->ib_dev->ops.get_netdev(smb_dev->ib_dev,
+							       i + 1);
+			if (!ndev)
+				continue;
+
+			if (ndev == netdev) {
+				dev_put(ndev);
+				rdma_capable = true;
+				goto out;
+			}
+			dev_put(ndev);
+		}
 	}
+out:
+	read_unlock(&smb_direct_device_lock);
 	return rdma_capable;
 }
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw

2021-12-23 7:43 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 46 lines

Set the rdma capability using ib_clien, Because For some devices, ib_device_get_by_netdev() returns NULL.

---
 fs/ksmbd/transport_rdma.c | 89 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 83 insertions(+), 6 deletions(-)
fs/ksmbd/transport_rdma.c +23 -0
index 7e57cbb0bb35..0820c6a9d75e 100644
@@ -79,6 +79,14 @@ static int smb_direct_max_read_write_size = 1024 * 1024;
 
 static int smb_direct_max_outstanding_rw_ops = 8;
 
+static LIST_HEAD(smb_direct_device_list);
+static DEFINE_RWLOCK(smb_direct_device_lock);
+
+struct smb_direct_device {
+	struct ib_device	*ib_dev;
+	struct list_head	list;
+};
+
 static struct smb_direct_listener {
 	struct rdma_cm_id	*cm_id;
 } smb_direct_listener;
@@ -2007,12 +2015,62 @@ static int smb_direct_listen(int port)
 	return ret;
 }
 
+static int smb_direct_ib_client_add(struct ib_device *ib_dev)
+{
+	struct smb_direct_device *smb_dev;
+
+	if (!ib_dev->ops.get_netdev ||
+	    ib_dev->node_type != RDMA_NODE_IB_CA ||
+	    !rdma_frwr_is_supported(&ib_dev->attrs))
+		return 0;
+
+	smb_dev = kzalloc(sizeof(*smb_dev), GFP_KERNEL);
+	if (!smb_dev)
+		return -ENOMEM;
+	smb_dev->ib_dev = ib_dev;
+
+	write_lock(&smb_direct_device_lock);

fs/ksmbd/transport_rdma.c static int smb_direct_listen(int port) · line 2042

Quoted 10 lines
fs/ksmbd/transport_rdma.c +10 -0
+	list_add(&smb_dev->list, &smb_direct_device_list);
+	write_unlock(&smb_direct_device_lock);
+
+	ksmbd_debug(RDMA, "ib device added: name %s\n", ib_dev->name);
+	return 0;
+}
+
+static void smb_direct_ib_client_remove(struct ib_device *ib_dev,
+					void *client_data)
+{

When is this function called? Is rdma shutdown needed here?

Quoted 5 lines
fs/ksmbd/transport_rdma.c +5 -0
+	struct smb_direct_device *smb_dev, *tmp;
+
+	write_lock(&smb_direct_device_lock);
+	list_for_each_entry_safe(smb_dev, tmp, &smb_direct_device_list, list) {
+		if (smb_dev->ib_dev == ib_dev) {

fs/ksmbd/transport_rdma.c static int smb_direct_listen(int port) · line 2057

Quoted 10 lines
fs/ksmbd/transport_rdma.c +10 -0
+			list_del(&smb_dev->list);
+			kfree(smb_dev);
+			break;
+		}
+	}
+	write_unlock(&smb_direct_device_lock);
+}
+
+static struct ib_client smb_direct_ib_client = {
+	.name	= "ksmbd_smb_direct_ib",

Move smb_direct_ib_client_add and smb_direct_ib_client_remove to here.

Quoted 20 lines
fs/ksmbd/transport_rdma.c +10 -0
+};
+
 int ksmbd_rdma_init(void)
 {
 	int ret;
 
 	smb_direct_listener.cm_id = NULL;
 
+	smb_direct_ib_client.add = smb_direct_ib_client_add;
+	smb_direct_ib_client.remove = smb_direct_ib_client_remove;
+	ret = ib_register_client(&smb_direct_ib_client);
+	if (ret) {
+		pr_err("failed to ib_register_client\n");
+		return ret;
+	}
+
 	/* When a client is running out of send credits, the credits are
 	 * granted by the server's sending a packet using this queue.
 	 * This avoids the situation that a clients cannot send packets

fs/ksmbd/transport_rdma.c int ksmbd_rdma_destroy(void) · line 2110

Quoted 7 lines
fs/ksmbd/transport_rdma.c +4 -0
@@ -2046,20 +2104,39 @@ int ksmbd_rdma_destroy(void)
 		destroy_workqueue(smb_direct_wq);
 		smb_direct_wq = NULL;
 	}
+
+	if (smb_direct_ib_client.add)
+		ib_unregister_client(&smb_direct_ib_client);
+	smb_direct_ib_client.add = NULL;

Why ?

Quoted 42 lines
fs/ksmbd/transport_rdma.c +21 -7
 	return 0;
 }
 
 bool ksmbd_rdma_capable_netdev(struct net_device *netdev)
 {
-	struct ib_device *ibdev;
+	struct smb_direct_device *smb_dev;
+	int i;
 	bool rdma_capable = false;
 
-	ibdev = ib_device_get_by_netdev(netdev, RDMA_DRIVER_UNKNOWN);
-	if (ibdev) {
-		if (rdma_frwr_is_supported(&ibdev->attrs))
-			rdma_capable = true;
-		ib_device_put(ibdev);
+	read_lock(&smb_direct_device_lock);
+	list_for_each_entry(smb_dev, &smb_direct_device_list, list) {
+		for (i = 0; i < smb_dev->ib_dev->phys_port_cnt; i++) {
+			struct net_device *ndev;
+
+			ndev = smb_dev->ib_dev->ops.get_netdev(smb_dev->ib_dev,
+							       i + 1);
+			if (!ndev)
+				continue;
+
+			if (ndev == netdev) {
+				dev_put(ndev);
+				rdma_capable = true;
+				goto out;
+			}
+			dev_put(ndev);
+		}
 	}
+out:
+	read_unlock(&smb_direct_device_lock);
 	return rdma_capable;
 }
 
--

2.25.1

#2 lore raw

2021년 12월 24일 (금) 오후 4:27, Namjae Jeon <[email protected]>님이 작성:

Quoted 51 lines

2021-12-23 7:43 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 49 lines

Set the rdma capability using ib_clien, Because For some devices, ib_device_get_by_netdev() returns NULL.

---
 fs/ksmbd/transport_rdma.c | 89 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 83 insertions(+), 6 deletions(-)
fs/ksmbd/transport_rdma.c +26 -0
index 7e57cbb0bb35..0820c6a9d75e 100644
@@ -79,6 +79,14 @@ static int smb_direct_max_read_write_size = 1024 * 1024;
 
 static int smb_direct_max_outstanding_rw_ops = 8;
 
+static LIST_HEAD(smb_direct_device_list);
+static DEFINE_RWLOCK(smb_direct_device_lock);
+
+struct smb_direct_device {
+     struct ib_device        *ib_dev;
+     struct list_head        list;
+};
+
 static struct smb_direct_listener {
      struct rdma_cm_id       *cm_id;
 } smb_direct_listener;
@@ -2007,12 +2015,62 @@ static int smb_direct_listen(int port)
      return ret;
 }
 
+static int smb_direct_ib_client_add(struct ib_device *ib_dev)
+{
+     struct smb_direct_device *smb_dev;
+
+     if (!ib_dev->ops.get_netdev ||
+         ib_dev->node_type != RDMA_NODE_IB_CA ||
+         !rdma_frwr_is_supported(&ib_dev->attrs))
+             return 0;
+
+     smb_dev = kzalloc(sizeof(*smb_dev), GFP_KERNEL);
+     if (!smb_dev)
+             return -ENOMEM;
+     smb_dev->ib_dev = ib_dev;
+
+     write_lock(&smb_direct_device_lock);
+     list_add(&smb_dev->list, &smb_direct_device_list);
+     write_unlock(&smb_direct_device_lock);
+
Quoted 9 lines

fs/ksmbd/transport_rdma.c static int smb_direct_listen(int port) · line 2042

Quoted 7 lines
fs/ksmbd/transport_rdma.c +7 -0
+     ksmbd_debug(RDMA, "ib device added: name %s\n", ib_dev->name);
+     return 0;
+}
+
+static void smb_direct_ib_client_remove(struct ib_device *ib_dev,
+                                     void *client_data)
+{

When is this function called? Is rdma shutdown needed here?

This is called when a device is unplugged. After this call, RDMA_CM_EVENT_DEVICE_REMOVAL event is generated. And ksmbd handles this event.

Quoted 37 lines
Quoted 5 lines
fs/ksmbd/transport_rdma.c +5 -0
+     struct smb_direct_device *smb_dev, *tmp;
+
+     write_lock(&smb_direct_device_lock);
+     list_for_each_entry_safe(smb_dev, tmp, &smb_direct_device_list, list) {
+             if (smb_dev->ib_dev == ib_dev) {

fs/ksmbd/transport_rdma.c static int smb_direct_listen(int port) · line 2057

Quoted 10 lines
fs/ksmbd/transport_rdma.c +10 -0
+                     list_del(&smb_dev->list);
+                     kfree(smb_dev);
+                     break;
+             }
+     }
+     write_unlock(&smb_direct_device_lock);
+}
+
+static struct ib_client smb_direct_ib_client = {
+     .name   = "ksmbd_smb_direct_ib",

Move smb_direct_ib_client_add and smb_direct_ib_client_remove to here.

Quoted 20 lines
fs/ksmbd/transport_rdma.c +10 -0
+};
+
 int ksmbd_rdma_init(void)
 {
      int ret;
 
      smb_direct_listener.cm_id = NULL;
 
+     smb_direct_ib_client.add = smb_direct_ib_client_add;
+     smb_direct_ib_client.remove = smb_direct_ib_client_remove;
+     ret = ib_register_client(&smb_direct_ib_client);
+     if (ret) {
+             pr_err("failed to ib_register_client\n");
+             return ret;
+     }
+
      /* When a client is running out of send credits, the credits are
       * granted by the server's sending a packet using this queue.
       * This avoids the situation that a clients cannot send packets
@@ -2046,20 +2104,39 @@ int ksmbd_rdma_destroy(void)
Quoted 9 lines

fs/ksmbd/transport_rdma.c int ksmbd_rdma_destroy(void) · line 2110

Quoted 7 lines
fs/ksmbd/transport_rdma.c +4 -0
              destroy_workqueue(smb_direct_wq);
              smb_direct_wq = NULL;
      }
+
+     if (smb_direct_ib_client.add)
+             ib_unregister_client(&smb_direct_ib_client);
+     smb_direct_ib_client.add = NULL;

Why ?

To avoid multiple calls of ib_unregister_client, because ksmbd_rdma_destory() can be called without ksmbd_rdma_init(). I will clean two functions and remove these statements.

Quoted 42 lines
Quoted 42 lines
fs/ksmbd/transport_rdma.c +21 -7
      return 0;
 }
 
 bool ksmbd_rdma_capable_netdev(struct net_device *netdev)
 {
-     struct ib_device *ibdev;
+     struct smb_direct_device *smb_dev;
+     int i;
      bool rdma_capable = false;
 
-     ibdev = ib_device_get_by_netdev(netdev, RDMA_DRIVER_UNKNOWN);
-     if (ibdev) {
-             if (rdma_frwr_is_supported(&ibdev->attrs))
-                     rdma_capable = true;
-             ib_device_put(ibdev);
+     read_lock(&smb_direct_device_lock);
+     list_for_each_entry(smb_dev, &smb_direct_device_list, list) {
+             for (i = 0; i < smb_dev->ib_dev->phys_port_cnt; i++) {
+                     struct net_device *ndev;
+
+                     ndev = smb_dev->ib_dev->ops.get_netdev(smb_dev->ib_dev,
+                                                            i + 1);
+                     if (!ndev)
+                             continue;
+
+                     if (ndev == netdev) {
+                             dev_put(ndev);
+                             rdma_capable = true;
+                             goto out;
+                     }
+                     dev_put(ndev);
+             }
      }
+out:
+     read_unlock(&smb_direct_device_lock);
      return rdma_capable;
 }
 
--

2.25.1

Signature · 2 lines
Thanks,
Hyunchul
maintainer
#3 lore raw

2021-12-25 7:53 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 63 lines

2021년 12월 24일 (금) 오후 4:27, Namjae Jeon <[email protected]>님이 작성:

Quoted 52 lines

2021-12-23 7:43 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 50 lines

Set the rdma capability using ib_clien, Because For some devices, ib_device_get_by_netdev() returns NULL.

---
 fs/ksmbd/transport_rdma.c | 89 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 83 insertions(+), 6 deletions(-)
fs/ksmbd/transport_rdma.c +8 -0
index 7e57cbb0bb35..0820c6a9d75e 100644
@@ -79,6 +79,14 @@ static int smb_direct_max_read_write_size = 1024 *
 1024;
 
 static int smb_direct_max_outstanding_rw_ops = 8;
 
+static LIST_HEAD(smb_direct_device_list);
+static DEFINE_RWLOCK(smb_direct_device_lock);
+
+struct smb_direct_device {
+     struct ib_device        *ib_dev;
+     struct list_head        list;
+};
+
 static struct smb_direct_listener {
      struct rdma_cm_id       *cm_id;

} smb_direct_listener;

fs/ksmbd/transport_rdma.c +18 -0
@@ -2007,12 +2015,62 @@ static int smb_direct_listen(int port)
      return ret;
 }
 
+static int smb_direct_ib_client_add(struct ib_device *ib_dev)
+{
+     struct smb_direct_device *smb_dev;
+
+     if (!ib_dev->ops.get_netdev ||
+         ib_dev->node_type != RDMA_NODE_IB_CA ||
+         !rdma_frwr_is_supported(&ib_dev->attrs))
+             return 0;
+
+     smb_dev = kzalloc(sizeof(*smb_dev), GFP_KERNEL);
+     if (!smb_dev)
+             return -ENOMEM;
+     smb_dev->ib_dev = ib_dev;
+
+     write_lock(&smb_direct_device_lock);
+     list_add(&smb_dev->list, &smb_direct_device_list);
+     write_unlock(&smb_direct_device_lock);
+
Quoted 9 lines

fs/ksmbd/transport_rdma.c static int smb_direct_listen(int port) · line 2042

Quoted 7 lines
fs/ksmbd/transport_rdma.c +7 -0
+     ksmbd_debug(RDMA, "ib device added: name %s\n", ib_dev->name);
+     return 0;
+}
+
+static void smb_direct_ib_client_remove(struct ib_device *ib_dev,
+                                     void *client_data)
+{

When is this function called? Is rdma shutdown needed here?

Quoted 3 lines

This is called when a device is unplugged. After this call, RDMA_CM_EVENT_DEVICE_REMOVAL event is generated. And ksmbd handles this event.

Okay, Have you actually tested it while unplugging NICs? And This patch doesn't work on Chelsio NICs(iWARP).

Quoted 103 lines
Quoted 39 lines
Quoted 7 lines
fs/ksmbd/transport_rdma.c +5 -0
+     struct smb_direct_device *smb_dev, *tmp;
+
+     write_lock(&smb_direct_device_lock);
+     list_for_each_entry_safe(smb_dev, tmp, &smb_direct_device_list,
 list) {
+             if (smb_dev->ib_dev == ib_dev) {

fs/ksmbd/transport_rdma.c static int smb_direct_listen(int port) · line 2057

Quoted 10 lines
fs/ksmbd/transport_rdma.c +10 -0
+                     list_del(&smb_dev->list);
+                     kfree(smb_dev);
+                     break;
+             }
+     }
+     write_unlock(&smb_direct_device_lock);
+}
+
+static struct ib_client smb_direct_ib_client = {
+     .name   = "ksmbd_smb_direct_ib",

Move smb_direct_ib_client_add and smb_direct_ib_client_remove to here.

Quoted 20 lines
fs/ksmbd/transport_rdma.c +10 -0
+};
+
 int ksmbd_rdma_init(void)
 {
      int ret;
 
      smb_direct_listener.cm_id = NULL;
 
+     smb_direct_ib_client.add = smb_direct_ib_client_add;
+     smb_direct_ib_client.remove = smb_direct_ib_client_remove;
+     ret = ib_register_client(&smb_direct_ib_client);
+     if (ret) {
+             pr_err("failed to ib_register_client\n");
+             return ret;
+     }
+
      /* When a client is running out of send credits, the credits are
       * granted by the server's sending a packet using this queue.

* This avoids the situation that a clients cannot send packets

fs/ksmbd/transport_rdma.c +0 -0
@@ -2046,20 +2104,39 @@ int ksmbd_rdma_destroy(void)
Quoted 9 lines

fs/ksmbd/transport_rdma.c int ksmbd_rdma_destroy(void) · line 2110

Quoted 7 lines
fs/ksmbd/transport_rdma.c +4 -0
              destroy_workqueue(smb_direct_wq);
              smb_direct_wq = NULL;
      }
+
+     if (smb_direct_ib_client.add)
+             ib_unregister_client(&smb_direct_ib_client);
+     smb_direct_ib_client.add = NULL;

Why ?

To avoid multiple calls of ib_unregister_client, because ksmbd_rdma_destory() can be called without ksmbd_rdma_init(). I will clean two functions and remove these statements.

Quoted 39 lines
Quoted 39 lines
fs/ksmbd/transport_rdma.c +21 -6
      return 0;
 }
 
 bool ksmbd_rdma_capable_netdev(struct net_device *netdev)
 {
-     struct ib_device *ibdev;
+     struct smb_direct_device *smb_dev;
+     int i;
      bool rdma_capable = false;
 
-     ibdev = ib_device_get_by_netdev(netdev, RDMA_DRIVER_UNKNOWN);
-     if (ibdev) {
-             if (rdma_frwr_is_supported(&ibdev->attrs))
-                     rdma_capable = true;
-             ib_device_put(ibdev);
+     read_lock(&smb_direct_device_lock);
+     list_for_each_entry(smb_dev, &smb_direct_device_list, list) {
+             for (i = 0; i < smb_dev->ib_dev->phys_port_cnt; i++) {
+                     struct net_device *ndev;
+
+                     ndev =
 smb_dev->ib_dev->ops.get_netdev(smb_dev->ib_dev,
+                                                            i + 1);
+                     if (!ndev)
+                             continue;
+
+                     if (ndev == netdev) {
+                             dev_put(ndev);
+                             rdma_capable = true;
+                             goto out;
+                     }
+                     dev_put(ndev);
+             }
      }
+out:
+     read_unlock(&smb_direct_device_lock);
      return rdma_capable;
 }
Quoted 4 lines
Quoted 4 lines

--
2.25.1

--
Thanks,
Hyunchul

#4 lore raw

2021년 12월 25일 (토) 오전 8:05, Namjae Jeon <[email protected]>님이 작성:

Quoted 65 lines

2021-12-25 7:53 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 63 lines

2021년 12월 24일 (금) 오후 4:27, Namjae Jeon <[email protected]>님이 작성:

Quoted 61 lines

2021-12-23 7:43 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 47 lines

Set the rdma capability using ib_clien, Because For some devices, ib_device_get_by_netdev() returns NULL.

---
 fs/ksmbd/transport_rdma.c | 89 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 83 insertions(+), 6 deletions(-)
fs/ksmbd/transport_rdma.c +8 -0
index 7e57cbb0bb35..0820c6a9d75e 100644
@@ -79,6 +79,14 @@ static int smb_direct_max_read_write_size = 1024 *
 1024;
 
 static int smb_direct_max_outstanding_rw_ops = 8;
 
+static LIST_HEAD(smb_direct_device_list);
+static DEFINE_RWLOCK(smb_direct_device_lock);
+
+struct smb_direct_device {
+     struct ib_device        *ib_dev;
+     struct list_head        list;
+};
+
 static struct smb_direct_listener {
      struct rdma_cm_id       *cm_id;

} smb_direct_listener;

fs/ksmbd/transport_rdma.c +15 -0
@@ -2007,12 +2015,62 @@ static int smb_direct_listen(int port)
      return ret;
 }
 
+static int smb_direct_ib_client_add(struct ib_device *ib_dev)
+{
+     struct smb_direct_device *smb_dev;
+
+     if (!ib_dev->ops.get_netdev ||
+         ib_dev->node_type != RDMA_NODE_IB_CA ||
+         !rdma_frwr_is_supported(&ib_dev->attrs))
+             return 0;
+
+     smb_dev = kzalloc(sizeof(*smb_dev), GFP_KERNEL);
+     if (!smb_dev)
+             return -ENOMEM;
+     smb_dev->ib_dev = ib_dev;
+
+     write_lock(&smb_direct_device_lock);

fs/ksmbd/transport_rdma.c static int smb_direct_listen(int port) · line 2042

Quoted 10 lines
fs/ksmbd/transport_rdma.c +10 -0
+     list_add(&smb_dev->list, &smb_direct_device_list);
+     write_unlock(&smb_direct_device_lock);
+
+     ksmbd_debug(RDMA, "ib device added: name %s\n", ib_dev->name);
+     return 0;
+}
+
+static void smb_direct_ib_client_remove(struct ib_device *ib_dev,
+                                     void *client_data)
+{

When is this function called? Is rdma shutdown needed here?

Quoted 6 lines
Quoted 3 lines

This is called when a device is unplugged. After this call, RDMA_CM_EVENT_DEVICE_REMOVAL event is generated. And ksmbd handles this event.

Okay, Have you actually tested it while unplugging NICs? And This patch doesn't work on Chelsio NICs(iWARP).

Not yet. I will test it but need some time because of setting up my test environment.

Is the rdma capability set on Chelsio NICs without this patch?

Quoted 103 lines
Quoted 103 lines
Quoted 39 lines
Quoted 7 lines
fs/ksmbd/transport_rdma.c +5 -0
+     struct smb_direct_device *smb_dev, *tmp;
+
+     write_lock(&smb_direct_device_lock);
+     list_for_each_entry_safe(smb_dev, tmp, &smb_direct_device_list,
 list) {
+             if (smb_dev->ib_dev == ib_dev) {

fs/ksmbd/transport_rdma.c static int smb_direct_listen(int port) · line 2057

Quoted 10 lines
fs/ksmbd/transport_rdma.c +10 -0
+                     list_del(&smb_dev->list);
+                     kfree(smb_dev);
+                     break;
+             }
+     }
+     write_unlock(&smb_direct_device_lock);
+}
+
+static struct ib_client smb_direct_ib_client = {
+     .name   = "ksmbd_smb_direct_ib",

Move smb_direct_ib_client_add and smb_direct_ib_client_remove to here.

Quoted 20 lines
fs/ksmbd/transport_rdma.c +10 -0
+};
+
 int ksmbd_rdma_init(void)
 {
      int ret;
 
      smb_direct_listener.cm_id = NULL;
 
+     smb_direct_ib_client.add = smb_direct_ib_client_add;
+     smb_direct_ib_client.remove = smb_direct_ib_client_remove;
+     ret = ib_register_client(&smb_direct_ib_client);
+     if (ret) {
+             pr_err("failed to ib_register_client\n");
+             return ret;
+     }
+
      /* When a client is running out of send credits, the credits are
       * granted by the server's sending a packet using this queue.

* This avoids the situation that a clients cannot send packets

fs/ksmbd/transport_rdma.c +0 -0
@@ -2046,20 +2104,39 @@ int ksmbd_rdma_destroy(void)
Quoted 9 lines

fs/ksmbd/transport_rdma.c int ksmbd_rdma_destroy(void) · line 2110

Quoted 7 lines
fs/ksmbd/transport_rdma.c +4 -0
              destroy_workqueue(smb_direct_wq);
              smb_direct_wq = NULL;
      }
+
+     if (smb_direct_ib_client.add)
+             ib_unregister_client(&smb_direct_ib_client);
+     smb_direct_ib_client.add = NULL;

Why ?

To avoid multiple calls of ib_unregister_client, because ksmbd_rdma_destory() can be called without ksmbd_rdma_init(). I will clean two functions and remove these statements.

Quoted 39 lines
Quoted 39 lines
fs/ksmbd/transport_rdma.c +21 -6
      return 0;
 }
 
 bool ksmbd_rdma_capable_netdev(struct net_device *netdev)
 {
-     struct ib_device *ibdev;
+     struct smb_direct_device *smb_dev;
+     int i;
      bool rdma_capable = false;
 
-     ibdev = ib_device_get_by_netdev(netdev, RDMA_DRIVER_UNKNOWN);
-     if (ibdev) {
-             if (rdma_frwr_is_supported(&ibdev->attrs))
-                     rdma_capable = true;
-             ib_device_put(ibdev);
+     read_lock(&smb_direct_device_lock);
+     list_for_each_entry(smb_dev, &smb_direct_device_list, list) {
+             for (i = 0; i < smb_dev->ib_dev->phys_port_cnt; i++) {
+                     struct net_device *ndev;
+
+                     ndev =
 smb_dev->ib_dev->ops.get_netdev(smb_dev->ib_dev,
+                                                            i + 1);
+                     if (!ndev)
+                             continue;
+
+                     if (ndev == netdev) {
+                             dev_put(ndev);
+                             rdma_capable = true;
+                             goto out;
+                     }
+                     dev_put(ndev);
+             }
      }
+out:
+     read_unlock(&smb_direct_device_lock);
      return rdma_capable;
 }
Quoted 4 lines
Quoted 4 lines

--
2.25.1

--
Thanks,
Hyunchul

Signature · 2 lines
Thanks,
Hyunchul
maintainer
#5 lore raw

2021-12-25 8:38 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 71 lines

2021년 12월 25일 (토) 오전 8:05, Namjae Jeon <[email protected]>님이 작성:

Quoted 70 lines

2021-12-25 7:53 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 68 lines

2021년 12월 24일 (금) 오후 4:27, Namjae Jeon <[email protected]>님이 작성:

Quoted 54 lines

2021-12-23 7:43 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 52 lines

Set the rdma capability using ib_clien, Because For some devices, ib_device_get_by_netdev() returns NULL.

---
 fs/ksmbd/transport_rdma.c | 89
++++++++++++++++++++++++++++++++++++---
 1 file changed, 83 insertions(+), 6 deletions(-)
fs/ksmbd/transport_rdma.c +8 -0
index 7e57cbb0bb35..0820c6a9d75e 100644
@@ -79,6 +79,14 @@ static int smb_direct_max_read_write_size = 1024
 *
 1024;
 
 static int smb_direct_max_outstanding_rw_ops = 8;
 
+static LIST_HEAD(smb_direct_device_list);
+static DEFINE_RWLOCK(smb_direct_device_lock);
+
+struct smb_direct_device {
+     struct ib_device        *ib_dev;
+     struct list_head        list;
+};
+
 static struct smb_direct_listener {
      struct rdma_cm_id       *cm_id;

} smb_direct_listener;

fs/ksmbd/transport_rdma.c +18 -0
@@ -2007,12 +2015,62 @@ static int smb_direct_listen(int port)
      return ret;
 }
 
+static int smb_direct_ib_client_add(struct ib_device *ib_dev)
+{
+     struct smb_direct_device *smb_dev;
+
+     if (!ib_dev->ops.get_netdev ||
+         ib_dev->node_type != RDMA_NODE_IB_CA ||
+         !rdma_frwr_is_supported(&ib_dev->attrs))
+             return 0;
+
+     smb_dev = kzalloc(sizeof(*smb_dev), GFP_KERNEL);
+     if (!smb_dev)
+             return -ENOMEM;
+     smb_dev->ib_dev = ib_dev;
+
+     write_lock(&smb_direct_device_lock);
+     list_add(&smb_dev->list, &smb_direct_device_list);
+     write_unlock(&smb_direct_device_lock);
+
Quoted 9 lines

fs/ksmbd/transport_rdma.c static int smb_direct_listen(int port) · line 2042

Quoted 7 lines
fs/ksmbd/transport_rdma.c +7 -0
+     ksmbd_debug(RDMA, "ib device added: name %s\n", ib_dev->name);
+     return 0;
+}
+
+static void smb_direct_ib_client_remove(struct ib_device *ib_dev,
+                                     void *client_data)
+{

When is this function called? Is rdma shutdown needed here?

This is called when a device is unplugged. After this call, RDMA_CM_EVENT_DEVICE_REMOVAL event is generated. And ksmbd handles this event.

Quoted 6 lines
Quoted 3 lines

Okay, Have you actually tested it while unplugging NICs? And This patch doesn't work on Chelsio NICs(iWARP).

Not yet. I will test it but need some time because of setting up my test environment.

Don't send untested patch to the list.

Quoted 3 lines

Is the rdma capability set on Chelsio NICs without this patch?

Yes.

Quoted 114 lines
Quoted 96 lines
Quoted 96 lines
Quoted 43 lines
Quoted 9 lines
fs/ksmbd/transport_rdma.c +5 -0
+     struct smb_direct_device *smb_dev, *tmp;
+
+     write_lock(&smb_direct_device_lock);
+     list_for_each_entry_safe(smb_dev, tmp,
 &smb_direct_device_list,
 list) {
+             if (smb_dev->ib_dev == ib_dev) {

fs/ksmbd/transport_rdma.c static int smb_direct_listen(int port) · line 2057

Quoted 10 lines
fs/ksmbd/transport_rdma.c +10 -0
+                     list_del(&smb_dev->list);
+                     kfree(smb_dev);
+                     break;
+             }
+     }
+     write_unlock(&smb_direct_device_lock);
+}
+
+static struct ib_client smb_direct_ib_client = {
+     .name   = "ksmbd_smb_direct_ib",

Move smb_direct_ib_client_add and smb_direct_ib_client_remove to here.

Quoted 22 lines
fs/ksmbd/transport_rdma.c +10 -0
+};
+
 int ksmbd_rdma_init(void)
 {
      int ret;
 
      smb_direct_listener.cm_id = NULL;
 
+     smb_direct_ib_client.add = smb_direct_ib_client_add;
+     smb_direct_ib_client.remove = smb_direct_ib_client_remove;
+     ret = ib_register_client(&smb_direct_ib_client);
+     if (ret) {
+             pr_err("failed to ib_register_client\n");
+             return ret;
+     }
+
      /* When a client is running out of send credits, the credits

are
* granted by the server's sending a packet using this queue.
* This avoids the situation that a clients cannot send
packets

fs/ksmbd/transport_rdma.c +0 -0
@@ -2046,20 +2104,39 @@ int ksmbd_rdma_destroy(void)
Quoted 9 lines

fs/ksmbd/transport_rdma.c int ksmbd_rdma_destroy(void) · line 2110

Quoted 7 lines
fs/ksmbd/transport_rdma.c +4 -0
              destroy_workqueue(smb_direct_wq);
              smb_direct_wq = NULL;
      }
+
+     if (smb_direct_ib_client.add)
+             ib_unregister_client(&smb_direct_ib_client);
+     smb_direct_ib_client.add = NULL;

Why ?

To avoid multiple calls of ib_unregister_client, because ksmbd_rdma_destory() can be called without ksmbd_rdma_init(). I will clean two functions and remove these statements.

Quoted 39 lines
Quoted 39 lines
fs/ksmbd/transport_rdma.c +21 -6
      return 0;
 }
 
 bool ksmbd_rdma_capable_netdev(struct net_device *netdev)
 {
-     struct ib_device *ibdev;
+     struct smb_direct_device *smb_dev;
+     int i;
      bool rdma_capable = false;
 
-     ibdev = ib_device_get_by_netdev(netdev, RDMA_DRIVER_UNKNOWN);
-     if (ibdev) {
-             if (rdma_frwr_is_supported(&ibdev->attrs))
-                     rdma_capable = true;
-             ib_device_put(ibdev);
+     read_lock(&smb_direct_device_lock);
+     list_for_each_entry(smb_dev, &smb_direct_device_list, list) {
+             for (i = 0; i < smb_dev->ib_dev->phys_port_cnt; i++) {
+                     struct net_device *ndev;
+
+                     ndev =
 smb_dev->ib_dev->ops.get_netdev(smb_dev->ib_dev,
+                                                            i + 1);
+                     if (!ndev)
+                             continue;
+
+                     if (ndev == netdev) {
+                             dev_put(ndev);
+                             rdma_capable = true;
+                             goto out;
+                     }
+                     dev_put(ndev);
+             }
      }
+out:
+     read_unlock(&smb_direct_device_lock);
      return rdma_capable;
 }
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines

--
2.25.1

--
Thanks,
Hyunchul

--
Thanks,
Hyunchul

#6 lore raw

2021년 12월 25일 (토) 오후 1:24, Namjae Jeon <[email protected]>님이 작성:

Quoted 77 lines

2021-12-25 8:38 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 75 lines

2021년 12월 25일 (토) 오전 8:05, Namjae Jeon <[email protected]>님이 작성:

Quoted 73 lines

2021-12-25 7:53 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 65 lines

2021년 12월 24일 (금) 오후 4:27, Namjae Jeon <[email protected]>님이 작성:

Quoted 54 lines

2021-12-23 7:43 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 52 lines

Set the rdma capability using ib_clien, Because For some devices, ib_device_get_by_netdev() returns NULL.

---
 fs/ksmbd/transport_rdma.c | 89
++++++++++++++++++++++++++++++++++++---
 1 file changed, 83 insertions(+), 6 deletions(-)
fs/ksmbd/transport_rdma.c +8 -0
index 7e57cbb0bb35..0820c6a9d75e 100644
@@ -79,6 +79,14 @@ static int smb_direct_max_read_write_size = 1024
 *
 1024;
 
 static int smb_direct_max_outstanding_rw_ops = 8;
 
+static LIST_HEAD(smb_direct_device_list);
+static DEFINE_RWLOCK(smb_direct_device_lock);
+
+struct smb_direct_device {
+     struct ib_device        *ib_dev;
+     struct list_head        list;
+};
+
 static struct smb_direct_listener {
      struct rdma_cm_id       *cm_id;

} smb_direct_listener;

fs/ksmbd/transport_rdma.c +18 -0
@@ -2007,12 +2015,62 @@ static int smb_direct_listen(int port)
      return ret;
 }
 
+static int smb_direct_ib_client_add(struct ib_device *ib_dev)
+{
+     struct smb_direct_device *smb_dev;
+
+     if (!ib_dev->ops.get_netdev ||
+         ib_dev->node_type != RDMA_NODE_IB_CA ||
+         !rdma_frwr_is_supported(&ib_dev->attrs))
+             return 0;
+
+     smb_dev = kzalloc(sizeof(*smb_dev), GFP_KERNEL);
+     if (!smb_dev)
+             return -ENOMEM;
+     smb_dev->ib_dev = ib_dev;
+
+     write_lock(&smb_direct_device_lock);
+     list_add(&smb_dev->list, &smb_direct_device_list);
+     write_unlock(&smb_direct_device_lock);
+
Quoted 9 lines

fs/ksmbd/transport_rdma.c static int smb_direct_listen(int port) · line 2042

Quoted 7 lines
fs/ksmbd/transport_rdma.c +7 -0
+     ksmbd_debug(RDMA, "ib device added: name %s\n", ib_dev->name);
+     return 0;
+}
+
+static void smb_direct_ib_client_remove(struct ib_device *ib_dev,
+                                     void *client_data)
+{

When is this function called? Is rdma shutdown needed here?

Quoted 3 lines

This is called when a device is unplugged. After this call, RDMA_CM_EVENT_DEVICE_REMOVAL event is generated. And ksmbd handles this event.

Okay, Have you actually tested it while unplugging NICs? And This patch doesn't work on Chelsio NICs(iWARP).

Quoted 7 lines
Quoted 2 lines

Not yet. I will test it but need some time because of setting up my test environment.

Don't send untested patch to the list.

Quoted 3 lines

Is the rdma capability set on Chelsio NICs without this patch?

Yes.

Okay, After testing device removal and fixing this, I will send the v2 patch.

Quoted 114 lines
Quoted 114 lines
Quoted 96 lines
Quoted 96 lines
Quoted 43 lines
Quoted 9 lines
fs/ksmbd/transport_rdma.c +5 -0
+     struct smb_direct_device *smb_dev, *tmp;
+
+     write_lock(&smb_direct_device_lock);
+     list_for_each_entry_safe(smb_dev, tmp,
 &smb_direct_device_list,
 list) {
+             if (smb_dev->ib_dev == ib_dev) {

fs/ksmbd/transport_rdma.c static int smb_direct_listen(int port) · line 2057

Quoted 10 lines
fs/ksmbd/transport_rdma.c +10 -0
+                     list_del(&smb_dev->list);
+                     kfree(smb_dev);
+                     break;
+             }
+     }
+     write_unlock(&smb_direct_device_lock);
+}
+
+static struct ib_client smb_direct_ib_client = {
+     .name   = "ksmbd_smb_direct_ib",

Move smb_direct_ib_client_add and smb_direct_ib_client_remove to here.

Quoted 22 lines
fs/ksmbd/transport_rdma.c +10 -0
+};
+
 int ksmbd_rdma_init(void)
 {
      int ret;
 
      smb_direct_listener.cm_id = NULL;
 
+     smb_direct_ib_client.add = smb_direct_ib_client_add;
+     smb_direct_ib_client.remove = smb_direct_ib_client_remove;
+     ret = ib_register_client(&smb_direct_ib_client);
+     if (ret) {
+             pr_err("failed to ib_register_client\n");
+             return ret;
+     }
+
      /* When a client is running out of send credits, the credits

are
* granted by the server's sending a packet using this queue.
* This avoids the situation that a clients cannot send
packets

fs/ksmbd/transport_rdma.c +0 -0
@@ -2046,20 +2104,39 @@ int ksmbd_rdma_destroy(void)
Quoted 9 lines

fs/ksmbd/transport_rdma.c int ksmbd_rdma_destroy(void) · line 2110

Quoted 7 lines
fs/ksmbd/transport_rdma.c +4 -0
              destroy_workqueue(smb_direct_wq);
              smb_direct_wq = NULL;
      }
+
+     if (smb_direct_ib_client.add)
+             ib_unregister_client(&smb_direct_ib_client);
+     smb_direct_ib_client.add = NULL;

Why ?

To avoid multiple calls of ib_unregister_client, because ksmbd_rdma_destory() can be called without ksmbd_rdma_init(). I will clean two functions and remove these statements.

Quoted 39 lines
Quoted 39 lines
fs/ksmbd/transport_rdma.c +21 -6
      return 0;
 }
 
 bool ksmbd_rdma_capable_netdev(struct net_device *netdev)
 {
-     struct ib_device *ibdev;
+     struct smb_direct_device *smb_dev;
+     int i;
      bool rdma_capable = false;
 
-     ibdev = ib_device_get_by_netdev(netdev, RDMA_DRIVER_UNKNOWN);
-     if (ibdev) {
-             if (rdma_frwr_is_supported(&ibdev->attrs))
-                     rdma_capable = true;
-             ib_device_put(ibdev);
+     read_lock(&smb_direct_device_lock);
+     list_for_each_entry(smb_dev, &smb_direct_device_list, list) {
+             for (i = 0; i < smb_dev->ib_dev->phys_port_cnt; i++) {
+                     struct net_device *ndev;
+
+                     ndev =
 smb_dev->ib_dev->ops.get_netdev(smb_dev->ib_dev,
+                                                            i + 1);
+                     if (!ndev)
+                             continue;
+
+                     if (ndev == netdev) {
+                             dev_put(ndev);
+                             rdma_capable = true;
+                             goto out;
+                     }
+                     dev_put(ndev);
+             }
      }
+out:
+     read_unlock(&smb_direct_device_lock);
      return rdma_capable;
 }
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines

--
2.25.1

--
Thanks,
Hyunchul

--
Thanks,
Hyunchul

Signature · 2 lines
Thanks,
Hyunchul